<?php
require_once("lib/inc.php");
require_once("lib/security.php");
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title ="::: Edit Purchase :::";
$smarty->assign('title',$title);
// Date & Time to be dispalyed on the header
$date_time = date("h:i:s A")." ".date("d-m-Y");
$smarty->assign('date_time',$date_time);
// Done
$date = date("Y-m-d");
$status = $_SESSION['status'];
$user_id = $_SESSION['user_id'];
$smarty->assign('user_id',$user_id);
$row = $database->get_from_database("select * from asset_users where user_id='$user_id'");
$name = $row['full_name'];
$rw = $database->get_from_database("select * from asset_users where user_id='$_SESSION[user_id]'");
$last_login = $rw['last_login'];
$last_logout = $rw['last_logout'];
$smarty->assign('last_login',$last_login);
$smarty->assign('last_logout',$last_logout);
if($status < 4)
{
if(isset($_GET['act']))
{
if($_GET['act']=="edit")
{
$po_no = $_POST['po_no'];
$po_date = $_POST['date'];
$vendor_id = $_POST['vendor_id'];
$equipment_id = $_POST['equipment_id'];
$eq_pc = $_POST['eq_pc'];
// foreach($equipment_id as $n=>$v)
// {
// $eqpmnt_id.=$v.",";
// }
if(is_array($equipment_id))
{
$eqpmnt_id = implode(",",$equipment_id);
}
else
{
$eqpmnt_id = $equipment_id;
}
foreach($eq_pc as $n=>$v)
{
if($v!=0)
{
$eqpmnt_pc.=$v.",";
}
}
$smarty->assign('po_no',$po_no);
$smarty->assign('po_date',$po_date);
$smarty->assign('vendorid',$vendorid);
$smarty->assign('equipmentid',$equipmentid);
if($database->update("update asset_purchase_order set po_date='$po_date', vendor_id='$vendor_id', equipment_id='$eqpmnt_id', no_pcs='$eqpmnt_pc' where po_no='$po_no'"))
{
$database->update("update asset_assets set vendor_id='$vendor_id', equipment_id='$eqpmnt_id' where po_no='$po_no'");
redirect ("manage_purchase.php","Edit");
}
}
}
$res3 = $database->Execute("select * from asset_equipment");
while($row3 = mysql_fetch_array($res3))
{
$equipment_id[] = $row3['equipment_id'];
$equipment_name[] = $row3['equipment_name'];
$equipment_model[] = $row3['equipment_model'];
}
$no1 = $database->no_of_rows("select * from asset_equipment");
$smarty->assign("no1",$no1);
$smarty->assign("equipment_id",$equipment_id);
$smarty->assign("equipment_name",$equipment_name);
$smarty->assign("equipment_model",$equipment_model);
$res4 = $database->Execute("select * from asset_vendor");
while($row4 = mysql_fetch_array($res4))
{
$vendor_id[] = $row4['vendor_id'];
$vendor_name[] = $row4['vendor_name'];
}
$smarty->assign("no2",$no2);
$smarty->assign("vendor_id",$vendor_id);
$smarty->assign("vendor_name",$vendor_name);
if(isset($_GET['hd83___2y8dh328f____8hhdiw___jd9']))
{
$po_no = $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
$nor= $database->no_of_rows("select * from asset_assets where po_no='$po_no'");
$row = $database->get_from_database("select * from asset_purchase_order where po_no='$po_no'");
$po_date = $row['po_date'];
$vendorid = $row['vendor_id'];
$equipmentid = $row['equipment_id'];
$no_pcs = $row['no_pcs'];
$cate_id = $row['category_id'];
//echo "cat id=";echo $cate_id;
$eq = explode(",",$equipmentid);
$pcs = explode(",",$no_pcs);
array_pop($pcs);
// print_r($pcs);
$row_cate = $database->get_from_database("select * from asset_category where category_id='$cate_id'");
$cate_name =$row_cate['category_name'];
$cate_id =$row_cate['category_id'];
//echo "category name="; echo $cate_name;
$smarty->assign('po_no',$po_no);
$smarty->assign('po_date',$po_date);
$smarty->assign('vendorid',$vendorid);
$smarty->assign('equipmentid',$equipmentid);
$smarty->assign('category_name',$cate_name);
$smarty->assign('equip_arr',$eq);
$smarty->assign('pcs',$pcs);
$smarty->assign('nor',$nor);
}
$result_equip = $database->Execute("select * from asset_equipment where category_id='$cate_id'");
$equip_id=array();
$equip_name=array();
$equip_model=array();
while($row=mysql_fetch_array($result_equip))
{
array_push($equip_id,$row[0]);
array_push($equip_name,$row[2]);
array_push($equip_model,$row[3]);
}
$smarty->assign('equip_name',$equip_name);
$smarty->assign('equip_id',$equip_id);
$smarty->assign('equip_model',$equip_model);
$smarty->assign('eq_siz',sizeof($equip_id));
//print_r($equip_id);
}
else
{
$mes = "Sorry ! You have no such Privillage ...";
$smarty->assign('mes',$mes);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);
$smarty->assign('i',1);
$smarty->display('edit_purchase.tpl');
?>