2016-02-01 15:23:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Pandora FMS - http://pandorafms.com
|
|
|
|
// ==================================================
|
|
|
|
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
|
|
|
// Please see http://pandorafms.org for full contribution list
|
|
|
|
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation; version 2
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package Include
|
|
|
|
* @subpackage Maps
|
|
|
|
*/
|
|
|
|
|
|
|
|
function maps_save_map($values) {
|
2016-02-02 16:58:39 +01:00
|
|
|
$result_add = db_process_sql_insert('tmap', $values);
|
|
|
|
return $result_add;
|
2016-02-01 15:23:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function maps_get_maps($filter) {
|
|
|
|
return db_get_all_rows_filter('tmap', $filter);
|
|
|
|
}
|
2016-02-01 16:02:43 +01:00
|
|
|
|
|
|
|
function maps_get_subtype_string($subtype) {
|
|
|
|
switch ($subtype) {
|
|
|
|
case MAP_SUBTYPE_TOPOLOGY:
|
|
|
|
return __('Topology');
|
|
|
|
break;
|
|
|
|
case MAP_SUBTYPE_POLICIES:
|
|
|
|
return __('Policies');
|
|
|
|
break;
|
|
|
|
case MAP_SUBTYPE_GROUPS:
|
|
|
|
return __('Groups');
|
|
|
|
break;
|
|
|
|
case MAP_SUBTYPE_RADIAL_DYNAMIC:
|
|
|
|
return __('Dynamic');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return __('Unknown');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 09:30:01 +01:00
|
|
|
function maps_duplicate_map($id) {
|
|
|
|
global $config;
|
2016-02-02 16:58:39 +01:00
|
|
|
$map = db_get_all_rows_sql("SELECT * FROM tmap WHERE id = " . $id);
|
|
|
|
$result = false;
|
|
|
|
$map = $map[0];
|
2016-02-02 09:30:01 +01:00
|
|
|
if (!empty($map)) {
|
2016-02-02 16:58:39 +01:00
|
|
|
$map_names = db_get_row_sql("SELECT name FROM tmap WHERE name LIKE '" . $map['name'] . "%'");
|
2016-02-02 09:30:01 +01:00
|
|
|
$index = 0;
|
|
|
|
foreach ($map_names as $map_name) {
|
|
|
|
$index++;
|
|
|
|
}
|
2016-02-03 09:20:31 +01:00
|
|
|
$new_name = __('Copy of ') . $map['name'];
|
2016-02-02 09:30:01 +01:00
|
|
|
$result = db_process_sql_insert('tmap', array('id_group' => $map['id_group'],
|
|
|
|
'id_user' => $config['id_user'], 'type' => $map['type'], 'subtype' => $map['subtype'],
|
2016-02-02 16:58:39 +01:00
|
|
|
'name' => $new_name, 'description' => $map['description'], 'width' => $map['width'],
|
2016-02-02 09:30:01 +01:00
|
|
|
'height' => $map['height'], 'center_x' => $map['center_x'], 'center_y' => $map['center_y'],
|
|
|
|
'background' => $map['background'], 'background_options' => $map['background_options'],
|
|
|
|
'source_period' => $map['source_period'], 'source' => $map['source'],
|
|
|
|
'source_data' => $map['source_data'], 'generation_method' => $map['generation_method'],
|
|
|
|
'filter' => $map['filter']));
|
|
|
|
}
|
2016-02-04 10:31:37 +01:00
|
|
|
if ($result) {
|
|
|
|
$map_items = db_get_all_rows_sql("SELECT * FROM titem WHERE id_map = " . $id);
|
|
|
|
maps_duplicate_items_map($result, $map_items);
|
|
|
|
}
|
2016-02-02 09:30:01 +01:00
|
|
|
return (int)$result;
|
|
|
|
}
|
|
|
|
|
2016-02-04 10:31:37 +01:00
|
|
|
function maps_duplicate_items_map($id, $map_items) {
|
|
|
|
if (empty($map_items)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach ($map_items as $item) {
|
|
|
|
$copy_items = array('id_map' => $id, 'x' => $item['x'], 'y' => $item['y'], 'z' => $item['z'],
|
|
|
|
'deleted' => $item['deleted'], 'type' => $item['type'], 'refresh' => $item['refresh'],
|
|
|
|
'source' => $item['source'], 'source_data' => $item['source_data'],
|
|
|
|
'options' => $item['options'], 'style' => $item['style']);
|
|
|
|
$result_copy_item = db_process_sql_insert('titem', $copy_items);
|
|
|
|
if ($result_copy_item) {
|
2018-01-22 16:17:10 +01:00
|
|
|
$item_relations = db_get_all_rows_sql("SELECT * FROM trel_item WHERE id = " . $item['id'] . " AND deleted = 0");
|
2016-02-04 10:31:37 +01:00
|
|
|
if ($item['id'] == $item_relations['parent_id']) {
|
2016-02-04 11:45:17 +01:00
|
|
|
$copy_item_relations = array(
|
|
|
|
'id_parent' => $result_copy_item,
|
|
|
|
'id_child' => $item_relations['id_child'],
|
|
|
|
'parent_type' => $item_relations['parent_type'],
|
|
|
|
'child_type' => $item_relations['child_type'],
|
|
|
|
'id_item' => $item_relations['id_item'],
|
|
|
|
'deleted' => $item_relations['deleted']);
|
2016-02-04 10:31:37 +01:00
|
|
|
}
|
|
|
|
else {
|
2016-02-04 11:45:17 +01:00
|
|
|
$copy_item_relations = array(
|
|
|
|
'id_parent' => $item_relations['id_parent'],
|
|
|
|
'id_child' => $result_copy_item,
|
|
|
|
'parent_type' => $item_relations['parent_type'],
|
|
|
|
'child_type' => $item_relations['child_type'],
|
|
|
|
'id_item' => $item_relations['id_item'],
|
|
|
|
'deleted' => $item_relations['deleted']);
|
2016-02-04 10:31:37 +01:00
|
|
|
}
|
|
|
|
db_process_sql_insert('trel_item', $copy_item_relations);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 14:10:13 +01:00
|
|
|
function maps_delete_map($id) {
|
|
|
|
$where = 'id=' . $id;
|
2016-02-02 16:58:39 +01:00
|
|
|
$result = db_process_sql_delete('tmap', $where);
|
|
|
|
return (int)$result;
|
2016-02-02 14:10:13 +01:00
|
|
|
}
|
|
|
|
|
2016-02-01 16:02:43 +01:00
|
|
|
function maps_get_count_nodes($id) {
|
2016-02-02 09:30:01 +01:00
|
|
|
$result = db_get_sql("SELECT COUNT(*) FROM titem WHERE id_map = " . $id);
|
2016-02-01 16:02:43 +01:00
|
|
|
return (int)$result;
|
|
|
|
}
|
2016-02-02 09:30:01 +01:00
|
|
|
|
|
|
|
function maps_update_map ($id, $values) {
|
|
|
|
$where = 'id=' . $id;
|
|
|
|
$result = db_process_sql_update('tmap', $values, $where);
|
|
|
|
return (int)$result;
|
|
|
|
}
|
2016-04-01 09:52:15 +02:00
|
|
|
|
|
|
|
function maps_add_node ($values) {
|
|
|
|
$result_add_node = db_process_sql_insert('titem', $values);
|
|
|
|
return $result_add_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function maps_add_node_relationship ($values) {
|
|
|
|
$result_add_node_rel = db_process_sql_insert('trel_item', $values);
|
|
|
|
return $result_add_node_rel;
|
|
|
|
}
|
2016-02-01 15:23:56 +01:00
|
|
|
?>
|