<?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"]);
$mi = enco($_GET["MI"]);
$monitor = enco($_GET["MONITOR"]);
$cname = enco($_GET["CNAME"]);
$cname2 = enco($_GET["CNAME2"]);
$cinfo = enco($_GET["CINFO"]);
$cinfo2 = enco($_GET["CINFO2"]);
$pinfo = enco($_GET["PINFO"]);
$prino = enco($_GET["PRINO"]);
$cip = enco($_GET["CIP"]);
$proto = enco($_GET["PROTO"]);
$com = enco($_GET["COM"]);
$port = enco($_GET["PORT"]);
$free1 = enco($_GET["FREE1"]);
$free4 = enco($_GET["FREE4"]);
$free42 = enco($_GET["FREE42"]);
$errdata = enco($_GET["ERRDATA"]);

$ye_ch = enco($_GET["YE_CH"]);
$mo_ch = enco($_GET["MO_CH"]);
$da_ch = enco($_GET["DA_CH"]);
$ha_ch = enco($_GET["HA_CH"]);
$mi_ch = enco($_GET["MI_CH"]);
$monitor_ch = enco($_GET["MONITOR_CH"]);
$cname_ch = enco($_GET["CNAME_CH"]);
$cname2_ch = enco($_GET["CNAME2_CH"]);
$cinfo_ch = enco($_GET["CINFO_CH"]);
$cinfo2_ch = enco($_GET["CINFO2_CH"]);
$pinfo_ch = enco($_GET["PINFO_CH"]);
$prino_ch = enco($_GET["PRINO_CH"]);
$cip_ch = enco($_GET["CIP_CH"]);
$proto_ch = enco($_GET["PROTO_CH"]);
$com_ch = enco($_GET["COM_CH"]);
$port_ch = enco($_GET["PORT_CH"]);
$free1_ch = enco($_GET["FREE1_CH"]);
$free4_ch = enco($_GET["FREE4_CH"]);
$free42_ch = enco($_GET["FREE42_CH"]);
$errdata_ch = enco($_GET["ERRDATA_CH"]);

$csv_ch = enco($_GET["CSV_CH"]);

$start = enco($_GET["START"]);



$ncol1 = "bgcolor=#f0f0d2";
$ncol2 = "bgcolor=#d2f0f0";
$acol1 = "bgcolor=#e0e0a0";
$acol2 = "bgcolor=#a0e0e0";
$bcol1 = "bgcolor=#f0c0c0";
$bcol2 = "bgcolor=#c0c0f0";
$kcal1 = "bgcolor=#6de051";
$kcal2 = "bgcolor=#d9c37a";


//$auth_user = $_SERVER["PHP_AUTH_USER"];
//$auth_pw = $_SERVER["PHP_AUTH_PW"];


// printf("USERNAME= $user_name\n");
// printf("AUTHUSER= $auth_user\n");

//if(0 != strcmp($auth_user, $user_name)){
//   echo "検索する権限があなたにはありませぬ\n";
//   exit;
//   }
//if(0 != strcmp($auth_user, $free4)){
//   echo "検索する権限があなたにはありませぬ\n";
//   exit;
//   }

if(0 == strcmp($csv_ch, "on")){
   $countdata = 1500;
   }
else{
   $countdata = 50;
   }

$SE="LIKE";
$EE="=";
$AE="NOT";

if(1 < strlen($cname)){
   if(0 == strcmp($cname_ch, "on")){
      $select_data = "select * from errlog where " . "cname" . " != " . "'$cname'";
      $select_data2 = "cname" . " $EE " . "'$cname'";
      }
   else{
      $select_data = "select * from errlog where " . "cname" . " $EE " . "'$cname'";
      $select_data2 = "cname" . " $EE " . "'$cname'";
      }
   }
else if(1 < strlen($cname2)){
   if(0 == strcmp($cname2_ch, "on")){
      $select_data = "select * from errlog where " . "cname" . " NOT LIKE " . "'$cname2'";
      $select_data2 = "cname" . " NOT LIKE " . "'$cname2'";
      }
   else{
      $select_data = "select * from errlog where " . "cname" . " LIKE " . "'$cname2'";
      $select_data2 = "cname" . " LIKE " . "'$cname2'";
      }
   }
else{
   print("not host name?\n");
   $select_data = "select * from errlog where " . "cname" . " $SE " . "'%'";
   $select_data2 = "cname" . " $SE " . "'%'";
   }


