<?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['menu-btn34-title'];

  require_once "../config_sams.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_sams.php";

  $button = $TEXT['btn_run'];
  $action = "sams_upd.php";
  $button2 = $TEXT['btn-next'];
  $action2 = "index.php";
  $action3 = "../podset/newoneform.php?a=".$_GET['a']."&amp;descr=".$_GET['descr']."&amp;pods_id=".$_GET['pods_id']."";
  
  if(strlen($_GET['descr'])>255) {puterror($result2['skin'],$TEXT['error-addr3']); require_once "../utils/bottom_sams.php"; exit();}
  if(strlen($_GET['ip'])>15) {puterror($result2['skin'],$TEXT['error-addr5']); require_once "../utils/bottom_sams.php"; exit();}
  if(strlen($_GET['a'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}

  $_GET['descr'] = rep($_GET['descr']);
  $_GET['ip'] = rep($_GET['ip']);
  $_GET['ip_old'] = rep($_GET['ip_old']);

  if($_GET['ip'] !== $_GET['ip_old']) {$ipcomp = "<td align='right'><img alt='".$TEXT['addr-vkluchit']."' src='../skins/".$skin_tmp."/warn.png' /> <span class='upd_bld'>".$TEXT['addr-move-sams']."&nbsp;".$_GET['ip_old']." &rArr; ".$_GET['ip']."</span></td>";}
   else {$ipcomp = "";}

?>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr><td class="bold_it"><?php echo $TEXT['grp-addr-del1']; ?> - <?php echo $_GET['ip']; ?> (<?php echo $_GET['descr']; ?>)</td><?php echo $ipcomp; ?></tr>
</table>
<?php
     $query_body = "SELECT `id`, `ip`, `nick`, `name`, `family`, `soname`, `enabled`, `quotes`, `size`, `domain` FROM squidctrl.squidusers WHERE ip = '".$_GET['ip_old']."' ORDER BY `ip` ";
     $result_body = mysqli_query($dbcnx,$query_body);
     if(!$result_body) {echo mysqli_error($dbcnx); require_once "../utils/bottom_sams.php"; exit();}
      $result_rows2 = mysqli_num_rows($result_body);
       if($result_rows2 > 0)
        {
           echo "<form enctype='multipart/form-data' action=".$action." method=post>
         <table align='center' border='0' cellpadding='0' cellspacing='0' width='90%'>
         <tr>
         <td>
         <table align='center' border='1' cellpadding='3' cellspacing='0' width='100%'>
         <thead><tr class='tableheadercat'>
            <td>".$TEXT['srv-vkl-tit']."</td>
            <td>".$TEXT['addr-ip-addr']."</td>
            <td>".$TEXT['login-login']."</td>
            <td>".$TEXT['menu-btn12']."</td>
            <td>".$TEXT['login-fullname']."</td>
            <td>".$TEXT['ondisk_dost']." / ".$TEXT['ondisk_use']."</td>
            <td>".$TEXT['grp-addr-vibran']."</td>
            </tr></thead><tbody id='tab'>";

           while($result_body_addr = mysqli_fetch_array($result_body,MYSQLI_ASSOC))
               {

              $online = "<img alt='".$TEXT['addr-vikluchit']."' src='../skins/".$skin_tmp."/online.png' />";
              $offline = "<img alt='".$TEXT['addr-vkluchit']."' src='../skins/".$skin_tmp."/offline.png' />";
              $warn = "<img alt='".$TEXT['addr-vkluchit']."' src='../skins/".$skin_tmp."/warn.png' />";
              $ip_id = $result_body_addr['id'];

              $size = round($result_body_addr['size']/1024/1024);
              $size = $size." ".$TEXT['size-mb'];

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

              if($size > intval($result_body_addr['quotes']) && intval($result_body_addr['quotes']) !== 0) {$strvisible = $warn;}
              $fio = trim($result_body_addr['family']." ".$result_body_addr['name']." ".$result_body_addr['soname']);
              if($fio == "") {$fio = "---";}
               else {$fio = $fio;}

           ?>
           <tr>
              <td><?php echo $strvisible; ?></td>
              <td><?php echo $result_body_addr['ip']; ?></td>
              <td><?php echo $result_body_addr['nick']; ?></td>
              <td><?php echo $result_body_addr['domain']; ?></td>
              <td><?php echo $fio; ?></td>
              <td><?php echo $result_body_addr['quotes']; ?> <?php echo $TEXT['size-mb']; ?> / <?php echo $size; ?></td>
              <td>
                  <input type="checkbox" name=ip[<?php echo $ip_id; ?>]>
              </td>
           </tr>
           <?php
               }
         }
          else
         {
         if($_GET['a'] == "3") {echo "<form enctype='multipart/form-data' action=".$action3." method=post>";}
           else {echo "<form enctype='multipart/form-data' action=".$action2." method=post>";}

         echo "<table align='center' border='0' cellpadding='0' cellspacing='0' width='90%'>
         <tr>
         <td>
         <table align='center' border='1' cellpadding='3' cellspacing='0' width='100%'>
         <thead><tr class='tableheadercat'>
            <td>".$TEXT['srv-vkl-tit']."</td>
            <td>".$TEXT['addr-ip-addr']."</td>
            <td>".$TEXT['login-login']."</td>
            <td>".$TEXT['menu-btn12']."</td>
            <td>".$TEXT['login-fullname']."</td>
            <td>".$TEXT['ondisk_dost']." / ".$TEXT['ondisk_use']."</td>
            <td>".$TEXT['grp-addr-vibran']."</td>
            </tr></thead><tbody id='tab'>";

         ?>
         <tr><td colspan="7" class="bold_it"><?php echo $TEXT['search-err4']; ?></td></tr>
         <?php
         }        
?>
</tbody>
<tfoot>
<tr class='tableheadercat'>
<td colspan="7" align="right"><?php echo $TEXT['addr-found']; ?><?php echo $result_rows2; ?><?php echo $TEXT['addr-found-obg']; ?></td>
</tr>
</tfoot>
</table>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="descr" value="<?php echo $_GET['descr']; ?>" />
<input type="hidden" name="a" value="<?php echo $_GET['a']; ?>" />
<input type="hidden" name="skin" value="<?php echo $skin_tmp; ?>" />
<input type="hidden" name="ipclnt" value="<?php echo $_GET['ip']; ?>" />
<input type="hidden" name="pods_id" value="<?php echo $_GET['pods_id']; ?>" />
<?php
if($result_rows2 > 0) {echo "<input class='button' type=submit value='".$button."' />";}
 else {echo "<input class='button' type=submit value='".$button2."' />";}
?>
</td>
</tr>
</table>
</form>
<?php
  require_once "../utils/bottom_sams.php";
?>