summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-29 15:44:44 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-29 15:44:44 +0000
commitb3fdbc2e18481417daa954df4a84715019ead9a3 (patch)
treea66eaa27f88e3a180afc8f28c7b04b82b0b47eed /frontends/php/include
parent9ebbcf5e025c0353bef8bf11d8bccd811c663024 (diff)
- [DEV-118] updates and fixes {still beta} (Artem)
- [DEV-126] removed screen/maps/graphs {beta} (Artem) - other changes (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5423 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/blocks.inc.php58
-rw-r--r--frontends/php/include/config.inc.php185
-rw-r--r--frontends/php/include/hosts.inc.php29
-rw-r--r--frontends/php/include/locales/en_gb.inc.php2
-rw-r--r--frontends/php/include/page_header.php13
-rw-r--r--frontends/php/include/profiles.inc.php241
6 files changed, 297 insertions, 231 deletions
diff --git a/frontends/php/include/blocks.inc.php b/frontends/php/include/blocks.inc.php
index 8e3819b6..6ecb2bda 100644
--- a/frontends/php/include/blocks.inc.php
+++ b/frontends/php/include/blocks.inc.php
@@ -167,11 +167,10 @@ function make_favorite_graphs($available_hosts=false){
$table = new CTableInfo();
- $graphids = get_profile('web.favorite.graphids',array());
- $graph_rsrc = get_profile('web.favorite.graph_rsrc',array());
+ $fav_graphs = get4favorites('web.favorite.graphids');
- foreach($graphids as $key => $resourceid){
- if('simple_graph' == $graph_rsrc[$key]){
+ foreach($fav_graphs['id'] as $key => $resourceid){
+ if('simple_graph' == $fav_graphs['resource'][$key]){
if(!$item = get_item_by_itemid($resourceid)) continue;
$host = get_host_by_itemid($resourceid);
@@ -202,7 +201,7 @@ function make_favorite_graphs($available_hosts=false){
$capt)
));
}
-
+ $table->SetFooter(new CCol(new CLink(S_SHOW.SPACE.S_GRAPHS,'charts.php','link')));
return $table;
}
@@ -210,11 +209,9 @@ return $table;
function make_favorite_screens(){
$table = new CTableInfo();
- $screenids = get_profile('web.favorite.screenids',array());
- $screen_rsrc = get_profile('web.favorite.screen_rsrc',array());
-
- foreach($screenids as $key => $resourceid){
- if('slides' == $screen_rsrc[$key]){
+ $fav_screens = get4favorites('web.favorite.screenids');
+ foreach($fav_screens['id'] as $key => $resourceid){
+ if('slides' == $fav_screens['resource'][$key]){
if(!$slide = get_slideshow_by_slideshowid($resourceid)) continue;
$capt = new CSpan(new CLink($slide['name'],'screens.php?config=1&elementid='.$resourceid));
@@ -239,7 +236,7 @@ function make_favorite_screens(){
$capt)
));
}
-
+ $table->SetFooter(new CCol(new CLink(S_SHOW.SPACE.S_SCREENS,'screens.php','link')));
return $table;
}
@@ -247,14 +244,15 @@ return $table;
function make_favorite_maps(){
$table = new CTableInfo();
- $sysmapids = get_profile('web.favorite.sysmapids',array());
- foreach($sysmapids as $key => $sysmapid){
- if(!$sysmap = get_sysmap_by_sysmapid($sysmapid)) continue;
+ $fav_sysmaps = get4favorites('web.favorite.sysmapids');
+
+ foreach($fav_sysmaps['id'] as $key => $resourceid){
+ if(!$sysmap = get_sysmap_by_sysmapid($resourceid)) continue;
- $capt = new CSpan(new CLink($sysmap['name'],'maps.php?sysmapid='.$sysmapid));
+ $capt = new CSpan(new CLink($sysmap['name'],'maps.php?sysmapid='.$resourceid));
$capt->AddOption('style','line-height: 14px; vertical-align: middle;');
- $icon = new CLink(new CImg('images/general/chart.png','map',18,18,'borderless'),'maps.php?sysmapid='.$sysmapid.'&fullscreen=1');
+ $icon = new CLink(new CImg('images/general/chart.png','map',18,18,'borderless'),'maps.php?sysmapid='.$resourceid.'&fullscreen=1');
$icon->SetTarget('blank');
$table->AddRow(new CCol(array(
@@ -263,7 +261,7 @@ function make_favorite_maps(){
$capt)
));
}
-
+ $table->SetFooter(new CCol(new CLink(S_SHOW.SPACE.S_MAPS,'maps.php','link')));
return $table;
}
@@ -577,12 +575,10 @@ function make_graph_menu(&$menu,&$submenu){
function make_graph_submenu(){
$graphids = array();
-
- $fav_graphids = get_profile('web.favorite.graphids',array());
- $graph_rsrc = get_profile('web.favorite.graph_rsrc',array());
-
- foreach($fav_graphids as $key => $resourceid){
- if('simple_graph' == $graph_rsrc[$key]){
+
+ $fav_graphs = get4favorites('web.favorite.graphids');
+ foreach($fav_graphs['id'] as $key => $resourceid){
+ if('simple_graph' == $fav_graphs['resource'][$key]){
if(!$item = get_item_by_itemid($resourceid)) continue;
$host = get_host_by_itemid($resourceid);
@@ -636,15 +632,15 @@ function make_sysmap_menu(&$menu,&$submenu){
function make_sysmap_submenu(){
$sysmapids = array();
- $fav_sysmaps = get_profile('web.favorite.sysmapids',array());
+ $fav_sysmaps = get4favorites('web.favorite.sysmapids');
- foreach($fav_sysmaps as $key => $sysmapid){
- if(!$sysmap = get_sysmap_by_sysmapid($sysmapid)) continue;
+ foreach($fav_sysmaps['id'] as $key => $resourceid){
+ if(!$sysmap = get_sysmap_by_sysmapid($resourceid)) continue;
$sysmapids[] = array(
'name' => $sysmap['name'],
'favobj'=> 'sysmaps',
- 'favid' => $sysmapid,
+ 'favid' => $resourceid,
'action'=> 'remove'
);
}
@@ -690,11 +686,9 @@ function make_screen_menu(&$menu,&$submenu){
function make_screen_submenu(){
$screenids = array();
- $fav_screens = get_profile('web.favorite.screenids',array());
- $screen_rsrc = get_profile('web.favorite.screen_rsrc',array());
-
- foreach($fav_screens as $key => $resourceid){
- if('slides' == $screen_rsrc[$key]){
+ $fav_screens = get4favorites('web.favorite.screenids');
+ foreach($fav_screens['id'] as $key => $resourceid){
+ if('slides' == $fav_screens['resource'][$key]){
if(!$slide = get_slideshow_by_slideshowid($resourceid)) continue;
$screenids[] = array(
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 8b196474..13c50189 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -27,6 +27,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
require_once "include/defines.inc.php";
require_once "include/html.inc.php";
require_once "include/copt.lib.php";
+ require_once "include/profiles.inc.php";
require_once "conf/maintenance.inc.php";
// GLOBALS
@@ -115,7 +116,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
if(file_exists($ZBX_CONFIGURATION_FILE) && !isset($_COOKIE['ZBX_CONFIG']) && !isset($DENY_GUI)){
include $ZBX_CONFIGURATION_FILE;
- require_once "include/db.inc.php";
+ require_once("include/db.inc.php");
$error = '';
if(!DBconnect($error)){
@@ -157,7 +158,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
if(!defined('ZBX_PAGE_NO_AUTHERIZATION')){
check_authorisation();
- include_once "include/locales/".$USER_DETAILS["lang"].".inc.php";
+ include_once("include/locales/".$USER_DETAILS["lang"].".inc.php");
process_locales();
}
else{
@@ -183,16 +184,16 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
if(isset($DENY_GUI)){
unset($show_warning);
- include_once "warning.php";
+ include_once("warning.php");
}
if(isset($show_setup)){
unset($show_setup);
- include_once "setup.php";
+ include_once("setup.php");
}
else if(isset($show_warning)){
unset($show_warning);
- include_once "warning.php";
+ include_once("warning.php");
}
/********** END INITIALIZATION ************/
@@ -207,8 +208,8 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
$ZBX_CURRENT_SUBNODES = array();
$ZBX_NODES = array();
- if(!defined('ZBX_PAGE_NO_AUTHERIZATION') && ZBX_DISTRIBUTED)
- {
+ if(!defined('ZBX_PAGE_NO_AUTHERIZATION') && ZBX_DISTRIBUTED){
+
$ZBX_CURRENT_NODEID = get_cookie('zbx_current_nodeid', $ZBX_LOCALNODEID); // Selected node
$ZBX_WITH_SUBNODES = get_cookie('zbx_with_subnodes', false); // Show elements from subnodes
@@ -221,35 +222,30 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
unset($node_data);
}
- if(isset($_REQUEST['show_subnodes']))
- {
+ if(isset($_REQUEST['show_subnodes'])){
$ZBX_WITH_SUBNODES = !empty($_REQUEST['show_subnodes']);
}
- if($node_data = DBfetch(DBselect("select * from nodes where nodeid=".$ZBX_CURRENT_NODEID)))
- {
+ if($node_data = DBfetch(DBselect("select * from nodes where nodeid=".$ZBX_CURRENT_NODEID))){
$ZBX_CURMASTERID = $node_data['masterid'];
}
$ZBX_NODES = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_LIST, null, PERM_RES_DATA_ARRAY);
- if ( !isset($ZBX_NODES[$ZBX_CURRENT_NODEID]) )
- {
+ if ( !isset($ZBX_NODES[$ZBX_CURRENT_NODEID]) ){
$denyed_page_requested = true;
$ZBX_CURRENT_NODEID = $ZBX_LOCALNODEID;
$ZBX_CURMASTERID = $ZBX_LOCMASTERID;
}
- foreach ( $ZBX_NODES as $nodeid => $node_data )
- {
+ foreach ( $ZBX_NODES as $nodeid => $node_data ){
for ( $curr_node = &$node_data;
$curr_node['masterid'] != 0 &&
(bccomp($curr_node['masterid'] , $ZBX_CURRENT_NODEID) != 0);
$curr_node = &$ZBX_NODES[$curr_node['masterid']]
);
- if (bccomp($curr_node['masterid'],$ZBX_CURRENT_NODEID) == 0 )
- {
+ if (bccomp($curr_node['masterid'],$ZBX_CURRENT_NODEID) == 0 ){
$ZBX_CURRENT_SUBNODES[$nodeid] = $nodeid;
}
}
@@ -257,8 +253,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
zbx_set_post_cookie('zbx_current_nodeid',$ZBX_CURRENT_NODEID);
zbx_set_post_cookie('zbx_with_subnodes',$ZBX_WITH_SUBNODES);
}
- else
- {
+ else{
$ZBX_CURRENT_NODEID = $ZBX_LOCALNODEID;
$ZBX_CURMASTERID = $ZBX_LOCMASTERID;
$ZBX_WITH_SUBNODES = false;
@@ -286,8 +281,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
return $result;
}
- function get_node_name_by_elid($id_val, $forse_with_subnodes = null)
- {
+ function get_node_name_by_elid($id_val, $forse_with_subnodes = null){
global $ZBX_NODES;
if ( ! is_show_subnodes($forse_with_subnodes) )
@@ -301,13 +295,11 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
return '['.$ZBX_NODES[$nodeid]['name'].'] ';
}
- function is_show_subnodes($forse_with_subnodes = null)
- {
+ function is_show_subnodes($forse_with_subnodes = null){
global $ZBX_WITH_SUBNODES;
- if ( is_null($forse_with_subnodes) )
- {
- if ( defined('ZBX_DISABLE_SUBNODES') )
+ if ( is_null($forse_with_subnodes)){
+ if ( defined('ZBX_DISABLE_SUBNODES'))
$forse_with_subnodes = false;
else
$forse_with_subnodes = $ZBX_WITH_SUBNODES;
@@ -315,12 +307,10 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
return $forse_with_subnodes;
}
- function access_deny()
- {
+ function access_deny(){
+
include_once "include/page_header.php";
-
show_error_message(S_NO_PERMISSIONS);
-
include_once "include/page_footer.php";
}
@@ -1386,141 +1376,6 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
return ($var == "") ? null : $var;
}
-
-/********** USER PROFILE ***********/
-
-//---------- GET USER VALUE -------------
- function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN){
- global $USER_DETAILS;
-
- $result = array();
-// $result = $default_value;
-
- if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){
- $db_profiles = DBselect('SELECT * FROM profiles WHERE userid='.$USER_DETAILS["userid"].' AND idx='.zbx_dbstr($idx));
-
- while($profile=DBfetch($db_profiles)){
- if($type==PROFILE_TYPE_UNKNOWN) $type = $profile["valuetype"];
-
- switch($type){
- case PROFILE_TYPE_INT:
- $result[] = intval($profile["value"]);
- break;
- case PROFILE_TYPE_STR:
- default:
- $result[] = strval($profile["value"]);
- }
- }
- }
-
- $result = array_filter($result, "not_empty");
-
- if(isset($result[0]) && (PROFILE_TYPE_ARRAY != $type)) $result = $result[0];
- if(empty($result)) $result = $default_value;
-
- return $result;
- }
-
-//----------- ADD/EDIT USERPROFILE -------------
- function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
- global $USER_DETAILS;
-
- if($USER_DETAILS["alias"]==ZBX_GUEST_USER){
- return false;
- }
-
- if($type==PROFILE_TYPE_UNKNOWN && is_array($value)) $type = PROFILE_TYPE_ARRAY;
- if($type==PROFILE_TYPE_ARRAY && !is_array($value)) $value = array($value);
-
- $sql='DELETE FROM profiles WHERE userid='.$USER_DETAILS["userid"].' and idx='.zbx_dbstr($idx);
- DBExecute($sql);
-
- insert_profile($idx,$value,$type);
-
- return true;
- }
-
- function insert_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
- global $USER_DETAILS;
-
- if(is_array($value)){
- foreach($value as $key => $val){
- insert_profile($idx,$val,$type); // recursion!!!
- }
- }
- else{
- $profileid = get_dbid('profiles', 'profileid');
- $sql='INSERT INTO profiles (profileid,userid,idx,value,valuetype)'.
- ' VALUES ('.$profileid.','.$USER_DETAILS["userid"].','.zbx_dbstr($idx).','.zbx_dbstr($value).','.$type.')';
- DBexecute($sql);
- }
-
- }
-
-/***********************************/
-
-/************ HISTORY **************/
- function get_user_history(){
- $history=array();
- $delimiter = new CSpan('&raquo;','delimiter');
- for($i = 0; $i < ZBX_HISTORY_COUNT; $i++){
- if($rows = get_profile('web.history.'.$i,false)){
- if($i>0){
- array_push($history,$delimiter);
- }
- $url = new CLink($rows[0],$rows[1],'history');
- array_push($history,array(SPACE,$url,SPACE));
- }
- }
- return $history;
- }
-
- function add_user_history($page){
-
- $title = explode('[',$page['title']);
- $title = $title[0];
-
- if(!(isset($page['hist_arg']) && is_array($page['hist_arg']))){
- return FALSE;
- }
-
- $url = '';
- foreach($page['hist_arg'] as $key => $arg){
- if(isset($_REQUEST[$arg]) && !empty($_REQUEST[$arg])){
- $url.=((empty($url))?('?'):('&')).$arg.'='.$_REQUEST[$arg];
- }
- }
- $url = $page['file'].$url;
-
- $curr = 0;
- $profile = array();
- for($i = 0; $i < ZBX_HISTORY_COUNT; $i++){
- if($history = get_profile('web.history.'.$i,false)){
- if($history[0] != $title){
- $profile[$curr] = $history;
- $curr++;
- }
- }
- }
-
- $history = array($title,$url);
-
- if($curr < ZBX_HISTORY_COUNT){
- for($i = 0; $i < $curr; $i++){
- update_profile('web.history.'.$i,$profile[$i],PROFILE_TYPE_ARRAY);
- }
- $result = update_profile('web.history.'.$curr,$history,PROFILE_TYPE_ARRAY);
- } else {
- for($i = 1; $i < ZBX_HISTORY_COUNT; $i++){
- update_profile('web.history.'.($i-1),$profile[$i],PROFILE_TYPE_ARRAY);
- }
- $result = update_profile('web.history.'.(ZBX_HISTORY_COUNT-1),$history,PROFILE_TYPE_ARRAY);
- }
-
- return $result;
- }
-
-
/* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */
if(function_exists("imagesetstyle"))
{
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 7a843557..81ac6b60 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -20,7 +20,6 @@
?>
<?php
require_once "include/graphs.inc.php";
-require_once "include/profiles.inc.php";
require_once "include/triggers.inc.php";
require_once "include/items.inc.php";
@@ -1288,4 +1287,32 @@ require_once "include/items.inc.php";
}
return $status;
}
+
+// Add Host Profile
+
+ function add_host_profile($hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,$hardware,$software,$contact,$location,$notes){
+
+ $result=DBselect("select * from hosts_profiles where hostid=$hostid");
+ if(DBfetch($result)){
+ error("Host profile already exists");
+ return 0;
+ }
+
+ $result=DBexecute("insert into hosts_profiles".
+ " (hostid,devicetype,name,os,serialno,tag,macaddress,hardware,software,contact,".
+ "location,notes) values ($hostid,".zbx_dbstr($devicetype).",".zbx_dbstr($name).",".
+ zbx_dbstr($os).",".zbx_dbstr($serialno).",".zbx_dbstr($tag).",".zbx_dbstr($macaddress).
+ ",".zbx_dbstr($hardware).",".zbx_dbstr($software).",".zbx_dbstr($contact).",".
+ zbx_dbstr($location).",".zbx_dbstr($notes).")");
+
+ return $result;
+ }
+
+// Delete Host Profile
+
+ function delete_host_profile($hostid){
+ $result=DBexecute("delete from hosts_profiles where hostid=$hostid");
+
+ return $result;
+ }
?>
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index e61c3e27..6dfbdb06 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -489,6 +489,7 @@
'S_LATEST_VALUES'=> 'Latest values',
'S_NO_PERMISSIONS'=> 'No permissions !',
'S_LATEST_DATA_BIG'=> 'LATEST DATA',
+ 'S_ALL'=> 'All',
'S_ALL_SMALL'=> 'all',
'S_ALL_BIG'=> 'ALL',
'S_MINUS_ALL_MINUS'=> '- all -',
@@ -940,6 +941,7 @@
'S_SYSTEM_STATUS'=> 'System status',
'S_LATEST_ISSUES'=> 'Latest issues',
'S_FAVORITE'=> 'Favorite',
+ 'S_FAVORITES'=> 'Favorites',
'S_EVERY'=> 'Every',
'S_REFRESHED'=> 'Refreshed',
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
index 628a5447..67672747 100644
--- a/frontends/php/include/page_header.php
+++ b/frontends/php/include/page_header.php
@@ -102,7 +102,11 @@ COpt::profiling_start("page");
"node_perm" => PERM_READ_LIST,
"default_page_id" => 0,
"pages"=>array(
- array("url"=>"dashboard.php" ,"label"=>S_DASHBOARD ),
+ array(
+ "url"=>"dashboard.php",
+ "label"=>S_DASHBOARD,
+ "sub_pages"=>array("chart2.php","charts.php","screens.php","maps.php","map.php")
+ ),
array("url"=>"overview.php" ,"label"=>S_OVERVIEW ),
array("url"=>"httpmon.php" ,"label"=>S_WEB ,
"sub_pages"=>array("httpdetails.php")
@@ -117,13 +121,6 @@ COpt::profiling_start("page");
array("url"=>"queue.php" ,"label"=>S_QUEUE ),
array("url"=>"events.php" ,"label"=>S_EVENTS ),
array("url"=>"actions.php" ,"label"=>S_ACTIONS ),
- array("url"=>"maps.php" ,"label"=>S_MAPS ,
- "sub_pages"=>array("map.php")
- ),
- array("url"=>"charts.php" ,"label"=>S_GRAPHS ,
- "sub_pages"=>array("chart2.php")
- ),
- array("url"=>"screens.php" ,"label"=>S_SCREENS ),
array("url"=>"discovery.php" ,"label"=>S_DISCOVERY , "user_type"=>USER_TYPE_ZABBIX_ADMIN),
array("url"=>"srv_status.php" ,"label"=>S_IT_SERVICES , 'forse_disable_subnodes' => true,
"sub_pages"=>array("report3.php","chart_sla.php","chart5.php")
diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php
index 2e74ab64..889b09dc 100644
--- a/frontends/php/include/profiles.inc.php
+++ b/frontends/php/include/profiles.inc.php
@@ -1,7 +1,7 @@
<?php
/*
** ZABBIX
-** Copyright (C) 2000-2005 SIA Zabbix
+** Copyright (C) 2000-2008 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
@@ -19,35 +19,226 @@
**/
?>
<?php
- # Add Host Profile
+/********** USER PROFILE ***********/
- function add_host_profile(
- $hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,
- $hardware,$software,$contact,$location,$notes)
- {
- $result=DBselect("select * from hosts_profiles where hostid=$hostid");
- if(DBfetch($result))
- {
- error("Host profile already exists");
- return 0;
+//---------- GET USER VALUE -------------
+function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN){
+ global $USER_DETAILS;
+
+ $result = array();
+// $result = $default_value;
+
+ if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){
+ $db_profiles = DBselect('SELECT * FROM profiles WHERE userid='.$USER_DETAILS["userid"].' AND idx='.zbx_dbstr($idx));
+
+ while($profile=DBfetch($db_profiles)){
+ if($type==PROFILE_TYPE_UNKNOWN) $type = $profile["valuetype"];
+
+ switch($type){
+ case PROFILE_TYPE_INT:
+ $result[] = intval($profile["value"]);
+ break;
+ case PROFILE_TYPE_STR:
+ default:
+ $result[] = strval($profile["value"]);
+ }
}
+ }
+
+ $result = array_filter($result, "not_empty");
+
+ if(isset($result[0]) && (PROFILE_TYPE_ARRAY != $type)) $result = $result[0];
+ if(empty($result)) $result = $default_value;
+
+return $result;
+}
+
+//----------- ADD/EDIT USERPROFILE -------------
+function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
+ global $USER_DETAILS;
- $result=DBexecute("insert into hosts_profiles".
- " (hostid,devicetype,name,os,serialno,tag,macaddress,hardware,software,contact,".
- "location,notes) values ($hostid,".zbx_dbstr($devicetype).",".zbx_dbstr($name).",".
- zbx_dbstr($os).",".zbx_dbstr($serialno).",".zbx_dbstr($tag).",".zbx_dbstr($macaddress).
- ",".zbx_dbstr($hardware).",".zbx_dbstr($software).",".zbx_dbstr($contact).",".
- zbx_dbstr($location).",".zbx_dbstr($notes).")");
-
- return $result;
+ if($USER_DETAILS["alias"]==ZBX_GUEST_USER){
+ return false;
}
+
+ if($type==PROFILE_TYPE_UNKNOWN && is_array($value)) $type = PROFILE_TYPE_ARRAY;
+ if($type==PROFILE_TYPE_ARRAY && !is_array($value)) $value = array($value);
- # Delete Host Profile
+ if(PROFILE_TYPE_ARRAY == $type){
+ $sql='DELETE FROM profiles WHERE userid='.$USER_DETAILS["userid"].' and idx='.zbx_dbstr($idx);
+ DBExecute($sql);
- function delete_host_profile($hostid)
- {
- $result=DBexecute("delete from hosts_profiles where hostid=$hostid");
+ insert_profile($idx,$value,$type);
+ }
+ else{
+ $row = DBfetch(DBselect('SELECT value FROM profiles WHERE userid='.$USER_DETAILS["userid"].' AND idx='.zbx_dbstr($idx)));
- return $result;
+ if(!$row){
+ insert_profile($idx,$value,$type);
+ }
+ else{
+ $sql='UPDATE profiles SET value='.zbx_dbstr($value).',valuetype='.$type.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx);
+ DBexecute($sql);
+ }
}
-?>
+
+return true;
+}
+
+// Author: Aly
+function insert_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
+ global $USER_DETAILS;
+
+ if(is_array($value)){
+ foreach($value as $key => $val){
+ insert_profile($idx,$val,$type); // recursion!!!
+ }
+ }
+ else{
+ $profileid = get_dbid('profiles', 'profileid');
+ $sql='INSERT INTO profiles (profileid,userid,idx,value,valuetype)'.
+ ' VALUES ('.$profileid.','.$USER_DETAILS["userid"].','.zbx_dbstr($idx).','.zbx_dbstr($value).','.$type.')';
+ DBexecute($sql);
+ }
+
+}
+
+/***********************************/
+
+/************ HISTORY **************/
+// Author: Aly
+function get_user_history(){
+ $history=array();
+ $delimiter = new CSpan('&raquo;','delimiter');
+ for($i = 0; $i < ZBX_HISTORY_COUNT; $i++){
+ if($rows = get_profile('web.history.'.$i,false)){
+ if($i>0){
+ array_push($history,$delimiter);
+ }
+ $url = new CLink($rows[0],$rows[1],'history');
+ array_push($history,array(SPACE,$url,SPACE));
+ }
+ }
+return $history;
+}
+
+// Author: Aly
+function add_user_history($page){
+
+ $title = explode('[',$page['title']);
+ $title = $title[0];
+
+ if(!(isset($page['hist_arg']) && is_array($page['hist_arg']))){
+ return FALSE;
+ }
+
+ $url = '';
+ foreach($page['hist_arg'] as $key => $arg){
+ if(isset($_REQUEST[$arg]) && !empty($_REQUEST[$arg])){
+ $url.=((empty($url))?('?'):('&')).$arg.'='.$_REQUEST[$arg];
+ }
+ }
+ $url = $page['file'].$url;
+
+ $curr = 0;
+ $profile = array();
+ for($i = 0; $i < ZBX_HISTORY_COUNT; $i++){
+ if($history = get_profile('web.history.'.$i,false)){
+ if($history[0] != $title){
+ $profile[$curr] = $history;
+ $curr++;
+ }
+ }
+ }
+
+ $history = array($title,$url);
+
+ if($curr < ZBX_HISTORY_COUNT){
+ for($i = 0; $i < $curr; $i++){
+ update_profile('web.history.'.$i,$profile[$i],PROFILE_TYPE_ARRAY);
+ }
+ $result = update_profile('web.history.'.$curr,$history,PROFILE_TYPE_ARRAY);
+ } else {
+ for($i = 1; $i < ZBX_HISTORY_COUNT; $i++){
+ update_profile('web.history.'.($i-1),$profile[$i],PROFILE_TYPE_ARRAY);
+ }
+ $result = update_profile('web.history.'.(ZBX_HISTORY_COUNT-1),$history,PROFILE_TYPE_ARRAY);
+ }
+
+return $result;
+}
+/********* END USER HISTORY **********/
+
+/********** USER FAVORITES ***********/
+// Author: Aly
+function add2favorites($favobj,$favid,$resource=null){
+ $favrsrc = $favobj.'_rsrc';
+
+ $favorites = get_profile($favobj,array());
+ $fav_rsrc = get_profile($favrsrc,array());
+
+ $favorites[] = $favid;
+ $fav_rsrc[] = (is_null($resource))?0:$resource;
+
+ $result = update_profile($favobj,$favorites);
+ $result &= update_profile($favrsrc,$fav_rsrc);
+
+return $result;
+}
+
+// Author: Aly
+function rm4favorites($favobj,$favid,$favcnt=null,$resource=null){
+ $favrsrc = $favobj.'_rsrc';
+
+ $favorites = get_profile($favobj,array());
+ $fav_rsrc = get_profile($favrsrc,array());
+
+ $resource = (is_null($resource))?0:$resource;
+ $favcnt = (is_null($favcnt))?0:$favcnt;
+
+ foreach($favorites as $key => $value){
+ if(($favid == $value) && ($fav_rsrc[$key] == $resource)){
+ if($favcnt < 1){
+ unset($favorites[$key]);
+ unset($fav_rsrc[$key]);
+ break;
+ }
+ }
+ $favcnt--;
+ }
+
+ $result = update_profile($favobj,$favorites);
+ $result &= update_profile($favrsrc,$fav_rsrc);
+return $result;
+}
+
+// Author: Aly
+function get4favorites($favobj){
+ $favrsrc = $favobj.'_rsrc';
+
+ $fav = array();
+ $fav['id'] = get_profile($favobj,array());
+ $fav['resource'] = get_profile($favrsrc,array());
+
+return $fav;
+}
+
+
+// Author: Aly
+function infavorites($favobj,$favid,$resource=null){
+
+ $fav = get4favorites($favobj);
+ if(!empty($fav)){
+ foreach($fav['id'] as $id => $resourceid){
+ if($favid == $resourceid){
+ if(is_null($resource) || ($fav['resource'][$id] == $resource))
+ return true;
+ }
+ }
+ }
+return false;
+}
+/********** END USER FAVORITES ***********/
+?> \ No newline at end of file