<?php
require("./total.inc");

session_start();
require("./ninsyou.inc");
if(0 > ninsyou_check(5)){
   exit;
   }


echo "<!DOCTYP:pserver:cvs@dhcvs.ms-n.com:/usr/home/cvsE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
echo "<HTML>";
echo "<HEAD>";
echo "<META name='GENERATOR' content='AmBuilder'>";
echo "<META http-equiv='Content-Type' content='text/html; charset=euc-jp'>";


$view_mode = enco($_GET["VIEW_MODE"]);
$view_name = enco($_GET["VIEW_NAME"]);

$ye = enco($_GET["YE"]);
$mo = enco($_GET["MO"]);
$da = enco($_GET["DA"]);
$ha = enco($_GET["HA"]);
$monitor = enco($_GET["MONITOR"]);
$proto = enco($_GET["PROTO"]);
$prino = enco($_GET["PRINO"]);
$port = enco($_GET["PORT"]);
$by = enco($_GET["BY"]);

$ye_ch = enco($_GET["YE_CH"]);
$mo_ch = enco($_GET["MO_CH"]);
$da_ch = enco($_GET["DA_CH"]);
$ha_ch = enco($_GET["HA_CH"]);
$monitor_ch = enco($_GET["MONITOR_CH"]);
$proto_ch = enco($_GET["PROTO_CH"]);
$prino_ch = enco($_GET["PRINO_CH"]);
$port_ch = enco($_GET["PORT_CH"]);

$ncol1 = "bgcolor=#f0f0d2";
$ncol2 = "bgcolor=#d2f0f0";
$acol1 = "bgcolor=#e0e0a0";
$acol2 = "bgcolor=#a0e0e0";
$bcol1 = "bgcolor=#f0c0c0";
$bcol2 = "bgcolor=#c0c0f0";


if(0 != strlen($monitor)){
   if(0 == strcmp("on", $monitor_ch)){
      $select_data = "select * from errlog where " . "monitor != '$monitor'";
      }
   else{ 
      $select_data = "select * from errlog where " . "monitor='$monitor'";
      }
   }
else{
   if(0 == strcmp("on", $monitor_ch)){
      $select_data = "select * from errlog where " . "monitor NOT LIKE '%'";
      }
   else{
      $select_data = "select * from errlog where " . "monitor LIKE '%'";
      }
   }

if(0 != strlen($ye)){
   if(0 == strcmp("on", $ye_ch)){
      $select_data = $select_data . " and ye != '$ye'";
      }
   else{
      $select_data = $select_data . " and ye='$ye'";
      }
   }
if(0 != strlen($mo)){
   if(0 == strcmp("on", $mo_ch)){
      $select_data = $select_data . " and mo != '$mo'";
      }
   else{
      $select_data = $select_data . " and mo='$mo'";
      }
   }
if(0 != strlen($da)){
   if(0 == strcmp("on", $da_ch)){
      $select_data = $select_data . " and da != '$da'";
      }
   else{
      $select_data = $select_data . " and da='$da'";
      }
   }
if(0 != strlen($ha)){
   if(0 == strcmp("on", $ha_ch)){
      $select_data = $select_data . " and ha != '$ha'";
      }
   else{
      $select_data = $select_data . " and ha='$ha'";
      }
   }
if(0 != strlen($proto)){
   if(0 == strcmp("on", $proto_ch)){
      $select_data = $select_data . " and proto != '$proto'";
      }
   else{
      $select_data = $select_data . " and proto = '$proto'";
      }
   }
if(0 != strlen($port)){
   if(0 == strcmp("on", $port_ch)){
      $select_data = $select_data . " and port != '$port'";
      }
   else{
      $select_data = $select_data . " and port = '$port'";
      }
   }
if(0 != strlen($prino)){
   if(0 == strcmp("on", $prino_ch)){
      $select_data = $select_data . " and prino != '$prino'";
      }
   else{
      $select_data = $select_data . " and prino = '$prino'";
      }
   }


