<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../../lang/".$lang."/".$lang.".php")) include "../../lang/".$lang."/".$lang.".php";
     else include "../../lang/ru/ru.php";

  $title=$titlepage = $TEXT['exusr-title'];
  $helppage = $TEXT['exusr-help'];
  require_once "../../config.php";
  require_once "../../util/top_layer2.php";
  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);
  if(!isset($button)) $button = $TEXT['btn_filter'];
  if(!isset($action)) $action = "index.php";

  if(empty($_POST['id'])) $_POST['id'] = "";
  if(empty($_POST['quota'])) $_POST['quota'] = "";
  if(empty($_POST['name'])) $_POST['name'] = "";
  if(empty($_POST['active'])) $_POST['active'] = "";
  if(empty($_POST['user_id'])) $_POST['user_id'] = "";
  if(empty($_POST['rows'])) $_POST['rows'] = "100";

  if(strlen($_POST['id'])>200) puterror3($TEXT['error-user18']);
  if(strlen($_POST['quota'])>4) puterror3($TEXT['exusr-error13']);
  if(strlen($_POST['name'])>255) puterror3($TEXT['error-user14']);
  if(strlen($_POST['active'])>3) puterror3($TEXT['exusr-error16']);
  if(strlen($_POST['user_id'])>11) puterror3($TEXT['error-user2']);
  if(strlen($_POST['rows'])>12) puterror3($TEXT['error-log10']);
  $_POST['id'] = rep($_POST['id']);
  $_POST['quota'] = rep($_POST['quota']);
  $_POST['name'] = rep($_POST['name']);
  $_POST['active'] = rep($_POST['active']);
  $_POST['user_id'] = rep($_POST['user_id']);
  $_POST['rows'] = rep($_POST['rows']);
  $_POST['rows'] = intval($_POST['rows']);

  $id_per=$_POST['id'];
  $quota_per=$_POST['quota'];
  $name_per=$_POST['name'];
  $active_per=$_POST['active'];
  $user_per=$_POST['user_id'];
  $rows=$_POST['rows'];

  $query2 = mysql_query("SELECT COUNT(id) FROM users");
    $coun = mysql_result($query2, 0);
?>
<img alt="<?php echo $TEXT['exusr-add']; ?>" src= "../../img/insert.png" height="15" align="top" /><a class="boldit" href="user_add.php" title="<?php echo $TEXT['exusr-add-title']; ?>"><?php echo $TEXT['exusr-add']; ?></a>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="80%">
<tr><td>
<fieldset class="filterr">
<legend align="left" title="<?php echo $TEXT['log-tit7']; ?>"><?php echo $TEXT['btn_filter']; ?></legend>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr class="zag2"><td><?php echo $TEXT['bllst-text2']; ?></td><td><?php echo $TEXT['exusr-kvota']; ?></td><td><?php echo $TEXT['login-user']; ?></td><td><?php echo $TEXT['exusr-act11']; ?></td><td><?php echo $TEXT['exusr-act']; ?></td><td><?php echo $TEXT['tbl-rows']; ?></td></tr>
<tr><td><input size=20 maxlength=200 class="input" type=text name=id title='<?php echo $TEXT['exusr-example1']; ?>' value='<?php echo $id_per; ?>'></td>
    <td><input size=10 maxlength=4 class="input" type=text name=quota title='<?php echo $TEXT['exusr-example2']; ?>' value='<?php echo $quota_per; ?>'></td>
    <td><input size=20 maxlength=255 class="input" type=text name=name title='<?php echo $TEXT['exusr-example3']; ?>' value='<?php echo $name_per; ?>'></td>
    <td><input size=10 maxlength=11 class="input" type=text name=user_id title='<?php echo $TEXT['exusr-example5']; ?>' value='<?php echo $user_per; ?>'></td>
    <td><input size=10 maxlength=1 class="input" type=text name=active title='<?php echo $TEXT['exusr-example4']; ?>' value='<?php echo $active_per; ?>'></td>
    <td><input size=11 maxlength=11 class="input" type=text name=rows title='<?php echo $TEXT['log-tit12']; ?>' value='<?php echo $rows; ?>'></td>
    <td><input class="button" type=submit value='<?php echo $button; ?>'></td>
</tr>
</table>
</fieldset>
</td></tr>
</table>
</form>
 <br />
 <span class="tabledata"><?php echo $TEXT['exusr-act6']; ?></span><span class="boldit"><?php echo $coun; ?></span>