if(0 != strlen($monitor)){
   if(0 == strcmp($monitor_ch, "on")){
      $select_data = $select_data . " and monitor !='$monitor'";
      $select_data2 = $select_data2 . " and monitor !='$monitor'";
      }
   else{
      $select_data = $select_data . " and monitor='$monitor'";
      $select_data2 = $select_data2 . " and monitor='$monitor'";
      }
   }
if(0 != strlen($ye)){
   if(0 == strcmp($ye_ch, "on")){
      $select_data = $select_data . " and ye !='$ye'";
      $select_data2 = $select_data2 . " and ye !='$ye'";
      }
   else{
      $select_data = $select_data . " and ye='$ye'";
      $select_data2 = $select_data2 . " and ye='$ye'";
      }
   }
if(0 != strlen($mo)){
   if(0 == strcmp($mo_ch, "on")){
      $select_data = $select_data . " and mo !='$mo'";
      $select_data2 = $select_data2 . " and mo !='$mo'";
      }
   else{
      $select_data = $select_data . " and mo='$mo'";
      $select_data2 = $select_data2 . " and mo='$mo'";
      }
   }
if(0 != strlen($da)){
   if(0 == strcmp($da_ch, "on")){
      $select_data = $select_data . " and da !='$da'";
      $select_data2 = $select_data2 . " and da !='$da'";
      }
   else{
      $select_data = $select_data . " and da='$da'";
      $select_data2 = $select_data2 . " and da='$da'";
      }
   }
if(0 != strlen($ha)){
   if(0 == strcmp($ha_ch, "on")){
      $select_data = $select_data . " and ha !='$ha'";
      $select_data2 = $select_data2 . " and ha !='$ha'";
      }
   else{
      $select_data = $select_data . " and ha='$ha'";
      $select_data2 = $select_data2 . " and ha='$ha'";
      }
   }
if(0 != strlen($mi)){
   if(0 == strcmp($mi_ch, "on")){
      $select_data = $select_data . " and mi !='$mi'";
      $select_data2 = $select_data2 . " and mi !='$mi'";
      }
   else{
      $select_data = $select_data . " and mi='$mi'";
      $select_data2 = $select_data2 . " and mi='$mi'";
      }
   }
if(0 != strlen($prino)){
   if(0 == strcmp($prino_ch, "on")){
      $select_data = $select_data . " and prino !='$prino'";
      $select_data2 = $select_data2 . " and prino !='$prino'";
      }
   else{
      $select_data = $select_data . " and prino='$prino'";
      $select_data2 = $select_data2 . " and prino='$prino'";
      }
   }
if(0 != strlen($proto)){
   if(0 == strcmp($proto_ch, "on")){
      $select_data = $select_data . " and proto !='$proto'";
      $select_data2 = $select_data2 . " and proto !='$proto'";
      }
   else{
      $select_data = $select_data . " and proto='$proto'";
      $select_data2 = $select_data2 . " and proto='$proto'";
      }
   }
if(0 != strlen($pinfo)){
   if(0 == strcmp($pinfo_ch, "on")){
      $select_data = $select_data . " and pinfo NOT LIKE '$pinfo'";
      $select_data2 = $select_data2 . " and pinfo NOT LIKE '$pinfo'";
      }
   else{
      $select_data = $select_data . " and pinfo LIKE '$pinfo'";
      $select_data2 = $select_data2 . " and pinfo LIKE '$pinfo'";
      }
   }
if(0 != strlen($cip)){
   if(0 == strcmp($cip_ch, "on")){
      $select_data = $select_data . " and cip !='$cip'";
      $select_data2 = $select_data2 . " and cip !='$cip'";
      }
   else{
      $select_data = $select_data . " and cip ='$cip'";
      $select_data2 = $select_data2 . " and cip ='$cip'";
      }
   }
if(0 != strlen($com)){
   if(0 == strcmp($com_ch, "on")){
      $select_data = $select_data . " and com NOT LIKE '$com'";
      $select_data2 = $select_data2 . " and com NOT LIKE'$com'";
      }
   else{
      $select_data = $select_data . " and com LIKE '$com'";
      $select_data2 = $select_data2 . " and com LIKE '$com'";
      }
   }
if(0 != strlen($port)){
   if(0 == strcmp($port_ch, "on")){
      $select_data = $select_data . " and port !='$port'";
      $select_data2 = $select_data2 . " and port !='$port'";
      }
   else{
      $select_data = $select_data . " and port ='$port'";
      $select_data2 = $select_data2 . " and port ='$port'";
      }
   }
