<?php

/* FIRESHOP: Advanced Content Market System                         */

/* ============================================                         */

/*                                                                      */

/* Copyright (c) 2012 by Mohamad Porhaji                                */

/* http://Firedesign.ir                                                   */

/*                                                                      */

/* This program is free software.  */

/************************************************************************/

/* $Id: product.php,v 1.0.0.1 2012/02/18 By Mohamad Porhaji $ */

if (stristr(htmlentities($_SERVER["PHP_SELF"]), "product.php")) {
    Header("Location: index.php");
    die();
}



if(isset($_POST['edit_product'])){
$id=$_POST['id'];
$query = $db->sql_query("SELECT * FROM fireshop_product WHERE `id`='$id'");
$row = $db->sql_fetchrow($query);
$product_title = $row['product_title'];
$product_des = $row['product_des'];
$product_pic = $row['product_pic'];
$id= $row['id'];
$product_price = $row['product_price'];
$is_active = $row['is_active'];
$is_vip = $row['is_vip'];

echo"


<div style='padding:10px'  align='center' >
<form action='admin.php?do=product' method='post'>
<table width='100%' dir='rtl' cellpadding='0' cellspacing='0'>
<tr>

<td>
عنوان كالا *:  <input type='text' size='30' name='title' value='$product_title'/><br/><br/>
توضيحات *:  <br/><br/>";

wysiwyg_textarea('des', "$product_des", 'FireShopAdmin', 50, 15);


echo"<br/><br/>

لينك تصوير *:  <input type='text' name='image' size='40' value='$product_pic'/>  سايز استاندارد تصوير : 173x101 <a onclick=\"window.open('upload.php','upload','status=yes,scrollbars=yes,toolbar=no,menubar=no,location=no ,width=380px,height=250px');\">[ آپلود تصوير ]</a><br/><br/>

قيمت *:  <input type='text' name='price' size='30' value='$product_price'/> به تومان <br/><br/>
دسته بندي *:  <select name='cat'>";

$query = $db->sql_query("SELECT * FROM fireshop_category Where `is_a_cat`='0' ORDER BY `id` ASC");
while ($row = $db->sql_fetchrow($query)) {
$title = $row['title'];
$id_par= $row['id'];
echo"<option value='$id_par'>$title</option>";}

echo"</select><br/><br/>
وضعيت *:  <select name='is_active'><option value='1'>فعال</option>
<option value='0'>غير فعال</option>
</select><br/><br/>

محصول ويژه : (براي نمايش در صفحه اصلي)  بله :  <input type='radio' name='is_vip' value='1'/>
خير : <input type='radio' name='is_vip' value='0'  checked='checked'/>

</td>
</tr>
</table>
<div align='left' style='margin-left:20px;'>
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='edit_product_w' value='ويرايش'/>&nbsp;&nbsp;&nbsp;
<button onclick='javascript:history.go(-1)' class='button'>بازگشت</button></div></form></div></BODY>

";
}else{
echo"
<table dir=\"rtl\" style=\"width: 670px;border: 1px solid #C0C0C0\"><tr>
<td style=\"width: 28px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">آيدي</td>
<td style=\"width: 280px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">عنوان</td>
<td style=\"width: 80px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">قيمت</td>
<td style=\"width: 25px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">ويژه</td>
<td style=\"width: 30px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">وضعيت</td>
<td style=\"width: 180px\">اختيارات</td></tr>";



$sql = $db->sql_query("SELECT * FROM fireshop_product ORDER BY `product_time_stamp`DESC");
while ($row = $db->sql_fetchrow($sql)) {
$product_title = $row['product_title'];
$id= $row['id'];
$product_price = $row['product_price'];
$product_price = number_format($product_price, 0);
$is_active = $row['is_active'];
$is_vip = $row['is_vip'];


if($is_vip>0){$is_vip="بله";}else{$is_vip="خير";}
if($is_active>0){$is_active="فعال";}else{$is_active="غير فعال";}
echo"<tr>
<td style=\"width: 28px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$id</td>
<td style=\"width: 280px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$product_title | <a href='product.php?id=$id'>لينك مستقيم</a></td>
<td style=\"width: 80px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$product_price  تومان </td>
<td style=\"width: 25px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$is_vip</td>
<td style=\"width: 30px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$is_active</td>


<td style=\"width: 226px;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">
<form style='float:right;' action=\"admin.php?do=del_product\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='del_product' value='حذف'/></form>
<form style='float:right;' action=\"admin.php?do=view_product\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='view_product' value='مشاهده'/></form>
<form style='float:right;' action=\"admin.php?do=product\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='edit_product' value='ويرايش'/></form><div class=\"clear\"></div>
</td></tr>";}echo"</table>";


}

if(isset($_POST['edit_product_w'])){
$id= $_POST['id'];
if(empty($_POST['title'])
or empty($_POST['des'])
or empty($_POST['image'])
or empty($_POST['price'])
){
echo"<br/>
پر كردن همه ي فيلد ها الزامي است<br/><br/><button onclick='javascript:history.go(-1)' class='button'>بازگشت</button>";
}else{
$id= $_POST['id'];
$title = $_POST['title'];
$is_active = $_POST['is_active'];
$des = $_POST['des'];
$image = $_POST['image'];
$price = $_POST['price'];
$cat = $_POST['cat'];
$is_vip = $_POST['is_vip'];

$query = $db->sql_query("UPDATE `fireshop_product` SET `product_title`='$title',`product_des`='$des'  ,`product_pic`='$image'  ,`product_cat`='$cat'  ,`product_price`='$price'  ,`is_vip`='$is_vip',`is_active`='$is_active' WHERE id='$id' LIMIT 1");
if($query){print('<div class="contact_active"> محصول با موفقيت ويرايش گرديد<br/></div>');
}else{print('<div class="failed"><div class="MsgBody">خطا<br/><button onclick="javascript:history.go(-1)" class="button">بازگشت</button></div></div>');}}}


?>