<?php
require("./total.inc");
require("./count.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'>";


$myutime = date("U");
$settime = $myutime - 86400;
$ncol1 = "bgcolor=#f0f0d2";
$ncol2 = "bgcolor=#d2f0f0";
$acol1 = "bgcolor=#e0e0a0";
$acol2 = "bgcolor=#a0e0e0";
$bcol1 = "bgcolor=#f0c0c0";
$bcol2 = "bgcolor=#c0c0f0";
$kcal1 = "bgcolor=#6de051";
$kcal2 = "bgcolor=#d9c37a";


$BNAME = enco($_GET["BNAME"]);
$BNAME2 = enco($_GET["BNAME2"]);
$CNAME = enco($_GET["CNAME"]);
$CNAME2 = enco($_GET["CNAME2"]);
$MAILTO = enco($_GET["MAILTO"]);
$MAILCC = enco($_GET["MAILCC"]);
$MAILSEND = enco($_GET["MAILSEND"]);
$PLUSTIME = enco($_GET["PLUSTIME"]);
$STAT = enco($_GET["STAT"]);
$STARTTIME = enco($_GET["STARTTIME"]);
$STOPSETTIME = enco($_GET["STOPSETTIME"]);
$FREE1 = enco($_GET["FREE1"]);
$UNO = enco($_GET["UNO"]);

$BNAME_CH = enco($_GET["BNAME_CH"]);
$BNAME2_CH = enco($_GET["BNAME2_CH"]);
$CNAME_CH = enco($_GET["CNAME_CH"]);
$CNAME2_CH = enco($_GET["CNAME2_CH"]);
$MAILTO_CH = enco($_GET["MAILTO_CH"]);
$MAILCC_CH = enco($_GET["MAILCC_CH"]);
$MAILSEND_CH = enco($_GET["MAILSEND_CH"]);
$PLUSTIME_CH = enco($_GET["PLUSTIME_CH"]);
$STAT_CH = enco($_GET["STAT_CH"]);
$STARTTIME_CH = enco($_GET["STARTTIME_CH"]);
$STOPSETTIME_CH = enco($_GET["STOPSETTIME_CH"]);
$FREE1_CH = enco($_GET["FREE1_CH"]);
$UNO_CH = enco($_GET["UNO_CH"]);


if(0 != strlen($CNAME)){
   if(0 == strcmp("on", $CNAME_CH)){
      $select_data = "select * from userblock where " . "cname != '$CNAME'";
      $select_data2 = " where " . "cname != '$CNAME'";
      }
   else{
      $select_data = "select * from userblock where " . "cname = '$CNAME'";
      $select_data2 = " where " . "cname = '$CNAME'";
      }
   }
else{
   if(0 == strcmp("on", $CNAME_CH)){
      $select_data = "select * from userblock where " . "cname NOT LIKE '%'";
      $select_data2 = " where " . "cname NOT LIKE '%'";
      }
   else{
      $select_data = "select * from userblock where " . "cname LIKE '%'";
      $select_data2 = " where " . "cname LIKE '%'";
      }
   }

if(2 < strlen($BNAME2)){
   if(0 == strcmp("on", $BNAME2_CH)){
      $select_data = $select_data . " and bname NOT LIKE '$BNAME2'";
      $select_data2 = $select_data2 . " and bname NOT LIKE '$BNAME2'";
      }
   else{
      $select_data = $select_data . " and bname LIKE '$BNAME2'";
      $select_data2 = $select_data2 . " and bname LIKE '$BNAME2'";
      }
   }
else {
   if(0 != strlen($BNAME)){
      if(0 == strcmp("on", $BNAME_CH)){
         $select_data = $select_data . " and bname != '$BNAME'";
         $select_data2 = $select_data2 . " and bname !='$BNAME'";
         }
      else{
         $select_data = $select_data . " and bname='$BNAME'";
         $select_data2 = $select_data2 . " and bname ='$BNAME'";
         }
      }
   }


if(0 != strlen($STAT)){
   if(0 == strcmp("on", $STAT_CH)){
      $select_data = $select_data . " and stat != '$STAT'";
      $select_data2 = $select_data2 . " and stat !='$STAT'";
      }
   else{
      $select_data = $select_data . " and stat='$STAT'";
      $select_data2 = $select_data2 . " and stat='$STAT'";
      }
   }

if(0 != strlen($MAILSEND)){
   if(0 == strcmp("on", $MAILSEND_CH)){
      $select_data = $select_data . " and mailsend != '$MAILSEND'";
      $select_data2 = $select_data2 . " and mailsend !='$MAILSEND'";
      }
   else{
      $select_data = $select_data . " and mailsend='$MAILSEND'";
      $select_data2 = $select_data2 . " and mailsend='$MAILSEND'";
      }
   }

if(0 != strlen($MAILTO)){
   if(0 == strcmp("on", $MAILTO_CH)){
      $select_data = $select_data . " and mailto NOT LIKE '$MAILTO'";
      $select_data2 = $select_data2 . " and mailto NOT LIKE '$MAILTO'";
      }
   else{
      $select_data = $select_data . " and mailto LIKE '$MAILTO'";
      $select_data2 = $select_data2 . " and mailto LIKE '$MAILTO'";
      }
   }


if(0 != strlen($STARTTIME)){
   if(0 == strcmp("on", $STARTTIME_CH)){
      $select_data = $select_data . " and starttime NOT LIKE '$STARTTIME'";
      $select_data2 = $select_data2 . " and starttime NOT LIKE '$STARTTIME'";
      }
   else{
      $select_data = $select_data . " and starttime LIKE '$STARTTIME'";
      $select_data2 = $select_data2 . " and starttime LIKE '$STARTTIME'";
      }
   }


if(0 != strlen($STOPSETTIME)){
   if(0 == strcmp("on", $STOPSETTIME_CH)){
      $select_data = $select_data . " and stopsettime NOT LIKE '$STOPSETTIME'";
      $select_data2 = $select_data2 . " and stopsettime NOT LIKE '$STOPSETTIME'";
      }
   else{
      $select_data = $select_data . " and stopsettime LIKE '$STOPSETTIME'";
      $select_data2 = $select_data2 . " and stopsettime LIKE '$STOPSETTIME'";
      }
   }



if(0 != strlen($PLUSTIME)){
   if(0 == strcmp("on", $PLUSTIME_CH)){
      $select_data = $select_data . " and plustime !='$PLUSTIME'";
      $select_data2 = $select_data2 . " and plustime !='$PLUSTIME'";
      }
   else{
      $select_data = $select_data . " and plustime ='$PLUSTIME'";
      $select_data2 = $select_data2 . " and plustime ='$PLUSTIME'";
      }
   }

if(0 != strlen($MAILCC)){
   if(0 == strcmp("on", $MAILCC_CH)){
      $select_data = $select_data . " and mailcc NOT LIKE '$MAILCC'";
      $select_data2 = $select_data2 . " and mailcc NOT LIKE '$MAILCC'";
      }
   else{
      $select_data = $select_data . " and mailcc LIKE '$MAILCC'";
      $select_data2 = $select_data2 . " and mailcc LIKE '$MAILCC'";
      }
   }

if(0 != strlen($UNO)){
   if(0 == strcmp("on", $UNO_CH)){
      $select_data = "select * from userblock where " . "uno != $UNO";
      $select_data2 = " where " . "uno != '$UNO'";
      }
   else{
      $select_data = "select * from userblock where " . "uno=$UNO";
      $select_data2 = " where " . "uno = '$UNO'";
      }
   }


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");
echo "このページの使い方は<a href='./block_help.html' target=help>使い方</a> を見てください";
print("\n");
// print("\n");
// print(" select_data > $select_data \n");
// print("\n");
// print(" select_data2 > $select_data2 \n");
// print("\n");


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

//  監視ブロック名リスト作成
$bname_count = 0;
$result = db_query($conn, "select distinct(bname) from userblock;");
if(!$result){
   print("banem select , bud query\n");
   exit;
   }
$num = db_num_rows($result);
if($num > 0){
   while($bname_count < $num){
      $bname_data[$bname_count] = enco_rtrim(db_fetch_Result($result, $bname_count, bname));
      $result1=db_query($conn,"select distinct(cname) from userblock where bname='$bname_data[$bname_count]';");
      if(!$result1){
         print("bname , canem select , bud query\n");
         exit;
         }
      $num1 = db_num_rows($result1);
      if($num1 > 0){
         $cname_data[$bname_count] = enco_rtrim(db_fetch_Result($result1, 0, cname));
         }
      $bname_count++;
      }
   }
else{
   print("NG 監視ブロックが無いです \n");
   }
db_free_result($result);
db_free_result($result1);


// 監視クライアントリストの作成
$cname_count = 0;
$result=db_query($conn,"select distinct(cname) from connection;");
if(!$result){
   print("canem select , bud query\n");
   exit;
   }
$num = db_num_rows($result);
if($num > 0){
   while($cname_count < $num){
      $xcname_data[$cname_count] = enco_rtrim(db_fetch_Result($result, $cname_count, cname));
      $cname_count++;
      }
   }
db_free_result($result);



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

$num = db_num_rows($result);
if($num <= 0){
   print("no data\n");
   exit;
   }



print("\n\n");

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

echo "<tr>"; 
echo "<td $kcal1><font size=1>監視数</font></td>";
echo "<td $kcal1><font size=1>監視Client名</font></td>";
echo "<td $kcal1><font size=1>ブロック名</font></td>";
echo "<td $kcal1><font size=1>メール送信</font></td>";
echo "<td $kcal1><font size=1>実行ステータス</font></td>";
echo "<td $kcal1><font size=1>加算時間</font></td>";
echo "<td $kcal1><font size=1>開始時刻</font></td>";
echo "<td $kcal1><font size=1>停止時刻</font></td>";
echo "<td $kcal1><font size=1>メールTO:</font></td>";
echo "<td $kcal1><font size=1>メールCC:</font></td>";
echo "<td $kcal1><font size=1>情報</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 "<td $kcal2><font size=1>書式(2008:01:1:00:0)</font></td>";
echo "<td $kcal2><font size=1>書式(2008:01:1:00:0)</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>"; 

$kazu = 0;

while($s < $num){
   $YOUNAME = enco_rtrim(db_fetch_Result($result, $s, youname));
   $CNAME = enco_rtrim(db_fetch_Result($result, $s, cname));
   $BNAME = enco_rtrim(db_fetch_Result($result, $s, bname));
   $MAILSEND = enco_rtrim(db_fetch_Result($result, $s, mailsend));
   $STAT = enco_rtrim(db_fetch_Result($result, $s, stat));
   $PLUSTIME = enco_rtrim(db_fetch_Result($result, $s, plustime));
   $STARTTIME = enco_rtrim(db_fetch_Result($result, $s, starttime));
   $STOPSETTIME = enco_rtrim(db_fetch_Result($result, $s, stopsettime));
   $MAILTO = enco_rtrim(db_fetch_Result($result, $s, mailto));
   $MAILCC = enco_rtrim(db_fetch_Result($result, $s, mailcc));
   $FREE1 = enco_rtrim(db_fetch_Result($result, $s, free1));
   $UNO = enco_rtrim(db_fetch_Result($result, $s, uno));

   $pmode = $acol1;
   $moni = monitor_count($BNAME);

   if(0 == strcmp($STAT, "JUST")){
      $pcol = "bgcolor=yellow";
      }
   elseif(0 == strcmp($STAT, "FOR")){
      $pcol = "bgcolor=magenta";
      }
   elseif(0 == strcmp($STAT, "RES")){
      $pcol = "bgcolor=11ff00";
      }
   else{
      $pcol = $acol2;
      }

   if(0 == strcmp($MAILSEND, "OFF")){
      $pcol2 = "bgcolor=red";
      }
   elseif(0 == strcmp($MAILSEND, "MID")){
      $pcol2 = "bgcolor=magenta";
      }
   elseif(0 == strcmp($MAILSEND, "MIX")){
      $pcol2 = "bgcolor=yellow";
      }
   else{
      $pcol2 = $acol1;
      }

   $kazu = $kazu + $moni;

   echo "<td $acol2><a target=_self href=$menucnew?BNAME=$BNAME&CNAME=$CNAME>$moni</td>";
   echo "<td $acol1><a target=_outwind href=$monitorwatch?FREE4=$BNAME>$CNAME</a></td>";
   echo "<td $acol2><a target=_self href=$blocknewedit?BNAME=$BNAME>$BNAME</a></td>";
   echo "<td $pcol2>$MAILSEND</td>";
   echo "<td $pcol>$STAT</td>";
   echo "<td $acol1>$PLUSTIME</td>";
   echo "<td $acol2>$STARTTIME</td>";
   echo "<td $acol1>$STOPSETTIME</td>";
   echo "<td $acol2>$MAILTO</td>";
   echo "<td $acol1>$MAILCC</td>";
   echo "<td $acol2>$FREE1</td>";
   echo "<td $acol1>$UNO</td>";
   $no = $s + 1; 
   echo "<td $acol1>$no</td>";

   echo "</tr>";

   $s++;
   }

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


echo "<FORM METHOD=GET ACTION='userblock_cut_edit.php' target='insert'>";
echo "<tr>";
echo "<td>";
echo "$kazu";
echo "<td\>";

echo "<td align=center>";
echo "<select size=1 name=CNAME class='example'>";
echo "<option value=''>なし";
for($select_count = 0; $select_count < $cname_count; $select_count++){
   echo "<option value=$xcname_data[$select_count]>$xcname_data[$select_count]";
   }
echo "</select>";
echo "</font>";
echo "</td>";

echo "<td>";
echo "not";
echo "<td\>";

echo "<td>";
echo "<select size=1 name=MAILSEND>";
echo "<option value='' selected>編集しない";
echo "<option value=OFF>(OFF)送信停止";
echo "<option value=ON>(ON)送信";
echo "<option value=MID>(MID)間欠モード１";
echo "<option value=MIX>(MIX)間欠モード２";
echo "</select>";
echo "</td>";


echo "<td>";
echo "<select size=1 name=STAT>";
echo "<option value='' selected>編集しない";
echo "<option value=NOT>NOT";
echo "<option value=JUST>JUST";
echo "<option value=FOR>FOR";
echo "<option value=RES>RES";
echo "</select><br>";
echo "</td>";


echo "<td>";
echo "<select size=1 name=PLUSTIME>";
echo "<option value='' selected>編集しない";
echo "<option value=0>0";
echo "<option value=60>1分";
echo "<option value=120>2分";
echo "<option value=180>3分";
echo "<option value=240>4分";
echo "<option value=300>5分";
echo "<option value=360>6分";
echo "<option value=420>7分";
echo "<option value=480>8分";
echo "<option value=540>9分";
echo "<option value=600>10分";
echo "<option value=900>15分";
echo "<option value=1200>20分";
echo "<option value=1500>25分";
echo "<option value=1800>30分";
echo "<option value=2100>35分";
echo "<option value=2400>40分";
echo "<option value=2700>45分";
echo "<option value=3000>50分";
echo "<option value=3300>55分";
echo "<option value=3600>1時間";
echo "</select>";
echo "</td>";


echo "<td>";
echo "<INPUT type='text' NAME=STARTTIME size='20' value='' maxlength=20>";
echo "</td>";


echo "<td>";
echo "<INPUT type='text' NAME=STOPSETTIME size='20' value='' maxlength=20>";
echo "</td>";


echo "<td>";
echo "<INPUT type='text' NAME=MAILTO size='20' value=''>";
echo "</td>";


echo "<td>";
echo "<INPUT type='text' NAME=MAILCC size='20' value=''>";
echo "</td>";


echo "<td>";
echo "<INPUT type='text' NAME=FREE1 size='20' value=''>";
echo "</td>";


echo "</tr>";
echo"</table>";

echo"<table>";
echo "<tr>";
echo "<td>";

$select_data_put = urlencode($select_data2);
echo "<INPUT type='hidden' NAME=SELECT size='0' value='$select_data_put'>";
echo "<INPUT type='hidden' NAME=GEN value='taro'>";
echo "<input type=submit value='検索内容編集(注！要確認)'>";
echo "</td>";
echo "</tr>";
echo "</FORM>";

echo"</table>";

echo "監視数: $kazu  ブロック数: $no";

echo "\n";



?>

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


