diff --git a/pandora_console/extensions/resource_exportation.php b/pandora_console/extensions/resource_exportation.php
deleted file mode 100755
index 476b7ef1bf..0000000000
--- a/pandora_console/extensions/resource_exportation.php
+++ /dev/null
@@ -1,497 +0,0 @@
-'."\n";
- echo "\n";
- echo '\n";
- if (isset($report['description'])) {
- echo '\n";
- }
-
- $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $report['id_group']);
- echo '\n";
- $items = db_get_all_rows_field_filter(
- 'treport_content',
- 'id_report',
- $report['id_report']
- );
- foreach ($items as $item) {
- echo "- \n";
- echo ''.io_safe_output($item['type'])."\n";
- echo ''.io_safe_output($item['description'])."\n";
- echo ''.io_safe_output($item['period'])."\n";
- if ($item['id_agent'] != 0) {
- $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']);
- }
-
- if ($item['id_agent_module'] != 0) {
- $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']);
- $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agent_module']);
- $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']);
-
- echo '\n";
- }
-
- if (isset($agent)) {
- echo '\n";
- }
-
- $agent = null;
- switch (io_safe_output($item['type'])) {
- case 2:
- case 'custom_graph':
- case 'automatic_custom_graph':
- $graph = db_get_value('name', 'tgraph', 'id_graph', $item['id_gs']);
- echo '\n";
- break;
-
- case 3:
- case 'SLA':
- echo ''.$item['only_display_wrong']."\n";
- echo ''.$item['monday']."\n";
- echo ''.$item['tuesday']."\n";
- echo ''.$item['wednesday']."\n";
- echo ''.$item['thursday']."\n";
- echo ''.$item['friday']."\n";
- echo ''.$item['saturday']."\n";
- echo ''.$item['sunday']."\n";
- echo ''.$item['time_from']."\n";
- echo ''.$item['time_to']."\n";
-
- $slas = db_get_all_rows_field_filter('treport_content_sla_combined', 'id_report_content', $item['id_rc']);
- if ($slas === false) {
- $slas = [];
- }
-
- foreach ($slas as $sla) {
- $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']);
- $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $sla['id_agent_module']);
- $agent = db_get_value('alias', 'tagente', 'id_agente', $item['id_agent']);
- echo '';
- echo '\n";
- echo '\n";
- echo ''.$sla['sla_max']."\n";
- echo ''.$sla['sla_min']."\n";
- echo ''.$sla['sla_limit']."\n";
- echo '';
- }
- break;
-
- case 'text':
- echo '\n";
- break;
-
- case 'sql':
- echo '\n";
- if (!empty($item['external_source'])) {
- echo '\n";
- } else {
- $sql = db_get_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']);
- echo ''.io_safe_output($sql)."\n";
- }
- break;
-
- case 'sql_graph_pie':
- case 'sql_graph_vbar':
- case 'sql_graph_hbar':
- echo ''.io_safe_output($item['header_definition'])."\n";
- if (!empty($item['external_source'])) {
- echo ''.io_safe_output($item['external_source'])."\n";
- } else {
- $sql = db_get_value('sql', 'treport_custom_sql', 'id', $item['treport_custom_sql_id']);
- echo ''.io_safe_output($sql)."\n";
- }
- break;
-
- case 'event_report_group':
- $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $item['id_agent']);
- echo '\n";
- break;
-
- case 'url':
- echo '';
- break;
-
- case 'database_serialized':
- echo '';
- echo '';
- echo '';
- break;
-
- case 1:
- case 'simple_graph':
- case 'simple_baseline_graph':
- case 6:
- case 'monitor_report':
- case 7:
- case 'avg_value':
- case 8:
- case 'max_value':
- case 9:
- case 'min_value':
- case 10:
- case 'sumatory':
- case 'agent_detailed_event':
- case 'event_report_agent':
- case 'event_report_module':
- case 'alert_report_module':
- case 'alert_report_agent':
- case 'alert_report_group':
- default:
- // Do nothing.
- break;
- }
-
- echo "
\n";
- }
-
- echo "\n";
-}
-
-
-function output_xml_visual_console($id)
-{
- $visual_map = db_get_row('tlayout', 'id', $id);
-
- echo ''."\n";
- echo "\n";
- echo '\n";
- if ($visual_map['id_group'] != 0) {
- $group = db_get_value('nombre', 'tgrupo', 'id_grupo', $visual_map['id_group']);
- echo '\n";
- }
-
- echo '\n";
- echo ''.io_safe_output($visual_map['height'])."\n";
- echo ''.io_safe_output($visual_map['width'])."\n";
- $items = db_get_all_rows_field_filter('tlayout_data', 'id_layout', $visual_map['id']);
- if ($items === false) {
- $items = [];
- }
-
- foreach ($items as $item) {
- echo "- \n";
- echo ''.$item['id']."\n";
- // OLD ID USE FOR parent item
- $agent = '';
- if ($item['id_agent'] != 0) {
- $agent = db_get_value('nombre', 'tagente', 'id_agente', $item['id_agent']);
- }
-
- if (!empty($item['label'])) {
- echo '\n";
- }
-
- echo ''.$item['pos_x']."\n";
- echo ''.$item['pos_y']."\n";
- echo ''.$item['type']."\n";
- if ($item['width'] != 0) {
- echo ''.$item['width']."\n";
- }
-
- if ($item['height'] != 0) {
- echo ''.$item['height']."\n";
- }
-
- if (!empty($item['image'])) {
- echo ''.$item['image']."\n";
- }
-
- if ($item['period'] != 0) {
- echo ''.$item['period']."\n";
- }
-
- if (isset($item['id_agente_modulo'])) {
- if ($item['id_agente_modulo'] != 0) {
- $module = db_get_value('nombre', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']);
- $id_agent = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', $item['id_agente_modulo']);
- $agent = db_get_value('nombre', 'tagente', 'id_agente', $id_agent);
-
- echo '\n";
- }
- }
-
- if (!empty($agent)) {
- echo '\n";
- }
-
- if ($item['id_layout_linked'] != 0) {
- echo ''.$item['id_layout_linked']."\n";
- }
-
- if ($item['parent_item'] != 0) {
- echo ''.$item['parent_item']."\n";
- }
-
- if (!empty($item['clock_animation'])) {
- echo ''.$item['clock_animation']."\n";
- }
-
- if (!empty($item['fill_color'])) {
- echo ''.$item['fill_color']."\n";
- }
-
- if (!empty($item['type_graph'])) {
- echo ''.$item['type_graph']."\n";
- }
-
- if (!empty($item['time_format'])) {
- echo ''.$item['time_format']."\n";
- }
-
- if (!empty($item['timezone'])) {
- echo ''.$item['timezone']."\n";
- }
-
- if (!empty($item['border_width'])) {
- echo ''.$item['border_width']."\n";
- }
-
- if (!empty($item['border_color'])) {
- echo ''.$item['border_color']."\n";
- }
-
- echo "
\n";
- }
-
- echo "\n";
-}
-
-
-function get_name_xml_resource($hook_enterprise)
-{
- global $config;
-
- $type = get_parameter('type');
- $id = (int) get_parameter('id');
-
- switch ($type) {
- case 'report':
- $name = db_get_value('name', 'treport', 'id_report', $id);
- break;
-
- case 'visual_console':
- $name = db_get_value('name', 'tlayout', 'id', $id);
- break;
-
- default:
- if ($hook_enterprise === true) {
- return enterprise_get_name_xml_resource($type, $id);
- }
- break;
- }
-
- $file = io_safe_output($name).'.ptr';
-
- return $file;
-}
-
-
-function get_xml_resource()
-{
- global $config;
-
- $hook_enterprise = enterprise_include('extensions/resource_exportation/functions.php');
-}
-
-
-function resource_exportation_extension_main()
-{
- global $config;
-
- check_login();
-
- if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
- db_pandora_audit(
- AUDIT_LOG_ACL_VIOLATION,
- 'Trying to access Setup Management'
- );
- include 'general/noaccess.php';
- return;
- }
-
- $hook_enterprise = enterprise_include('extensions/resource_exportation/functions.php');
-
- ui_print_standard_header(
- __('Resource exportation'),
- 'images/extensions.png',
- false,
- '',
- true,
- [],
- [
- [
- 'link' => '',
- 'label' => __('Resources'),
- ],
- [
- 'link' => '',
- 'label' => __('Resource exporting'),
- ],
- ]
- );
-
- ui_print_warning_message(
- __('This extension makes exportation of resource template more easy.').'
'.__('You can export resource templates in .ptr format.')
- );
-
- $table = new stdClass();
- $table->class = 'databox filter-table-adv';
- $table->id = 'resource_exportation_table';
- $table->style = [];
- $table->style[0] = 'width: 30%';
- $table->style[1] = 'vertical-align: bottom;';
- $table->data = [];
- $table->data[0][] = html_print_label_input_block(
- __('Report'),
- html_print_div(
- [
- 'class' => 'flex-content-left',
- 'content' => html_print_select_from_sql('SELECT id_report, name FROM treport', 'report', '', '', '', 0, true),
- ],
- true
- )
- );
- $table->data[0][] = html_print_button(__('Export'), '', false, 'export_to_ptr("report");', '', true);
-
- $table->data[1][] = html_print_label_input_block(
- __('Visual console'),
- html_print_div(
- [
- 'class' => 'flex-content-left',
- 'content' => html_print_select_from_sql('SELECT id, name FROM tlayout', 'visual_console', '', '', '', 0, true),
- ],
- true
- )
- );
- $table->data[1][] = html_print_button(__('Export'), '', false, 'export_to_ptr("visual_console");', '', true);
-
- if ($hook_enterprise === true) {
- add_rows_for_enterprise($table->data);
- }
-
- html_print_table($table);
-
- ?>
-
- $name) {
- $values['id_report'] = $id;
- $result = (bool) db_process_sql_insert('treport_content', $values);
-
- ui_print_result_message(
- $result,
- sprintf(
- __("Success add '%s' item in report '%s'."),
- $values['type'],
- $name
- ),
- sprintf(
- __("Error create '%s' item in report '%s'."),
- $values['type'],
- $name
- )
- );
- }
-}
-
-
-function process_upload_xml_report($xml, $group_filter=0)
-{
- foreach ($xml->xpath('/report') as $reportElement) {
- $values = [];
-
- if (isset($reportElement->name)) {
- $values['name'] = $reportElement->name;
-
- $posible_name = $values['name'];
- $exist = true;
- $loops = 30;
- // Loops to exit or tries.
- while ($exist && $loops > 0) {
- $exist = (bool) db_get_row_filter(
- 'treport',
- ['name' => io_safe_input($posible_name)]
- );
-
- if ($exist) {
- $loops--;
- $posible_name = $values['name'].' ('.(30 - $loops).')';
- }
- }
-
- if ($exist) {
- ui_print_error_message(
- sprintf(
- __("Error create '%s' report, the name exist and there aren't free name."),
- $reportElement->name
- )
- );
- break;
- } else if ($loops != 30) {
- ui_print_warning_message(
- sprintf(
- __("Warning create '%s' report, the name exist, the report have a name %s."),
- $reportElement->name,
- $posible_name
- )
- );
- }
-
- $values['name'] = io_safe_input($posible_name);
- } else {
- ui_print_error_message(__("Error the report haven't name."));
- break;
- }
-
- if (isset($reportElement->group) === true
- && empty($reportElement->group) === false
- ) {
- $id_group = db_get_value(
- 'id_grupo',
- 'tgrupo',
- 'nombre',
- $reportElement->group
- );
- if ($id_group === false) {
- ui_print_error_message(__("Error the report haven't group."));
- break;
- }
- }
-
- if (isset($reportElement->description) === true) {
- $values['description'] = $reportElement->description;
- }
-
- $id_report = db_process_sql_insert('treport', $values);
-
- ui_print_result_message(
- $id_report,
- sprintf(__("Success create '%s' report."), $posible_name),
- sprintf(__("Error create '%s' report."), $posible_name)
- );
-
- if ($id_report) {
- db_pandora_audit(
- AUDIT_LOG_REPORT_MANAGEMENT,
- 'Create report '.$id_report,
- false,
- false
- );
- } else {
- db_pandora_audit(
- AUDIT_LOG_REPORT_MANAGEMENT,
- 'Fail to create report',
- false,
- false
- );
- break;
- }
-
- foreach ($reportElement->item as $item) {
- $item = (array) $item;
-
- $values = [];
- $values['id_report'] = $id_report;
- if (isset($item['description']) === true) {
- $values['description'] = io_safe_input($item['description']);
- }
-
- if (isset($item['period']) === true) {
- $values['period'] = io_safe_input($item['period']);
- }
-
- if (isset($item['type']) === true) {
- $values['type'] = io_safe_input($item['type']);
- }
-
- $agents_item = [];
- if (isset($item['agent']) === true) {
- $agents = agents_get_agents(
- ['id_grupo' => $group_filter],
- [
- 'id_agente',
- 'alias',
- ]
- );
-
- $agent_clean = str_replace(
- [
- '[',
- ']',
- ],
- '',
- io_safe_output($item['agent'])
- );
- $regular_expresion = ($agent_clean != $item['agent']);
-
- foreach ($agents as $agent) {
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['alias']))) {
- $agents_item[$agent['id_agente']]['name'] = $agent['alias'];
- }
- } else {
- if ($agent_clean == io_safe_output($agent['alias'])) {
- $agents_item[$agent['id_agente']]['name'] = $agent['alias'];
- }
- }
- }
- }
-
- if (isset($item['module']) === true) {
- $module_clean = str_replace(['[', ']'], '', $item['module']);
- $regular_expresion = ($module_clean != $item['module']);
-
- foreach ($agents_item as $id => $agent) {
- $modules = db_get_all_rows_filter(
- 'tagente_modulo',
- ['id_agente' => $id],
- [
- 'id_agente_modulo',
- 'nombre',
- ]
- );
-
- $agents_item[$id]['modules'] = [];
-
- foreach ($modules as $module) {
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) {
- $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = $module['nombre'];
- }
- } else {
- if ($module_clean == io_safe_output($module['nombre'])) {
- $agents_item[$id]['modules'][$module['id_agente_modulo']]['name'] = $module['nombre'];
- }
- }
- }
- }
- }
-
- switch ($item['type']) {
- case 2:
- case 'custom_graph':
- case 'automatic_custom_graph':
- $group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($item['graph']));
- $values['id_gs'] = $group;
- break;
-
- case 3:
- case 'SLA':
- if (isset($item['only_display_wrong'])) {
- $values['only_display_wrong'] = (string) $item['only_display_wrong'];
- }
-
- if (isset($item['monday'])) {
- $values['monday'] = (string) $item['monday'];
- }
-
- if (isset($item['tuesday'])) {
- $values['tuesday'] = (string) $item['tuesday'];
- }
-
- if (isset($item['wednesday'])) {
- $values['wednesday'] = (string) $item['wednesday'];
- }
-
- if (isset($item['thursday'])) {
- $values['thursday'] = (string) $item['thursday'];
- }
-
- if (isset($item['friday'])) {
- $values['friday'] = (string) $item['friday'];
- }
-
- if (isset($item['saturday'])) {
- $values['saturday'] = (string) $item['saturday'];
- }
-
- if (isset($item['sunday'])) {
- $values['sunday'] = (string) $item['sunday'];
- }
-
- if (isset($item['time_from'])) {
- $values['time_from'] = (string) $item['time_from'];
- }
-
- if (isset($item['time_to'])) {
- $values['time_to'] = (string) $item['time_to'];
- }
-
- $slas = [];
- if (!isset($item['sla'])) {
- $item['sla'] = [];
- }
-
- foreach ($item['sla'] as $sla_xml) {
- if (isset($sla_xml->agent)) {
- $agents = agents_get_agents(['id_grupo' => $group_filter], ['id_agente', 'nombre']);
-
- $agent_clean = str_replace(['[', ']'], '', $sla_xml->agent);
- $regular_expresion = ($agent_clean != $sla_xml->agent);
-
- foreach ($agents as $agent) {
- $id_agent = false;
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent['nombre']))) {
- $id_agent = $agent['id_agente'];
- } else {
- if ($agent_clean == io_safe_output($agent['nombre'])) {
- $id_agent = $agent['id_agente'];
- }
- }
- }
-
- if ($id_agent) {
- if (isset($sla_xml->module)) {
- $module_clean = str_replace(['[', ']'], '', $sla_xml->module);
- $regular_expresion = ($module_clean != $sla_xml->module);
-
- $modules = db_get_all_rows_filter(
- 'tagente_modulo',
- ['id_agente' => $id_agent],
- [
- 'id_agente_modulo',
- 'nombre',
- ]
- );
-
- foreach ($modules as $module) {
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) {
- $slas[] = [
- 'id_agent_module' => $module['id_agente_modulo'],
- 'sla_max' => (string) $sla_xml->sla_max,
- 'sla_min' => (string) $sla_xml->sla_min,
- 'sla_limit' => (string) $sla_xml->sla_limit,
- ];
- }
- } else {
- if ($module_clean == io_safe_output($module['nombre'])) {
- $slas[] = [
- 'id_agent_module' => $module['id_agente_modulo'],
- 'sla_max' => (string) $sla_xml->sla_max,
- 'sla_min' => (string) $sla_xml->sla_min,
- 'sla_limit' => (string) $sla_xml->sla_limit,
- ];
- }
- }
- }
- }
- }
- }
- }
- }
- break;
-
- case 'text':
- $values['text'] = io_safe_input($item['text']);
- break;
-
- case 'sql':
- $values['header_definition'] = io_safe_input($item['header_definition']);
- $values['external_source'] = io_safe_input($item['sql']);
- break;
-
- case 'sql_graph_pie':
- case 'sql_graph_vbar':
- case 'sql_graph_hbar':
- $values['header_definition'] = io_safe_input($item['header_definition']);
- $values['external_source'] = io_safe_input($item['sql']);
- break;
-
- case 'event_report_group':
- $values['id_agent'] = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($item->group));
- break;
-
- case 'url':
- $values['external_source'] = io_safe_input($item['url']);
- break;
-
- case 'database_serialized':
- $values['header_definition'] = io_safe_input($item['header_definition']);
- $values['line_separator'] = io_safe_input($item['line_separator']);
- $values['column_separator'] = io_safe_input($item['column_separator']);
- break;
-
- case 1:
- case 'simple_graph':
- case 'simple_baseline_graph':
- case 6:
- case 'monitor_report':
- case 7:
- case 'avg_value':
- case 8:
- case 'max_value':
- case 9:
- case 'min_value':
- case 10:
- case 'sumatory':
- case 'event_report_module':
- case 'alert_report_module':
- case 'alert_report_agent':
- case 'alert_report_group':
- case 'agent_detailed_event':
- case 'event_report_agent':
- default:
- // Do nothing.
- break;
- }
-
- if (empty($agents_item) === true) {
- $id_content = db_process_sql_insert('treport_content', $values);
- ui_print_result_message(
- $id_content,
- sprintf(__("Success add '%s' content."), $values['type']),
- sprintf(__("Error add '%s' action."), $values['type'])
- );
-
- if ($item['type'] == 'SLA') {
- foreach ($slas as $sla) {
- $sla['id_report_content'] = $id_content;
- $result = db_process_sql_insert('treport_content_sla_combined', $sla);
- ui_print_result_message(
- $result,
- sprintf(__("Success add '%s' SLA."), $sla['id_agent_module']),
- sprintf(__("Error add '%s' SLA."), $sla['id_agent_module'])
- );
- }
- }
- } else {
- foreach ($agents_item as $id_agent => $agent) {
- if (empty($agent['modules'])) {
- $values['id_agent'] = $id_agent;
- $id_content = db_process_sql_insert('treport_content', $values);
- ui_print_result_message(
- $id_content,
- sprintf(__("Success add '%s' content."), $values['type']),
- sprintf(__("Error add '%s' action."), $values['type'])
- );
- } else {
- foreach ($agent['modules'] as $id_module => $module) {
- $values['id_agent_module'] = $id_module;
- $values['id_agent'] = $id_agent;
-
- $id_content = db_process_sql_insert('treport_content', $values);
- ui_print_result_message(
- $id_content,
- sprintf(__("Success add '%s' content."), $values['type']),
- sprintf(__("Error add '%s' action."), $values['type'])
- );
- }
- }
- }
- }
- }
- }
-}
-
-
-function process_upload_xml_visualmap($xml, $filter_group=0)
-{
- global $config;
-
- foreach ($xml->xpath('/visual_map') as $visual_map) {
- if (isset($visual_map->name)) {
- $values['name'] = (string) $visual_map->name;
- } else {
- ui_print_error_message(
- __("Error create '%s' visual map, lost tag name.")
- );
- break;
- }
-
- $values['id_group'] = 0;
- if (isset($visual_map->group)) {
- $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($visual_map->group));
- if ($id_group !== false) {
- $values['id_group'] = $id_group;
- }
- }
-
- if (isset($visual_map->background)) {
- $values['background'] = (string) $visual_map->background;
- }
-
- $values['width'] = 0;
- if (isset($visual_map->width)) {
- $values['width'] = (string) $visual_map->width;
- }
-
- $values['height'] = 0;
- if (isset($visual_map->height)) {
- $values['height'] = (string) $visual_map->height;
- }
-
- $posible_name = $values['name'];
- $exist = true;
- $loops = 30;
- // Loops to exit or tries
- while ($exist && $loops > 0) {
- $exist = (bool) db_get_row_filter('tlayout', ['name' => io_safe_input($posible_name)]);
-
- if ($exist) {
- $loops--;
- $posible_name = $values['name'].' ('.(30 - $loops).')';
- }
- }
-
- if ($exist) {
- ui_print_error_message(
- sprintf(
- __("Error create '%s' visual map, the name exist and there aren't free name."),
- $values['name']
- )
- );
- continue;
- } else if ($loops != 30) {
- ui_print_error_message(
- sprintf(
- __("Warning create '%s' visual map, the name exist, the report have a name %s."),
- $values['name'],
- $posible_name
- )
- );
- }
-
- $values['name'] = io_safe_input($posible_name);
- $id_visual_map = db_process_sql_insert('tlayout', $values);
-
- ui_print_result_message(
- (bool) $id_visual_map,
- sprintf(__("Success create '%s' visual map."), $posible_name),
- sprintf(__("Error create '%s' visual map."), $posible_name)
- );
-
- if ($id_visual_map !== false) {
- db_pandora_audit(
- AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT,
- sprintf('Create Visual Console #%s', $id_visual_map),
- $config['id_user']
- );
- } else {
- break;
- }
-
- $relation_other_ids = [];
-
- foreach ($visual_map->item as $item) {
- $no_agents = true;
-
- if (isset($item->agent)) {
- $agent_clean = str_replace(['[', ']'], '', $item->agent);
- $regular_expresion = ($agent_clean != $item->agent);
-
- $agents = agents_get_agents(['id_grupo' => $filter_group], ['id_agente', 'nombre']);
- if ($agents === false) {
- $agents = [];
- }
-
- $temp = [];
- foreach ($agents as $agent) {
- $temp[$agent['id_agente']] = $agent['nombre'];
- }
-
- $agents = $temp;
-
- $agents_in_item = [];
- foreach ($agents as $id => $agent) {
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$agent_clean.'/', io_safe_output($agent))) {
- $agents_in_item[$id]['name'] = $agent;
- $no_agents = false;
- }
- } else {
- if ($agent_clean == io_safe_output($agent)) {
- $agents_in_item[$id]['name'] = $agent;
- $no_agents = false;
- break;
- }
- }
- }
- }
-
- $no_modules = true;
- if (isset($item->module)) {
- $module_clean = str_replace(['[', ']'], '', $item->module);
- $regular_expresion = ($module_clean != $item->module);
-
- foreach ($agents_in_item as $id => $agent) {
- $modules = db_get_all_rows_filter(
- 'tagente_modulo',
- ['id_agente' => $id],
- [
- 'id_agente_modulo',
- 'nombre',
- ]
- );
-
- $modules_in_item = [];
- foreach ($modules as $module) {
- if ($regular_expresion) {
- if ((bool) preg_match('/'.$module_clean.'/', io_safe_output($module['nombre']))) {
- $modules_in_item[$module['id_agente_modulo']] = $module['nombre'];
- $no_modules = false;
- }
- } else {
- if ($module_clean == io_safe_output($module['nombre'])) {
- $modules_in_item[$module['id_agente_modulo']] = $module['nombre'];
- $no_modules = false;
- break;
- }
- }
- }
-
- $agents_in_item[$id]['modules'] = $modules_in_item;
- }
- }
-
- $values = [];
-
- $values['id_layout'] = $id_visual_map;
- if (isset($item->label)) {
- $values['label'] = io_safe_input($item->label);
- }
-
- if (isset($item->x)) {
- $values['pos_x'] = (string) $item->x;
- }
-
- if (isset($item->y)) {
- $values['pos_y'] = (string) $item->y;
- }
-
- if (isset($item->height)) {
- $values['height'] = (string) $item->height;
- }
-
- if (isset($item->width)) {
- $values['width'] = (string) $item->width;
- }
-
- if (isset($item->image)) {
- $values['image'] = (string) $item->image;
- }
-
- if (isset($item->period)) {
- $values['period'] = (string) $item->period;
- }
-
- if (isset($item->parent_item)) {
- // Hack for link the items use the OTHER_ID
- // and have too OTHER_ID
- // then $relation_other_ids[OTHER_ID] have the item_id in DB.
- $values['parent_item'] = (string) $relation_other_ids[(string) $item->parent_item];
- }
-
- if (isset($item->map_linked)) {
- $values['id_layout_linked'] = (string) $item->map_linked;
- }
-
- if (isset($item->type)) {
- $values['type'] = (string) $item->type;
- }
-
- if (isset($item->clock_animation)) {
- $values['clock_animation'] = (string) $item->clock_animation;
- }
-
- if (isset($item->fill_color)) {
- $values['fill_color'] = (string) $item->fill_color;
- }
-
- if (isset($item->type_graph)) {
- $values['type_graph'] = (string) $item->type_graph;
- }
-
- if (isset($item->time_format)) {
- $values['time_format'] = (string) $item->time_format;
- }
-
- if (isset($item->timezone)) {
- $values['timezone'] = (string) $item->timezone;
- }
-
- if (isset($item->border_width)) {
- $values['border_width'] = (string) $item->border_width;
- }
-
- if (isset($item->border_color)) {
- $values['border_color'] = (string) $item->border_color;
- }
-
- if ($no_agents) {
- $id_item = db_process_sql_insert('tlayout_data', $values);
-
- ui_print_result_message(
- (bool) $id_item,
- sprintf(__("Success create item type '%d' visual map."), $values['type']),
- sprintf(__("Error create item type '%d' visual map."), $values['type'])
- );
-
- if ($id_item !== false) {
- db_pandora_audit(
- AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT,
- sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']),
- $config['id_user']
- );
- }
- } else {
- foreach ($agents_in_item as $id => $agent) {
- if ($no_modules) {
- $values['id_agent'] = $id;
-
- $id_item = db_process_sql_insert('tlayout_data', $values);
-
- if (isset($item->other_id) === true) {
- $relation_other_ids[(string) $item->other_id] = $id_item;
- }
-
- ui_print_result_message(
- (bool) $id_item,
- sprintf(__("Success create item for agent '%s' visual map."), $agent['name']),
- sprintf(__("Error create item for agent '%s' visual map."), $agent['name'])
- );
-
- if ($id_item !== false) {
- db_pandora_audit(
- AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT,
- sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']),
- $config['id_user']
- );
- }
- } else {
- // TODO: Review this else.
- foreach ($agent['modules'] as $id_module => $module) {
- $values['id_agent'] = $id;
- $values['id_agente_modulo'] = $id_module;
-
- db_process_sql_insert('tlayout_data', $values);
-
- ui_print_result_message(
- (bool) $id_item,
- sprintf(__("Success create item for agent '%s' visual map."), $agent['name']),
- sprintf(__("Error create item for agent '%s' visual map."), $agent['name'])
- );
-
- if ($id_item !== false) {
- db_pandora_audit(
- AUDIT_LOG_VISUAL_CONSOLE_MANAGEMENT,
- sprintf('Create Item %s in Visual Console #%s', $id_item, $values['id_layout']),
- $config['id_user']
- );
- }
- }
- }
- }
- }
- }
- }
-}
-
-
-function process_upload_xml_component($xml)
-{
- // Extract components.
- $components = [];
- foreach ($xml->xpath('/component') as $componentElement) {
- $name = io_safe_input((string) $componentElement->name);
- $id_os = (int) $componentElement->id_os;
- $os_version = io_safe_input((string) $componentElement->os_version);
- $data = io_safe_input((string) $componentElement->data);
- $type = (int) $componentElement->type;
- $group = (int) $componentElement->group;
- $description = io_safe_input((string) $componentElement->description);
- $module_interval = (int) $componentElement->module_interval;
- $max = (float) $componentElement->max;
- $min = (float) $componentElement->min;
- $tcp_send = io_safe_input((string) $componentElement->tcp_send);
- $tcp_rcv_text = io_safe_input((string) $componentElement->tcp_rcv_text);
- $tcp_port = (int) $componentElement->tcp_port;
- $snmp_oid = io_safe_input((string) $componentElement->snmp_oid);
- $snmp_community = io_safe_input((string) $componentElement->snmp_community);
- $id_module_group = (int) $componentElement->id_module_group;
- $module_source = (int) $componentElement->module_source;
- $plugin = (int) $componentElement->plugin;
- $plugin_username = io_safe_input((string) $componentElement->plugin_username);
- $plugin_password = io_safe_input((string) $componentElement->plugin_password);
- $plugin_parameters = io_safe_input((string) $componentElement->plugin_parameters);
- $max_timeout = (int) $componentElement->max_timeout;
- $max_retries = (int) $componentElement->max_retries;
- $historical_data = (int) $componentElement->historical_data;
- $dynamic_interval = (int) $componentElement->dynamic_interval;
- $dynamic_min = (int) $componentElement->dynamic_min;
- $dynamic_max = (int) $componentElement->dynamic_max;
- $dynamic_two_tailed = (int) $componentElement->dynamic_two_tailed;
- $min_war = (float) $componentElement->min_war;
- $max_war = (float) $componentElement->max_war;
- $str_war = (string) $componentElement->str_war;
- $min_cri = (float) $componentElement->min_cri;
- $max_cri = (float) $componentElement->max_cri;
- $str_cri = (string) $componentElement->str_cri;
- $ff_treshold = (int) $componentElement->ff_treshold;
- $snmp_version = (int) $componentElement->snmp_version;
- $auth_user = io_safe_input((string) $componentElement->auth_user);
- $auth_password = io_safe_input((string) $componentElement->auth_password);
- $auth_method = io_safe_input((string) $componentElement->auth_method);
- $privacy_method = io_safe_input((string) $componentElement->privacy_method);
- $privacy_pass = io_safe_input((string) $componentElement->privacy_pass);
- $security_level = io_safe_input((string) $componentElement->security_level);
- $wmi_query = io_safe_input((string) $componentElement->wmi_query);
- $key_string = io_safe_input((string) $componentElement->key_string);
- $field_number = (int) $componentElement->field_number;
- $namespace = io_safe_input((string) $componentElement->namespace);
- $wmi_user = io_safe_input((string) $componentElement->wmi_user);
- $wmi_password = io_safe_input((string) $componentElement->wmi_password);
- $post_process = io_safe_input((float) $componentElement->post_process);
-
- $idComponent = false;
- switch ((int) $componentElement->module_source) {
- case 1:
- // Local component.
- $values = [
- 'description' => $description,
- 'id_network_component_group' => $group,
- 'os_version' => $os_version,
- ];
- $return = enterprise_hook('local_components_create_local_component', [$name, $data, $id_os, $values]);
- if ($return !== ENTERPRISE_NOT_HOOK) {
- $idComponent = $return;
- }
- break;
-
- case 2:
- // Network component
- // for modules
- // 15 = remote_snmp, 16 = remote_snmp_inc,
- // 17 = remote_snmp_string, 18 = remote_snmp_proc.
- $custom_string_1 = '';
- $custom_string_2 = '';
- $custom_string_3 = '';
- if ($type >= 15 && $type <= 18) {
- // New support for snmp v3.
- $tcp_send = $snmp_version;
- $plugin_user = $auth_user;
- $plugin_pass = $auth_password;
- $plugin_parameters = $auth_method;
- $custom_string_1 = $privacy_method;
- $custom_string_2 = $privacy_pass;
- $custom_string_3 = $security_level;
- }
-
- $idComponent = network_components_create_network_component(
- $name,
- $type,
- $group,
- [
- 'description' => $description,
- 'module_interval' => $module_interval,
- 'max' => $max,
- 'min' => $min,
- 'tcp_send' => $tcp_send,
- 'tcp_rcv' => $tcp_rcv_text,
- 'tcp_port' => $tcp_port,
- 'snmp_oid' => $snmp_oid,
- 'snmp_community' => $snmp_community,
- 'id_module_group' => $id_module_group,
- 'id_modulo' => $module_source,
- 'id_plugin' => $plugin,
- 'plugin_user' => $plugin_username,
- 'plugin_pass' => $plugin_password,
- 'plugin_parameter' => $plugin_parameters,
- 'max_timeout' => $max_timeout,
- 'max_retries' => $max_retries,
- 'history_data' => $historical_data,
- 'dynamic_interval' => $dynamic_interval,
- 'dynamic_min' => $dynamic_min,
- 'dynamic_max' => $dynamic_max,
- 'dynamic_two_tailed' => $dynamic_two_tailed,
- 'min_warning' => $min_war,
- 'max_warning' => $max_war,
- 'str_warning' => $str_war,
- 'min_critical' => $min_cri,
- 'max_critical' => $max_cri,
- 'str_critical' => $str_cri,
- 'min_ff_event' => $ff_treshold,
- 'custom_string_1' => $custom_string_1,
- 'custom_string_2' => $custom_string_2,
- 'custom_string_3' => $custom_string_3,
- 'post_process' => $post_process,
- ]
- );
- if ((bool) $idComponent === true) {
- $components[] = $idComponent;
- }
- break;
-
- case 4:
- // Plugin component.
- $idComponent = network_components_create_network_component(
- $name,
- $type,
- $group,
- [
- 'description' => $description,
- 'module_interval' => $module_interval,
- 'max' => $max,
- 'min' => $min,
- 'tcp_send' => $tcp_send,
- 'tcp_rcv' => $tcp_rcv_text,
- 'tcp_port' => $tcp_port,
- 'snmp_oid' => $snmp_oid,
- 'snmp_community' => $snmp_community,
- 'id_module_group' => $id_module_group,
- 'id_modulo' => $module_source,
- 'id_plugin' => $plugin,
- 'plugin_user' => $plugin_username,
- 'plugin_pass' => $plugin_password,
- 'plugin_parameter' => $plugin_parameters,
- 'max_timeout' => $max_timeout,
- 'max_retries' => $max_retries,
- 'history_data' => $historical_data,
- 'dynamic_interval' => $dynamic_interval,
- 'dynamic_min' => $dynamic_min,
- 'dynamic_max' => $dynamic_max,
- 'dynamic_two_tailed' => $dynamic_two_tailed,
- 'min_warning' => $min_war,
- 'max_warning' => $max_war,
- 'str_warning' => $str_war,
- 'min_critical' => $min_cri,
- 'max_critical' => $max_cri,
- 'str_critical' => $str_cri,
- 'min_ff_event' => $ff_treshold,
- 'custom_string_1' => $custom_string_1,
- 'custom_string_2' => $custom_string_2,
- 'custom_string_3' => $custom_string_3,
- 'post_process' => $post_process,
- ]
- );
- if ((bool) $idComponent === true) {
- $components[] = $idComponent;
- }
- break;
-
- case 6:
- // WMI component.
- $idComponent = network_components_create_network_component(
- $name,
- $type,
- $group,
- [
- 'description' => $description,
- 'module_interval' => $module_interval,
- 'max' => $max,
- 'min' => $min,
- 'tcp_send' => $namespace,
- // work around
- 'tcp_rcv' => $tcp_rcv_text,
- 'tcp_port' => $field_number,
- // work around
- 'snmp_oid' => $wmi_query,
- // work around
- 'snmp_community' => $key_string,
- // work around
- 'id_module_group' => $id_module_group,
- 'id_modulo' => $module_source,
- 'id_plugin' => $plugin,
- 'plugin_user' => $wmi_user,
- // work around
- 'plugin_pass' => $wmi_password,
- // work around
- 'plugin_parameter' => $plugin_parameters,
- 'max_timeout' => $max_timeout,
- 'max_retries' => $max_retries,
- 'history_data' => $historical_data,
- 'dynamic_interval' => $dynamic_interval,
- 'dynamic_min' => $dynamic_min,
- 'dynamic_max' => $dynamic_max,
- 'dynamic_two_tailed' => $dynamic_two_tailed,
- 'min_warning' => $min_war,
- 'max_warning' => $max_war,
- 'str_warning' => $str_war,
- 'min_critical' => $min_cri,
- 'max_critical' => $max_cri,
- 'str_critical' => $str_cri,
- 'min_ff_event' => $ff_treshold,
- 'custom_string_1' => $custom_string_1,
- 'custom_string_2' => $custom_string_2,
- 'custom_string_3' => $custom_string_3,
- 'post_process' => $post_process,
- ]
- );
- if ((bool) $idComponent === true) {
- $components[] = $idComponent;
- }
- break;
-
- case 5:
- // Prediction component.
- case 7:
- // Web component.
- default:
- // Do nothing.
- break;
- }
-
- ui_print_result_message(
- (bool) $idComponent,
- sprintf(__("Success create '%s' component."), $name),
- sprintf(__("Error create '%s' component."), $name)
- );
- }
-
- // Extract the template.
- $templateElement = $xml->xpath('//template');
- if (empty($templateElement) === false) {
- $templateElement = $templateElement[0];
-
- $templateName = (string) $templateElement->name;
- $templateDescription = (string) $templateElement->description;
-
- $idTemplate = db_process_sql_insert('tnetwork_profile', ['name' => $templateName, 'description' => $templateDescription]);
-
- $result = false;
- if ((bool) $idTemplate) {
- foreach ($components as $idComponent) {
- db_process_sql_insert('tnetwork_profile_component', ['id_nc' => $idComponent, 'id_np' => $idTemplate]);
- }
- }
- }
-}
-
-
-function process_upload_xml($xml)
-{
- $hook_enterprise = enterprise_include('extensions/resource_registration/functions.php');
-
- // Extract component.
- process_upload_xml_component($xml);
-
- $group_filter = get_parameter('group');
-
- // Extract visual map.
- process_upload_xml_visualmap($xml, $group_filter);
-
- // Extract policies.
- if ($hook_enterprise === true) {
- $centralized_management = is_management_allowed();
- if ($centralized_management === true) {
- process_upload_xml_policy($xml, $group_filter);
- }
- }
-
- // Extract reports.
- process_upload_xml_report($xml, $group_filter);
-}
-
-
-function resource_registration_extension_main()
-{
- global $config;
-
- if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user'])) {
- db_pandora_audit(
- AUDIT_LOG_ACL_VIOLATION,
- 'Trying to access Setup Management'
- );
- include 'general/noaccess.php';
- return;
- }
-
- include_once $config['homedir'].'/include/functions_network_components.php';
- include_once $config['homedir'].'/include/functions_db.php';
- enterprise_include_once('include/functions_local_components.php');
-
- ui_print_standard_header(
- __('Resource registration'),
- 'images/extensions.png',
- false,
- '',
- true,
- [],
- [
- [
- 'link' => '',
- 'label' => __('Resources'),
- ],
- [
- 'link' => '',
- 'label' => __('Resource registration'),
- ],
- ]
- );
-
- if (extension_loaded('libxml') === false) {
- ui_print_error_message(_('Error, please install the PHP libXML in the system.'));
-
- return;
- }
-
- if (is_management_allowed() === false) {
- if (is_metaconsole() === false) {
- $url = ''.__('metaconsole').'';
- } else {
- $url = __('any node');
- }
-
- ui_print_warning_message(
- __(
- 'This node is configured with centralized mode. Go to %s to create a policy.',
- $url
- )
- );
-
- return;
- }
-
- ui_print_warning_message(
- __('This extension makes registering resource templates easier.').'
'.__('Here you can upload a resource template in .ptr format.').'
'.__('Please refer to our documentation for more information on how to obtain and use %s resources.', get_product_name()).' '.'
'.__('You can get more resurces in our Public Resource Library')
- );
-
- $table = new stdClass();
- $table->class = 'databox filter-table-adv';
- $table->id = 'resource_registration_table';
-
- $table->data = [];
-
- $table->data[0][] = html_print_label_input_block(
- __('File to upload'),
- html_print_input_file('resource_upload', true)
- );
-
- $table->data[0][] = html_print_label_input_block(
- __('Group filter'),
- html_print_select_groups(false, 'AW', true, 'group', '', '', __('All'), 0, true)
- );
-
- // Upload form.
- echo '
';
- /*
- echo '';*/
-
- if (isset($_FILES['resource_upload']['tmp_name']) === false) {
- return;
- }
-
- $xml = simplexml_load_file($_FILES['resource_upload']['tmp_name'], null, LIBXML_NOCDATA);
-
- if ($xml === false) {
- ui_print_error_message(
- __('Error uploading resource. Check if the selected file is a valid resource template in .ptr format')
- );
- } else {
- process_upload_xml($xml);
- }
-}
-
-
-extensions_add_godmode_menu_option(__('Resource registration'), 'PM', 'gagente', '', 'v1r1');
-extensions_add_godmode_function('resource_registration_extension_main');
diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt
index f3eada8070..b3fbea46dd 100644
--- a/pandora_console/extras/delete_files/delete_files.txt
+++ b/pandora_console/extras/delete_files/delete_files.txt
@@ -1736,3 +1736,5 @@ extensions/files_repo/sql/files_repo.oracle.sql
extensions/files_repo/sql/files_repo.postgreSQL.sql
extensions/files_repo/sql/files_repo.sql
extensions/files_repo
+extensions/resource_exportation.php
+extensions/resource_registration.php
diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php
index 3505e7cf2c..68d789cd74 100644
--- a/pandora_console/godmode/menu.php
+++ b/pandora_console/godmode/menu.php
@@ -208,6 +208,9 @@ if ($access_console_node === true) {
$sub['godmode/setup/os']['text'] = __('Operating systems');
$sub['godmode/setup/os']['id'] = 'edit_OS';
+
+ $sub['godmode/resources/resources_export_import']['text'] = __('Resources export/import');
+ $sub['godmode/resources/resources_export_import']['id'] = 'resources_export_import';
}
if ((bool) check_acl($config['id_user'], 0, 'AW') === true) {
diff --git a/pandora_console/godmode/resources/resources_export_import.php b/pandora_console/godmode/resources/resources_export_import.php
new file mode 100644
index 0000000000..86583ec69b
--- /dev/null
+++ b/pandora_console/godmode/resources/resources_export_import.php
@@ -0,0 +1,404 @@
+importPrd($data);
+ } else {
+ $msg = [
+ 'status' => false,
+ 'items' => [],
+ 'errors' => ['Unexpected error: Unable to parse PRD file.'],
+ ];
+ }
+ } else {
+ $msg = [
+ 'status' => false,
+ 'items' => [],
+ 'errors' => ['No files have selected'],
+ ];
+ }
+}
+
+$msg = json_encode($msg);
+
+echo '';
+// Import section.
+$label_import = html_print_label(
+ __('Import resources to').' '.get_product_name(),
+ 'label_import',
+ true,
+ ['style' => 'font-size: 13px; line-height: 16px'],
+);
+
+$div_label_import = html_print_div(
+ [
+ 'style' => 'padding-bottom: 20px;',
+ 'content' => $label_import,
+ ],
+ true
+);
+
+$input_file = '';
+
+$div_input_file = html_print_div(
+ [
+ 'style' => 'padding-top: 20px;display: flex; justify-content: left;width:100%; height: 60px;',
+ 'content' => $input_file,
+ ],
+ true
+);
+
+$button_import = html_print_submit_button(
+ __('Import'),
+ 'upload',
+ false,
+ [
+ 'icon' => 'import',
+ 'class' => 'disabled',
+ 'disabled' => '',
+ ],
+ true
+);
+
+$div_button_import = html_print_div(
+ [
+ 'style' => 'padding-bottom: 20px',
+ 'content' => $button_import,
+ ],
+ true
+);
+
+$div_import = html_print_div(
+ [
+ 'style' => 'width: 80%',
+ 'content' => $div_label_import.$div_input_file.$div_button_import,
+ ],
+ true
+);
+
+$img_import = html_print_image(
+ 'images/import_to.svg',
+ true,
+ [
+ 'border' => '0',
+ 'width' => '100%',
+ ]
+);
+
+$div_img_import = html_print_div(
+ [
+ 'style' => 'margin-left: 40px; margin-right: 20px',
+ 'content' => $img_import,
+ ],
+ true
+);
+
+echo '';
+
+
+// Export section.
+$label_export = html_print_label(
+ __('Export resources from').' '.get_product_name(),
+ 'label_export',
+ true,
+ ['style' => 'font-size: 13px; line-height: 16px'],
+);
+
+$div_label_export = html_print_div(
+ [
+ 'style' => 'padding-bottom: 20px',
+ 'content' => $label_export,
+ ],
+ true
+);
+
+$export_type = $prd->getTypesPrd();
+
+$select_export_type = html_print_label_input_block(
+ __('Export type'),
+ html_print_select(
+ $export_type,
+ 'export_type',
+ '',
+ '',
+ __('None'),
+ 0,
+ true,
+ false,
+ true,
+ 'w90p'
+ ),
+ ['div_style' => 'display: flex; flex-direction: column; width: 50%'],
+);
+
+$div_select_export = html_print_div(
+ [
+ 'id' => 'div_select_export',
+ 'style' => 'padding-bottom: 20px;display: flex; flex-direction: row; height: 60px',
+ 'content' => $select_export_type,
+ ],
+ true
+);
+
+$button_export = html_print_button(
+ __('Export'),
+ 'export_button',
+ false,
+ '',
+ [
+ 'class' => 'flex_justify disabled',
+ 'icon' => 'export',
+ 'disabled' => '',
+ ],
+ true
+);
+
+$div_button_export = html_print_div(
+ [
+ 'style' => '',
+ 'content' => $button_export,
+ ],
+ true
+);
+
+$div_export = html_print_div(
+ [
+ 'style' => 'padding-bottom: 20px; width: 80%',
+ 'content' => $div_label_export.$div_select_export.$div_button_export,
+ ],
+ true
+);
+
+$img_export = html_print_image(
+ 'images/export_to.svg',
+ true,
+ [
+ 'border' => '0',
+ 'width' => '100%',
+ ]
+);
+
+$div_img_export = html_print_div(
+ [
+ 'style' => 'margin-left: 40px; margin-right: 20px',
+ 'content' => $img_export,
+ ],
+ true
+);
+
+echo html_print_div(
+ [
+ 'class' => 'div-export',
+ 'content' => $div_export.$div_img_export,
+ ],
+ true
+);
+
+echo '
';
+
+?>
+
\ No newline at end of file
diff --git a/pandora_console/images/export.svg b/pandora_console/images/export.svg
new file mode 100644
index 0000000000..7d26fc3fed
--- /dev/null
+++ b/pandora_console/images/export.svg
@@ -0,0 +1,18 @@
+
+
\ No newline at end of file
diff --git a/pandora_console/images/export_to.svg b/pandora_console/images/export_to.svg
new file mode 100644
index 0000000000..d5b9beac66
--- /dev/null
+++ b/pandora_console/images/export_to.svg
@@ -0,0 +1,25 @@
+
+
\ No newline at end of file
diff --git a/pandora_console/images/import.svg b/pandora_console/images/import.svg
new file mode 100644
index 0000000000..18a77c8c0d
--- /dev/null
+++ b/pandora_console/images/import.svg
@@ -0,0 +1,18 @@
+
+
\ No newline at end of file
diff --git a/pandora_console/images/import_to.svg b/pandora_console/images/import_to.svg
new file mode 100644
index 0000000000..0dee1bb4a3
--- /dev/null
+++ b/pandora_console/images/import_to.svg
@@ -0,0 +1,24 @@
+
+
\ No newline at end of file
diff --git a/pandora_console/include/ajax/resources.ajax.php b/pandora_console/include/ajax/resources.ajax.php
new file mode 100644
index 0000000000..0e34d756c0
--- /dev/null
+++ b/pandora_console/include/ajax/resources.ajax.php
@@ -0,0 +1,115 @@
+getOnePrdData($type);
+ if (empty($data) === false) {
+ $sql = sprintf(
+ 'SELECT %s FROM %s',
+ reset($data['items']['value']).', '.reset($data['items']['show']),
+ $data['items']['table']
+ );
+ $result = html_print_label_input_block(
+ $data['label'],
+ io_safe_output(
+ html_print_select_from_sql(
+ $sql,
+ 'select_value',
+ '',
+ '',
+ '',
+ 0,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ GENERIC_SIZE_TEXT,
+ 'w90p',
+ ),
+ ),
+ [
+ 'div_style' => 'display: flex; flex-direction: column; width: 50%',
+ 'div_id' => 'resource_type',
+ ],
+ );
+ }
+
+ echo $result;
+ return;
+ }
+
+ if ($exportPrd === true) {
+ $type = (string) get_parameter('type', '');
+ $value = (int) get_parameter('value', 0);
+ $name = (string) get_parameter('name', '');
+ $filename = (string) get_parameter('filename', '');
+
+ try {
+ $data = $prd->exportPrd($type, $value, $name);
+ } catch (\Exception $e) {
+ $data = '';
+ }
+
+ $return = [];
+
+ if (empty($data) === false) {
+ $filename_download = date('YmdHis').'-'.$type.'-'.$name.'.prd';
+ $file = $config['attachment_store'].'/'.$filename;
+
+ $file_pointer = fopen($file, 'a');
+ if ($file_pointer !== false) {
+ $write = fwrite($file_pointer, $data);
+
+ if ($write === false) {
+ $return['error'] = -2;
+ unlink($config['attachment_store'].'/'.$filename);
+ } else {
+ $return['name'] = $filename;
+ $return['name_download'] = $filename_download;
+ }
+
+ fclose($file_pointer);
+ } else {
+ $return['error'] = -1;
+ }
+ }
+
+ echo json_encode($return);
+
+ return;
+ }
+
+ if ($deleteFile === true) {
+ $filename = (string) get_parameter('filename', '');
+
+ unlink($config['attachment_store'].'/'.$filename);
+ }
+}
diff --git a/pandora_console/include/class/Prd.class.php b/pandora_console/include/class/Prd.class.php
new file mode 100644
index 0000000000..cfd6e754f8
--- /dev/null
+++ b/pandora_console/include/class/Prd.class.php
@@ -0,0 +1,3710 @@
+prdData = [
+ 'visual_console' => [
+ 'label' => __('Visual console'),
+ 'items' => [
+ 'table' => 'tlayout',
+ 'value' => ['id'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'tlayout_data',
+ 'ref' => ['id_layout'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ 'custom_report' => [
+ 'label' => __('Custom report'),
+ 'items' => [
+ 'table' => 'treport',
+ 'value' => ['id_report'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'treport_content',
+ 'ref' => ['id_report'],
+ 'value' => ['id_rc'],
+ 'data' => [
+ [
+ 'table' => 'treport_content_item',
+ 'ref' => ['id_report_content'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'treport_content_sla_combined',
+ 'ref' => ['id_report_content'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ 'policy' => [
+ 'label' => __('Policy'),
+ 'items' => [
+ 'table' => 'tpolicies',
+ 'value' => ['id'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'tpolicy_agents',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'tpolicy_modules',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ 'data' => [
+ [
+ 'table' => 'ttag_policy_module',
+ 'ref' => ['id_policy_module'],
+ 'value' => [
+ 'id_tag',
+ 'id_policy_module',
+ ],
+ ],
+ [
+ 'table' => 'tpolicy_modules_synth',
+ 'ref' => ['id_agent_module_target'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ [
+ 'table' => 'tpolicy_alerts',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ 'data' => [
+ [
+ 'table' => 'tpolicy_alerts_actions',
+ 'ref' => ['id_policy_alert'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ [
+ 'table' => 'tpolicy_collections',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'tpolicy_group_agents',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'tpolicy_groups',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'tpolicy_modules_inventory',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'tpolicy_plugins',
+ 'ref' => ['id_policy'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ 'service' => [
+ 'label' => __('Service'),
+ 'items' => [
+ 'table' => 'tservice',
+ 'value' => ['id'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'tservice_element',
+ 'ref' => ['id_service'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ 'network_map' => [
+ 'label' => __('Network map'),
+ 'items' => [
+ 'table' => 'tmap',
+ 'value' => ['id'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'titem',
+ 'ref' => ['id_map'],
+ 'value' => ['id'],
+ ],
+ [
+ 'table' => 'trel_item',
+ 'ref' => ['id_map'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ 'gis_map' => [
+ 'label' => __('GIS map'),
+ 'items' => [
+ 'table' => 'tgis_map',
+ 'value' => ['id_tgis_map'],
+ 'show' => ['map_name'],
+ 'data' => [
+ [
+ 'table' => 'tgis_map_layer',
+ 'ref' => ['tgis_map_id_tgis_map'],
+ 'value' => ['id_tmap_layer'],
+ 'data' => [
+ [
+ 'table' => 'tgis_map_layer_groups',
+ 'ref' => ['layer_id'],
+ 'value' => [
+ 'layer_id',
+ 'group_id',
+ ],
+ ],
+ [
+ 'table' => 'tgis_map_layer_has_tagente',
+ 'ref' => ['tgis_map_layer_id_tmap_layer'],
+ 'value' => [
+ 'tgis_map_layer_id_tmap_layer',
+ 'tagente_id_agente',
+ ],
+ ],
+ ],
+ ],
+ [
+ 'table' => 'tgis_map_has_tgis_map_con',
+ 'ref' => ['tgis_map_id_tgis_map'],
+ 'value' => [
+ 'tgis_map_id_tgis_map',
+ 'tgis_map_con_id_tmap_con',
+ ],
+ ],
+ ],
+ ],
+ ],
+ 'custom_graph' => [
+ 'label' => __('Custom graph'),
+ 'items' => [
+ 'table' => 'tgraph',
+ 'value' => ['id_graph'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'tgraph_source',
+ 'ref' => ['id_graph'],
+ 'value' => ['id_gs'],
+ ],
+ ],
+ ],
+ ],
+ 'dashboard' => [
+ 'label' => __('Dashboard'),
+ 'items' => [
+ 'table' => 'tdashboard',
+ 'value' => ['id'],
+ 'show' => ['name'],
+ 'data' => [
+ [
+ 'table' => 'twidget_dashboard',
+ 'ref' => ['id_dashboard'],
+ 'value' => ['id'],
+ ],
+ ],
+ ],
+ ],
+ ];
+
+ // Define variables for tables references
+ // Variables order is very important due to hierarchy.
+ $this->tgrupo = [
+ 'table' => 'tgrupo',
+ 'id' => 'id_grupo',
+ 'columns' => ['nombre'],
+ 'autocreate_item' => 'agent_groups',
+ ];
+
+ $this->ttipoModulo = [
+ 'table' => 'ttipo_modulo',
+ 'id' => 'id_tipo',
+ 'columns' => ['nombre'],
+ ];
+
+ $this->tmoduleGroup = [
+ 'table' => 'tmodule_group',
+ 'id' => 'id_mg',
+ 'columns' => ['name'],
+ 'autocreate_item' => 'module_groups',
+ ];
+
+ $this->tconfigOs = [
+ 'table' => 'tconfig_os',
+ 'id' => 'id_os',
+ 'columns' => ['name'],
+ 'autocreate_item' => 'operating_systems',
+ ];
+
+ $this->tcategory = [
+ 'table' => 'tcategory',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ 'autocreate_item' => 'categories',
+ ];
+
+ $this->ttag = [
+ 'table' => 'ttag',
+ 'id' => 'id_tag',
+ 'columns' => ['name'],
+ 'autocreate_item' => 'tags',
+ ];
+
+ $this->tagente = [
+ 'table' => 'tagente',
+ 'id' => 'id_agente',
+ 'columns' => ['nombre'],
+ ];
+
+ $this->tagenteModulo = [
+ 'table' => 'tagente_modulo',
+ 'id' => 'id_agente_modulo',
+ 'columns' => ['nombre'],
+ 'join' => ['id_agente' => $this->tagente],
+ ];
+
+ $this->tplugin = [
+ 'table' => 'tplugin',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tmoduleInventory = [
+ 'table' => 'tmodule_inventory',
+ 'id' => 'id_module_inventory',
+ 'columns' => ['name'],
+ 'join' => ['id_os' => $this->tconfigOs],
+ ];
+
+ $this->tpolicies = [
+ 'table' => 'tpolicies',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tpolicyModules = [
+ 'table' => 'tpolicy_modules',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ 'join' => ['id_policy' => $this->tpolicies],
+ ];
+
+ $this->talertActions = [
+ 'table' => 'talert_actions',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->talertTemplates = [
+ 'table' => 'talert_templates',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tcollection = [
+ 'table' => 'tcollection',
+ 'id' => 'id',
+ 'columns' => ['short_name'],
+ ];
+
+ $this->tgraph = [
+ 'table' => 'tgraph',
+ 'id' => 'id_graph',
+ 'columns' => ['name'],
+ ];
+
+ $this->tservice = [
+ 'table' => 'tservice',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tlayout = [
+ 'table' => 'tlayout',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tlayoutData = [
+ 'table' => 'tlayout_data',
+ 'id' => 'id',
+ 'columns' => [
+ 'pos_x',
+ 'pos_y',
+ 'height',
+ 'width',
+ 'type',
+ ],
+ 'join' => ['id_layout' => $this->tlayout],
+ ];
+
+ $this->treportCustomSql = [
+ 'table' => 'treport_custom_sql',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->tserverExport = [
+ 'table' => 'tserver_export',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->treconTask = [
+ 'table' => 'trecon_task',
+ 'id' => 'id_rt',
+ 'columns' => [
+ 'name',
+ 'type',
+ ],
+ ];
+
+ $this->tmap = [
+ 'table' => 'tmap',
+ 'id' => 'id',
+ 'columns' => ['name'],
+ ];
+
+ $this->titem = [
+ 'table' => 'titem',
+ 'id' => 'id',
+ 'columns' => [
+ 'id_map',
+ 'type',
+ 'source_data',
+ 'x',
+ 'y',
+ 'z',
+ ],
+ ];
+
+ $this->tgisMapConnection = [
+ 'table' => 'tgis_map_connection',
+ 'id' => 'id_tmap_connection',
+ 'columns' => ['conection_name'],
+ ];
+
+ $this->tserver = [
+ 'table' => 'tserver',
+ 'id' => 'id_server',
+ 'columns' => [
+ 'name',
+ 'server_type',
+ ],
+ ];
+
+ $this->twidget = [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'columns' => ['unique_name'],
+ ];
+
+ $this->treport = [
+ 'table' => 'treport',
+ 'id' => 'id_report',
+ 'columns' => ['name'],
+ ];
+
+ $this->tnetflowFilter = [
+ 'table' => 'tnetflow_filter',
+ 'id' => 'id_sg',
+ 'columns' => [
+ 'ip_dst',
+ 'ip_src',
+ 'dst_port',
+ 'src_port',
+ 'router_ip',
+ 'advanced_filter',
+ 'filter_args',
+ 'aggregate',
+ 'netflow_monitoring',
+ 'traffic_max',
+ 'traffic_critical',
+ 'traffic_warning',
+ 'netflow_monitoring_interval',
+ ],
+ ];
+
+ // Define references between tables fields.
+ $this->columnRefs = [
+ 'tlayout' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ ],
+ 'tlayout_data' => [
+ 'id_agente_modulo' => ['ref' => $this->tagenteModulo],
+ 'id_agent' => ['ref' => $this->tagente],
+ 'id_layout_linked' => ['ref' => $this->tlayout],
+ 'parent_item' => ['ref' => $this->tlayoutData],
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'id_custom_graph' => ['ref' => $this->tgraph],
+ 'element_group' => ['ref' => $this->tgrupo],
+ ],
+ 'treport' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'id_group_edit' => ['ref' => $this->tgrupo],
+ ],
+ 'treport_content' => [
+ 'id_gs' => ['ref' => $this->tgraph],
+ 'id_agent_module' => ['ref' => $this->tagenteModulo],
+ 'id_agent' => ['ref' => $this->tagente],
+ 'treport_custom_sql_id' => ['ref' => $this->treportCustomSql],
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'id_module_group' => ['ref' => $this->tmoduleGroup],
+ 'ncm_agents' => ['ref' => ($this->tagente + ['array' => true])],
+ 'text' => [
+ 'conditional_refs' => [
+ [
+ 'when' => ['type' => 'netflow_area'],
+ 'ref' => $this->tnetflowFilter,
+ ],
+ [
+ 'when' => ['type' => 'netflow_data'],
+ 'ref' => $this->tnetflowFilter,
+ ],
+ [
+ 'when' => ['type' => 'netflow_summary'],
+ 'ref' => $this->tnetflowFilter,
+ ],
+ [
+ 'when' => ['type' => 'netflow_top_N'],
+ 'ref' => $this->tnetflowFilter,
+ ]
+ ]
+ ],
+ ],
+ 'treport_content_item' => [
+ 'id_agent_module' => ['ref' => $this->tagenteModulo],
+ ],
+ 'treport_content_sla_combined' => [
+ 'id_agent_module' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_report_content' => [
+ 'table' => 'treport_content',
+ 'id' => 'id_rc',
+ 'when' => ['type' => 'SLA_services'],
+ ],
+ ],
+ 'ref' => $this->tservice,
+ ]
+ ],
+ 'ref' => $this->tagenteModulo
+ ]
+ ],
+ 'tpolicies' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ ],
+ 'tpolicy_agents' => [
+ 'id_agent' => ['ref' => $this->tagente],
+ ],
+ 'tpolicy_alerts' => [
+ 'id_policy_module' => ['ref' => $this->tpolicyModules],
+ 'id_alert_template' => ['ref' => $this->talertTemplates],
+ ],
+ 'tpolicy_alerts_actions' => [
+ 'id_alert_action' => ['ref' => $this->talertActions],
+ ],
+ 'tpolicy_collections' => [
+ 'id_collection' => ['ref' => $this->tcollection],
+ ],
+ 'tpolicy_group_agents' => [
+ 'id_agent' => ['ref' => $this->tagente],
+ ],
+ 'tpolicy_groups' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ ],
+ 'tpolicy_modules' => [
+ 'id_tipo_modulo' => ['ref' => $this->ttipoModulo],
+ 'id_module_group' => ['ref' => $this->tmoduleGroup],
+ 'id_export' => ['ref' => $this->tserverExport],
+ 'id_plugin' => ['ref' => $this->tplugin],
+ 'id_category' => ['ref' => $this->tcategory],
+ ],
+ 'ttag_policy_module' => [
+ 'id_tag' => ['ref' => $this->ttag],
+ ],
+ 'tpolicy_modules_synth' => [
+ 'id_agent_module_source' => ['ref' => $this->tagenteModulo],
+ ],
+ 'tpolicy_modules_inventory' => [
+ 'id_module_inventory' => ['ref' => $this->tmoduleInventory],
+ ],
+ 'tservice' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'id_agent_module' => ['ref' => ($this->tagenteModulo + ['autocreate_item' => 'service_module'])],
+ 'sla_id_module' => ['ref' => ($this->tagenteModulo + ['autocreate_item' => 'service_sla_module'])],
+ 'sla_value_id_module' => ['ref' => ($this->tagenteModulo + ['autocreate_item' => 'service_sla_value_module'])],
+ 'id_template_alert_warning' => ['ref' => $this->talertTemplates],
+ 'id_template_alert_critical' => ['ref' => $this->talertTemplates],
+ 'id_template_alert_unknown' => ['ref' => $this->talertTemplates],
+ 'id_template_alert_critical_sla' => ['ref' => $this->talertTemplates],
+ ],
+ 'tservice_element' => [
+ 'id_agente_modulo' => ['ref' => $this->tagenteModulo],
+ 'id_agent' => ['ref' => $this->tagente],
+ 'id_service_child' => ['ref' => $this->tservice],
+ ],
+ 'tmap' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'source_data' => [
+ 'conditional_refs' => [
+ [
+ 'when' => ['source' => '0'],
+ 'ref' => ($this->tgrupo + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ [
+ 'when' => ['source' => '1'],
+ 'ref' => $this->treconTask,
+ ],
+ ],
+ ],
+ 'id_group_map' => ['ref' => $this->tgrupo],
+ ],
+ 'titem' => [
+ 'source_data' => [
+ 'conditional_refs' => [
+ [
+ 'when' => ['type' => '0'],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => ['type' => '1'],
+ 'ref' => $this->tagenteModulo,
+ ],
+ ],
+ ],
+ ],
+ 'trel_item' => [
+ 'id_parent' => ['ref' => $this->titem],
+ 'id_child' => ['ref' => $this->titem],
+ 'id_parent_source_data' => [
+ 'conditional_refs' => [
+ [
+ 'when' => ['parent_type' => '0'],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => ['parent_type' => '1'],
+ 'ref' => $this->tagenteModulo,
+ ],
+ ],
+ ],
+ 'id_child_source_data' => [
+ 'conditional_refs' => [
+ [
+ 'when' => ['child_type' => '0'],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => ['child_type' => '1'],
+ 'ref' => $this->tagenteModulo,
+ ],
+ ],
+ ],
+ ],
+ 'tgis_map' => [
+ 'group_id' => ['ref' => $this->tgrupo],
+ ],
+ 'tgis_map_layer' => [
+ 'tgrupo_id_grupo' => ['ref' => $this->tgrupo],
+ ],
+ 'tgis_map_layer_groups' => [
+ 'group_id' => ['ref' => $this->tgrupo],
+ 'agent_id' => ['ref' => $this->tagente],
+ ],
+ 'tgis_map_layer_has_tagente' => [
+ 'tagente_id_agente' => ['ref' => $this->tagente],
+ ],
+ 'tgis_map_has_tgis_map_con' => [
+ 'tgis_map_con_id_tmap_con' => ['ref' => $this->tgisMapConnection],
+ ],
+ 'tgraph' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ ],
+ 'tgraph_source' => [
+ 'id_server' => ['ref' => $this->tserver],
+ 'id_agent_module' => ['ref' => $this->tagenteModulo],
+ ],
+ 'tdashboard' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ ],
+ 'twidget_dashboard' => [
+ 'id_widget' => ['ref' => $this->twidget],
+ ],
+ ];
+
+ // Define references between tables fields with JSON format.
+ $this->jsonRefs = [
+ 'tservice_element' => [
+ 'rules' => [
+ 'group' => ['ref' => $this->tgrupo],
+ ],
+ ],
+ 'titem' => [
+ 'style' => [
+ 'id_group' => ['ref' => $this->tgrupo],
+ 'networkmap' => ['ref' => $this->tmap],
+ 'id_agent' => ['ref' => $this->tagente],
+ ],
+ ],
+ 'treport_content' => [
+ 'external_source' => [
+ 'module' => ['ref' => $this->tagenteModulo + ['array' => true, 'values_as_keys' => true]],
+ 'id_agents' => ['ref' => $this->tagente + ['array' => true]],
+ 'templates' => ['ref' => $this->talertTemplates + ['array' => true]],
+ 'actions' => ['ref' => $this->talertActions + ['array' => true]],
+ ],
+ ],
+ 'twidget_dashboard' => [
+ 'options' => [
+ 'id_group' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'single_graph'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'wux_transaction'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'inventory'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'service_view'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ ],
+ ],
+ 'agentId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'single_graph'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'wux_transaction'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'AvgSumMaxMinModule'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'BasicChart'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_icon'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'inventory'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'graph_module_histogram'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_table_value'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_status'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_value'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'sla_percent'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'wux_transaction_stats'],
+ ],
+ ],
+ 'ref' => $this->tagente,
+ ],
+ ],
+ ],
+ 'moduleId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'single_graph'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'AvgSumMaxMinModule'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'BasicChart'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_icon'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'graph_module_histogram'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_table_value'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_status'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'module_value'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'sla_percent'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ ],
+ ],
+ 'transactionId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'wux_transaction'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'wux_transaction_stats'],
+ ],
+ ],
+ 'ref' => $this->tagenteModulo,
+ ],
+ ],
+ ],
+ 'mGroup' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'agent_module'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'service_level'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ ],
+ ],
+ 'mModuleGroup' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'agent_module'],
+ ],
+ ],
+ 'ref' => $this->tmoduleGroup,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'service_level'],
+ ],
+ ],
+ 'ref' => $this->tmoduleGroup,
+ ],
+ ],
+ ],
+ 'mAgents' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'agent_module'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'service_level'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'groups[0]' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'AgentHive'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'heatmap'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'agentsBlockHistogram[0]' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'BlockHistogram'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'moduleBlockHistogram' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'BlockHistogram'],
+ ],
+ ],
+ 'ref' => ($this->tagenteModulo + ['array' => true, 'values_as_keys' => true]),
+ ],
+ ],
+ ],
+ 'agentsColorModuleTabs[0]' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'ColorModuleTabs'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'moduleColorModuleTabs' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'ColorModuleTabs'],
+ ],
+ ],
+ 'ref' => ($this->tagenteModulo + ['array' => true, 'values_as_keys' => true]),
+ ],
+ ],
+ ],
+ 'reportId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'reports'],
+ ],
+ ],
+ 'ref' => $this->treport,
+ ],
+ ],
+ ],
+ 'agentsDataMatrix[0]' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'DataMatrix'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'moduleDataMatrix' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'DataMatrix'],
+ ],
+ ],
+ 'ref' => ($this->tagenteModulo + ['array' => true, 'values_as_keys' => true]),
+ ],
+ ],
+ ],
+ 'id_graph' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'custom_graph'],
+ ],
+ ],
+ 'ref' => $this->tgraph,
+ ],
+ ],
+ ],
+ 'groupId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'EventCardboard'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'groups_status'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'groups_status_map'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'system_group_status'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'events_list'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'tactical'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'top_n_events_by_group'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'top_n_events_by_module'],
+ ],
+ ],
+ 'ref' => ($this->tgrupo + ['array' => true]),
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'tree_view'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'alerts_fired'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ ],
+ ],
+ 'maps' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'maps_status'],
+ ],
+ ],
+ 'ref' => ($this->tlayout + ['array' => true]),
+ ],
+ ],
+ ],
+ 'idGroup' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'inventory'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ ],
+ ],
+ 'agentsGroupedMeterGraphs[0]' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'GroupedMeterGraphs'],
+ ],
+ ],
+ 'ref' => ($this->tagente + ['csv' => true, 'csv_separator' => ',']),
+ ],
+ ],
+ ],
+ 'moduleGroupedMeterGraphs' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'GroupedMeterGraphs'],
+ ],
+ ],
+ 'ref' => ($this->tagenteModulo + ['array' => true, 'values_as_keys' => true]),
+ ],
+ ],
+ ],
+ 'tagsId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'events_list'],
+ ],
+ ],
+ 'ref' => ($this->ttag + ['array' => true]),
+ ],
+ ],
+ ],
+ 'networkmapId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'network_map'],
+ ],
+ ],
+ 'ref' => $this->tmap,
+ ],
+ ],
+ ],
+ 'group' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'security_hardening'],
+ ],
+ ],
+ 'ref' => $this->tgrupo,
+ ],
+ ],
+ ],
+ 'serviceId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'service_map'],
+ ],
+ ],
+ 'ref' => $this->tservice,
+ ],
+ ],
+ ],
+ 'vcId' => [
+ 'conditional_refs' => [
+ [
+ 'when' => [
+ 'id_widget' => [
+ 'table' => 'twidget',
+ 'id' => 'id',
+ 'when' => ['unique_name' => 'maps_made_by_user'],
+ ],
+ ],
+ 'ref' => $this->tlayout,
+ ],
+ ],
+ ],
+ ],
+ ],
+ ];
+
+ $this->currentItem = [
+ 'table' => '',
+ 'value' => '',
+ 'last_autocreate' => '',
+ 'autocreate' => [],
+ 'parsed' => [],
+ ];
+
+ $this->itemsReferences = [];
+ }
+
+
+ /**
+ * Initialize result
+ *
+ * @return void
+ */
+ private function initializeResult()
+ {
+ $this->result = [
+ 'status' => true,
+ 'items' => [],
+ 'errors' => [],
+ 'info' => [],
+ ];
+ }
+
+
+ /**
+ * Fills result with status.
+ *
+ * @param boolean $status Result status.
+ *
+ * @return void
+ */
+ public function setResultStatus(bool $status)
+ {
+ $this->result['status'] = $status;
+ }
+
+
+ /**
+ * Fills result with item.
+ *
+ * @param string $table Item table.
+ * @param array $values Item values.
+ *
+ * @return void
+ */
+ public function addResultItem(string $table, array $values)
+ {
+ $this->result['items'][] = [
+ $table,
+ $values,
+ ];
+ }
+
+
+ /**
+ * Fills result with info message.
+ *
+ * @param string $msg Info message.
+ *
+ * @return void
+ */
+ public function addResultInfo(string $msg)
+ {
+ $this->result['info'][] = $msg;
+ }
+
+
+ /**
+ * Fills result with error message.
+ *
+ * @param string $msg Error message.
+ *
+ * @return void
+ */
+ public function addResultError(string $msg)
+ {
+ $this->result['errors'][] = $msg;
+ }
+
+
+ /**
+ * Get current result status.
+ *
+ * @return boolean
+ */
+ public function getResultStatus()
+ {
+ return $this->result['status'];
+ }
+
+
+ /**
+ * Get $prdData.
+ *
+ * @return array
+ */
+ public function getPrdData(): array
+ {
+ return $this->prdData;
+ }
+
+
+ /**
+ * Get one $prdData.
+ *
+ * @param string $item Item to be searched in array.
+ *
+ * @return boolean|array
+ */
+ public function getOnePrdData(string $item): bool|array
+ {
+ if (isset($this->prdData[$item]) === false) {
+ return false;
+ }
+
+ return $this->prdData[$item];
+ }
+
+
+ /**
+ * Recursive function to extract tables.
+ *
+ * @param array $prd_data PrdData.
+ * @param array $result Empty array.
+ * @param string $parent_table Parent level table name.
+ *
+ * @return void
+ */
+ private function getTablesPrdData($prd_data, &$result=[], $parent_table='')
+ {
+ if (isset($prd_data['items']) === true) {
+ $result[] = $prd_data['items']['table'];
+ $this->crossed_refs[$prd_data['items']['table']] = [
+ 'value' => $prd_data['items']['value'],
+ 'ref' => [],
+ 'parent_table' => $parent_table,
+ ];
+ if ($prd_data['items']['data']) {
+ $this->getTablesPrdData($prd_data['items']['data'], $result, $prd_data['items']['table']);
+ }
+ } else {
+ foreach ($prd_data as $key => $value) {
+ $result[] = $value['table'];
+ $this->crossed_refs[$value['table']] = [
+ 'value' => $value['value'],
+ 'ref' => isset($value['ref']) ? $value['ref'] : [],
+ 'parent_table' => $parent_table,
+ ];
+ if (isset($value['data'])) {
+ $this->getTablesPrdData($value['data'], $result, $value['table']);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Get $columnRefs.
+ *
+ * @return array
+ */
+ public function getColumnRefs(): array
+ {
+ return $this->columnRefs;
+ }
+
+
+ /**
+ * Get one $columnRefs.
+ *
+ * @param string $item Item to be searched in array.
+ *
+ * @return boolean|array
+ */
+ public function getOneColumnRefs(string $item): bool|array
+ {
+ if (isset($this->columnRefs[$item]) === false) {
+ return false;
+ }
+
+ return $this->columnRefs[$item];
+ }
+
+
+ /**
+ * Get $jsonRefs.
+ *
+ * @return array
+ */
+ public function getJsonRefs(): array
+ {
+ return $this->jsonRefs;
+ }
+
+
+ /**
+ * Get one $jsonRefs.
+ *
+ * @param string $item Item to be searched in array.
+ *
+ * @return boolean|array
+ */
+ public function getOneJsonRefs(string $item): bool|array
+ {
+ if (isset($this->jsonRefs[$item]) === false) {
+ return false;
+ }
+
+ return $this->jsonRefs[$item];
+ }
+
+
+ /**
+ * Get types of prd.
+ *
+ * @return array
+ */
+ public function getTypesPrd(): array
+ {
+ $result = [];
+ foreach ($this->prdData as $key => $value) {
+ $result[$key] = $value['label'];
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Search value in database.
+ *
+ * @param array $columns Column.
+ * @param string $table Table.
+ * @param string $id Id.
+ * @param integer|string $value Value.
+ *
+ * @return mixed
+ */
+ private function searchValue(array $columns, string $table, string $id, $value)
+ {
+ $sql_column = sprintf(
+ 'SELECT %s FROM %s WHERE %s="%s"',
+ implode(
+ ',',
+ $columns
+ ),
+ $table,
+ $id,
+ $value
+ );
+
+ $result = db_get_row_sql($sql_column);
+ if ($result !== false) {
+ $value = $result;
+ $new_array = [];
+ $new_array[$table] = $value;
+ $value = $new_array;
+ }
+
+ return $value;
+ }
+
+ /**
+ * Function that checks if a value is a base64.
+ *
+ * @param string $string Value to be checked.
+ *
+ * @return boolean
+ */
+ private function validateBase64(string $string): bool
+ {
+ // Check if the string is valid base64 by decoding it
+ $decoded = base64_decode($string, true);
+
+ // Check if decoding was successful and if the decoded string matches the original
+ return ($decoded !== false && base64_encode($decoded) === $string);
+ }
+
+ /**
+ * Function that checks if a value is a json.
+ *
+ * @param string $json Value to be checked.
+ *
+ * @return boolean
+ */
+ private function validateJSON(string $json): bool
+ {
+ try {
+ json_decode($json);
+ return (json_last_error() === JSON_ERROR_NONE);
+ } catch (Exception $e) {
+ return false;
+ }
+ }
+
+
+ /**
+ * Function to traverse the array based on the reference.
+ *
+ * @param mixed $data JSON Array.
+ * @param string $reference JSON key reference.
+ *
+ * @return mixed
+ */
+ private function extractJsonArrayValue($data, $reference)
+ {
+ $keys = explode('.', $reference);
+
+ foreach ($keys as $key) {
+ if (preg_match('/(.+)\[(\d+)\]/', $key, $matches)) {
+ // Handle array access
+ $data = $data[$matches[1]][$matches[2]];
+ } else {
+ // Handle regular key access
+ $data = $data[$key];
+ }
+ }
+
+ return $data;
+ }
+
+
+ /**
+ * Function to update a value in the JSON based on the reference.
+ *
+ * @param mixed $data JSON Array.
+ * @param string $reference JSON key reference.
+ * @param mixed $newValue JSON new value.
+ *
+ * @return void
+ */
+ private function updateJsonArrayValue(&$data, $reference, $newValue)
+ {
+ preg_match_all('/(\w+)|\[(\d+)\]/', $reference, $matches, PREG_SET_ORDER);
+ $keys = [];
+ foreach ($matches as $match) {
+ if (isset($match[2]) === true) {
+ $keys[] = (int) $match[2];
+ } else {
+ $keys[] = $match[1];
+ }
+ }
+
+ $lastIndex = (count($keys) - 1);
+ $updated_data = &$data;
+
+ for ($i = 0; $i < $lastIndex; $i++) {
+ $updated_data = &$updated_data[$keys[$i]];
+ }
+
+ $updated_data[$keys[$lastIndex]] = $newValue;
+ }
+
+
+ /**
+ * Get reference from value and return true if found.
+ *
+ * @param mixed $when_value Condition to build SQL.
+ * @param array $sql_tables SQL tables.
+ * @param array $sql_wheres SQL wheres.
+ *
+ * @return void
+ */
+ private function recursiveWhenSQLBuildWhere($when_value, &$sql_tables, &$sql_wheres)
+ {
+ $rec_when = reset($when_value['when']);
+ if (is_array($rec_when) === true) {
+ $sql_tables[] = '`'.$rec_when['table'].'`';
+ $sql_wheres[] = '`'.$when_value['table'].'`.`'.array_key_first($when_value['when']).'` = `'.$rec_when['table'].'`.`'.$rec_when['id'].'`';
+
+ $this->recursiveWhenSQLBuildWhere($rec_when, $sql_tables, $sql_wheres);
+ } else {
+ $sql_wheres[] = '`'.$when_value['table'].'`.`'.array_key_first($when_value['when']).'` = "'.$rec_when.'"';
+ }
+ }
+
+
+ /**
+ * Evals conditional references.
+ *
+ * @param string $compare_value Value to compare.
+ * @param mixed $when Condition to check.
+ *
+ * @return boolean
+ */
+ private function evalConditionalRef($compare_value, $when)
+ {
+ if (is_array($when) === true) {
+ $when_value = reset($when);
+ } else {
+ $when_value = $when;
+ }
+
+ if ($compare_value == $when_value) {
+ return true;
+ } else {
+ if (is_array($when_value) === true) {
+ if (isset($when_value['table']) === true
+ && isset($when_value['id']) === true
+ && isset($when_value['when']) === true
+ ) {
+ if ($this->validateJSON($compare_value) === true) {
+ $json_value = json_decode($compare_value, true);
+ foreach ($when_value['when'] as $when_key => $w) {
+ if (isset($json_value[$when_value['table']][$when_key]) === true) {
+ $match_compare_value = $json_value[$when_value['table']][$when_key];
+ return $this->evalConditionalRef($match_compare_value, $w);
+ }
+ }
+ }
+
+ $sql_fields = [];
+ $sql_tables = [];
+ $sql_wheres = [];
+
+ $sql_fields[] = '`'.$when_value['table'].'`.`'.$when_value['id'].'`';
+ $sql_tables[] = '`'.$when_value['table'].'`';
+
+ $this->recursiveWhenSQLBuildWhere($when_value, $sql_tables, $sql_wheres);
+
+ $sql = sprintf(
+ 'SELECT %s FROM %s WHERE %s',
+ implode(',', $sql_fields),
+ implode(',', $sql_tables),
+ implode(' AND ', $sql_wheres)
+ );
+
+ $sql_value = db_get_value_sql($sql);
+
+ $crossed_ref = $this->getItemReference($when_value['table'], $when_value['id'], $compare_value);
+ if ($crossed_ref !== false) {
+ $compare_value = $crossed_ref;
+ }
+
+ if ($compare_value == $sql_value) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Get reference from value and return true if found.
+ *
+ * @param string $table Table.
+ * @param string $column Table column.
+ * @param array $reference Reference to extract value.
+ * @param array $row Current row values.
+ * @param string $value Value to update.
+ *
+ * @return void
+ */
+ private function getReferenceFromValue($table, $column, $reference, $row, &$value)
+ {
+ if (isset($reference['conditional_refs']) === true) {
+ // Conditional refs.
+ $conditional = $reference['conditional_refs'];
+ foreach ($conditional as $key => $condition) {
+ if (isset($condition['when']) === true
+ && isset($condition['ref']) === true
+ ) {
+ if (isset($row[array_key_first($condition['when'])]) === true) {
+ $compare_value = $row[array_key_first($condition['when'])];
+
+ if ($this->evalConditionalRef($compare_value, $condition['when']) === true
+ && empty($value) === false
+ ) {
+ $ref = $condition['ref'];
+ if (isset($ref['join']) === true) {
+ if (isset($ref['array']) === true
+ && $ref['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $val
+ );
+ $ref_arr[] = [$ref['table'] => $join_array];
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($ref['csv']) === true
+ && $ref['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($ref['csv_separator']) === true
+ && $ref['csv_separator'] === true
+ ) {
+ $csv_separator = $ref['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $val
+ );
+ $val = [$ref['table'] => $join_array];
+ $ref_arr[] = json_encode($val);
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $value
+ );
+ $value = [$ref['table'] => $join_array];
+ $value = json_encode($value);
+ }
+ } else {
+ if (isset($ref['array']) === true
+ && $ref['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $val
+ );
+ if ($ref_val !== false) {
+ if (isset($ref['values_as_keys']) === true
+ && $ref['values_as_keys'] === true
+ ) {
+ $ref_arr[$ref_val] = $ref_val;
+ } else {
+ $ref_arr[] = $ref_val;
+ }
+ }
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($ref['csv']) === true
+ && $ref['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($ref['csv_separator']) === true
+ && $ref['csv_separator'] === true
+ ) {
+ $csv_separator = $ref['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $val
+ );
+ if (is_array($ref_val) === true) {
+ $ref_val = json_encode($ref_val);
+ }
+ $ref_arr[] = $ref_val;
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $value = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $value
+ );
+ }
+ }
+
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ if (isset($reference['ref']) === true) {
+ $ref = $reference['ref'];
+
+ if (isset($ref['join']) === true) {
+ if (isset($ref['array']) === true
+ && $ref['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $val
+ );
+ $ref_arr[] = [$ref['table'] => $join_array];
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($ref['csv']) === true
+ && $ref['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($ref['csv_separator']) === true
+ && $ref['csv_separator'] === true
+ ) {
+ $csv_separator = $ref['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $val
+ );
+ $val = [$ref['table'] => $join_array];
+ $ref_arr[] = json_encode($val);
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $join_array = $this->recursiveJoin(
+ $ref,
+ $value
+ );
+ $value = [$ref['table'] => $join_array];
+ $value = json_encode($value);
+ }
+ } else {
+ if (isset($ref['array']) === true
+ && $ref['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $val
+ );
+ if ($ref_val !== false) {
+ if (isset($ref['values_as_keys']) === true
+ && $ref['values_as_keys'] === true
+ ) {
+ $ref_arr[$ref_val] = $ref_val;
+ } else {
+ $ref_arr[] = $ref_val;
+ }
+ }
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($ref['csv']) === true
+ && $ref['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($ref['csv_separator']) === true
+ && $ref['csv_separator'] === true
+ ) {
+ $csv_separator = $ref['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $val
+ );
+ if (is_array($ref_val) === true) {
+ $ref_val = json_encode($ref_val);
+ }
+ $ref_arr[] = $ref_val;
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $value = $this->searchValue(
+ $ref['columns'],
+ $ref['table'],
+ $ref['id'],
+ $value
+ );
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Get value from reference and return true if found.
+ *
+ * @param string $table Table.
+ * @param string $column Table column.
+ * @param array $reference Reference to extract value.
+ * @param string $value Value to update.
+ *
+ * @return boolean
+ */
+ private function getValueFromReference($table, $column, $reference, &$value)
+ {
+ if (isset($reference['conditional_refs']) === true) {
+ // Conditional refs.
+ $prd_item = false;
+ $conditional = $reference['conditional_refs'];
+ foreach ($conditional as $key => $condition) {
+ if (isset($condition['when']) === true
+ && isset($condition['ref']) === true
+ ) {
+ if (isset($this->currentItem['parsed'][array_key_first($condition['when'])]) === true) {
+ $compare_value = $this->currentItem['parsed'][array_key_first($condition['when'])];
+
+ if ($this->evalConditionalRef($compare_value, $condition['when']) === true
+ && empty($value) === false
+ ) {
+ if (isset($condition['ref']['array']) === true
+ && $condition['ref']['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->findPrdItem(
+ $condition['ref'],
+ is_array($val) ? json_encode($val) : $val
+ );
+
+ if ($ref_val === false && $ref_val != $val) {
+ if ($this->evalAutocreateItem($condition['ref'], is_array($val) ? json_encode($val) : $val, $column) === false) {
+ return false;
+ }
+ }
+
+ if ($ref_val !== false) {
+ if (isset($ref['values_as_keys']) === true
+ && $ref['values_as_keys'] === true
+ ) {
+ $ref_arr[$ref_val] = $ref_val;
+ } else {
+ $ref_arr[] = $ref_val;
+ }
+ }
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($condition['ref']['csv']) === true
+ && $condition['ref']['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($condition['ref']['csv_separator']) === true
+ && $condition['ref']['csv_separator'] === true
+ ) {
+ $csv_separator = $condition['ref']['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->findPrdItem(
+ $condition['ref'],
+ $val
+ );
+
+ if ($ref_val === false && $ref_val != $val) {
+ if ($this->evalAutocreateItem($condition['ref'], $val, $column) === false) {
+ return false;
+ }
+ }
+
+ $ref_arr[] = $ref_val;
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $prd_item = $this->findPrdItem(
+ $condition['ref'],
+ is_array($value) ? json_encode($value) : $value
+ );
+
+ if ($prd_item === false && $prd_item != $value) {
+ if ($this->evalAutocreateItem($condition['ref'], is_array($value) ? json_encode($value) : $value, $column) === false) {
+ return false;
+ }
+ }
+
+ $value = $prd_item;
+ }
+
+ return true;
+ }
+ }
+ }
+ }
+ }
+
+ if (isset($reference['ref']) === true) {
+ $ref = $reference['ref'];
+ if (isset($ref['array']) === true
+ && $ref['array'] === true
+ ) {
+ if (is_array($value) === true) {
+ $value_arr = $value;
+ } else {
+ $value_arr = json_decode($value, true);
+ }
+ if (is_array($value_arr)) {
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->findPrdItem(
+ $ref,
+ is_array($val) ? json_encode($val) : $val
+ );
+
+ if ($ref_val === false && $ref_val != $val) {
+ if ($this->evalAutocreateItem($ref, is_array($val) ? json_encode($val) : $val, $column) === false) {
+ return false;
+ }
+ }
+
+ if ($ref_val !== false) {
+ if (isset($ref['values_as_keys']) === true
+ && $ref['values_as_keys'] === true
+ ) {
+ $ref_arr[$ref_val] = $ref_val;
+ } else {
+ $ref_arr[] = $ref_val;
+ }
+ }
+ }
+
+ $value = $ref_arr;
+ }
+ } else if (isset($ref['csv']) === true
+ && $ref['csv'] === true
+ ) {
+ $csv_separator = ',';
+ if (isset($ref['csv_separator']) === true
+ && $ref['csv_separator'] === true
+ ) {
+ $csv_separator = $ref['csv_separator'];
+ }
+
+ $value_arr = explode($csv_separator, $value);
+ $ref_arr = [];
+ foreach ($value_arr as $val) {
+ $ref_val = $this->findPrdItem(
+ $ref,
+ $val
+ );
+
+ if ($ref_val === false && $ref_val != $val) {
+ if ($this->evalAutocreateItem($ref, $val, $column) === false) {
+ return false;
+ }
+ }
+
+ $ref_arr[] = $ref_val;
+ }
+
+ $value = implode($csv_separator, $ref_arr);
+ } else {
+ $prd_item = $this->findPrdItem(
+ $ref,
+ is_array($value) ? json_encode($value) : $value
+ );
+
+ if ($prd_item === false && $prd_item != $value) {
+ if ($this->evalAutocreateItem($ref, is_array($value) ? json_encode($value) : $value, $column) === false) {
+ return false;
+ }
+ }
+
+ $value = $prd_item;
+ }
+
+ return true;
+ }
+
+ if (isset($reference['fixed_value']) === true) {
+ $value = $reference['fixed_value'];
+ return true;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Converts a resource into a string.
+ *
+ * @param string $type Item type.
+ * @param mixed $id Item value.
+ * @param string $name Item name.
+ *
+ * @return string
+ */
+ public function exportPrd(string $type, mixed $id, string $name) :string
+ {
+ $result = '';
+
+ $prd_data = $this->getOnePrdData($type);
+ if (empty($prd_data) === false) {
+ $result .= '[prd_data]'.LINE_BREAK.LINE_BREAK;
+ $result .= 'type="'.$type.'"'.LINE_BREAK;
+ $result .= 'name="'.io_safe_output($name).'"'.LINE_BREAK.LINE_BREAK;
+
+ $prd_export_tables = [];
+ $this->recursiveExportPrd([$prd_data['items']], $id, $prd_export_tables);
+
+ foreach ($prd_export_tables as $table => $rows) {
+ $result .= '['.$table.']'.LINE_BREAK.LINE_BREAK;
+
+ foreach ($rows as $index => $row) {
+ foreach ($row as $field => $value) {
+ // Scape double quotes in all values.
+ $value = str_replace('"', '\"', $value);
+ $result .= $field.'['.$index.']="'.$value.'"'.LINE_BREAK;
+ }
+
+ $result .= LINE_BREAK;
+ }
+ }
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Recursive function to traverse all data
+ *
+ * @param mixed $data Data.
+ * @param mixed $id Id value for search.
+ * @param mixed $result Result.
+ *
+ * @return void
+ */
+ private function recursiveExportPrd($data, $id, &$result=[])
+ {
+ foreach ($data as $key => $element) {
+ if (!isset($result[$element['table']])) {
+ $result[$element['table']] = [];
+ }
+
+ $columns_ref = $this->getOneColumnRefs($element['table']);
+ $json_ref = $this->getOneJsonRefs($element['table']);
+
+ $sql_field = reset($element['value']);
+ if (isset($element['ref'])) {
+ $sql_field = reset($element['ref']);
+ }
+
+ $sql = sprintf(
+ 'SELECT * FROM %s WHERE %s = "%s"',
+ $element['table'],
+ $sql_field,
+ $id,
+ );
+
+ if (empty($id) === false && empty($element['table']) === false
+ && empty(reset($element['value'])) === false
+ ) {
+ $rows = db_get_all_rows_sql($sql);
+ } else {
+ $rows = [];
+ }
+
+ foreach ($rows as $row) {
+ if (count($element['value']) > 1) {
+ $primary_key = '';
+ foreach ($element['value'] as $value) {
+ $primary_key .= $row[$value].'-';
+ }
+
+ $primary_key = substr($primary_key, 0, -1);
+ } else {
+ $primary_key = $row[reset($element['value'])];
+ }
+
+ foreach ($row as $column => $value) {
+ $isBase64 = false;
+ if (isset($columns_ref[$column]) === true
+ && empty($value) === false
+ ) {
+ if (is_string($value) === true && $this->validateBase64($value) === true) {
+ $value = base64_decode($value);
+ $isBase64 = true;
+ }
+ // The column is inside column refs.
+ $this->getReferenceFromValue(
+ $element['table'],
+ $column,
+ $columns_ref[$column],
+ $row,
+ $value
+ );
+ } else if (isset($json_ref[$column]) === true
+ && empty($value) === false
+ ) {
+ // Json ref.
+ $array_value = json_decode($value, true);
+ foreach ($json_ref[$column] as $json_key => $ref) {
+ $json_value = $this->extractJsonArrayValue($array_value, $json_key);
+ if (isset($json_value) === true) {
+ $isBase64 = false;
+ if (is_string($json_value) === true && $this->validateBase64($json_value) === true) {
+ $json_value = base64_decode($json_value);
+ $isBase64 = true;
+ }
+ $this->getReferenceFromValue(
+ $element['table'],
+ $column,
+ $ref,
+ $row,
+ $json_value
+ );
+ if ($isBase64 === true) {
+ if (is_array($json_value) === true) {
+ $json_value = json_encode($json_value);
+ }
+ $json_value = base64_encode($json_value);
+ }
+ $this->updateJsonArrayValue($array_value, $json_key, $json_value);
+ }
+ }
+
+ $isBase64 = false;
+ $value = json_encode($array_value);
+ }
+
+ if (is_array($value) === true) {
+ $value = json_encode($value);
+ }
+
+ if ($isBase64 === true) {
+ $value = base64_encode($value);
+ }
+
+ if (!isset($result[$element['table']][$primary_key])) {
+ $result[$element['table']][$primary_key] = [];
+ }
+
+ $result[$element['table']][$primary_key][$column] = $value;
+ }
+
+ if (isset($element['data']) === true) {
+ $this->recursiveExportPrd($element['data'], $primary_key, $result);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Recursive function to traverse all join data
+ *
+ * @param array $data Data.
+ * @param mixed $value Value for search.
+ *
+ * @return array
+ */
+ private function recursiveJoin(array $data, $value):array
+ {
+ $result = [];
+ if (empty($data['join']) === false) {
+ $sql = sprintf(
+ 'SELECT %s, %s FROM %s WHERE %s="%s"',
+ implode(
+ ',',
+ $data['columns']
+ ),
+ array_key_first($data['join']),
+ $data['table'],
+ $data['id'],
+ $value
+ );
+
+ $result = db_get_row_sql($sql);
+ $join = reset($data['join']);
+ $result_deep = $this->recursiveJoin($join, $result[array_key_first($data['join'])]);
+
+ $result[array_key_first($data['join'])] = $result_deep;
+ } else {
+ $sql = sprintf(
+ 'SELECT %s FROM %s WHERE %s="%s"',
+ implode(
+ ',',
+ $data['columns']
+ ),
+ $data['table'],
+ $data['id'],
+ $value
+ );
+
+ $result_sql = db_get_row_sql($sql);
+ $result[$data['table']] = $result_sql;
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Function to fill current item.
+ *
+ * @param string|integer $id Id.
+ * @param string $table Table.
+ * @param array $data Array with data.
+ *
+ * @return void
+ */
+ private function fillCurrentItem($id, string $table, array $data)
+ {
+ $this->currentItem['table'] = $table;
+ $this->currentItem['id'] = $id;
+ $this->currentItem['value'] = '';
+ $this->currentItem['last_autocreate'] = '';
+ $this->currentItem['autocreate'] = [];
+ $this->currentItem['parsed'] = [];
+ foreach ($data as $column => $value) {
+ $this->currentItem['parsed'][$column] = $value[$id];
+ }
+ }
+
+
+ /**
+ * Converts a resource into a string.
+ *
+ * @param array $data_file Array with import data.
+ *
+ * @return array
+ */
+ public function importPrd($data_file): array
+ {
+ global $config;
+
+ $this->initializeResult();
+
+ if (empty($data_file['prd_data']) === false) {
+ $type = $data_file['prd_data']['type'];
+ $name = io_safe_input($data_file['prd_data']['name']);
+ unset($data_file['prd_data']);
+
+ $prd_data = $this->getOnePrdData($type);
+ if ($prd_data !== false) {
+ // Begin transaction.
+ $db = $config['dbconnection'];
+ $db->begin_transaction();
+
+ try {
+ $tables = [];
+ $this->crossed_refs = [];
+ $tables_id = [];
+ $this->getTablesPrdData($prd_data, $tables);
+ foreach ($tables as $table) {
+ if (isset($data_file[$table]) === false) {
+ continue;
+ }
+
+ $internal_array = $data_file[$table];
+
+ $column_refs = $this->getOneColumnRefs($table);
+ $json_refs = $this->getOneJsonRefs($table);
+
+ $ids = reset($internal_array);
+ foreach ($ids as $id => $i) {
+ $create_item = true;
+ $this->fillCurrentItem($id, $table, $internal_array);
+ foreach ($this->currentItem['parsed'] as $column => $value) {
+ if (isset($column_refs[$column]) === true
+ && empty($value) === false
+ ) {
+ $isBase64 = false;
+ if (is_string($value) === true && $this->validateBase64($value)) {
+ $value = base64_decode($value);
+ $isBase64 = true;
+ }
+ $create_item = $this->getValueFromReference(
+ $table,
+ $column,
+ $column_refs[$column],
+ $value
+ );
+
+ if (is_array($value) === true) {
+ $value = json_encode($value);
+ }
+
+ if ($isBase64 === true) {
+ $value = base64_encode($value);
+ }
+ } else if (isset($json_refs[$column]) === true
+ && empty($value) === false
+ ) {
+ $array_value = json_decode($value, true);
+ foreach ($json_refs[$column] as $json_key => $json_ref) {
+ $json_value = $this->extractJsonArrayValue($array_value, $json_key);
+ if (isset($json_value) === true) {
+ $isBase64 = false;
+ if (is_string($json_value) === true && $this->validateBase64($json_value) === true) {
+ $json_value = base64_decode($json_value);
+ $isBase64 = true;
+ }
+ if ($this->getValueFromReference(
+ $table,
+ $column,
+ $json_refs[$column][$json_key],
+ $json_value
+ ) === true
+ ) {
+ if ($isBase64 === true) {
+ if (is_array($json_value) === true) {
+ $json_value = json_encode($json_value);
+ }
+ $json_value = base64_encode($json_value);
+ }
+ $this->updateJsonArrayValue($array_value, $json_key, $json_value);
+ } else {
+ $create_item = false;
+ break;
+ }
+ }
+ }
+
+ $value = json_encode($array_value);
+ }
+
+ if($create_item === false){
+ break;
+ }
+
+ $this->currentItem['parsed'][$column] = $value;
+ }
+
+ if ($create_item === true) {
+ if ($this->createItem($table) === false) {
+ $this->setResultStatus(false);
+ break;
+ }
+ } else {
+ $this->addResultInfo(
+ sprintf(
+ 'Skipped item creation at least one reference not found: table => %s, item => %s',
+ $table,
+ $id
+ )
+ );
+ }
+ }
+
+ if ($this->getResultStatus() === false) {
+ break;
+ }
+ }
+ } catch (\Throwable $th) {
+ $this->setResultStatus(false);
+ $this->addResultError('Unexpected error: '.$th->getMessage());
+ }
+ } else {
+ $this->setResultStatus(false);
+ $this->addResultError('[prd_data] => "type" not valid to import: '.$type);
+ }
+ } else {
+ $this->setResultStatus(false);
+ $this->addResultError('[prd_data] not found in PRD file.');
+ }
+
+ if (isset($db)) {
+ if ($this->getResultStatus() === true) {
+ $db->commit();
+ } else {
+ $db->rollback();
+ }
+ }
+
+ return $this->result;
+ }
+
+
+ /**
+ * Finds value in database.
+ *
+ * @param array $ref Reference.
+ * @param mixed $value Value.
+ *
+ * @return mixed
+ */
+ private function findPrdItem($ref, $value)
+ {
+ $result = false;
+ $array_value = json_decode($value, true);
+ if (isset($ref['join']) === true) {
+ $result = $this->inverseRecursiveJoin(
+ $ref,
+ $array_value
+ );
+ } else {
+ if (empty($array_value) === false
+ && empty($array_value[$ref['table']]) === false
+ ) {
+ $where = '';
+ foreach ($ref['columns'] as $column_name) {
+ if (isset($array_value[$ref['table']][$column_name])) {
+ $where .= sprintf(
+ "%s = '%s' AND ",
+ $column_name,
+ $array_value[$ref['table']][$column_name]
+ );
+ }
+ }
+
+ $where = rtrim($where, 'AND ');
+ $sql_column = sprintf(
+ 'SELECT %s FROM %s WHERE %s',
+ $ref['id'],
+ $ref['table'],
+ $where,
+ );
+
+ $result = db_get_value_sql($sql_column);
+ } else {
+ // Empty json.
+ $result = $value;
+ }
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Recursive function to traverse all join data
+ *
+ * @param array $ref Data.
+ * @param mixed $value Value for search.
+ *
+ * @return mixed
+ */
+ private function inverseRecursiveJoin($ref, $value)
+ {
+ $result = '';
+ if (empty($ref['join']) === false) {
+ $result = $this->inverseRecursiveJoin(
+ $ref['join'],
+ $value[$ref['table']][array_key_first($ref['join'])]
+ );
+
+ if (empty($result) === false) {
+ $where = '';
+ foreach ($ref['columns'] as $column_name) {
+ if (isset($value[$ref['table']][$column_name]) === true) {
+ $where .= sprintf(
+ "%s = '%s' AND ",
+ $column_name,
+ $value[$ref['table']][$column_name]
+ );
+ }
+ }
+
+ $where .= ' '.array_key_first($ref['join']).' = "'.reset($result).'"';
+ $where = rtrim($where, 'AND ');
+
+ $sql = sprintf(
+ 'SELECT %s FROM %s WHERE %s',
+ $ref['id'],
+ $ref['table'],
+ $where
+ );
+
+ $result = db_get_value_sql($sql);
+ }
+ } else {
+ $key = array_key_first($ref);
+ $where = '';
+ foreach ($ref[$key]['columns'] as $column_name) {
+ if (isset($value[$ref[$key]['table']][$column_name]) === true) {
+ $where .= sprintf(
+ "%s = '%s' AND ",
+ $column_name,
+ $value[$ref[$key]['table']][$column_name]
+ );
+ }
+ }
+
+ if (empty($where) === false) {
+ $where = rtrim($where, 'AND ');
+
+ $sql = sprintf(
+ 'SELECT %s FROM %s WHERE %s',
+ $ref[$key]['id'],
+ $ref[$key]['table'],
+ $where
+ );
+
+ $result = db_get_row_sql($sql);
+ }
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Eval autocreate Item.
+ *
+ * @param array $ref References.
+ * @param string $value Current value.
+ * @param string $column Table column.
+ *
+ * @return boolean
+ */
+ private function evalAutocreateItem(array $ref, string $value='', string $column='')
+ {
+ if (isset($ref['autocreate_item']) === true) {
+ $this->autocreateItem(
+ $ref,
+ $column,
+ $value,
+ $ref['autocreate_item']
+ );
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
+
+ /**
+ * Autocreate Item.
+ *
+ * @param array $ref References.
+ * @param string $field Field.
+ * @param string $autocreate_key Key.
+ *
+ * @return void
+ */
+ private function autocreateItem(array $ref, string $field='', $ref_value, string $autocreate_key='')
+ {
+ $current_item = $this->currentItem['parsed'][$field];
+ $current_item = json_decode($current_item, true);
+
+ switch ($autocreate_key) {
+ case 'service_module':
+ $autocreate_globals = [
+ 'service_module' => [
+ 'id_agent' => $this->findPrdItem(
+ $this->tagente,
+ json_encode($current_item['tagente_modulo']['id_agente'])
+ ),
+ 'interval' => 300,
+ 'status' => AGENT_MODULE_STATUS_NO_DATA,
+ ],
+ ];
+
+ $autocreate_pre_items = [
+ 'service_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'id' => ['id_agente_modulo'],
+ 'fields' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'nombre' => $this->currentItem['parsed']['name'].'_service',
+ 'flag' => 1,
+ 'module_interval' => $autocreate_globals[$autocreate_key]['interval'],
+ 'prediction_module' => 2,
+ 'id_modulo' => MODULE_PREDICTION,
+ 'id_tipo_modulo' => MODULE_TYPE_GENERIC_DATA,
+ 'min_warning' => $this->currentItem['parsed']['warning'],
+ 'min_critical' => $this->currentItem['parsed']['critical'],
+ ],
+ ],
+ [
+ 'table' => 'tagente_estado',
+ 'id' => ['id_agente_estado'],
+ 'fields' => [
+ 'id_agente_modulo' => &$this->currentItem['last_autocreate'],
+ 'datos' => '',
+ 'timestamp' => '0000-00-00 00:00:00',
+ 'estado' => $autocreate_globals[$autocreate_key]['status'],
+ 'known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'utimestamp' => 0,
+ 'status_changes' => 0,
+ 'last_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'last_known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'current_interval' => 0,
+ ],
+ ],
+ ],
+ ];
+
+ $autocreate_post_updates = [
+ 'service_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'fields' => [
+ 'custom_integer_1' => &$this->currentItem['value'],
+ ],
+ 'conditions' => [
+ 'id_agente_modulo' => &$this->currentItem['parsed'][$field],
+ ],
+ ],
+ [
+ 'table' => 'tagente',
+ 'fields' => ['update_module_count' => '1'],
+ 'conditions' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ ],
+ ],
+ ],
+ ];
+ break;
+
+ case 'service_sla_module':
+ $autocreate_globals = [
+ 'service_sla_module' => [
+ 'id_agent' => $this->findPrdItem(
+ $this->tagente,
+ json_encode($current_item['tagente_modulo']['id_agente'])
+ ),
+ 'interval' => 300,
+ 'status' => AGENT_MODULE_STATUS_NO_DATA,
+ ],
+ ];
+
+ $autocreate_pre_items = [
+ 'service_sla_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'id' => ['id_agente_modulo'],
+ 'fields' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'nombre' => $this->currentItem['parsed']['name'].'_SLA_service',
+ 'flag' => 1,
+ 'module_interval' => $autocreate_globals[$autocreate_key]['interval'],
+ 'prediction_module' => 2,
+ 'id_modulo' => MODULE_PREDICTION,
+ 'id_tipo_modulo' => MODULE_TYPE_GENERIC_PROC,
+ ],
+ ],
+ [
+ 'table' => 'tagente_estado',
+ 'id' => ['id_agente_estado'],
+ 'fields' => [
+ 'id_agente_modulo' => &$this->currentItem['last_autocreate'],
+ 'datos' => '',
+ 'timestamp' => '0000-00-00 00:00:00',
+ 'estado' => $autocreate_globals[$autocreate_key]['status'],
+ 'known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'utimestamp' => 0,
+ 'status_changes' => 0,
+ 'last_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'last_known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'current_interval' => 0,
+ ],
+ ],
+ ],
+ ];
+
+ $autocreate_post_updates = [
+ 'service_sla_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'fields' => [
+ 'custom_integer_1' => &$this->currentItem['value'],
+ ],
+ 'conditions' => [
+ 'id_agente_modulo' => &$this->currentItem['parsed'][$field],
+ ],
+ ],
+ [
+ 'table' => 'tagente',
+ 'fields' => ['update_module_count' => '1'],
+ 'conditions' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ ],
+ ],
+ ],
+ ];
+ break;
+
+ case 'service_sla_value_module':
+ $autocreate_globals = [
+ 'service_sla_value_module' => [
+ 'id_agent' => $this->findPrdItem(
+ $this->tagente,
+ json_encode($current_item['tagente_modulo']['id_agente'])
+ ),
+ 'interval' => 300,
+ 'status' => AGENT_MODULE_STATUS_NO_DATA,
+ ],
+ ];
+
+ $autocreate_pre_items = [
+ 'service_sla_value_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'id' => ['id_agente_modulo'],
+ 'fields' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'nombre' => $this->currentItem['parsed']['name'].'_SLA_Value_service',
+ 'flag' => 1,
+ 'module_interval' => $autocreate_globals[$autocreate_key]['interval'],
+ 'prediction_module' => 2,
+ 'id_modulo' => MODULE_PREDICTION,
+ 'id_tipo_modulo' => MODULE_TYPE_GENERIC_DATA,
+ 'min_critical' => $this->currentItem['parsed']['sla_limit'],
+ ],
+ ],
+ [
+ 'table' => 'tagente_estado',
+ 'id' => ['id_agente_estado'],
+ 'fields' => [
+ 'id_agente_modulo' => &$this->currentItem['last_autocreate'],
+ 'datos' => '',
+ 'timestamp' => '0000-00-00 00:00:00',
+ 'estado' => $autocreate_globals[$autocreate_key]['status'],
+ 'known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ 'utimestamp' => 0,
+ 'status_changes' => 0,
+ 'last_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'last_known_status' => $autocreate_globals[$autocreate_key]['status'],
+ 'current_interval' => 0,
+ ],
+ ],
+ ],
+ ];
+
+ $autocreate_post_updates = [
+ 'service_sla_value_module' => [
+ [
+ 'table' => 'tagente_modulo',
+ 'fields' => [
+ 'custom_integer_1' => &$this->currentItem['value'],
+ ],
+ 'conditions' => [
+ 'id_agente_modulo' => &$this->currentItem['parsed'][$field],
+ ],
+ ],
+ [
+ 'table' => 'tagente',
+ 'fields' => ['update_module_count' => '1'],
+ 'conditions' => [
+ 'id_agente' => $autocreate_globals[$autocreate_key]['id_agent'],
+ ],
+ ],
+ ],
+ ];
+ break;
+
+ case 'agent_groups':
+ $autocreate_pre_items = [
+ 'agent_groups' => [
+ [
+ 'table' => 'tgrupo',
+ 'id' => ['id_grupo'],
+ 'fields' => ['nombre' => json_decode($ref_value, true)['tgrupo']['nombre']],
+ ],
+ ],
+ ];
+ break;
+
+ case 'module_groups':
+ $autocreate_pre_items = [
+ 'module_groups' => [
+ [
+ 'table' => 'tmodule_group',
+ 'id' => ['id_mg'],
+ 'fields' => ['name' => json_decode($ref_value, true)['tmodule_group']['name']],
+ ],
+ ],
+ ];
+ break;
+
+ case 'operating_systems':
+ $autocreate_pre_items = [
+ 'operating_systems' => [
+ [
+ 'table' => 'tconfig_os',
+ 'id' => ['id_os'],
+ 'fields' => ['name' => json_decode($ref_value, true)['tconfig_os']['name']],
+ ],
+ ],
+ ];
+ break;
+
+ case 'categories':
+ $autocreate_pre_items = [
+ 'categories' => [
+ [
+ 'table' => 'tcategory',
+ 'id' => ['id'],
+ 'fields' => ['name' => json_decode($ref_value, true)['tcategory']['name']],
+ ],
+ ],
+ ];
+ break;
+
+ case 'tags':
+ $autocreate_pre_items = [
+ 'tags' => [
+ [
+ 'table' => 'ttag',
+ 'id' => ['id_tag'],
+ 'fields' => ['name' => json_decode($ref_value, true)['ttag']['name']],
+ ],
+ ],
+ ];
+ break;
+
+ default:
+ // Empty.
+ break;
+ }
+
+ $this->currentItem['autocreate'][$field]['ref'] = $ref;
+ $this->currentItem['autocreate'][$field]['pre_items']
+ = (isset($autocreate_pre_items[$autocreate_key]) === true
+ ? $autocreate_pre_items[$autocreate_key]
+ : []
+ );
+ $this->currentItem['autocreate'][$field]['post_updates']
+ = (isset($autocreate_post_updates[$autocreate_key]) === true
+ ? $autocreate_post_updates[$autocreate_key]
+ : []
+ );
+ }
+
+
+ /**
+ * Function to add an old ID reference.
+ *
+ * @param string $table Table.
+ * @param array $fields Table fields.
+ * @param string $old_value Old value.
+ * @param string $current_value Current value.
+ *
+ * @return void
+ */
+ private function addItemReference(string $table, array $fields, string $old_value, string $current_value)
+ {
+ if (count($fields) > 1) {
+ $old_value = explode('-', $old_value);
+ $current_value = explode('-', $current_value);
+ } else {
+ $old_value = [$old_value];
+ $current_value = [$current_value];
+ }
+
+ if (!isset($this->itemsReferences[$table])) {
+ $this->itemsReferences[$table] = [];
+ }
+
+ foreach ($fields as $k => $field) {
+ if (!isset($this->itemsReferences[$table][$field])) {
+ $this->itemsReferences[$table][$field] = [];
+ }
+
+ $this->itemsReferences[$table][$field][$old_value[$k]] = $current_value[$k];
+ }
+ }
+
+
+ /**
+ * Function to get an old ID reference.
+ *
+ * @param string $table Table.
+ * @param string $field Table field.
+ * @param string $old_value Old value.
+ *
+ * @return mixed
+ */
+ private function getItemReference(string $table, string $field, string $old_value)
+ {
+ if (isset($this->itemsReferences[$table][$field][$old_value]) === true) {
+ return $this->itemsReferences[$table][$field][$old_value];
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Function to create item in database.
+ *
+ * @param string $table Table.
+ *
+ * @return mixed
+ */
+ private function createItem(string $table)
+ {
+ $id = $this->crossed_refs[$table]['value'];
+
+ // Remove primary keys not references
+ foreach ($id as $id_column) {
+ if (in_array($id_column, $this->crossed_refs[$table]['ref']) === false
+ && isset($this->columnRefs[$table][$id_column]) === false
+ ) {
+ unset($this->currentItem['parsed'][$id_column]);
+ }
+ }
+
+ // Update current item crossed references.
+ if (isset($this->crossed_refs[$table]) === true
+ && empty($this->crossed_refs[$table]['ref']) === false
+ ) {
+ $parent_table = $this->crossed_refs[$table]['parent_table'];
+ foreach ($this->crossed_refs[$table]['ref'] as $k => $f) {
+ $itemReference = $this->getItemReference(
+ $parent_table,
+ $this->crossed_refs[$parent_table]['value'][$k],
+ $this->currentItem['parsed'][$f]
+ );
+
+ if ($itemReference === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to create item (crossed references): table => %s, item => %s',
+ $table,
+ $this->currentItem['id']
+ )
+ );
+ return false;
+ }
+
+ $this->currentItem['parsed'][$f] = $itemReference;
+ }
+ }
+
+ foreach ($this->currentItem['autocreate'] as $field => $values) {
+ if (isset($values['pre_items']) === true) {
+ foreach ($values['pre_items'] as $insert) {
+ // Run each INSERT and store each value in $this->currentItem['last_autocreate'] overwriting.
+ foreach ($insert['fields'] as $insert_f => $insert_v) {
+ if ($insert_v === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to autocreate unexisting item (dependent item not found in pre inserts): table => %s, item => %s, field => %s',
+ $this->currentItem['table'],
+ $this->currentItem['id'],
+ $field
+ )
+ );
+ return false;
+ }
+ }
+
+ $insert_query = db_process_sql_insert(
+ $insert['table'],
+ $insert['fields'],
+ false
+ );
+
+ $last_autocreate = db_get_all_rows_filter(
+ $insert['table'],
+ $insert['fields'],
+ $insert['id']
+ );
+
+ if ($insert_query === false || $last_autocreate === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to autocreate unexisting item: table => %s, item => %s, field => %s',
+ $this->currentItem['table'],
+ $this->currentItem['id'],
+ $field
+ )
+ );
+ return false;
+ }
+
+ $last_autocreate = end($last_autocreate);
+
+ $this->addResultItem($insert['table'], $last_autocreate);
+
+ $this->currentItem['last_autocreate'] = implode('-', array_values($last_autocreate));
+ }
+ }
+
+ $this->currentItem['parsed'][$field] = $this->findPrdItem(
+ $values['ref'],
+ $this->currentItem['parsed'][$field]
+ );
+ }
+
+ // Create item itself with INSERT query and store its value in $this->currentItem['value'].
+ $sql_fields = [];
+ foreach ($this->currentItem['parsed'] as $f => $v) {
+ $sql_fields['`'.$f.'`'] = $v;
+ }
+
+ $insert_query = db_process_sql_insert(
+ $table,
+ $sql_fields,
+ false
+ );
+
+ $insert = db_get_all_rows_filter(
+ $table,
+ $sql_fields,
+ $id
+ );
+
+ if ($insert_query === false || $insert === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to create item: table => %s, item => %s',
+ $table,
+ $this->currentItem['id']
+ )
+ );
+ return false;
+ }
+
+ $insert = end($insert);
+
+ $this->addResultItem($table, $insert);
+
+ $this->currentItem['value'] = implode('-', array_values($insert));
+
+ if (isset($this->crossed_refs[$table]) === true) {
+ $this->addItemReference(
+ $table,
+ $this->crossed_refs[$table]['value'],
+ $this->currentItem['id'],
+ $this->currentItem['value']
+ );
+ }
+
+ foreach ($this->currentItem['autocreate'] as $field => $values) {
+ if (isset($values['post_updates']) === true) {
+ foreach ($values['post_updates'] as $update) {
+ // Run each UPDATE query.
+ foreach ($update['fields'] as $update_f => $update_v) {
+ if ($update_v === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to autocreate unexisting item (dependent item not found in post updates): table => %s, item => %s, field => %s',
+ $this->currentItem['table'],
+ $this->currentItem['id'],
+ $field,
+ )
+ );
+ return false;
+ }
+ }
+
+ $update = db_process_sql_update(
+ $update['table'],
+ $update['fields'],
+ $update['conditions'],
+ 'AND',
+ false
+ );
+
+ if ($update === false) {
+ $this->addResultError(
+ sprintf(
+ 'Failed when trying to create item (post updates): table => %s, item => %s',
+ $table,
+ $this->currentItem['id']
+ )
+ );
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+
+}
diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php
index d68bba9c22..820bf65f40 100644
--- a/pandora_console/include/constants.php
+++ b/pandora_console/include/constants.php
@@ -907,3 +907,6 @@ define('DEMO_SERVICE', 6);
define('DEMO_DASHBOARD', 7);
define('DEMO_VISUAL_CONSOLE', 8);
define('DEMO_PLUGIN', 9);
+
+// Export resources.
+define('LINE_BREAK', "\n");
diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php
index fc54d29d2c..0c81045403 100644
--- a/pandora_console/include/lib/Dashboard/Manager.php
+++ b/pandora_console/include/lib/Dashboard/Manager.php
@@ -1266,7 +1266,7 @@ class Manager implements PublicLogin
}
if (empty($cells) === false) {
- $result = array_reduce(
+ $result = array_values(array_reduce(
$cells,
function ($carry, $item) {
$carry[$item['order']]['id'] = $item['id'];
@@ -1276,7 +1276,7 @@ class Manager implements PublicLogin
return $carry;
},
[]
- );
+ ));
}
echo json_encode($result);
diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css
index a1f76eef71..b94418b090 100644
--- a/pandora_console/include/styles/pandora.css
+++ b/pandora_console/include/styles/pandora.css
@@ -10954,6 +10954,18 @@ div.status_dot {
-webkit-mask: url(../../images/status_dot.svg) no-repeat center / contain;
}
+button div.import {
+ mask: url(../../images/import.svg) no-repeat center / contain;
+ -webkit-mask: url(../../images/import.svg) no-repeat center / contain;
+ height: 1.5rem;
+}
+
+button div.export {
+ mask: url(../../images/export.svg) no-repeat center / contain;
+ -webkit-mask: url(../../images/export.svg) no-repeat center / contain;
+ height: 1.5rem;
+}
+
.status_dot.ok {
background-color: #82b92e;
}
@@ -13504,3 +13516,71 @@ tr.shown td.details-control {
mask: url(../../images/minimizar.svg) no-repeat right / contain;
-webkit-mask: url(../../images/minimizar.svg) no-repeat right / contain;
}
+
+/* Import/export */
+.div-import-export {
+ display: flex;
+ flex-direction: row;
+}
+
+.form-import {
+ width: 48%;
+ height: auto;
+ margin-right: 40px;
+}
+
+.div-import {
+ background-color: #ffffff;
+ border: 1px solid #e5e9ed;
+ border-radius: 8px;
+ width: 100%;
+ height: 180px;
+ display: flex;
+ flex-direction: row;
+ align-items: normal;
+ padding-top: 20px;
+ padding-left: 20px;
+ margin-bottom: 20px;
+}
+
+.div-export {
+ background-color: #ffffff;
+ border: 1px solid #e5e9ed;
+ border-radius: 8px;
+ width: 48%;
+ height: 180px;
+ display: flex;
+ flex-direction: row;
+ align-items: normal;
+ padding-top: 20px;
+ padding-left: 20px;
+ margin-bottom: 20px;
+}
+
+@media (max-width: 1300px) {
+ .div-import-export {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .div-export {
+ width: calc(100% - 20px);
+ }
+
+ .form-import {
+ width: calc(100% - 20px);
+ }
+}
+
+.input-file-style::file-selector-button {
+ background-color: #ffffff;
+ border: 1px solid #979797;
+ border-radius: 4px;
+ width: 120px;
+ height: 32px;
+}
+
+button.disabled {
+ background: #c0ccdc !important;
+ border: 0px;
+}