<table class="table" border="1" cellpadding="3" cellspacing="0" width="90%">
<?php
   if(!empty($_POST['id'])) $id_q = "AND `id`REGEXP '".$_POST['id']."' ";
    else $id_q = "";

   if(!empty($_POST['quota'])) $quota_q = "AND `quota` = '".$_POST['quota']."' ";
    else $quota_q = "";

   if(!empty($_POST['name'])) $name_q = "AND LOWER(name) LIKE LOWER('%".$_POST['name']."%') ";
    else $name_q = "";

   if(!empty($_POST['active'])) $active_q = "AND `active`REGEXP '".$_POST['active']."' ";
    else $active_q = "";

   if(!empty($_POST['user_id'])) $user_q = "AND `user_id` = '".$_POST['user_id']."' ";
    else $user_q = "";

     $query = "SELECT * FROM `users` WHERE `home`!='' ".$id_q." ".$quota_q." ".$name_q." ".$active_q." ".$user_q." ORDER BY id LIMIT ".$rows."";
     $result = mysql_query($query);
     if(!$result) puterror3($TEXT['error-tbl34']);
       if(mysql_num_rows($result)>0);
         {
	   ?>
           <tr class='tableheadercat'>
            <td><?php echo $TEXT['bllst-text2']; ?></td>
            <td><?php echo $TEXT['exusr-kvota']; ?></td>
            <td><?php echo $TEXT['login-user']; ?></td>
            <td><?php echo $TEXT['exusr-act']; ?></td>
            <td colspan=3><?php echo $TEXT['tbl-action']; ?></td>
           </tr>
	    <?php
             while($result_users = mysql_fetch_array($result,MYSQL_ASSOC))
               {
              $act = "<a href=editform.php?id=".$result_users['id']." title='".$TEXT['bllst-text3']."'>".$TEXT['tbl-edit']."</a>";

              if($result_users['active'] == 'N') $active = "<a href=enable.php?id=".$result_users['id']." title='".$TEXT['exusr-act2']."'>".$TEXT['exusr-act2']."</a>";
                else $active = "<a href=disable.php?id=".$result_users['id']." title='".$TEXT['exusr-act3']."'>".$TEXT['exusr-act3']."</a>";

              if($result_users['active'] == "N") $act = "<b class='translit_no'>".$TEXT['exusr-act5']."</b>";
                   else $act = "<b class='translit_ok'>".$TEXT['exusr-act4']."</b>";

              $edit = "<a href=editform.php?id=".$result_users['id']." title='".$TEXT['bllst-text3']."'>".$TEXT['tbl-edit']."</a>";
              $delete = "<a href=delete.php?id=".$result_users['id']." title='".$TEXT['bllst-text4']."'>".$TEXT['tbl-delete']."</a>";
              $email = $result_users['id']."@".$result_users['mbox_host'];

	      if($result_users['user_id'] !=="0")
		{
           ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><a href=mailto:<?php echo $email; ?>><?php echo $email; ?></a></td>
              <td><?php echo $result_users['quota']; ?></td>
              <td><a href# onClick=window.open('user.php?user_id=<?php echo $result_users['user_id']; ?>&id=<?php echo $result_users['id']; ?>','popup','top=<?php echo $TEXT['user-top']; ?>,left=<?php echo $TEXT['user-left']; ?>,width=<?php echo $TEXT['exim-user-width']; ?>,height=<?php echo $TEXT['exim-user-height']; ?>,status=no,scrollbars=no,location=no,menubar=no,toolbar=no') title='<?php echo $TEXT['btn_test']; ?>'><?php echo $result_users['name']; ?></a></td>
              <td><?php echo $act; ?></td>
              <td><?php echo $active; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
                 </tr>
           <?php
		}
	   else
		{
           ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><a href=user2.php?id=<?php echo $result_users['id']; ?> target=_blank title='<?php echo $TEXT['btn_test']; ?>'><?php echo $result_users['id'] ?>@<?php echo $result_users['mbox_host']; ?></a></td>
              <td><?php echo $result_users['quota']; ?></td>
              <td><?php echo $result_users['name']; ?></td>
              <td><?php echo $act; ?></td>
              <td><?php echo $active; ?></td>
              <td><?php echo $edit; ?></td>
              <td><?php echo $delete; ?></td>
                 </tr>
           <?php
		}
               }
         }
?>
</table>
<?php
  require_once "../../util/bottom_exp.php";
?>