summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--frontends/php/include/actions.inc.php5
-rw-r--r--frontends/php/include/config.inc.php214
-rw-r--r--frontends/php/include/db.inc.php4
-rw-r--r--frontends/php/include/forms.inc.php96
-rw-r--r--frontends/php/include/hosts.inc.php14
-rw-r--r--frontends/php/include/items.inc.php5
-rw-r--r--frontends/php/include/maps.inc.php25
-rw-r--r--frontends/php/include/services.inc.php37
-rw-r--r--frontends/php/include/triggers.inc.php35
9 files changed, 207 insertions, 228 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index 6d3ea372..551cf25c 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -94,10 +94,9 @@
{
$sql="select actionid from actions where userid=$userid";
$result=DBexecute($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $actionid=DBget_field($result,$i,0);
- delete_alert_by_actionid($actionid);
+ delete_alert_by_actionid($row["actionid"]);
}
$sql="delete from actions where userid=$userid";
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index cf3fa45d..9c9e5496 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -597,17 +597,15 @@
$priorities=0;
for($i=0;$i<=5;$i++)
{
- $result=DBselect("select count(*) from triggers t,hosts h,items i,functions f where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0 and t.priority=$i");
-// $priorities+=(1000^$i)*DBget_field($result,0,0);
- $priorities+=pow(100,$i)*DBget_field($result,0,0);
-// echo "$i $priorities ",DBget_field($result,0,0),"<br>";
-// echo pow(100,5)*13;
+ $result=DBselect("select count(*) as cnt from triggers t,hosts h,items i,functions f where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0 and t.priority=$i");
+ $row=DBfetch($result);
+ $priorities+=pow(100,$i)*$row["cnt"];
}
$triggerids="";
$result=DBselect("select t.triggerid from triggers t,hosts h,items i,functions f where t.value=1 and f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.status=0");
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $triggerids="$triggerids,".DBget_field($result,$i,0);
+ $triggerids="$triggerids,".$row["triggerid"];
}
$md5sum=md5($triggerids);
@@ -674,19 +672,12 @@
function select_config()
{
-// $sql="select smtp_server,smtp_helo,smtp_email,alarm_history,alert_history from config";
- $sql="select alarm_history,alert_history from config";
+ $sql="select * from config";
$result=DBselect($sql);
if(DBnum_rows($result) == 1)
{
- $config["alarm_history"]=DBget_field($result,0,0);
- $config["alert_history"]=DBget_field($result,0,1);
-// $config["smtp_server"]=DBget_field($result,0,0);
-// $config["smtp_helo"]=DBget_field($result,0,1);
-// $config["smtp_email"]=DBget_field($result,0,2);
-// $config["alarm_history"]=DBget_field($result,0,3);
-// $config["alert_history"]=DBget_field($result,0,4);
+ return DBfetch($result);
}
else
{
@@ -778,9 +769,10 @@
// echo $function,"<br>";
// echo $parameter,"<br>";
- $sql="select count(*) from hosts h,items i where h.host='$host' and i.key_='$key' and h.hostid=i.hostid";
+ $sql="select count(*) as cnt from hosts h,items i where h.host='$host' and i.key_='$key' and h.hostid=i.hostid";
$result=DBselect($sql);
- if(DBget_field($result,0,0)!=1)
+ $row=DBfetch($result);
+ if($row["cnt"]!=1)
{
error("No such host ($host) or monitored parameter ($key)");
return -1;
@@ -955,12 +947,7 @@
setcookie("sessionid",$sessionid);
$sql="update sessions set lastaccess=".time()." where sessionid='$sessionid'";
DBexecute($sql);
- $USER_DETAILS["userid"]=DBget_field($result,0,0);
- $USER_DETAILS["alias"]=DBget_field($result,0,1);
- $USER_DETAILS["name"]=DBget_field($result,0,2);
- $USER_DETAILS["surname"]=DBget_field($result,0,3);
- $USER_DETAILS["lang"]=DBget_field($result,0,4);
- $USER_DETAILS["refresh"]=DBget_field($result,0,5);
+ $USER_DETAILS=DBfetch($result);
return;
}
else
@@ -974,12 +961,7 @@
$result=DBselect($sql);
if(DBnum_rows($result)==1)
{
- $USER_DETAILS["userid"]=DBget_field($result,0,0);
- $USER_DETAILS["alias"]=DBget_field($result,0,1);
- $USER_DETAILS["name"]=DBget_field($result,0,2);
- $USER_DETAILS["surname"]=DBget_field($result,0,3);
- $USER_DETAILS["lang"]=DBget_field($result,0,4);
- $USER_DETAILS["refresh"]=DBget_field($result,0,5);
+ $USER_DETAILS=DBfetch($result);
return;
}
@@ -1282,10 +1264,10 @@ echo "</head>";
$result=DBselect($sql);
echo "<PRE>\n";
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $clock=DBget_field($result,$i,0);
- $value=DBget_field($result,$i,1);
+ $clock=$row["clock"];
+ $value=$row["value"];
echo date("Y-m-d H:i:s",$clock);
echo "\t$clock\t$value\n";
}
@@ -1314,20 +1296,21 @@ echo "</head>";
$state='';
$sql="select h.host,i.key_,f.function,f.parameter,i.itemid from items i,functions f,hosts h where functionid=$functionid and i.itemid=f.itemid and h.hostid=i.hostid";
$res1=DBselect($sql);
+ $row1=DBfetch($res1);
if($html == 0)
{
- $exp=$exp."{".DBget_field($res1,0,0).":".DBget_field($res1,0,1).".".DBget_field($res1,0,2)."(".DBget_field($res1,0,3).")}";
+ $exp=$exp."{".$row1["host"].":".$row1["key_"].".".$row1["function"]."(".$row1["parameter"].")}";
}
else
{
- $item=get_item_by_itemid(DBget_field($res1,0,4));
+ $item=get_item_by_itemid($row1["itemid"]);
if($item["value_type"] ==0)
{
- $exp=$exp."{<A HREF=\"history.php?action=showhistory&itemid=".DBget_field($res1,0,4)."\">".DBget_field($res1,0,0).":".DBget_field($res1,0,1)."</A>.<B>".DBget_field($res1,0,2)."(</B>".DBget_field($res1,0,3)."<B>)</B>}";
+ $exp=$exp."{<A HREF=\"history.php?action=showhistory&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
}
else
{
- $exp=$exp."{<A HREF=\"history.php?action=showvalues&period=3600&itemid=".DBget_field($res1,0,4)."\">".DBget_field($res1,0,0).":".DBget_field($res1,0,1)."</A>.<B>".DBget_field($res1,0,2)."(</B>".DBget_field($res1,0,3)."<B>)</B>}";
+ $exp=$exp."{<A HREF=\"history.php?action=showvalues&period=3600&itemid=".$row1["itemid"]."\">".$row1["host"].":".$row1["key_"]."</A>.<B>".$row1["function"]."(</B>".$row1["parameter"]."<B>)</B>}";
}
}
continue;
@@ -1375,31 +1358,20 @@ echo "</head>";
$sql="select i.itemid from items i,hosts h where i.key_='$key' and h.host='$host' and h.hostid=i.hostid";
# echo $sql,"<Br>";
$res=DBselect($sql);
+ $row=DBfetch($res);
- $itemid=DBget_field($res,0,0);
+ $itemid=row["itemid"];
# echo "ITEMID:$itemid<BR>";
-# $sql="select functionid,count(functionid) from functions where function='$function' and parameter=$parameter group by 1";
+ $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'$function','$parameter')";
# echo $sql,"<Br>";
-# $res=DBselect($sql);
-#
-# if(DBget_field($res,0,1)>0)
-# {
-# $functionid=DBget_field($res,0,0);
-# }
-# else
-# {
- $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'$function','$parameter')";
-# echo $sql,"<Br>";
- $res=DBexecute($sql);
- if(!$res)
- {
-# echo "ERROR<br>";
- return $res;
- }
- $functionid=DBinsert_id($res,"functions","functionid");
-# }
-# echo "FUNCTIONID:$functionid<BR>";
+ $res=DBexecute($sql);
+ if(!$res)
+ {
+# echo "ERROR<br>";
+ return $res;
+ }
+ $functionid=DBinsert_id($res,"functions","functionid");
$exp=$exp.'{'.$functionid.'}';
@@ -1585,10 +1557,9 @@ echo "</head>";
{
$sql="select itemid from functions where triggerid=$triggerid";
$result=DBselect($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $itemid=DBget_field($result,$i,0);
- $sql="update items set nextcheck=0 where itemid=$itemid";
+ $sql="update items set nextcheck=0 where itemid=".$row["itemid"];
DBexecute($sql);
}
}
@@ -2236,7 +2207,7 @@ echo "</head>";
{
$descr=array("January","February","March","April","May","June",
"July","August","September","October","November","December");
- $sql="select min(clock),max(clock) from history where itemid=$itemid";
+ $sql="select min(clock) as minn,max(clock) as maxx from history where itemid=$itemid";
$result=DBselect($sql);
if(DBnum_rows($result) == 0)
@@ -2246,8 +2217,9 @@ echo "</head>";
}
else
{
- $min=DBget_field($result,0,0);
- $max=DBget_field($result,0,1);
+ $row=DBfetch($result);
+ $min=$row["minn"];
+ $max=$row["maxx"];
}
$now=time()-3600*$from-$period;
@@ -2523,68 +2495,87 @@ echo "</head>";
if ($DB_TYPE == "MYSQL")
{
$result=DBselect("show table status like 'history'");
- $stat["history_count"]=DBget_field($result,0,3);
+ $row=DBfetch($result);
+ $stat["history_count"]=$row["Rows"];
$result=DBselect("show table status like 'trends'");
- $stat["trends_count"]=DBget_field($result,0,3);
+ $row=DBfetch($result);
+ $stat["trends_count"]=$row["Rows"];
}
else
{
- $result=DBselect("select count(itemid) from history");
- $stat["history_count"]=DBget_field($result,0,3);
+ $result=DBselect("select count(itemid) as cnt from history");
+ $row=DBfetch($result);
+ $stat["history_count"]=$row["cnt"];
- $result=DBselect("select count(itemid) from trends");
- $stat["trends_count"]=DBget_field($result,0,3);
+ $result=DBselect("select count(itemid) as cnt from trends");
+ $row=DBfetch($result);
+ $stat["trends_count"]=$row["cnt"];
}
- $result=DBselect("select count(alarmid) from alarms");
- $stat["alarms_count"]=DBget_field($result,0,0);
-
- $result=DBselect("select count(alertid) from alerts");
- $stat["alerts_count"]=DBget_field($result,0,0);
+ $result=DBselect("select count(alarmid) as cnt from alarms");
+ $row=DBfetch($result);
+ $stat["alarms_count"]=$row["cnt"];
- $result=DBselect("select count(triggerid) from triggers");
- $stat["triggers_count"]=DBget_field($result,0,0);
+ $result=DBselect("select count(alertid) as cnt from alerts");
+ $row=DBfetch($result);
+ $stat["alerts_count"]=$row["cnt"];
- $result=DBselect("select count(triggerid) from triggers where status=0");
- $stat["triggers_count_enabled"]=DBget_field($result,0,0);
+ $result=DBselect("select count(triggerid) as cnt from triggers");
+ $row=DBfetch($result);
+ $stat["triggers_count"]=$row["cnt"];
- $result=DBselect("select count(triggerid) from triggers where status=1");
- $stat["triggers_count_disabled"]=DBget_field($result,0,0);
+ $result=DBselect("select count(triggerid) as cnt from triggers where status=0");
+ $row=DBfetch($result);
+ $stat["triggers_count_enabled"]=$row["cnt"];
- $result=DBselect("select count(itemid) from items");
- $stat["items_count"]=DBget_field($result,0,0);
+ $result=DBselect("select count(triggerid) as cnt from triggers where status=1");
+ $row=DBfetch($result);
+ $stat["triggers_count_disabled"]=$row["cnt"];
- $result=DBselect("select count(itemid) from items where status=0");
- $stat["items_count_active"]=DBget_field($result,0,0);
+ $result=DBselect("select count(itemid) as cnt from items");
+ $row=DBfetch($result);
+ $stat["items_count"]=$row["cnt"];
- $result=DBselect("select count(itemid) from items where status=1");
- $stat["items_count_not_active"]=DBget_field($result,0,0);
+ $result=DBselect("select count(itemid) as cnt from items where status=0");
+ $row=DBfetch($result);
+ $stat["items_count_active"]=$row["cnt"];
- $result=DBselect("select count(itemid) from items where status=3");
- $stat["items_count_not_supported"]=DBget_field($result,0,0);
+ $result=DBselect("select count(itemid) as cnt from items where status=1");
+ $row=DBfetch($result);
+ $stat["items_count_not_active"]=$row["cnt"];
- $result=DBselect("select count(itemid) from items where type=2");
- $stat["items_count_trapper"]=DBget_field($result,0,0);
+ $result=DBselect("select count(itemid) as cnt from items where status=3");
+ $row=DBfetch($result);
+ $stat["items_count_not_supported"]=$row["cnt"];
- $result=DBselect("select count(hostid) from hosts");
- $stat["hosts_count"]=DBget_field($result,0,0);
+ $result=DBselect("select count(itemid) as cnt from items where type=2");
+ $row=DBfetch($result);
+ $stat["items_count_trapper"]=$row["cnt"];
- $result=DBselect("select count(hostid) from hosts where status=".HOST_STATUS_MONITORED);
- $stat["hosts_count_monitored"]=DBget_field($result,0,0);
+ $result=DBselect("select count(hostid) as cnt from hosts");
+ $row=DBfetch($result);
+ $stat["hosts_count"]=$row["cnt"];
- $result=DBselect("select count(hostid) from hosts where status!=".HOST_STATUS_MONITORED);
- $stat["hosts_count_not_monitored"]=DBget_field($result,0,0);
+ $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_MONITORED);
+ $row=DBfetch($result);
+ $stat["hosts_count_monitored"]=$row["cnt"];
- $result=DBselect("select count(hostid) from hosts where status=".HOST_STATUS_TEMPLATE);
- $stat["hosts_count_template"]=DBget_field($result,0,0);
+ $result=DBselect("select count(hostid) as cnt from hosts where status!=".HOST_STATUS_MONITORED);
+ $row=DBfetch($result);
+ $stat["hosts_count_not_monitored"]=$row["cnt"];
- $result=DBselect("select count(hostid) from hosts where status=".HOST_STATUS_DELETED);
- $stat["hosts_count_deleted"]=DBget_field($result,0,0);
+ $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_TEMPLATE);
+ $row=DBfetch($result);
+ $stat["hosts_count_template"]=$row["cnt"];
- $result=DBselect("select count(userid) from users");
- $stat["users_count"]=DBget_field($result,0,0);
+ $result=DBselect("select count(hostid) as cnt from hosts where status=".HOST_STATUS_DELETED);
+ $row=DBfetch($result);
+ $stat["hosts_count_deleted"]=$row["cnt"];
+ $result=DBselect("select count(userid) as cnt from users");
+ $row=DBfetch($result);
+ $stat["users_count"]=$row["cnt"];
return $stat;
}
@@ -2594,20 +2585,21 @@ echo "</head>";
{
if(($period_start==0)&&($period_end==0))
{
- $sql="select count(*),min(clock),max(clock) from alarms where triggerid=$triggerid";
+ $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid";
}
else
{
- $sql="select count(*),min(clock),max(clock) from alarms where triggerid=$triggerid and clock>=$period_start and clock<=$period_end";
+ $sql="select count(*) as cnt,min(clock) as minn,max(clock) as maxx from alarms where triggerid=$triggerid and clock>=$period_start and clock<=$period_end";
}
// echo $sql,"<br>";
$result=DBselect($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
- $min=DBget_field($result,0,1);
- $max=DBget_field($result,0,2);
+ $min=$row["minn"];
+ $max=$row["maxx"];
}
else
{
@@ -2644,10 +2636,10 @@ echo "</head>";
{
$max=time();
}
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $clock=DBget_field($result,$i,0);
- $value=DBget_field($result,$i,1);
+ $clock=$row["clock"];
+ $value=$row["value"];
$diff=$clock-$time;
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index dc235ee5..d31278a9 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -115,7 +115,7 @@
}
}
- function DBget_field($result,$rownum,$fieldnum)
+ function get_field($result,$rownum,$fieldnum)
{
global $DB_TYPE;
@@ -166,7 +166,7 @@
// echo "OID:$oid<br>";
$sql="select $field from $table where oid=$oid";
$result=DBselect($sql);
- return DBget_field($result,0,0);
+ return get_field($result,0,0);
}
}
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index f13e14c2..0e1b6aff 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -139,17 +139,17 @@
{
if(isset($userid))
{
+ $user=get_user_by_userid($userid);
$result=DBselect("select u.alias,u.name,u.surname,u.passwd,u.url,u.autologout,u.lang,u.refresh from users u where u.userid=$userid");
- $alias=DBget_field($result,0,0);
- $name=DBget_field($result,0,1);
- $surname=DBget_field($result,0,2);
-# $password=DBget_field($result,0,3);
+ $alias=$user["alias"];
+ $name=$user["name"];
+ $surname=$user["surname"];
$password="";
- $url=DBget_field($result,0,4);
- $autologout=DBget_field($result,0,5);
- $lang=DBget_field($result,0,6);
- $refresh=DBget_field($result,0,7);
+ $url=$user["url"];
+ $autologout=$user["autologout"];
+ $lang=$user["lang"];
+ $refresh=$user["refresh"];
}
else
{
@@ -293,33 +293,34 @@
if(isset($_REQUEST["register"])&&($_REQUEST["register"] == "change"))
{
$result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status, i.type, i.snmp_community,i.snmp_oid,i.value_type,i.trapper_hosts,i.snmp_port,i.units,i.multiplier,h.hostid,i.delta,i.trends,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,i.logtimefmt from items i,hosts h where i.itemid=".$_REQUEST["itemid"]." and h.hostid=i.hostid");
+ $row=DBfetch($result);
- $description=DBget_field($result,0,0);
- $key=DBget_field($result,0,1);
- $host=DBget_field($result,0,2);
- $port=DBget_field($result,0,3);
- $delay=DBget_field($result,0,4);
- $history=DBget_field($result,0,5);
- $status=DBget_field($result,0,6);
- $type=iif(isset($_REQUEST["type"]),isset($_REQUEST["type"]),DBget_field($result,0,7));
- $snmp_community=DBget_field($result,0,8);
- $snmp_oid=DBget_field($result,0,9);
- $value_type=DBget_field($result,0,10);
- $trapper_hosts=DBget_field($result,0,11);
- $snmp_port=DBget_field($result,0,12);
- $units=DBget_field($result,0,13);
- $multiplier=DBget_field($result,0,14);
- $hostid=DBget_field($result,0,15);
- $delta=DBget_field($result,0,16);
- $trends=DBget_field($result,0,17);
-
- $snmpv3_securityname=DBget_field($result,0,18);
- $snmpv3_securitylevel=DBget_field($result,0,19);
- $snmpv3_authpassphrase=DBget_field($result,0,20);
- $snmpv3_privpassphrase=DBget_field($result,0,21);
-
- $formula=DBget_field($result,0,22);
- $logtimefmt=DBget_field($result,0,23);
+ $description=$row["description"];
+ $key=$row["key_"];
+ $host=$row["host"];
+ $port=$row["port"];
+ $delay=$row["delay"];
+ $history=$row["history"];
+ $status=$row["status"];
+ $type=iif(isset($_REQUEST["type"]),isset($_REQUEST["type"]),$row["type"]);
+ $snmp_community=$row["snmp_community"];
+ $snmp_oid=$row["snmp_oid"];
+ $value_type=$row["value_type"];
+ $trapper_hosts=$row["trapper_hosts"];
+ $snmp_port=$row["snmp_port"];
+ $units=$row["units"];
+ $multiplier=$row["multiplier"];
+ $hostid=$row["hostid"];
+ $delta=$row["delta"];
+ $trends=$row["trends"];
+
+ $snmpv3_securityname=$row["snmpv3_securityname"];
+ $snmpv3_securitylevel=$row["snmpv3_securitylevel"];
+ $snmpv3_authpassphrase=$row["snmpv3_authpassphrase"];
+ $snmpv3_privpassphrase=$row["snmpv3_privpassphrase"];
+
+ $formula=$row["formula"];
+ $logtimefmt=$row["logtimefmt"];
}
show_form_begin("items.item");
@@ -341,10 +342,10 @@
show_table2_h_delimiter();
echo "<select class=\"biginput\" name=\"hostid\" value=\"3\">";
$result=DBselect("select hostid,host from hosts where status not in (".HOST_STATUS_DELETED.")order by host");
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $hostid_=DBget_field($result,$i,0);
- $host_=DBget_field($result,$i,1);
+ $hostid_=$row["hostid"];
+ $host_=$row["host"];
if($hostid==$hostid_)
{
echo "<option value=\"$hostid_\" selected>$host_";
@@ -1048,14 +1049,10 @@
$sql="select t.triggerid,t.description from triggers t,trigger_depends d where t.triggerid=d.triggerid_up and d.triggerid_down=$triggerid";
$result1=DBselect($sql);
echo "<SELECT class=\"biginput\" NAME=\"dependency\" size=\"1\">";
- for($i=0;$i<DBnum_rows($result1);$i++)
+ while($row1=DBfetch($result1))
{
- $depid=DBget_field($result1,$i,0);
-// $depdescr=DBget_field($result1,$i,1);
-// if( strstr($depdescr,"%s"))
-// {
- $depdescr=expand_trigger_description($depid);
-// }
+ $depid=$row1["triggerid"];
+ $depdescr=expand_trigger_description($depid);
echo "<OPTION VALUE=\"$depid\">$depdescr";
}
echo "</SELECT>";
@@ -1066,15 +1063,10 @@
$sql="select t.triggerid,t.description from triggers t where t.triggerid!=$triggerid order by t.description";
$result=DBselect($sql);
echo "<SELECT class=\"biginput\" NAME=\"depid\" size=\"1\">";
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row1=DBfetch($result1))
{
- $depid=DBget_field($result,$i,0);
-// $depdescr=DBget_field($result,$i,1);
-
-// if( strstr($depdescr,"%s"))
-// {
- $depdescr=expand_trigger_description($depid);
-// }
+ $depid=$row1["triggerid"];
+ $depdescr=expand_trigger_description($depid);
echo "<OPTION VALUE=\"$depid\">$depdescr";
}
echo "</SELECT>";
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 87f67db6..b215715f 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -190,16 +190,11 @@
function get_host_by_hostid($hostid)
{
- $sql="select hostid,host,useip,ip,port,status from hosts where hostid=$hostid";
+ $sql="select * from hosts where hostid=$hostid";
$result=DBselect($sql);
if(DBnum_rows($result) == 1)
{
- $host["hostid"]=DBget_field($result,0,0);
- $host["host"]=DBget_field($result,0,1);
- $host["useip"]=DBget_field($result,0,2);
- $host["ip"]=DBget_field($result,0,3);
- $host["port"]=DBget_field($result,0,4);
- $host["status"]=DBget_field($result,0,5);
+ return DBfetch($result);
}
else
{
@@ -220,12 +215,13 @@
$sql="select status,host from hosts where hostid=$hostid";
$result=DBselect($sql);
- $old_status=DBget_field($result,0,0);
+ $row=DBfetch($result);
+ $old_status=$row["status"];
if($status != $old_status)
{
update_trigger_value_to_unknown_by_hostid($hostid);
$sql="update hosts set status=$status where hostid=$hostid and status!=".HOST_STATUS_DELETED;
- info("Updated status of host ".DBget_field($result,0,1));
+ info("Updated status of host ".$row["host"]);
return DBexecute($sql);
}
else
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index e3979e2c..1db16857 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -81,9 +81,10 @@
$host=get_host_by_hostid($hostid);
- $sql="select count(*) from items where hostid=$hostid and key_='$key'";
+ $sql="select count(*) as cnt from items where hostid=$hostid and key_='$key'";
$result=DBexecute($sql);
- if(DBget_field($result,0,0)>0)
+ $row = DBfetch($result);
+ if($row["cnt"]>0)
{
error("An item with the same Key already exists for host ".$host["host"].". The key must be unique.");
return 0;
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index 9845240f..90a08797 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -161,18 +161,18 @@
{
$map="\n<map name=links$sysmapid>";
$result=DBselect("select h.host,sh.shostid,sh.sysmapid,sh.hostid,sh.label,sh.x,sh.y,h.status,sh.icon,sh.url from sysmaps_hosts sh,hosts h where sh.sysmapid=$sysmapid and h.hostid=sh.hostid");
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $host=DBget_field($result,$i,0);
- $shostid=DBget_field($result,$i,1);
- $sysmapid=DBget_field($result,$i,2);
- $hostid=DBget_field($result,$i,3);
- $label=DBget_field($result,$i,4);
- $x=DBget_field($result,$i,5);
- $y=DBget_field($result,$i,6);
- $status=DBget_field($result,$i,7);
- $icon=DBget_field($result,$i,8);
- $url=DBget_field($result,$i,9);
+ $host=$row["host"];
+ $shostid=$row["shostid"];
+ $sysmapid=$row["sysmapid"];
+ $hostid=$row["hostid"];
+ $label=$row["label"];
+ $x=$row["x"];
+ $y=$row["y"];
+ $status=$row["status"];
+ $icon=$row["icon"];
+ $url=$row["url"];
if($status==HOST_STATUS_MONITORED)
{
@@ -180,7 +180,8 @@
$result2=DBselect($sql);
if(DBnum_rows($result2)==1)
{
- $back=ImageCreateFromString(DBget_field($result2,0,0));
+ $row2=DBfetch($result2);
+ $back=ImageCreateFromString($row2["image"]);
$sizex = imagesx($back);
$sizey = imagesy($back);
if($url=="")
diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php
index bbaabf5d..2d791c69 100644
--- a/frontends/php/include/services.inc.php
+++ b/frontends/php/include/services.inc.php
@@ -76,9 +76,10 @@
function is_service_hardlinked($serviceid)
{
- $sql="select count(*) from services_links where servicedownid=$serviceid and soft=0";
+ $sql="select count(*) as cnt from services_links where servicedownid=$serviceid and soft=0";
$result=DBselect($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
return TRUE;
}
@@ -138,9 +139,10 @@
function service_has_parent($serviceid)
{
- $sql="select count(*) from services_links where servicedownid=$serviceid";
+ $sql="select count(*) as cnt from services_links where servicedownid=$serviceid";
$result=DBselect($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
return TRUE;
}
@@ -149,9 +151,10 @@
function service_has_no_this_parent($parentid,$serviceid)
{
- $sql="select count(*) from services_links where serviceupid=$parentid and servicedownid=$serviceid";
+ $sql="select count(*) as cnt from services_links where serviceupid=$parentid and servicedownid=$serviceid";
$result=DBselect($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
return FALSE;
}
@@ -200,19 +203,20 @@
function get_last_service_value($serviceid,$clock)
{
- $sql="select count(*),max(clock) from service_alarms where serviceid=$serviceid and clock<=$clock";
+ $sql="select count(*) as cnt,max(clock) as maxx from service_alarms where serviceid=$serviceid and clock<=$clock";
// echo " $sql<br>";
$result=DBselect($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
- $sql="select value from service_alarms where serviceid=$serviceid and clock=".DBget_field($result,0,1);
+ $sql="select value from service_alarms where serviceid=$serviceid and clock=".$row["maxx"];
$result2=DBselect($sql);
// Assuring that we get very latest service value. There could be several with the same timestamp
// $value=DBget_field($result2,0,0);
- for($i=0;$i<DBnum_rows($result2);$i++)
+ while($row2=DBfetch($result2))
{
- $value=DBget_field($result2,$i,0);
+ $value=$row2["value"];
}
}
else
@@ -234,10 +238,10 @@
$problem_time=0;
$ok_time=0;
$time=$period_start;
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $clock=DBget_field($result,$i,0);
- $value=DBget_field($result,$i,1);
+ $clock=$row["clock"];
+ $value=$row["value"];
$diff=$clock-$time;
@@ -328,9 +332,10 @@
function get_num_of_service_childs($serviceid)
{
- $sql="select count(*) from services_links where serviceupid=$serviceid";
+ $sql="select count(*) as cnt from services_links where serviceupid=$serviceid";
$result=DBselect($sql);
- return DBget_field($result,0,0);
+ $row=DBfetch($result);
+ return $row["cnt"];
}
function get_service_by_serviceid($serviceid)
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 552a1d67..19ebead0 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -131,9 +131,10 @@
function delete_trigger($triggerid)
{
- $sql="select count(*) from trigger_depends where triggerid_down=$triggerid or triggerid_up=$triggerid";
+ $sql="select count(*) as cnt from trigger_depends where triggerid_down=$triggerid or triggerid_up=$triggerid";
$result=DBexecute($sql);
- if(DBget_field($result,0,0)>0)
+ $row=DBfetch($result);
+ if($row["cnt"]>0)
{
error("Delete dependencies first");
return FALSE;
@@ -224,20 +225,12 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
function delete_trigger_dependency($triggerid_down,$triggerid_up)
{
-// Why this was here?
-// $sql="select count(*) from trigger_depends where triggerid_down=$triggerid_up and triggerid_up=$triggerid_down";
-// $result=DBexecute($sql);
-// if(DBget_field($result,0,0)>0)
-// {
-// return FALSE;
-// }
-
$sql="select triggerid_down,triggerid_up from trigger_depends where triggerid_up=$triggerid_up and triggerid_down=$triggerid_down";
$result=DBexecute($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $down=DBget_field($result,$i,0);
- $up=DBget_field($result,$i,1);
+ $down=$row["triggerid_down"];
+ $up=$row["triggerid_up"];
$sql="update triggers set dep_level=dep_level-1 where triggerid=$up";
DBexecute($sql);
}
@@ -266,17 +259,17 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
{
$sql="select triggerid_down from trigger_depends where triggerid_up=$triggerid_down";
$result=DBselect($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $triggerid=DBget_field($result,$i,0);
+ $triggerid=$row["triggerid_down"];
insert_dependency($triggerid,$triggerid_up);
add_additional_dependencies($triggerid,$triggerid_up);
}
$sql="select triggerid_up from trigger_depends where triggerid_down=$triggerid_up";
$result=DBselect($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- $triggerid=DBget_field($result,$i,0);
+ $triggerid=$row["triggerid_up"];
insert_dependency($triggerid_down,$triggerid);
add_additional_dependencies($triggerid_down,$triggerid);
}
@@ -304,9 +297,9 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
{
$sql="select triggerid from functions where itemid=$itemid";
$result=DBselect($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- if(!delete_trigger(DBget_field($result,$i,0)))
+ if(!delete_trigger($row["triggerid"]))
{
return FALSE;
}
@@ -321,9 +314,9 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid";
{
$sql="select serviceid from services where triggerid=$triggerid";
$result=DBselect($sql);
- for($i=0;$i<DBnum_rows($result);$i++)
+ while($row=DBfetch($result))
{
- delete_service(DBget_field($result,$i,0));
+ delete_service($row["serviceid"]);
}
return TRUE;
}