Location: PHPKode > projects > MyZCI > myzci/supervisor/composite_update.php
<?
include "../zciconfig.php";
include "../engine/zciobject.php";

$masterconf = new masterconfig();
//make database connection
$mydbcon = $masterconf->dbconnect();
$master = new masterobject();
$master->authenticate();


switch ($_GET['type'])	{
	case "serialnumber"	:
		$new_sn=strtoupper($_GET['svalue']);
		if ($new_sn!=""){
		$table=$_GET['object'];
		$result=dbx_query($mydbcon,"select a.modelid,a.serialnumber,b.modelid from ".$table." a,ownership_".$table." b where a.itemid=".$_GET['itemid']." and b.componentid=a.itemid and b.removed is null");
		$v_modelid=$result->data[0][0];$old_sn=$result->data[0][1];$old_ownership=$result->data[0][2];
		$result=dbx_query($mydbcon,"select itemid from ".$table." where modelid=".$v_modelid." and serialnumber='".$new_sn."'");
		if ($result->rows!=0)	{
			if (is_null($old_sn) || $old_sn="")	dbx_query($mydbcon,"delete from ".$table." where itemid=".$_GET['itemid']);
			else	dbx_query($mydbcon,"update ".$table." set reserved='Y' where itemid=".$_GET['itemid']);
			dbx_query($mydbcon,"update ".$table." set reserved=null where itemid=".$result->data[0][0]);
			$master->singleupdate_phr($mydbcon,"ownership_".$_GET['object'],$_GET['compid'],$result->data[0][0],$old_ownership);
		}
		else	{
			if (is_null($old_sn) || $old_sn="")
				$result=dbx_query($mydbcon,"update ".$table." set serialnumber='".$new_sn."' where itemid=".$_GET['itemid']);
			else	{
				dbx_query($mydbcon,"update ".$table." set reserved='Y' where itemid=".$_GET['itemid']);
				dbx_query($mydbcon,"insert into ".$table." (modelid,serialnumber,registerdate) values (".$v_modelid.",'".$new_sn."',now())");
				$result=dbx_query($mydbcon,"select itemid from ".$table." where modelid=".$v_modelid." and serialnumber='".$new_sn."'");
				$master->singleupdate_phr($mydbcon,"ownership_".$table,$_GET['compid'],$result->data[0][0],$old_ownership);
			}
		}
		}
		break;
	case "invnumber"	:
		$new_inv=$_GET['svalue'];
		if ($new_inv!=""){
		$table=$_GET['object'];
		$result=dbx_query($mydbcon,"select a.modelid,a.invn,b.modelid from ".$table." a,ownership_".$table." b where a.itemid=".$_GET['itemid']." and b.componentid=a.itemid and b.removed is null");
		$v_modelid=$result->data[0][0];$old_inv=$result->data[0][1];$old_ownership=$result->data[0][2];
		$result=dbx_query($mydbcon,"select itemid from ".$table." where modelid=".$v_modelid." and serialnumber='".$new_inv."'");
		if ($result->rows!=0)	{
			if (is_null($old_inv) || $old_inv="")	dbx_query($mydbcon,"delete from ".$table." where itemid=".$_GET['itemid']);
			else	dbx_query($mydbcon,"update ".$table." set reserved='Y' where itemid=".$_GET['itemid']);
			dbx_query($mydbcon,"update ".$table." set reserved=null where itemid=".$result->data[0][0]);
			$master->singleupdate_phr($mydbcon,"ownership_".$_GET['object'],$_GET['compid'],$result->data[0][0],$old_ownership);
		}
		else	{
			if (is_null($old_inv) || $old_inv="")
				$result=dbx_query($mydbcon,"update ".$table." set invn='".$new_inv."' where itemid=".$_GET['itemid']);
			else	{
				dbx_query($mydbcon,"update ".$table." set reserved='Y' where itemid=".$_GET['itemid']);
				dbx_query($mydbcon,"insert into ".$table." (modelid,invn,registerdate) values (".$v_modelid.",'".$new_inv."',now())");
				$result=dbx_query($mydbcon,"select itemid from ".$table." where modelid=".$v_modelid." and invn='".$new_inv."'");
				$master->singleupdate_phr($mydbcon,"ownership_".$table,$_GET['compid'],$result->data[0][0],$old_ownership);
			}
		}
		}
		break;
	case "delete"	:
		$table=$_GET['object'];
		$result=dbx_query($mydbcon,"delete from ".$table." where itemid=".$_GET['itemid'].";");
		$result=dbx_query($mydbcon,"delete from ownership_".$table." where componentid=".$_GET['itemid'].";");
		break;		
	case "ownership"	:
		if ($_GET['object']=="computer")	{
			$master->singleupdate($mydbcon,"ownership",$_GET['itemid'],$_REQUEST['svalue']);
			if ($_REQUEST['chmonitor']==1)	{
				//echo "dsafdf";
				$result=dbx_query($mydbcon,"select b.componentid from ownership_monitor b,monitor a where b.computerid=".$_GET['compid']." and b.removed is null and a.itemid=b.componentid and a.reserved is null");
				for ($i=0;$i<$result->rows;$i++)
					$master->singleupdate_phr($mydbcon,"ownership_monitor",$_GET['compid'],$result->data[$i][0],$_REQUEST['svalue']);
			}
		}
		else
			$master->singleupdate_phr($mydbcon,"ownership_".$_GET['object'],$_GET['compid'],$_GET['itemid'],$_REQUEST['svalue']);
}
header("Location: computer_details_spvisor.php?compid=".$_REQUEST['compid']);
?>
Return current item: MyZCI