Location: PHPKode > projects > RadMacLab > radmaclab/admin/add_machines_process.php
<?php

include ('includes/func_vars_inc.php');
include ('includes/auth_check.php');

if ($_POST['mac'] == ""){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+enter+a+valid+mac+address.");
}

if ($_POST['ip_range'] == "0"){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+select+an+ip+range.");
}

if ($_POST['ip'] == ""){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+enter+a+valid+ip+address.");
}

if ($_POST['machinename'] == ""){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+enter+a+valid+machine+name.");
}

if ($_POST['room'] == ""){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+enter+a+room+number.");
}

if ($_POST['location'] == ""){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+enter+some+location+info.");
}

if ($_POST['initial_buildID'] == "" OR $_POST['initial_buildID'] == "0"){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+select+a+valid+initial+build+configuration.");
}

if ($_POST['after_buildID'] == "" OR $_POST['after_buildID'] == "0"){
	@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=You+must+select+a+valid+after+build+configuration.");
}




$sql  = "INSERT  INTO  `machines` (  `machineID` ,  `mac` , `net_mode`,  `netID`, `ip` ,  `machinename` , `room`,  `location` ,  `run_suc`, `initial_buildID`, `after_buildID`, `default_printer`, `screenID`  ) 
	VALUES (  '',  '".addslashes($_POST['mac'])."', '".addslashes($_POST['net_mode'])."', '".addslashes($_POST['ip_range'])."',  '".addslashes($_POST['ip'])."',  '".addslashes($_POST['machinename'])."',
	'".addslashes($_POST['room'])."', '".addslashes($_POST['location'])."', '0', '".addslashes($_POST['initial_buildID'])."', '".addslashes($_POST['after_buildID'])."', '".addslashes($_POST['default_printer'])."', '".$_POST['screenID']."' );"; 
	
dbase_query($sql);


//process printers
$ID = mysql_insert_id();
for ($i = 0;$i < count($_POST["printers"]); $i++){
	$sql = "INSERT INTO `assigned_printers` (`machineID`, `printerID`) VALUES ('".$ID."','".$_POST["printers"][$i]."');";
	dbase_query($sql);
}


//process repeating schedule
if ($_POST['month'] != "" && $_POST['mday'] != "" && $_POST['wday'] != "" && $_POST['hour'] != ""){
	//format minutes
	if ($_POST['repeat_deviation_range'] == ""){
		$min = 0;
	} else {
		if ($_POST['repeat_deviation_range'] > 59){
			$_POST['repeat_deviation_range'] = 59;
		}
		$min = rand(0, $_POST['repeat_deviation_range']);

	}
	
	 $sql = 'INSERT INTO `schedules_repeat` ( `machineID` , `month` , `mday` , `wday` , `hour`, `min`, `orig_dev` ) ';
	 $sql .= "VALUES ( '".$ID."', '".$_POST['month']."', '".$_POST['mday']."', '".$_POST['wday']."', '".$_POST['hour']."', '".$min."', '".$_POST['repeat_deviation_range']."' );";
	 dbase_query($sql);
}

//process one time only schedule
if ($_POST['runtime'] != "--:--"){
	$curtime = strtotime("now");
	$schedtime = strtotime($_POST['rundate']." ".$_POST['runtime']);
	if ($_POST['single_deviation'] == ""){
		$min = 0;
	} else {
		if ($_POST['single_deviation'] > 59){
			$_POST['single_deviation'] = 59;
		}
		$min = rand(0, $_POST['single_deviation']);

	}
	$devschedtime = strtotime($_POST['rundate']." ".$_POST['runtime']." +".$min." minutes");
	$run_time = date('H:i',$devschedtime);
	$run_date = date('Y-m-d',$devschedtime);
	
	if ($devschedtime > $curtime){
		$sql = 'INSERT INTO `schedules` ( `machineID` , `rundate`, `runtime`, `deviation`, `orig_date`, `orig_time` ) ';
		$sql .= "VALUES ( '".$ID."', '".$run_date."', '".$run_time."', '".$min."', '".$_POST['rundate']."', '".$_POST['runtime']."')";
		dbase_query($sql);
	}
}




@ header("Location: ".$uri_scheme.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/add_machines.php?msg=Machine added successfully.");

?>
Return current item: RadMacLab