<?php
  include "../include/dbcon.php";
  include "../include/CPRODUCT.php";
?>
<?php
//  print_r($_POST);
//  print_r($_FILES);
?>
<?php
  $pid = $_POST["pid"];
  $pename = $_POST["ename"];
  $pcname = $_POST["cname"];
  $pprice = $_POST["price"];
  $pstock = $_POST["stock"];
  $psubmit = $_POST["submit"];

  if($psubmit == "SAVE"){
  
  $myprod = new PRODUCT();
  $myprod->setProduct("id",$pid);
  $myprod->name = $pcname;
  $myprod->ename = $pename;
  $myprod->price = $pprice;
  $myprod->stock = $pstock;
  
?>
<?php
  if($_FILES["myphoto"]!=""){

    $newphoto = time() . ".jpg";

    $file = "../img/" . $newphoto;

    if(move_uploaded_file($_FILES['myphoto']['tmp_name'], $file)) {
	  $myprod->photo = $newphoto;
    }

  }
?>
<?php
//  print_r($myprod);
  $myprod->updateProduct();
?>
<?php
  $_SESSION["infomsg"] = "#INFO:<br>UPDATE SUCCESS";
  header("location: main.php?pg=pdt");
?>
<?php
  }elseif($psubmit == "PASSIVE"){
    $myprod = new PRODUCT();
    $myprod->setProduct("id",$pid);
	$myprod->pstatus = 0;
	$myprod->updateProduct();
	
	$_SESSION["infomsg"] = "#INFO:<br>".$myprod->name." UPDATED";
    header("location: main.php?pg=pdt");
  }elseif($psubmit == "ACTIVE"){
    $myprod = new PRODUCT();
    $myprod->setProduct("id",$pid);
	$myprod->pstatus = 1;
	$myprod->updateProduct();
	
	$_SESSION["infomsg"] = "#INFO:<br>".$myprod->name." UPDATED";
    header("location: main.php?pg=pdt");
  }elseif($psubmit == "DELETE"){
	header("location: main.php?pg=pdtd&pid=".$pid);
  }
?>