<?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";

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

  if(empty($_GET['otd_id']) && !empty($_GET['org_id']) && !empty($_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 class='texttableusrtit'>".$org['organizaciya']."</td></tr>";

   $query2 = "SELECT * FROM tbl_upravlenie WHERE upr_id = '".$_GET['upr_id']."'";
    $upravlenie = mysql_query($query2);
    if(!$upravlenie) puterror($TEXT['error-tbl9']);
     while($upr = mysql_fetch_array($upravlenie,MYSQL_ASSOC))
      {
       echo "<tr><td class='texttableusrtit'>&nbsp;&nbsp;".$TEXT['top-upr'].$upr['upravlenie']."</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_users.phone_mob,
         tbl_users.mail,
         tbl_users.dom_id,
         tbl_dolzhnost.dolzhnost,
         tbl_domain.domain
         FROM tbl_users 
         JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
         JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id
         WHERE tbl_users.otd_id = '$user_otd' 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, 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))
             {
              echo "<tr align=left>";
              echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user['familiya']." ".$user['name']." ".$user['otchestvo']."</span><br />";
              if(!empty($user['dolzhnost']) && $user['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user['dolzhnost']."</span><br />";
              if(!empty($user['phone_mob']) && $user['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user['phone_mob']."</span><br />";
              if(!empty($user['phone_city']) && $user['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user['phone_city']."</span><br />";
              if(!empty($user['phone_int']) && $user['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user['phone_int']."</span><br />";
              if(!empty($user['dom_id']) && $user['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user['mail']."@".$user['domain']."</span><br />";
              echo "</tr>";
              }
        }
    $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 = '".$_GET['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 class='support4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='support4' href='upravlenie_podr_prn.php?otd_id=".$otd_res['otd_id']."&amp;org_id=".$_GET['org_id']."&amp;upr_id=".$_GET['upr_id']."' target=_blank >".$TEXT['top-otd'].$otd_res['otdel']."&nbsp;".$phone."</a></td></tr>";

         $query7 = "SELECT 
             tbl_users.user_id,
             tbl_users.dol_id,
             tbl_users.name,
             tbl_users.familiya,
             tbl_users.otchestvo,
             tbl_users.phone_city,
             tbl_users.phone_int,
             tbl_users.phone_mob,
             tbl_users.mail,
             tbl_users.dom_id,
             tbl_dolzhnost.dolzhnost,
             tbl_domain.domain
             FROM tbl_users
             JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
             JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id
             WHERE tbl_users.otd_id = '".$otd_res['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, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo";
           $users2 = mysql_query($query7);
            if(!$users2) puterror($TEXT['error-tbl2']);
            if(mysql_num_rows($users2)==0) echo "<tr><td class='about'>".$TEXT['error-empty-otd']."</td></tr>";
            while($user2 = mysql_fetch_array($users2,MYSQL_ASSOC))
            {
             echo "<tr align=left>";
             echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user2['familiya']." ".$user2['name']." ".$user2['otchestvo']."</span><br />";
             if(!empty($user2['dolzhnost']) && $user2['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user2['dolzhnost']."</span><br />";
             if(!empty($user2['phone_mob']) && $user2['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user2['phone_mob']."</span><br />";
             if(!empty($user2['phone_city']) && $user2['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user2['phone_city']."</span><br />";
             if(!empty($user2['phone_int']) && $user2['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user2['phone_int']."</span><br />";
             if(!empty($user2['dom_id']) && $user2['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user2['mail']."@".$user2['domain']."</span><br />";
             echo "</tr>";
             }
        }
      }
echo "</table>";
}
elseif(!empty($_GET['otd_id']) && !empty($_GET['org_id']) && !empty($_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 class='texttableusrtit'>".$org['organizaciya']."</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 class='texttableusrtit'>&nbsp;&nbsp;".$TEXT['top-upr'].$upr['upravlenie']."</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;&nbsp;&nbsp;".$TEXT['top-otd'].$otd['otdel']."&nbsp;".$phone."</td>
             </tr>";

  $query2 = "SELECT 
      tbl_users.user_id,
      tbl_users.dol_id,
      tbl_users.name,
      tbl_users.familiya,
      tbl_users.otchestvo,
      tbl_users.phone_city,
      tbl_users.phone_int,
      tbl_users.phone_mob,
      tbl_users.mail,
      tbl_users.dom_id,
      tbl_dolzhnost.dolzhnost,
      tbl_domain.domain
      FROM tbl_users
     JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
     JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_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, tbl_users.familiya, tbl_users.name, tbl_users.otchestvo";
  $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))
      {
     echo "<tr align=left>";
     echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user['familiya']." ".$user['name']." ".$user['otchestvo']."</span><br />";
     if(!empty($user['dolzhnost']) && $user['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user['dolzhnost']."</span><br />";
     if(!empty($user['phone_mob']) && $user['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user['phone_mob']."</span><br />";
     if(!empty($user['phone_city']) && $user['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user['phone_city']."</span><br />";
     if(!empty($user['phone_int']) && $user['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user['phone_int']."</span><br />";
     if(!empty($user['dom_id']) && $user['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user['mail']."@".$user['domain']."</span><br />";
     echo "</tr>";
     }
echo "</table>";
}
elseif(empty($_GET['otd_id']) && !empty($_GET['org_id']) && empty($_GET['upr_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']."</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,
                           tbl_users.phone_mob,
                           tbl_users.mail,
                           tbl_users.dom_id,
                           tbl_domain.domain
                           FROM tbl_users
                           JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
                           JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_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))
                           {
                           echo "<tr align=left>";
                           echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user8['familiya']." ".$user8['name']." ".$user8['otchestvo']."</span><br />";
                           if(!empty($user8['dolzhnost']) && $user8['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user8['dolzhnost']."</span><br />";
                           if(!empty($user8['phone_mob']) && $user8['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user8['phone_mob']."</span><br />";
                           if(!empty($user8['phone_city']) && $user8['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user8['phone_city']."</span><br />";
                           if(!empty($user8['phone_int']) && $user8['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user8['phone_int']."</span><br />";
                           if(!empty($user8['dom_id']) && $user8['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user8['mail']."@".$user8['domain']."</span><br />";
                           echo "</tr>";
                           }
                        }

                $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_prn.php?org_id=".$org['org_id']."&amp;upr_id=".$upr_res['upr_id']."' target=_blank >".$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,
                           tbl_users.phone_mob,
                           tbl_users.mail,
                           tbl_users.dom_id,
                           tbl_domain.domain
                           FROM tbl_users
                           JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
                           JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_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))
                            {
                           echo "<tr align=left>";
                           echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user['familiya']." ".$user['name']." ".$user['otchestvo']."</span><br />";
                           if(!empty($user['dolzhnost']) && $user['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user['dolzhnost']."</span><br />";
                           if(!empty($user['phone_mob']) && $user['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user['phone_mob']."</span><br />";
                           if(!empty($user['phone_city']) && $user['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user['phone_city']."</span><br />";
                           if(!empty($user['phone_int']) && $user['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user['phone_int']."</span><br />";
                           if(!empty($user['dom_id']) && $user['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user['mail']."@".$user['domain']."</span><br />";
                           echo "</tr>";
                            }
                          }
                   $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 class='support4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='support4' href='upravlenie_podr_prn.php?otd_id=".$otd_res['otd_id']."&amp;org_id=".$_GET['org_id']."&amp;upr_id=".$upr_res['upr_id']."' target=_blank >".$TEXT['top-otd'].$otd_res['otdel']."&nbsp;".$phone."</a></td>
                                         </tr>";

                      $query7 = "SELECT 
                          tbl_users.user_id,
                          tbl_users.dol_id,
                          tbl_users.name,
                          tbl_users.familiya,
                          tbl_users.otchestvo,
                          tbl_users.phone_city,
                          tbl_users.phone_int,
                          tbl_users.phone_int,
                           tbl_dolzhnost.dolzhnost,
                           tbl_users.phone_mob,
                           tbl_users.mail,
                           tbl_users.dom_id,
                           tbl_domain.domain
                          FROM tbl_users
                          JOIN tbl_dolzhnost ON tbl_users.dol_id=tbl_dolzhnost.dol_id
                          JOIN tbl_domain ON tbl_users.dom_id=tbl_domain.dom_id
                          WHERE tbl_users.otd_id = '".$otd_res['otd_id']."' 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";
                        $users2 = mysql_query($query7);
                         if(!$users2) puterror($TEXT['error-tbl2']);
                         if(mysql_num_rows($users2)==0) echo "<tr><td class='about'>".$TEXT['error-empty-otd']."</td></tr>";
                          while($user2 = mysql_fetch_array($users2,MYSQL_ASSOC))
                           {
                           echo "<tr align=left>";
                           echo "<td class='userpage'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneusr'>".$user2['familiya']." ".$user2['name']." ".$user2['otchestvo']."</span><br />";
                           if(!empty($user2['dolzhnost']) && $user2['dolzhnost']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['search-dol']."</span>&nbsp;<span class='userpage'>".$user2['dolzhnost']."</span><br />";
                           if(!empty($user2['phone_mob']) && $user2['phone_mob']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-mob']."</span>&nbsp;<span class='userpage'>".$user2['phone_mob']."</span><br />";
                           if(!empty($user2['phone_city']) && $user2['phone_city']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-city']."</span>&nbsp;<span class='userpage'>".$user2['phone_city']."</span><br />";
                           if(!empty($user2['phone_int']) && $user2['phone_int']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-tel-int']."</span>&nbsp;<span class='userpage'>".$user2['phone_int']."</span><br />";
                           if(!empty($user2['dom_id']) && $user2['domain']!=="-") echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='phoneotd'>".$TEXT['user-e-mail']."</span>&nbsp;<span class='userpage'>".$user2['mail']."@".$user2['domain']."</span><br />";
                           echo "</tr>";
                           }
                    }
                }
echo "</table>";
}
require_once "utils/bottom.php";
?>