summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-12 07:01:06 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-12 07:01:06 +0000
commit06f68476ff0a32ab823885118054595894016f06 (patch)
treeb0f18b6058f40b4daa8aafc0c4e6995372ccaf8d /frontends/php/include
parentb327677b4e405ccc71f6292fad2ff08abe2f7c99 (diff)
- fixes to zabbix_sender and other changes (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@2823 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/acknow.inc.php5
-rw-r--r--frontends/php/include/actions.inc.php13
-rw-r--r--frontends/php/include/bulkloader.inc.php8
-rw-r--r--frontends/php/include/config.inc.php354
-rw-r--r--frontends/php/include/db.inc.php10
-rw-r--r--frontends/php/include/forms.inc.php24
-rw-r--r--frontends/php/include/graphs.inc.php31
-rw-r--r--frontends/php/include/hosts.inc.php52
-rw-r--r--frontends/php/include/items.inc.php23
-rw-r--r--frontends/php/include/maps.inc.php20
-rw-r--r--frontends/php/include/media.inc.php5
-rw-r--r--frontends/php/include/profiles.inc.php2
-rw-r--r--frontends/php/include/screens.inc.php15
-rw-r--r--frontends/php/include/services.inc.php2
-rw-r--r--frontends/php/include/triggers.inc.php66
-rw-r--r--frontends/php/include/users.inc.php18
16 files changed, 187 insertions, 461 deletions
diff --git a/frontends/php/include/acknow.inc.php b/frontends/php/include/acknow.inc.php
index 2db7d35c..00db756a 100644
--- a/frontends/php/include/acknow.inc.php
+++ b/frontends/php/include/acknow.inc.php
@@ -23,8 +23,9 @@
{
$db_alarms = DBselect("select * from alarms where triggerid=$triggerid".
" order by clock desc limit 1");
- if(DBnum_rows($db_alarms)!=1) return FALSE;
- return DBfetch($db_alarms);
+ $row=DBfetch($db_alarms);
+ if(!$row) return FALSE;
+ return $row;
}
function get_acknowledges_by_alarmid($alarmid)
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index fba6096a..2beb10f2 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -23,9 +23,10 @@
{
$sql="select * from actions where actionid=$actionid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -138,11 +139,11 @@
$sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"];
$result=DBselect($sql);
- if(DBnum_rows($result)!=1)
+ $row=DBfetch($result);
+ if(!$row)
{
return;
}
- $row=DBfetch($result);
$host_template=get_host_by_hostid($row["hostid"]);
@@ -378,7 +379,7 @@
}
if($cmd_items[2] == "#")
{ // group
- if(DBnum_rows(DBselect("select groupid from groups where name=".zbx_dbstr($cmd_items[1])))!=1)
+ if(!DBfetch(DBselect("select groupid from groups where name=".zbx_dbstr($cmd_items[1]))))
{
error("Uncnown group name: '".$cmd_items[1]."' in command ".$cmd."'");
return FALSE;
@@ -386,7 +387,7 @@
}
elseif($cmd_items[2] == ":")
{ // host
- if(DBnum_rows(DBselect("select hostid from hosts where host=".zbx_dbstr($cmd_items[1])))!=1)
+ if(!DBfetch(DBselect("select hostid from hosts where host=".zbx_dbstr($cmd_items[1]))))
{
error("Uncnown host name '".$cmd_items[1]."' in command '".$cmd."'");
return FALSE;
diff --git a/frontends/php/include/bulkloader.inc.php b/frontends/php/include/bulkloader.inc.php
index 1de27ccb..0175c167 100644
--- a/frontends/php/include/bulkloader.inc.php
+++ b/frontends/php/include/bulkloader.inc.php
@@ -29,9 +29,9 @@ include_once "include/config.inc.php";
function create_Host_Group($group)
{
$result=DBselect("select distinct(groupid) from groups where name=".zbx_dbstr($group));
- if(DBnum_rows($result)>0)
+ $row=DBfetch($result);
+ if($row)
{
- $row=DBfetch($result);
return $row["groupid"];
}
@@ -51,9 +51,9 @@ include_once "include/config.inc.php";
function create_User_Group($group)
{
$result=DBselect("select distinct(usrgrpid) from usrgrp where name='$group'");
- if(DBnum_rows($result)>0)
+ $row=DBfetch($result);
+ if($row)
{
- $row=DBfetch($result);
return $row["usrgrpid"];
}
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 4fc628c9..08f92c81 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -338,224 +338,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
return $cnt;
}
-/*
- function check_anyright($right,$permission)
- {
- global $USER_DETAILS;
-
- $sql="select permission from rights where name='Default permission' and userid=".$USER_DETAILS["userid"];
- $result=DBselect($sql);
-
- $default_permission="H";
- if(DBnum_rows($result)>0)
- {
- $default_permission="";
- while($row=DBfetch($result))
- {
- $default_permission=$default_permission.$row["permission"];
- }
- }
-# default_permission
-
- $sql="select permission from rights where name=".zbx_dbstr($right)." and id!=0 and userid=".$USER_DETAILS["userid"];
- $result=DBselect($sql);
-
- $all_permissions="";
- if(DBnum_rows($result)>0)
- {
- while($row=DBfetch($result))
- {
- $all_permissions=$all_permissions.$row["permission"];
- }
- }
-# all_permissions
-
-// echo "$all_permissions|$default_permission<br>";
-
- switch ($permission) {
- case 'A':
- if(strstr($all_permissions,"A"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"A"))
- {
- return 1;
- }
- break;
- case 'R':
- if(strstr($all_permissions,"R"))
- {
- return 1;
- }
- else if(strstr($all_permissions,"U"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"R"))
- {
- return 1;
- }
- else if(strstr($default_permission,"U"))
- {
- return 1;
- }
- break;
- case 'U':
- if(strstr($all_permissions,"U"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"U"))
- {
- return 1;
- }
- break;
- default:
- return 0;
- }
- return 0;
- }
-*/
-/*
- function check_right($right,$permission,$id)
- {
-// global $USER_DETAILS;
- global $USER_RIGHTS;
-
- $default_permission="H";
- $group_permission="";
- $id_permission="";
-// echo $id,"<br>";
-// echo DBnum_rows($rights),"<br>";
- if(isset($USER_RIGHTS[0]["name"]))
- {
- $default_permission="";
- for($i=0;isset($USER_RIGHTS[$i]["name"]);$i++)
- {
-// echo "*";
- if($USER_RIGHTS[$i]["name"] == 'Default permission')
- $default_permission=$default_permission.$USER_RIGHTS[$i]["permission"];
- if(($USER_RIGHTS[$i]["name"] == $right)&&($USER_RIGHTS[$i]["id"]==0))
- $group_permission=$group_permission.$USER_RIGHTS[$i]["permission"];
- if(($USER_RIGHTS[$i]["name"] == $right)&&($USER_RIGHTS[$i]["id"]==$id))
- $id_permission=$id_permission.$USER_RIGHTS[$i]["permission"];
- }
- }
-// echo $default_permission,"<br>";
-
-# id_permission
-// echo "$id_permission|$group_permission|$default_permission<br>";
-
- switch ($permission) {
- case 'A':
- if(strstr($id_permission,"H"))
- {
- return 0;
- }
- else if(strstr($id_permission,"A"))
- {
- return 1;
- }
- if(strstr($group_permission,"H"))
- {
- return 0;
- }
- else if(strstr($group_permission,"A"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"A"))
- {
- return 1;
- }
- break;
- case 'R':
- if(strstr($id_permission,"H"))
- {
- return 0;
- }
- else if(strstr($id_permission,"R"))
- {
- return 1;
- }
- else if(strstr($id_permission,"U"))
- {
- return 1;
- }
- if(strstr($group_permission,"H"))
- {
- return 0;
- }
- else if(strstr($group_permission,"R"))
- {
- return 1;
- }
- else if(strstr($group_permission,"U"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"R"))
- {
- return 1;
- }
- else if(strstr($default_permission,"U"))
- {
- return 1;
- }
- break;
- case 'U':
- if(strstr($id_permission,"H"))
- {
- return 0;
- }
- else if(strstr($id_permission,"U"))
- {
- return 1;
- }
- if(strstr($group_permission,"H"))
- {
- return 0;
- }
- else if(strstr($group_permission,"U"))
- {
- return 1;
- }
- if(strstr($default_permission,"H"))
- {
- return 0;
- }
- else if(strstr($default_permission,"U"))
- {
- return 1;
- }
- break;
- default:
- return 0;
- }
- return 0;
- }
-*/
// The hash has form <md5sum of triggerid>,<sum of priorities>
function calc_trigger_hash()
@@ -582,9 +364,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select * from images where imagetype=$imagetype and name=".zbx_dbstr($name);
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -596,9 +379,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select * from functions where functionid=$functionid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -611,10 +395,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select * from config";
$result=DBselect($sql);
-
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -1054,84 +838,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
echo "\n";
}
-/*
- function check_authorisation()
- {
- global $page;
- global $PHP_AUTH_USER,$PHP_AUTH_PW;
- global $USER_DETAILS;
- global $USER_RIGHTS;
- global $_COOKIE;
- global $_REQUEST;
-// global $sessionid;
-
- if(isset($_COOKIE["sessionid"]))
- {
- $sessionid=$_COOKIE["sessionid"];
- }
- else
- {
- unset($sessionid);
- }
-
- if(isset($sessionid))
- {
- $sql="select u.userid,u.alias,u.name,u.surname,u.lang,u.refresh from sessions s,users u where s.sessionid=".zbx_dbstr($sessionid)." and s.userid=u.userid and ((s.lastaccess+u.autologout>".time().") or (u.autologout=0))";
- $result=DBselect($sql);
- if(DBnum_rows($result)==1)
- {
-// setcookie("sessionid",$sessionid,time()+3600);
- setcookie("sessionid",$sessionid);
- $sql="update sessions set lastaccess=".time()." where sessionid=".zbx_dbstr($sessionid);
- DBexecute($sql);
- $USER_DETAILS=DBfetch($result);
-
- $result2=DBselect("select * from rights where userid=".$USER_DETAILS["userid"]);
- $i=0;
- while($row=DBfetch($result2))
- {
- $USER_RIGHTS[$i]["name"]=$row["name"];
- $USER_RIGHTS[$i]["id"]=$row["id"];
- $USER_RIGHTS[$i]["permission"]=$row["permission"];
- $i++;
- }
- return;
- }
- else
- {
- setcookie("sessionid",$sessionid,time()-3600);
- unset($sessionid);
- }
- }
-
- $sql="select u.userid,u.alias,u.name,u.surname,u.lang,u.refresh from users u where u.alias='guest'";
- $result=DBselect($sql);
- if(DBnum_rows($result)==1)
- {
- $USER_DETAILS=DBfetch($result);
- $result2=DBselect("select * from rights where userid=".$USER_DETAILS["userid"]);
- $i=0;
- while($row=DBfetch($result2))
- {
- $USER_RIGHTS[$i]["name"]=$row["name"];
- $USER_RIGHTS[$i]["id"]=$row["id"];
- $USER_RIGHTS[$i]["permission"]=$row["permission"];
- $i++;
- }
- return;
- }
-
- if($page["file"]!="index.php")
- {
- echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php\">";
- }
- show_header("Login",0,1,1);
- show_error_message("Login name or password is incorrect");
- insert_login_form();
- show_page_footer();
- exit;
- }
-*/
# Header for HTML pages
@@ -1515,9 +1221,9 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select value from alarms where triggerid=$triggerid and clock=".$row[0];
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- $row=DBfetch($result);
if($row["value"] == $value)
{
return 0;
@@ -1569,9 +1275,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select * from media_type where mediatypeid=$mediatypeid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -1599,7 +1306,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$sql="select * from media_type where description=".zbx_dbstr($description)." and mediatypeid!=$mediatypeid";
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("An action type with description '$description' already exists.");
}
@@ -1624,7 +1331,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$sql="select * from media_type where description=".zbx_dbstr($description);
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("An action type with description '$description' already exists.");
}
@@ -1752,7 +1459,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$sql="select * from users where userid=$userid and alias='guest'";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ if(DBfetch($result))
{
error("Cannot delete user 'guest'");
return 0;
@@ -1792,15 +1499,15 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
"July","August","September","October","November","December");
$sql="select min(clock) as minn,max(clock) as maxx from history where itemid=$itemid";
$result=DBselect($sql);
+ $row=Dvfetch($result);
- if(DBnum_rows($result) == 0)
+ if(!row)
{
$min=time(NULL);
$max=time(NULL);
}
else
{
- $row=DBfetch($result);
$min=$row["minn"];
$max=$row["maxx"];
}
@@ -2103,7 +1810,9 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$row=DBfetch(DBselect("select count(userid) as cnt from users"));
$status["users_count"]=$row["cnt"];
- $status["users_online"]=DBnum_rows(DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and (s.lastaccess+u.autologout)>".time()));
+ $status["users_online"]=0;
+ $result=DBselect("select distinct s.userid from sessions s, users u where u.userid=s.userid and (s.lastaccess+u.autologout)>".time());
+ while(DBfetch($result)) $status["users_online"]++;
return $status;
}
@@ -2164,6 +1873,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
{
$max=time();
}
+ $rows=0;
while($row=DBfetch($result))
{
$clock=$row["clock"];
@@ -2204,9 +1914,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$unknown_time+=$diff;
$state=$value;
}
+ $rows++;
}
- if(DBnum_rows($result)==0)
+ if($rows==0)
{
$false_time=$max-$min;
}
@@ -2354,11 +2065,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
if($USER_DETAILS["alias"]!="guest")
{
$db_profiles = DBselect("select * from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx));
+ $profile=DBfetch($db_profiles);
- if(DBnum_rows($db_profiles)==1)
+ if($profile)
{
- $profile = DBfetch($db_profiles);
-
if($type==PROFILE_TYPE_UNCNOWN)
$type = $profile["valuetype"];
@@ -2403,8 +2113,9 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$sql="select value from profiles where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
$result=DBselect($sql);
+ $row=DBfetch($result);
- if(DBnum_rows($result)==0)
+ if(!$row)
{
$sql="insert into profiles (userid,idx,value,valuetype)".
" values (".$USER_DETAILS["userid"].",".zbx_dbstr($idx).",".zbx_dbstr($value).",".$type.")";
@@ -2412,7 +2123,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
}
else
{
- $row=DBfetch($result);
$sql="update profiles set value=".zbx_dbstr($value).",valuetype=".$type.
" where userid=".$USER_DETAILS["userid"]." and idx=".zbx_dbstr($idx);
DBexecute($sql);
@@ -2759,10 +2469,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
$result = DBselect("select newvalue from mappings".
" where valuemapid=".zbx_dbstr($valuemapid)." and value=".zbx_dbstr($value));
- if(DBnum_rows($result))
+ $row = DBfetch($result);
+ if($row)
{
- $result = DBfetch($result);
- return $result["newvalue"].SPACE."($value)";
+ return $row["newvalue"].SPACE."($value)";
}
return $value;
}
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index bc84a16d..c6f34cd0 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -170,7 +170,7 @@
{
$result[strtolower($k)]=$row[$k];
}
- }
+ }
return $result;
}
return FALSE;
@@ -242,7 +242,13 @@
}
if($DB_TYPE == "ORACLE")
{
- $result=FALSE;
+ $sql="select max($field) from $table";
+ $parse=DBexecute($sql);
+ while(OCIFetch($parse))
+ {
+ $colvalue = OCIResult($parse, 1);
+ return $colvalue;
+ }
}
}
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index aa631b00..878b5a8a 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -30,7 +30,7 @@
global $_REQUEST;
$db_acks = get_acknowledges_by_alarmid($_REQUEST["alarmid"]);
- if(DBnum_rows($db_acks)==0)
+ if(!DBfetch($db_acks))
{
$title = S_ACKNOWLEDGE_ALARM_BY;
$btn_txt = S_ACKNOWLEDGE;
@@ -193,7 +193,7 @@
if(isset($usrgrpid) && !isset($_REQUEST["form_refresh"]))
{
$name = $usrgrp["name"];
- $db_users=DBselect("select distinct u.userid from users u,users_groups ug ".
+ $db_users=DBselect("select distinct u.userid,u.alias from users u,users_groups ug ".
"where u.userid=ug.userid and ug.usrgrpid=".$usrgrpid.
" order by alias");
@@ -797,14 +797,14 @@
$db_hosts = get_hosts_by_graphid($_REQUEST["graphid"]);
- if(DBnum_rows($db_hosts)==0)
+ $db_host = DBfetch($db_hosts);
+ if(!$db_host)
{
// empty graph, can contain any item
$host_condition = " and h.status in(".HOST_STATUS_MONITORED.",".HOST_STATUS_TEMPLATE.")";
}
else
{
- $db_host = DBfetch($db_hosts);
if($db_host["status"]==HOST_STATUS_TEMPLATE)
{// graph for template must use only one host
$host_condition = " and h.hostid=".$db_host["hostid"];
@@ -1606,9 +1606,9 @@
while($row=DBfetch($result))
{
$db_hosts = get_hosts_by_graphid($row["graphid"]);
- if(DBnum_rows($db_hosts)==1)
+ $db_host = DBfetch($db_hosts);
+ if($db_host)
{
- $db_host = DBfetch($db_hosts);
$name = $db_host["host"].":".$row["name"];
}
else
@@ -1998,11 +1998,11 @@
$db_profiles = DBselect("select * from hosts_profiles where hostid=".$_REQUEST["hostid"]);
$useprofile = "no";
- if(DBnum_rows($db_profiles)==1)
+ $db_profile = DBfetch($db_profiles);
+ if($db_profile)
{
$useprofile = "yes";
- $db_profile = DBfetch($db_profiles);
$devicetype = $db_profile["devicetype"];
$name = $db_profile["name"];
@@ -2224,9 +2224,9 @@
$result=DBselect("select * from hosts_profiles where hostid=".$_REQUEST["hostid"]);
- if(DBnum_rows($result)==1)
+ $row=DBfetch($result);
+ if($row)
{
- $row=DBfetch($result);
$devicetype=$row["devicetype"];
$name=$row["name"];
@@ -2452,11 +2452,11 @@
$cmbType = new CComboBox("elementtype",$elementtype,"submit()");
$db_hosts = DBselect("select hostid from hosts");
- if(DBnum_rows($db_hosts)>0)
+ if(DBfetch($db_hosts))
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST);
$db_maps = DBselect("select sysmapid from sysmaps where sysmapid!=".$_REQUEST["sysmapid"]);
- if(DBnum_rows($db_maps)>0)
+ if(DBfetch($db_maps))
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_MAP, S_MAP);
$cmbType->AddItem(SYSMAP_ELEMENT_TYPE_IMAGE, S_IMAGE);
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index 17e02abe..065f1b33 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -57,9 +57,10 @@
function get_graphitem_by_gitemid($gitemid)
{
$result=DBselect("select * from graphs_items where gitemid=$gitemid");
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No graph item with gitemid=[$gitemid]");
return $result;
@@ -68,9 +69,10 @@
function get_graphitem_by_itemid($itemid)
{
$result=DBselect("select * from graphs_items where itemid=$itemid");
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
return $result;
}
@@ -79,9 +81,10 @@
{
$result=DBselect("select * from graphs where graphid=$graphid");
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No graph with graphid=[$graphid]");
return $result;
@@ -209,7 +212,7 @@
if($gitemid && $host["status"]==HOST_STATUS_TEMPLATE)
{// add to child graphs
$gitems = get_graphitems_by_graphid($graphid);
- if(DBnum_rows($gitems)==1)
+ if(DBfetch($gitems))
{// create graphs for childs with item
$chd_hosts = get_hosts_by_templateid($host["hostid"]);
while($chd_host = DBfetch($chd_hosts))
@@ -226,12 +229,12 @@
$db_items = DBselect("select itemid from items".
" where key_=".zbx_dbstr($item["key_"]).
" and hostid=".$chd_host["hostid"]);
- if(DBnum_rows($db_items)==0)
+ $db_item = DBfetch($db_items);
+ if(!$db_item)
{
$result = FALSE;
break;
}
- $db_item = DBfetch($db_items);
// recursion
$result = add_item_to_graph($new_graphid,$db_item["itemid"],
$color,$drawtype,$sortorder,$yaxisside);
@@ -251,12 +254,12 @@
$db_items = DBselect("select itemid from items".
" where key_=".zbx_dbstr($item["key_"]).
" and hostid=".$chd_host["hostid"]);
- if(DBnum_rows($db_items)==0)
+ $db_item = DBfetch($db_items);
+ if(!$db_item)
{
$result = FALSE;
break;
}
- $db_item = DBfetch($db_items);
// recursion
$result = add_item_to_graph($child["graphid"],$db_item["itemid"],
$color,$drawtype,$sortorder,$yaxisside);
@@ -294,9 +297,9 @@
$db_items = DBselect("select itemid from items".
" where key_=".zbx_dbstr($item["key_"]).
" and hostid=".$chd_host["hostid"]);
- if(DBnum_rows($db_items)==0)
- return FALSE;
$db_item = DBfetch($db_items);
+ if(!$db_item)
+ return FALSE;
$chd_gitems = get_graphitems_by_graphid($child["graphid"]);
while($chd_gitem = DBfetch($chd_gitems))
@@ -351,7 +354,7 @@
info("Item '".$item["description"]."' deleted from graph '".$graph["name"]."'");
$graph_items = get_graphitems_by_graphid($graph["graphid"]);
- if($graph["templateid"]>0 && DBnum_rows($graph_items) < 1)
+ if($graph["templateid"]>0 && !DBfetch($graph_items))
{
return delete_graph($graph["graphid"]);
}
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 07e1c686..abe8d003 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -43,7 +43,7 @@
$result = DBexecute("select * from groups where name=".zbx_dbstr($name).
" and groupid<>$groupid");
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("Group '$name' already exists");
return FALSE;
@@ -151,7 +151,7 @@
$result=DBexecute("select * from hosts where host=".zbx_dbstr($host).
" and hostid<>$hostid");
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("Host '$host' already exists");
return FALSE;
@@ -318,9 +318,10 @@
function get_hostgroup_by_groupid($groupid)
{
$result=DBselect("select * from groups where groupid=".$groupid);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No host groups with groupid=[$groupid]");
return FALSE;
@@ -330,9 +331,10 @@
{
$sql="select h.* from hosts h, items i where i.hostid=h.hostid and i.itemid=$itemid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No host with itemid=[$itemid]");
return FALSE;
@@ -342,9 +344,10 @@
{
$sql="select * from hosts where hostid=$hostid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
if($no_error_message == 0)
error("No host with hostid=[$hostid]");
@@ -429,8 +432,8 @@
$groupid = $a_groupid;
if($groupid > 0)
- if(DBnum_rows(DBselect("select hg.groupid from hosts_groups hg".
- " where hg.groupid=".$groupid." group by hg.groupid")) != 1)
+ if(!DBfetch(DBselect("select hg.groupid from hosts_groups hg".
+ " where hg.groupid=".$groupid." group by hg.groupid")))
$groupid = 0;
if($groupid > 0)
@@ -478,9 +481,6 @@
if($groupid > 0)
{
-// if(DBnum_rows(DBselect("select hg.hostid from hosts_groups hg".
-// " where hg.groupid=".$groupid." and hg.hostid=".$hostid)) != 1)
-// $hostid = 0;
if(!DBfetch(DBselect("select hg.hostid from hosts_groups hg".
" where hg.groupid=".$groupid." and hg.hostid=".$hostid)))
$hostid = 0;
@@ -490,10 +490,6 @@
if($hostid > 0)
{
-// if(DBnum_rows(DBselect("select distinct h.hostid from hosts h".$item_table.
-// " where h.status<>".HOST_STATUS_DELETED.$with_host_status.$with_items.
-// " and h.hostid=".$hostid)) != 1)
-// $hostid = 0;
if(!DBfetch(DBselect("select distinct h.hostid from hosts h".$item_table.
" where h.status<>".HOST_STATUS_DELETED.$with_host_status.$with_items.
" and h.hostid=".$hostid)))
@@ -567,22 +563,18 @@
$result = DBexecute("select * from applications where name=".zbx_dbstr($name)." and hostid=".$hostid.
" and applicationid<>$applicationid");
- $match_cnt = DBnum_rows($result);
- if($match_cnt > 0)
- {
- $db_app = DBfetch($result);;
- }
- if($match_cnt > 0 && $templateid==0)
+ $db_app = DBfetch($result);
+ if($db_app && $templateid==0)
{
error("Application '$name' already exists");
return FALSE;
}
- if($match_cnt > 0 && $applicationid!=NULL)
+ if($db_app && $applicationid!=NULL)
{ // delete old item with same name
delete_application($db_app["applicationid"]);
}
- if($match_cnt > 0 && $applicationid==NULL)
+ if($db_app && $applicationid==NULL)
{ // if found application with same name update them, adding not needed
$applicationid = $db_app["applicationid"];
}
@@ -670,9 +662,10 @@
function get_application_by_applicationid($applicationid,$no_error_message=0)
{
$result = DBselect("select * from applications where applicationid=".$applicationid);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
if($no_error_message == 0)
error("No application with id=[$applicationid]");
@@ -698,9 +691,10 @@
{
$sql="select h.* from hosts h, applications a where a.hostid=h.hostid and a.applicationid=$applicationid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No host with applicationid=[$applicationid]");
return FALSE;
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index bd9a2dda..79d56bae 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -146,13 +146,13 @@
$db_items = DBexecute("select itemid,hostid from items".
" where hostid=$hostid and key_=".zbx_dbstr($key));
- if(DBnum_rows($db_items) > 0 && $templateid == 0)
+ $db_item = DBfetch($db_items);
+ if($db_item && $templateid == 0)
{
error("An item with the same Key already exists for host ".$host["host"].".".
" The key must be unique.");
return FALSE;
- } elseif (DBnum_rows($db_items) > 0 && $templateid != 0){
- $db_item = DBfetch($db_items);
+ } elseif ($db_item && $templateid != 0){
$result = update_item(
$db_item["itemid"], $description, $key, $db_item["hostid"],
@@ -276,7 +276,8 @@
$db_items = DBexecute("select itemid from items".
" where hostid=$hostid and itemid<>$itemid and key_=".zbx_dbstr($key));
- if(DBnum_rows($db_items) > 0 && $templateid == 0)
+ $db_item = DBfetch($db_items);
+ if($db_item && $templateid == 0)
{
error("An item with the same Key already exists for host ".$host["host"].".".
" The key must be unique.");
@@ -303,9 +304,8 @@
return $result;
}
- if(DBnum_rows($db_items) > 0 && $templateid != 0)
+ if($db_item && $templateid != 0)
{
- $db_item = DBfetch($db_items);
$result = delete_item($db_item["itemid"]);
if(!$result) {
error("Can't update item '".$host["host"].":$key'");
@@ -439,9 +439,10 @@
function get_item_by_itemid($itemid)
{
$result=DBselect("select * from items where itemid=$itemid");
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No item with itemid=[$itemid]");
return FALSE;
@@ -562,12 +563,12 @@
{
$db_host_items = DBselect("select itemid,value_type,lastvalue,units from items where".
" hostid=$hostid and status=".ITEM_STATUS_ACTIVE." and description=".zbx_dbstr($item["description"]));
- if(DBnum_rows($db_host_items)!=1)
+ $host_item = DBfetch($db_host_items);
+ if(!$host_item)
{
array_push($table_row,"-");
continue;
}
- $host_item = DBfetch($db_host_items);
if(!check_right("Item","R",$host_item["itemid"])) continue;
@@ -596,7 +597,7 @@
$db_item_triggers = DBselect("select t.triggerid from triggers t, items i, functions f where".
" i.hostid=$hostid and i.itemid=".$host_item["itemid"]." and i.itemid=f.itemid".
" and t.priority>1 and t.triggerid=f.triggerid and t.value=".TRIGGER_VALUE_TRUE);
- if(DBnum_rows($db_item_triggers) > 0) $style = "high";
+ if(DBfetch($db_item_triggers)) $style = "high";
else $style = NULL;
if($host_item["value_type"] == 0)
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index c2197b9d..9517927d 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -23,9 +23,10 @@
{
$sql="select * from sysmaps where sysmapid=$sysmapid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -38,9 +39,10 @@
{
$sql="select * from sysmaps_elements where selementid=$selementid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -261,16 +263,18 @@
" and i.hostid=".$db_element["elementid"]." and i.itemid=f.itemid".
" and f.triggerid=t.triggerid and t.value=1 and t.status=0".
" and h.status=".HOST_STATUS_MONITORED." and i.status=0");
- $count = DBnum_rows($db_triggers);
- if($count == 1)
+ $count=0;
+ $trigger = DBfetch($db_triggers);
+ if($trigger)
{
- $trigger = DBfetch($db_triggers);
+ for($count=1; DBfetch($db_triggers); $count++);
+
if ($trigger["priority"] > 3) $color=$colors["Red"];
else $color=$colors["Dark Yellow"];
$info = expand_trigger_description_simple($trigger["triggerid"]);
}
- elseif($count==0)
+ else
{
$host = get_host_by_hostid($db_element["elementid"]);
if($host["status"] == HOST_STATUS_TEMPLATE)
diff --git a/frontends/php/include/media.inc.php b/frontends/php/include/media.inc.php
index 7e56732c..90066f7d 100644
--- a/frontends/php/include/media.inc.php
+++ b/frontends/php/include/media.inc.php
@@ -23,9 +23,10 @@
{
$sql="select * from media where mediaid=$mediaid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php
index 6ad187ee..87ee793a 100644
--- a/frontends/php/include/profiles.inc.php
+++ b/frontends/php/include/profiles.inc.php
@@ -33,7 +33,7 @@
}
$result=DBexecute("select * from hosts_profiles where hostid=$hostid");
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("Host profile already exists");
return 0;
diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php
index aa04850c..6c1ab827 100644
--- a/frontends/php/include/screens.inc.php
+++ b/frontends/php/include/screens.inc.php
@@ -80,9 +80,10 @@
{
$sql="select * from screens where screenid=$screenid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -115,8 +116,8 @@
$effectiveperiod = 3600;
$result=DBselect("select name,cols,rows from screens where screenid=$screenid");
- if(DBnum_rows($result) == 0) return new CSpan("Screen missing".BR);
$row=DBfetch($result);
+ if(!row) return new CSpan("Screen missing".BR);
for($r=0;$r<$row["rows"];$r++)
{
@@ -126,9 +127,9 @@
$sql="select * from screens_items where screenid=$screenid and x=$c and y=$r";
$iresult=DBSelect($sql);
- if(DBnum_rows($iresult)>0)
+ $irow=DBfetch($iresult);
+ if($irow)
{
- $irow=DBfetch($iresult);
$colspan=$irow["colspan"];
$rowspan=$irow["rowspan"];
} else {
@@ -158,9 +159,9 @@
$iresult=DBSelect("select * from screens_items".
" where screenid=$screenid and x=$c and y=$r");
- if(DBnum_rows($iresult)>0)
+ $irow = DBfetch($iresult);
+ if($irow)
{
- $irow = DBfetch($iresult);
$screenitemid = $irow["screenitemid"];
$resource = $irow["resource"];
$resourceid = $irow["resourceid"];
diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php
index 5a830e16..84362b3a 100644
--- a/frontends/php/include/services.inc.php
+++ b/frontends/php/include/services.inc.php
@@ -233,7 +233,7 @@
}
// echo $problem_time,"-",$ok_time,"<br>";
- if(DBnum_rows($result)==0)
+ if(!DBfetch($result))
{
if(get_last_service_value($serviceid,$period_start)<=1)
{
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index fc0c6539..20449515 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -43,9 +43,10 @@
{
$sql="select * from triggers where triggerid=$triggerid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No trigger with triggerid=[$triggerid]");
return FALSE;
@@ -74,7 +75,7 @@
while($db_trigger = DBfetch($db_triggers))
{
$db_hosts = get_hosts_by_triggerid($db_trigger["triggerid"]);
- if(DBnum_rows($db_hosts) == 1)
+ if(DBfetch($db_hosts))
{
array_push($triggers,$db_trigger["triggerid"]);
}
@@ -245,22 +246,30 @@
}
- $hosts_num = DBnum_rows($exp_hosts);
- if($hosts_num == 0)
+ $exp_host = DBfetch($exp_hosts);
+ if(!$exp_host)
{
error("Incorrect trigger expression. Incorrect host is used.");
return 1;
}
- else if(DBnum_rows($exp_hosts) <> 1)
+ else
{
- while($exp_host = DBfetch($exp_hosts))
+ $rows=0;
+ unset($fail);
+ do
{
if($exp_host["status"]==HOST_STATUS_TEMPLATE)
{
- error("Incorrect trigger expression. You can't use template hosts".
- " in mixed expressions.");
- return 1;
+ $fail=1;
}
+ $rows++;
+ } while($exp_host = DBfetch($exp_hosts));
+
+ if(isset($fail) && ($rows>1))
+ {
+ error("Incorrect trigger expression. You can't use template hosts".
+ " in mixed expressions.");
+ return 1;
}
}
@@ -308,22 +317,20 @@
$result = add_trigger_dependency($triggerid, $val);
}
+ $trig_hosts = get_hosts_by_triggerid($triggerid);
+ $trig_host = DBfetch($trig_hosts);
if($result)
{
- $trig_hosts = get_hosts_by_triggerid($triggerid);
$msg = "Added trigger '".$description."'";
- if(DBnum_rows($trig_hosts) == 1)
+ if($trig_host)
{
- $trig_host = DBfetch($trig_hosts);
$msg .= " to host '".$trig_host["host"]."'";
}
info($msg);
}
- $trig_hosts = get_hosts_by_triggerid($triggerid);
- if(DBnum_rows($trig_hosts) == 1)
+ if($trig_host)
{
- $trig_host = DBfetch($trig_hosts);
$child_hosts = get_hosts_by_templateid($trig_host["hostid"]);
while($child_host = DBfetch($child_hosts))
{
@@ -392,12 +399,12 @@
$host_items = DBselect("select * from items".
" where key_=".zbx_dbstr($item["key_"]).
" and hostid=".$host["hostid"]);
- if(DBnum_rows($host_items)!=1)
+ $host_item = DBfetch($host_items);
+ if(!$host_item)
{
error("Missing key '".$item["key_"]."' for host '".$host["host"]."'");
return FALSE;
}
- $host_item = DBfetch($host_items);
$result = DBexecute("insert into functions (itemid,triggerid,function,parameter)".
" values (".$host_item["itemid"].",$newtriggerid,".
@@ -639,9 +646,9 @@
" and f.itemid=i.itemid and i.hostid=h.hostid");
- if(DBnum_rows($result)>0)
+ $row = DBfetch($result);
+ if($row)
{
- $row = DBfetch($result);
$description = str_replace("{HOSTNAME}", $row["host"],$row["description"]);
}
else
@@ -738,9 +745,9 @@
if($result)
{
$msg = "Trigger '".$trigger["description"]."' deleted";
- if(DBnum_rows($trig_hosts) == 1)
+ $trig_host = DBfetch($trig_hosts);
+ if($trig_host)
{
- $trig_host = DBfetch($trig_hosts);
$msg .= " from host '".$trig_host["host"]."'";
}
info($msg);
@@ -776,7 +783,7 @@
$exp_hosts = get_hosts_by_expression($expression);
$chd_hosts = get_hosts_by_templateid($trig_host["hostid"]);
- if(DBnum_rows($chd_hosts) > 0)
+ if(DBfetch($chd_hosts))
{
$exp_host = DBfetch($exp_hosts);
$db_chd_triggers = get_triggers_by_templateid($triggerid);
@@ -835,9 +842,9 @@
{
$trig_hosts = get_hosts_by_triggerid($triggerid);
$msg = "Trigger '".$trigger["description"]."' updated";
- if(DBnum_rows($trig_hosts) == 1)
+ $trig_host = DBfetch($trig_hosts);
+ if($trig_host)
{
- $trig_host = DBfetch($trig_hosts);
$msg .= " from host '".$trig_host["host"]."'";
}
info($msg);
@@ -953,11 +960,6 @@
$trig2 = get_trigger_by_triggerid($triggerid2);
$trig_fnc1 = get_functions_by_triggerid($triggerid1);
- $trig_fnc2 = get_functions_by_triggerid($triggerid2);
- if(DBnum_rows($trig_fnc1) != DBnum_rows($trig_fnc2))
- {
- return 1;
- }
$expr1 = $trig1["expression"];
while($fnc1 = DBfetch($trig_fnc1))
@@ -1043,9 +1045,9 @@
$db_host_triggers = DBselect("select distinct t.value,t.lastchange from triggers t,functions f,items i".
" where f.triggerid=t.triggerid and i.itemid=f.itemid and t.status=".TRIGGER_STATUS_ENABLED.
" and i.hostid=$hostid and t.description=".zbx_dbstr($triggers["description"]));
- if(DBnum_rows($db_host_triggers)==1)
+ $host_trigger = DBfetch($db_host_triggers);
+ if($host_trigger)
{
- $host_trigger = DBfetch($db_host_triggers);
if($host_trigger["value"] == TRIGGER_VALUE_FALSE) $style = "normal";
elseif($host_trigger["value"] == TRIGGER_VALUE_UNKNOWN) $style = "unknown_trigger";
diff --git a/frontends/php/include/users.inc.php b/frontends/php/include/users.inc.php
index 87a762ac..26ea84d1 100644
--- a/frontends/php/include/users.inc.php
+++ b/frontends/php/include/users.inc.php
@@ -36,7 +36,7 @@
$sql="select * from users where alias=".zbx_dbstr($alias);
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("User '$alias' already exists");
return 0;
@@ -64,7 +64,7 @@
$sql="select * from users where alias=".zbx_dbstr($alias)." and userid<>$userid";
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("User '$alias' already exists");
return 0;
@@ -117,9 +117,10 @@
function get_usergroup_by_groupid($groupid)
{
$result=DBselect("select * from usrgrp where usrgrpid=".$groupid);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
error("No user groups with usrgrpid=[$groupid]");
return FALSE;
@@ -129,9 +130,10 @@
{
$sql="select * from users where userid=$userid";
$result=DBselect($sql);
- if(DBnum_rows($result) == 1)
+ $row=DBfetch($result);
+ if($row)
{
- return DBfetch($result);
+ return $row;
}
else
{
@@ -155,7 +157,7 @@
$sql="select * from usrgrp where name=".zbx_dbstr($name);
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("Group '$name' already exists");
return 0;
@@ -190,7 +192,7 @@
$sql="select * from usrgrp where name=".zbx_dbstr($name)." and usrgrpid<>$usrgrpid";
$result=DBexecute($sql);
- if(DBnum_rows($result)>0)
+ if(DBfetch($result))
{
error("Group '$name' already exists");
return 0;