Preview: product-addf.php
Size: 28.54 KB
/home/godevadmin/public_html/admin/product-addf.php
<?php
include("../include/config.php");
include("../include/functions.php");
include("../include/simpleimage.php");
validate_admin();
$cat_id=mysqli_real_escape_string($GLOBALS['conn'],$_POST['cat_id']);
$catAr=getCategoryArray($cat_id,$array='');
if(count($catAr)>0){
$categories=implode(",",$catAr);
}
$brand_id=mysqli_real_escape_string($GLOBALS['conn'],$_POST['brand_id']);
$product_name=mysqli_real_escape_string($GLOBALS['conn'],$_POST['product_name']);
$product_code=mysqli_real_escape_string($GLOBALS['conn'],$_POST['product_code']);
$description=mysqli_real_escape_string($GLOBALS['conn'],$_POST['description']);
$ingredients=mysqli_real_escape_string($GLOBALS['conn'],$_POST['ingredients']);
$how_to_use=mysqli_real_escape_string($GLOBALS['conn'],$_POST['how_to_use']);
$nutritional_facts=mysqli_real_escape_string($GLOBALS['conn'],$_POST['nutritional_facts']);
$meta_title=mysqli_real_escape_string($GLOBALS['conn'],$_POST['meta_title']);
$meta_keywords=mysqli_real_escape_string($GLOBALS['conn'],$_POST['meta_keywords']);
$meta_description=mysqli_real_escape_string($GLOBALS['conn'],$_POST['meta_description']);
#################################################### Product Price ######################################
$product_id=ucfirst(mysqli_real_escape_string($GLOBALS['conn'],$_POST['product_id']));
$size=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['size']);
$sizetype=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['sizetype']);
$tax=mysqli_real_escape_string($GLOBALS['conn'],$_POST['tax']);
$tax_method=mysqli_real_escape_string($GLOBALS['conn'],$_POST['tax_method']);
$actual_price=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['actual_price']);
$mrp_price=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['mrp_price']);
$discount=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['discount']);
$sell_price=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['sell_price']);
$minimum_quantity=mysqli_real_escape_string($GLOBALS['conn'],$_POST['minimum_quantity']);
$wholesale_discount=mysqli_real_escape_string($GLOBALS['conn'],$_POST['wholesale_discount']);
$in_stock=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['in_stock']);
$video=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['video']);
$barcode_number=mysqli_real_escape_string($GLOBALS['conn'],$_REQUEST['barcode_number']);
if($sizetype=='KG'){
$weight= $size*2.20462;
}elseif($sizetype=='LTR'){
$weight= $size*2.204;
}elseif($sizetype=='OZ'){
$weight= $size*0.0625;
}elseif($sizetype=='GM'){
$weight= $size*0.00220462;
}elseif($sizetype=='ML'){
$weight= $size*.00220462;
}elseif($sizetype=='GAL'){
$weight= $size*8.35;
}elseif($sizetype=='FLOZ'){
$weight= $size*0.0625;
}elseif($sizetype=='LBS'){
$weight= $size*1;
}else{
$weight='';}
if($tax_method=='Amount'){
$tax_value=$tax;
}
if($tax_method=='Low Tax'){
$tax_value=($mrp_price*2.25)/100;
}
if($tax_method=='High Tax'){
$tax_value=($mrp_price*10.25)/100;
}
if($tax_method=='City of Chicago/Soda Tax'){
$tax_value=((($mrp_price*10.25/100)+$mrp_price)*3/100)+($mrp_price*10.25/100);
}
#################################################### Product Price End ######################################
if($_REQUEST['submitForm']=='yes'){
if($_FILES['photo']['size']>0 && $_FILES['photo']['error']==''){
$product_img_name = buildURL($product_name);
$Image= new SimpleImage();
$filename = $_FILES['photo']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$img=time()."-".$product_img_name.".".$ext;
move_uploaded_file($_FILES['photo']['tmp_name'],"../upload_images/product/".$img);
copy("../upload_images/product/".$img,"../upload_images/product/thumb/".$img);
copy("../upload_images/product/".$img,"../upload_images/product/tiny/".$img);
$Image->load("../upload_images/product/thumb/".$img);
$Image->resize(180,180);
$Image->save("../upload_images/product/thumb/".$img);
$Image->load("../upload_images/product/tiny/".$img);
$Image->resize(300,300);
$Image->save("../upload_images/product/tiny/".$img);
CompressImage('../upload_images/product/'.$img, '../upload_images/product/'.$img, 40);
CompressImage('../upload_images/product/thumb/'.$img, '../upload_images/product/thumb/'.$img, 40);
CompressImage('../upload_images/product/tiny/'.$img, '../upload_images/product/tiny/'.$img, 40);
}
$obj->query("insert into $tbl_product set cat_id='$cat_id',categories='$categories',brand_id='$brand_id',product_name='$product_name',product_code='$product_code',photo='$img',description='$description', meta_title='$meta_title',meta_keywords='$meta_keywords',meta_description='$meta_description',posted_date=now(),posted_by='".$_SESSION['sess_admin_id']."',status=1 ");
$product_id=mysqli_insert_id($GLOBALS['conn']);
$sql="insert into $tbl_productprice set product_id='$product_id',sizes='$size',size='$size',size_type='$sizetype',weight='$weight',actual_price='$actual_price',mrp_price='$mrp_price',discount='$discount',sell_price='$sell_price',wholesale_min='$minimum_quantity',wholesale_discount='$wholesale_discount',in_stock='$in_stock',barcode_number='$barcode_number',pphoto='$img',status=1";
$obj->query($sql);
if(count($_REQUEST['att'])>0){
foreach($_REQUEST['att'] as $key=>$val){
if(is_array($val)){
$val=implode(",",$val);
}
if($val!=''){
$obj->query("insert into $tbl_features set product_id='$product_id',attribute_id='$key',feature_value='".mysqli_real_escape_string($GLOBALS['conn'],$val)."' ");
}
}
}
$_SESSION['sess_msg']='Product added sucessfully';
header("location:product-list.php");
exit();
}
if($_REQUEST['id']!=''){
$sql=$obj->query("select * from $tbl_product where id=".$_REQUEST['id']);
$result=$obj->fetchNextObject($sql);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SITE_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function validate(obj)
{
if(obj.category.value==''){
alert("Please enter category");
obj.category.focus();
return false;
}
if(obj.product_name.value==''){
alert("Please enter product name");
obj.product_name.focus();
return false;
}
if(obj.mrp_price.value=='' || obj.mrp_price.value==0){
alert("Please enter mrp price");
obj.mrp_price.focus();
return false;
}
if(obj.sell_price.value=='' || obj.sell_price.value==0){
alert("Please enter sell price");
obj.sell_price.focus();
return false;
}
}
</script>
<script type="text/javascript" src="../include/ckeditor/ckeditor.js"></script>
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<?php include("header.php");?>
<script>
$(function() {
$('#tax').hide();
$('#wholesale').hide();
$('#tax_method').change(function(){
if($('#tax_method').val() == 'Amount') {
$('#tax').show();
} else {
$('#tax').hide();
}
});
});
</script>
<script type="text/javascript">
function calcPrice(){
var mrp_price=document.getElementById('mrp_price').value;
var dis=document.getElementById('discount').value;
if(mrp_price!='' && dis!='' ){
document.getElementById('sell_price').value=mrp_price-(mrp_price*dis/100);
}
}
</script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#category').autocomplete({
search: function () {},
source: function (request, response)
{
$.ajax(
{
url:"getCategoryTree.php" ,
dataType: "json",
data:
{
q: request.term,
},
success: function (data)
{
response(data);
}
});
},
minLength: 2,
select: function( event, ui ) {
$( "#category" ).val( ui.item.value );
$( "#hdnId" ).val( ui.item.key );
var cat_id=$( "#hdnId" ).val();
//alert(cat_id);
$.ajax({
url:"getBrand.php",
data:{cat_id:cat_id},
beforeSend:function(){
$("#brand_id").html('<option value="">Select Brand</option>');
},
success:function(data){
$("#brand_id").append(data);
}
})
$.ajax({
url:"getAttribute.php",
data:{cat_id:cat_id},
beforeSend:function(){
$("#features").html('');
},
success:function(data){
$("#features").html(data);
}
})
return false;
}
});
})
</script>
<script type="text/javascript">
$(document).ready(function(){
$('#size').autocomplete({
search: function () {},
source: function (request, response)
{
$.ajax(
{
url:"sizesSource.php" ,
dataType: "json",
data:
{
q: request.term,
},
success: function (data)
{
response(data);
}
});
},
minLength:1,
select: function( event, ui ) {
$( "#size" ).val( ui.item.value );
return false;
}
});
})
</script>
<!--<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
$("#size").autocomplete("sizesSource.php", {
//selectFirst: true
});
});
</script> -->
<tr>
<td align="right" class="paddRtLt70" valign="top">
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="middle" class="headingbg bodr text14">
<em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Add Product
<span style="float:right; padding-right:10px;">
<input type="button" name="add" value="View Products" class="button" onclick="location.href='product-list.php'" /></span></td>
</tr>
<tr>
<td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr">
<form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)">
<input type="hidden" name="submitForm" value="yes" />
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center" colspan="2" class="paddRt14 paddBot11">
<font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><h2>Product Details</h2></td>
<td align="left" class="paddBot11"> </td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Category :</strong></td>
<td align="left" class="paddBot11">
<input type="text" name="category" id="category" style="width:500px;" value="<?php echo getCategoryTree($_REQUEST['cat_id'],$array='');?>" />
<input type="hidden" name="cat_id" id="hdnId" value="<?php echo $_REQUEST['cat_id'];?>" />
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Brand :</strong></td>
<td align="left" class="paddBot11"><select name="brand_id" id="brand_id" style="width:250px;" >
<option value="">Select Brand</option>
<?php $cat_id=getMainParent($_REQUEST['cat_id']);
$brandArr=$obj->query("select * from $tbl_brand where status=1 and bcat_id='".$cat_id."' order by brand ",$debug=-1);
while($resultBrand=$obj->fetchNextObject($brandArr)){
?>
<option value="<?php echo $resultBrand->id; ?>"<?php if($resultBrand->id==$result->brand_id){?>selected<?php } ?>><?php echo stripslashes($resultBrand->brand); ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Product Code:</strong></td>
<td align="left" class="paddBot11"><input name="product_code" type="text" id="product_code" size="36" value="<?php echo stripslashes($result->product_code);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Product Name:</strong></td>
<td align="left" class="paddBot11"><input name="product_name" type="text" id="product_name" size="36" value="<?php echo stripslashes($result->product_name);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Image<br/>
(300 X 300px)(Not more than 100 KB):</strong></td>
<td align="left" class="paddBot11"><input name="photo" type="file" /><br/>
<?php if(is_file("../upload_images/product/thumb/".$result->photo)) {?>
<img src="../upload_images/product/thumb/<?php echo $result->photo; ?>" />
<?php } ?>
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Size :</strong></td>
<td align="left" class="paddBot11"><input name="size" type="text" id="size" size="36" value="<?php echo stripslashes($result->size);?>" /> Enter digits only</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Size Type :</strong></td>
<td align="left" class="paddBot11"> <select name="sizetype" style="width:245px;" required >
<?php if($_REQUEST['id']!=''){?> <option value="<?php echo $result->size_type; ?>" selected="selected"><?php echo $result->size_type; ?></option><?php } else { ?>
<option value="" selected="selected">Select Size</option>
<?php } $sqlsize=$obj->query("select * from tbl_psizes where status=1 order by psize asc");
while($resultsize=$obj->fetchNextObject($sqlsize)){ ?>
<option value="<?php echo $resultsize->psize; ?>"><?php echo $resultsize->psize; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Actual Price:</strong></td>
<td align="left" class="paddBot11"><input name="actual_price" type="text" id="actual_price" size="20" value="<?php echo stripslashes($result->actual_price);?>" /> <strong><?php echo $website_currency_code; ?></strong></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>MRP Price:</strong></td>
<td align="left" class="paddBot11"><input name="mrp_price" type="text" id="mrp_price" size="20" value="<?php echo stripslashes($result->mrp_price);?>" onkeyup="return calcPrice()"/> <strong><?php echo $website_currency_code; ?></strong></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Discount:</strong></td>
<td align="left" class="paddBot11"><input name="discount" type="text" id="discount" size="20" value="<?php echo stripslashes($result->discount);?>" onkeyup="return calcPrice()" /> <strong> %</strong></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Tax:</strong></td>
<td align="left" class="paddBot11"><select name="tax_method" id="tax_method" style="width:148px;" required >
<option value="">Select one</option>
<option value="Low Tax">Low Tax</option>
<option value="High Tax">High Tax</option>
<option value="City of Chicago/Soda Tax">City of Chicago/Soda Tax</option> <option value="Amount">Amount</option> </select>
<span id="tax"> <input name="tax" type="text" size="20" value="<?php echo stripslashes($result->tax);?>" /> <strong> <?php echo $website_currency_code; ?></strong></span></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Sell Price (After Discount) :</strong></td>
<td align="left" class="paddBot11"><input name="sell_price" type="text" id="sell_price" size="20" value="<?php echo stripslashes($result->sell_price);?>" />
<strong> <?php echo $website_currency_code; ?></strong></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Wholesale Minimum Quantity :</strong></td>
<td align="left" class="paddBot11"><input name="minimum_quantity" type="text" id="sell_price" size="20" value="<?php echo stripslashes($result->wholesale_min);?>" required />
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Wholesale Discount :</strong></td>
<td align="left" class="paddBot11"><input name="wholesale_discount" type="text" id="sell_price" size="20" value="<?php echo stripslashes($result->wholesale_discount);?>" required />
<strong> per pcs/unit etc.</strong></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>IN Stock:</strong></td>
<td align="left" class="paddBot11">
<input type="checkbox" name="in_stock" value="1" <?php if($result->in_stock==1 || $_REQUEST['id']==''){ ?>checked<?php } ?> />
</td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Barcode Number:</strong></td>
<td align="left" class="paddBot11"><input name="barcode_number" type="text" id="barcode_number" size="36" value="<?php echo stripslashes($result->barcode_number);?>" /></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Video(YouTube URL):</strong></td>
<td align="left" class="paddBot11">
<textarea name="video" rows="5" cols="40" id="video"><?php echo $result->video; ?></textarea> </td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong> Details:</strong></td>
<td align="left" class="paddBot11"><textarea name="description" class="ckeditor" id="description" rows="5" cols="40"><?php echo stripslashes($result->description); ?></textarea></td>
</tr>
<tr><td colspan="2" id="features">
<?php ###################################### Features ##################################################
$fArray='';
if($cat_id!=''){
$groupArr=$obj->query("select attribute_ids from $tbl_maincategory join $tbl_attributegroup on $tbl_attributegroup.id=$tbl_maincategory.group_id where $tbl_maincategory.id='".$cat_id."' ");
if($obj->numRows($groupArr)>0){
$rsGroup=$obj->fetchNextObject($groupArr);
if($rsGroup->attribute_ids!=''){
$AttrbueArr=$obj->query("select * from $tbl_attribute where id in($rsGroup->attribute_ids) ");
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php while($resultAttribute=$obj->fetchNextObject($AttrbueArr)){ ?>
<tr>
<td width="25%" align="right" class="paddBot11 paddRt14"><strong> <?php echo stripslashes($resultAttribute->attribute); ?>:</strong></td>
<td width="75%" align="left" class="paddBot11">
<?php if($resultAttribute->attribute_type=='Dropdown'){?>
<select name="att[<?php echo stripslashes($resultAttribute->id); ?>]" style="width:240px;">
<option value="">-Select-</option>
<?php $AttrbuteValueArr=$obj->query("select * from $tbl_attributevalue where attribute_id='".$resultAttribute->id."' ");
while($resultVal=$obj->fetchNextObject($AttrbuteValueArr)){?>
<option value="<?php echo stripslashes($resultVal->attributevalue);?>" <?php if($fArray[$resultAttribute->id]==$resultVal->attributevalue){ ?>selected<?php } ?>><?php echo stripslashes($resultVal->display_value);?></option>
<?php } ?>
</select>
<?php } ?>
<?php if($resultAttribute->attribute_type=='MultipleSelect'){
$mutiArr='';
$mutiArr=explode(",",$fArray[$resultAttribute->id]);
// print_r($mutiArr);
?>
<select name="att[<?php echo stripslashes($resultAttribute->id); ?>][]" multiple style="width:240px;">
<option value="">-Select-</option>
<?php $AttrbuteValueArr=$obj->query("select * from $tbl_attributevalue where attribute_id='".$resultAttribute->id."' ");
while($resultVal=$obj->fetchNextObject($AttrbuteValueArr)){?>
<option value="<?php echo stripslashes($resultVal->attributevalue);?>" <?php if($mutiArr!='' && in_array($resultVal->attributevalue,$mutiArr)){ ?>selected<?php } ?> ><?php echo stripslashes($resultVal->display_value);?></option>
<?php } ?>
</select>
<?php } ?>
<?php if($resultAttribute->attribute_type=='Yes/No'){?>
<input type="radio" name="att[<?php echo stripslashes($resultAttribute->id); ?>]" <?php if($fArray[$resultAttribute->id]=='Yes'){ ?>checked<?php } ?> value="Yes" />
<input type="radio" name="att[<?php echo stripslashes($resultAttribute->id); ?>]" <?php if($fArray[$resultAttribute->id]=='No'){ ?>checked<?php } ?> value="No" />
<?php } ?>
<?php if($resultAttribute->attribute_type=='Textbox'){?>
<input type="text" name="att[<?php echo stripslashes($resultAttribute->id); ?>]" value="<?php echo $fArray[$resultAttribute->id]; ?>" />
<?php } ?>
<?php if($resultAttribute->attribute_type=='Date'){?>
<link rel="stylesheet" href="calender/css/jquery-ui.css">
<script src="calender/js/jquery-1.9.1.js"></script>
<script src="calender/js/jquery-ui.js"></script>
<script>
$(function() {
$( "#feature_date" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange:'2013:<?php echo date('Y') ?>'
});
});
</script>
<input type="text" name="att[<?php echo stripslashes($resultAttribute->id); ?>]" id="feature_date" value="<?php echo $fArray[$resultAttribute->id]; ?>" />
<?php } ?>
<?php if($resultAttribute->attribute_type=='TextArea'){?>
<textarea name="att[<?php echo stripslashes($resultAttribute->id); ?>]" rows="5" cols="40"><?php echo $fArray[$resultAttribute->id]; ?></textarea>
<?php } ?>
</td>
</tr>
<?php } ?>
</table>
<?php } } ?>
</td></tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><h2>Meta Tags</h2></td>
<td align="left" class="paddBot11"> </td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Meta Title:</strong></td>
<td align="left" class="paddBot11"><textarea name="meta_title" rows="5" cols="40"><?php echo stripslashes($result->meta_title); ?></textarea></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Meta Keywords:</strong></td>
<td align="left" class="paddBot11"><textarea name="meta_keywords" rows="5" cols="40"><?php echo stripslashes($result->meta_keywords); ?></textarea></td>
</tr>
<tr>
<td align="right" class="paddBot11 paddRt14"><strong>Meta Description:</strong></td>
<td align="left" class="paddBot11"><textarea name="meta_description" rows="5" cols="40"><?php echo stripslashes($result->meta_description); ?></textarea></td>
</tr>
<tr>
<td align="right" class="paddRt14 paddBot11"> </td>
<td align="left" class="paddBot11"> </td>
</tr>
<tr>
<td width="25%" align="right" class="paddRt14 paddBot11"> </td>
<td width="75%" align="left" class="paddBot11">
<input type="submit" name="submit" value="Submit" class="submit" border="0"/>
<input name="Reset" type="reset" id="Reset" value="Reset" class="submit" border="0" /> </td>
</tr>
</table></form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<?php include('footer.php'); ?>
</table>
</body>
</html>
Directory Contents
Dirs: 10 × Files: 414