<?php
  ///////////////////////////////////////////////////
  //2010 (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 = $TEXT['upr-title'];

  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm.php";

  if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}
?>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr align="right">
    <td><img alt="<?php echo $TEXT['add-new']; ?>" align="bottom" src="../skins/<?php echo $result2['skin']; ?>/add.png" /><a class="bold_it" href="addform.php" title="<?php echo $TEXT['add-new-tit']; ?>"><?php echo $TEXT['add-new']; ?></a></td>
</tr>
<tr align="right">
    <td><img alt="<?php echo $TEXT['upr-recod']; ?>" align="bottom" src="../skins/<?php echo $result2['skin']?>/pass.png" /><a class="bold_it" href="recodform.php" title="<?php echo $TEXT['upr-recod-tit']; ?>"><?php echo $TEXT['upr-recod']; ?></a></td>
</tr>
</table>
<table align="center" border="1" cellpadding="3" cellspacing="0" width="90%">
<?php
     $query_body = "SELECT 
     tbl_upr.*,
     tbl_srv.srv_id,
     tbl_srv.name AS srv_name,
     tbl_srv.descr AS srv_descr
     FROM tbl_upr
     JOIN tbl_srv ON tbl_upr.srv_id=tbl_srv.srv_id
     ORDER BY tbl_srv.name, tbl_upr.usr ";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {puterror($result2['skin'],$TEXT['error-tbl3']); require_once "../utils/bottom_adm.php"; exit();}
       if(mysqli_num_rows($result_body)>0)
         {
           echo "<thead><tr class='tableheadercat'>
            <td>".$TEXT['srv-name']."</td>
            <td>".$TEXT['upr-type']."</td>
            <td>".$TEXT['user-tit']."</td>
            <td>".$TEXT['srv-vkl-tit']."</td>
            <td colspan=2>".$TEXT['global-action']."</td>
                 </tr></thead><tbody id='tab'>";
             while($result_body_addr = mysqli_fetch_array($result_body,MYSQLI_ASSOC))
               {
              $edit = "<a href=passform.php?addr_id=".$result_body_addr['addr_id']." title='".$TEXT['edit-tit']."'>".$TEXT['edit-new']."</a>";

              $delete_pic = "<img alt='delete' src='../skins/".$result2['skin']."/delete.png' />";
              $delete = $delete_pic."&nbsp;<a href=delete.php?addr_id=".$result_body_addr['addr_id']." title='".$TEXT['delete-tit']."'>".$TEXT['delete-new']."</a>";

              $online = "<img alt='online' src='../skins/".$result2['skin']."/online.png' />";
              $offline = "<img alt='offline' src='../skins/".$result2['skin']."/offline.png' />";
              $edit_pic = "<img alt='edit' src='../skins/".$result2['skin']."/edit.png' />";

              if($result_body_addr['vkl_upr'] == 1) {$vkl = $online;}
                else {$vkl = $offline;}

              if($result_body_addr['vkl_upr'] == '0') {$strvisible = "<a href=on.php?addr_id=".$result_body_addr['addr_id']." title='".$TEXT['srv-vkluchit']."'>".$vkl."</a>";}
                else {$strvisible = "<a href=off.php?addr_id=".$result_body_addr['addr_id']." title='".$TEXT['srv-vikluchit']."'>".$vkl."</a>";}

              if($result_body_addr['comanda'] == "scp") {$comanda = $TEXT['upr-vnesh'];}
                else {$comanda = $TEXT['upr-vnutr'];}

              if(trim($result_body_addr['srv_descr'] !== ""))
              {
           ?>
           <tr>
              <td><?php echo $result_body_addr['srv_name']; ?>&nbsp;(<?php echo $result_body_addr['srv_descr']; ?>)</td>
              <td title="<?php echo $result_body_addr['locpath']; ?>"><?php echo $comanda; ?></td>
              <td><?php echo $result_body_addr['usr']; ?></td>
              <td align="center"><?php echo $strvisible; ?></td>
              <td align="center"><?php echo $edit_pic; ?>&nbsp;<?php echo $edit; ?></td>
              <td align="center"><?php echo $delete; ?></td>
           </tr>
           <?php
              }
              else
              {
             ?>
           <tr>
              <td><?php echo $result_body_addr['srv_name']; ?></td>
              <td><?php echo $comanda; ?></td>
              <td><?php echo $result_body_addr['usr']; ?></td>
              <td align="center"><?php echo $strvisible; ?></td>
              <td align="center"><?php echo $edit_pic; ?>&nbsp;<?php echo $edit; ?></td>
              <td align="center"><?php echo $delete; ?></td>
           </tr>
           <?php
              }
            }
         }
?>
</tbody>
</table>
<?php
  require_once "../utils/bottom_adm.php";
?>