if(0 != strlen($free1)){
   if(0 == strcmp($free1_ch, "on")){
      $select_data = $select_data . " and free1 NOT LIKE '$free1'";
      $select_data2 = $select_data2 . " and free1 NOT LIKE '$free1'";
      }
   else{
      $select_data = $select_data . " and free1 LIKE '$free1'";
      $select_data2 = $select_data2 . " and free1 LIKE '$free1'";
      }
   }
if(0 != strlen($errdata)){
   if(0 == strcmp($errdata_ch, "on")){
      $select_data = $select_data . " and errdata NOT LIKE '$errdata'";
      $select_data2 = $select_data2 . " and errdata NOT LIKE '$errdata'";
      }
   else{
      $select_data = $select_data . " and errdata LIKE '$errdata'";
      $select_data2 = $select_data2 . " and errdata LIKE '$errdata'";
      }
   }


if(0 != strlen($free4)){
   if(0 == strcmp($free4_ch, "on")){
      $select_data = $select_data . " and free4 !='$free4'";
      $select_data2 = $select_data2 . " and free4 !='$free4'";
      }
   else{
      $select_data = $select_data . " and free4 ='$free4'";
      $select_data2 = $select_data2 . " and free4 ='$free4'";
      }
   }
else if(0 != strlen($free42)){
   if(0 == strcmp($free42_ch, "on")){
      $select_data = $select_data . " and free4 NOT LIKE '$free42'";
      $select_data2 = $select_data2 . " and free4 NOT LIKE '$free42'";
      }
   else{
      $select_data = $select_data . " and free4 LIKE '$free42'";
      $select_data2 = $select_data2 . " and free4 LIKE '$free42'";
      }
   }
else{
   $select_data = $select_data . " and free4 LIKE '%'";
   $select_data2 = $select_data2 . " and free4 LIKE '%'";
   }

if(0 != strlen($cinfo)){
   if(0 == strcmp($cinfo_ch, "on")){
      $select_data = $select_data . " and cinfo !='$cinfo'";
      $select_data2 = $select_data2 . " and cinfo !='$cinfo'";
      }
   else{
      $select_data = $select_data . " and cinfo ='$cinfo'";
      $select_data2 = $select_data2 . " and cinfo ='$cinfo'";
      }
   }
else if(0 != strlen($cinfo2)){
   if(0 == strcmp($cinfo2_ch, "on")){
      $select_data = $select_data . " and cinfo NOT LIKE '$cinfo2'";
      $select_data2 = $select_data2 . " and cinfo NOT LIKE '$cinfo2'";
      }
   else{
      $select_data = $select_data . " and cinfo LIKE '$cinfo2'";
      $select_data2 = $select_data2 . " and cinfo LIKE '$cinfo2'";
      }
   }
else{
   $select_data = $select_data . " and cinfo LIKE '%'";
   $select_data2 = $select_data2 . " and cinfo LIKE '%'";
   }


// 新しい順に表示
$select_data = $select_data . " order by uct desc";

if(0 != strlen($select_data2)){
   $select_data2_encode = urlencode($select_data2);
   }
if(0 != strlen($select_data)){
   $select_data_encode = urlencode($select_data);
   }

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 \n");
// print("delete from errlog where $select_data2 \n");

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

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

$num = db_num_rows($result);



$s = 0;
$stop = $start + $countdata;
$s = $start;

echo "\n";
echo "全ヒット数 $num 中 $start 〜 $stop を新しいデータ順に表示しています \n";




if($num <= 0){
   print("検索された条件のエラーログはありませんでした\n");
   exit;
   }
if($num <= ($stop - $countdata)){
   print("全て表示済みです、再度検索しなおしてください。\n");
   exit;
   }


// header("content-type: application/oted-streem");
print("\n\n");


