<?php

/* FIRESHOP: Advanced Content Market System                         */

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

/*                                                                      */

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

/* http://Firedesign.ir                                                   */

/*                                                                      */

/* This program is free software.  */

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

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

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




if(isset($_POST['edit_news'])){$id=$_POST['id'];
$query = $db->sql_query("SELECT * FROM fireshop_news WHERE `id`='$id'");
$row = $db->sql_fetchrow($query);$date = $row['date'];$title = $row['title'];$des = $row['des'];$id= $row['id'];
echo" <div dir='rtl' align='right' style='padding:10px;'>
<a target='_blank' href='news.php?id=$id' title='$title'>لينك مستقيم خبر</a><br/>
$title | ارسال شده در تاريخ : $date<br/>$des <br/><br/></div>";echo"

<br/>


<div style='padding:10px'  align='center' >
<form action='admin.php?do=news' method='post'>
<table width='100%' dir='rtl' cellpadding='0' cellspacing='0'><tr><td>
عنوان : <input type='text' size='30' name='title_news' value='$title' /><br/>
متن خبر : 
<br/><br/>";
wysiwyg_textarea('des_news', "$des", 'FireShopAdmin', 50, 15);

echo"<br/></td>
</tr></table><div align='left' style='margin-left:20px;'>
<input  type='hidden' size='20' name='id'  value='$id'/>
<input  type='submit' name='edit_news_w' value='ويرايش خبر'/>&nbsp;&nbsp;&nbsp;
<button onclick='javascript:history.go(-1)' class='button'>بازگشت</button>
</div></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: 480px; 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_news ORDER BY `time_stamp` DESC");
while ($row = $db->sql_fetchrow($query)) {$date = $row['date'];$title = $row['title'];$des = $row['des'];$id= $row['id'];
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  | $date | <a href='news.php?id=$id'>لينك مستقيم خبر</a></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_news\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='del_news' value='حذف'/></form>
<form style='float:right;' action=\"admin.php?do=view_news\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='view_news' value='مشاهده'/></form>
<form style='float:right;' action=\"admin.php?do=news\" method=\"post\">
<input  type='hidden' size='10' name='id'  value='$id'/>
<input  type='submit' name='edit_news' value='ويرايش'/></form><div class=\"clear\"></div>
</td></tr>";}echo"</table>";}

if(isset($_POST['edit_news_w'])){if(empty($_POST['title_news'])or empty($_POST['des_news'])){echo"
پر كردن همه ي فيلد ها الزامي است<br/><button onclick='javascript:history.go(-1)' class='button'>بازگشت</button>";
}else{$title_news =$_POST['title_news'];$des_news =$_POST['des_news'];$id=$_POST['id'];
$query = $db->sql_query("UPDATE `fireshop_news` SET `title`='$title_news',`des`='$des_news'   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>');}}}


?>