<?php
$uxa = addslashes($_COOKIE['pass']);
$pa = "hpl]hgadjd";
$uxx = str_replace($pa,"",$uxa);

if(isset($_POST['xxxx']) AND $_POST['ppp']==$uxx AND isset($_POST['password'])){
$id = intval($_POST['id']);
$pass = md5($_POST['password']);
$passwordmd5xx = $pa.$pass;
//setcookie("userid",$id,time()+86400);
setcookie("pass",$passwordmd5xx,time()+14400);
}

include('header.php');
echo $h;

$action = $_GET['action'];
if(!isset($action)) $action = "home";

IF ($action=="home"){

$query = mysql_query("SELECT * FROM admin where id='1'");
$row = mysql_fetch_array($query);
$row['password'] = stripslashes($row['password']);
$row['password'] = htmlspecialchars($row['password']);

$row['username'] = stripslashes($row['username']);
$row['username'] = htmlspecialchars($row['username']);

$form1 = "<form method='post' action='admininfo.php?action=edit'>
<input name='ppp' type='hidden' value='".$row['password']."' />
<input type='hidden' name='uu' value='".$row['username']."' />
<input type='hidden' name='id' value='".$row['id']."' />


<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td width='100%' colspan='2' class='xtt' align='center'>".$LANGAUGE_CP[9]."</td>
</tr>

    <tr>
      <td width='25%' class='xtr'>".$LANGAUGE_CP[10]."</td>
      <td width='75%' class='xtd'><input size='50' name='username' value='".$row['username']."' /></td>
    </tr>
    <tr>
      <td width='25%' class='xtr'>".$LANGAUGE_CP[11]."</td>
      <td width='75%' class='xtd'><input size='50' name='password' type='password' /></td>
    </tr>
     <tr>
      <td width='100%' colspan='2' class='xtr' align='center'><input type='submit' value=' ".$LANGAUGE_CP[12]." ' class='addsubmit' name='xxxx' /></td>
    </tr>
  </table>
</form>";

echo $form1;

}ELSEIF ($action=="edit"){

$username = addslashes($_POST['username']);
$username = trim($username);
$password = addslashes($_POST['password']);
$password = trim($password);

$ppp = addslashes($_POST['ppp']);
$ppp = trim($ppp);

if(empty($password)){
$xpass = $ppp;
}else{
$xpass = md5($password);
}

if(empty($username)){
$form = $LANGAUGE_CP[13];
echo $form;
}else{
$query =  mysql_query("UPDATE admin SET username='$username',password='$xpass'");
print $LANGAUGE_CP[14];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL= admininfo.php?action=home' />";
}


}ELSEIF ($action=="adduser"){

echo "<form method='post' action='admininfo.php?action=insertuser'>

<table class='xtable' width='100%' id='AutoNumber15'>
<tr>
<td width='100%' colspan='2' class='xtt' align='center'>إضافة عضوية جديده</td>
</tr>

    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[10]."</td>
      <td width='70%' class='xtd'><input size='50' name='username' /></td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[11]."</td>
      <td width='70%' class='xtd'><input size='50' name='password' /></td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[15]."</td>
      <td width='70%' class='xtd'>

<select size='1' name='adminoruser'>
<option value='1' selected='selected'>".$LANGAUGE_CP[16]."</option>
<option value='0'>".$LANGAUGE_CP[17]."</option>
</select>

      </td>
    </tr>
     <tr>
      <td width='100%' colspan='2' class='xtr' align='center'>
      <input type='submit' value=' ".$LANGAUGE_CP[18]." ' name='xxxx' /></td>
    </tr>
  </table>
</form>";
}ELSEIF ($action=="insertuser"){
$username = addslashes($_POST['username']);
$username = trim($username);
$password = addslashes($_POST['password']);
$password = trim($password);
$passwordm = md5($password);

$adminoruser = intval($_POST['adminoruser']);

if (empty($username)){
echo $LANGAUGE_CP[19];
}elseif (empty($password)){
echo $LANGAUGE_CP[20];
}else{
$query =  mysql_query ("INSERT INTO admin (username,password,adminoruser) VALUES ('$username','$passwordm','$adminoruser')") or die ("error");
echo $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=admininfo.php?action=adduser' />";
}


}ELSEIF ($action=="selectuser"){

$queryx = mysql_query("SELECT * FROM admin where id != '1' order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo $LANGAUGE_CP[22];
}else{

echo "<table class='xtable' width='100%' id='AutoNumber15'>
<tr>
<td width='100%' colspan='4' class='xtt' align='center'>".$LANGAUGE_CP[23]."</td>
</tr>
<tr>
      <td width='66%' align='center' class='xtr'>".$LANGAUGE_CP[24]."</td>
      <td width='20%' align='center' class='xtr'>".$LANGAUGE_CP[25]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[26]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[27]."</td>
</tr>";
while($p = mysql_fetch_array($queryx))
{
$p['username'] = stripslashes($p['username']);
$p['username'] = htmlspecialchars($p['username']);

if($p['adminoruser'] == 1){
$fz = $LANGAUGE_CP[29];
}else{
$fz = $LANGAUGE_CP[30];
}

echo "<tr>
      <td width='66%' class='xtd'>» ".$p['username']."</td>
      <td width='66%' class='xtd' align='center'>".$fz."</td>
      <td width='7%' align='center' class='xtd'><a href='admininfo.php?action=edituser&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$LANGAUGE_CP[26]." ".$p['username']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='admininfo.php?action=deleteuser&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$LANGAUGE_CP[25]." ".$p['username']."' /></a></td>
    </tr>";
}
echo "</table>";
}
}ELSEIF ($action=="edituser"){
$id = intval($_GET['id']);
if($id==1){
echo $LANGAUGE_CP[31];
}else{
$query = mysql_query("SELECT * FROM admin where id='$id'");
$p= mysql_fetch_array($query);
$p['username'] = stripslashes($p['username']);
$p['username'] = htmlspecialchars($p['username']);

$p['password'] = stripslashes($p['password']);

echo "<form method='post' action='admininfo.php?action=updateuser'>
<input name='ppp' type='hidden' value='".$p['password']."' />
<input name='id' type='hidden' value='".$id."' />

<table class='xtable' width='100%' id='AutoNumber15'>
    <tr>
<td width='100%' colspan='2' class='xtt' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[10]."</td>
      <td width='70%' class='xtd'><input size='50' name='username' value='".$p['username']."' /></td>
    </tr>
    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[11]."</td>
      <td width='70%' class='xtd'><input size='50' name='password' /></td>
    </tr>

    <tr>
      <td width='30%' class='xtr'>".$LANGAUGE_CP[15]."</td>
      <td width='70%' class='xtd'>";

echo "<select size='1' name='adminoruser'>";
if($p['adminoruser'] == 1){
echo "<option value='1' selected='selected'>".$LANGAUGE_CP[16]."</option>\n
<option value='0'>".$LANGAUGE_CP[17]."</option>\n";
}else{
echo "<option value='1'>".$LANGAUGE_CP[16]."</option>\n
<option value='0' selected='selected'>".$LANGAUGE_CP[17]."</option>\n";
}

//}
echo "</select>";

      echo "</td>
    </tr>

     <tr>
      <td width='100%' colspan='2' class='xtr' align='center'>
      <input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='xxxx' /></td>
    </tr>
  </table>
</form>";
}

}ELSEIF ($action=="updateuser"){
$id = intval($_POST['id']);
$username = addslashes($_POST['username']);
$username = trim($username);
$password = addslashes($_POST['password']);
$password = trim($password);

$ppp = addslashes($_POST['ppp']);
$ppp = trim($ppp);

if(empty($password)){
$xpass = $ppp;
}else{
$xpass = md5($password);
}

$adminoruser = intval($_POST['adminoruser']);

if(empty($username)){
echo $LANGAUGE_CP[19];
}else{
$query =  mysql_query("UPDATE admin SET username='$username',password='$xpass',adminoruser='$adminoruser' where id='$id'");
print $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL= admininfo.php?action=selectuser' />";
}

}ELSEIF ($action=="deleteuser"){
$id = intval($_GET['id']);
$query =  mysql_query("DELETE FROM admin WHERE id='$id'");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=admininfo.php?action=selectuser' />";
}

echo $f;
?>