if(0 == strcmp($csv_ch, "on")){

   echo "<pre>";
   echo "NO, MO/DA HA:MI:SE, 正逆, プロトコル, コマンド, IP|HOST, ポート, 待ち時間, 監視対象情報, 重要度, 監視情報, クライアントVr, エラー情報, ブロック名\n";

   while($s < $num && $s < $stop){

      $CIP = enco_rtrim(db_fetch_Result($result, $s, cip));
      $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
      $MONITOR = enco_rtrim(db_fetch_Result($result, $s, monitor));
      $UCT = enco_rtrim(db_fetch_Result($result, $s, uct));
      $YE = enco_rtrim(db_fetch_Result($result, $s, ye));
      $MO = enco_rtrim(db_fetch_Result($result, $s, mo));
      $DA = enco_rtrim(db_fetch_Result($result, $s, da));
      $HA = enco_rtrim(db_fetch_Result($result, $s, ha));
      $MI = enco_rtrim(db_fetch_Result($result, $s, mi));
      $SE = enco_rtrim(db_fetch_Result($result, $s, se));
      $SIGN = enco_rtrim(db_fetch_Result($result, $s, sign));
      $PROTO = enco_rtrim(db_fetch_Result($result, $s, proto));
      $COM = enco_rtrim(db_fetch_Result($result, $s, com));
      $CINFO = enco_rtrim(db_fetch_Result($result, $s, cinfo));
      $PORT = enco_rtrim(db_fetch_Result($result, $s, port));
      $WTIME = enco_rtrim(db_fetch_Result($result, $s, wtime));
      $PINFO = enco_rtrim(db_fetch_Result($result, $s, pinfo));
      $ERRDATA = enco_rtrim(db_fetch_Result($result, $s, errdata));
      $PRINO = enco_rtrim(db_fetch_Result($result, $s, prino));
      $FREE1 = enco_rtrim(db_fetch_Result($result, $s, free1));
      $FREE2 = enco_rtrim(db_fetch_Result($result, $s, free2));
      $FREE3 = enco_rtrim(db_fetch_Result($result, $s, free3));
      $FREE4 = enco_rtrim(db_fetch_Result($result, $s, free4));
      $UNO = enco_rtrim(db_fetch_Result($result, $s, uno));

      $ERR = strtr($ERRDATA, "\n", "||");
      $SS = $s + 1;

      echo "$SS, $MO/$DA $HA:$MI:$SE, $SIGN, $PROTO, $COM, $CINFO, $PORT, $WTIME, $PINFO, $PRINO, $FREE1, $FREE2, $ERR, $FREE4\n";

      $s++;
      }

   echo "</pre>";
   }


else {
   echo "<TABLE border=0  WIDTH=80% height=1% BGCOLOR=$my_bocolor>";

   echo "<tr>";
   echo "<td $kcal1><font size=1>観測時間</font></td>";
   echo "<td $kcal1><font size=1>監視先のIP</font></td>";
   echo "<td $kcal1><font size=1>監視属性</font></td>";
   echo "<td $kcal1><font size=1>Info & command & Protocol</font></td>";
   echo "<td $kcal1><font size=1>検索番号</font></td>";
   echo "<td $kcal1><font size=1>監視ブロック名</font></td>";
   echo "</tr>";
   echo "<tr>";
   echo "<td $kcal2><font size=1>監視設定<font></td>";
   echo "<td $kcal2><font size=1>*</font></td>";
   echo "<td $kcal2><font size=1>エラー詳細表示</font></td>";
   echo "<td $kcal2><font size=1>*</font></td>";
   echo "<td $kcal2><font size=1>*</font></td>";
   echo "<td $kcal2><font size=1></font>ツリー（ブロック単位）</td>";
   echo "</tr>";

   while($s < $num && $s < $stop){
      $CIP = enco_rtrim(db_fetch_Result($result, $s, cip));
      $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
      $MONITOR = enco_rtrim(db_fetch_Result($result, $s, monitor));
      $UCT = enco_rtrim(db_fetch_Result($result, $s, uct));
      $YE = enco_rtrim(db_fetch_Result($result, $s, ye));
      $MO = enco_rtrim(db_fetch_Result($result, $s, mo));
      $DA = enco_rtrim(db_fetch_Result($result, $s, da));
      $HA = enco_rtrim(db_fetch_Result($result, $s, ha));
      $MI = enco_rtrim(db_fetch_Result($result, $s, mi));
      $SE = enco_rtrim(db_fetch_Result($result, $s, se));
      $SIGN = enco_rtrim(db_fetch_Result($result, $s, sign));
      $PROTO = enco_rtrim(db_fetch_Result($result, $s, proto));
      $COM = enco_rtrim(db_fetch_Result($result, $s, com));
      $CINFO = enco_rtrim(db_fetch_Result($result, $s, cinfo));
      $PORT = enco_rtrim(db_fetch_Result($result, $s, port));
      $WTIME = enco_rtrim(db_fetch_Result($result, $s, wtime));
      $PINFO = enco_rtrim(db_fetch_Result($result, $s, pinfo));
      $ERRDATA = enco_rtrim(db_fetch_Result($result, $s, errdata));
      $PRINO = enco_rtrim(db_fetch_Result($result, $s, prino));
      $FREE1 = enco_rtrim(db_fetch_Result($result, $s, free1));
      $FREE2 = enco_rtrim(db_fetch_Result($result, $s, free2));
      $FREE3 = enco_rtrim(db_fetch_Result($result, $s, free3));
      $FREE4 = enco_rtrim(db_fetch_Result($result, $s, free4));
      $UNO = enco_rtrim(db_fetch_Result($result, $s, uno));

      if($PRINO <= 1){
         $pcol = "bgcolor=red";
         } 
      else if($PRINO == 2){
         $pcol = "bgcolor=magenta";
         } 
      else if($PRINO == 3){
         $pcol = "bgcolor=green";
         }
      else if($PRINO == 4){
         $pcol = "bgcolor=orengi";
         }
      else if($PRINO == 5){
         $pcol = "bgcolor='#ffff99'";
         }
      else if($PRINO == 6){
         $pcol = "bgcolor='#ffff99'";
         }
      else if($PRINO == 11){
         $pcol = "bgcolor='#cc0099'";
         }
      else if($PRINO == 12){
         $pcol = "bgcolor='#9900ff'";
         }
      else if($PRINO == 13){
         $pcol = "bgcolor='#99cc00'";
         }
      else{
         $pcol = "bgcolor=cyan";
         }








         echo "<td $pcol><a target=top href=$my_url/monitor_edit.php?UNO=$FREE3&STATUS=UPDATE>$MO/$DA $HA:$MI:$SE</a></td>";
         echo "<td $ncol2>$CINFO</td>";
         echo "<td $ncol1><a target=top href=$detaile?KEY=$UNO>$MONITOR</a></td>";
         if(0 == strcmp($MONITOR, "PORT")){
            if(0 == strcmp($PROTO, "DHW")){
               echo "<td $ncol2>$PROTO($COM)</td>";
               }
            else{
               echo "<td $ncol2>$PROTO(Port $PORT)</td>";
               }
            }
         elseif(0 == strcmp($MONITOR, "SNMP")){
            echo "<td $ncol2>$FREE1</td>";
            }
         else{
            echo "<td $ncol2>$COM</td>";
            }
         echo "<td $ncol1>$s</td>";

      echo "<td $acol2>$FREE4</td>";

      echo "</tr>";

      $s++;
      }

   echo"</table>";

   }

