<?php
session_start();
if(!isset($_SESSION['user'])) {
	header("location: ../index.php");
	exit;
}

include('../dbconnect.php');

if($_POST['act'] == 'item_on'){
	$mode = $_POST['mode'];
	$itemid = $_POST['itemid'];
	if($mode == true){
		echo "update web_items set item_is_active = '1' where item_id = '$itemid'";
		mysql_query("update web_items set item_is_active = '1' where item_id = '$itemid'");
	}
}
// Add Category
if(isset($_POST['cat_submit'])){
	$cat_name = $_POST['cat_name'];
	$cat_desc = $_POST['cat_desc'];
	$active = $_POST['is_active']; 
	
	//if(isset($_POST[''])){
	 $cat_img = $_FILES['cat_image']['name'];
	 /* $size = $_FILES['cat_image']['size'];
	 $type = $_FILES['cat_image']['type'];
	 $tmp = $_FILES['cat_image']['tmp_name'];
	 $store= "upload/".$name;
	move_uploaded_file($tmp, $store); */
	
	$sub_cat = $_POST['subcat']; 
	$cat_tag = $_POST['cat_tags']; 
	$order_by= $_POST['order_by']; 
	$item_update = $_POST['item_update']; 
	
			$result = mysql_query("insert into web_categories(category_name, category_description, category_is_active, category_image_url, category_tags, has_subcategory, order_by, is_item_updated) values ('$cat_name', '$cat_desc', '$active', '$cat_img ', '$sub_cat', '$cat_tag', '$order_by', '$item_update')"); 
}
		
// Add Item

if(isset($_POST['item_submit'])){
	$item_name = $_POST['item_name'];
	$item_desc = $_POST['item_desc'];
	$active_item = $_POST['is_active-item']; 
	
	//if(isset($_POST[''])){
	 $item_img = $_FILES['item_image']['name'];
	 /* $size = $_FILES['cat_image']['size'];
	 $type = $_FILES['cat_image']['type'];
	 $tmp = $_FILES['cat_image']['tmp_name'];
	 $store= "upload/".$name;
	move_uploaded_file($tmp, $store); */
	
	$item_tag = $_POST['item_tags']; 
	$update = $_POST['update_item']; 
	
	/* echo "insert into web_items(item_name, 	item_long_description, item_is_active, item_image_url, item_tags, is_item_updated) values ('$item_name', '$item_desc', '$active_item', '$item_img ', '$item_tag',  '$update')"; */
	
	 $result = mysql_query("insert into web_items(item_name, 	item_long_description, item_is_active, item_image_url, item_tags, is_item_updated) values ('$item_name', '$item_desc', '$active_item', '$item_img ', '$item_tag',  '$update')"); 
	 
	
}

if(isset($_POST['update'])){
	 $itemid = $_POST['id_item'];
	$item_name = $_POST['name_of_item'];
	//$active_item_update = $_POST['outlet'];
	$item_price = $_POST['item_price'];	
	$item_description = $_POST['item_description'];
	$is_active_item = $_POST['is_active-item']; 
	
	//if(isset($_POST[''])){
	 $item_image = $_FILES['image_update']['name'];
	 /* $size = $_FILES['cat_image']['size'];
	 $type = $_FILES['cat_image']['type'];
	 $tmp = $_FILES['cat_image']['tmp_name'];
	 $store= "upload/".$name;
	move_uploaded_file($tmp, $store); */
	
	$update_item_tag = $_POST['upd_item_tags']; 
	$upd_item = $_POST['upd_item']; 
	
	/*  "update web_items set item_name = '$item_name', item_final_price = '$item_price', 	item_long_description = \"".$item_description."\", item_is_active = '$is_active_item', item_image_url = '$item_image', item_tags = '$update_item_tag', is_item_updated = '$upd_item'  where item_id = '$itemid'"; 
 */
	 
	 
	$update = mysql_query("update web_items set item_name = '$item_name', item_final_price = '$item_price', 	item_long_description = \"".$item_description."\", item_is_active = '$is_active_item', item_image_url = '$item_image', item_tags = '$update_item_tag', is_item_updated = '$upd_item'  where item_id = '$itemid'");
	if($update){ 
		echo "update successfully";
		header("location: item.php");
		unset($item_name, $item_price, $item_description, $is_active_item, $item_image, $update_item_tag, $update_order_by, $upd_item );
		
	}}
	//$active_item_update 
	if(isset($_POST['active'])){
		 $itemid = $_POST['itemid'];
		$outlet = $_POST['outlet']; 
		$radio = $_POST['inline-radios']; 
		
		$active_qry = mysql_query("update web_items set item_is_active = '$radio' where UnitId = '$outlet' and item_id = '$itemid'");
		if($active_qry){ 
			header("location: item.php");
			unset( $unitid, $outlet);
		}
			
		
	}

?>