0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
admin
/
pages
/
[
Home
]
File: edit_product.php
<? include_once('FCKeditor/fckeditor.php'); if(isset($_SESSION['admin_login'])) { if($_POST['Submit']=="Update Product Details") { $content=stripslashes($_POST['content']); $q_update_content="update product_details set product_description='".$_POST['content']."', product_weight='".$_POST['weight']."', product_small_description='".$_POST['small_description']."' where product_id='".$_POST['product_id']."'"; $r_update_content=mysql_query($q_update_content); if(!$r_update_content) { echo mysql_error(); } } if($_POST['Submit']=="Update Price") { //$content=stripslashes($_POST['content']); $q_update_price="update product_details set product_price='".str_replace(",","",number_format($_POST['product_price'],2))."' where product_id='".$_POST['product_id']."'"; $r_update_price=mysql_query($q_update_price); if(!$r_update_price) { echo mysql_error(); } } if($_POST['Submit']=="Delete Current Image") { $q_delete_image="update product_details set product_main_image_path='' where product_id='".$_POST['product_id']."'"; $r_delete_image=mysql_query($q_delete_image); if(!$r_delete_image) { echo mysql_error(); } } if($_POST['Submit']=="Update Image") { if(!empty($_FILES["uploaded_file"])) { $filename2 = basename($_FILES['uploaded_file']['name']); $ext2 = strtolower(substr($filename2, strrpos($filename2, '.') + 1)); } if($_POST['image_name'] && !empty($_FILES["uploaded_file"])) { $image_name=stripslashes($_POST['image_name']).".".$ext2; } else if($_POST['image_name']=="" && !empty($_FILES["uploaded_file"])) { $image_name=$filename2; } else { $image_name="no_image.jpg"; } $image_path="catalog_images/".str_replace(" ","_",$_POST['catalog_name'])."/".$image_name; $q_update_content="update product_details set product_main_image_path ='".$image_path."' where product_id='".$_POST['product_id']."'"; $r_update_content=mysql_query($q_update_content); if(!$r_update_content) { echo mysql_error(); } //image uploading if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb $filename = basename($_FILES['uploaded_file']['name']); $ext = strtolower(substr($filename, strrpos($filename, '.') + 1)); if ((($ext == "jpg") || ($ext == "gif") || ($ext == "JPG") || ($ext == "jpeg") || ($ext == "bmp") || ($ext == "pjpeg")) && ($_FILES["uploaded_file"]["size"] < 350000)) { //$newname = '../catimages/'.$cathead.'/'.$picnm; $newname="../catalog_images/".str_replace(" ","_",$_POST['catalog_name'])."/".$image_name; //Check if the file with the same name is already exists on the server if (!file_exists($image_name)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newname))) { chmod($newname, 0777); echo "It's done! The file has been saved as: ".$newname; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: Only .jpg images under 350Kb are accepted for upload"; } } else { echo "Error: No file uploaded"; } //End of image uploading } $table_exist = 0; $sql = "show TABLES FROM $dbname"; $result = mysql_query($sql); if(!$resilt) { echo mysql_error(); } while ($row=@mysql_fetch_array($result)) { if($row[0] == 'catalog') { $table_exist = 1; } } if($_GET['action']=="del") { $q_image_path="select * from product_details where product_id='".$_GET['product_id']."'"; $r_image_path=mysql_query($q_image_path); $row_image_path=mysql_fetch_array($r_image_path); $del_image_path="../".$row_image_path['product_main_image_path']; $q_del_product="delete from product_details where product_id='".$_GET['product_id']."'"; $r_del_product=mysql_query($q_del_product); unlink($del_image_path); } $q_product="select * from product_details where catalog_id='".$_GET['catalog_id']."'"; $r_product=mysql_query($q_product); if($table_exist == 1) { $q_catalog_list="select * from `catalog` where catalog_id='".$_GET['catalog_id']."'"; $r_catalog_list=mysql_query($q_catalog_list); $row_catalog_list=mysql_fetch_array($r_catalog_list); } ?> <link href="../css/admin-style.css" rel="stylesheet" type="text/css"> <? if($_GET['action']=="edit") { $q_product_edit="select * from product_details where product_id='".$_GET['product_id']."'"; $r_product_edit=mysql_query($q_product_edit); $row_product_edit=mysql_fetch_array($r_product_edit); $image_path=explode("/",$row_product_edit['product_main_image_path']); $image_ext=explode(".",$image_path[2]); $image_name=$image_ext[0]; //echo $imagepath[2]; ?> <table width="900" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top" style="padding-left:20px"><form action="" method="post" enctype="multipart/form-data" name="form1"> <table width="880" border="0" cellpadding="4" cellspacing="0" class="table-all-thin-border"> <tr> <td height="32" align="left" valign="middle" class="create-catalog-header">Edit Product Attributes</td> </tr> <tr> <td width="390" align="left" valign="middle" class="create-catalog-text"><table width="700" border="0" cellspacing="0" cellpadding="3"> <tr> <td width="137" height="30" align="left" valign="middle">Select Catalog</td> <td width="500" class="left-links"> <?=$row_catalog_list['catalog_name']?> <input name="product_id" type="hidden" id="product_id" value="<?=$row_product_edit['product_id']?>"> <input name="catalog_name" type="hidden" id="catalog_name" value="<?=$row_catalog_list['catalog_name']?>"> </td> </tr> <tr> <td height="30" align="left" valign="middle">Product Name</td> <td><input name="product_name" type="text" id="product_name" value="<?=$row_product_edit['product_name']?>" readonly> <span class="left-links"><font color="#990000">**product name cann't be changed</font></span></td> </tr> <? if($image_name!="") { ?> <tr> <td height="30" align="left" valign="top">Current Image</td> <td class="left-links"> <img src="../<?=$row_product_edit['product_main_image_path']?>" width="125" height="80"> <font color="#990000"> <input name="Submit" type="submit" id="Submit" value="Delete Current Image"> </font> </td> </tr> <? } else { ?> <tr> <td height="30" align="left" valign="middle" bgcolor="#E1FFF3">Image Name</td> <td bgcolor="#E1FFF3" class="left-links"> <input name="image_name" type="text" id="image_name" value="<?=$image_name?>"> <font color="#990000"> Currently No main Image Uploaded</font> (*optional) </td> </tr> <tr> <td height="30" align="left" valign="middle" bgcolor="#E1FFF3">Browse Image</td> <td bgcolor="#E1FFF3"> <input name="uploaded_file" type="file" size="40"> <input name="Submit" type="submit" id="Submit" value="Update Image"></td> </tr> <tr> <? } ?> <td height="30" align="left" valign="middle">Product Price</td> <td><font color="#009900"><strong>$</strong></font> <input name="product_price" type="text" id="product_price" value="<?=$row_product_edit['product_price']?>" size="15"> <input name="Submit" type="submit" id="Submit" value="Update Price"> </td> </tr> <? $y_checked="Unchecked"; $n_checked="Unchecked"; if($row_product_edit['new_product']=="Y") { $y_checked="Checked"; } else { $n_checked="Checked"; } ?> <tr> <td height="30">New Product</td> <td><input name="new_product" type="radio" value="Yes" <?=$y_checked?>> Yes <input type="radio" name="new_product" value="No" <?=$n_checked?>> No </td> </tr> <tr> <td height="30" align="left" valign="top">Product Small Description</td> <td align="left" valign="top"><textarea name="small_description" cols="30" rows="3" id="small_description"><?=$row_product_edit['product_small_description']?></textarea></td> </tr> <tr> <td height="30" align="left" valign="top">Product Weight</td> <td align="left" valign="top"><input name="weight" type="text" id="weight" value="<?=$row_product_edit['product_weight']?>" size="6"> <font size="2">Unit</font> </td> </tr> </table></td> </tr> <tr> <td align="left" valign="middle" class="create-catalog-text"> </td> </tr> <tr> <td align="left" valign="middle" class="create-catalog-text"><table width="390" border="0" cellspacing="0" cellpadding="3"> <tr> <td height="32" align="left" valign="middle" class="create-catalog-header">Edit Product Description </td> </tr> </table></td> </tr> <tr> <td align="left" valign="middle" class="create-catalog-text"> <?php $sValue = stripslashes($row_product_edit['product_description']); $sBasePath=FCKPATH; $oFCKeditor = new FCKeditor('content') ; $oFCKeditor->BasePath = $sBasePath; $oFCKeditor->Width = '100%'; $oFCKeditor->Height = '500'; $oFCKeditor->Value = $sValue; $oFCKeditor->Create(); ?> </td> </tr> <tr> <td align="center" valign="middle" class="create-catalog-text"><input type="submit" name="Submit" value="Update Product Details"></td> </tr> </table> </form></td> </tr> </table> <? } ?> <table width="900" border="0" cellpadding="2" cellspacing="0" class="table-all-thin-border"> <tr align="center" valign="middle"> <td height="32" colspan="5" class="view-edit-header">VIEW / EDIT FOR <?=strtoupper($row_catalog_list['catalog_name'])?> CATALOG</td> </tr> <tr align="left" valign="middle"> <td width="125" height="32" class="create-catalog-header">Product Name</td> <td width="150" class="create-catalog-header">Product Image</td> <td class="create-catalog-header">Product Small Description</td> <td width="100" class="create-catalog-header">Product Price</td> <td width="100" align="center" class="create-catalog-header">Action</td> </tr> <? if(mysql_num_rows($r_product)>0) { $n=0; while($row_product=mysql_fetch_array($r_product)) { if($n%2==0) { $bgcol='#E6F4FF'; } else { $bgcol='#EFFEED'; } ?> <tr align="left" valign="top" class="left-links"> <td bgcolor="<?=$bgcol?>" style="padding-left:10px"> <?=$row_product['product_name']?> </td> <td bgcolor="<?=$bgcol?>"><img src="../<?=$row_product['product_main_image_path']?>" width="125" height="80"></td> <td bgcolor="<?=$bgcol?>"> <?=$row_product['product_small_description']?> </td> <td bgcolor="<?=$bgcol?>"> <?=$row_product['product_price']?> </td> <td align="center" bgcolor="<?=$bgcol?>"><a href="index.php?page=edit_product&&catalog_id=<?=$_GET['catalog_id']?>&&action=edit&&product_id=<?=$row_product['product_id']?>"><img src="admin_images/icon_edit.gif" width="18" height="18" border="0"></a> <a href="index.php?page=edit_product&&catalog_id=<?=$_GET['catalog_id']?>&&action=del&&product_id=<?=$row_product['product_id']?>"><img src="admin_images/icon_delete.gif" width="15" height="16" border="0"></a></td> </tr> <? $n++; } } else { ?> <td height="25" colspan="5" align="center" valign="middle" class="left-links"><font color="#FF0000">No Product inserted inside this catalog</font></td> <? } ?> </table> <? } ?>