summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-07 13:14:00 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-07 13:14:00 +0000
commitd1f0507236793e1d4b28eb213b17432cef9bdd99 (patch)
treed6c07129b66ba6acb0cac47fab9a6bf5452e7b86 /frontends/php/include
parent81c4d84a47e5d82758d45a83cd0b4b9cb35c7ea8 (diff)
downloadzabbix-d1f0507236793e1d4b28eb213b17432cef9bdd99.tar.gz
zabbix-d1f0507236793e1d4b28eb213b17432cef9bdd99.tar.xz
zabbix-d1f0507236793e1d4b28eb213b17432cef9bdd99.zip
- [DEV-137] improvements in permissions checks (Artem)
- [DEV-137] fixed issue "viewing items, hosts without group in latest data" (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5595 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/forms.inc.php125
-rw-r--r--frontends/php/include/html.inc.php13
-rw-r--r--frontends/php/include/import.inc.php19
-rw-r--r--frontends/php/include/maps.inc.php128
4 files changed, 146 insertions, 139 deletions
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 288a437b..fb774f30 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -995,8 +995,8 @@
'SELECT r.*,n.name as name FROM rights r, nodes n WHERE r.groupid='.$_REQUEST["usrgrpid"].
' AND r.type='.RESOURCE_TYPE_NODE.' AND r.id=n.nodeid',
'SELECT r.*, n.name as node_name, g.name as name FROM groups g '.
- ' left join rights r on r.type='.RESOURCE_TYPE_GROUP.' AND r.id=g.groupid '.
- ' left join nodes n on n.nodeid='.DBid2nodeid('g.groupid').
+ ' LEFT JOIN rights r on r.type='.RESOURCE_TYPE_GROUP.' AND r.id=g.groupid '.
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('g.groupid').
' WHERE r.groupid='.$_REQUEST["usrgrpid"],
);
foreach($sqls as $sql)
@@ -2327,10 +2327,12 @@
$comments = $trigger["comments"];
$url = $trigger["url"];
- $trigs=DBselect("SELECT t.triggerid,t.description,t.expression FROM triggers t,trigger_depends d".
- " WHERE t.triggerid=d.triggerid_up AND d.triggerid_down=".$_REQUEST["triggerid"]);
- while($trig=DBfetch($trigs))
- {
+ $trigs=DBselect('SELECT t.triggerid,t.description,t.expression '.
+ ' FROM triggers t,trigger_depends d '.
+ ' WHERE t.triggerid=d.triggerid_up '.
+ ' AND d.triggerid_down='.$_REQUEST['triggerid']);
+
+ while($trig=DBfetch($trigs)){
if(uint_in_array($trig["triggerid"],$dependencies)) continue;
array_push($dependencies,$trig["triggerid"]);
}
@@ -2417,11 +2419,14 @@
$frmTrig->Show();
}
- function insert_trigger_comment_form($triggerid)
- {
- $trigger = DBfetch(DBselect('SELECT t.*, h.* FROM triggers t, functions f, items i, hosts h '.
- ' WHERE t.triggerid='.$triggerid.' AND f.triggerid=t.triggerid AND f.itemid=i.itemid '.
- ' AND i.hostid=h.hostid '));
+ function insert_trigger_comment_form($triggerid){
+
+ $trigger = DBfetch(DBselect('SELECT t.*, h.* '.
+ ' FROM triggers t, functions f, items i, hosts h '.
+ ' WHERE t.triggerid='.$triggerid.
+ ' AND f.triggerid=t.triggerid '.
+ ' AND f.itemid=i.itemid '.
+ ' AND i.hostid=h.hostid '));
$frmComent = new CFormTable(S_COMMENTS." for ".$trigger['host']." : \"".expand_trigger_description_by_data($trigger)."\"");
$frmComent->SetHelp("web.tr_comments.comments.php");
@@ -2433,8 +2438,7 @@
$frmComent->Show();
}
- function insert_graph_form()
- {
+ function insert_graph_form(){
global $_REQUEST;
$frmGraph = new CFormTable(S_GRAPH,null,'post');
@@ -3734,7 +3738,7 @@ include_once 'include/discovery.inc.php';
if($resourceid > 0){
$result=DBselect('SELECT n.name as node_name,h.host,i.description,i.itemid,i.key_ '.
' FROM hosts h,items i '.
- ' left join nodes n on n.nodeid='.DBid2nodeid('i.itemid').
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('i.itemid').
' WHERE h.hostid=i.hostid '.
' AND h.status='.HOST_STATUS_MONITORED.
' AND i.status='.ITEM_STATUS_ACTIVE.
@@ -3797,7 +3801,7 @@ include_once 'include/discovery.inc.php';
if($resourceid > 0){
$result=DBselect('SELECT n.name as node_name,h.host,i.description,i.itemid,i.key_ '.
' FROM hosts h,items i '.
- ' left join nodes n on n.nodeid='.DBid2nodeid('i.itemid').
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('i.itemid').
' WHERE h.hostid=i.hostid '.
' AND h.status='.HOST_STATUS_MONITORED.
' AND i.status='.ITEM_STATUS_ACTIVE.
@@ -4804,16 +4808,15 @@ include_once 'include/discovery.inc.php';
$frmEl->SetHelp("web.sysmap.host.php");
$frmEl->AddVar("sysmapid",$_REQUEST["sysmapid"]);
- if(isset($_REQUEST["selementid"]))
- {
+ if(isset($_REQUEST["selementid"])){
$frmEl->AddVar("selementid",$_REQUEST["selementid"]);
$element = get_sysmaps_element_by_selementid($_REQUEST["selementid"]);
$frmEl->SetTitle("Map element \"".$element["label"]."\"");
}
- if(isset($_REQUEST["selementid"]) && !isset($_REQUEST["form_refresh"]))
- {
+ if(isset($_REQUEST["selementid"]) && !isset($_REQUEST["form_refresh"])){
+
$elementid = $element["elementid"];
$elementtype = $element["elementtype"];
$label = $element["label"];
@@ -4826,8 +4829,8 @@ include_once 'include/discovery.inc.php';
$label_location = $element["label_location"];
if(is_null($label_location)) $label_location = -1;
}
- else
- {
+ else{
+
$elementid = get_request("elementid", 0);
$elementtype = get_request("elementtype", SYSMAP_ELEMENT_TYPE_HOST);
$label = get_request("label", "");
@@ -4842,17 +4845,19 @@ include_once 'include/discovery.inc.php';
$cmbType = new CComboBox("elementtype",$elementtype,"submit()");
- $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT);
- $allowed_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $available_triggers = get_accessible_triggers(PERM_READ_ONLY, null, get_current_nodeid());
- $db_hosts = DBselect("SELECT DISTINCT n.name as node_name,h.hostid,h.host FROM hosts h".
- " left join nodes n on n.nodeid=".DBid2nodeid("h.hostid").
- " WHERE h.hostid not in(".$denyed_hosts.")".
- " order by node_name,h.host");
+ $db_hosts = DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host '.
+ ' FROM hosts h'.
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('h.hostid').
+ ' WHERE h.hostid IN ('.$available_hosts.')'.
+ ' ORDER BY node_name,h.host');
if($db_hosts)
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST);
- $db_maps = DBselect("SELECT sysmapid FROM sysmaps WHERE sysmapid!=".$_REQUEST["sysmapid"]);
+ $db_maps = DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid!='.$_REQUEST['sysmapid']);
if(DBfetch($db_maps))
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_MAP, S_MAP);
@@ -4871,14 +4876,13 @@ include_once 'include/discovery.inc.php';
$cmbLocation->AddItem(3,S_TOP);
$frmEl->AddRow(S_LABEL_LOCATION,$cmbLocation);
- if($elementtype==SYSMAP_ELEMENT_TYPE_HOST)
- {
- $host = "";
+ if($elementtype==SYSMAP_ELEMENT_TYPE_HOST) {
+ $host = '';
$host_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host '.
' FROM hosts h '.
' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid("h.hostid").
- ' WHERE h.hostid not in('.$denyed_hosts.') '.
+ ' WHERE h.hostid IN ('.$available_hosts.') '.
' AND hostid='.$elementid.
' ORDER BY node_name,h.host'));
if($host_info)
@@ -4899,66 +4903,65 @@ include_once 'include/discovery.inc.php';
"T")
));
}
- elseif($elementtype==SYSMAP_ELEMENT_TYPE_MAP)
- {
+ else if($elementtype==SYSMAP_ELEMENT_TYPE_MAP){
$cmbMaps = new CComboBox("elementid",$elementid);
$db_maps = DBselect('SELECT DISTINCT n.name as node_name,s.sysmapid,s.name '.
' FROM sysmaps s'.
- ' left join nodes n on n.nodeid='.DBid2nodeid("s.sysmapid").
- ' order by node_name,s.name');
- while($db_map = DBfetch($db_maps))
- {
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('s.sysmapid').
+ ' ORDER BY node_name,s.name');
+ while($db_map = DBfetch($db_maps)){
if(!sysmap_accessible($db_map["sysmapid"],PERM_READ_ONLY)) continue;
$node_name = isset($db_map['node_name']) ? '('.$db_map['node_name'].') ' : '';
$cmbMaps->AddItem($db_map["sysmapid"],$node_name.$db_map["name"]);
}
$frmEl->AddRow(S_MAP, $cmbMaps);
}
- elseif($elementtype==SYSMAP_ELEMENT_TYPE_TRIGGER)
- {
+ else if($elementtype==SYSMAP_ELEMENT_TYPE_TRIGGER){
$trigger = "";
- $trigger_info = DBfetch(DBselect("SELECT DISTINCT n.name as node_name,h.hostid,h.host,t.*".
- " FROM triggers t left join functions f on t.triggerid=f.triggerid ".
- " left join items i on i.itemid=f.itemid left join hosts h on h.hostid=i.hostid ".
- " left join nodes n on n.nodeid=".DBid2nodeid("t.triggerid").
- " WHERE h.hostid not in (".$denyed_hosts.") AND t.triggerid=".$elementid.
- " order by node_name,h.host,t.description"));
+ $trigger_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host,t.*'.
+ ' FROM triggers t '.
+ ' LEFT JOIN functions f on t.triggerid=f.triggerid '.
+ ' LEFT JOIN items i on i.itemid=f.itemid '.
+ ' LEFT JOIN hosts h on h.hostid=i.hostid '.
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('t.triggerid').
+ ' WHERE t.triggerid='.$elementid.
+ ' AND t.triggerid IN ('.$available_triggers.') '.
+ ' ORDER BY node_name,h.host,t.description'));
if($trigger_info)
$trigger = expand_trigger_description_by_data($trigger_info);
else
$elementid=0;
- if($elementid==0)
- {
- $trigger = "";
+ if($elementid==0){
+ $trigger = '';
$elementid = 0;
}
- $frmEl->AddVar("elementid",$elementid);
+ $frmEl->AddVar('elementid',$elementid);
$frmEl->AddRow(S_TRIGGER, array(
- new CTextBox("trigger",$trigger,32,'yes'),
- new CButton("btn1",S_SELECT,"return PopUp('popup.php?dstfrm=".$frmEl->GetName().
+ new CTextBox('trigger',$trigger,32,'yes'),
+ new CButton('btn1',S_SELECT,"return PopUp('popup.php?dstfrm=".$frmEl->GetName().
"&dstfld1=elementid&dstfld2=trigger&srctbl=triggers&srcfld1=triggerid&srcfld2=description');",
"T")
));
}
- elseif($elementtype==SYSMAP_ELEMENT_TYPE_HOST_GROUP)
- {
- $group = "";
+ else if($elementtype==SYSMAP_ELEMENT_TYPE_HOST_GROUP){
+ $group = '';
- $group_info = DBfetch(DBselect("SELECT DISTINCT n.name as node_name,g.groupid,g.name FROM groups g ".
- " left join nodes n on n.nodeid=".DBid2nodeid("g.groupid").
- " WHERE g.groupid in (".$allowed_groups.") AND g.groupid=".$elementid.
- " order by node_name,g.name"));
+ $group_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name '.
+ ' FROM groups g '.
+ ' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('g.groupid').
+ ' WHERE g.groupid in ('.$available_groups.') '.
+ ' AND g.groupid='.$elementid.
+ ' ORDER BY node_name,g.name'));
if($group_info)
$group = $group_info["name"];
else
$elementid=0;
- if($elementid==0)
- {
+ if($elementid==0){
$group = "";
$elementid = 0;
}
diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php
index a3c7ff08..a84b2139 100644
--- a/frontends/php/include/html.inc.php
+++ b/frontends/php/include/html.inc.php
@@ -65,16 +65,12 @@
{
$result = "";
- if(is_array($var))
- {
+ if(is_array($var)){
foreach($var as $id => $par)
- $result .= prepare_url($par,
- isset($varname) ? $varname."[".$id."]": $id
- );
+ $result .= prepare_url($par,isset($varname) ? $varname."[".$id."]": $id);
}
- else
- {
- $result = "&".$varname."=".urlencode($var);
+ else{
+ $result = '&'.$varname.'='.urlencode($var);
}
return $result;
}
@@ -100,6 +96,7 @@
if(isset($var)){
$result = prepare_url($var,$name);
}
+
return $result;
}
diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php
index 242f4871..0563cc37 100644
--- a/frontends/php/include/import.inc.php
+++ b/frontends/php/include/import.inc.php
@@ -36,13 +36,13 @@
$this->trigger = array('exist' => 0, 'missed' => 0);
$this->graph = array('exist' => 0, 'missed' => 0);
- $this->accessible_groups = get_accessible_groups_by_user($USER_DETAILS,
+ $this->available_groups = get_accessible_groups_by_user($USER_DETAILS,
PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, get_current_nodeid());
- $this->accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS,
+ $this->available_hosts = get_accessible_hosts_by_user($USER_DETAILS,
PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, get_current_nodeid());
- $this->accessible_nodes = get_accessible_nodes_by_user($USER_DETAILS,
+ $this->available_nodes = get_accessible_nodes_by_user($USER_DETAILS,
PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, get_current_nodeid());
}
@@ -92,7 +92,7 @@
if($host_data = DBfetch(DBselect('select hostid from hosts'.
' where host='.zbx_dbstr($data['name']).
- ' and '.DBin_node('hostid',get_current_nodeid(false)))))
+ ' and '.DBin_node('hostid',get_current_nodeid(false)))))
{ /* exist */
if($this->host['exist']==1) /* skip */
{
@@ -100,7 +100,7 @@
info('Host ['.$data['name'].'] skipped - user rule');
break; // case
}
- if(!uint_in_array($host_data['hostid'], $this->accessible_hosts)){
+ if(!uint_in_array($host_data['hostid'], $this->available_hosts)){
error('Host ['.$data['name'].'] skipped - Access deny.');
break; // case
}
@@ -117,8 +117,8 @@
break; // case
}
-// if( count($this->accessible_nodes) > 0 ){
- if(!uint_in_array(get_current_nodeid(),$this->accessible_nodes)){
+// if( count($this->available_nodes) > 0 ){
+ if(!uint_in_array(get_current_nodeid(),$this->available_nodes)){
error('Host ['.$data['name'].'] skipped - Access deny.');
break; // case
}
@@ -183,7 +183,6 @@
global $USER_DETAILS;
$data = &$this->data[$name];
-
switch($name)
{
case XML_TAG_HOST:
@@ -243,7 +242,7 @@
break; // case
}
- if(!uint_in_array($group["groupid"], $this->accessible_groups))
+ if(!uint_in_array($group["groupid"], $this->available_groups))
{
error('Group ['.$this->element_data.'] skipped - Access deny.');
break; // case
@@ -287,7 +286,7 @@
break; // case
}
- if(!uint_in_array($template["hostid"], $this->accessible_hosts))
+ if(!uint_in_array($template["hostid"], $this->available_hosts))
{
error('Template ['.$this->element_data.'] skipped - Access deny.');
break; // case
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index 6c7c24e6..303bced6 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -77,8 +77,7 @@
* Eugene Grigorjev
*
*/
- function sysmap_accessible($sysmapid,$perm)
- {
+ function sysmap_accessible($sysmapid,$perm){
global $USER_DETAILS;
$result = false;
@@ -102,43 +101,42 @@
$result &= sysmap_accessible($se_data['elementid'], PERM_READ_ONLY);
break;
case SYSMAP_ELEMENT_TYPE_TRIGGER:
- if(DBfetch(DBselect('SELECT triggerid FROM triggers WHERE triggerid='.$se_data['elementid']))){
- $sql = 'SELECT DISTINCT t.triggerid'.
- ' FROM triggers t,items i,functions f'.
- ' WHERE f.itemid=i.itemid '.
- ' AND t.triggerid=f.triggerid'.
- ' AND i.hostid NOT IN ('.$available_hosts.') '.
- ' AND t.triggerid='.$se_data['elementid'];
- if(DBfetch(DBselect($sql,1))){
+ $available_triggers = get_accessible_triggers(PERM_READ_ONLY, null, get_current_nodeid());
+
+ $sql = 'SELECT t.triggerid '.
+ ' FROM triggers t'.
+ ' WHERE t.triggerid='.$se_data['elementid'].
+ ' AND t.triggerid NOT IN ('.$available_triggers.') ';
+ if(DBfetch(DBselect($sql,1))){
$result = false;
- }
- }
+ }
+
break;
case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
- $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY, null, PERM_RES_IDS_ARRAY);
+ $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY, null);
- $sql = 'SELECT groupid '.
- ' FROM groups '.
- ' WHERE groupid='.$se_data['elementid'];
+ $sql = 'SELECT g.groupid '.
+ ' FROM groups g '.
+ ' WHERE g.groupid='.$se_data['elementid'].
+ ' AND g.groupid NOT IN('.$available_groups.') ';
- if(DBfetch(DBselect($sql,1)) && !uint_in_array($se_data['elementid'],$available_groups)){
+ if(DBfetch(DBselect($sql,1))){
$result = false;
}
break;
}
}
}
- else
- {
- if(DBselect('select sysmapid from sysmaps where sysmapid='.$sysmapid.
- ' and '.DBin_node('sysmapid', get_current_nodeid($perm))))
+ else{
+ if(DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid='.$sysmapid.
+ ' AND '.DBin_node('sysmapid', get_current_nodeid($perm))))
$result = true;
}
return $result;
}
function get_sysmap_by_sysmapid($sysmapid){
- $row = DBfetch(DBselect("select * from sysmaps where sysmapid=".$sysmapid));
+ $row = DBfetch(DBselect('SELECT * FROM sysmaps WHERE sysmapid='.$sysmapid));
if($row){
return $row;
}
@@ -147,7 +145,7 @@
}
function get_sysmaps_element_by_selementid($selementid){
- $sql="select * from sysmaps_elements where selementid=$selementid";
+ $sql="select * FROM sysmaps_elements WHERE selementid=$selementid";
$result=DBselect($sql);
$row=DBfetch($result);
if($row){
@@ -181,7 +179,7 @@
{
return DBexecute("update sysmaps set name=".zbx_dbstr($name).",width=$width,height=$height,".
"backgroundid=".$backgroundid.",label_type=$label_type,".
- "label_location=$label_location where sysmapid=$sysmapid");
+ "label_location=$label_location WHERE sysmapid=$sysmapid");
}
// Delete System Map
@@ -194,16 +192,16 @@
while($rows = DBfetch($res)){
$result&=delete_link($rows['linkid']);
}
-// $result = DBexecute("delete from sysmaps_links where sysmapid=$sysmapid");
+// $result = DBexecute("delete FROM sysmaps_links WHERE sysmapid=$sysmapid");
// if(!$result) return $result;
- $result = DBexecute("delete from sysmaps_elements where sysmapid=$sysmapid");
+ $result = DBexecute("delete FROM sysmaps_elements WHERE sysmapid=$sysmapid");
if(!$result) return $result;
$result = rm4favorites('web.favorite.sysmapids',$sysmapd,ZBX_FAVORITES_ALL,'sysmapid');
if(!$result) return $result;
- return DBexecute("delete from sysmaps where sysmapid=$sysmapid");
+ return DBexecute("delete FROM sysmaps WHERE sysmapid=$sysmapid");
}
// LINKS
@@ -253,7 +251,7 @@
function delete_link($linkid){
$result = delete_all_link_triggers($linkid);
- $result&= DBexecute("delete from sysmaps_links where linkid=$linkid");
+ $result&= DBexecute("delete FROM sysmaps_links WHERE linkid=$linkid");
return $result;
}
@@ -304,8 +302,8 @@
if(bccomp($sysmapid ,$elementid)==0) return TRUE;
- $db_elements = DBselect("select elementid, elementtype from sysmaps_elements".
- " where sysmapid=$elementid");
+ $db_elements = DBselect("select elementid, elementtype FROM sysmaps_elements".
+ " WHERE sysmapid=$elementid");
while($element = DBfetch($db_elements))
{
@@ -341,7 +339,7 @@
return $selementid;
}
- # Update Element from system map
+ # Update Element FROM system map
function update_sysmap_element($selementid,$sysmapid,$elementid,$elementtype,
$label,$x,$y,$iconid_off,$iconid_unknown,$iconid_on,$url,$label_location)
@@ -363,7 +361,7 @@
/******************************************************************************
* *
- * Purpose: Delete Element from sysmap definition *
+ * Purpose: Delete Element FROM sysmap definition *
* *
* Comments: !!! Don't forget sync code with C !!! *
* *
@@ -382,7 +380,7 @@
if(!$result) return $result;
- return DBexecute("delete from sysmaps_elements where selementid=$selementid");
+ return DBexecute("delete FROM sysmaps_elements WHERE selementid=$selementid");
}
/******************************************************************************
@@ -391,8 +389,8 @@
* *
******************************************************************************/
function delete_sysmaps_elements_with_hostid($hostid){
- $db_elements = DBselect("select selementid from sysmaps_elements".
- " where elementid=$hostid and elementtype=".SYSMAP_ELEMENT_TYPE_HOST);
+ $db_elements = DBselect("select selementid FROM sysmaps_elements".
+ " WHERE elementid=$hostid AND elementtype=".SYSMAP_ELEMENT_TYPE_HOST);
while($db_element = DBfetch($db_elements)){
delete_sysmaps_element($db_element["selementid"]);
}
@@ -400,8 +398,8 @@
}
function delete_sysmaps_elements_with_sysmapid($sysmapid){
- $db_elements = DBselect("select selementid from sysmaps_elements".
- " where elementid=$sysmapid and elementtype=".SYSMAP_ELEMENT_TYPE_MAP);
+ $db_elements = DBselect("select selementid FROM sysmaps_elements".
+ " WHERE elementid=$sysmapid AND elementtype=".SYSMAP_ELEMENT_TYPE_MAP);
while($db_element = DBfetch($db_elements))
{
delete_sysmaps_element($db_element["selementid"]);
@@ -438,7 +436,7 @@
function get_png_by_selementid($selementid)
{
- $elements = DBselect("select * from sysmaps_elements where selementid=$selementid");
+ $elements = DBselect("select * FROM sysmaps_elements WHERE selementid=$selementid");
if(!$elements) return FALSE;
$element = DBfetch($elements);
@@ -474,26 +472,36 @@
$el_type =& $db_element["elementtype"];
$sql = array(
- SYSMAP_ELEMENT_TYPE_TRIGGER => 'select distinct t.triggerid, t.priority, t.value, t.description, t.expression, h.host '.
- 'from triggers t, items i, functions f, hosts h where t.triggerid='.$db_element['elementid'].
- ' and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid '.
- ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE,
- SYSMAP_ELEMENT_TYPE_HOST_GROUP => 'select distinct t.triggerid, t.priority, t.value,'.
- ' t.description, t.expression, h.host, g.name as el_name '.
- ' from items i,functions f,triggers t,hosts h,hosts_groups hg,groups g '.
- ' where h.hostid=i.hostid and hg.groupid=g.groupid and g.groupid='.$db_element['elementid'].
- ' and hg.hostid=h.hostid and i.itemid=f.itemid'.
- ' and f.triggerid=t.triggerid and t.status='.TRIGGER_STATUS_ENABLED.
- ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE,
- SYSMAP_ELEMENT_TYPE_HOST => 'select distinct t.triggerid, t.priority, t.value,'.
- ' t.description, t.expression, h.host, h.host as el_name'.
- ' from items i,functions f,triggers t,hosts h where h.hostid=i.hostid'.
- ' and i.hostid='.$db_element['elementid'].' and i.itemid=f.itemid'.
- ' and f.triggerid=t.triggerid and t.status='.TRIGGER_STATUS_ENABLED.
- ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE
+ SYSMAP_ELEMENT_TYPE_TRIGGER => 'SELECT DISTINCT t.triggerid, t.priority, t.value, t.description, t.expression, h.host '.
+ ' FROM triggers t, items i, functions f, hosts h '.
+ ' WHERE t.triggerid='.$db_element['elementid'].
+ ' AND h.hostid=i.hostid '.
+ ' AND i.itemid=f.itemid '.
+ ' AND f.triggerid=t.triggerid '.
+ ' AND h.status='.HOST_STATUS_MONITORED.
+ ' AND i.status='.ITEM_STATUS_ACTIVE,
+ SYSMAP_ELEMENT_TYPE_HOST_GROUP => 'SELECT DISTINCT t.triggerid, t.priority, t.value, t.description, t.expression, h.host, g.name as el_name '.
+ ' FROM items i,functions f,triggers t,hosts h,hosts_groups hg,groups g '.
+ ' WHERE h.hostid=i.hostid '.
+ ' AND hg.groupid=g.groupid '.
+ ' AND g.groupid='.$db_element['elementid'].
+ ' AND hg.hostid=h.hostid '.
+ ' AND i.itemid=f.itemid'.
+ ' AND f.triggerid=t.triggerid '.
+ ' AND t.status='.TRIGGER_STATUS_ENABLED.
+ ' AND h.status='.HOST_STATUS_MONITORED.
+ ' AND i.status='.ITEM_STATUS_ACTIVE,
+ SYSMAP_ELEMENT_TYPE_HOST => 'SELECT DISTINCT t.triggerid, t.priority, t.value, t.description, t.expression, h.host, h.host as el_name'.
+ ' FROM items i,functions f,triggers t,hosts h WHERE h.hostid=i.hostid'.
+ ' AND i.hostid='.$db_element['elementid'].
+ ' AND i.itemid=f.itemid'.
+ ' AND f.triggerid=t.triggerid '.
+ ' AND t.status='.TRIGGER_STATUS_ENABLED.
+ ' AND h.status='.HOST_STATUS_MONITORED.
+ ' AND i.status='.ITEM_STATUS_ACTIVE
);
- if( isset($sql[$el_type]) )
- {
+
+ if( isset($sql[$el_type]) ){
$db_triggers = DBselect($sql[$el_type]);
$trigger = DBfetch($db_triggers);
if($trigger)
@@ -542,11 +550,11 @@
}
elseif($el_type==SYSMAP_ELEMENT_TYPE_MAP)
{
- $db_map = DBfetch(DBselect('select name from sysmaps where sysmapid='.$db_element["elementid"]));
+ $db_map = DBfetch(DBselect('select name FROM sysmaps WHERE sysmapid='.$db_element["elementid"]));
$el_name = $db_map['name'];
- $db_subelements = DBselect("select selementid from sysmaps_elements".
- " where sysmapid=".$db_element["elementid"]);
+ $db_subelements = DBselect("select selementid FROM sysmaps_elements".
+ " WHERE sysmapid=".$db_element["elementid"]);
while($db_subelement = DBfetch($db_subelements))
{// recursion
$inf = get_info_by_selementid($db_subelement["selementid"]);