<?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-title5'];
  $helppage = $TEXT['usr-help5'];

  require_once "../config.php";
  require_once "../util/top.php";

  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(!isset($button)) $button = $TEXT['btn_filter'];
  if(!isset($action)) $action = "index.php";
  if(!isset($button2)) $button2 = $TEXT['btn_clear'];
  if(!isset($action2)) $action2 = "index.php";

  if(empty($_POST['familiya'])) $_POST['familiya'] = "";
  if(empty($_POST['name'])) $_POST['name'] = "";
  if(empty($_POST['otchestvo'])) $_POST['otchestvo'] = "";
  if(empty($_POST['mail'])) $_POST['mail'] = "";
  if(empty($_POST['city'])) $_POST['city'] = "";
  if(empty($_POST['street'])) $_POST['street'] = "";
  if(empty($_POST['house'])) $_POST['house'] = "";
  if(empty($_POST['room'])) $_POST['room'] = "";
  if(empty($_POST['scribe'])) $_POST['scribe'] = "";
  if(empty($_POST['phonem'])) $_POST['phonem'] = "";
  if(empty($_POST['phonec'])) $_POST['phonec'] = "";
  if(empty($_POST['phonei'])) $_POST['phonei'] = "";
  if(empty($_POST['org'])) $_POST['org'] = "";
  if(empty($_POST['upr'])) $_POST['upr'] = "";
  if(empty($_POST['otd'])) $_POST['otd'] = "";
  if(empty($_POST['post'])) $_POST['post'] = "";
  if(empty($_POST['visible'])) $_POST['visible'] = "";
  if(empty($_GET['familiya'])) $_GET['familiya'] = "";
  if(empty($_GET['name'])) $_GET['name'] = "";
  if(empty($_GET['otchestvo'])) $_GET['otchestvo'] = "";
  if(empty($_GET['mail'])) $_GET['mail'] = "";
  if(empty($_GET['city'])) $_GET['city'] = "";
  if(empty($_GET['street'])) $_GET['street'] = "";
  if(empty($_GET['house'])) $_GET['house'] = "";
  if(empty($_GET['room'])) $_GET['room'] = "";
  if(empty($_GET['scribe'])) $_GET['scribe'] = "";
  if(empty($_GET['phonem'])) $_GET['phonem'] = "";
  if(empty($_GET['phonec'])) $_GET['phonec'] = "";
  if(empty($_GET['phonei'])) $_GET['phonei'] = "";
  if(empty($_GET['org'])) $_GET['org'] = "";
  if(empty($_GET['upr'])) $_GET['upr'] = "";
  if(empty($_GET['otd'])) $_GET['otd'] = "";
  if(empty($_GET['post'])) $_GET['post'] = "";
  if(empty($_GET['visible'])) $_GET['visible'] = "";

  if(strlen($_POST['familiya'])>200) puterror2($TEXT['error-user12']);
  if(strlen($_POST['name'])>200) puterror2($TEXT['error-user14']);
  if(strlen($_POST['otchestvo'])>200) puterror2($TEXT['error-user15']);
  if(strlen($_POST['mail'])>100) puterror2($TEXT['error-user18']);
  if(strlen($_POST['city'])>120) puterror2($TEXT['error-city2']);
  if(strlen($_POST['street'])>200) puterror2($TEXT['error-str2']);
  if(strlen($_POST['house'])>80) puterror2($TEXT['error-house2']);
  if(strlen($_POST['room'])>64) puterror2($TEXT['error-user22']);
  if(strlen($_POST['scribe'])>8) puterror2($TEXT['error-user24']);
  if(strlen($_POST['phonem'])>30) puterror2($TEXT['error-user19']);
  if(strlen($_POST['phonec'])>30) puterror2($TEXT['error-user20']);
  if(strlen($_POST['phonei'])>20) puterror2($TEXT['error-user21']);
  if(strlen($_POST['org'])>400) puterror2($TEXT['error-org4']);
  if(strlen($_POST['upr'])>400) puterror2($TEXT['error-upr4']);
  if(strlen($_POST['otd'])>280) puterror2($TEXT['error-otd3']);
  if(strlen($_POST['post'])>120) puterror2($TEXT['error-post3']);
  if(strlen($_POST['visible'])>4) puterror2($TEXT['error-user23']);
  if(strlen($_GET['familiya'])>200) puterror2($TEXT['error-user12']);
  if(strlen($_GET['name'])>200) puterror2($TEXT['error-user14']);
  if(strlen($_GET['otchestvo'])>200) puterror2($TEXT['error-user15']);
  if(strlen($_GET['mail'])>100) puterror2($TEXT['error-user18']);
  if(strlen($_GET['city'])>120) puterror2($TEXT['error-city2']);
  if(strlen($_GET['street'])>200) puterror2($TEXT['error-str2']);
  if(strlen($_GET['house'])>80) puterror2($TEXT['error-house2']);
  if(strlen($_GET['room'])>64) puterror2($TEXT['error-user22']);
  if(strlen($_GET['scribe'])>8) puterror2($TEXT['error-user24']);
  if(strlen($_GET['phonem'])>30) puterror2($TEXT['error-user19']);
  if(strlen($_GET['phonec'])>30) puterror2($TEXT['error-user20']);
  if(strlen($_GET['phonei'])>20) puterror2($TEXT['error-user21']);
  if(strlen($_GET['org'])>400) puterror2($TEXT['error-org4']);
  if(strlen($_GET['upr'])>400) puterror2($TEXT['error-upr4']);
  if(strlen($_GET['otd'])>280) puterror2($TEXT['error-otd3']);
  if(strlen($_GET['post'])>120) puterror2($TEXT['error-post3']);
  if(strlen($_GET['visible'])>4) puterror2($TEXT['error-user23']);
  $_POST['familiya'] = rep($_POST['familiya']);
  $_POST['name'] = rep($_POST['name']);
  $_POST['otchestvo'] = rep($_POST['otchestvo']);
  $_POST['mail'] = rep($_POST['mail']);
  $_POST['city'] = rep($_POST['city']);
  $_POST['street'] = rep($_POST['street']);
  $_POST['house'] = rep($_POST['house']);
  $_POST['room'] = rep($_POST['room']);
  $_POST['scribe'] = rep($_POST['scribe']);
  $_POST['phonem'] = rep($_POST['phonem']);
  $_POST['phonec'] = rep($_POST['phonec']);
  $_POST['phonei'] = rep($_POST['phonei']);
  $_POST['org'] = rep($_POST['org']);
  $_POST['upr'] = rep($_POST['upr']);
  $_POST['otd'] = rep($_POST['otd']);
  $_POST['post'] = rep($_POST['post']);
  $_POST['visible'] = rep($_POST['visible']);
  $_GET['familiya'] = rep($_GET['familiya']);
  $_GET['name'] = rep($_GET['name']);
  $_GET['otchestvo'] = rep($_GET['otchestvo']);
  $_GET['mail'] = rep($_GET['mail']);
  $_GET['city'] = rep($_GET['city']);
  $_GET['street'] = rep($_GET['street']);
  $_GET['house'] = rep($_GET['house']);
  $_GET['room'] = rep($_GET['room']);
  $_GET['scribe'] = rep($_GET['scribe']);
  $_GET['phonem'] = rep($_GET['phonem']);
  $_GET['phonec'] = rep($_GET['phonec']);
  $_GET['phonei'] = rep($_GET['phonei']);
  $_GET['org'] = rep($_GET['org']);
  $_GET['upr'] = rep($_GET['upr']);
  $_GET['otd'] = rep($_GET['otd']);
  $_GET['post'] = rep($_GET['post']);
  $_GET['visible'] = rep($_GET['visible']);
  
  $rows = 100;

  if(empty($_POST['familiya'])) $familiya=$_GET['familiya'];
    else $familiya=$_POST['familiya'];
  if(empty($_POST['name'])) $name=$_GET['name'];
    else $name=$_POST['name'];
  if(empty($_POST['otchestvo'])) $otchestvo=$_GET['otchestvo'];
    else $otchestvo=$_POST['otchestvo'];
  if(empty($_POST['mail'])) $mail=$_GET['mail'];
    else $mail=$_POST['mail'];
  if(empty($_POST['city'])) $city=$_GET['city'];
    else $city=$_POST['city'];
  if(empty($_POST['street'])) $street=$_GET['street'];
    else $street=$_POST['street'];
  if(empty($_POST['house'])) $house=$_GET['house'];
    else $house=$_POST['house'];
  if(empty($_POST['room'])) $room=$_GET['room'];
    else $room=$_POST['room'];
  if(empty($_POST['scribe'])) $scribe=$_GET['scribe'];
    else $scribe=$_POST['scribe'];
  if(empty($_POST['phonem'])) $phonem=$_GET['phonem'];
    else $phonem=$_POST['phonem'];
  if(empty($_POST['phonec'])) $phonec=$_GET['phonec'];
    else $phonec=$_POST['phonec'];
  if(empty($_POST['phonei'])) $phonei=$_GET['phonei'];
    else $phonei=$_POST['phonei'];
  if(empty($_POST['org'])) $org=$_GET['org'];
    else $org=$_POST['org'];
  if(empty($_POST['upr'])) $upr=$_GET['upr'];
    else $upr=$_POST['upr'];
  if(empty($_POST['otd'])) $otd=$_GET['otd'];
    else $otd=$_POST['otd'];
  if(empty($_POST['post'])) $post=$_GET['post'];
    else $post=$_POST['post'];
  if(empty($_POST['visible'])) $visible=$_GET['visible'];
    else $visible=$_POST['visible'];
  if(empty($_POST['rows'])) $rows=$_GET['rows'];
    else $rows=$_POST['rows'];

  if(!empty($mail))
 {
  $delimiter = "@";
  $srch_tmp = explode($delimiter, $mail);
  $mail = $srch_tmp['0'];
 }

  if(empty($rows)) $rows = 100;
  if(strlen($rows)>12) puterror2($TEXT['error-log10']);
  $rows = rep($rows);
  $rows = intval($rows);
  //$rows=$_POST['rows'];

  $query_count = mysql_query("SELECT COUNT(user_id) FROM tbl_users");
    $coun = mysql_result($query_count, 0);

                 $query_city1 = "SELECT * FROM `tbl_city` WHERE `city`='".$_POST['city']."' ";
                 $result_cit1 = mysql_query($query_city1);
                   if(!$result_cit1) puterror2($TEXT['error-tbl1']);
                       $result_city1 = mysql_fetch_array($result_cit1,MYSQL_ASSOC);
                       $res_cit1 = $result_city1['city_id'];

                 $query_street1 = "SELECT * FROM `tbl_street` WHERE `street`='".$_POST['street']."' ";
                 $result_str1 = mysql_query($query_street1);
                   if(!$result_str1) puterror2($TEXT['error-tbl3']);
                       $result_street1 = mysql_fetch_array($result_str1,MYSQL_ASSOC);
                       $res_str1 = $result_street1['str_id'];

                 $query_house1 = "SELECT * FROM `tbl_house` WHERE `house`='".$_POST['house']."' ";
                 $result_hou1 = mysql_query($query_house1);
                   if(!$result_hou1) puterror2($TEXT['error-tbl4']);
                       $result_house1 = mysql_fetch_array($result_hou1,MYSQL_ASSOC);
                       $res_hou1 = $result_house1['house_id'];

                 $query_organizaciya1 = "SELECT * FROM `tbl_organizaciya` WHERE `organizaciya`='".$org."' ";
                 $result_org1 = mysql_query($query_organizaciya1);
                   if(!$result_org1) puterror2($TEXT['error-tbl7']);
                       $result_organizaciya1 = mysql_fetch_array($result_org1,MYSQL_ASSOC);
                       $res_org1 = $result_organizaciya1['org_id'];

                 $query_upravlenie1 = "SELECT * FROM `tbl_upravlenie` WHERE `upravlenie`='".$upr."' ";
                 $result_upr1 = mysql_query($query_upravlenie1);
                   if(!$result_upr1) puterror2($TEXT['error-tbl9']);
                       $result_upravlenie1 = mysql_fetch_array($result_upr1,MYSQL_ASSOC);
                       $res_upr1 = $result_upravlenie1['upr_id'];

                 $query_otdel1 = "SELECT * FROM `tbl_otdel` WHERE `otdel`='".$otd."' ";
                 $result_otd1 = mysql_query($query_otdel1);
                   if(!$result_otd1) puterror2($TEXT['error-tbl8']);
                       $result_otdel1 = mysql_fetch_array($result_otd1,MYSQL_ASSOC);
                       $res_otd1 = $result_otdel1['otd_id'];

                 $query_dolzhnost1 = "SELECT * FROM `tbl_dolzhnost` WHERE `dolzhnost`='".$_POST['post']."' ";
                 $result_dol1 = mysql_query($query_dolzhnost1);
                   if(!$result_dol1) puterror2($TEXT['error-tbl6']);
                       $result_dolzhnost1 = mysql_fetch_array($result_dol1,MYSQL_ASSOC);
                       $res_dol1 = $result_dolzhnost1['dol_id'];

