<?

  include_once '../../config.inc.php';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  if (!($result_proper = mysql_query ('select * from properties')))
  {
    exit ('<b>Error:</b>' . mysql_error ());
    ;
  }

  $proper = mysql_fetch_array ($result_proper);
  include '../lang/' . $proper['admin_language'];
  echo '
<HTML><BODY STYLE="color: Navy;"><LINK HREF="../style.css" REL="stylesheet" TYPE="text/css"><TABLE WIDTH="600" BORDER=0 CELLSPACING=0 CELLPADDING=1><TR><TD style="background-color:#505090;"><TABLE WIDTH="100%" BORDER=0 CELLSPACING=0 CELLPADDING=5 BGCOLOR="#EFEFF8">
<TR><TD VALIGN=top BGCOLOR="#BFBFDF" STYLE="border-bottom: 1px solid #505090;"><FONT COLOR="navy"><B>';
  echo $admin_Add_Edit_Delete_Users;
  echo '</B></FONT></TD></TR><TR><TD VALIGN=top>

';
  echo '<S';
  echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function confirmSubmit(record) 
{
if (confirm("Are you sure you wish to delete user \\"" + record + "\\"?"))
	return true ;
else
	return false ;
}
//-->
</SCRIPT>


';
  if (!include '../autorization.php')
  {
    echo 'Access denied!';
    exit ();
  }

  echo '



';
  if ($_GET['delete'])
  {
    if (!(mysql_query ('' . 'DELETE FROM users WHERE id=\'' . $_GET['delete'] . '\'')))
    {
      exit ('Query failed');
      ;
    }
  }

  echo '





';
  if ($_POST['useradd'])
  {
    if (($_POST['user'] AND $_POST['pass'] == $_POST['repass']))
    {
      if (!($result = mysql_query ('' . 'SELECT * FROM users WHERE username=\'' . $_POST['user'] . '\'')))
      {
        exit ('Query failed4');
        ;
      }

      $row = mysql_fetch_array ($result);
      if (!$row)
      {
        if ($_POST['post_allow'])
        {
          $separated = join ('
', $_POST['post_allow']) . '
';
        }

        $SQL = '' . 'INSERT INTO users VALUES(\'\',\'' . $_POST['user'] . '\',\'' . md5 ($_POST['pass']) . ('' . '\',\'' . $_POST['admin'] . '\',\'' . $separated . '\')');
        if (!(mysql_query ($SQL)))
        {
          exit ('Query failed');
          ;
        }
      }
      else
      {
        echo '<S';
        echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">alert("User already exist!!")</SCRIPT>';
      }
    }
    else
    {
      echo '<S';
      echo 'CRIPT LANGUAGE="JavaScript" TYPE="text/javascript">alert("Passwords does not match or username is empty!")</SCRIPT>';
    }
  }

  echo '



<FORM ACTION="';
  echo $php_self;
  echo '" METHOD="post">

<TABLE>
<TR>
	<TD ALIGN=right>';
  echo $admin_Username;
  echo '</TD>
	<TD><INPUT TYPE=text NAME="user"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Password;
  echo '</TD>
	<TD><INPUT TYPE=password NAME="pass"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Repeat_Password;
  echo '</TD>
	<TD><INPUT TYPE=password NAME="repass"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
  echo $admin_Allowed_Categories;
  echo '</TD>
	<TD>
		';
  echo '<S';
  echo 'ELECT NAME="post_allow[]" SIZE="10" MULTIPLE>
		';
  if (!($result = mysql_query ('SELECT * FROM categories')))
  {
    exit ('Query failed4');
    ;
  }

  while ($row = mysql_fetch_array ($result))
  {
    echo '				<option value="';
    echo $row['id'];
    echo '">';
    echo $row['name'];
    echo '</option>
		';
  }

  echo '		</select>		
	</TD>
</TR>

';
  if ($_COOKIE['root'])
  {
    echo '<TR>
	<TD ALIGN=right>';
    echo $admin_table2[0];
    echo ':</TD>
	<TD><INPUT TYPE=radio NAME="admin" VALUE="0"></TD>
</TR>
<TR>
	<TD ALIGN=right>';
    echo $admin_table2[1];
    echo ':</TD>
	<TD><INPUT TYPE=radio NAME="admin" VALUE="1"></TD>
</TR>
';
  }

  echo '<TR>
	<TD ALIGN=right>';
  echo $admin_table2[2];
  echo ':</TD>
	<TD><INPUT TYPE=radio NAME="admin" VALUE="2"></TD>
</TR>
<TR>
	<TD ALIGN=right></TD>
	<TD><INPUT TYPE=submit NAME="useradd" VALUE="';
  echo $admin_Add_user;
  echo '"></TD>
</TR>
</TABLE>

</FORM>






<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3>
<TR BGCOLOR="#505090">
<TD><FONT COLOR="#FFFFFF">';
  echo $admin_table3[0];
  echo '</FONT></TD>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table3[1];
  echo '</FONT></td>
<td><FONT COLOR="#FFFFFF">';
  echo $admin_table3[2];
  echo '</FONT></td>
</tr>

';
  if ($_COOKIE['root'])
  {
    $SQL = 'SELECT * FROM users';
  }
  else
  {
    $SQL = 'SELECT * FROM users WHERE root=2';
  }

  if (!($result = mysql_query ($SQL)))
  {
    exit ('Query failed4');
    ;
  }

  while ($row = mysql_fetch_array ($result))
  {
    echo '<TR bgcolor="';
    if ($i++ % 2)
    {
      echo '#BFBFDF';
    }
    else
    {
      echo '#DCDCED';
    }

    echo '">
					<TD width=200>';
    echo $row['username'];
    echo '</TD>
					<TD>';
    if ($row['root'] == 0)
    {
      echo $admin_table2[0];
    }
    else
    {
      if ($row['root'] == 1)
      {
        echo $admin_table2[1];
      }
      else
      {
        echo $admin_table2[2];
      }
    }

    echo '</TD>
					<TD ALIGN=center>
						<A HREF="edit.php?id=';
    echo $row['id'];
    echo ';"><IMG SRC="../images/edit.gif" ALT="Edit" BORDER=0></A>
						<A onclick="return confirmSubmit(\'';
    echo urlencode ($row['username']);
    echo '\')" HREF="index.php?delete=';
    echo $row['id'];
    echo '"><IMG SRC="../images/delete.gif" ALT="Delete" BORDER=0></A>
					</TD>
				</TR>
			';
  }

  echo '</TABLE>









</TD></TR></TABLE></TD></TR></TABLE></BODY></HTML>';
?>
