22
include "include/config.inc.php";
22
require_once "include/config.inc.php";
23
24
$page["title"] = "S_IT_NOTIFICATIONS";
24
25
$page["file"] = "report4.php";
25
show_header($page["title"],0,0);
29
if(!check_right("User","R",0))
31
show_table_header("<font color=\"AA0000\">No permissions !</font>");
38
if(!isset($_REQUEST["year"]))
40
$_REQUEST["year"]=2006;
41
// show_table_header("<font color=\"AA0000\">Undefined serviceid !</font>");
42
// show_page_footer();
48
if(!isset($_REQUEST["period"]))
50
$_REQUEST["period"]="weekly";
53
if(!isset($_REQUEST["media_type"]))
55
$_REQUEST["media_type"]="0";
58
$h1=S_NOTIFICATIONS_BIG;
62
$h2=$h2."<select class=\"biginput\" name=\"year\" onChange=\"submit()\">";
63
$result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host");
66
for($year=date("Y")-2;$year<=date("Y");$year++)
68
$h2=$h2.form_select("year",$year,$year);
72
$h2=$h2.SPACE.S_PERIOD.SPACE;
73
$h2=$h2."<select class=\"biginput\" name=\"period\" onChange=\"submit()\">";
74
$h2=$h2.form_select("period","daily",S_DAILY);
75
$h2=$h2.form_select("period","weekly",S_WEEKLY);
76
$h2=$h2.form_select("period","monthly",S_MONTHLY);
77
$h2=$h2.form_select("period","yearly",S_YEARLY);
79
$h2=$h2.SPACE.S_MEDIA_TYPE.SPACE;
80
$h2=$h2."<select class=\"biginput\" name=\"media_type\" onChange=\"submit()\">";
81
// $h2=$h2.form_select("media_type","0",S_ALL_SMALL);
82
$result=DBselect("select * from media_type order by description");
84
while($row=DBfetch($result))
87
$descarray[$type_count]=$row["description"];
88
$id=$row["mediatypeid"];
89
$idarray[$type_count]=$id;
98
if(!is_null("media_type"))
100
if(isset($_REQUEST["media_type"])&&$_REQUEST["media_type"]==$i)
101
$selected = "selected";
103
$form_select1="<option value=$i $selected>$descarray[$i]";
104
$h2=$h2.$form_select1;
105
// $h2=$h2.form_select("media_type","$descarray[$i]",S_EMAIL);
110
show_header2($h1,$h2,"<form name=\"selection\" method=\"get\" action=\"report4.php\">", "</form>");
27
include_once "include/page_header.php";
31
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
33
"year"=> array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO, NULL, NULL),
34
"period"=> array(T_ZBX_STR, O_OPT, P_SYS|P_NZERO, IN('"dayly","weekly","monthly","yearly"'), NULL),
35
"media_type"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL)
38
check_fields($fields);
41
$year = get_request("year", intval(date("Y")));
42
$period = get_request("period", "weekly");
43
$media_type = get_request("media_type", 0);
46
if( ($min_time = DBfetch(DBselect('select min(clock) as clock from alerts'))) && $min_time['clock'])
48
$MIN_YEAR = intval(date("Y", $min_time['clock']));
51
if( !isset($MIN_YEAR) )
53
$MIN_YEAR = intval(date("Y"));
58
$form->AddItem(SPACE.S_MEDIA_TYPE.SPACE);
59
$cmbMedia = new CComboBox("media_type", $media_type, "submit();");
60
$cmbMedia->AddItem(0,S_ALL_SMALL);
61
$db_medias = DBselect("select * from media_type where ".DBid2nodeid("mediatypeid")."=".$ZBX_CURNODEID." order by description");
62
while($media_data = DBfetch($db_medias))
64
$cmbMedia->AddItem($media_data["mediatypeid"], $media_data["description"]);
66
$form->AddItem($cmbMedia);
68
$form->AddItem(SPACE.S_PERIOD.SPACE);
69
$cmbPeriod = new CComboBox("period", $period, "submit();");
70
$cmbPeriod->AddItem("dayly", S_DAILY);
71
$cmbPeriod->AddItem("weekly", S_WEEKLY);
72
$cmbPeriod->AddItem("monthly", S_MONTHLY);
73
$cmbPeriod->AddItem("yearly", S_YEARLY);
74
$form->AddItem($cmbPeriod);
76
if($period != "yearly")
78
$form->AddItem(SPACE.S_YEAR.SPACE);
79
$cmbYear = new CComboBox("year", $year, "submit();");
80
for($y = $MIN_YEAR; $y <= date("Y"); $y++)
81
$cmbYear->AddItem($y, $y);
82
$form->AddItem($cmbYear);
85
show_table_header(S_NOTIFICATIONS_BIG, $form);
88
$_REQUEST["year"] = $year;
89
$_REQUEST["period"] = $period;
90
$_REQUEST["media_type"] = $media_type;
115
93
$table = new CTableInfo();
116
if($_REQUEST["period"]=="yearly")
118
$header=array(new CCol(S_YEAR,"center"));
120
$result=DBselect("select * from users".
122
while($row=DBfetch($result))
124
$header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
125
$userarray[$uindex]=$row["userid"];
128
$table->setHeader($header,"vertical_header");
132
for($year=date("Y")-5;$year<=date("Y");$year++)
134
$start=mktime(0,0,0,1,1,$year);
135
$end=mktime(0,0,0,1,1,$year+1);
136
$table_row = array(nbsp($year));
139
while ($counter<$uindex)
141
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
142
while($row=DBfetch($result))
147
while ($i<$type_count)
150
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
151
while($row=DBfetch($result))
153
$count_by_type[$i]=$row[0];
156
if ($_REQUEST["media_type"]==0)
158
$total_count=$count_all;
161
while ($i<$type_count)
164
if($i>1) { $total_count.="/"; }
165
$total_count.=$count_by_type[$i];
170
while($i<=$type_count)
173
if ($_REQUEST["media_type"]==$i)
174
$total_count=$count_by_type[$i];
176
array_push($table_row,new CCol($total_count,$style));
179
$table->AddRow($table_row);
183
else if($_REQUEST["period"]=="monthly")
185
$header=array(new CCol(SPACE.S_MONTH,"center"));
187
$result=DBselect("select * from users order by alias");
188
while($row=DBfetch($result))
190
$header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
191
$userarray[$uindex]=$row["userid"];
194
$table->setHeader($header,"vertical_header");
196
for($month=1;$month<=12;$month++)
198
$start=mktime(0,0,0,$month,1,$_REQUEST["year"]);
199
$end=mktime(0,0,0,$month+1,1,$_REQUEST["year"]);
200
if($start>time()) break;
201
$table_row = array(nbsp(date("M Y",$start)));
204
while ($counter<$uindex)
206
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
207
while($row=DBfetch($result))
212
while ($i<$type_count)
215
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
216
while($row=DBfetch($result))
218
$count_by_type[$i]=$row[0];
221
if ($_REQUEST["media_type"]==0)
223
$total_count=$count_all;
226
while ($i<$type_count)
229
if($i>1) { $total_count.="/"; }
230
$total_count.=$count_by_type[$i];
235
while($i<=$type_count)
238
if ($_REQUEST["media_type"]==$i)
239
$total_count=$count_by_type[$i];
241
array_push($table_row,new CCol($total_count,$style));
245
$table->AddRow($table_row);
248
else if($_REQUEST["period"]=="daily")
250
$header=array(new CCol(SPACE.S_DAY,"center"));
252
$result=DBselect("select * from users order by alias");
253
while($row=DBfetch($result))
255
$header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
256
$userarray[$uindex]=$row["userid"];
259
$table->setHeader($header,"vertical_header");
261
$s=mktime(0,0,0,1,1,$_REQUEST["year"]);
262
$e=mktime(0,0,0,1,1,$_REQUEST["year"]+1);
263
for($day=$s;$day<$e;$day+=24*3600)
268
if($start>time()) break;
270
$table_row = array(nbsp(date("d M Y",$start)));
273
while ($counter<$uindex)
275
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end");
276
while($row=DBfetch($result))
281
while ($i<$type_count)
284
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$start and clock<$end and mediatypeid=$idarray[$i]");
285
while($row=DBfetch($result))
287
$count_by_type[$i]=$row[0];
290
if ($_REQUEST["media_type"]==0)
292
$total_count=$count_all;
295
while ($i<$type_count)
298
if($i>1) { $total_count.="/"; }
299
$total_count.=$count_by_type[$i];
304
while($i<=$type_count)
307
if ($_REQUEST["media_type"]==$i)
308
$total_count=$count_by_type[$i];
310
array_push($table_row,new CCol($total_count,$style));
315
$table->AddRow($table_row);
320
//-------Weekly-------------
322
$header=array(new CCol(SPACE.S_FROM,"center"),new CCol(SPACE.S_TILL,"center"));
324
$result=DBselect("select * from users order by alias");
325
while($row=DBfetch($result))
327
$header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"])));
328
$userarray[$uindex]=$row["userid"];
331
$table->setHeader($header,"vertical_header");
332
for($year=date("Y")-2;$year<=date("Y");$year++)
334
if( isset($_REQUEST["year"]) && ($_REQUEST["year"] != $year) )
338
$start=mktime(0,0,0,1,1,$year);
340
$wday=date("w",$start);
341
if($wday==0) $wday=7;
342
$start=$start-($wday-1)*24*3600;
346
$period_start=$start+7*24*3600*$i;
347
$period_end=$start+7*24*3600*($i+1);
348
if($period_start>time())
352
$from=date(S_DATE_FORMAT_YMD,$period_start);
353
$till=date(S_DATE_FORMAT_YMD,$period_end);
354
$table_row = array($from,$till);
357
while ($counter<$uindex)
359
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$period_start and clock<$period_end");
360
while($row=DBfetch($result))
365
while ($k<$type_count)
368
$result=DBselect("select count(*) from alerts where userid='$userarray[$counter]' and clock>$period_start and clock<$period_end and mediatypeid=$idarray[$k]");
369
while($row=DBfetch($result))
371
$count_by_type[$k]=$row[0];
374
if ($_REQUEST["media_type"]==0)
376
$total_count=$count_all;
379
while ($l<$type_count)
382
if($l>1) { $total_count.="/"; }
383
$total_count.=$count_by_type[$l];
388
while($m<=$type_count)
391
if ($_REQUEST["media_type"]==$m)
392
$total_count=$count_by_type[$m];
394
array_push($table_row,new CCol($total_count,$style));
399
$table->AddRow($table_row);
401
//--------Weekly-------------
404
if ($_REQUEST["media_type"]=="0")
407
$table = new CTableInfo();
410
while($i<$type_count)
413
if($i>1) {$types.="/";}
414
$types.=$descarray[$i];
417
$table->AddRow(new CSpan(SPACE.SPACE.SPACE.SPACE.SPACE.SPACE.$types,$style));
96
$db_users = DBselect("select * from users where ".DBid2nodeid("userid")."=".$ZBX_CURNODEID." order by alias,userid");
97
while($user_data = DBfetch($db_users))
99
array_push($header, new CImg("vtext.php?text=".$user_data["alias"]));
100
$users[$user_data['userid']] = $user_data['alias'];
103
$media_types = array();
105
$db_media_types = DBselect("select * from media_type where ".DBid2nodeid("mediatypeid")."=".$ZBX_CURNODEID.
106
($media_type > 0 ? " and mediatypeid=".$media_type : "" ).
107
" order by description,mediatypeid");
108
while($media_type_data = DBfetch($db_media_types))
110
$media_types[$media_type_data['mediatypeid']] = $media_type_data['description'];
118
array_unshift($header, new CCol(S_YEAR,"center"));
119
function get_time($y) { return mktime(0,0,0,1,1,$y); }
120
function format_time($t){ return date("Y", $t); }
121
function format_time2($t){ return null; };
126
array_unshift($header, new CCol(S_MONTH,"center"));
127
function get_time($m) { global $year; return mktime(0,0,0,$m,1,$year); }
128
function format_time($t){ return date("M Y",$t); }
129
function format_time2($t){ return null; };
134
array_unshift($header, new CCol(S_DAY,"center"));
135
function get_time($d) { global $year; return mktime(0,0,0,1,$d,$year); }
136
function format_time($t){ return date("d M Y",$t); }
137
function format_time2($t){ return null; };
143
array_unshift($header,new CCol(S_FROM,"center"),new CCol(S_TILL,"center"));
144
function get_time($w) {
147
$time = mktime(0,0,0,1, 1, $year);
148
$wd = date("w", $time);
149
$wd = $wd == 0 ? 6 : $wd - 1;
151
return ($time + ($w*7 - $wd)*24*3600);
153
function format_time($t){ return date("d M Y H:i",$t); }
154
function format_time2($t){ return format_time($t); };
159
$table->SetHeader($header,"vertical_header");
161
for($t = $from; $t <= $to; $t++)
163
if(($start = get_time($t)) > time())
166
if(($end = get_time($t+1)) > time())
169
$table_row = array(format_time($start),format_time2($end));
170
foreach($users as $userid => $alias)
173
$cnt_by_type = array();
174
foreach($media_types as $mediatypeid => $description)
176
$cnt_data = DBfetch(DBselect("select count(*) as cnt from alerts a ".
177
" where a.userid=".$userid." and a.mediatypeid=".$mediatypeid.
178
" and clock>$start and clock<$end "));
179
if(!$cnt_data) $cnt_data = 0;
180
else $cnt_data = $cnt_data['cnt'];
181
array_push($cnt_by_type, $cnt_data);
184
array_push($table_row,array($all, ($media_type == 0 ? SPACE."(".implode('/',$cnt_by_type).")" : "" )));
186
$table->AddRow($table_row);
192
$table = new CTableInfo();
193
$table->AddRow(new CSpan(SPACE.SPACE.SPACE.SPACE.SPACE.SPACE."all".SPACE."(".implode('/', $media_types).")","off"));
199
include_once "include/page_footer.php";