summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-06-25 11:52:41 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-06-25 11:52:41 +0000
commit56a5e3453ca8651296755d5833aac6becf620fa3 (patch)
tree7d633b3cbc921d8065939a923da02b5fc0fb4836 /frontends/php/include
parentd3fc7944f6fd4a51dba16bcb1e24fa154a29e5fb (diff)
downloadzabbix-56a5e3453ca8651296755d5833aac6becf620fa3.tar.gz
zabbix-56a5e3453ca8651296755d5833aac6becf620fa3.tar.xz
zabbix-56a5e3453ca8651296755d5833aac6becf620fa3.zip
- [DEV-137] fix simple graphs error. Tnx to Palmertree. (Artem)
- [DEV-137] added profile value_id devision by nodes (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5788 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/config.inc.php5
-rw-r--r--frontends/php/include/db.inc.php2
-rw-r--r--frontends/php/include/hosts.inc.php20
-rw-r--r--frontends/php/include/profiles.inc.php94
4 files changed, 52 insertions, 69 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 2f8c9c91..f031b854 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -1271,8 +1271,9 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
}
function zbx_empty($var){
- if(is_null($var)) return true;
- if($var === '') return true;
+ if(is_null($var)) return true;
+ if(is_array($var) && empty($var)) return true;
+ if(is_string($var) && ($var === '')) return true;
return false;
}
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 31f018c3..1136adcc 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -645,7 +645,7 @@ else {
if(empty($nodes))
$nodes = 0;
- if(is_numeric($nodes)){
+ if(ctype_digit($nodes)){
$nodes = array($nodes);
}
else if(is_string($nodes)){
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index bfabd80a..0923fc2b 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -847,11 +847,11 @@ require_once "include/httptest.inc.php";
if(is_null($group_var)) $group_var = "web.latest.groupid";
if(is_null($host_var)) $host_var = "web.latest.hostid";
- $_REQUEST["groupid"] = get_request("groupid", -1 );
- $_REQUEST["hostid"] = get_request("hostid", get_profile($host_var,0));
+ $_REQUEST["groupid"] = get_request("groupid", -1);
+ $_REQUEST["hostid"] = get_request("hostid", get_profile($host_var, 0, PROFILE_TYPE_ID));
if(-1 == $_REQUEST["groupid"]){
- $_REQUEST["groupid"] = get_profile($group_var,0);
+ $_REQUEST["groupid"] = get_profile($group_var, 0, PROFILE_TYPE_ID);
if(!in_node($_REQUEST["groupid"])) $_REQUEST["groupid"] = 0;
@@ -868,8 +868,8 @@ require_once "include/httptest.inc.php";
$_REQUEST["groupid"] = $result["groupid"];
$_REQUEST["hostid"] = $result["hostid"];
- update_profile($host_var,$_REQUEST["hostid"]);
- update_profile($group_var,$_REQUEST["groupid"]);
+ update_profile($host_var,$_REQUEST["hostid"], PROFILE_TYPE_ID);
+ update_profile($group_var,$_REQUEST["groupid"], PROFILE_TYPE_ID);
}
/*
@@ -885,18 +885,18 @@ require_once "include/httptest.inc.php";
* Modified: by Aly
*/
function validate_group($perm, $options = array(),$group_var=null){
- if(is_null($group_var)) $group_var = "web.latest.groupid";
- $_REQUEST["groupid"] = get_request("groupid",get_profile($group_var,0));
+ if(is_null($group_var)) $group_var = 'web.latest.groupid';
+ $_REQUEST["groupid"] = get_request('groupid',get_profile($group_var, 0, PROFILE_TYPE_ID));
- if(!in_node($_REQUEST["groupid"])) $_REQUEST["groupid"] = 0;
+ if(!in_node($_REQUEST['groupid'])) $_REQUEST['groupid'] = 0;
if(str_in_array('always_select_first_group',$options) && ($_REQUEST['groupid'] == 0))
$_REQUEST['groupid'] = -1;
$result = get_correct_group_and_host($_REQUEST['groupid'],null,$perm,$options);
- $_REQUEST["groupid"] = $result["groupid"];
+ $_REQUEST['groupid'] = $result['groupid'];
- update_profile($group_var,$_REQUEST["groupid"]);
+ update_profile($group_var, $_REQUEST['groupid'], PROFILE_TYPE_ID);
}
/* APPLICATIONS */
diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php
index 929b8527..5790c356 100644
--- a/frontends/php/include/profiles.inc.php
+++ b/frontends/php/include/profiles.inc.php
@@ -30,8 +30,9 @@ function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN,$idx2=n
if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){
$sql_cond = '';
- if(ctype_digit($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2');
- if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source);
+ if(profile_type($type,'id')) $sql_cond.= ' AND '.DBin_node('value_id');
+ if(ctype_digit($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2');
+ if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source);
$sql = 'SELECT value_id, value_int, value_str, type '.
' FROM profiles '.
@@ -43,10 +44,10 @@ function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN,$idx2=n
if($profile=DBfetch($db_profiles)){
- if(PROFILE_TYPE_UNKNOWN == $type) $type = $profile['type'];
+ if(profile_type($type,'unknown')) $type = $profile['type'];
$value_type = profile_field_by_type($type);
- if(profile_type_array($type)){
+ if(profile_type($type,'array')){
$result[] = $profile[$value_type];
while($profile=DBfetch($db_profiles)){
$result[] = $profile[$value_type];
@@ -70,8 +71,9 @@ function get_source_profile($idx,$default_value=array(),$type=PROFILE_TYPE_UNKNO
if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){
$sql_cond = '';
- if(ctype_digit($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2');
- if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source);
+ if(profile_type($type,'id')) $sql_cond.= ' AND '.DBin_node('value_id');
+ if(ctype_digit($idx2)) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2');
+ if(!is_null($source)) $sql_cond.= ' AND source='.zbx_dbstr($source);
$sql = 'SELECT value_id,value_int,value_str,source,type '.
' FROM profiles '.
@@ -82,10 +84,10 @@ function get_source_profile($idx,$default_value=array(),$type=PROFILE_TYPE_UNKNO
$db_profiles = DBselect($sql);
if($profile=DBfetch($db_profiles)){
- if(PROFILE_TYPE_UNKNOWN == $type) $type = $profile['type'];
+ if(profile_type($type,'unknown')) $type = $profile['type'];
$value_type = profile_field_by_type($type);
- if(profile_type_array($type)){
+ if(profile_type($type,'array')){
$result[] = array('value'=>$profile[$value_type], 'source'=>$profile['source']);
while($profile=DBfetch($db_profiles)){
@@ -103,17 +105,12 @@ function get_source_profile($idx,$default_value=array(),$type=PROFILE_TYPE_UNKNO
return $result;
}
-function get_node_profile($idx,$default_value=null,$nodeid=null){
- $profile = profiles_in_node(get_profile($idx,$default_value),$nodeid);
-return (zbx_empty($profile))?$default_value:$profile;
-}
-
//----------- ADD/EDIT USERPROFILE -------------
function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$source=null){
global $USER_DETAILS;
if($USER_DETAILS["alias"]==ZBX_GUEST_USER) return false;
- if(PROFILE_TYPE_UNKNOWN == $type) $type = profile_type_by_value($value);
+ if(profile_type($type,'unknown')) $type = profile_type_by_value($value);
else $value = profile_value_by_type($value,$type);
if($value === false) return false;
@@ -122,7 +119,7 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$idx2=null,$sourc
if(ctype_digit($idx2)) $sql_cond = ' AND idx2='.$idx2.' AND '.DBin_node('idx2');
DBstart();
- if(profile_type_array($type)){
+ if(profile_type($type,'array')){
$sql='DELETE FROM profiles '.
' WHERE userid='.$USER_DETAILS["userid"].
@@ -225,8 +222,28 @@ return $result;
}
// ----------- MISC PROFILE FUNCTIONS -----------
-function profile_type_array($type){
- return uint_in_array($type,array(PROFILE_TYPE_ARRAY_ID,PROFILE_TYPE_ARRAY_INT,PROFILE_TYPE_ARRAY_STR));
+function profile_type($type,$profile_type){
+ $profile_type = strtolower($profile_type);
+ switch($profile_type){
+ case 'array':
+ $result = uint_in_array($type,array(PROFILE_TYPE_ARRAY_ID,PROFILE_TYPE_ARRAY_INT,PROFILE_TYPE_ARRAY_STR));
+ break;
+ case 'id':
+ $result = uint_in_array($type,array(PROFILE_TYPE_ID,PROFILE_TYPE_ARRAY_ID));
+ break;
+ case 'int':
+ $result = uint_in_array($type,array(PROFILE_TYPE_INT,PROFILE_TYPE_ARRAY_INT));
+ break;
+ case 'str':
+ $result = uint_in_array($type,array(PROFILE_TYPE_STR,PROFILE_TYPE_ARRAY_STR));
+ break;
+ case 'unknown':
+ $result = ($type == PROFILE_TYPE_UNKNOWN);
+ break;
+ default:
+ $result = false;
+ }
+return $result;
}
function profile_field_by_type($type){
@@ -269,7 +286,7 @@ return $type;
function profile_value_by_type(&$value,$type){
- if(profile_type_array($type)){
+ if(profile_type($type,'array')){
$result = is_array($value)?$value:array($value);
}
else if(is_array($value)){
@@ -309,8 +326,7 @@ function profile_value_by_type(&$value,$type){
return $result;
}
-/***********************************/
-
+/********** END MISC ***********/
/************ HISTORY **************/
@@ -404,20 +420,10 @@ return $result;
/********** USER FAVORITES ***********/
// Author: Aly
function get_favorites($favobj,$nodeid=null){
- $fav = get_source_profile($favobj);
-
- if(is_null($nodeid))
- $nodeid = get_current_nodeid();
-
- if(!is_array($nodeid))
- $nodeid = array($nodeid);
-
- foreach($fav as $key => $favorite){
- if(!uint_in_array(id2nodeid($favorite['value']),$nodeid)) unset($fav[$key]);
- }
-
+ $fav = get_source_profile($favobj,array(),PROFILE_TYPE_ARRAY_ID);
return $fav;
}
+
// Author: Aly
function add2favorites($favobj,$favid,$source=null){
$favorites = get_favorites($favobj,get_current_nodeid(true));
@@ -464,28 +470,4 @@ function infavorites($favobj,$favid,$source=null){
return false;
}
/********** END USER FAVORITES ***********/
-
-/********** MISC ***********/
-
-function profiles_in_node($profile, $nodeid=null){
- if(is_null($nodeid))
- $nodeid = get_current_nodeid();
-
- if(!is_array($nodeid))
- $nodeid = array($nodeid);
-
- if(is_array($profile)){
- foreach($profile as $key => $value){
- $value = profiles_in_node($value,$nodeid);
- if(!zbx_empty($value)) $profile[$key] = $value;
- else unset($profile[$key]);
- }
- }
- else if(is_numeric($profile)){
- if(!uint_in_array(id2nodeid($profile),$nodeid)) $profile = null;;
- }
-
-return $profile;
-}
-/********** END MISC ***********/
?> \ No newline at end of file