<?php
  include "../include/dbcon.php";
  include "../include/CPRODUCT.php";
?>
<?php
//  print_r($_POST);
//  print_r($_FILES);
  $pename = $_POST["ename"];
  $pcname = $_POST["cname"];
  $pprice = $_POST["price"];
  $pstock = $_POST["stock"];
?>
<?
  $myprod = new PRODUCT();
  $myprod->name = $pcname;
  $myprod->ename = $pename;
  $myprod->price = $pprice;
  $myprod->stock = $pstock;
  $myprod->pstatus = 1;
  $myprod->photo = "ico_image.png";
?>
<?php
  if($pename!="" && $pcname!=""){
  
	  if($_FILES["myphoto"]!=""){
	
		$newphoto = time() . ".jpg";
	
		$file = "../img/" . $newphoto;
	
		if(move_uploaded_file($_FILES['myphoto']['tmp_name'], $file)) {
		  $myprod->photo = $newphoto;
		}
	
	  }
	  
	  $myprod->saveProduct();
	  $_SESSION["infomsg"] = "#INFO:<br>PRODUCT ADDED";
  
  }else{
    $_SESSION["errmsg"] = "#ERROR:<br>FAIL SAVE";
  }
?>
<?php
  
  header("location: main.php?pg=pdt");
?>