echo "<title>zither monitorring save info</title>";
echo "</head>";
echo "<body alink='#ff0000' bgcolor='$my_bgcolor' link='#0000ff' text='#000000' vlink='#000080'>";

echo "<pre>";

echo "<TABLE border=0 bgcolor=FFA500 cellspacing=3 cellpadding=0 width=100%>";
echo "<tr><td align=left><font color=ffffff><b>　情報 -> クライアント別エラー件数</b></font></td></tr>";
echo "</table><br><br>";

print("<font size=1>");
print($version_name);
print("\n");
print(date("Y m d g i s A"));
print("\n");
print($select_data);


$conn = db_connect();
if(!$conn){
   echo "not connection!<br>";
   exit;
   }

$result = db_query($conn, "select distinct(cip) from monitor;");
if(!$result){
   print("bud query\n");
   exit;
   }
$num = db_num_rows($result);
if($num <= 0){
   print("no data\n");
   exit;
   }
else{

   echo "<TABLE border=0  WIDTH=50% height=10% BGCOLOR=$my_bocolor>";

   echo "<tr bgcolor='#D9DBED'>";
   echo "<td>";
   print("監視先のIP及びホスト名");
   echo "</td>";
   echo "<td>";
   print("エラー件数");
   echo "</td>";
   echo "<td>";

   echo "</td>";
   echo "</tr>";


// データ検索
   $count = 0;
   while($s < $num){
      $cip = enco_rtrim(db_fetch_Result($result, $s, cip));

      if(0 != strlen($cip)){
         $select_data_2 = " and cinfo='$cip'";
         }

      $result2 = db_query($conn, "$select_data$select_data_2");
      if(!$result2){
         print("bud query\n");
         exit;
         }
      $num2 = db_num_rows($result2);

      $data_ip[$count] = $cip;
      $data_num2[$count] = $num2;

      db_free_result($result2);
      $num2 = 0;
      $select_data_2 ="";
      $count++;
      $s++;
      }


// データ並び替え(そーと)
   $max = 0;
   $del = 0;
   for($count2 = 1; $count2 < $count; $count2++){
      for($count3 = 0; $count3 < $count; $count3++){
         if($max < $data_num2[$count3]){
            $max = $data_num2[$count3];
            $del = $count3;
            }
         }
      if($max > 0){
         $Data_num2[$count2] = $max;
         $Data_ip[$count2] = $data_ip[$del];
         }
      else{
         $Data_num2[$count2] = $data_num2[$count2];
         $Data_ip[$count2] = $data_ip[$count2];
         }
      $data_num2[$del] = 0;
      $del = 0;
      $max = 0;
      }

// for($count2 = 0; $count2 < $count; $count2++){
//    print("$count2 -> ");
//    print("$Data_num2[$count2] , $Data_ip[$count2]\n");
//    }


// データ表示
   $count2 = 1;
   $size = $Data_num2[$count2] / $by;
   while($count2 < $count){

      echo "<tr bgcolor='#D9DBED'>";
      echo "<td>";
      print($Data_ip[$count2]);
      echo "</td>";
      echo "<td>";
      print($Data_num2[$count2]);
      echo "</td>";
      echo "<td>";

      $width_size = $Data_num2[$count2] / $size;

      if($count2 == 1){
         echo "<img src='../img/red.png' height=10 width=$width_size alt='apoimg'>";
         }
      if($count2 == 2){
         echo "<img src='../img/mag.png' height=10 width=$width_size alt='apoimg'>";
         }
      if($count2 == 3){
         echo "<img src='../img/mag2.png' height=10 width=$width_size alt='apoimg'>";
         }
      if($count2 > 3){
         echo "<img src='../img/blue.png' height=10 width=$width_size alt='apoimg'>";
         }

      $width_size = 0;

      echo "</td>";
      echo "</tr>";

      $count2++;
      }
   echo "</table>";
   }


echo "</font>";

db_free_result($result);
db_Close($conn);

?>
</pre>
<br>
<br>
</body>
</html>