?>
<img alt="<?php echo $TEXT['usr-add-new']; ?>" src= "../img/insert.png" height="15" align="top" /><a class="boldit" href="user_translit.php" title="<?php echo $TEXT['usr-add-new-tit']; ?>"><?php echo $TEXT['usr-add-new']; ?></a>
<form enctype='multipart/form-data' action="<?php echo $action; ?>" method=post>
<table align="center" class="table" border="0" cellpadding="0" cellspacing="0" width="80%">
<tr><td>
<?php
$big = 0;
if($_GET['big'] == 1) $big = 1;
 else
{
 if($_POST['big'] == 1) $big = 1;
  else $big = 0;
}

if($big == 1)
{
echo "<fieldset class='filterr'>";
echo "<legend align='left' title='".$TEXT['log-tit7']."'>".$TEXT['btn_filter']."</legend>";
echo "<table class='table' border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td><a href='index.php?familiya=".$familiya."&amp;name=".$name."&amp;mail=".$mail."&amp;room=".$room."&amp;phonei=".$phonei."&amp;rows=".$rows."&amp;big=0' title='".$TEXT['usr-small-tit']."'><img alt='".$TEXT['usr-small']."' src='../img/minus.png' />".$TEXT['usr-small']."</a></td></tr></table>";
echo "<table class='table' border='0' cellpadding='0' cellspacing='0' width='90%'>";
echo "<tr class='zag2'>";
    echo "<td>".$TEXT['tbl-lastname']."</td>";
    echo "<td>".$TEXT['tbl-name']."</td>";
    echo "<td>".$TEXT['tbl-otch']."</td>";
    echo "<td>".$TEXT['res-field4']."</td>";
echo "</tr>";
echo "<tr><td><input size=20 maxlength=100 type=text name=familiya title='".$TEXT['filter-tit']."' value='".$familiya."'></td>";
    echo "<td><input size=20 maxlength=100 type=text name=name title='".$TEXT['filter-tit2']."' value='".$name."'></td>";
    echo "<td><input size=20 maxlength=100 type=text name=otchestvo title='".$TEXT['filter-tit3']."' value='".$otchestvo."'></td>";
    echo "<td><input size=20 maxlength=100 type=text name=mail title='".$TEXT['filter-tit4']."' value='".$mail."'></td>";
echo "</tr>";
echo "<tr class='zag2'>";
    echo "<td><a href='city.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-city']."</a></td>";
    echo "<td><a href='street.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-str']."</a></td>";
    echo "<td><a href='house.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-house']."</a></td>";
    echo "<td>".$TEXT['usr-field4']."</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><input size=20 maxlength=60 class='inputfilter' type=text name=city title='".$TEXT['filter-tit5']."' value='".$city."'></td>";
    echo "<td><input size=20 maxlength=100 class='inputfilter' type=text name=street title='".$TEXT['filter-tit5']."' value='".$street."'></td>";
    echo "<td><input size=20 maxlength=40 class='inputfilter' type=text name=house title='".$TEXT['filter-tit5']."' value='".$house."'></td>";
    echo "<td><input size=20 maxlength=16 type=text name=room title='".$TEXT['filter-tit6']."' value='".$room."'></td>";
echo "</tr>";
echo "<tr class='zag2'>";
    echo "<td>".$TEXT['tbl-scribe']."</td>";
    echo "<td>".$TEXT['usr-field1']."</td>";
    echo "<td>".$TEXT['usr-field2']."</td>";
    echo "<td>".$TEXT['usr-field3']."</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><input size=20 maxlength=8 type=text name=scribe title='".$TEXT['filter-tit7']."' value='".$scribe."'></td>";
    echo "<td><input size=20 maxlength=30 type=text name=phonem title='".$TEXT['filter-tit8']."' value='".$phonem."'></td>";
    echo "<td><input size=20 maxlength=30 type=text name=phonec title='".$TEXT['filter-tit8']."' value='".$phonec."'></td>";
    echo "<td><input size=20 maxlength=20 type=text name=phonei title='".$TEXT['filter-tit8']."' value='".$phonei."'></td>";
echo "</tr>";
echo "<tr class='zag2'>";
    echo "<td><a href='org.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-org']."</a></td>";
    echo "<td><a href='upr.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-upr']."</a></td>";
    echo "<td><a href='otd.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-otd']."</a></td>";
    echo "<td><a href='post.php?familiya=".$familiya."&amp;name=".$name."&amp;otchestvo=".$otchestvo."&amp;mail=".$mail."&amp;city=".$city."&amp;street=".$street."&amp;house=".$house."&amp;room=".$room."&amp;scribe=".$scribe."&amp;phonem=".$phonem."&amp;phonec=".$phonec."&amp;phonei=".$phonei."&amp;org=".$org."&amp;upr=".$upr."&amp;otd=".$otd."&amp;post=".$post."&amp;visible=".$visible."&amp;big=".$big."' title='".$TEXT['filter-tit11']."'>".$TEXT['tbl-post']."</a></td>";
echo "</tr>";
echo "<tr>";
    echo "<td><input size=20 maxlength=200 class='inputfilter' type=text name=org title='".$TEXT['filter-tit5']."' value='".$org."'></td>";
    echo "<td><input size=20 maxlength=200 class='inputfilter' type=text name=upr title='".$TEXT['filter-tit5']."' value='".$upr."'></td>";
    echo "<td><input size=20 maxlength=140 class='inputfilter' type=text name=otd title='".$TEXT['filter-tit5']."' value='".$otd."'></td>";
    echo "<td><input size=20 maxlength=60 class='inputfilter' type=text name=post title='".$TEXT['filter-tit5']."' value='".$post."'></td>";
echo "</tr>";
echo "<tr class='zag2'>";
    echo "<td>".$TEXT['tbl-visible']."</td><td>".$TEXT['tbl-rows']."</td>";
echo "</tr>";
echo "<tr>";
    echo "<td><input size=20 maxlength=4 type=text name=visible title='".$TEXT['filter-tit9']."' value='".$visible."'></td>";
    echo "<td><input size=11 maxlength=11 type=text name=rows title='".$TEXT['log-tit12']."' value='".$rows."'></td>";
    echo "<td align='right'><input type='hidden' name='big' value=".$big." /><input class='button' type=submit value='".$button."' />";
echo "</td>";
echo "</form>";
echo "<td align='left'>";
echo "<form enctype='multipart/form-data' action='".$action2."' method=post>";
echo "<input class='button' type=submit value='".$button2."'>";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</fieldset>";
}
else
{
echo "<fieldset class='filterr'>";
echo "<legend align='left' title='".$TEXT['log-tit7']."'>".$TEXT['btn_filter']."</legend>";
echo "<table class='table' border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td><a href='index.php?familiya=".$familiya."&amp;name=".$name."&amp;mail=".$mail."&amp;room=".$room."&amp;phonei=".$phonei."&amp;rows=".$rows."&amp;big=1' title='".$TEXT['usr-big-tit']."'><img alt='".$TEXT['usr-big']."' src='../img/plus.png' />".$TEXT['usr-big']."</a></td></tr></table>";
echo "<table class='table' border='0' cellpadding='0' cellspacing='0' width='90%'>";
echo "<tr class='zag2'>";
    echo "<td>".$TEXT['tbl-lastname']."</td>";
    echo "<td>".$TEXT['tbl-name']."</td>";
    echo "<td>".$TEXT['usr-field4']."</td>";
    echo "<td>".$TEXT['usr-field3']."</td>";
    echo "<td>".$TEXT['res-field4']."</td>";
    echo "<td>".$TEXT['tbl-rows']."</td>";
echo "</tr>";
echo "<tr><td><input size=20 maxlength=100 type=text name=familiya title='".$TEXT['filter-tit']."' value='".$familiya."'></td>";
    echo "<td><input size=15 maxlength=100 type=text name=name title='".$TEXT['filter-tit2']."' value='".$name."'></td>";
    echo "<td><input size=10 maxlength=16 type=text name=room title='".$TEXT['filter-tit6']."' value='".$room."'></td>";
    echo "<td><input size=10 maxlength=20 type=text name=phonei title='".$TEXT['filter-tit8']."' value='".$phonei."'></td>";
    echo "<td><input size=15 maxlength=100 type=text name=mail title='".$TEXT['filter-tit4']."' value='".$mail."'></td>";
    echo "<td><input size=8 maxlength=11 type=text name=rows title='".$TEXT['log-tit12']."' value='".$rows."'></td>";
    echo "<td align='right'><input type='hidden' name='big' value=".$big." /><input class='button' type=submit value='".$button."' /></td>";
    echo "</form>";
    echo "<td align='left'>";
    echo "<form enctype='multipart/form-data' action='".$action2."' method=post>";
    echo "<input class='button' type=submit value='".$button2."'>";
    echo "</form>";
    echo "</td>";
    echo "</tr>";
echo "</table>";
echo "</fieldset>";
}
?>
</td></tr>
</table>
</form>
 <br />
 <span class="tabledata"><?php echo $TEXT['usr-text1']; ?></span><span class="boldit"><?php echo $coun; ?></span>