echo "<TABLE border=0  WIDTH=80% height=1% BGCOLOR=$my_bocolor>";
echo "<FORM METHOD=GET ACTION='monitor_select.php' target='top'>";
echo "<tr>";
echo "<td>";
   echo "<font color=red size=2>";
   echo "表示出来なかった次のページの表示  ";
   echo "<INPUT type='hidden' NAME=YE value='$ye'>";
   echo "<INPUT type='hidden' NAME=MO value='$mo'>";
   echo "<INPUT type='hidden' NAME=DA value='$da'>";
   echo "<INPUT type='hidden' NAME=HA value='$ha'>";
   echo "<INPUT type='hidden' NAME=MI value='$mi'>";
   echo "<INPUT type='hidden' NAME=PINFO value='$pinfo'>";
   echo "<INPUT type='hidden' NAME=CNAME value='$cname'>";
   echo "<INPUT type='hidden' NAME=CINFO value='$cinfo'>";
   echo "<INPUT type='hidden' NAME=PORT value='$port'>";
   echo "<INPUT type='hidden' NAME=COM value='$com'>";
   echo "<INPUT type='hidden' NAME=FREE4 value='$free4'>";
   echo "<INPUT type='hidden' NAME=FREE1 value='$free1'>";
   echo "<INPUT type='hidden' NAME=ERRDATA value='$errdata'>";
   echo "<INPUT type='hidden' NAME=MONITOR value='$monitor'>";
   echo "<INPUT type='hidden' NAME=PROTO value='$proto'>";
   echo "<INPUT type='hidden' NAME=PRINO value='$prino'>";
   echo "<INPUT type='hidden' NAME=START value=$stop>";
   echo "<INPUT type='hidden' NAME=CSV_CH value=$csv_ch>";
   echo "<input type=submit value='再読み込み'>";
   echo "</font>";
echo "</td>";
echo "</tr>";
echo "</form>";
echo"</table>";


echo "<TABLE border=0  WIDTH=80% height=1% BGCOLOR=$my_bocolor>";
echo "<FORM METHOD=GET ACTION='kanshi_delete_user.php' target='top'>";
echo "<tr>";
echo "<td>";
   echo "<font color=red size=2>";
   echo "検索されたエラーを削除出来ます   ";
   echo "<INPUT type='hidden' NAME=GEN value='taro'>";
   echo "<INPUT type='hidden' NAME=SELECT value='$select_data2_encode'>";
   echo "<input type=submit value='検索されたエラーログを削除(注！要確認)'>";
   echo "</font>";
echo "</td>";
echo "</tr>";
echo "</form>";

echo"</table>";



print("</font>");

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

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


