<?
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">
<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>
<script language="JavaScript" src="./js/globtrax.js" type="text/javascript"></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>
  <?
	if (($_GET['do'])==('search')){
 ?>
 <br>
 <br>
 <br>
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
<form name="" action="user.php?do=search&go=get" method="post">
      <div align="center">
          <table width="368" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="362" class="backtablemun" colspan="2">
				<p align="center">خيارات البحث</td>
            </tr>
            <tr>
              <td width="96" class="submun">
				<p align="center">اسم المستخدم : </td>
              <td width="262" class="subsub" >
				<font color="#FF0000">
				<input name="username" type="text" value="" size="33" dir="rtl"></font></td>
            </tr>
            <tr>
              <td width="96" class="submun">
				<p align="center">البريد الالكتروني :</td>
              <td width="262" class="subsub" >
				<font color="#FF0000">
				<input name="email" type="text" value="" size="33" dir="rtl"></font></td>
            </tr>
            <tr>
              <td width="96"  class="submun">
				&nbsp;</td>
              <td width="262" class="subsub">
				<p align="center">&nbsp;<input type="submit" value="بحث"></td>
            </tr>
            </table>
        </div>
        </form>
        </td>
    </tr>
  </table>
  <?
  if (($_GET['go'])==('get')){
  $username = trim ($_POST['username']);
  $mail = trim ($_POST['email']);
  $selectuser = @mysql_db_query("$dbName", "SELECT * FROM `users`   where   user_name = '$username' or  user_mail = '$mail'") ;
  $total = mysql_affected_rows();

  if (($total)==('0')){
 ?>
 <br>
  <table width="72%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="714" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="708" class="backtablemun">
				<p align="center"><span lang="ar-sa">الرسالة</span></td>
            </tr>
            <tr>
              <td width="704" class="submun">
				<p align="center"><span lang="ar-sa">عفوا لا يوجد أعضاء بمواصفات
				البحث</span></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>
 <?
  }else{
  ?>
  <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="4">
				<p align="center">نتائج البحث</td>
            </tr>
            <tr>
              <td width="190" class="submun">
				<p align="center">اسم المستخدم </td>
              <td width="187" class="submun" >
				<p align="center">البريد الالكتروني </td>
              <td width="176" class="submun" >
				<p align="center">حالة العضو</td>
              <td width="162" class="submun" >
				<p align="center">تعديل /حذف</td>
            </tr>
            <?
            while  ($user = mysql_fetch_array($selectuser)){
            ?>
            <tr>
              <td width="190" class="subsub">
				<p align="center"><?echo $user[user_name]; ?></td>
              <td width="187" class="subsub" >
				<p align="center"><?echo $user[user_mail]; ?>&nbsp;&nbsp; <a href="javascript:TraidntPopUp('send.php?mail=<?echo $user[user_mail]; ?>','125','200','400','250');">
				<img border="0" src="images/send.gif" alt="مراسلة العضو"></a></td>
              <td width="176" class="subsub" >
				<p align="center">
				<?
				if (($user[user_group]) == ('1')){
				echo "نشط";
				}elseif (($user[user_group]) == ('2')){
                echo"بنتظار التفعيل";
				}elseif (($user[user_group]) == ('3')){
				echo"محظور";
				}
				?>

				</td>
              <td width="162" class="subsub" >
				<p align="center"><a href="javascript:TraidntPopUp('edituser.php?id=<?echo $user['user_id']?>','125','200','400','250');">تعديل</a> /<a href="user.php?do=search&go=del&id=<?echo $user['user_id']?>">حذف</a></td>
            </tr>
            <?
            }
            ?>
            </table>
        </div>
        </td>
    </tr>
  </table>

 <?
 }
 }elseif (($_GET['go'])==('del')){
 $id = trim($_GET['id']);
 $delfromdb = @mysql_db_query("$dbName", "DELETE from users WHERE user_id = '$id'") ;
 if($delfromdb){
 ?>
 <META HTTP-EQUIV='Refresh' CONTENT='2; url=user.php?do=search'>
 <br>
  <table width="72%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="714" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="708" class="backtablemun">
				<p align="center"><span lang="ar-sa">الرسالة</span></td>
            </tr>
            <tr>
              <td width="704" class="submun">
				<p align="center"><span lang="ar-sa">تم حذف العضو بنجاح</span></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>
 <?
 }else{
 ?>
 <br>
  <table width="72%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="714" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="708" class="backtablemun">
				<p align="center"><span lang="ar-sa">الرسالة</span></td>
            </tr>
            <tr>
              <td width="704" class="submun">
				<p align="center"><span lang="ar-sa">عفوا هناك مشكلة بحذف هذا
				العضو</span></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>


 <?
 }

 }
 	}elseif (($_GET['do'])==('userlist')){
 	?>
       <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="4">
				<p align="center">قائمة الأعضاء</td>
            </tr>
            <tr>
              <td width="190" class="submun">
				<p align="center">اسم المستخدم </td>
              <td width="187" class="submun" >
				<p align="center">البريد الالكتروني </td>
              <td width="176" class="submun" >
				<p align="center">حالة العضو</td>
              <td width="162" class="submun" >
				<p align="center">تعديل /حذف</td>
            </tr>
            <?
  //بداية تقسيم الصفحة
  $page = (!isset($_GET['page']) ? 1 : intval($_GET['page']));
$page =(intval($_GET['page'])<=0 ? 1 : $page );
$numpage=200; #العدد بكل صفحة
$limit=($page * $numpage) - $numpage;
//نهاية

$scan = @mysql_db_query("$dbName", " SELECT * FROM `users`  limit  $limit,$numpage ") ;
$totaluser = mysql_affected_rows();
while  ($user = mysql_fetch_array($scan)){
            ?>
            <tr>
              <td width="190" class="subsub">
				<p align="center"><?echo $user[user_name]; ?></td>
              <td width="187" class="subsub" >
				<p align="center"><?echo $user[user_mail]; ?>&nbsp;&nbsp; <a href="javascript:TraidntPopUp('send.php?mail=<?echo $user[user_mail]; ?>','125','200','400','250');">
				<img border="0" src="images/send.gif" alt="مراسلة العضو"></a></td>
              <td width="176" class="subsub" >
				<p align="center">
				<?
				if (($user[user_group]) == ('1')){
				echo "نشط";
				}elseif (($user[user_group]) == ('2')){
                echo"بنتظار التفعيل";
				}elseif (($user[user_group]) == ('3')){
				echo"محظور";
				}
				?>

				</td>
              <td width="162" class="subsub" >
				<p align="center"><a href="javascript:TraidntPopUp('edituser.php?id=<?echo $user['user_id']?>','125','200','400','250');">تعديل</a> /<a href="user.php?do=search&go=del&id=<?echo $user['user_id']?>">حذف</a></td>
            </tr>
            <?
            }

            ?>
  </table>
 	<?
 	             	$all = @mysql_db_query("$dbName", " SELECT * FROM `users`  ") ;
 	$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='user.php?do=userlist&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;";


}
 	}elseif (($_GET['do'])==('activation')){

 	$scan = @mysql_db_query("$dbName", " SELECT * FROM `users`  WHERE  `user_group` = '2'  ") ;
	$totaluser = mysql_affected_rows();
	if (($totaluser)==('0')){
  ?>
  <br>
  <table width="21%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="304" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="298" class="backtablemun">
				<p align="center"><span lang="ar-sa">الرسالة</span></td>
            </tr>
            <tr>
              <td width="298" class="submun">
				<p align="center"><span lang="ar-sa">لا يوجد أعضاء بانتظار
				التفعيل</span></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>
   <?
	}else{
 	?>

  <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="4">
				<p align="center"><span lang="ar-sa">أعضاء بانتظار التفعيل</span></td>
            </tr>
            <tr>
              <td width="190" class="submun">
				<p align="center">اسم المستخدم </td>
              <td width="187" class="submun" >
				<p align="center">البريد الالكتروني </td>
              <td width="176" class="submun" >
				<p align="center">حالة العضو</td>
              <td width="162" class="submun" >
				<p align="center">تفعيل</td>
            </tr>
            <?
            while  ($user = mysql_fetch_array($scan)){
            ?>
            <tr>

              <td width="190" class="subsub">
				<p align="center"><?echo $user[user_name] ?></td>
              <td width="187" class="subsub" >
				<p align="center"><?echo $user[user_mail] ?>&nbsp;&nbsp; <a href="send.php?mail=<?echo $user[user_mail]?>">
				<img border="0" src="images/send.gif" width="16" height="16"></a></td>
              <td width="176" class="subsub" >
				<p align="center">بنتظار التفعيل</td>
              <td width="162" class="subsub" >
				<p align="center"><a href="user.php?do=activation&go=ac&id=<?echo $user[user_id]?>">
				تفعيل</a></td>
            </tr>
            <?
            }
            ?>
            </table>
        </div>
        </td>
    </tr>
  </table>

   <?
   if (($_GET['go'])==('ac')){
   $update = @mysql_db_query("$dbName", "UPDATE `users` SET `user_group` = '1' WHERE `user_id` ='$_GET[id]' ;") ;
   if ($update){
   echo "تم تفعيل العضو بنجاح";
   print ("<META HTTP-EQUIV='Refresh' CONTENT='1; url=user.php?do=activation'>");
   }else{
   echo"هناك مشكلة بتفعيل العضو";
   }

   }
   ?>


 	<?
 	}
 	}elseif (($_GET['do'])==('addnew')){
    if(($_GET['go'])==('')){
	?>

  <br>
  <form name="traid" action="user.php?do=addnew&go=add" method="post">
  <table width="20%" align="center"  cellpadding="0" cellspacing="0" class="mytable">
    <tr>
      <td>
      <div align="center">
          <table width="365" height="100%" align="center" bordercolor="#006633">
            <tr>
              <td width="359" class="backtablemun" colspan="2">
				<p align="center">أضافه عضو جديد</td>
            </tr>
            <tr>
              <td width="118" class="submun" align="center">
				اسم المستخدم : </td>
              <td width="237" class="subsub" align="center">
				<input name="username" type="text" value="" size="36"></td>
            </tr>
            <tr>
              <td width="118" class="submun" align="center">
				البريد الالكتروني :</td>
              <td width="237" class="subsub" align="center">
				<input name="mail" type="text" value="" size="36"></td>
            </tr>
            <tr>
              <td width="118" class="submun" align="center">
				<span lang="ar-sa">كلمة المرور</span> : </td>
              <td width="237" class="subsub" align="center">
				<input name="password" type="password" value="" size="36"></td>
            </tr>
            <tr>
              <td width="118" class="submun" align="center">
				&nbsp;</td>
              <td width="237" class="subsub" align="center">
				&nbsp;<input type="submit" value="اضافه العضو"></td>
            </tr>
            </table>
        </div>
        </td>
    </tr>
  </table>
</form>
  <script language="JavaScript" type="text/javascript">
  var frmvalidator  = new Validator("traid");
  frmvalidator.addValidation("username","req","من فضلك ادخل اسم المستخدم");
 frmvalidator.addValidation("mail","req","من فضلك ادخل البريد الالكتروني");
 frmvalidator.addValidation("mail","email","عفواً البريد الالكتروني غير صحيح");
  frmvalidator.addValidation("password","req","من فضلك ادخل كلمة المرور");

</script>

  <br>

	<?
	}else{
	$username= trim($_POST[username]);
 	$username = strip_tags($username);

 	$mail = trim($_POST['mail']);

  	$password= trim($_POST[password]);
   	$md5pass = md5($password);

    $cuser = @mysql_db_query("$dbName", "SELECT * FROM `users` WHERE `user_name` = '$username' ") ;
    $issetuser = mysql_affected_rows();

    $cmail = @mysql_db_query("$dbName", "SELECT * FROM `users` WHERE `user_mail` = '$mail' ") ;
    $issetmail = mysql_affected_rows();

	$lastvisite = time();
    if(($issetuser)==('1')){
    	echo"برجاء استخدام اسم مستخدم آخر هذا الاسم مستعمل من قبل";
    	}elseif(($issetmail)==('1')){
    		echo"برجاء استخدام بريد الكتروني آخر هذا البريد مستخدم من قبل";
    		}else{
      		$addnewuser = @mysql_db_query("$dbName", "INSERT INTO `users` ( `user_id` , `user_name` , `user_password` , `user_mail` , `user_visit` , `user_group` )
				VALUES (NULL , '$username', '$md5pass', '$mail', '$lastvisite', '1'); ") ;
				if ($addnewuser){
					echo"<b>تم اضافه العضو بنجاح</b>";
					}else{
						echo"عفوا هناك مشكلة باضافه هذا العضو";
						}
    		}

	}

 	}

  ?>

  <br>
        <br>
      </td>
    </tr>

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

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