<?
include "../zciconfig.php";
include "../engine/zciobject.php";
$masterconf = new masterconfig();
$master = new masterobject();
$master->authenticate();
if ($_POST['ownership']!=0) {
//make database connection
$mydbcon = $masterconf->dbconnect();
//make object for common function
$master = new masterobject();
$devtype=$_GET['type'];
if ($_POST['flag_newmodel']==2) {
$colnames[0]="name";$colvalues[0]="'".$_POST['device_name']."'";
$peripheral_id=$master->getid($mydbcon,$devtype."_category",$colnames,$colvalues);
}
else $peripheral_id=$_POST['phr_model'];
$phr_sn=strtoupper($_REQUEST['device_sn']);
$phr_inv=$_REQUEST['invn'];
// echo $_POST['device_name'].$phr_sn;
$result=dbx_query($mydbcon,"select itemid from ".$devtype." where modelid=".$peripheral_id." and serialnumber='".$phr_sn."'");
if ($result->rows==0) {
dbx_query($mydbcon,"insert into ".$devtype." (modelid,serialnumber,invn,registerdate) values (".$peripheral_id.",'".$phr_sn."','".$phr_inv."',now())");
$result=dbx_query($mydbcon,"select itemid from ".$devtype." where modelid=".$peripheral_id." and serialnumber='".$phr_sn."'");
}
else dbx_query($mydbcon,"update ".$devtype." set reserved=null where itemid=".$result->data[0][0]);
$master->singleupdate_phr($mydbcon,"ownership_".$devtype."",$_GET['compid'],$result->data[0][0],$_REQUEST['ownership']);
}
header("Location: computer_details_spvisor.php?compid=".$_REQUEST['compid']);
?>