<?
include("../includes/config.php");
$adminuser = @mysql_db_query("$dbName", "select *  from admin where  admin_id = '1'") ;
while  ($ab = mysql_fetch_array($adminuser)){
$adminu = $ab['admin_name'];
$adminp = $ab['admin_password'];
}
$loguser= $_COOKIE['adminuser'];
$logipass= $_COOKIE['adminpassword'];



if ( $adminp == $logipass  && $adminu == $loguser ){

?>
<html dir="rtl">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<meta http-equiv="Content-Language" content="ar-sa">
<meta name="GENERATOR" content="Traidnt.com">
<script type="text/javascript">
function del(confirmation_message)
{
	var ht = document.getElementsByTagName("html")[0];
	ht.style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm(confirmation_message))
	{
		return true;
	}
	else
	{
		ht.style.filter = "";
		return false;
	}
}
</script>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<script>
function TraidntPopUp(URLStr, left, top, width, height)
{
  window.open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
//	document.location=URLStr;
}
</script>
<title>لوحة تحكم الادارة</title>
</head>
<body leftmargin="0" rightmargin="0" bottommargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FCFAF7" text="#000000" >

<div align="left">
  <table border="0" cellpadding="0" cellspacing="0" width="100%" height="41">
    <tr>
      <td width="150%" bgcolor="#000000" height="1"></td>
    </tr>
    <tr >
      <td width="100%" align="left" valign="bottom" bgcolor="#FFFFFF" class="topheader"  >
        <p align="right"><a href="index.php">واجهة الادارة - </a>
		<a target="_blank" href="../index.php"><font color="#000000">&nbsp;واجهة
		الموقع</font></a></td>
    </tr>
  </table>
</div>

<div align="left">
  <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
      <td width="20%" valign="top">
        <? include("links.php"); ?>
      </td>
      <td width="80%" valign="top" align="center">
  <br>

<br>
<script language="JavaScript" src="./js/globtrax.js" type="text/javascript"></script>


