<?php

/* FIRESHOP: Advanced Content Market System                         */

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

/*                                                                      */

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

/* http://Firedesign.ir                                                   */

/*                                                                      */

/* This program is free software.  */

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

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

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

if (!defined('ADMIN_FILE')) {
	die ("Access Denied");
}

if(isset($_POST['edit_a_cat'])){
$id=$_POST['id'];
$query = $db->sql_query("SELECT * FROM fireshop_category WHERE `id`='$id'");
$row = $db->sql_fetchrow($query);
$title = $row['title'];
$id= $row['id'];

echo"
<div dir='rtl' align='right' style='padding:10px;'>
<form action='admin.php?do=a_cat' method='post'><table><tr><td valign='top'>
عنوان : <br/><br/><br/>
فعال :</td><td  valign='top'><input type='text' size='30' name='title' value='$title' /><br/><br/>
بله : <input type='radio' name='is_active' value='1' checked='checked'/>
خير : <input type='radio' name='is_active' value='0' /><br/><br/>
<input  type='hidden' size='10' name='id'  value='$id'/>
<input type='submit' name='edit_a_cat_ok' value='ويرايش' />   
<input type='submit' onclick='javascript:history.go(-1)' value='بازگشت' /></td></tr></table></form></div>";


}else{
echo"<table dir=\"rtl\" style=\"width: 670px;border: 1px solid #C0C0C0\"><tr>
<td style=\"width: 48px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">آيدي</td>
<td style=\"width: 380px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">عنوان</td>
<td style=\"width: 100px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;\">وضعيت</td>
<td style=\"width: 206px\">اختيارات</td></tr>";
$query = $db->sql_query("SELECT * FROM fireshop_category Where `is_a_cat`='1' ORDER BY `id` ASC");
while ($row = $db->sql_fetchrow($query)) {
$title = $row['title'];
$id= $row['id'];
$is_active= $row['is_active'];
if($is_active==0){$is_active="غيرفعال";}else{$is_active="فعال";}

echo"<tr>
<td style=\"width: 48px; 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: 405px; border-left-style: solid; border-left-width: 1px; border-left-color: #C0C0C0;border-top-style: solid; border-top-width: 1px; border-top-color: #C0C0C0;\">$title</a></td>
<td style=\"width: 100px; 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_cat\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='del_cat' value='حذف'/></form>

<form style='float:right;' action=\"admin.php?do=a_cat\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='edit_a_cat' value='ويرايش'/></form><div class=\"clear\"></div>
</td></tr>";}echo"</table>";
}

if(isset($_POST['edit_a_cat_ok'])){
$id=$_POST['id'];

if(empty($_POST['title'])){echo"پر كردن همه ي فيلد ها الزامي است";}else{
$title = $_POST['title'];
$is_active = $_POST['is_active'];

$query = $db->sql_query("UPDATE `fireshop_category` SET `title`='$title',`is_active`='$is_active'   WHERE id='$id' LIMIT 1");
if($query){print('<div class="contact_active">دسته با موفقيت ايجاد گرديد</div>');}else{
print('<div class="failed"><div class="MsgBody">خطا</div></div>');}
}
}

?>