<table class="table" border="1" cellpadding="22" cellspacing="0" width="100%">
<?php
   if(!empty($_POST['familiya'])) $familiya = "AND LOWER(tbl_users.familiya) LIKE LOWER('%".$_POST['familiya']."%') ";
    else $familiya = "";

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

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

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

   if(!empty($_POST['city'])) $city = "AND tbl_users.city_id ='".$res_cit1."' ";
    else $city = "";

   if(!empty($_POST['street'])) $street = "AND tbl_users.str_id ='".$res_str1."' ";
    else $street = "";

   if(!empty($_POST['house'])) $house = "AND tbl_users.house_id ='".$res_hou1."' ";
    else $house = "";

   if(!empty($_POST['room'])) $room = "AND tbl_users.room ='".$_POST['room']."' ";
    else $room = "";

   if(!empty($_POST['scribe'])) $scribe = "AND tbl_users.subscribe ='".$_POST['scribe']."' ";
    else $scribe = "";

   if(!empty($_POST['phonem'])) $phonem = "AND tbl_users.phone_mob LIKE '%".$_POST['phonem']."%' ";
    else $phonem = "";

   if(!empty($_POST['phonec'])) $phonec = "AND tbl_users.phone_city LIKE '%".$_POST['phonec']."%' ";
    else $phonec = "";

   if(!empty($_POST['phonei'])) $phonei = "AND tbl_users.phone_int ='".$_POST['phonei']."' ";
    else $phonei = "";

   if(!empty($_POST['org'])) $org = "AND tbl_users.org_id ='".$res_org1."' ";
    elseif (!empty($_GET['org'])) $org = "AND tbl_users.org_id ='".$res_org1."' ";
      else $org = "";

   if(!empty($_POST['upr'])) $upr = "AND tbl_users.upr_id ='".$res_upr1."' ";
    elseif (!empty($_GET['upr'])) $upr = "AND tbl_users.upr_id ='".$res_upr1."' ";
      else $upr = "";

   if(!empty($_POST['otd'])) $otd = "AND tbl_users.otd_id ='".$res_otd1."' ";
    elseif (!empty($_GET['otd'])) $otd = "AND tbl_users.otd_id ='".$res_otd1."' ";
      else $otd = "";

   if(!empty($_POST['post'])) $post = "AND tbl_users.dol_id ='".$res_dol1."' ";
    else $post = "";

   if(!empty($_POST['visible'])) $visible = "AND tbl_users.visible ='".$_POST['visible']."' ";
    else $visible = "";

     $query = "SELECT 
     tbl_users.visible AS visibl, 
     tbl_users.*, 
     tbl_organizaciya.org_id, 
     tbl_organizaciya.organizaciya, 
     tbl_upravlenie.upr_id, 
     tbl_upravlenie.upravlenie, 
     tbl_otdel.otd_id, 
     tbl_otdel.otdel, 
     tbl_dolzhnost.dol_id, 
     tbl_dolzhnost.dolzhnost  
     FROM tbl_users 
     JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id 
     JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id 
     JOIN tbl_otdel ON tbl_users.otd_id=tbl_otdel.otd_id 
     JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id 
     WHERE tbl_users.user_id != '' ".$familiya." ".$name." ".$otchestvo." ".$mail." ".$city." ".$street." ".$house." ".$room." ".$scribe." ".$phonem." ".$phonec." ".$phonei." ".$org." ".$upr." ".$otd." ".$post." ".$visible." 
     ORDER BY tbl_users.familiya LIMIT ".$rows." ";
     $result = mysql_query($query);
     if(!$result) puterror2($TEXT['error-tbl2']);
       if(mysql_num_rows($result)>0);
         {
	   if(empty($result_users['user_id'])) $result_users['user_id'] = "";
           $href = "index.php?user_id=".$result_users['user_id'];
           ?>
           <tr class="tableheadercat">
            <td><?php echo $TEXT['tbl-fio']; ?></td>
            <td><?php echo $TEXT['tbl-position']; ?></td>
            <td><?php echo $TEXT['tbl-org']; ?></td>
            <td><?php echo $TEXT['tbl-upr']; ?></td>
            <td><?php echo $TEXT['tbl-otd']; ?></td>
            <td><?php echo $TEXT['tbl-post']; ?></td>
            <td colspan=5><?php echo $TEXT['tbl-action']; ?></td>
           </tr>
<?php
             while($result_users = mysql_fetch_array($result,MYSQL_ASSOC))
               {
              if($result_users['visibl'] == 'hide') $strvisible = "<img alt='".$TEXT['tbl-show']."' src='../img/hide.png' height='16' width='16' align='top' /><br /><a href=show.php?user_id=".$result_users['user_id']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;big=".$big." title='".$TEXT['tbl-show-tit10']."'>".$TEXT['tbl-show']."</a>";
                else $strvisible = "<img alt='".$TEXT['tbl-hide']."' src='../img/show.png' height='16' width='16' align='top' /><br /><a href=hide.php?user_id=".$result_users['user_id']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;big=".$big." title='".$TEXT['tbl-hide-tit10']."'>".$TEXT['tbl-hide']."</a>";

              if($result_users['subscribe'] == 'unscribe') $strsubscribe = "<img alt='".$TEXT['tbl-subscribe']."' src='../img/nomail.png' height='16' width='16' align='top' /><br /><a href=scribe.php?user_id=".$result_users['user_id']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;big=".$big." title='".$TEXT['tbl-show-tit11']."'>".$TEXT['tbl-subscribe']."</a>";
                else $strsubscribe = "<img alt='".$TEXT['tbl-unscribe']."' src='../img/mail.png' height='16' width='16' align='top' /><br /><a href=unscribe.php?user_id=".$result_users['user_id']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;big=".$big." title='".$TEXT['tbl-hide-tit11']."'>".$TEXT['tbl-unscribe']."</a>";

              $edit = "<a href=editform.php?user_id=".$result_users['user_id']." title='".$TEXT['tbl-edit-tit-usr']."'>".$TEXT['tbl-edit']."</a>";
              $delete = "<a href=deleteform.php?user_id=".$result_users['user_id']." title='".$TEXT['tbl-delete-tit-usr']."'>".$TEXT['tbl-delete']."</a>";
              $move_up = "<a href=up-down.php?user_id=".$result_users['user_id']."&amp;position=".$result_users['position']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;moving=up&amp;big=".$big." title='".$TEXT['global-up-down-tit']."'><img alt='up' src='../img/up.png' height='16' width='16' align='top' /></a>";
              $move_down = "<a href=up-down.php?user_id=".$result_users['user_id']."&amp;position=".$result_users['position']."&amp;org=".$result_users['organizaciya']."&amp;upr=".$result_users['upravlenie']."&amp;otd=".$result_users['otdel']."&amp;moving=down&amp;big=".$big." title='".$TEXT['global-up-down-tit']."'><img alt='down' src='../img/down.png' height='16' width='16' align='top' /></a>";

                 $res_org = $result_users['organizaciya'];
                 $res_upr = $result_users['upravlenie'];
                 $res_otd = $result_users['otdel'];
                 $res_dol = $result_users['dolzhnost'];

              ?>
           <tr class="tabledata" onmouseover="this.style.backgroundColor='#cccccc';" onmouseout="this.style.backgroundColor='#ffffff';">
              <td><a href# onClick="window.open('../../user.php?user_id=<?php echo $result_users['user_id']; ?>','popup','top=<?php echo $TEXT['user-top']; ?>,left=<?php echo $TEXT['user-left']; ?>,width=<?php echo $TEXT['user-width']; ?>,height=<?php echo $TEXT['user-height']; ?>,status=no,scrollbars=no,location=no,menubar=no,toolbar=no')" title='<?php echo $TEXT['btn_test']; ?>'><?php echo $result_users['familiya']; ?><br /><?php echo $result_users['name']; ?><br /><?php echo $result_users['otchestvo']; ?></a></td>
              <td class="elupr"><?php echo $result_users['position']; ?></td>
              <td class="elupr"><?php echo $res_org; ?></td>
              <td class="elupr"><?php echo $res_upr; ?></td>
              <td class="elupr"><?php echo $res_otd; ?></td>
              <td class="elupr"><?php echo $res_dol; ?></td>
              <td class="elupr"><?php echo $strsubscribe; ?></td>
              <td class="elupr"><?php echo $strvisible; ?></td>
              <td class="elupr"><?php echo $move_up; ?><?php echo $move_down; ?></td>
              <td class="elupr"><?php echo $edit; ?></td>
              <td class="elupr"><?php echo $delete; ?></td>
                 </tr>
              <?php
               }
         }
?>
</table>
<?php
  require_once "../util/bottom.php";
?>