<br>
<?
if(($_GET['do'])==('activation')){
 $getcomm = @mysql_db_query("$dbName", "SELECT * FROM `comments` WHERE `comment_group` = '2' ") ;
 $totalaccomm = mysql_affected_rows();
 if(($totalaccomm)==('0')){
 	?>
       <br>
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="267" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="261" class="backtablemun">
				<p align="center"><span lang="ar-sa">تعليقات بانتظار التفعيل</td>
            </tr>
            <tr>
              <td width="261" class="submun">
				<p align="center"><span lang="ar-sa"><b>لا يوجد تعليقات بانتظار
				التفعيل</b></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>

 	<?
 	}else{
  if(($_GET['go'])==('ac')){
  $actcomm = @mysql_db_query("$dbName", "UPDATE `comments` SET `comment_group` = '1' WHERE `comment_id` = '$_GET[id]' ") ;
  if($actcomm){
   echo"تم تفعيل التعليق بنجاح";
   echo"<META HTTP-EQUIV='Refresh' CONTENT='1; url=comments.php?do=activation'>";
  	}else{
  	echo"هناك مشكلة بتفعيل التعليق";
  	}
  }elseif(($_GET['go'])==('del')){
  $dele = @mysql_db_query("$dbName", "DELETE FROM  `comments`  WHERE `comment_id` = '$_GET[id]' ") ;
  if($dele){
	echo"<b>تم حذف التعليق بنجاح</b>";
    echo"<META HTTP-EQUIV='Refresh' CONTENT='1; url=comments.php?do=activation'>";
  }else{
  echo"هناك مشكلة بحذف التعليق";
  }
  }
?>

   <br>
        <div align="center">
          <table width="692" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="686" class="backtablemun" colspan="5">
				<p align="center"><span lang="ar-sa">تعليقات بانتظار التفعيل</td>
            </tr>
            <tr>
              <td width="88" class="submun">
				<p align="center"><b>رقم التعليق</b></td>
              <td width="243" class="submun">
				<p align="center"><b>التعليق</b></td>
              <td width="95" class="submun">
				<p align="center"><b>كاتب التعليق</b></td>
              <td width="127" class="submun">
				<p align="center"><b>القصيدة</b></td>
              <td width="118" class="submun">
				<p align="center"><b>اعتماد / حذف</b></td>
            </tr>
            <?
            while  ($comment = mysql_fetch_array($getcomm)){
             $commentpoem = $comment[divan_id];
             $comentvalue = $comment[comment_value];
             $cvalue= wordwrap($comentvalue,20,'<br />');



          	 $getpoem = @mysql_db_query("$dbName", "SELECT * FROM divan WHERE divan_id = '$commentpoem'") ;
              while  ($pname = mysql_fetch_array($getpoem)){
              $poemname = $pname[divan_title];
              }

            	?>
             <tr>
              <td width="88"  class="subsub">
				<p align="center"><?echo $comment[comment_id];?></td>
              <td width="243"  class="subsub">
				<p align="center"><?echo $cvalue;?></td>
              <td width="95" class="subsub">
				<p align="center"><? echo $comment[user_name];?></td>
              <td width="127" class="subsub">
				<p align="center"><?echo $poemname?></td>
              <td width="118" class="subsub">
				<p align="center"><span lang="ar-sa">
				<a href="comments.php?do=activation&go=ac&id=<?echo $comment[comment_id];?>">اعتماد</a> /
				<a onclick="return del('هل انت متاكد من حذف التعليق ؟');" href="comments.php?do=activation&go=del&id=<?echo $comment[comment_id];?>" >حذف</a></td>
            </tr>
            <?
            }
            ?>
            </table>
        </div>
        </td>
    </tr>
  </table>


<?
}
}elseif(($_GET['do'])==('search')){
  if(($_GET['action'])==('del')){
       $dele = @mysql_db_query("$dbName", "DELETE FROM  `comments`  WHERE `comment_id` = '$_GET[id]' ") ;
  if($dele){
	echo"<b>تم حذف التعليق بنجاح</b>";
    echo"<META HTTP-EQUIV='Refresh' CONTENT='1; url=comments.php?do=search'>";
  }else{
  echo"هناك مشكلة بحذف التعليق";
  }
     }
?>
 <br>
   <form name="" action="comments.php?do=search&go=search" method="post">
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="267" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="261" class="backtablemun" colspan="2">
				<p align="center">البحث عن تعليق </td>
            </tr>
            <tr>
              <td width="104" class="submun">
				<p align="center">رقم التعليق : </td>
              <td width="153" class="submun">
				&nbsp;
				<input name="commnum" type="text" value="" size="19"></td>
            </tr>
            <tr>
              <td width="257" class="submun" colspan="2">
				<p align="center">&nbsp;<input type="submit" value="بحث"></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
    </form>
  </table>
<?
if(($_GET['go'])==('search')){
$getcomm = @mysql_db_query("$dbName", "SELECT * FROM `comments` WHERE `comment_id` = '$_POST[commnum]' ") ;
$total = mysql_affected_rows();
if(($total)==('0')){
	echo"عفوا التعليق غير متوفر";
	}else{

?>
  <br>
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="692" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="686" class="backtablemun" colspan="5">
				<p align="center"><span lang="ar-sa">نتائج البحث</td>
            </tr>
            <tr>
              <td width="88" class="submun">
				<p align="center"><b>رقم التعليق</b></td>
              <td width="243" class="submun">
				<p align="center"><b>التعليق</b></td>
              <td width="95" class="submun">
				<p align="center"><b>كاتب التعليق</b></td>
              <td width="127" class="submun">
				<p align="center"><b>القصيدة</b></td>
              <td width="118" class="submun">
				<p align="center"><b>&nbsp;حذف</b></td>
            </tr>
            <?
              while  ($comment = mysql_fetch_array($getcomm)){
             $commentpoem = $comment[divan_id];
             $comentvalue = $comment[comment_value];
             $cvalue= wordwrap($comentvalue,20,'<br />');



          	 $getpoem = @mysql_db_query("$dbName", "SELECT * FROM divan WHERE divan_id = '$commentpoem'") ;
              while  ($pname = mysql_fetch_array($getpoem)){
              $poemname = $pname[divan_title];
              }
            ?>
            <tr>
              <td width="88"  class="subsub">
				<p align="center"><?echo $comment[comment_id]?></td>
              <td width="243"  class="subsub">
				<p align="center"><?echo $cvalue;?></td>
              <td width="95" class="subsub">
				<p align="center"><?echo $comment[user_name];?></td>
              <td width="127" class="subsub">
				<p align="center"><?echo $poemname;?></td>
              <td width="118" class="subsub">
				<p align="center"><span lang="ar-sa">
				&nbsp;<a onclick="return del('هل انت متاكد من حذف التعليق ؟');" href="comments.php?do=search&action=del&id=<?echo $comment[comment_id]?>">حذف</a></td>
            </tr>
            <?
            }
            ?>
            </table>
        </div>
        </td>
    </tr>
  </table>

<?
}
}
}elseif(($_GET['do'])==('list')){
        //بداية تقسيم الصفحة
  $page = (!isset($_GET['page']) ? 1 : intval($_GET['page']));
$page =(intval($_GET['page'])<=0 ? 1 : $page );
$numpage=50; #العدد بكل صفحة
$limit=($page * $numpage) - $numpage;
//نهاية

 $select = @mysql_db_query("$dbName", "SELECT * FROM `comments` ORDER BY `comments`.`comment_id` DESC limit  $limit,$numpage") ;
 $getthisstotal = mysql_affected_rows();
 if(($getthisstotal)==(0)){
  echo "عفوا لا يوجد تعليقات حاليا";
  exit();
 	}
  ?>
   <p align="center">&nbsp;</p>
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="733" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="727" class="backtablemun" colspan="5">
				<p align="center">قائمة التعليقات</td>
            </tr>
            <tr>
              <td width="217" class="submun" align="center">
				التعليق</td>
              <td  width="120" class="submun" align="center">
				تاريخ الاضافه</td>
              <td width="122" class="submun" align="center">
				الكاتب</td>
              <td width="95" class="submun" align="center">
				القصيدة</td>
              <td width="157" class="submun" align="center">
				حذف</td>
            </tr>
            <?
            while  ($comm = mysql_fetch_array($select)){
            ?>
            <tr>
              <td width="217" class="subsub" align="center">
				<textarea readonly rows="3" cols="36" class="textform" name="comment"><?echo $comm[comment_value];?></textarea></td>
              <td width="120" class="subsub" align="center">
				<?echo $comm[comment_date];?></td>
              <td width="122" class="subsub" align="center">
				<?echo $comm[user_name];?></td>
              <td width="95" class="subsub" align="center">
				<?

			$thisdid =  $comm[divan_id];
       		$selectd = @mysql_db_query("$dbName", "SELECT * FROM `divan` WHERE `divan`.`divan_id` = '$thisdid'") ;
            while  ($thiss = mysql_fetch_array($selectd)){
            $poemtt =   $thiss[divan_short];
            }
             if(($poemtt) != ('')){
             	echo "$poemtt";
             	}else{
             	echo "<b>قصيدة محذوفة</b>";
             	}

				?></td>
              <td width="157" class="subsub" align="center">
				&nbsp;<a href="comments.php?do=search&action=del&id=<?echo $comm[comment_id];?>">حذف</a> </td>
            </tr>

            <?
            }

            ?>
            </table>
        </div>
        </td>
    </tr>
  </table>

  <?

 $all = @mysql_db_query("$dbName", "SELECT * FROM `comments` ORDER BY `comments`.`comment_id` DESC ") ;
 $total =mysql_affected_rows();
 $alluser= $total/$numpage;
 $i=0;
  echo"<p align='center'>";
echo "<div align='center'>الصفحات</div>";
while (($i)<($alluser)){
$i++;
if($page<>$i) {$n="<font face='Tahoma' size='1'><a href='comments.php?do=list&page=$i'>
<span style='text-decoration: none; font-weight: 700'>[$i]</span></a></font>";}else{$n="<font color='#008000'><b>[$i]
</b></font>";
}


echo "$n&nbsp;&nbsp;&nbsp;";


}
}
?>
  <br>
        <br>
      </td>
    </tr>

  </table>
</div>
</body>

</html>
<?
}else {
include("login.php");
	}
?>