diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-03-27 17:00:36 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-03-27 17:00:36 +0000 |
| commit | 5d1e6e58ae6245c3c2034ed7e35f95d45a73055a (patch) | |
| tree | 03ff74a4dd1aa3082fcbf6fe20b8631529ff0dab /frontends/php/include | |
| parent | 287db0bc8db438e082be402b6f3de174b23e2b31 (diff) | |
| download | zabbix-5d1e6e58ae6245c3c2034ed7e35f95d45a73055a.tar.gz zabbix-5d1e6e58ae6245c3c2034ed7e35f95d45a73055a.tar.xz zabbix-5d1e6e58ae6245c3c2034ed7e35f95d45a73055a.zip | |
- improvements in Class tree (Artem)
git-svn-id: svn://svn.zabbix.com/trunk@5555 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/classes/ctree.inc.php | 408 | ||||
| -rw-r--r-- | frontends/php/include/config.inc.php | 1 | ||||
| -rw-r--r-- | frontends/php/include/services.inc.php | 29 |
3 files changed, 230 insertions, 208 deletions
diff --git a/frontends/php/include/classes/ctree.inc.php b/frontends/php/include/classes/ctree.inc.php index 5ee4e6bd..3d07609a 100644 --- a/frontends/php/include/classes/ctree.inc.php +++ b/frontends/php/include/classes/ctree.inc.php @@ -1,7 +1,7 @@ <?php /* ** ZABBIX -** Copyright (C) 2000-2005 SIA Zabbix +** Copyright (C) 2007 SIA ZABBIX ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -30,227 +30,247 @@ var $size=0; var $maxlevel=0; -/*public*/ -function CTree($value=array(),$fields=array()){ -// parent::CTable(); - $this->tree = $value; - $this->fields = $fields; - $this->treename = $this->fields['caption']; + /*public*/ + public function CTree($value=array(),$fields=array()){ + $this->tree = $value; + $this->fields = $fields; + $this->treename = $this->fields['caption']; + + $this->size = count($value); + unset($value); + unset($fields); - $this->size = count($value); - unset($value); - unset($fields); - - if(!$this->CheckTree()){ - $this->Destroy(); - return false; - } else { - $this->CountDepth(); - } -} - -function GetTree(){ - return $this->tree; -} - -/*private*/ -function MakeHeaders(){ - $c=0; - $tr = new CRow(); - $tr->AddItem($this->fields['caption']); - $tr->SetClass('treeheader'); - unset($this->fields['caption']); - foreach($this->fields as $id => $caption){ - $tr->AddItem($caption); - $fields[$c] = $id; - $c++; + if(!$this->CheckTree()){ + $this->Destroy(); + return false; + } else { + $this->CountDepth(); + } } - $this->fields = $fields; -return $tr; -} - -function SimpleHTML(){ - $table = new CTableInfo('','tabletree'); - $table->SetCellSpacing(0); - $table->SetCellPadding(0); - - $table->oddRowClass = 'odd_row'; - $table->evenRowClass = 'even_row'; - $table->headerClass = 'header'; - $table->footerClass = 'footer'; + public function GetTree(){ + return $this->tree; + } - $table->AddOption('border','0'); - $table->AddRow($this->MakeHeaders()); -// $table->AddRow(); - foreach($this->tree as $id => $rows){ - $table->AddRow($this->MakeSHTMLRow($id)); + /*private*/ + public function MakeHeaders(){ + $c=0; + $tr = new CRow(); + $tr->AddItem($this->fields['caption']); + $tr->SetClass('treeheader'); + unset($this->fields['caption']); + foreach($this->fields as $id => $caption){ + $tr->AddItem($caption); + $fields[$c] = $id; + $c++; + } + $this->fields = $fields; + return $tr; } -return $table->ToString(); -} - - -function MakeSHTMLRow($id){ - $table = new CTable(); - $table->SetCellSpacing(0); - $table->SetCellPadding(0); - $table->AddOption('width','200'); - $tr = $this->MakeSImgStr($id); + public function SimpleHTML(){ + $table = new CTable('','tabletree'); + + $table->SetCellSpacing(0); + $table->SetCellPadding(0); - $td = new CCol($this->tree[$id]['caption']); - $td->SetAlign('left'); - - - $tr->AddItem($td); - $table->AddRow($tr); + $table->oddRowClass = 'odd_row'; + $table->evenRowClass = 'even_row'; + $table->headerClass = 'header'; + $table->footerClass = 'footer'; + + $table->AddOption('border','0'); + $table->AddRow($this->MakeHeaders()); - $tr = new CRow(); - $tr->AddItem($table); - $tr->AddOption('id',$id); - $tr->AddOption('style',($this->tree[$id]['parentid'] != '0')?('display: none;'):('')); - $tr->AddOption('valign','top'); - - foreach($this->fields as $key => $value){ - $td = new CCol($this->tree[$id][$value]); - $tr->AddItem($td); + foreach($this->tree as $id => $rows){ + $table->AddRow($this->MakeSHTMLRow($id)); + } + return $table; } -return $tr; -} - -function MakeSImgStr($id){ - $tr = new CRow(); - $tr->AddOption('height',18); -// $tr->AddOption('valign','top'); - $count=(isset($this->tree[$id]['nodeimg']))?(strlen($this->tree[$id]['nodeimg'])):(0); - for($i=0; $i<$count; $i++){ - switch($this->tree[$id]['nodeimg'][$i]){ - case 'O': - $img= new CImg('images/general/tree/O.gif','o','22','18'); - break; - case 'I': - $img= new CImg('images/general/tree/I.gif','i','22','18'); - break; - case 'L': - if($this->tree[$id]['nodetype'] == 2){ - $img= new CImg('images/general/tree/Yc.gif','y','22','18'); - $img->AddOption('OnClick','javascript: tree.closeSNodeX('.$id.',this);'); - $img->AddOption('id',$id.'I'); - $img->SetClass('imgnode'); - - } else { - $img= new CImg('images/general/tree/L.gif','l','22','18'); - } - break; - case 'T': - if($this->tree[$id]['nodetype'] == 2){ - $img= new CImg('images/general/tree/Xc.gif','x','22','18'); - $img->AddOption('OnClick','javascript: tree.closeSNodeX('.$id.',this);'); - $img->AddOption('id',$id.'I'); - $img->SetClass('imgnode'); - } else { - $img= new CImg('images/general/tree/T.gif','t','22','18'); - } - break; - } - $td = new CCol($img,'tdtree'); - $tr->AddItem($td); + public function getHTML(){ + $html[] = $this->CreateJS(); + $html[] = $this->SimpleHTML(); + return $html; } -// echo $txt.' '.$this->tree[$id]['Name'].'<br />'; -return $tr; -} - -function CountDepth(){ - foreach($this->tree as $id => $rows){ + + public function MakeSHTMLRow($id){ - if($id == '0'){ - continue; - } - $parentid = $this->tree[$id]['parentid']; + $table = new CTable(); + $table->SetCellSpacing(0); + $table->SetCellPadding(0); + // $table->AddOption('border','1'); - $this->tree[$id]['nodeimg'] = $this->GetImg($id,(isset($this->tree[$parentid]['nodeimg']))?($this->tree[$parentid]['nodeimg']):('')); - //$this->tree[$parentid]['childs'] = ($this->tree[$parentid]['childs']+$this->tree[$id]['childs']+1); + $tr = $this->MakeSImgStr($id); - $this->tree[$parentid]['nodetype'] = 2; + $td = new CCol($this->tree[$id]['caption']); + $td->AddOption('style','height: 20px; padding-right: 10px; padding-left: 2px;'); + $tr->AddItem($td); + + $table->AddRow($tr); + + $tr = new CRow(); + $tr->AddItem($table); + $tr->AddOption('id','id_'.$id); + $tr->AddOption('style',($this->tree[$id]['parentid'] != '0')?('display: none;'):('')); + + + foreach($this->fields as $key => $value){ + $td = new CCol($this->tree[$id][$value]); + $td->AddOption('style','padding-right: 10px; padding-left: 2px;'); + $tr->AddItem($td); + } - $this->tree[$id]['Level'] = (isset($this->tree[$parentid]['Level']))?($this->tree[$parentid]['Level']+1):(1); - ($this->maxlevel>$this->tree[$id]['Level'])?(''):($this->maxlevel = $this->tree[$id]['Level']); + return $tr; } - -} - - -function CreateJS(){ -global $page; - $js = ' - <script src="js/tree.js" type="text/javascript"></script> - <script src="js/cookies.js" type="text/javascript"></script> - <script type="text/javascript"> - var treenode = new Array(0); - var tree_name = "tree_'.$this->getUserAlias().'_'.$page["file"].'"; - var nodeid_list = new Array(); - '; - $js_node_list = ''; - foreach($this->tree as $id => $rows){ - $parentid = $rows['parentid']; - $this->tree[$parentid]['nodelist'].=$id.'.'; + public function MakeSImgStr($id){ + $tr = new CRow(); + $td = new CCol(); + + $count=(isset($this->tree[$id]['nodeimg']))?(strlen($this->tree[$id]['nodeimg'])):(0); + for($i=0; $i<$count; $i++){ + switch($this->tree[$id]['nodeimg'][$i]){ + case 'O': + $td->AddOption('style','width: 22px'); + $img= new CImg('images/general/tree/zero.gif','o','22','14'); + break; + case 'I': + $td->AddOption('style','width:22px; background-image:url(images/general/tree/pointc.gif);'); + $img= new CImg('images/general/tree/zero.gif','i','22','14'); + break; + case 'L': + $td->AddOption('valign','top'); + if($this->tree[$id]['nodetype'] == 2){ + $div = new CTag('div','yes'); + $div->AddOption('style','height: 10px; width:22px; background-image:url(images/general/tree/pointc.gif);'); + + $img= new CImg('images/general/tree/plus.gif','y','22','14'); + $img->AddOption('onclick','javascript: tree.closeSNodeX('.$id.',this);'); + $img->AddOption('id','idi_'.$id); + $img->SetClass('imgnode'); + + $div->AddItem($img); + } + else { + $div = new CTag('div','yes'); + $div->AddOption('style','height: 10px; width:22px; background-image:url(images/general/tree/pointc.gif);'); + $div->AddItem(new CImg('images/general/tree/pointl.gif','y','22','14')); + } + $img=$div; + break; + case 'T': + $td->AddOption('valign','top'); + if($this->tree[$id]['nodetype'] == 2){ + $td->AddOption('style','width:22px; background-image:url(images/general/tree/pointc.gif);'); + $img= new CImg('images/general/tree/plus.gif','t','22','14'); + + $img->AddOption('onclick','javascript: tree.closeSNodeX('.$id.',this);'); + $img->AddOption('id','idi_'.$id); + $img->SetClass('imgnode'); + } + else { + $td->AddOption('style','width:22px; background-image:url(images/general/tree/pointc.gif);'); + $img= new CImg('images/general/tree/pointl.gif','t','22','14'); + } + break; + } + $td->AddItem($img); + $tr->AddItem($td); + + $td = new CCol(); + } + // echo $txt.' '.$this->tree[$id]['Name'].'<br />'; + return $tr; } - $count=0; - foreach($this->tree as $id => $rows){ - if($rows['nodetype'] == '2'){ - $js_node_list.='nodeid_list['.$count.'] = '.$id.';'; - $count++; - - $js .= 'treenode["'.$id.'"] = { status: \'close\', nodelist : \''.$rows['nodelist'].'\', parentid : \''.$rows['parentid'].'\'};'; + + public function CountDepth(){ + foreach($this->tree as $id => $rows){ + + if($rows['id'] == '0'){ + continue; + } + $parentid = $this->tree[$id]['parentid']; + + $this->tree[$id]['nodeimg'] = $this->GetImg($id,(isset($this->tree[$parentid]['nodeimg']))?($this->tree[$parentid]['nodeimg']):('')); + //$this->tree[$parentid]['childs'] = ($this->tree[$parentid]['childs']+$this->tree[$id]['childs']+1); + + $this->tree[$parentid]['nodetype'] = 2; + + $this->tree[$id]['Level'] = (isset($this->tree[$parentid]['Level']))?($this->tree[$parentid]['Level']+1):(1); + + ($this->maxlevel>$this->tree[$id]['Level'])?(''):($this->maxlevel = $this->tree[$id]['Level']); } + } -return $js."\n".$js_node_list."\n".' window.onload = function(){tree.init()}; -</script>'; -} - -function GetImg($id,$img){ - $img=str_replace('T','I',$img); - $img=str_replace('L','O',$img); - $ch = 'L'; - - $childs = $this->tree[$this->tree[$id]['parentid']]['childnodes']; - $childs_last = count($this->tree[$this->tree[$id]['parentid']]['childnodes'])-1; - if(isset($childs[$childs_last]) && (strcmp($childs[$childs_last],$id) != 0)){ - $ch='T'; + public function CreateJS(){ + global $page; + $js = ' + <script src="js/tree.js" type="text/javascript"></script> + <script src="js/cookies.js" type="text/javascript"></script> + <script type="text/javascript"> + var treenode = new Array(0); + var tree_name = "tree_'.$this->getUserAlias().'_'.$page["file"].'"; + '; + + foreach($this->tree as $id => $rows){ + $parentid = $rows['parentid']; + $this->tree[$parentid]['nodelist'].=$id.'.'; + } + + foreach($this->tree as $id => $rows){ + if($rows['nodetype'] == '2'){ + $js .= 'treenode['.$id.'] = { status: \'close\', nodelist : \''.$rows['nodelist'].'\', parentid : \''.$rows['parentid'].'\'};'; + } + } + $js.='window.onload = function(){tree.init()}; </script>'; + + return new CScript($js); } - $img.=$ch; -return $img; -} - -function CheckTree(){ - if(!is_array($this->tree)){ - return false; + + public function GetImg($id,$img){ + $img=str_replace('T','I',$img); + $img=str_replace('L','O',$img); + $ch = 'L'; + + $childs = $this->tree[$this->tree[$id]['parentid']]['childnodes']; + $childs_last = count($this->tree[$this->tree[$id]['parentid']]['childnodes'])-1; + + if(isset($childs[$childs_last]) && ($childs[$childs_last] != $id)){ + $ch='T'; + } + $img.=$ch; + return $img; } - foreach($this->tree as $id => $cell){ - $this->tree[$id]['nodetype'] = 0; + + public function CheckTree(){ + if(!is_array($this->tree)){ + return false; + } + foreach($this->tree as $id => $cell){ + $this->tree[$id]['nodetype'] = 0; + + $parentid=$cell['parentid']; + $this->tree[$parentid]['childnodes'][] = $cell['id']; + + $this->tree[$id]['nodelist'] = ''; + // echo $id.BR; + } - $parentid=$cell['parentid']; - $this->tree[$parentid]['childnodes'][] = $id; - - $this->tree[$id]['nodelist'] = ''; + return true; } -return true; -} - -function Destroy(){ - unset($this->tree); -} - -function getUserAlias(){ -global $USER_DETAILS; -return $USER_DETAILS["alias"]; -} + public function Destroy(){ + unset($this->tree); + } + + public function getUserAlias(){ + global $USER_DETAILS; + return $USER_DETAILS["alias"]; + } } ?>
\ No newline at end of file diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 11e9c650..583c80e4 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -62,7 +62,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!! require_once("include/classes/ciframe.inc.php"); require_once("include/classes/cpumenu.inc.php"); require_once("include/classes/graph.inc.php"); - require_once('include/classes/ctree.inc.php'); require_once('include/classes/cscript.inc.php'); // Include Tactical Overview modules diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php index 44f67ffb..c00cf1f1 100644 --- a/frontends/php/include/services.inc.php +++ b/frontends/php/include/services.inc.php @@ -416,20 +416,25 @@ $data[$period_start]['alarm'] = get_last_service_value($serviceid,$period_start); - $service_alarms = DBselect("SELECT clock,value FROM service_alarms". - " WHERE serviceid=".$serviceid." and clock>=".$period_start." and clock<=".$period_end." order by clock"); + $service_alarms = DBselect('SELECT clock,value '. + ' FROM service_alarms '. + ' WHERE serviceid='.$serviceid. + ' AND clock>='.$period_start. + ' AND clock<='.$period_end. + ' ORDER BY clock'); /* add alarms */ - while($db_alarm_row = DBfetch($service_alarms)) - { + while($db_alarm_row = DBfetch($service_alarms)){ $data[$db_alarm_row['clock']]['alarm'] = $db_alarm_row['value']; } /* add periodical downtimes */ - $service_times = DBselect('SELECT ts_from,ts_to FROM services_times WHERE type='.SERVICE_TIME_TYPE_UPTIME. - ' and serviceid='.$serviceid); - if($db_time_row = DBfetch($service_times)) - { + $service_times = DBselect('SELECT ts_from,ts_to '. + ' FROM services_times '. + ' WHERE type='.SERVICE_TIME_TYPE_UPTIME. + ' AND serviceid='.$serviceid); + + if($db_time_row = DBfetch($service_times)){ /* if exist any uptime - unmarked time is downtime */ $unmarked_period_type = 'dt'; do{ @@ -440,8 +445,7 @@ }while($db_time_row = DBfetch($service_times)); } - else - { + else{ /* if missed any uptime - unmarked time is uptime */ $unmarked_period_type = 'ut'; } @@ -449,8 +453,7 @@ /* add periodical downtimes */ $service_times = DBselect('SELECT ts_from,ts_to FROM services_times WHERE type='.SERVICE_TIME_TYPE_DOWNTIME. ' and serviceid='.$serviceid); - while($db_time_row = DBfetch($service_times)) - { + while($db_time_row = DBfetch($service_times)){ expand_periodical_service_times($data, $period_start, $period_end, $db_time_row['ts_from'], $db_time_row['ts_to'], @@ -678,7 +681,7 @@ $dt = 0; } } } else { - $rows['caption'] = '<font style="color: #888888;">'.$rows['caption'].'</font>'; + $rows['caption'] = new CSpan($rows['caption'],'unknown'); $temp[$rows['serviceid'].','.$linkid]=$rows; } return ; |
