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

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

  $title=$titlepage=$TEXT['global-title'];

  require_once "config.php";
  require_once "utils/top_otd.php"; 
?>
<table class="table" border="0" cellpadding="1" cellspacing="1" width=85%>
<?php
  if(strlen($_GET['otd_id'])>20) puterror($TEXT['error-otd']);
  if(strlen($_GET['org_id'])>20) puterror($TEXT['error-org']);
  if(strlen($_GET['upr_id'])>20) puterror($TEXT['search-err10']);
  $_GET['otd_id'] = rep($_GET['otd_id']);
  $_GET['org_id'] = rep($_GET['org_id']);
  $_GET['upr_id'] = rep($_GET['upr_id']);

$query_org = "SELECT * FROM tbl_organizaciya WHERE org_id = '".$_GET['org_id']."'";
  $organizaciya = mysql_query($query_org);
    if(!$organizaciya) puterror($TEXT['error-tbl7']);
       $org = mysql_fetch_array($organizaciya,MYSQL_ASSOC);
           echo "<tr><td><a class='texttableusrtitl1' href=upravlenie.php?org_id=".$_GET['org_id']." title='".$TEXT['menu-btn10']."'>".$org['organizaciya']."</a></td></tr>";

$query_upr = "SELECT * FROM tbl_upravlenie WHERE upr_id = '".$_GET['upr_id']."'";
    $upravlenie = mysql_query($query_upr);
    if(!$upravlenie) puterror($TEXT['error-tbl9']);
      $upr = mysql_fetch_array($upravlenie,MYSQL_ASSOC);
       echo "<tr><td>&nbsp;<a class='texttableusrtitl2' href=upravlenie_podr.php?org_id=".$_GET['org_id']."&amp;upr_id=".$_GET['upr_id']." title='".$TEXT['menu-btn10']."'>".$TEXT['top-upr'].$upr['upravlenie']."</a></td></tr>";

  $query1 = "SELECT otdel, phone FROM tbl_otdel WHERE otd_id = '".$_GET['otd_id']."' ";
                      $otdel = mysql_query($query1);
                        if(!$otdel) puterror($TEXT['error-tbl8']);
                          $otd = mysql_fetch_array($otdel,MYSQL_ASSOC);
                          if($otd['phone'] !== "") $phone="<span class='phoneotd'>(".$TEXT['search-int-phone']." - ".$otd['phone'].")</span>";
                           else $phone = "";
                           echo "<tr>
                                 <td class='texttableusrtit'>&nbsp;&nbsp;".$TEXT['top-otd'].$otd['otdel']."&nbsp;".$phone."&nbsp;<a href=upravlenie_podr_prn.php?org_id=".$_GET['org_id']."&amp;upr_id=".$_GET['upr_id']."&amp;otd_id=".$_GET['otd_id']." target=_blank title='".$TEXT['kat-edit-tit']."'><img alt='".$TEXT['tbl-edit']."' src='img/printer.png' height='16' width='16' align='bottom' /></a></td>
                                 </tr>";

  $query2 = "SELECT tbl_users.user_id, tbl_users.dol_id, tbl_users.org_id, tbl_users.upr_id, tbl_users.name, tbl_users.familiya,  tbl_users.otchestvo, tbl_users.phone_city, tbl_users.phone_int, tbl_dolzhnost.dolzhnost, tbl_organizaciya.organizaciya,  tbl_upravlenie.upravlenie 
FROM tbl_users 
JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id 
JOIN tbl_organizaciya ON tbl_users.org_id=tbl_organizaciya.org_id 
JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id 
WHERE tbl_users.otd_id = '".$_GET['otd_id']."' AND tbl_users.org_id = '".$_GET['org_id']."' AND tbl_users.upr_id = '".$_GET['upr_id']."' AND tbl_users.visible = 'show' ORDER BY tbl_users.position";
  $users = mysql_query($query2);
         if(!$users) puterror($TEXT['error-tbl2']);
          if(mysql_num_rows($users)==0) echo "<tr align='left'><td>".$TEXT['error-empty-otd']."</td></tr>";
            while($user = mysql_fetch_array($users,MYSQL_ASSOC))
            {
            ?>
            <tr align=left>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href=# onClick="window.open('user.php?user_id=<?php echo $user['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['search-org']; ?> <?php echo $user['organizaciya']; ?> / <?php echo $TEXT['search-upr']; ?> <?php echo $user['upravlenie']; ?>"><span class="phoneusr"><?php echo $user['familiya']; ?> <?php echo $user['name']; ?> <?php echo $user['otchestvo']; ?></span></a><span class="phoneotd"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<?php echo $TEXT['search-dol']; ?> <?php echo $user['dolzhnost']; ?> <?php echo $TEXT['msg-alf5']; ?> <?php echo $user['phone_city']; ?> <?php echo $TEXT['msg-alf6']; ?> <?php echo $user['phone_int']; ?>)</span></td>
            </tr>
            <?php
            }
?>
</table>
</div>
<?php
  require_once "utils/bottom.php";
 ?>