summaryrefslogtreecommitdiffstats
path: root/frontends/php
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
parentd3fc7944f6fd4a51dba16bcb1e24fa154a29e5fb (diff)
- [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')
-rw-r--r--frontends/php/chart.php4
-rw-r--r--frontends/php/charts.php4
-rw-r--r--frontends/php/events.php2
-rw-r--r--frontends/php/history.php4
-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
-rw-r--r--frontends/php/latest.php8
-rw-r--r--frontends/php/overview.php4
-rw-r--r--frontends/php/tr_events.php58
-rw-r--r--frontends/php/tr_status.php4
12 files changed, 96 insertions, 113 deletions
diff --git a/frontends/php/chart.php b/frontends/php/chart.php
index 7beeb1f1..9d9813e7 100644
--- a/frontends/php/chart.php
+++ b/frontends/php/chart.php
@@ -61,9 +61,9 @@ include_once "include/page_header.php";
$effectiveperiod = navigation_bar_calc();
- $_REQUEST['period'] = get_request('period',get_profile('web.item['.$_REQUEST['itemid'].'].graph.period', ZBX_PERIOD_DEFAULT));
+ $_REQUEST['period'] = get_request('period',get_profile('web.item.graph.period', ZBX_PERIOD_DEFAULT, PROFILE_TYPE_INT, $_REQUEST['itemid']));
if($_REQUEST['period'] >= ZBX_MIN_PERIOD){
- update_profile('web.item['.$_REQUEST['itemid'].'].graph.period',$_REQUEST['period']);
+ update_profile('web.item.graph.period',$_REQUEST['period'], PROFILE_TYPE_INT, $_REQUEST['itemid']);
}
diff --git a/frontends/php/charts.php b/frontends/php/charts.php
index 56ee2e4c..f5979932 100644
--- a/frontends/php/charts.php
+++ b/frontends/php/charts.php
@@ -92,8 +92,8 @@ include_once 'include/page_header.php';
$_REQUEST["groupid"] = $_REQUEST["hostid"] = 0;
}
- $_REQUEST['graphid'] = get_request('graphid', get_profile('web.charts.graphid', 0));
- if(!in_node($_REQUEST["graphid"])) $_REQUEST["graphid"] = 0;
+ $_REQUEST['graphid'] = get_request('graphid', get_profile('web.charts.graphid', 0, PROFILE_TYPE_ID));
+ if(!in_node($_REQUEST['graphid'])) $_REQUEST['graphid'] = 0;
$_REQUEST["keep"] = get_request('keep', 1); // possible excessed REQUEST variable !!!
$_REQUEST["period"] = get_request('period',get_profile('web.graph.period', ZBX_PERIOD_DEFAULT, PROFILE_TYPE_INT, $_REQUEST['graphid']));
diff --git a/frontends/php/events.php b/frontends/php/events.php
index 55de7e1b..cbe9debf 100644
--- a/frontends/php/events.php
+++ b/frontends/php/events.php
@@ -259,7 +259,7 @@ include_once "include/page_header.php";
$sql_cond = ' and h.hostid=hg.hostid and hg.groupid='.$_REQUEST['groupid'];
}
else{
- $sql_from = ', hosts_groups hg ';
+ $sql_from = '';
$sql_cond = ' and h.hostid in ('.$available_hosts.') ';
}
diff --git a/frontends/php/history.php b/frontends/php/history.php
index a3688b6f..cc716e64 100644
--- a/frontends/php/history.php
+++ b/frontends/php/history.php
@@ -169,12 +169,12 @@ include_once "include/page_header.php";
if(infavorites('web.favorite.graphids',$_REQUEST['itemid'],'itemid')){
$icon = new CDiv(SPACE,'iconminus');
$icon->AddOption('title',S_REMOVE_FROM.' '.S_FAVORITES);
- $icon->AddAction('onclick',new CScript('javascript: rm4favorites('itemid',''.$_REQUEST['itemid'].'',0);'));
+ $icon->AddAction('onclick',new CScript("javascript: rm4favorites('itemid','".$_REQUEST['itemid']."',0);"));
}
else{
$icon = new CDiv(SPACE,'iconplus');
$icon->AddOption('title',S_ADD_TO.' '.S_FAVORITES);
- $icon->AddAction('onclick',new CScript('javascript: add2favorites('itemid',''.$_REQUEST['itemid'].'');'));
+ $icon->AddAction('onclick',new CScript("javascript: add2favorites('itemid','".$_REQUEST['itemid']."');"));
}
$icon->AddOption('id','addrm_fav');
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
diff --git a/frontends/php/latest.php b/frontends/php/latest.php
index 8ccf0f6f..ac44a107 100644
--- a/frontends/php/latest.php
+++ b/frontends/php/latest.php
@@ -52,12 +52,12 @@ include_once "include/page_header.php";
$options = array('allow_all_hosts','monitored_hosts','with_monitored_items');
- $_REQUEST['hostid'] = get_request('hostid',get_profile('web.latest.last.hostid'));
- if(!isset($_REQUEST['hostid'])){
+ $_REQUEST['hostid'] = get_request('hostid',get_profile('web.latest.last.hostid', null, PROFILE_TYPE_ID));
+ if(is_null($_REQUEST['hostid'])){
array_push($options,'always_select_first_host');
- $_REQUEST['groupid'] = get_request('groupid',get_profile('web.latest.last.groupid'));
- if(!isset($_REQUEST['groupid'])){
+ $_REQUEST['groupid'] = get_request('groupid',get_profile('web.latest.last.groupid', null, PROFILE_TYPE_ID));
+ if(is_null($_REQUEST['groupid'])){
validate_group(PERM_READ_ONLY,array('allow_all_hosts','monitored_hosts','with_monitored_items','always_select_first_group'),'web.latest.last.groupid');
}
}
diff --git a/frontends/php/overview.php b/frontends/php/overview.php
index 26ff1b0e..bd0b97d6 100644
--- a/frontends/php/overview.php
+++ b/frontends/php/overview.php
@@ -52,8 +52,8 @@ if(isset($_REQUEST["select"])&&($_REQUEST["select"]!="")){
$options = array('allow_all_hosts','monitored_hosts','with_monitored_items');
- $_REQUEST['groupid'] = get_request('groupid',get_profile('web.latest.last.groupid'));
- if(!isset($_REQUEST['groupid'])){
+ $_REQUEST['groupid'] = get_request('groupid',get_profile('web.latest.last.groupid', null, PROFILE_TYPE_ID));
+ if(is_null($_REQUEST['groupid'])){
array_push($options,'always_select_first_group');
validate_group(PERM_READ_ONLY, $options, 'web.overview.groupid');
}
diff --git a/frontends/php/tr_events.php b/frontends/php/tr_events.php
index 360c3566..98015919 100644
--- a/frontends/php/tr_events.php
+++ b/frontends/php/tr_events.php
@@ -86,13 +86,13 @@
show_table_header(array(S_EVENTS_BIG.': "'.$trigger_data['exp_desc'].'"'), null);
-$left_tab = new CTable();
-$left_tab->SetCellPadding(3);
-$left_tab->SetCellSpacing(3);
-
-$left_tab->AddOption('border',0);
-
-$left_tab->AddRow(create_hat(
+ $left_tab = new CTable();
+ $left_tab->SetCellPadding(3);
+ $left_tab->SetCellSpacing(3);
+
+ $left_tab->AddOption('border',0);
+
+ $left_tab->AddRow(create_hat(
S_EVENT.SPACE.S_SOURCE.SPACE.S_DETAILS,
make_trigger_details($_REQUEST['triggerid'],$trigger_data),//null,
null,
@@ -100,7 +100,7 @@ $left_tab->AddRow(create_hat(
get_profile('web.tr_events.hats.hat_triggerdetails.state',1)
));
-$left_tab->AddRow(create_hat(
+ $left_tab->AddRow(create_hat(
S_EVENT_DETAILS,
make_event_details($_REQUEST['eventid']),//null,
null,
@@ -109,14 +109,14 @@ $left_tab->AddRow(create_hat(
));
-$right_tab = new CTable();
-$right_tab->SetCellPadding(3);
-$right_tab->SetCellSpacing(3);
+ $right_tab = new CTable();
+ $right_tab->SetCellPadding(3);
+ $right_tab->SetCellSpacing(3);
-$right_tab->AddOption('border',0);
+ $right_tab->AddOption('border',0);
-$right_tab->AddRow(create_hat(
+ $right_tab->AddRow(create_hat(
S_ACKNOWLEDGES,
make_acktab_by_eventid($_REQUEST['eventid']),//null,
null,
@@ -124,7 +124,7 @@ $right_tab->AddRow(create_hat(
get_profile('web.tr_events.hats.hat_eventack.state',1)
));
-$right_tab->AddRow(create_hat(
+ $right_tab->AddRow(create_hat(
S_MESSAGE_ACTIONS,
get_action_msgs_for_event($_REQUEST['eventid']),//null,
null,
@@ -132,7 +132,7 @@ $right_tab->AddRow(create_hat(
get_profile('web.tr_events.hats.hat_eventactionmsgs.state',1)
));
-$right_tab->AddRow(create_hat(
+ $right_tab->AddRow(create_hat(
S_COMMAND_ACTIONS,
get_action_cmds_for_event($_REQUEST['eventid']),//null,
null,
@@ -140,7 +140,7 @@ $right_tab->AddRow(create_hat(
get_profile('web.tr_events.hats.hat_eventactioncmds.state',1)
));
-$right_tab->AddRow(create_hat(
+ $right_tab->AddRow(create_hat(
S_EVENTS.SPACE.S_LIST.SPACE.'['.S_LAST.' 20]',
//null,//
make_small_eventlist($_REQUEST['triggerid'],$trigger_data),
@@ -150,19 +150,19 @@ $right_tab->AddRow(create_hat(
));
-$td_l = new CCol($left_tab);
-$td_l->AddOption('valign','top');
-
-$td_r = new CCol($right_tab);
-$td_r->AddOption('valign','top');
-
-$outer_table = new CTable();
-$outer_table->AddOption('border',0);
-$outer_table->SetCellPadding(1);
-$outer_table->SetCellSpacing(1);
-$outer_table->AddRow(array($td_l,$td_r));
-
-$outer_table->Show();
+ $td_l = new CCol($left_tab);
+ $td_l->AddOption('valign','top');
+
+ $td_r = new CCol($right_tab);
+ $td_r->AddOption('valign','top');
+
+ $outer_table = new CTable();
+ $outer_table->AddOption('border',0);
+ $outer_table->SetCellPadding(1);
+ $outer_table->SetCellSpacing(1);
+ $outer_table->AddRow(array($td_l,$td_r));
+
+ $outer_table->Show();
?>
<?php
diff --git a/frontends/php/tr_status.php b/frontends/php/tr_status.php
index 3eb174e9..e1e4a391 100644
--- a/frontends/php/tr_status.php
+++ b/frontends/php/tr_status.php
@@ -108,11 +108,11 @@ include_once "include/page_header.php";
$options = array('allow_all_hosts','monitored_hosts','with_monitored_items');
if(!$ZBX_WITH_SUBNODES) array_push($options,'only_current_node');
- $_REQUEST['hostid'] = get_request('hostid',get_profile('web.tr_status.hostid'));
+ $_REQUEST['hostid'] = get_request('hostid',get_profile('web.tr_status.hostid', null, PROFILE_TYPE_ID));
if(!isset($_REQUEST['hostid'])){
array_push($options,'always_select_first_host');
- $_REQUEST['groupid'] = get_request('groupid',get_profile('web.tr_status.groupid'));
+ $_REQUEST['groupid'] = get_request('groupid',get_profile('web.tr_status.groupid', null, PROFILE_TYPE_ID));
if(!isset($_REQUEST['groupid'])){
validate_group(PERM_READ_ONLY,array('allow_all_hosts','monitored_hosts','with_monitored_items','always_select_first_group'),'web.tr_status.groupid');
}