summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-14 13:26:42 +0000
committerartem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-14 13:26:42 +0000
commit5348f67b28ed1da2539db6de7a11c605a5dc3a57 (patch)
tree4646832d5a7263dbe6818409d9ce9e9dff419008 /frontends/php/include
parentc44eed92d3f3bcfc0efad6e18e31323f089a9ce6 (diff)
downloadzabbix-5348f67b28ed1da2539db6de7a11c605a5dc3a57.tar.gz
zabbix-5348f67b28ed1da2539db6de7a11c605a5dc3a57.tar.xz
zabbix-5348f67b28ed1da2539db6de7a11c605a5dc3a57.zip
- [DEV-142] added transactions to DB actions (beta) (Artem)
- [DEV-137] improvements in permission checks (Artem) - [DEV-137] changes in schema (Artem) git-svn-id: svn://svn.zabbix.com/trunk@5619 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/actions.inc.php12
-rw-r--r--frontends/php/include/blocks.inc.php69
-rw-r--r--frontends/php/include/config.inc.php15
-rw-r--r--frontends/php/include/db.inc.php306
-rw-r--r--frontends/php/include/defines.inc.php5
-rw-r--r--frontends/php/include/forms.inc.php46
-rw-r--r--frontends/php/include/graphs.inc.php19
-rw-r--r--frontends/php/include/hosts.inc.php10
-rw-r--r--frontends/php/include/images.inc.php125
-rw-r--r--frontends/php/include/import.inc.php183
-rw-r--r--frontends/php/include/items.inc.php44
-rw-r--r--frontends/php/include/maps.inc.php14
-rw-r--r--frontends/php/include/page_header.php5
-rw-r--r--frontends/php/include/perm.inc.php74
-rw-r--r--frontends/php/include/profiles.inc.php265
-rw-r--r--frontends/php/include/screens.inc.php54
-rw-r--r--frontends/php/include/scripts.inc.php4
-rw-r--r--frontends/php/include/setup.inc.php126
-rw-r--r--frontends/php/include/triggers.inc.php21
19 files changed, 693 insertions, 704 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index c35ca4a9..1201ff32 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -609,8 +609,7 @@ include_once 'include/discovery.inc.php';
{
case CONDITION_TYPE_HOST_GROUP:
if(!uint_in_array($value,
- get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,null,
- PERM_RES_IDS_ARRAY)))
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY)))
{
error(S_INCORRECT_GROUP);
return false;
@@ -626,8 +625,7 @@ include_once 'include/discovery.inc.php';
break;
case CONDITION_TYPE_HOST:
if(!uint_in_array($value,
- get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,
- PERM_RES_IDS_ARRAY)))
+ get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_RES_IDS_ARRAY)))
{
error(S_INCORRECT_HOST);
return false;
@@ -718,8 +716,7 @@ include_once 'include/discovery.inc.php';
case OPERATION_TYPE_GROUP_ADD:
case OPERATION_TYPE_GROUP_REMOVE:
if(!uint_in_array($operation['objectid'],
- get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,null,
- PERM_RES_IDS_ARRAY)))
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY)))
{
error(S_INCORRECT_GROUP);
return false;
@@ -728,8 +725,7 @@ include_once 'include/discovery.inc.php';
case OPERATION_TYPE_TEMPLATE_ADD:
case OPERATION_TYPE_TEMPLATE_REMOVE:
if(!uint_in_array($operation['objectid'],
- get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,
- PERM_RES_IDS_ARRAY)))
+ get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_RES_IDS_ARRAY)))
{
error(S_INCORRECT_HOST);
return false;
diff --git a/frontends/php/include/blocks.inc.php b/frontends/php/include/blocks.inc.php
index bc676c20..b90b398d 100644
--- a/frontends/php/include/blocks.inc.php
+++ b/frontends/php/include/blocks.inc.php
@@ -28,10 +28,14 @@ require_once "include/maps.inc.php";
function make_favorite_graphs(){
$table = new CTableInfo();
- $fav_graphs = get4favorites('web.favorite.graphids');
+ $fav_graphs = get_multi_profile('web.favorite.graphids');
- foreach($fav_graphs['id'] as $key => $resourceid){
- if('itemid' == $fav_graphs['resource'][$key]){
+ foreach($fav_graphs as $key => $favorite){
+
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
+ if('itemid' == $resource){
if(!$item = get_item_by_itemid($resourceid)) continue;
$host = get_host_by_itemid($resourceid);
@@ -81,9 +85,13 @@ return $table;
function make_favorite_screens(){
$table = new CTableInfo();
- $fav_screens = get4favorites('web.favorite.screenids');
- foreach($fav_screens['id'] as $key => $resourceid){
- if('slideshowid' == $fav_screens['resource'][$key]){
+ $fav_screens = get_multi_profile('web.favorite.screenids');
+
+ foreach($fav_screens as $key => $favorite){
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
+ if('slideshowid' == $resource){
if(!$slide = get_slideshow_by_slideshowid($resourceid)) continue;
if(!slideshow_accessible($resourceid, PERM_READ_ONLY)) continue;
@@ -129,9 +137,13 @@ return $table;
function make_favorite_maps(){
$table = new CTableInfo();
- $fav_sysmaps = get4favorites('web.favorite.sysmapids');
+ $fav_sysmaps = get_multi_profile('web.favorite.sysmapids');
- foreach($fav_sysmaps['id'] as $key => $resourceid){
+ foreach($fav_sysmaps as $key => $favorite){
+
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
if(!$sysmap = get_sysmap_by_sysmapid($resourceid)) continue;
if(!sysmap_accessible($resourceid,PERM_READ_ONLY)) continue;
@@ -164,8 +176,8 @@ function make_system_summary(){
global $USER_DETAILS;
$config=select_config();
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid());
- $available_triggers = get_accessible_triggers(PERM_READ_LIST, null, get_current_nodeid());
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $available_triggers = get_accessible_triggers(PERM_READ_LIST);
$table = new CTableInfo();
$table->SetHeader(array(
@@ -498,8 +510,8 @@ return $table;
function make_latest_issues(){
global $USER_DETAILS;
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid());
- $available_triggers = get_accessible_triggers(PERM_READ_LIST, null, get_current_nodeid());
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
+ $available_triggers = get_accessible_triggers(PERM_READ_LIST);
$scripts_by_hosts = get_accessible_scripts_by_hosts(explode(',',$available_hosts));
$config=select_config();
@@ -669,7 +681,7 @@ return $table;
function make_webmon_overview(){
global $USER_DETAILS;
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid());
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
$table = new CTableInfo();
$table->SetHeader(array(
@@ -742,7 +754,7 @@ return $table;
function make_latest_data(){
global $USER_DETAILS;
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid());
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
while($db_app = DBfetch($db_applications)){
$db_items = DBselect('SELECT DISTINCT i.* '.
@@ -879,9 +891,14 @@ function make_graph_menu(&$menu,&$submenu){
function make_graph_submenu(){
$graphids = array();
- $fav_graphs = get4favorites('web.favorite.graphids');
- foreach($fav_graphs['id'] as $key => $resourceid){
- if('itemid' == $fav_graphs['resource'][$key]){
+ $fav_graphs = get_multi_profile('web.favorite.graphids');
+
+ foreach($fav_graphs as $key => $favorite){
+
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
+ if('itemid' == $resource){
if(!$item = get_item_by_itemid($resourceid)) continue;
$item_added = true;
@@ -957,9 +974,13 @@ function make_sysmap_menu(&$menu,&$submenu){
function make_sysmap_submenu(){
$sysmapids = array();
- $fav_sysmaps = get4favorites('web.favorite.sysmapids');
+ $fav_sysmaps = get_multi_profile('web.favorite.sysmapids');
+
+ foreach($fav_sysmaps as $key => $favorite){
- foreach($fav_sysmaps['id'] as $key => $resourceid){
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
if(!$sysmap = get_sysmap_by_sysmapid($resourceid)) continue;
$sysmapids[] = array(
@@ -1020,9 +1041,13 @@ function make_screen_menu(&$menu,&$submenu){
function make_screen_submenu(){
$screenids = array();
- $fav_screens = get4favorites('web.favorite.screenids');
- foreach($fav_screens['id'] as $key => $resourceid){
- if('slideshowid' == $fav_screens['resource'][$key]){
+ $fav_screens = get_multi_profile('web.favorite.screenids');
+
+ foreach($fav_screens as $key => $favorite){
+ $resource = $favorite['resource'];
+ $resourceid = $favorite['value'];
+
+ if('slideshowid' == $resource){
if(!$slide = get_slideshow_by_slideshowid($resourceid)) continue;
$slide_added = true;
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 583c80e4..dd8207db 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -90,7 +90,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
set_error_handler('zbx_err_handler');
- global $ZBX_LOCALNODEID, $ZBX_LOCMASTERID, $ZBX_CONFIGURATION_FILE, $DB_TYPE, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $ZBX_LOCALNODEID, $ZBX_LOCMASTERID, $ZBX_CONFIGURATION_FILE, $DB;
global $ZBX_SERVER, $ZBX_SERVER_PORT;
global $ZBX_LOCALES;
@@ -264,8 +264,8 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
define('ZBX_DISABLE_SUBNODES', 1);
}
- function get_current_nodeid( $forse_with_subnodes = null, $perm = null ){
- global $ZBX_CURRENT_NODEID, $ZBX_CURRENT_SUBNODES, $ZBX_WITH_SUBNODES;
+ function get_current_nodeid($forse_with_subnodes = null, $perm = null){
+ global $USER_DETAILS, $ZBX_CURRENT_NODEID, $ZBX_CURRENT_SUBNODES, $ZBX_WITH_SUBNODES;
if(!isset($ZBX_CURRENT_NODEID))
init_nodes();
@@ -273,14 +273,13 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
$result = ( is_show_subnodes($forse_with_subnodes) ? $ZBX_CURRENT_SUBNODES : $ZBX_CURRENT_NODEID );
if(!is_null($perm)){
- global $USER_DETAILS;
$result = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_ONLY, null, null, $result);
}
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) )
@@ -294,7 +293,7 @@ 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)){
@@ -1081,7 +1080,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
function get_status(){
- global $DB_TYPE;
+ global $DB;
$status = array();
// server
if( (exec('ps -ef|grep zabbix_server|grep -v grep|wc -l')>0) || (exec('ps -ax|grep zabbix_server|grep -v grep|wc -l')>0) ){
@@ -1091,7 +1090,7 @@ function TODO($msg) { echo "TODO: ".$msg.SBR; } // DEBUG INFO!!!
$status["zabbix_server"] = S_NO;
}
// history & trends
-/* if ($DB_TYPE == "MYSQL")
+/* if ($DB['DB_TYPE'] == "MYSQL")
{
$row=DBfetch(DBselect("show table status like 'history'"));
$status["history_count"] = $row["Rows"];
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 76af876c..a839c1ca 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -19,39 +19,33 @@
**/
?>
<?php
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS;
+ global $DB;
- function DBconnect(&$error)
- {
+ function DBconnect(&$error){
$result = true;
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS;
+ global $DB;
- $DB = null;
+ $DB['DB'] = null;
+ $DB['TRANSACTIONS'] = 0;
-//SDI('type: '.$DB_TYPE.'; server: '.$DB_SERVER.'; port: '.$DB_PORT.'; db: '.$DB_DATABASE.'; usr: '.$DB_USER.'; pass: '.$DB_PASSWORD);
+//SDI('type: '.$DB['TYPE'].'; server: '.$DB['SERVER'].'; port: '.$DB['PORT'].'; db: '.$DB['DATABASE'].'; usr: '.$DB['USER'].'; pass: '.$DB['PASSWORD']);
- if(!isset($DB_TYPE))
- {
+ if(!isset($DB['TYPE'])){
$error = "Unknown database type.";
$result = false;
}
- else
- {
- switch($DB_TYPE)
- {
+ else{
+ switch($DB['TYPE']){
case "MYSQL":
- $mysql_server = $DB_SERVER.( !empty($DB_PORT) ? ':'.$DB_PORT : '');
+ $mysql_server = $DB['SERVER'].( !empty($DB['PORT']) ? ':'.$DB['PORT'] : '');
- if ( !($DB = mysql_pconnect($mysql_server,$DB_USER,$DB_PASSWORD)))
- {
+ if (!$DB['DB']= mysql_pconnect($mysql_server,$DB['USER'],$DB['PASSWORD'])){
$error = "Error connecting to database [".mysql_error()."]";
$result = false;
}
- else
- {
- if ( !mysql_select_db($DB_DATABASE) )
- {
+ else{
+ if (!mysql_select_db($DB['DATABASE'])){
$error = 'Error database selection ['.mysql_error().']';
$result = false;
}
@@ -59,38 +53,35 @@
break;
case "POSTGRESQL":
$pg_connection_string =
- ( !empty($DB_SERVER) ? 'host=\''.$DB_SERVER.'\' ' : '').
- 'dbname=\''.$DB_DATABASE.'\' '.
- ( !empty($DB_USER) ? 'user=\''.$DB_USER.'\' ' : '').
- ( !empty($DB_PASSWORD) ? 'password=\''.$DB_PASSWORD.'\' ' : '').
- ( !empty($DB_PORT) ? 'port='.$DB_PORT : '');
-
- $DB=pg_connect($pg_connection_string);
- if(!$DB)
- {
+ ( !empty($DB['SERVER']) ? 'host=\''.$DB['SERVER'].'\' ' : '').
+ 'dbname=\''.$DB['DATABASE'].'\' '.
+ ( !empty($DB['USER']) ? 'user=\''.$DB['USER'].'\' ' : '').
+ ( !empty($DB['PASSWORD']) ? 'password=\''.$DB['PASSWORD'].'\' ' : '').
+ ( !empty($DB['PORT']) ? 'port='.$DB['PORT'] : '');
+
+ $DB['DB']= pg_connect($pg_connection_string);
+ if(!$DB['DB']){
$error = 'Error connecting to database';
$result = false;
}
break;
case "ORACLE":
- $DB = ociplogon($DB_USER, $DB_PASSWORD, $DB_DATABASE);
-/* $DB = ocilogon($DB_USER, $DB_PASSWORD, $DB_DATABASE);*/
- //$DB = ocilogon($DB_USER, $DB_PASSWORD, "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$DB_SERVER)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=$DB_DATABASE)))");
- if(!$DB)
- {
+ $DB['DB']= ociplogon($DB['USER'], $DB['PASSWORD'], $DB['DATABASE']);
+// $DB['DB']= ociplogon($DB['USER'], $DB['PASSWORD'], "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$DB['SERVER'])(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=$DB['DATABASE'])))");
+ if(!$DB['DB']){
$error = "Error connecting to database";
$result = false;
}
break;
case "SQLITE3":
- $DB_TRANSACTIONS = 0;
+ $DB['TRANSACTIONS'] = 0;
if(!function_exists('init_db_access')){
function init_db_access(){
- global $DB_DATABASE, $ZBX_SEM_ID;
+ global $DB, $ZBX_SEM_ID;
$ZBX_SEM_ID = false;
- if(function_exists('ftok') && function_exists('sem_get') && file_exists($DB_DATABASE)){
- $ZBX_SEM_ID = sem_get(ftok($DB_DATABASE, 'z'), 1);
+ if(function_exists('ftok') && function_exists('sem_get') && file_exists($DB['DATABASE'])){
+ $ZBX_SEM_ID = sem_get(ftok($DB['DATABASE'], 'z'), 1);
}
}
}
@@ -126,9 +117,9 @@
}
- if(file_exists($DB_DATABASE)){
- $DB = sqlite3_open($DB_DATABASE);
- if(!$DB){
+ if(file_exists($DB['DATABASE'])){
+ $DB['DB']= sqlite3_open($DB['DATABASE']);
+ if(!$DB['DB']){
$error = "Error connecting to database";
$result = false;
}
@@ -146,30 +137,30 @@
}
}
if( false == $result )
- $DB = null;
+ $DB['DB']= null;
return $result;
}
function DBclose(){
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $DB_TRANSACTIONS;
+ global $DB;
$result = false;
- if( isset($DB) && !empty($DB) ){
- switch($DB_TYPE){
+ if( isset($DB['DB']) && !empty($DB['DB']) ){
+ switch($DB['TYPE']){
case "MYSQL":
- $result = mysql_close($DB);
+ $result = mysql_close($DB['DB']);
break;
case "POSTGRESQL":
- $result = pg_close($DB);
+ $result = pg_close($DB['DB']);
break;
case "ORACLE":
- $result = ocilogoff($DB);
+ $result = ocilogoff($DB['DB']);
break;
case "SQLITE3":
$result = true;
- sqlite3_close($DB);
+ sqlite3_close($DB['DB']);
free_db_access();
break;
default: break;
@@ -190,12 +181,10 @@
return $result;
}
- function DBloadfile($file, &$error)
- {
- global $DB_TYPE;
+ function DBloadfile($file, &$error){
+ global $DB;
- if(!file_exists($file))
- {
+ if(!file_exists($file)){
$error = 'DBloadfile. Missing file['.$file.']';
return false;
}
@@ -220,12 +209,21 @@
return true;
}
- function DBStart(){
- global $DB,$DB_TYPE,$DB_TRANSACTIONS;
-//SDI('TRANSACTION STARTED');
+ function DBstart(){
+ global $DB;
+
+ $DB['TRANSACTIONS']++;
+
+ if($DB['TRANSACTIONS']>1){
+ info('POSSIBLE ERROR: Used incorect logic in database processing, started subtransaction!');
+ return $DB['TRANSACTION_STATE'];
+ }
+
+ $DB['TRANSACTION_STATE'] = true;
+
$result = false;
- if( isset($DB) && !empty($DB) )
- switch($DB_TYPE){
+ if(isset($DB['DB']) && !empty($DB['DB']))
+ switch($DB['TYPE']){
case "MYSQL":
$result = DBexecute('begin;');
break;
@@ -233,31 +231,39 @@
$result = DBexecute('begin;');
break;
case "ORACLE":
- $DB_TRANSACTIONS++;
-
- if($DB_TRANSACTIONS>1){
- info("POSSIBLE ERROR: Used incorect logic in database processing started subtransaction!");
- }
$result = true;
// TODO OCI_DEFAULT
break;
- case "SQLITE3":
- $DB_TRANSACTIONS++;
-
- if(1 == $DB_TRANSACTIONS){
+ case "SQLITE3":
+ if(1 == $DB['TRANSACTIONS']){
lock_db_access();
$result = DBexecute('begin;');
}
- else{
- error("POSSIBLE ERROR: Used incorect logic in database processing started subtransaction!");
- }
break;
}
return $result;
}
- function DBend($result=true){
+ function DBend($result=null){
+ global $DB;
+
+ if($DB['TRANSACTIONS'] != 1){
+ $DB['TRANSACTIONS']--;
+
+ if($DB['TRANSACTIONS'] < 1){
+ $DB['TRANSACTIONS'] = 0;
+ $DB['TRANSACTION_STATE'] = false;
+ info('POSSIBLE ERROR: Used incorect logic in database processing, transaction not started!');
+ }
+ return $DB['TRANSACTION_STATE'];
+ }
+
+ $DB['TRANSACTIONS'] = 0;
+
+ if(empty($result))
+ $result = $DB['TRANSACTION_STATE'];
+
if($result){ // OK
$result = DBcommit();
}
@@ -265,16 +271,16 @@
if(!$result){ // FAIL
DBrollback();
}
-//SDI('TRANSACTION ENDED: '.$result);
+
return $result;
}
function DBcommit(){
- global $DB,$DB_TYPE,$DB_TRANSACTIONS;
-//SDI('COMMITED!');
+ global $DB;
+
$result = false;
- if( isset($DB) && !empty($DB) )
- switch($DB_TYPE){
+ if( isset($DB['DB']) && !empty($DB['DB']) )
+ switch($DB['TYPE']){
case "MYSQL":
$result = DBexecute('commit;');
break;
@@ -282,30 +288,24 @@
$result = DBexecute('commit;');
break;
case "ORACLE":
- $result = ocicommit($DB);
- $DB_TRANSACTIONS = 0;
+ $result = ocicommit($DB['DB']);
+
break;
case "SQLITE3":
- if($DB_TRANSACTIONS>1)
- $DB_TRANSACTIONS--;
-
- if(1 == $DB_TRANSACTIONS){
- $result = DBexecute('commit;');
- $DB_TRANSACTIONS = 0;
-
- unlock_db_access();
- }
+ $result = DBexecute('commit;');
+ unlock_db_access();
break;
}
+
return $result;
}
function DBrollback(){
- global $DB,$DB_TYPE,$DB_TRANSACTIONS;
-//SDI('ROLLED BACK!');
+ global $DB;
+
$result = false;
- if( isset($DB) && !empty($DB) )
- switch($DB_TYPE){
+ if( isset($DB['DB']) && !empty($DB['DB']) )
+ switch($DB['TYPE']){
case "MYSQL":
$result = DBexecute('rollback;');
break;
@@ -313,21 +313,14 @@
$result = DBexecute('rollback;');
break;
case "ORACLE":
- $result = ocirollback($DB);
- $DB_TRANSACTIONS = 0;
+ $result = ocirollback($DB['DB']);
break;
- case "SQLITE3":
- if($DB_TRANSACTIONS>1)
- $DB_TRANSACTIONS--;
-
- if(1 == $DB_TRANSACTIONS){
- $result = DBexecute('rollback;');
- $DB_TRANSACTIONS = 0;
-
- unlock_db_access();
- }
+ case "SQLITE3":
+ $result = DBexecute('rollback;');
+ unlock_db_access();
break;
}
+
return $result;
}
@@ -347,20 +340,19 @@
SELECT * FROM (SELECT ROWNUM as RN, * FROM tbl) WHERE RN BETWEEN 6 AND 15
*/
- function &DBselect($query, $limit='NO')
- {
- global $DB, $DB_TYPE, $DB_TRANSACTIONS;
+ function &DBselect($query, $limit='NO'){
+ global $DB;
//COpt::savesqlrequest($query);
$result = false;
- if( isset($DB) && !empty($DB) )
- switch($DB_TYPE){
+ if( isset($DB['DB']) && !empty($DB['DB']) )
+ switch($DB['TYPE']){
case "MYSQL":
if(is_numeric($limit)){
$query .= ' limit '.intval($limit);
}
- $result=mysql_query($query,$DB);
+ $result=mysql_query($query,$DB['DB']);
if(!$result){
error("Error in query [$query] [".mysql_error()."]");
}
@@ -369,7 +361,7 @@
if(is_numeric($limit)){
$query .= ' limit '.intval($limit);
}
- $result = pg_query($DB,$query);
+ $result = pg_query($DB['DB'],$query);
if(!$result){
error("Error in query [$query] [".pg_last_error()."]");
}
@@ -378,29 +370,20 @@
if(is_numeric($limit)){
$query = 'select * from ('.$query.') where rownum<'.intval($limit);
}
-
- $stid=OCIParse($DB,$query);
- if(!$stid){
- $e=@ocierror();
- error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
- }
-
- $result=@OCIExecute($stid,($DB_TRANSACTIONS?OCI_DEFAULT:OCI_COMMIT_ON_SUCCESS));
+ $result = DBexecute($query);
if(!$result){
- $e=ocierror($stid);
+ $e = ocierror($stid);
error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
}
- else{
- $result = $stid;
- }
+
break;
case "SQLITE3":
- if(!$DB_TRANSACTIONS){
+ if(!$DB['TRANSACTIONS']){
lock_db_access();
}
- if(!($result = sqlite3_query($DB,$query))){
- error("Error in query [$query] [".sqlite3_error($DB)."]");
+ if(!($result = sqlite3_query($DB['DB'],$query))){
+ error("Error in query [$query] [".sqlite3_error($DB['DB'])."]");
}
else{
$data = array();
@@ -419,7 +402,7 @@
$result = &$data;
}
- if(!$DB_TRANSACTIONS){
+ if(!$DB['TRANSACTIONS']){
unlock_db_access();
}
break;
@@ -428,60 +411,75 @@
return $result;
}
- function DBexecute($query, $skip_error_messages=0){
- global $DB,$DB_TYPE,$DB_TRANSACTIONS;
+ function DBexecute($query, $skip_error_messages=0){
+ global $DB;
//COpt::savesqlrequest($query);
$result = false;
- if( isset($DB) && !empty($DB) )
- switch($DB_TYPE){
+ if( isset($DB['DB']) && !empty($DB['DB']) )
+ switch($DB['TYPE']){
case "MYSQL":
- $result=mysql_query($query,$DB);
+ $result=mysql_query($query,$DB['DB']);
if(!$result){
error("Error in query [$query] [".mysql_error()."]");
}
break;
case "POSTGRESQL":
- if(!($result = pg_query($DB,$query))){
+ if(!($result = pg_query($DB['DB'],$query))){
error("Error in query [$query] [".pg_last_error()."]");
}
break;
case "ORACLE":
- $result = DBselect($query);
+ $stid=OCIParse($DB['DB'],$query);
+ if(!$stid){
+ $e=@ocierror();
+ error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
+ }
+
+ $result=@OCIExecute($stid,($DB['TRANSACTIONS']?OCI_DEFAULT:OCI_COMMIT_ON_SUCCESS));
if(!$result){
- $e = ocierror($stid);
+ $e=ocierror($stid);
error("SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
}
+ else{
+ $result = $stid;
+ }
+
break;
case "SQLITE3":
- if(!$DB_TRANSACTIONS){
+ if(!$DB['TRANSACTIONS']){
lock_db_access();
}
- $result = sqlite3_exec($DB, $query);
+ $result = sqlite3_exec($DB['DB'], $query);
if(!$result){
- error("Error in query [$query] [".sqlite3_error($DB)."]");
+ error("Error in query [$query] [".sqlite3_error($DB['DB'])."]");
}
- if(!$DB_TRANSACTIONS){
+ if(!$DB['TRANSACTIONS']){
unlock_db_access();
}
break;
}
+ if($DB['TRANSACTIONS']){
+ $DB['TRANSACTION_STATE'] &= $result;
+// SDI($query);
+// SDI($DB['TRANSACTION_STATE']);
+ }
return $result;
}
function DBfetch(&$cursor){
- global $DB, $DB_TYPE;
+ global $DB;
$result = false;
- if(isset($DB) && !empty($DB))
- switch($DB_TYPE){
+ if(isset($DB['DB']) && !empty($DB['DB']))
+ switch($DB['TYPE']){
case "MYSQL":
$result = mysql_fetch_assoc($cursor);
break;
@@ -509,7 +507,7 @@
/* string value prepearing */
-if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
+if(isset($DB['TYPE']) && $DB['TYPE'] == "ORACLE") {
function zbx_dbstr($var) {
return "'".ereg_replace('\'','\'\'',$var)."'";
}
@@ -518,7 +516,7 @@ if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
return ' CAST('.$field.' AS NUMBER(20)) ';
}
}
-else if(isset($DB_TYPE) && $DB_TYPE == "MYSQL") {
+else if(isset($DB['TYPE']) && $DB['TYPE'] == "MYSQL") {
function zbx_dbstr($var) {
return "'".mysql_real_escape_string($var)."'";
}
@@ -527,7 +525,7 @@ else if(isset($DB_TYPE) && $DB_TYPE == "MYSQL") {
return ' CAST('.$field.' AS UNSIGNED) ';
}
}
-else if(isset($DB_TYPE) && $DB_TYPE == "POSTGRESQL") {
+else if(isset($DB['TYPE']) && $DB['TYPE'] == "POSTGRESQL") {
function zbx_dbstr($var) {
return "'".pg_escape_string($var)."'";
}
@@ -546,11 +544,11 @@ else {
}
}
- function zbx_dbconcat($params)
+ function zbx_dbconcat($params)
{
- global $DB_TYPE;
+ global $DB;
- switch($DB_TYPE)
+ switch($DB['TYPE'])
{
case "SQLITE3":
return implode(' || ',$params);
@@ -560,9 +558,9 @@ else {
}
function zbx_sql_mod($x,$y){
- global $DB_TYPE;
+ global $DB;
- switch($DB_TYPE)
+ switch($DB['TYPE'])
{
case "SQLITE3":
return ' ('.$x.' %% '.$y.')';
@@ -573,9 +571,9 @@ else {
function DBid2nodeid($id_name)
{
- global $DB_TYPE;
+ global $DB;
- switch($DB_TYPE)
+ switch($DB['TYPE'])
{
case "MYSQL":
$result = '('.$id_name.' div 100000000000000)';
@@ -713,11 +711,11 @@ else {
}
function DBin_condition($fieldname, &$array){
- global $DB_TYPE;
+ global $DB;
$condition = '';
- switch($DB_TYPE) {
+ switch($DB['TYPE']) {
case 'ORACLE':
$items = array_chunk($array, 1000);
foreach($items as $id => $value){
@@ -733,4 +731,4 @@ else {
return '('.$fieldname.' IN ('.$condition.'))';
}
-?>
+?> \ No newline at end of file
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 53461d93..3126a35f 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -328,8 +328,9 @@
define('PROFILE_TYPE_UNKNOWN', 0);
define('PROFILE_TYPE_ARRAY', 1);
- define('PROFILE_TYPE_INT', 2);
- define('PROFILE_TYPE_STR', 3);
+
+ define('PROFILE_TYPE_MULTI', 2);
+ define('PROFILE_TYPE_MULTI_ARRAY', 3);
define('CALC_FNC_MIN', 1);
define('CALC_FNC_AVG', 2);
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index fb774f30..0c196e51 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -1162,7 +1162,7 @@
$lst['node']['read_only'] = new CListBox('nodes_read' ,null ,6);
$lst['node']['deny'] = new CListBox('nodes_deny' ,null ,6);
- $nodes = get_accessible_nodes_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY);
+ $nodes = get_accessible_nodes_by_rights($rights, $user_type, PERM_DENY, null, PERM_RES_DATA_ARRAY);
foreach($nodes as $node)
{
@@ -1182,8 +1182,7 @@
$lst['group']['read_only'] = new CListBox('groups_read' ,null ,10);
$lst['group']['deny'] = new CListBox('groups_deny' ,null ,10);
- $groups = get_accessible_groups_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY,
- ZBX_DISTRIBUTED ? null : $ZBX_LOCALNODEID);
+ $groups = get_accessible_groups_by_rights($rights, $user_type, PERM_DENY, null, PERM_RES_DATA_ARRAY, get_current_nodeid(false));
foreach($groups as $group)
{
@@ -1202,13 +1201,10 @@
$lst['host']['read_only'] = new CListBox('hosts_read' ,null ,15);
$lst['host']['deny'] = new CListBox('hosts_deny' ,null ,15);
- $hosts = get_accessible_hosts_by_rights($rights, $user_type, PERM_DENY, PERM_MODE_GE, PERM_RES_DATA_ARRAY,
- ZBX_DISTRIBUTED ? null : $ZBX_LOCALNODEID);
+ $hosts = get_accessible_hosts_by_rights($rights, $user_type, PERM_DENY, null, PERM_RES_DATA_ARRAY, get_current_nodeid(false));
- foreach($hosts as $host)
- {
- switch($host['permission'])
- {
+ foreach($hosts as $host){
+ switch($host['permission']){
case PERM_READ_ONLY: $list_name='read_only'; break;
case PERM_READ_WRITE: $list_name='read_write'; break;
default: $list_name='deny'; break;
@@ -1217,11 +1213,9 @@
}
unset($hosts);
- foreach($lst as $name => $lists)
- {
+ foreach($lst as $name => $lists){
$row = new CRow();
- foreach($lists as $class => $list_obj)
- {
+ foreach($lists as $class => $list_obj){
$row->AddItem(new CCol($list_obj, $class));
}
$table->AddRow($row);
@@ -1960,7 +1954,7 @@
$cmbGroups = new CComboBox("add_groupid",$add_groupid);
$groups=DBselect("SELECT DISTINCT groupid,name FROM groups ".
- "where groupid in (".get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid()).") ".
+ "where groupid in (".get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY).") ".
" order by name");
while($group=DBfetch($groups))
{
@@ -3696,9 +3690,9 @@ include_once 'include/discovery.inc.php';
$cmbRes->AddItem(SCREEN_RESOURCE_EVENTS, S_HISTORY_OF_EVENTS);
$form->AddRow(S_RESOURCE,$cmbRes);
- if($resourcetype == SCREEN_RESOURCE_GRAPH)
- {
+ if($resourcetype == SCREEN_RESOURCE_GRAPH){
// User-defined graph
+ $resourceid = graph_accessible($resourceid)?$resourceid:0;
$caption = '';
$id=0;
@@ -3710,8 +3704,7 @@ include_once 'include/discovery.inc.php';
' LEFT JOIN items i ON gi.itemid=i.itemid '.
' LEFT JOIN hosts h ON h.hostid=i.hostid '.
' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('g.graphid').
- ' WHERE i.hostid NOT IN ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).')'.
- ' AND g.graphid='.$resourceid);
+ ' WHERE g.graphid='.$resourceid);
while($row=DBfetch($result)){
$row["node_name"] = isset($row["node_name"]) ? "(".$row["node_name"].") " : '';
@@ -3742,7 +3735,7 @@ include_once 'include/discovery.inc.php';
' WHERE h.hostid=i.hostid '.
' AND h.status='.HOST_STATUS_MONITORED.
' AND i.status='.ITEM_STATUS_ACTIVE.
- ' AND i.hostid not in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).')'.
+ ' AND i.hostid IN ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
' AND i.itemid='.$resourceid);
while($row=DBfetch($result)){
@@ -3792,8 +3785,7 @@ include_once 'include/discovery.inc.php';
$form->AddRow(S_PARAMETER,array($textfield,SPACE,$selectbtn));
}
- elseif($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT)
- {
+ else if($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT){
// Plain text
$caption = '';
$id=0;
@@ -3805,7 +3797,7 @@ include_once 'include/discovery.inc.php';
' WHERE h.hostid=i.hostid '.
' AND h.status='.HOST_STATUS_MONITORED.
' AND i.status='.ITEM_STATUS_ACTIVE.
- ' AND i.hostid not in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,PERM_MODE_LT).')'.
+ ' AND i.hostid IN ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
' AND i.itemid='.$resourceid);
while($row=DBfetch($result)){
@@ -3847,7 +3839,7 @@ include_once 'include/discovery.inc.php';
$result=DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name '.
' FROM hosts_groups hg,hosts h,groups g '.
' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('g.groupid').
- ' WHERE g.groupid in ('.get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
+ ' WHERE g.groupid IN ('.get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
' AND g.groupid=hg.groupid '.
' AND hg.hostid=h.hostid '.
' AND h.status='.HOST_STATUS_MONITORED.
@@ -4245,7 +4237,7 @@ include_once 'include/discovery.inc.php';
// add groups
$db_groups=DBselect("SELECT DISTINCT groupid FROM hosts_groups WHERE hostid=".$_REQUEST["hostid"].
" AND groupid in (".
- get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST,null,null,get_current_nodeid()).
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST).
") ");
while($db_group=DBfetch($db_groups)){
if(uint_in_array($db_group["groupid"],$groups)) continue;
@@ -4295,7 +4287,7 @@ include_once 'include/discovery.inc.php';
$db_groups=DBselect("SELECT DISTINCT groupid,name FROM groups ".
" WHERE groupid in (".
- get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST,null,null,get_current_nodeid()).
+ get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST).
") order by name");
while($db_group=DBfetch($db_groups))
{
@@ -4504,7 +4496,7 @@ include_once 'include/discovery.inc.php';
$cmbHosts = new CListBox("hosts[]",$hosts,10);
$db_hosts=DBselect('SELECT DISTINCT hostid,host FROM hosts'.
' WHERE status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')'.
- ' AND hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid()).')'.
+ ' AND hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
' order by host');
while($db_host=DBfetch($db_hosts))
{
@@ -4571,7 +4563,7 @@ include_once 'include/discovery.inc.php';
$cmbHosts = new CListBox("hosts[]",$hosts,10);
$db_hosts=DBselect('select hostid,proxy_hostid,host from hosts'.
' where status in ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.') '.
- ' and hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid()).')'.
+ ' and hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY).')'.
' order by host');
while($db_host=DBfetch($db_hosts))
{
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index d42a687d..9c5867ac 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -197,7 +197,7 @@
if(is_null($perm_res))
$perm_res = PERM_RES_STRING_LINE;
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, null, $nodeid);
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, $nodeid);
$denied_graphs = array();
$result = array();
@@ -220,7 +220,7 @@
(!empty($hostid)?' AND i.hostid='.$hostid:'').
' AND i.itemid=gi.itemid '.
' AND i.status='.ITEM_STATUS_ACTIVE.
- (!empty($denied_graphs)?' AND g.graphid NOT IN ('.implode(',',$denied_graphs).')':'');
+ (!empty($denied_graphs)?' AND g.graphid NOT IN ('.implode(',',$denied_graphs).')':'');
$db_graphs = DBselect($sql);
while($graph = DBfetch($db_graphs)){
@@ -632,21 +632,20 @@
while($db_host = DBfetch($db_hosts)){
$host_list[] = '"'.$db_host['host'].'"';
}
-
+
+ $result = true;
/* firstly remove child graphs */
$chd_graphs = get_graphs_by_templateid($graphid);
- while($chd_graph = DBfetch($chd_graphs))
- { /* recursion */
- if ( !($result = delete_graph($chd_graph['graphid'])) )
- return $result;
+ while($chd_graph = DBfetch($chd_graphs)){ /* recursion */
+ $result &= delete_graph($chd_graph['graphid']);
}
- DBexecute('delete from screens_items where resourceid='.$graphid.' and resourcetype='.SCREEN_RESOURCE_GRAPH);
+ $result &= DBexecute('DELETE FROM screens_items WHERE resourceid='.$graphid.' AND resourcetype='.SCREEN_RESOURCE_GRAPH);
/* delete graph */
- $result = DBexecute('DELETE FROM graphs_items WHERE graphid='.$graphid);
+ $result &= DBexecute('DELETE FROM graphs_items WHERE graphid='.$graphid);
$result &= DBexecute('DELETE FROM graphs WHERE graphid='.$graphid);
- $result &= rm4favorites('web.favorite.graphids',$graphid,ZBX_FAVORITES_ALL,'graphid');
+ $result &= DBexecute('DELETE FROM profiles WHERE idx="web.favorite.graphids" AND resource="graphid" AND value='.$graphid);
if($result){
info('Graph "'.$graph['name'].'" deleted from hosts '.implode(',',$host_list));
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index 468b3b3e..920adde5 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -423,10 +423,7 @@ require_once "include/items.inc.php";
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function delete_host($hostid, $unlink_mode = false)
- {
- global $DB_TYPE;
-
+ function delete_host($hostid, $unlink_mode = false){
$ret = false;
// unlink child hosts
@@ -438,8 +435,7 @@ require_once "include/items.inc.php";
// delete items -> triggers -> graphs
$db_items = get_items_by_hostid($hostid);
- while($db_item = DBfetch($db_items))
- {
+ while($db_item = DBfetch($db_items)){
delete_item($db_item["itemid"]);
}
@@ -735,7 +731,7 @@ require_once "include/items.inc.php";
$with_node = '';
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,null,null,get_current_nodeid(!$only_current_node));
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,null,get_current_nodeid(!$only_current_node));
if(is_null($a_groupid)){
$groupid = 0;
diff --git a/frontends/php/include/images.inc.php b/frontends/php/include/images.inc.php
index 96286bc9..92abc817 100644
--- a/frontends/php/include/images.inc.php
+++ b/frontends/php/include/images.inc.php
@@ -22,26 +22,26 @@
function get_image_by_imageid($imageid){
/*global $DB;
- $st = sqlite3_query($DB, 'select * from images where imageid='.$imageid);
+ $st = sqlite3_query($DB['DB'], 'select * from images where imageid='.$imageid);
info(implode(',',sqlite3_fetch_array($st)));
info(sqlite3_column_type($st,3));
info(SQLITE3_INTEGER.','.SQLITE3_FLOAT.','.SQLITE3_TEXT.','.SQLITE3_BLOB.','.SQLITE3_NULL);
return 0;*/
- global $DB_TYPE;
+ global $DB;
$result = DBselect('select * from images where imageid='.$imageid);
$row = DBfetch($result);
if($row){
- if($DB_TYPE == "ORACLE"){
+ if($DB['TYPE'] == "ORACLE"){
if(!isset($row['image']))
return 0;
$row['image'] = $row['image']->load();
}
- else if($DB_TYPE == "POSTGRESQL"){
+ else if($DB['TYPE'] == "POSTGRESQL"){
$row['image'] = pg_unescape_bytea($row['image']);
}
- else if($DB_TYPE == "SQLITE3"){
+ else if($DB['TYPE'] == "SQLITE3"){
$row['image'] = pack('H*', $row['image']);
}
return $row;
@@ -51,31 +51,25 @@
}
}
- function add_image($name,$imagetype,$file)
- {
- if(!is_null($file))
- {
- if($file["error"] != 0 || $file["size"]==0)
- {
+ function add_image($name,$imagetype,$file){
+ if(!is_null($file)){
+ if($file["error"] != 0 || $file["size"]==0){
error("Incorrect Image");
}
- elseif($file["size"]<1024*1024)
- {
- global $DB_TYPE;
+ else if($file["size"]<1024*1024){
global $DB;
$imageid = get_dbid("images","imageid");
$image = fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
- if($DB_TYPE == "ORACLE")
- {
- $lobimage = OCINewDescriptor($DB, OCI_D_LOB);
+ if($DB['TYPE'] == "ORACLE"){
+ DBstart();
+ $lobimage = OCINewDescriptor($DB['DB'], OCI_D_LOB);
- $stid = OCIParse($DB, "insert into images (imageid,name,imagetype,image)".
+ $stid = OCIParse($DB['DB'], "insert into images (imageid,name,imagetype,image)".
" values ($imageid,".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())".
" return image into :image");
- if(!$stid)
- {
+ if(!$stid){
$e = ocierror($stid);
error("Parse SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
return false;
@@ -83,20 +77,16 @@
OCIBindByName($stid, ':image', $lobimage, -1, OCI_B_BLOB);
- if(!OCIExecute($stid, OCI_DEFAULT))
- {
+ if(!OCIExecute($stid, OCI_DEFAULT)){
$e = ocierror($stid);
error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
return false;
}
-
- if ($lobimage->save($image)) {
- OCICommit($DB);
- }
- else {
- OCIRollback($DB);
+
+
+ if(DBend($lobimage->save($image))){
error("Couldn't save image!\n");
- return false;
+ return false;
}
$lobimage->free();
@@ -104,102 +94,79 @@
return $stid;
}
- else if($DB_TYPE == "POSTGRESQL")
- {
+ else if($DB['TYPE'] == "POSTGRESQL"){
$image = pg_escape_bytea($image);
}
- else if($DB_TYPE == "SQLITE3")
- {
+ else if($DB['TYPE'] == "SQLITE3"){
$image = bin2hex($image);
}
return DBexecute("insert into images (imageid,name,imagetype,image)".
" values ($imageid,".zbx_dbstr($name).",".$imagetype.",".zbx_dbstr($image).")");
}
- else
- {
+ else{
error("Image size must be less than 1Mb");
}
}
- else
- {
+ else{
error("Select image to download");
}
return false;
}
- function update_image($imageid,$name,$imagetype,$file)
- {
+ function update_image($imageid,$name,$imagetype,$file){
if(is_null($file))
{ /* only update parameters */
return DBexecute("update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
" where imageid=$imageid");
}
- else
- {
- global $DB_TYPE;
+ else{
global $DB;
- if($file["error"] != 0 || $file["size"]==0)
- {
+ if($file["error"] != 0 || $file["size"]==0){
error("Incorrect Image");
return FALSE;
}
- if($file["size"]<1024*1024)
- {
+ if($file["size"]<1024*1024){
$image=fread(fopen($file["tmp_name"],"r"),filesize($file["tmp_name"]));
- if($DB_TYPE == "ORACLE")
- {
+ if($DB['TYPE'] == "ORACLE"){
- $result = DBexecute("update images set name=".zbx_dbstr($name).
- ",imagetype=".zbx_dbstr($imagetype).
- " where imageid=$imageid");
+ $result = DBexecute('UPDATE images SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).
+ ' WHERE imageid='.$imageid);
if(!$result) return $result;
-
- $stid = OCIParse($DB, "select image from images where imageid=".$imageid." for update");
-
- $result = OCIExecute($stid, OCI_DEFAULT);
- if(!$result){
- $e = ocierror($stid);
- error("Execute SQL error [".$e["message"]."] in [".$e["sqltext"]."]");
- OCIRollback($DB);
- return false;
+
+ DBstart();
+ if(!$stid = DBselect('SELECT image FROM images WHERE imageid='.$imageid.' FOR UPDATE')){
+ DBend();
+ return false;
}
$row = DBfetch($stid);
-
$lobimage = $row['image'];
- if (!$lobimage->save($image)) {
- OCIRollback($DB);
- } else {
- OCICommit($DB);
- }
-
+ DBend($lobimage->save($image));
$lobimage->free();
- return $stid;
+ return $stid;
}
- else if($DB_TYPE == "POSTGRESQL")
- {
+ else if($DB['TYPE'] == "POSTGRESQL"){
$image = pg_escape_bytea($image);
- $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
- ",image='".$image."' where imageid=$imageid";
- return DBexecute($sql);
+ $sql='UPDATE images SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).",image='".$image."'".
+ ' WHERE imageid='.$imageid;
+ return DBexecute($sql);
}
- else if($DB_TYPE == "SQLITE3")
- {
+ else if($DB['TYPE'] == "SQLITE3"){
$image = bin2hex($image);
}
- $sql="update images set name=".zbx_dbstr($name).",imagetype=".zbx_dbstr($imagetype).
- ",image=".zbx_dbstr($image)." where imageid=$imageid";
+ $sql='UPDATE images SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).',image='.zbx_dbstr($image).
+ ' WHERE imageid='.$imageid;
+
return DBexecute($sql);
}
- else
- {
+ else{
error("Image size must be less than 1Mb");
return FALSE;
}
diff --git a/frontends/php/include/import.inc.php b/frontends/php/include/import.inc.php
index 0563cc37..afa58df6 100644
--- a/frontends/php/include/import.inc.php
+++ b/frontends/php/include/import.inc.php
@@ -21,10 +21,8 @@
include_once "include/hosts.inc.php";
?>
<?php
- class CZabbixXMLImport
- {
- function CZabbixXMLImport()
- {
+ class CZabbixXMLImport{
+ function CZabbixXMLImport(){
global $USER_DETAILS;
$this->main_node= null;
@@ -46,33 +44,27 @@
PERM_READ_WRITE, null, PERM_RES_IDS_ARRAY, get_current_nodeid());
}
- function CharacterData($parser, $data)
- {
+ function CharacterData($parser, $data) {
$this->element_data .= html_entity_decode($data);
}
- function StartElement($parser, $name, $attrs)
- {
+ function StartElement($parser, $name, $attrs) {
$this->element_data = '';
- if(!isset($this->root))
- {
+ if(!isset($this->root)){
if($name == XML_TAG_ZABBIX_EXPORT)
if(isset($attrs['version']))
- if($attrs['version'] == '1.0')
- {
+ if($attrs['version'] == '1.0'){
$this->root = true;
return;
}
- else
- {
+ else{
error(S_UNSUPPORTED_VERSION_OF_IMPORTED_DATA);
}
error(S_UNSUPPORTED_FILE_FORMAT);
$this->root = false;
}
- elseif(!$this->root)
- {
+ else if(!$this->root){
return false;
}
@@ -81,8 +73,7 @@
foreach($attrs as $id => $val)
$attrs[$id] = html_entity_decode($val);
- switch($name)
- {
+ switch($name){
case XML_TAG_HOST:
$this->main_node= array($name);
$this->sub_node = null;
@@ -94,8 +85,7 @@
' where host='.zbx_dbstr($data['name']).
' and '.DBin_node('hostid',get_current_nodeid(false)))))
{ /* exist */
- if($this->host['exist']==1) /* skip */
- {
+ if($this->host['exist']==1) /* skip */{
$data['skip'] = true;
info('Host ['.$data['name'].'] skipped - user rule');
break; // case
@@ -108,16 +98,13 @@
$data['hostid'] = $host_data['hostid'];
$data['templates'] = get_templates_by_hostid($host_data['hostid']);
}
- else
- { /* missed */
- if($this->host['missed']==1) /* skip */
- {
+ else{ /* missed */
+ if($this->host['missed']==1){ /* skip */
$data['skip'] = true;
info('Host ['.$data['name'].'] skipped - user rule');
break; // case
}
-// if( count($this->available_nodes) > 0 ){
if(!uint_in_array(get_current_nodeid(),$this->available_nodes)){
error('Host ['.$data['name'].'] skipped - Access deny.');
break; // case
@@ -173,18 +160,15 @@
}
}
- function EndElement($parser, $name)
- {
- if(!$this->root)
- {
+ function EndElement($parser, $name) {
+ if(!$this->root){
return false;
}
global $USER_DETAILS;
$data = &$this->data[$name];
- switch($name)
- {
+ switch($name){
case XML_TAG_HOST:
if($data['skip'] || !isset($data['hostid']) || !$data['hostid'])
break; // case
@@ -242,8 +226,7 @@
break; // case
}
- if(!uint_in_array($group["groupid"], $this->available_groups))
- {
+ if(!uint_in_array($group["groupid"], $this->available_groups)){
error('Group ['.$this->element_data.'] skipped - Access deny.');
break; // case
}
@@ -265,8 +248,7 @@
{
$applicationid = add_application($this->element_data, $this->data[XML_TAG_HOST]['hostid']);
}
- else
- {
+ else{
$applicationid = $application['applicationid'];
}
@@ -280,14 +262,12 @@
if(!($template = DBfetch(DBselect('SELECT DISTINCT host, hostid '.
' FROM hosts'.
' WHERE '.DBin_node('hostid').
- ' AND host='.zbx_dbstr($this->element_data)))))
- {
+ ' AND host='.zbx_dbstr($this->element_data))))){
error('Missed template ['.$this->element_data.']');
break; // case
}
- if(!uint_in_array($template["hostid"], $this->available_hosts))
- {
+ if(!uint_in_array($template["hostid"], $this->available_hosts)){
error('Template ['.$this->element_data.'] skipped - Access deny.');
break; // case
}
@@ -295,10 +275,8 @@
$this->data[XML_TAG_HOST]['templates'][$template["hostid"]] = $template['host'];
break; // case
case XML_TAG_ITEM:
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']){
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']){
info('Item ['.$data['description'].'] skipped - user rule for host');
break; // case
}
@@ -331,16 +309,14 @@
if(!isset($data['params'])) $data['params'] = '';
if(!isset($data['applications'])) $data['applications'] = array();
- if(!empty($data['valuemap']))
- {
+ if(!empty($data['valuemap'])){
if( $valuemap = DBfetch(DBselect('select valuemapid from valuemaps '.
' where '.DBin_node('valuemapid', get_current_nodeid(false)).
' and name='.zbx_dbstr($data['valuemap']))) )
{
$data['valuemapid'] = $valuemap['valuemapid'];
}
- else
- {
+ else{
$data['valuemapid'] = add_valuemap($data['valuemap'],array());
}
}
@@ -350,13 +326,12 @@
' and hostid='.$this->data[XML_TAG_HOST]['hostid'].' and '.
DBin_node('itemid', get_current_nodeid(false)))))
{ /* exist */
- if($this->item['exist']==1) /* skip */
- {
+ if($this->item['exist']==1) /* skip */{
info('Item ['.$data['description'].'] skipped - user rule');
break;
}
- if( !isset($data['valuemapid']) )
+ if(!isset($data['valuemapid']))
$data['valuemapid'] = $item['valuemapid'];
update_item(
@@ -392,10 +367,8 @@
)),
$item['templateid']);
}
- else
- { /* missed */
- if($this->item['missed']==1) /* skip */
- {
+ else{ /* missed */
+ if($this->item['missed']==1) /* skip */{
info('Item ['.$data['description'].'] skipped - user rule');
break; // case
}
@@ -442,21 +415,17 @@
if(!isset($data['comments'])) $data['comments'] = '';
if(!isset($data['url'])) $data['url'] = '';
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']){
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']){
info('Trigger ['.$data['description'].'] skipped - user rule for host');
break; // case
}
- if(zbx_strstr($data['expression'],'{HOSTNAME}'))
- {
+ if(zbx_strstr($data['expression'],'{HOSTNAME}')){
error('Trigger ['.$data['description'].'] skipped - missed host');
break; // case
}
}
- else
- {
+ else{
$data['expression'] = str_replace('{HOSTNAME}',
$this->data[XML_TAG_HOST]['name'],
$data['expression']);
@@ -494,14 +463,12 @@
break; // case
}
- else /* missed */
- {
+ else{ /* missed */
// continue [add_trigger]
}
}
- if($this->trigger['missed']==1) /* skip */
- {
+ if($this->trigger['missed']==1) /* skip */{
info('Trigger ['.$data['description'].'] skipped - user rule');
break; // case
}
@@ -517,8 +484,7 @@
break; // case
case XML_TAG_GRAPH:
- if(isset($data['error']))
- {
+ if(isset($data['error'])){
error('Graph ['.$data['name'].'] skipped - error occured');
break; // case
}
@@ -533,31 +499,27 @@
if(!isset($data['show_3d'])) $data['show_3d'] = 0;
if(!isset($data['items'])) $data['items'] = array();
- if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid'])
- {
- if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip'])
- {
+ if(!isset($this->data[XML_TAG_HOST]['hostid']) || !$this->data[XML_TAG_HOST]['hostid']){
+ if(isset($this->data[XML_TAG_HOST]['skip']) && $this->data[XML_TAG_HOST]['skip']){
info('Graph ['.$data['name'].'] skipped - user rule for host');
break; // case
}
foreach($data['items'] as $id)
- if(zbx_strstr($data['name'],'{HOSTNAME}'))
- {
+ if(zbx_strstr($data['name'],'{HOSTNAME}')){
error('Graph ['.$data['name'].'] skipped - missed host');
break; // case
}
}
- else
- {
+ else{
if($graph = DBfetch(DBselect('select distinct g.graphid, g.templateid'.
' from graphs g, graphs_items gi, items i'.
- ' where g.graphid=gi.graphid and gi.itemid=i.itemid'.
- ' and g.name='.zbx_dbstr($data['name']).
- ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'])))
+ ' where g.graphid=gi.graphid '.
+ ' and gi.itemid=i.itemid'.
+ ' and g.name='.zbx_dbstr($data['name']).
+ ' and i.hostid='.$this->data[XML_TAG_HOST]['hostid'])))
{ /* exist */
- if($this->graph['exist']==1) /* skip */
- {
+ if($this->graph['exist']==1){ /* skip */
info('Graph ['.$data['name'].'] skipped - user rule');
break; // case
}
@@ -580,16 +542,13 @@
$graph['templateid']);
DBexecute('delete from graphs_items where graphid='.$data['graphid']);
}
- else
- { /* missed */
+ else{ /* missed */
// continue [add_group]
}
}
- if(!isset($data['graphid']))
- {
- if($this->graph['missed']==1) /* skip */
- {
+ if(!isset($data['graphid'])){
+ if($this->graph['missed']==1){ /* skip */
info('Graph ['.$data['name'].'] skipped - user rule');
break; // case
}
@@ -609,8 +568,7 @@
);
}
- foreach($data['items'] as $item)
- {
+ foreach($data['items'] as $item){
add_item_to_graph(
$data['graphid'],
$item['itemid'],
@@ -628,8 +586,7 @@
break; // case
$data['key'] = explode(':', $data['item']);
- if(count($data['key']) < 2)
- {
+ if(count($data['key']) < 2){
$this->data[XML_TAG_GRAPH]['error'] = true;
error('Incorrect element for graph ['.$data['name'].']');
break; // case
@@ -638,8 +595,7 @@
$data['host'] = array_shift($data['key']);
$data['key'] = implode(':', $data['key']);
- if(isset($this->data[XML_TAG_HOST]['name']))
- {
+ if(isset($this->data[XML_TAG_HOST]['name'])){
$data['host'] = str_replace('{HOSTNAME}',$this->data[XML_TAG_HOST]['name'],$data['host']);
}
@@ -670,8 +626,7 @@
case XML_TAG_SCREEN_ELEMENT:
break; // case*/
default:
- if(isset($this->sub_node) && isset($this->main_node))
- {
+ if(isset($this->sub_node) && isset($this->main_node)){
$main_node = array_pop($this->main_node);
$this->data[$main_node][$this->sub_node] = $this->element_data;
array_push($this->main_node, $main_node);
@@ -685,8 +640,7 @@
array_pop($this->main_node);
}
- function Parse($file)
- {
+ function Parse($file){
$this->main_node = null;
$this->sub_node = null;
$this->data = null;
@@ -699,19 +653,15 @@
xml_set_character_data_handler($xml_parser, array(&$this, "characterData"));
- if (!($fp = fopen($file, "r")))
- {
+ if(!$fp = fopen($file, "r")){
error("could not open XML input");
xml_parser_free($xml_parser);
return false;
}
- else
- {
- while ($data = fread($fp, 4096))
- {
- if (!xml_parse($xml_parser, $data, feof($fp)))
- {
- error( sprintf("XML error: %s at line %d",
+ else{
+ while($data = fread($fp, 4096)){
+ if(!xml_parse($xml_parser, $data, feof($fp))){
+ error(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser))
);
@@ -731,8 +681,7 @@
return true;
}
- function SetRules($host, $template, $item, $trigger, $graph)
- {
+ function SetRules($host, $template, $item, $trigger, $graph){
$this->host = $host;
$this->template = $template;
$this->item = $item;
@@ -741,24 +690,18 @@
}
}
- class CZabbixHostImport
- {
- function CZabbixHostImport()
- {
+ class CZabbixHostImport{
+ function CZabbixHostImport(){
}
- function Parse($file)
- {
- if (!($fp = fopen($file, "r")))
- {
+ function Parse($file){
+ if (!($fp = fopen($file, "r"))){
error("could not open XML input");
xml_parser_free($xml_parser);
return false;
}
- else
- {
- while(!feof($fp))
- {
+ else{
+ while(!feof($fp)){
$len = fgets($fp);
echo $len.'<br/>'."\n";
}
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 45233964..4dd3197d 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -142,29 +142,26 @@
}
# Delete Item definition from selected group
-
- function delete_item_from_group($groupid,$itemid)
- {
- if(!isset($itemid))
- {
+ function delete_item_from_group($groupid,$itemid){
+ if(!isset($itemid)){
return 0;
}
$item=get_item_by_itemid($itemid);
- if(!$item)
- {
+ if(!$item){
return 0;
}
- $sql="select i.itemid from hosts_groups hg,items i".
- " where hg.groupid=$groupid and i.key_=".zbx_dbstr($item["key_"]).
- " and hg.hostid=i.hostid";
+ $sql='SELECT i.itemid '.
+ ' FROM hosts_groups hg,items i'.
+ ' WHERE hg.groupid='.$groupid.
+ ' AND i.key_='.zbx_dbstr($item["key_"]).
+ ' AND hg.hostid=i.hostid';
$result=DBexecute($sql);
- while($row=DBfetch($result))
- {
+ while($row=DBfetch($result)){
delete_item($row["itemid"]);
}
- return 1;
+ return 1;
}
# Add Item definition to selected group
@@ -776,15 +773,13 @@
* Comments: !!! Don't forget sync code with C !!! *
* *
******************************************************************************/
- function delete_item($itemid)
- {
+ function delete_item($itemid){
$item = get_item_by_itemid($itemid);
$host = get_host_by_itemid($itemid);
// first delete child items
$db_items = DBselect("select itemid from items where templateid=$itemid");
- while($db_item = DBfetch($db_items))
- {// recursion
+ while($db_item = DBfetch($db_items)){// recursion
$result = delete_item($db_item["itemid"]);
if(!$result) return $result;
}
@@ -802,24 +797,21 @@
$result = delete_history_by_itemid($itemid, 1 /* use housekeeper */);
if(!$result) return $result;
- DBexecute('delete from screens_items where resourceid='.$itemid.' and resourcetype in ('.
+ $result &= DBexecute('delete from screens_items where resourceid='.$itemid.' and resourcetype in ('.
(implode(',',array(
SCREEN_RESOURCE_SIMPLE_GRAPH,
SCREEN_RESOURCE_PLAIN_TEXT)
)
).')');
- $result = DBexecute("delete from items_applications where itemid=$itemid");
- if(!$result) return $result;
-
- $result = DBexecute("delete from items where itemid=$itemid");
- if(!$result) return $result;
+ $result &= DBexecute('delete from items_applications where itemid='.$itemid);
+ $result &= DBexecute('delete from items where itemid='.$itemid);
+ $result &= DBexecute('DELETE FROM profiles WHERE idx="web.favorite.graphids" AND resource="itemid" AND value='.$itemid);
- $result = rm4favorites('web.favorite.graphids',$itemid,ZBX_FAVORITES_ALL,'itemid');
if($result){
info("Item '".$host["host"].":".$item["key_"]."' deleted");
}
- return $result;
+ return $result;
}
/*
@@ -889,7 +881,7 @@
function get_items_data_overview($groupid,$view_style=null)
{
global $USER_DETAILS;
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid());
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY);
if(is_null($view_style)) $view_style = get_profile('web.overview.view.style',STYLE_TOP);
diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php
index 303bced6..40329cb8 100644
--- a/frontends/php/include/maps.inc.php
+++ b/frontends/php/include/maps.inc.php
@@ -113,7 +113,7 @@
break;
case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
- $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY, null);
+ $available_groups = get_accessible_groups_by_user($USER_DETAILS,PERM_READ_ONLY);
$sql = 'SELECT g.groupid '.
' FROM groups g '.
@@ -192,16 +192,12 @@
while($rows = DBfetch($res)){
$result&=delete_link($rows['linkid']);
}
-// $result = DBexecute("delete FROM sysmaps_links WHERE sysmapid=$sysmapid");
-// if(!$result) return $result;
- $result = DBexecute("delete FROM sysmaps_elements WHERE sysmapid=$sysmapid");
- if(!$result) return $result;
+ $result = DBexecute('delete FROM sysmaps_elements WHERE sysmapid='.$sysmapid);
+ $result &= DBexecute('DELETE FROM profiles WHERE idx="web.favorite.sysmapids" AND resource="sysmapid" AND value='.$sysmapid);
+ $result &= DBexecute('DELETE FROM sysmaps WHERE sysmapid='.$sysmapid);
- $result = rm4favorites('web.favorite.sysmapids',$sysmapd,ZBX_FAVORITES_ALL,'sysmapid');
- if(!$result) return $result;
-
- return DBexecute("delete FROM sysmaps WHERE sysmapid=$sysmapid");
+ return $result;
}
// LINKS
diff --git a/frontends/php/include/page_header.php b/frontends/php/include/page_header.php
index 6efb46cb..2746bb9e 100644
--- a/frontends/php/include/page_header.php
+++ b/frontends/php/include/page_header.php
@@ -388,7 +388,7 @@ COpt::profiling_start("page");
<link rel="stylesheet" href="css.css" />
<?php
global $DB;
- if(!is_null($DB)){
+ if(!is_null($DB['DB'])){
$css = false;
$config=select_config();
if(isset($config['default_theme']) && file_exists('styles/'.$config['default_theme'])){
@@ -567,7 +567,8 @@ COpt::compare_files_with_menu($ZBX_MENU);
$table->AddRow($tr);
$table->Show();
- } elseif(($page["type"] == PAGE_TYPE_HTML) && !defined('ZBX_PAGE_NO_MENU')) {
+ }
+ else if(($page["type"] == PAGE_TYPE_HTML) && !defined('ZBX_PAGE_NO_MENU')) {
echo SBR;
}
//------------------------------------ </HISTORY> ---------------------------------------
diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php
index 4c15b0f5..9576ba2f 100644
--- a/frontends/php/include/perm.inc.php
+++ b/frontends/php/include/perm.inc.php
@@ -184,26 +184,25 @@
return $perm_mode;
}
- function get_accessible_hosts_by_user(&$user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null,$cache=1){
- global $DB_TYPE;
+ function get_accessible_hosts_by_user(&$user_data,$perm,$perm_res=null,$nodeid=null,$cache=1){
+ global $DB;
static $available_hosts;
if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE;
if($perm == PERM_READ_LIST) $perm = PERM_READ_ONLY;
- if(is_null($perm_mode)) $perm_mode = PERM_MODE_GE;
-
$result = array();
$userid =& $user_data['userid'];
$user_type =& $user_data['type'];
if(!isset($userid)) fatal_error('Incorrect user data in "get_accessible_hosts_by_user"');
+ if(is_null($nodeid)) $nodeid = get_current_nodeid();
+
+ $nodeid_str =(is_array($nodeid))?md5(implode('',$nodeid)):strval($nodeid);
- $nodeid_str =(is_array($nodeid))?implode('',$nodeid):strval($nodeid);
-
- if($cache && isset($available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str])){
- return $available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str];
+ if($cache && isset($available_hosts[$userid][$perm][$perm_res][$nodeid_str])){
+ return $available_hosts[$userid][$perm][$perm_res][$nodeid_str];
}
switch($perm_res){
@@ -215,24 +214,22 @@
break;
}
-COpt::counter_up('perm_host['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
+COpt::counter_up('perm_host['.$userid.','.$perm.','.$perm_res.','.$nodeid.']');
COpt::counter_up('perm');
$where = array();
- if ( !is_null($nodeid) ) array_push($where, DBin_node('h.hostid', $nodeid));
-
-// if(is_array($hostid)) array_push($where, ' h.hostid in ('.implode(',', $hostid).') ');
-// else if(!empty($hostid)) array_push($where, ' h.hostid in ('.$hostid.') ');
-
+ if(!is_null($nodeid))
+ array_push($where, DBin_node('h.hostid', $nodeid));
+
if(count($where))
- $where = ' where '.implode(' and ',$where);
+ $where = ' WHERE '.implode(' AND ',$where);
else
$where = '';
- $sortorder = (isset($DB_TYPE) && (($DB_TYPE == 'MYSQL') || ($DB_TYPE == 'SQLITE3')))?' DESC ':'';
+// $sortorder = (isset($DB['TYPE']) && (($DB['TYPE'] == 'MYSQL') || ($DB['TYPE'] == 'SQLITE3')))?' DESC ':'';
- $sql = 'SELECT DISTINCT n.nodeid,n.name as node_name,h.hostid,h.host, min(r.permission) as permission,ug.userid '.
+ $sql = 'SELECT DISTINCT n.nodeid, n.name as node_name, h.hostid, h.host, min(r.permission) as permission, ug.userid '.
' FROM hosts h '.
' LEFT JOIN hosts_groups hg ON hg.hostid=h.hostid '.
' LEFT JOIN groups g ON g.groupid=hg.groupid '.
@@ -241,7 +238,7 @@ COpt::counter_up('perm');
' LEFT JOIN nodes n ON '.DBid2nodeid('h.hostid').'=n.nodeid '.
$where.
' GROUP BY h.hostid,n.nodeid,n.name,h.host,ug.userid '.
- ' ORDER BY n.name,n.nodeid, h.host, permission '.$sortorder.', userid '.$sortorder;
+ ' ORDER BY n.name,n.nodeid, h.host, permission, ug.userid ';
$db_hosts = DBselect($sql);
@@ -264,9 +261,8 @@ COpt::counter_up('perm');
}
$processed[$host_data['hostid']] = true;
-
- if(eval('return ('.$host_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
- continue;
+ if($host_data['permission'] < $perm) continue;
+// if(eval('return ('.$host_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;')) continue;
$result[$host_data['hostid']] = eval('return '.$resdata.';');
}
@@ -280,18 +276,18 @@ COpt::counter_up('perm');
$result = implode(',',$result);
}
- $available_hosts[$userid][$perm][$perm_mode][$perm_res][$nodeid_str] = $result;
+ $available_hosts[$userid][$perm][$perm_res][$nodeid_str] = $result;
return $result;
}
- function get_accessible_groups_by_user($user_data,$perm,$perm_mode=null,$perm_res=null,$nodeid=null){
+ function get_accessible_groups_by_user($user_data,$perm,$perm_res=null,$nodeid=null){
global $ZBX_LOCALNODEID;
- if(is_null($perm_mode)) $perm_mode = PERM_MODE_GE;
+ if(is_null($nodeid)) $nodeid = get_current_nodeid();
if(is_null($perm_res)) $perm_res = PERM_RES_STRING_LINE;
$result = array();
-
+
$userid =& $user_data['userid'];
if(!isset($userid)) fatal_error('Incorrect user data in "get_accessible_groups_by_user"');
$user_type =& $user_data['type'];
@@ -305,15 +301,15 @@ COpt::counter_up('perm');
break;
}
-COpt::counter_up('perm_group['.$userid.','.$perm.','.$perm_mode.','.$perm_res.','.$nodeid.']');
+COpt::counter_up('perm_group['.$userid.','.$perm.','.$perm_res.','.$nodeid.']');
COpt::counter_up('perm');
$where = array();
- if ( !is_null($nodeid) ) array_push($where, DBin_node('hg.groupid', $nodeid));
+ if(!is_null($nodeid))
+ array_push($where, DBin_node('hg.groupid', $nodeid));
- if(count($where)) $where = ' where '.implode(' and ',$where);
- else $where = '';
+ $where = count($where)?' where '.implode(' and ',$where):'';
/* if no rights defined used node rights */
$db_groups = DBselect('SELECT n.nodeid as nodeid,n.name as node_name,hg.groupid,hg.name,min(r.permission) as permission,g.userid'.
@@ -323,16 +319,15 @@ COpt::counter_up('perm');
' LEFT JOIN nodes n ON '.DBid2nodeid('hg.groupid').'=n.nodeid '.
$where.
' GROUP BY n.nodeid, n.name, hg.groupid, hg.name, g.userid, g.userid '.
- ' ORDER BY n.name, hg.name, permission desc');
+ ' ORDER BY n.name, hg.name, permission ');
$processed = array();
while($group_data = DBfetch($db_groups)){
- if(is_null($group_data['nodeid'])) $group_data['nodeid'] = id2nodeid($group_data['groupid']);
+ if(empty($group_data['nodeid'])) $group_data['nodeid'] = id2nodeid($group_data['groupid']);
/* deny if no rights defined */
- if( is_null($group_data['permission']) || is_null($group_data['userid']) ){
- if(isset($processed[$group_data['groupid']]))
- continue;
+ if( empty($group_data['permission']) || empty($group_data['userid']) ){
+ if(isset($processed[$group_data['groupid']])) continue;
if(!isset($nodes)){
$nodes = get_accessible_nodes_by_user($user_data,
@@ -345,11 +340,9 @@ COpt::counter_up('perm');
$group_data['permission'] = $nodes[$group_data['nodeid']]['permission'];
}
-// $processed[$group_data['permission']] = true;
$processed[$group_data['groupid']] = true;
-
- if(eval('return ('.$group_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;'))
- continue;
+ if($group_data['permission'] < $perm) continue;
+// if(eval('return ('.$group_data["permission"].' '.perm_mode2comparator($perm_mode).' '.$perm.')? 0 : 1;')) continue;
$result[$group_data['groupid']] = eval('return '.$resdata.';');
}
@@ -430,7 +423,7 @@ COpt::counter_up('perm');
$processed_nodeids[$node_data["nodeid"]] = $node_data["nodeid"];
/* deny if no rights defined (for local node read/write)*/
- if(is_null($node_data['permission']) || is_null($node_data['userid'])){
+ if(empty($node_data['permission']) || empty($node_data['userid'])){
if($user_type == USER_TYPE_SUPER_ADMIN)
$node_data['permission'] = PERM_READ_WRITE;
else
@@ -440,8 +433,7 @@ COpt::counter_up('perm');
/* special processing for PERM_READ_LIST*/
if(PERM_DENY == $node_data['permission'] && PERM_READ_LIST == $perm){
- $groups = get_accessible_groups_by_user($user_data,
- $perm, PERM_MODE_GE,PERM_RES_DATA_ARRAY,$node_data['nodeid']);
+ $groups = get_accessible_groups_by_user($user_data,$perm,PERM_RES_DATA_ARRAY,$node_data['nodeid']);
if(count($groups) == 0) continue;
}
else{
diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php
index 3289b71b..885b6361 100644
--- a/frontends/php/include/profiles.inc.php
+++ b/frontends/php/include/profiles.inc.php
@@ -22,13 +22,19 @@
/********** USER PROFILE ***********/
//---------- GET USER VALUE -------------
-function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN){
+function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN,$resource=null){
global $USER_DETAILS;
$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).' ORDER BY profileid ASC');
+ $sql = 'SELECT value, valuetype '.
+ ' FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource)).
+ ' ORDER BY profileid ASC';
+ $db_profiles = DBselect($sql);
if($profile=DBfetch($db_profiles)){
@@ -41,15 +47,43 @@ function get_profile($idx,$default_value=null,$type=PROFILE_TYPE_UNKNOWN){
}
}
else{
- switch($type){
- case PROFILE_TYPE_INT:
- $result = intval($profile["value"]);
- break;
- case PROFILE_TYPE_STR:
- default:
- $result = strval($profile["value"]);
+ $result = strval($profile["value"]);
+ }
+ }
+ }
+
+return $result;
+}
+
+
+// multi value
+function get_multi_profile($idx,$default_value=array(),$type=PROFILE_TYPE_UNKNOWN,$resource=null){
+ global $USER_DETAILS;
+
+ $result = $default_value;
+
+ if($USER_DETAILS["alias"]!=ZBX_GUEST_USER){
+ $sql = 'SELECT value,value2,resource,valuetype '.
+ ' FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource)).
+ ' ORDER BY profileid ASC';
+ $db_profiles = DBselect($sql);
+
+ if($profile=DBfetch($db_profiles)){
+
+ if(PROFILE_TYPE_UNKNOWN == $type) $type = $profile["valuetype"];
+
+ if(PROFILE_TYPE_MULTI_ARRAY == $type){
+ $result[] = $profile;
+ while($profile=DBfetch($db_profiles)){
+ $result[] = $profile;
}
}
+ else{
+ $result = $profile;
+ }
}
}
@@ -57,7 +91,7 @@ return $result;
}
//----------- ADD/EDIT USERPROFILE -------------
-function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
+function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$resource=null){
global $USER_DETAILS;
if($USER_DETAILS["alias"]==ZBX_GUEST_USER){
@@ -65,49 +99,140 @@ function update_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
}
if($type==PROFILE_TYPE_UNKNOWN && is_array($value)) $type = PROFILE_TYPE_ARRAY;
- if($type==PROFILE_TYPE_ARRAY && !is_array($value)) $value = array($value);
+ if(($type==PROFILE_TYPE_ARRAY) && !is_array($value)) $value = array($value);
+
+ DBstart();
if(PROFILE_TYPE_ARRAY == $type){
- DBstart();
- $sql='DELETE FROM profiles WHERE userid='.$USER_DETAILS["userid"].' and idx='.zbx_dbstr($idx);
+
+ $sql='DELETE FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx);
DBExecute($sql);
-
- $result = insert_profile($idx,$value,$type);
- DBend($result);
+
+ foreach($value as $id => $val){
+ insert_profile($idx,$val,$type,$resource);
+ }
}
else{
- $row = DBfetch(DBselect('SELECT value FROM profiles WHERE userid='.$USER_DETAILS["userid"].' AND idx='.zbx_dbstr($idx)));
+ $sql = 'SELECT profileid '.
+ ' FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource));
+
+ $row = DBfetch(DBselect($sql));
if(!$row){
- insert_profile($idx,$value,$type);
+ insert_profile($idx,$value,$type,$resource);
}
else{
$sql='UPDATE profiles SET value='.zbx_dbstr($value).',valuetype='.$type.
' WHERE userid='.$USER_DETAILS["userid"].
- ' AND idx='.zbx_dbstr($idx);
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource));
DBexecute($sql);
}
}
-return true;
+ $result = DBend();
+
+return $result;
}
-// Author: Aly
-function insert_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN){
+function update_multi_profile($idx,$value,$type=PROFILE_TYPE_UNKNOWN,$resource=null){
global $USER_DETAILS;
+
+ if($USER_DETAILS["alias"]==ZBX_GUEST_USER){
+ return false;
+ }
+
+ if(empty($value)) $type = PROFILE_TYPE_MULTI_ARRAY;
+ if(!is_array($value)) $value = array('value' => $value);
- $result = true;
- if(is_array($value)){
- foreach($value as $key => $val){
- $result&=insert_profile($idx,$val,$type); // recursion!!!
+ if($type==PROFILE_TYPE_UNKNOWN && isset($value['value'])) $type = PROFILE_TYPE_MULTI;
+ if($type==PROFILE_TYPE_UNKNOWN && isset($value[0]['value'])) $type = PROFILE_TYPE_MULTI_ARRAY;
+
+ if(($type==PROFILE_TYPE_MULTI_ARRAY) && isset($value['value'])) $value = array($value);
+
+ DBstart();
+
+ if(PROFILE_TYPE_MULTI_ARRAY == $type){
+ $sql='DELETE FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx);
+ DBExecute($sql);
+
+ foreach($value as $id => $val){
+ insert_profile($idx,$val,$type,$resource);
}
}
- 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.')';
- $result = DBexecute($sql);
+ else {
+ $sql = 'SELECT profileid '.
+ ' FROM profiles '.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource));
+
+ $row = DBfetch(DBselect($sql));
+
+ if(!$row){
+ insert_profile($idx,$value,$type,$resource);
+ }
+ else{
+ $val1 = isset($value['value'])?$value['value']:'';
+ $val2 = isset($value['value2'])?$value['value2']:'';
+ $rsrc = isset($value['resource'])?$value['resource']:(is_null($resource)?'':resource);
+
+ $sql='UPDATE profiles '.
+ ' SET value='.zbx_dbstr($val1).
+ ',value2='.zbx_dbstr($val2).
+ ',resource='.zbx_dbstr($rsrc).
+ ',valuetype='.$type.
+ ' WHERE userid='.$USER_DETAILS["userid"].
+ ' AND idx='.zbx_dbstr($idx).
+ (is_null($resource)?'':' AND resource='.zbx_dbstr($resource));
+ DBexecute($sql);
+ }
+ }
+
+ $result = DBend();
+
+return $result;
+}
+
+
+// Author: Aly
+function insert_profile($idx,$value,$type,$resource=null){
+ global $USER_DETAILS;
+
+ $profileid = get_dbid('profiles', 'profileid');
+
+ $val1 = $value;
+ $val2 = '';
+ $rsrc = is_null($resource)?'':$resource;
+
+ if(($type == PROFILE_TYPE_MULTI_ARRAY) ||
+ ($type == PROFILE_TYPE_MULTI) ||
+ is_array($value))
+ {
+ $val1 = isset($value['value'])?$value['value']:'';
+ $val2 = isset($value['value2'])?$value['value2']:'';
+ $rsrc = isset($value['resource'])?$value['resource']:$rsrc;
}
+
+ if(empty($val1)) return false;
+
+ $sql='INSERT INTO profiles (profileid,userid,idx,value,value2,resource,valuetype)'.
+ ' VALUES ('.$profileid.','.
+ $USER_DETAILS["userid"].','.
+ zbx_dbstr($idx).','.
+ zbx_dbstr($val1).','.
+ zbx_dbstr($val2).','.
+ zbx_dbstr($rsrc).','.
+ $type.')';
+ $result = DBexecute($sql);
+
return $result;
}
@@ -119,11 +244,11 @@ 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($rows = get_multi_profile('web.history.'.$i,false,PROFILE_TYPE_MULTI)){
if($i>0){
array_push($history,$delimiter);
}
- $url = new CLink($rows[0],$rows[1],'history');
+ $url = new CLink($rows['value'],$rows['value2'],'history');
array_push($history,array(SPACE,$url,SPACE));
}
}
@@ -148,29 +273,32 @@ function add_user_history($page){
}
$url = $page['file'].$url;
+
$curr = 0;
$profile = array();
for($i = 0; $i < ZBX_HISTORY_COUNT; $i++){
- $history = get_profile('web.history.'.$i,false);
- if($history = get_profile('web.history.'.$i,false)){
- if($history[0] != $title){
+ if($history = get_multi_profile('web.history.'.$i,false)){
+ if($history['value'] != $title){
$profile[$curr] = $history;
$curr++;
}
}
}
-
- $history = array($title,$url);
+
+ $history = array('value' => $title,
+ 'value2' => $url);
+
if($curr < ZBX_HISTORY_COUNT){
for($i = 0; $i < $curr; $i++){
- update_profile('web.history.'.$i,$profile[$i],PROFILE_TYPE_ARRAY);
+ update_multi_profile('web.history.'.$i,$profile[$i]);
}
- $result = update_profile('web.history.'.$curr,$history,PROFILE_TYPE_ARRAY);
- } else {
+ $result = update_multi_profile('web.history.'.$curr,$history);
+ }
+ else {
for($i = 1; $i < ZBX_HISTORY_COUNT; $i++){
- update_profile('web.history.'.($i-1),$profile[$i],PROFILE_TYPE_ARRAY);
+ update_multi_profile('web.history.'.($i-1),$profile[$i]);
}
- $result = update_profile('web.history.'.(ZBX_HISTORY_COUNT-1),$history,PROFILE_TYPE_ARRAY);
+ $result = update_multi_profile('web.history.'.(ZBX_HISTORY_COUNT-1),$history);
}
return $result;
@@ -180,68 +308,43 @@ return $result;
/********** USER FAVORITES ***********/
// Author: Aly
function add2favorites($favobj,$favid,$resource=null){
- $favrsrc = $favobj.'_rsrc';
+ $favorites = get_multi_profile($favobj);
- $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);
+ $favorites[] = array('value' => $favid);
+ $result = update_multi_profile($favobj,$favorites,PROFILE_TYPE_MULTI_ARRAY,$resource);
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());
+ $favorites = get_multi_profile($favobj);
- $resource = (is_null($resource))?0:$resource;
- $favcnt = (is_null($favcnt))?0:$favcnt;
-
+ $favcnt = (is_null($favcnt))?0:$favcnt;
if($favid == 0) $favcnt = ZBX_FAVORITES_ALL;
- foreach($favorites as $key => $value){
- if(((bccomp($favid,$value) == 0) || ($favid == 0)) && ($fav_rsrc[$key] == $resource)){
+ foreach($favorites as $key => $favorite){
+ if(((bccomp($favid,$favorite['value']) == 0) || ($favid == 0)) && ($favorite['resource'] == $resource)){
if($favcnt < 1){
unset($favorites[$key]);
- unset($fav_rsrc[$key]);
if($favcnt > ZBX_FAVORITES_ALL) break; // foreach
}
}
$favcnt--;
}
- $result = update_profile($favobj,$favorites);
- $result &= update_profile($favrsrc,$fav_rsrc);
+ $result = update_multi_profile($favobj,$favorites,PROFILE_TYPE_MULTI_ARRAY);
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(bccomp($favid,$resourceid) == 0){
- if(is_null($resource) || ($fav['resource'][$id] == $resource))
+ $favorites = get_multi_profile($favobj);
+ if(!empty($favorites)){
+ foreach($favorites as $id => $favorite){
+ if(bccomp($favid,$favorite['value']) == 0){
+ if(is_null($resource) || ($favorite['resource'] == $resource))
return true;
}
}
diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php
index 25184ec4..9e2a48eb 100644
--- a/frontends/php/include/screens.inc.php
+++ b/frontends/php/include/screens.inc.php
@@ -105,23 +105,16 @@
}
function delete_screen($screenid){
- $result=DBexecute("delete from screens_items where screenid=$screenid");
- if(!$result) return $result;
-
- $result=DBexecute("delete from screens_items where resourceid=$screenid and resourcetype=".SCREEN_RESOURCE_SCREEN);
- if(!$result) return $result;
-
- $result=DBexecute('delete from slides where screenid='.$screenid);
- if(!$result) return $result;
-
- $result = rm4favorites('web.favorite.screenids',$screenid,ZBX_FAVORITES_ALL,'screenid');
- if(!$result) return $result;
-
- return DBexecute("delete from screens where screenid=$screenid");
+ $result=DBexecute('delete from screens_items where screenid='.$screenid);
+ $result&=DBexecute('delete from screens_items where resourceid='.$screenid.' and resourcetype='.SCREEN_RESOURCE_SCREEN);
+ $result&=DBexecute('delete from slides where screenid='.$screenid);
+ $result&=DBexecute('DELETE FROM profiles WHERE idx="web.favorite.screenids" AND resource="screenid" AND value='.$screenid);
+ $result&=DBexecute('delete from screens where screenid='.$screenid);
+ return $result;
}
function add_screen_item($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url,$dynamic){
- $sql="DELETE FROM screens_items WHERE screenid=$screenid and x=$x and y=$y";
+ $sql='DELETE FROM screens_items WHERE screenid='.$screenid.' and x='.$x.' and y='.$y;
DBexecute($sql);
$screenitemid=get_dbid("screens_items","screenitemid");
@@ -612,26 +605,22 @@
return $slideshowid;
}
- function update_slideshow($slideshowid, $name, $delay, $slides)
- {
- foreach($slides as $slide)
- {
- if( !validate_slide($slide) )
+ function update_slideshow($slideshowid, $name, $delay, $slides){
+ foreach($slides as $slide){
+ if(!validate_slide($slide))
return false;
}
- if( !($result = DBexecute('update slideshows set name='.zbx_dbstr($name).',delay='.$delay.' where slideshowid='.$slideshowid)) )
+ if(!$result = DBexecute('update slideshows set name='.zbx_dbstr($name).',delay='.$delay.' where slideshowid='.$slideshowid))
return false;
DBexecute('delete from slides where slideshowid='.$slideshowid);
$i = 0;
- foreach($slides as $slide)
- {
+ foreach($slides as $slide){
$slideid = get_dbid('slides','slideid');
if( !($result = DBexecute('insert into slides (slideid,slideshowid,screenid,step,delay) '.
- ' values ('.$slideid.','.$slideshowid.','.$slide['screenid'].','.($i++).','.$slide['delay'].')')) )
- {
+ ' values ('.$slideid.','.$slideshowid.','.$slide['screenid'].','.($i++).','.$slide['delay'].')')) ){
return false;
}
}
@@ -639,12 +628,13 @@
return true;
}
- function delete_slideshow($slideshowid)
- {
- return (
- DBexecute('delete from slideshows where slideshowid='.$slideshowid) &&
- DBexecute('delete from slides where slideshowid='.$slideshowid)
- );
+ function delete_slideshow($slideshowid){
+
+ $result = DBexecute('delete from slideshows where slideshowid='.$slideshowid);
+ $result &= DBexecute('delete from slides where slideshowid='.$slideshowid);
+ $result &= DBexecute('DELETE FROM profiles WHERE idx="web.favorite.screenids" AND resource="slideshowid" AND value='.$slideshowid);
+
+ return $result;
}
@@ -657,7 +647,7 @@
return $table;
}
- global $DB_TYPE;
+ global $DB;
$item=get_item_by_itemid($itemid);
switch($item["value_type"])
@@ -685,7 +675,7 @@
switch($item["value_type"])
{
case ITEM_VALUE_TYPE_TEXT:
- if($DB_TYPE == "ORACLE")
+ if($DB['TYPE'] == "ORACLE")
{
if(isset($row["value"]))
{
diff --git a/frontends/php/include/scripts.inc.php b/frontends/php/include/scripts.inc.php
index 3b53b932..037a15ef 100644
--- a/frontends/php/include/scripts.inc.php
+++ b/frontends/php/include/scripts.inc.php
@@ -111,8 +111,8 @@ function get_accessible_scripts_by_hosts($hosts){
$hosts = array('0' => hosts);
}
- $hosts_read_only = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,get_current_nodeid()));
- $hosts_read_write = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,null,null,get_current_nodeid()));
+ $hosts_read_only = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY));
+ $hosts_read_write = explode(',',get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE));
// initialize array
foreach($hosts as $id => $hostid){
diff --git a/frontends/php/include/setup.inc.php b/frontends/php/include/setup.inc.php
index c43ef973..08aa5ca3 100644
--- a/frontends/php/include/setup.inc.php
+++ b/frontends/php/include/setup.inc.php
@@ -350,9 +350,9 @@
$table = new CTable();
$table->SetAlign('center');
- $DB_TYPE = $this->GetConfig('DB_TYPE');
+ $DB['TYPE'] = $this->GetConfig('DB_TYPE');
- $cmbType = new CComboBox('type', $DB_TYPE);
+ $cmbType = new CComboBox('type', $DB['TYPE']);
foreach($ZBX_CONFIG['allowed_db'] as $id => $name)
{
$cmbType->AddItem($id, $name);
@@ -531,24 +531,24 @@
function CheckConnection()
{
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB;
- $old_DB = $DB;
- $old_DB_TYPE = $DB_TYPE;
- $old_DB_SERVER = $DB_SERVER;
- $old_DB_PORT = $DB_PORT;
- $old_DB_DATABASE= $DB_DATABASE;
- $old_DB_USER = $DB_USER;
- $old_DB_PASSWORD= $DB_PASSWORD;
+ $old_DB = $DB['DB'];
+ $old_DB_TYPE = $DB['TYPE'];
+ $old_DB_SERVER = $DB['SERVER'];
+ $old_DB_PORT = $DB['PORT'];
+ $old_DB_DATABASE= $DB['DATABASE'];
+ $old_DB_USER = $DB['USER'];
+ $old_DB_PASSWORD= $DB['PASSWORD'];
- $DB_TYPE = $this->GetConfig('DB_TYPE');
- if(is_null($DB_TYPE)) return false;
+ $DB['TYPE'] = $this->GetConfig('DB_TYPE');
+ if(is_null($DB['TYPE'])) return false;
- $DB_SERVER = $this->GetConfig('DB_SERVER', 'localhost');
- $DB_PORT = $this->GetConfig('DB_PORT', '0');
- $DB_DATABASE = $this->GetConfig('DB_DATABASE', 'zabbix');
- $DB_USER = $this->GetConfig('DB_USER', 'root');
- $DB_PASSWORD = $this->GetConfig('DB_PASSWORD', '');
+ $DB['SERVER'] = $this->GetConfig('DB_SERVER', 'localhost');
+ $DB['PORT'] = $this->GetConfig('DB_PORT', '0');
+ $DB['DATABASE'] = $this->GetConfig('DB_DATABASE', 'zabbix');
+ $DB['USER'] = $this->GetConfig('DB_USER', 'root');
+ $DB['PASSWORD'] = $this->GetConfig('DB_PASSWORD', '');
$error = '';
if(!($result = DBconnect($error)))
@@ -563,22 +563,22 @@
DBclose();
- if($DB_TYPE == 'SQLITE3' && !zbx_is_callable(array('sem_get','sem_acquire','sem_release','sem_remove')))
+ if($DB['TYPE'] == 'SQLITE3' && !zbx_is_callable(array('sem_get','sem_acquire','sem_release','sem_remove')))
{
error('SQLite3 required IPC functions');
$result &= false;
}
/* restore connection */
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD;
+ global $DB;
- $DB = $old_DB;
- $DB_TYPE = $old_DB_TYPE;
- $DB_SERVER = $old_DB_SERVER;
- $DB_PORT = $old_DB_PORT;
- $DB_DATABASE = $old_DB_DATABASE;
- $DB_USER = $old_DB_USER;
- $DB_PASSWORD = $old_DB_PASSWORD;
+ $DB['DB'] = $old_DB;
+ $DB['TYPE'] = $old_DB_TYPE;
+ $DB['SERVER'] = $old_DB_SERVER;
+ $DB['PORT'] = $old_DB_PORT;
+ $DB['DATABASE'] = $old_DB_DATABASE;
+ $DB['USER'] = $old_DB_USER;
+ $DB['PASSWORD'] = $old_DB_PASSWORD;
DBconnect($error);
@@ -595,7 +595,7 @@
{
include $ZBX_CONFIGURATION_FILE;
- switch($DB_TYPE)
+ switch($DB['TYPE'])
{
case 'MYSQL': $ZBX_SCHEMA_FILE = 'mysql.sql'; break;
case 'POSTGRESQL': $ZBX_SCHEMA_FILE = 'postgresql.sql'; break;
@@ -673,15 +673,15 @@
function CheckConfigurationFile()
{
- global $DB, $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $ZBX_SERVER, $ZBX_SERVER_PORT;
-
- $old_DB = $DB;
- $old_DB_TYPE = $DB_TYPE;
- $old_DB_SERVER = $DB_SERVER;
- $old_DB_PORT = $DB_PORT;
- $old_DB_DATABASE = $DB_DATABASE;
- $old_DB_USER = $DB_USER;
- $old_DB_PASSWORD = $DB_PASSWORD;
+ global $DB;
+
+ $old_DB = $DB['DB'];
+ $old_DB_TYPE = $DB['TYPE'];
+ $old_DB_SERVER = $DB['SERVER'];
+ $old_DB_PORT = $DB['PORT'];
+ $old_DB_DATABASE = $DB['DATABASE'];
+ $old_DB_USER = $DB['USER'];
+ $old_DB_PASSWORD = $DB['PASSWORD'];
$old_ZBX_SERVER = $ZBX_SERVER;
$old_ZBX_SERVER_PORT = $ZBX_SERVER_PORT;
@@ -694,20 +694,20 @@
{
include $ZBX_CONFIGURATION_FILE;
- if( isset($DB_TYPE) &&
- isset($DB_SERVER) &&
- isset($DB_DATABASE) &&
- isset($DB_USER) &&
- isset($DB_PASSWORD) &&
+ if( isset($DB['TYPE']) &&
+ isset($DB['SERVER']) &&
+ isset($DB['DATABASE']) &&
+ isset($DB['USER']) &&
+ isset($DB['PASSWORD']) &&
isset($ZBX_SERVER) &&
isset($ZBX_SERVER_PORT) &&
isset($IMAGE_FORMAT_DEFAULT) &&
- $DB_TYPE == $this->GetConfig('DB_TYPE', null) &&
- $DB_SERVER == $this->GetConfig('DB_SERVER', null) &&
- $DB_PORT == $this->GetConfig('DB_PORT', null) &&
- $DB_DATABASE == $this->GetConfig('DB_DATABASE', null) &&
- $DB_USER == $this->GetConfig('DB_USER', null) &&
- $DB_PASSWORD == $this->GetConfig('DB_PASSWORD', null)
+ $DB['TYPE'] == $this->GetConfig('DB_TYPE', null) &&
+ $DB['SERVER'] == $this->GetConfig('DB_SERVER', null) &&
+ $DB['PORT'] == $this->GetConfig('DB_PORT', null) &&
+ $DB['DATABASE'] == $this->GetConfig('DB_DATABASE', null) &&
+ $DB['USER'] == $this->GetConfig('DB_USER', null) &&
+ $DB['PASSWORD'] == $this->GetConfig('DB_PASSWORD', null)
)
{
if(!DBconnect($error_msg))
@@ -732,15 +732,15 @@
}
/* restore connection */
- global $DB, $DB_TYPE, $DB_PORT, $DB_SERVER, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $ZBX_SERVER, $ZBX_SERVER_PORT;
-
- $DB = $old_DB;
- $DB_TYPE = $old_DB_TYPE;
- $DB_SERVER = $old_DB_SERVER;
- $DB_PORT = $old_DB_PORT;
- $DB_DATABASE = $old_DB_DATABASE;
- $DB_USER = $old_DB_USER;
- $DB_PASSWORD = $old_DB_PASSWORD;
+ global $DB;
+
+ $DB['DB'] = $old_DB;
+ $DB['TYPE'] = $old_DB_TYPE;
+ $DB['SERVER'] = $old_DB_SERVER;
+ $DB['PORT'] = $old_DB_PORT;
+ $DB['DATABASE'] = $old_DB_DATABASE;
+ $DB['USER'] = $old_DB_USER;
+ $DB['PASSWORD'] = $old_DB_PASSWORD;
$ZBX_SERVER = $old_ZBX_SERVER;
$ZBX_SERVER_PORT= $old_ZBX_SERVER_PORT;
@@ -885,14 +885,14 @@
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
-global $DB_TYPE, $DB_SERVER, $DB_PORT, $DB_DATABASE, $DB_USER, $DB_PASSWORD, $IMAGE_FORMAT_DEFAULT, $ZBX_SERVER, $ZBX_SERVER_PORT;
+global $DB;
-$DB_TYPE = "'.$this->GetConfig('DB_TYPE' ,'unknown').'";
-$DB_SERVER = "'.$this->GetConfig('DB_SERVER' ,'unknown').'";
-$DB_PORT = "'.$this->GetConfig('DB_PORT' ,'0').'";
-$DB_DATABASE = "'.$this->GetConfig('DB_DATABASE' ,'unknown').'";
-$DB_USER = "'.$this->GetConfig('DB_USER' ,'unknown').'";
-$DB_PASSWORD = "'.$this->GetConfig('DB_PASSWORD' ,'').'";
+$DB["TYPE"] = "'.$this->GetConfig('DB_TYPE' ,'unknown').'";
+$DB["SERVER"] = "'.$this->GetConfig('DB_SERVER' ,'unknown').'";
+$DB["PORT"] = "'.$this->GetConfig('DB_PORT' ,'0').'";
+$DB["DATABASE"] = "'.$this->GetConfig('DB_DATABASE' ,'unknown').'";
+$DB["USER"] = "'.$this->GetConfig('DB_USER' ,'unknown').'";
+$DB["PASSWORD"] = "'.$this->GetConfig('DB_PASSWORD' ,'').'";
$ZBX_SERVER = "'.$this->GetConfig('ZBX_SERVER' ,'').'";
$ZBX_SERVER_PORT = "'.$this->GetConfig('ZBX_SERVER_PORT' ,'0').'";
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 1db8ad74..05e1f7e8 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -197,7 +197,7 @@
return $available_triggers[$perm][$perm_res][$nodeid_str][$hostid_str];
}
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, null, $nodeid);
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, null, $nodeid);
$denied_graphs = array();
$available_graphs = array();
@@ -1467,27 +1467,26 @@
return $result;
}
- function check_right_on_trigger_by_triggerid($permission,$triggerid,$accessible_hosts=null)
+ function check_right_on_trigger_by_triggerid($permission,$triggerid,$available_hosts=null)
{
$trigger_data = DBfetch(DBselect('select expression from triggers where triggerid='.$triggerid));
if(!$trigger_data) return false;
- return check_right_on_trigger_by_expression($permission, explode_exp($trigger_data['expression'], 0), $accessible_hosts);
+ return check_right_on_trigger_by_expression($permission, explode_exp($trigger_data['expression'], 0), $available_hosts);
}
- function check_right_on_trigger_by_expression($permission,$expression,$accessible_hosts=null)
+ function check_right_on_trigger_by_expression($permission,$expression,$available_hosts=null)
{
- if(is_null($accessible_hosts))
+ if(is_null($available_hosts))
{
global $USER_DETAILS;
- $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, $permission, null, PERM_RES_IDS_ARRAY);
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $permission, PERM_RES_IDS_ARRAY);
}
- if(!is_array($accessible_hosts)) $accessible_hosts = explode(',', $accessible_hosts);
+ if(!is_array($available_hosts)) $available_hosts = explode(',', $available_hosts);
$db_hosts = get_hosts_by_expression($expression);
- while($host_data = DBfetch($db_hosts))
- {
- if(!uint_in_array($host_data['hostid'], $accessible_hosts)) return false;
+ while($host_data = DBfetch($db_hosts)){
+ if(!uint_in_array($host_data['hostid'], $available_hosts)) return false;
}
return true;
@@ -1817,7 +1816,7 @@
' AND h.hostid=i.hostid '.
' AND i.itemid=f.itemid '.
' AND f.triggerid=t.triggerid'.
- ' AND h.hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, null, null, get_current_nodeid()).') '.
+ ' AND h.hostid in ('.get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY).') '.
' AND t.status='.TRIGGER_STATUS_ENABLED.
' AND i.status='.ITEM_STATUS_ACTIVE.
' ORDER BY t.description');