<?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_upr.php";
?>
<table class="table" border="0" cellpadding="0" cellspacing="0" width="85%">
<?php
  if(strlen($_GET['org_id'])>20) puterror($TEXT['error-org']);
  $_GET['org_id'] = rep($_GET['org_id']);

  $query1 = "SELECT * FROM tbl_organizaciya WHERE org_id = '".$_GET['org_id']."'";
  $organizaciya = mysql_query($query1);
    if(!$organizaciya) puterror($TEXT['error-tbl7']);
       $org = mysql_fetch_array($organizaciya,MYSQL_ASSOC);
           echo "<tr><td class='texttableusrtit'>".$org['organizaciya']."&nbsp;<a href=upravlenie_podr_prn.php?org_id=".$_GET['org_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>";
                      $query7 = "SELECT * FROM tbl_upravlenie WHERE upravlenie = '-'";
                      $upravlenie7 = mysql_query($query7);
                        if(!$upravlenie7) puterror($TEXT['error-tbl9']);
                          while($upr7 = mysql_fetch_array($upravlenie7,MYSQL_ASSOC))
                          {
                           $query8 = "SELECT
                           tbl_users.user_id,
                           tbl_users.familiya,
                           tbl_users.name,
                           tbl_users.otchestvo,
                           tbl_users.dol_id,
                           tbl_users.phone_city,
                           tbl_users.phone_int,
                           tbl_dolzhnost.dolzhnost
                           FROM tbl_users
                           JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
                           WHERE tbl_users.org_id = '".$_GET['org_id']."' AND tbl_users.upr_id = '".$upr7['upr_id']."' AND tbl_users.visible = 'show'
                           ORDER BY tbl_users.position, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo  ";
                       $users8 = mysql_query($query8);
                       if(!$users8) puterror($TEXT['error-tbl2']);
                         while($user8 = mysql_fetch_array($users8,MYSQL_ASSOC))
                           {
                          $res_dol8 = $user8['dolzhnost'];
			?>
                        <tr>
                         <td class="userpage">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=# onClick="window.open('user.php?user_id=<?php echo $user8['user_id']; ?>','ee','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,directories=no')"><span class="phoneusr"><?php echo $user8['familiya']; ?> <?php echo $user8['name']; ?> <?php echo $user8['otchestvo']; ?></span></a><span class="phoneotd"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<?php echo $TEXT['search-dol']; ?> <?php echo $res_dol8; ?> <?php echo $TEXT['msg-alf5']; ?> <?php echo $user8['phone_city']; ?> <?php echo $TEXT['msg-alf6']; ?> <?php echo $user8['phone_int']; ?>)</span></td>
                        </tr>
			<?php
                           }
                         }

             $query = "SELECT 
                 DISTINCT tbl_users.upr_id,
                 tbl_upravlenie.position AS upr_pos,
                 tbl_upravlenie.upravlenie
                 FROM tbl_users
                 JOIN tbl_upravlenie ON tbl_users.upr_id=tbl_upravlenie.upr_id
                 WHERE tbl_users.org_id = '".$_GET['org_id']."' AND  tbl_upravlenie.visible = 'show' ORDER BY upr_pos,  tbl_upravlenie.upravlenie";
               $tmp_upr = mysql_query($query);
                 if(!$tmp_upr) puterror($TEXT['error-tbl2']);
                     while($upr_res = mysql_fetch_array($tmp_upr,MYSQL_ASSOC))
                       if(mysql_num_rows($tmp_upr)==0) echo "<tr><td class='about'>".$TEXT['error-empty-doc']."</td></tr>";
                         else
                         {
                          echo "<tr>
                                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='support4' href='upravlenie_podr.php?org_id=".$org['org_id']."&amp;upr_id=".$upr_res['upr_id']."'>".$TEXT['top-upr'].$upr_res['upravlenie']."</a></td>
                                </tr>";

                      $query3 = "SELECT * FROM tbl_otdel WHERE otdel = '-'";
                      $otdel1 = mysql_query($query3);
                        if(!$otdel1) puterror($TEXT['error-tbl8']);
                          while($otd1 = mysql_fetch_array($otdel1,MYSQL_ASSOC))
                          {
                           $user_otd = $otd1['otd_id'];

                           $query4 = "SELECT
                           tbl_users.user_id,
                           tbl_users.familiya,
                           tbl_users.name,
                           tbl_users.otchestvo,
                           tbl_users.dol_id,
                           tbl_users.phone_city,
                           tbl_users.phone_int,
                           tbl_dolzhnost.dolzhnost
                           FROM tbl_users
                           JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
                           WHERE tbl_users.otd_id = '$user_otd' AND tbl_users.org_id = '".$_GET['org_id']."' AND tbl_users.upr_id = '".$upr_res['upr_id']."' AND tbl_users.visible = 'show'
                           ORDER BY tbl_users.position, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo ";
                       $users = mysql_query($query4);
                       if(!$users) puterror($TEXT['error-tbl2']);
                         while($user = mysql_fetch_array($users,MYSQL_ASSOC))
                           {
                          $res_dol = $user['dolzhnost'];
			?>
                        <tr>
                        <td class="userpage">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=# onClick="window.open('user.php?user_id=<?php echo $user['user_id']; ?>','ee','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,directories=no')" ><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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<?php echo $TEXT['search-dol']; ?> <?php echo $res_dol; ?> <?php echo $TEXT['msg-alf5']; ?> <?php echo $user['phone_city']; ?> <?php echo $TEXT['msg-alf6']; ?> <?php echo $user['phone_int']; ?>)</span></td>
                        </tr>
			<?php
                           }
                           }

                 $query6 = "SELECT
                 DISTINCT tbl_users.otd_id,
                 tbl_otdel.position AS otd_pos,
                 tbl_otdel.otdel,
                 tbl_otdel.phone
                 FROM tbl_users
                 JOIN tbl_otdel ON tbl_users.otd_id=tbl_otdel.otd_id
                 WHERE tbl_users.org_id = '".$_GET['org_id']."' AND tbl_users.upr_id = '".$upr_res['upr_id']."' AND tbl_otdel.visible = 'show' ORDER BY otd_pos, tbl_otdel.otdel ";
               $tmp_otd = mysql_query($query6);
                 if(!$tmp_otd) puterror($TEXT['error-tbl2']);
                     while($otd_res = mysql_fetch_array($tmp_otd,MYSQL_ASSOC))
                     {
                      if($otd_res['phone'] !== "") $phone="<span class='phoneotd'>(".$TEXT['search-int-phone']." - ".$otd_res['phone'].")</span>";
                        else $phone = "";
                           echo "<tr>
                                 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='support4' href='otdel.php?otd_id=".$otd_res['otd_id']."&amp;org_id=".$org['org_id']."&amp;upr_id=".$upr_res['upr_id']."'>".$TEXT['top-otd'].$otd_res['otdel']."&nbsp;".$phone."</a></td>
                                 </tr>";
                     }
             }
?>
</table>
</div>
<?php
  require_once "utils/bottom.php";
?>