$map['id_group'], 'id_user' => $config['id_user'], 'type' => $map['type'], 'subtype' => $map['subtype'], 'name' => $new_name, 'description' => $map['description'], 'width' => $map['width'], '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'], ] ); } if ($result) { $map_items = db_get_all_rows_sql('SELECT * FROM titem WHERE id_map = '.$id); maps_duplicate_items_map($result, $map_items); } return (int) $result; } function maps_duplicate_items_map($id, $map_items) { if (empty($map_items)) { return; } foreach ($map_items as $item) { $copy_items = [ '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) { $item_relations = db_get_all_rows_sql('SELECT * FROM trel_item WHERE id = '.$item['id'].' AND deleted = 0'); if ($item['id'] == $item_relations['parent_id']) { $copy_item_relations = [ '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'], ]; } else { $copy_item_relations = [ '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'], ]; } db_process_sql_insert('trel_item', $copy_item_relations); } } } function maps_delete_map($id) { $where = 'id='.$id; $result = db_process_sql_delete('tmap', $where); return (int) $result; } function maps_get_count_nodes($id) { $result = db_get_sql('SELECT COUNT(*) FROM titem WHERE id_map = '.$id); return (int) $result; } function maps_update_map($id, $values) { $where = 'id='.$id; $result = db_process_sql_update('tmap', $values, $where); return (int) $result; } 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; } function run_graphviz($filename_map, $filename_dot, $layout, $graph) { switch (PHP_OS) { case 'WIN32': case 'WINNT': case 'Windows': $filename_plain = sys_get_temp_dir().'\\plain.txt'; break; default: $filename_plain = sys_get_temp_dir().'/plain.txt'; break; } file_put_contents($filename_dot, $graph); file_put_contents($filename_dot, $graph); $cmd = $layout.' -Tcmapx -o'.$filename_map.' -Tplain -o'.$filename_plain.' '.$filename_dot; system($cmd); if (file_exists($filename_map)) { unlink($filename_map); } if (file_exists($filename_dot)) { unlink($filename_dot); } return $filename_plain; } function open_graph($size_x=50, $size_y=25) { $size = ''; $size = $size_x.','.$size_y; // BEWARE: graphwiz DONT use single ('), you need double ("). $head = 'graph vmwaremap { labeljust=l; margin=0; '; $head .= 'ratio=fill;'; $head .= 'root=0;'; $head .= 'rankdir=LR;'; $head .= 'size="'.$size.'";'; return $head; } function create_node($node, $font_size=10) { // Set node status. if (isset($node['status'])) { switch ($node['status']) { case AGENT_MODULE_STATUS_NORMAL: $status_color = COL_NORMAL; // Normal monitor. break; case AGENT_MODULE_STATUS_CRITICAL_BAD: $status_color = COL_CRITICAL; // Critical monitor. break; case AGENT_MODULE_STATUS_WARNING: $status_color = COL_WARNING; // Warning monitor. break; case AGENT_STATUS_ALERT_FIRED: case AGENT_MODULE_STATUS_CRITICAL_ALERT: case AGENT_MODULE_STATUS_WARNING_ALERT: $status_color = COL_ALERTFIRED; // Alert fired. break; case AGENT_MODULE_STATUS_NOT_INIT: $status_color = COL_NOTINIT; // Not init. break; default: $status_color = COL_UNKNOWN; // Unknown monitor. break; } $status_color = 'color="'.$status_color.'",'; } else { $status_color = ''; } // Short name. if (isset($node['nombre'])) { $name = io_safe_output(strtolower($node['nombre'])); if (strlen($name) > 16) { $name = substr($name, 0, 16).'...'; } } // Set node icon. if (isset($node['image'])) { if (file_exists($node['image'])) { $img_node = $node['image']; } else { $img_node = null; } } else { $img_node = null; } $result = $node['id_node'].' [ '.$status_color.' fontsize='.$font_size.', style="filled", fixedsize=true, width=0.40, height=0.40, label=<
'.html_print_image($img_node, true, false, false, true).' |
'.$name.' |