<?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['usr-title'];
  $helppage = $TEXT['exusr-add-title2'];
  require_once "../../config.php";
  require_once "../../util/top_layer2.php";
  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);
  if(empty($_POST['familiya'])) $_POST['familiya'] = "";
  if(strlen($_POST['familiya'])>200) puterror3($TEXT['error-user3']);
  $_POST['familiya'] = rep($_POST['familiya']);
  if(empty($_GET['id'])) puterror3($TEXT['exusr-error17']);
  if(strlen($_GET['id'])>220) puterror3($TEXT['exusr-error18']);
  $familiya=$_POST['familiya'];

  if(!isset($title)) $title = $TEXT['usr-title'];
  if(!isset($button)) $button = $TEXT['btn_search'];
  if(!isset($action)) $action = "user_add2.php?id=".$_GET['id']."'";
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table width="70%" align="center">
<tr><td class="useraddedit"><?php echo $TEXT['tbl-lastname']; ?></td><td class="useraddedit"><input size=50 maxlength=50 class="inputmandatory" type=text name=familiya title='<?php echo $TEXT['filter-tit']; ?>' value='<?php echo $familiya; ?>'></td></tr>
<tr><td class="useraddedit"><a href='editform.php?userid=0&id=<?php echo $_GET['id']; ?>' title='<?php echo $TEXT['exusr-act8']; ?>'><?php echo $TEXT['exusr-act7']; ?></a></td><td><input class=button type=submit value='<?php echo $button; ?>'></td></tr>
</table>
<br />
<table class="table" border="1" cellpadding="3" cellspacing="0" width="70%">
<?php
  if(empty($_POST['familiya'])) $_POST['familiya'] = " ";
           echo "<tr class='tableheadercat' border='1'>
            <td>".$TEXT['ex-bat-ex5']."</td>
            <td>".$TEXT['tbl-fio']."</td>
            <td>".$TEXT['tbl-verd']."</td>
            <td>".$TEXT['tbl-action']."</td>
                 </tr>";

  $query1 = "SELECT tbl_users.user_id, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo, tbl_users.mail,  tbl_domain.domain 
FROM tbl_users 
JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id 
WHERE LOWER(tbl_users.familiya) LIKE LOWER('%".$_POST['familiya']."%')";
  $result1 = mysql_query($query1);
  if (!$result1) puterror3($TEXT['error-tbl2']);
    while($res_mail = mysql_fetch_array($result1))
     {
  	$query2 = "SELECT `id` FROM `users` WHERE `id`='".$res_mail['mail']."'";
  	$result2 = mysql_query($query2);
  	if (!$result2) puterror3($TEXT['error-tbl34']);
  	  $res_mail2 = mysql_fetch_array($result2);
        if($res_mail2['id'] == $res_mail['mail']) $result_mail = "<b class='translit_no'>".$TEXT['tbl-addr-use']."</b>";
           else $result_mail = "<b class='translit_ok'>".$TEXT['tbl-addr-notuse']."</b>";
              ?>
           <tr class='tabledata' onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><?php echo $res_mail['mail']; ?>@<?php echo $res_mail['domain']; ?></td>
             <td><a href# onClick=open('userinfo.php?user_id=<?php echo $res_mail['user_id']; ?>','ee','top=168,left=280,width=<?php echo $TEXT['user-width']; ?>,height=<?php echo $TEXT['user-height']; ?>,status=no,scrollbars=no') title='<?php echo $TEXT['tbl-details']; ?>'><?php echo $res_mail['familiya']; ?> <?php echo $res_mail['name']; ?> <?php echo $res_mail['otchestvo']; ?></a></td>
              <td><?php echo $result_mail; ?></td>
              <td><a href='editform.php?userid=<?php echo $res_mail['user_id']; ?>&id=<?php echo $_GET['id']; ?>' title='<?php echo $TEXT['tbl-add-tit']; ?>'><?php echo $TEXT['btn_add']; ?></a></td>
                 </tr>
<?php
    }
  require_once "../../util/bottom.php";
?>
</table>