summaryrefslogtreecommitdiffstats
path: root/frontends/php/report4.php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-23 07:34:27 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-23 07:34:27 +0000
commit28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89 (patch)
tree8281ccd48964ee0dd11c5ea689091fa3cef706fb /frontends/php/report4.php
parent495799b2aa61aab23d74d7faa110a0cd09d59bf0 (diff)
- developed group permission system (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3371 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/report4.php')
-rw-r--r--frontends/php/report4.php542
1 files changed, 155 insertions, 387 deletions
diff --git a/frontends/php/report4.php b/frontends/php/report4.php
index 4f0c6283..e4bfa8b7 100644
--- a/frontends/php/report4.php
+++ b/frontends/php/report4.php
@@ -19,405 +19,173 @@
**/
?>
<?php
- include "include/config.inc.php";
+ require_once "include/config.inc.php";
+
$page["title"] = "S_IT_NOTIFICATIONS";
$page["file"] = "report4.php";
- show_header($page["title"],0,0);
-?>
+include_once "include/page_header.php";
+
+?>
<?php
-// if(!check_right("Host","R",0))
-// {
-// show_table_header("<font color=\"AA0000\">No permissions !</font>");
-// show_page_footer();
-// exit;
-// }
+// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
+ $fields=array(
+ "year"=> array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO, NULL, NULL),
+ "period"=> array(T_ZBX_STR, O_OPT, P_SYS|P_NZERO, IN('"dayly","weekly","monthly","yearly"'), NULL),
+ "media_type"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL)
+ );
+
+ check_fields($fields);
?>
-
<?php
- if(!isset($_REQUEST["year"]))
- {
- $_REQUEST["year"]=2006;
- // show_table_header("<font color=\"AA0000\">Undefined serviceid !</font>");
- // show_page_footer();
- // exit;
- }
+ $year = get_request("year", 2006);
+ $period = get_request("period", "weekly");
+ $media_type = get_request("media_type", 0);
?>
-
<?php
- if(!isset($_REQUEST["period"]))
- {
- $_REQUEST["period"]="weekly";
- }
-
- if(!isset($_REQUEST["media_type"]))
- {
- $_REQUEST["media_type"]="0";
- }
-
- $h1=S_NOTIFICATIONS_BIG;
-
-# $h2=S_GROUP.SPACE;
- $h2=S_YEAR.SPACE;
- $h2=$h2."<select class=\"biginput\" name=\"year\" onChange=\"submit()\">";
- $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host");
-
- $year=date("Y");
- for($year=date("Y")-2;$year<=date("Y");$year++)
- {
- $h2=$h2.form_select("year",$year,$year);
- }
- $h2=$h2."</select>";
-
- $h2=$h2.SPACE.S_PERIOD.SPACE;
- $h2=$h2."<select class=\"biginput\" name=\"period\" onChange=\"submit()\">";
- $h2=$h2.form_select("period","daily",S_DAILY);
- $h2=$h2.form_select("period","weekly",S_WEEKLY);
- $h2=$h2.form_select("period","monthly",S_MONTHLY);
- $h2=$h2.form_select("period","yearly",S_YEARLY);
- $h2=$h2."</select>";
- $h2=$h2.SPACE.S_MEDIA_TYPE.SPACE;
- $h2=$h2."<select class=\"biginput\" name=\"media_type\" onChange=\"submit()\">";
- // $h2=$h2.form_select("media_type","0",S_ALL_SMALL);
- $result=DBselect("select * from media_type where mod(mediatypeid,100)=$ZBX_CURNODEID order by description");
- $type_count=0;
- while($row=DBfetch($result))
- {
- $type_count++;
- $descarray[$type_count]=$row["description"];
- $id=$row["mediatypeid"];
- $idarray[$type_count]=$id;
- }
- $descarray[0]="all";
- $i=-1;
- while($i<$type_count)
- {
- $i++;
- global $_REQUEST;
- $selected = "";
- if(!is_null("media_type"))
- {
- if(isset($_REQUEST["media_type"])&&$_REQUEST["media_type"]==$i)
- $selected = "selected";
- }
- $form_select1="<option value=$i $selected>$descarray[$i]";
- $h2=$h2.$form_select1;
-// $h2=$h2.form_select("media_type","$descarray[$i]",S_EMAIL);
- }
- $h2=$h2."</select>";
-
-
- show_header2($h1,$h2,"<form name=\"selection\" method=\"get\" action=\"report4.php\">", "</form>");
+ define("YEAR_LEFT_SHIFT", 5);
+
+ $form = new CForm();
+
+ $form->AddItem(SPACE.S_MEDIA_TYPE.SPACE);
+ $cmbMedia = new CComboBox("media_type", $media_type, "submit();");
+ $cmbMedia->AddItem(0,S_ALL_SMALL);
+ $db_medias = DBselect("select * from media_type where ".DBid2nodeid("mediatypeid")."=".$ZBX_CURNODEID." order by description");
+ while($media_data = DBfetch($db_medias))
+ {
+ $cmbMedia->AddItem($media_data["mediatypeid"], $media_data["description"]);
+ }
+ $form->AddItem($cmbMedia);
+
+ $form->AddItem(SPACE.S_PERIOD.SPACE);
+ $cmbPeriod = new CComboBox("period", $period, "submit();");
+ $cmbPeriod->AddItem("dayly", S_DAILY);
+ $cmbPeriod->AddItem("weekly", S_WEEKLY);
+ $cmbPeriod->AddItem("monthly", S_MONTHLY);
+ $cmbPeriod->AddItem("yearly", S_YEARLY);
+ $form->AddItem($cmbPeriod);
+
+ if($period != "yearly")
+ {
+ $form->AddItem(SPACE.S_YEAR.SPACE);
+ $cmbYear = new CComboBox("year", $year, "submit();");
+ for($y = date("Y")-YEAR_LEFT_SHIFT; $y <= date("Y"); $y++)
+ $cmbYear->AddItem($y, $y);
+ $form->AddItem($cmbYear);
+ }
+
+ show_table_header(S_NOTIFICATIONS_BIG, $form);
?>
-
<?php
- $year=date("Y");
- $table = new CTableInfo();
- if($_REQUEST["period"]=="yearly")
- {
- $header=array(new CCol(S_YEAR,"center"));
- $uindex=1;
- $result=DBselect("select * from users".
- " where mod(userid,100)=".$ZBX_CURNODEID.
- " order by alias");
- while($row=DBfetch($result))
- {
- $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
- $userarray[$uindex]=$row["userid"];
- $uindex++;
- }
- $table->setHeader($header,"vertical_header");
+ $_REQUEST["year"] = $year;
+ $_REQUEST["period"] = $period;
+ $_REQUEST["media_type"] = $media_type;
+
+ $table = new CTableInfo();
+ $header = array();
+ $db_users = DBselect("select * from users where ".DBid2nodeid("userid")."=".$ZBX_CURNODEID." order by alias,userid");
+ while($user_data = DBfetch($db_users))
+ {
+ array_push($header, new CImg("vtext.php?text=".$user_data["alias"]));
+ $users[$user_data['userid']] = $user_data['alias'];
+ }
+
+ $db_media_types = DBselect("select * from media_type where ".DBid2nodeid("mediatypeid")."=".$ZBX_CURNODEID.
+ ($media_type > 0 ? " and mediatypeid=".$media_type : "" ).
+ " order by description,mediatypeid");
+ while($media_type_data = DBfetch($db_media_types))
+ {
+ $media_types[$media_type_data['mediatypeid']] = $media_type_data['description'];
+ }
+
+ switch($period)
+ {
+ case "yearly":
+ $from = (date("Y") - YEAR_LEFT_SHIFT);
+ $to = date("Y");
+ array_unshift($header, new CCol(S_YEAR,"center"));
+ function get_time($y) { return mktime(0,0,0,1,1,$y); }
+ function format_time($t){ return date("Y", $t); }
+ function format_time2($t){ return null; };
+ break;
+ case "monthly":
+ $from = 1;
+ $to = 12;
+ array_unshift($header, new CCol(S_MONTH,"center"));
+ function get_time($m) { global $year; return mktime(0,0,0,$m,1,$year); }
+ function format_time($t){ return date("M Y",$t); }
+ function format_time2($t){ return null; };
+ break;
+ case "dayly":
+ $from = 1;
+ $to = 365;
+ array_unshift($header, new CCol(S_DAY,"center"));
+ function get_time($d) { global $year; return mktime(0,0,0,1,$d,$year); }
+ function format_time($t){ return date("d M Y",$t); }
+ function format_time2($t){ return null; };
+ break;
+ case "weekly":
+ default:
+ $from = 0;
+ $to = 52;
+ array_unshift($header,new CCol(S_FROM,"center"),new CCol(S_TILL,"center"));
+ function get_time($w) {
+ global $year;
+
+ $time = mktime(0,0,0,1, 1, $year);
+ $wd = date("w", $time);
+ $wd = $wd == 0 ? 6 : $wd - 1;
+
+ return ($time + ($w*7 - $wd)*24*3600);
+ }
+ function format_time($t){ return date("d M Y H:i",$t); }
+ function format_time2($t){ return format_time($t); };
+ break;
+
+ }
+
+ $table->SetHeader($header,"vertical_header");
+
+ for($t = $from; $t <= $to; $t++)
+ {
+ if(($start = get_time($t)) > time())
+ break;
+
+ if(($end = get_time($t+1)) > time())
+ $end = time();
+
+ $table_row = array(format_time($start),format_time2($end));
+ foreach($users as $userid => $alias)
+ {
+ $all = 0;
+ $cnt_by_type = array();
+ foreach($media_types as $mediatypeid => $description)
+ {
+ $cnt_data = DBfetch(DBselect("select count(*) as cnt from alerts a ".
+ " where a.userid=".$userid." and a.mediatypeid=".$mediatypeid.
+ " and clock>$start and clock<$end "));
+ if(!$cnt_data) $cnt_data = 0;
+ else $cnt_data = $cnt_data['cnt'];
+ array_push($cnt_by_type, $cnt_data);
+ $all += $cnt_data;
+ }
+ array_push($table_row,array($all, ($media_type == 0 ? SPACE."(".implode('/',$cnt_by_type).")" : "" )));
+ }
+ $table->AddRow($table_row);
+ }
+ $table->show();
+
+ if($media_type == 0)
+ {
+ $table = new CTableInfo();
+ $table->AddRow(new CSpan(SPACE.SPACE.SPACE.SPACE.SPACE.SPACE."all".SPACE."(".implode('/', $media_types).")","off"));
+ $table->Show();
+ }
+?>
+<?php
- for($year=date("Y")-5;$year<=date("Y");$year++)
- {
- $start=mktime(0,0,0,1,1,$year);
- $end=mktime(0,0,0,1,1,$year+1);
- $table_row = array(nbsp($year));
- $style = NULL;
- $counter=1;
- while ($counter<$uindex)
- {
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
- while($row=DBfetch($result))
- {
- $count_all=$row[0];
- }
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
- while($row=DBfetch($result))
- {
- $count_by_type[$i]=$row[0];
- }
- }
- if ($_REQUEST["media_type"]==0)
- {
- $total_count=$count_all;
- $total_count.=" (";
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- if($i>1) { $total_count.="/"; }
- $total_count.=$count_by_type[$i];
- }
- $total_count.=")";
- }
- $i=0;
- while($i<=$type_count)
- {
- $i++;
- if ($_REQUEST["media_type"]==$i)
- $total_count=$count_by_type[$i];
- }
- array_push($table_row,new CCol($total_count,$style));
- $counter++;
- }
- $table->AddRow($table_row);
- }
-
- }
- else if($_REQUEST["period"]=="monthly")
- {
- $header=array(new CCol(SPACE.S_MONTH,"center"));
- $uindex=1;
- $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias");
- while($row=DBfetch($result))
- {
- $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
- $userarray[$uindex]=$row["userid"];
- $uindex++;
- }
- $table->setHeader($header,"vertical_header");
-
- for($month=1;$month<=12;$month++)
- {
- $start=mktime(0,0,0,$month,1,$_REQUEST["year"]);
- $end=mktime(0,0,0,$month+1,1,$_REQUEST["year"]);
- if($start>time()) break;
- $table_row = array(nbsp(date("M Y",$start)));
- $style = NULL;
- $counter=1;
- while ($counter<$uindex)
- {
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
- while($row=DBfetch($result))
- {
- $count_all=$row[0];
- }
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
- while($row=DBfetch($result))
- {
- $count_by_type[$i]=$row[0];
- }
- }
- if ($_REQUEST["media_type"]==0)
- {
- $total_count=$count_all;
- $total_count.=" (";
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- if($i>1) { $total_count.="/"; }
- $total_count.=$count_by_type[$i];
- }
- $total_count.=")";
- }
- $i=0;
- while($i<=$type_count)
- {
- $i++;
- if ($_REQUEST["media_type"]==$i)
- $total_count=$count_by_type[$i];
- }
- array_push($table_row,new CCol($total_count,$style));
- $counter++;
- }
-
- $table->AddRow($table_row);
- }
- }
- else if($_REQUEST["period"]=="daily")
- {
- $header=array(new CCol(SPACE.S_DAY,"center"));
- $uindex=1;
- $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias");
- while($row=DBfetch($result))
- {
- $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
- $userarray[$uindex]=$row["userid"];
- $uindex++;
- }
- $table->setHeader($header,"vertical_header");
-
- $s=mktime(0,0,0,1,1,$_REQUEST["year"]);
- $e=mktime(0,0,0,1,1,$_REQUEST["year"]+1);
- for($day=$s;$day<$e;$day+=24*3600)
- {
- $start=$day;
- $end=$day+24*3600;
-
- if($start>time()) break;
-
- $table_row = array(nbsp(date("d M Y",$start)));
- $style = NULL;
- $counter=1;
- while ($counter<$uindex)
- {
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
- while($row=DBfetch($result))
- {
- $count_all=$row[0];
- }
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
- while($row=DBfetch($result))
- {
- $count_by_type[$i]=$row[0];
- }
- }
- if ($_REQUEST["media_type"]==0)
- {
- $total_count=$count_all;
- $total_count.=" (";
- $i=0;
- while ($i<$type_count)
- {
- $i++;
- if($i>1) { $total_count.="/"; }
- $total_count.=$count_by_type[$i];
- }
- $total_count.=")";
- }
- $i=0;
- while($i<=$type_count)
- {
- $i++;
- if ($_REQUEST["media_type"]==$i)
- $total_count=$count_by_type[$i];
- }
- array_push($table_row,new CCol($total_count,$style));
- $counter++;
- }
-
-
- $table->AddRow($table_row);
- }
- }
- else
- {
- //-------Weekly-------------
- $year=date("Y");
- $header=array(new CCol(SPACE.S_FROM,"center"),new CCol(SPACE.S_TILL,"center"));
- $uindex=1;
- $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias");
- while($row=DBfetch($result))
- {
- $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
- $userarray[$uindex]=$row["userid"];
- $uindex++;
- }
- $table->setHeader($header,"vertical_header");
- for($year=date("Y")-2;$year<=date("Y");$year++)
- {
- if( isset($_REQUEST["year"]) && ($_REQUEST["year"] != $year) )
- {
- continue;
- }
- $start=mktime(0,0,0,1,1,$year);
-
- $wday=date("w",$start);
- if($wday==0) $wday=7;
- $start=$start-($wday-1)*24*3600;
- $i=0;
- for($i=0;$i<53;$i++)
- {
- $period_start=$start+7*24*3600*$i;
- $period_end=$start+7*24*3600*($i+1);
- if($period_start>time())
- {
- break;
- }
- $from=date(S_DATE_FORMAT_YMD,$period_start);
- $till=date(S_DATE_FORMAT_YMD,$period_end);
- $table_row = array($from,$till);
- $style = NULL;
- $counter=1;
- while ($counter<$uindex)
- {
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$period_start and clock<$period_end");
- while($row=DBfetch($result))
- {
- $count_all=$row[0];
- }
- $k=0;
- while ($k<$type_count)
- {
- $k++;
- $result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$period_start and clock<$period_end and mediatypeid=$idarray[$k]");
- while($row=DBfetch($result))
- {
- $count_by_type[$k]=$row[0];
- }
- }
- if ($_REQUEST["media_type"]==0)
- {
- $total_count=$count_all;
- $total_count.=" (";
- $l=0;
- while ($l<$type_count)
- {
- $l++;
- if($l>1) { $total_count.="/"; }
- $total_count.=$count_by_type[$l];
- }
- $total_count.=")";
- }
- $m=0;
- while($m<=$type_count)
- {
- $m++;
- if ($_REQUEST["media_type"]==$m)
- $total_count=$count_by_type[$m];
- }
- array_push($table_row,new CCol($total_count,$style));
-
- $counter++;
- }
+include_once "include/page_footer.php";
- $table->AddRow($table_row);
- } }
- //--------Weekly-------------
- }
- $table->show();
- if ($_REQUEST["media_type"]=="0")
- {
- $style = "off";
- $table = new CTableInfo();
- $types="all (";
- $i=0;
- while($i<$type_count)
- {
- $i++;
- if($i>1) {$types.="/";}
- $types.=$descarray[$i];
- }
- $types.=")";
- $table->AddRow(new CSpan(SPACE.SPACE.SPACE.SPACE.SPACE.SPACE.$types,$style));
- $table->Show();
- }
- show_page_footer();
?>
-