diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-29 15:44:44 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-29 15:44:44 +0000 |
| commit | b3fdbc2e18481417daa954df4a84715019ead9a3 (patch) | |
| tree | a66eaa27f88e3a180afc8f28c7b04b82b0b47eed /frontends/php/include/profiles.inc.php | |
| parent | 9ebbcf5e025c0353bef8bf11d8bccd811c663024 (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/profiles.inc.php')
| -rw-r--r-- | frontends/php/include/profiles.inc.php | 241 |
1 files changed, 216 insertions, 25 deletions
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('»','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 |
