', $plugin['description']); } if (isset($plugin['macros'])) { $macros = json_decode($plugin['macros'], true); if (!empty($macros)) { $macros = array_values($macros); if (!empty($macros)) { $plugin['macros'] = $macros; } } } echo io_json_mb_encode($plugin); return; } if ($get_agents) { $sql = "SELECT ta.id_agente, ta.alias AS agent_alias, tam.nombre AS module_name FROM tagente ta INNER JOIN tagente_modulo tam ON ta.id_agente = tam.id_agente AND tam.id_plugin = $plugin_id ORDER BY ta.alias, tam.nombre"; $result = db_get_all_rows_sql($sql); if (empty($result)) { $result = []; } $agents = []; $current_element = []; foreach ($result as $key => $value) { $id = (int) $value['id_agente']; $name = io_safe_output($value['agent_alias']); $module_name = $value['module_name']; if (!empty($current_element) && $current_element['id'] !== $id) { $agents[] = $current_element; $current_element = []; } $current_element['id'] = $id; $current_element['name'] = $name; if (!isset($current_element['module_names'])) { $current_element['module_names'] = []; } $current_element['module_names'][] = $module_name; } if (!empty($current_element)) { $agents[] = $current_element; } echo io_json_mb_encode($agents); return; } if ($get_module_plugin_macros) { $fields = ['macros']; $filter = [ 'id_plugin' => $plugin_id, 'id_agente' => $agent_ids, 'nombre' => $module_names, ]; $module_plugin_macros = db_get_all_rows_filter('tagente_modulo', $filter, $fields); $module_plugin_macros = io_safe_output($module_plugin_macros); if (empty($module_plugin_macros)) { $module_plugin_macros = []; } $module_plugin_macros = array_reduce( $module_plugin_macros, function ($carry, $item) { $macros = json_decode($item['macros'], true); if (!empty($macros)) { $macros = array_values($macros); if (!empty($macros)) { $carry[] = $macros; } } return $carry; }, [] ); echo io_json_mb_encode($module_plugin_macros); return; } return; } $update = (bool) get_parameter('update'); if ($update) { try { $plugin = db_get_row('tplugin', 'id', $plugin_id); // Macros retrieved from the plugin definition $plugin_macros = []; if (isset($plugin['macros'])) { $plugin_macros = json_decode($plugin['macros'], true); if (!empty($plugin_macros)) { $plugin_macros = array_values($plugin_macros); } } // Error if (empty($plugin_macros)) { throw new Exception(__('Error retrieving the plugin macros')); } // Macros returned by the form $macros = get_parameter('macros', []); // Error if (empty($macros)) { throw new Exception(__('Error retrieving the modified macros')); } $fields = [ 'id_agente_modulo', 'macros', ]; $filter = [ 'id_plugin' => $plugin_id, 'id_agente' => $agent_ids, 'nombre' => $module_names, ]; $module_plugin_macros = db_get_all_rows_filter( 'tagente_modulo', $filter, $fields ); if (empty($module_plugin_macros)) { $module_plugin_macros = []; } // Error if (empty($module_plugin_macros)) { throw new Exception(__('Error retrieving the module plugin macros')); } // Begin transaction // db_process_sql_begin(); $errors = 0; $count = 0; foreach ($module_plugin_macros as $item) { $module_id = $item['id_agente_modulo']; $module_macros_str = $item['macros']; // Macros retrieved from the agent module $module_macros = json_decode($module_macros_str, true); // Error if (empty($module_macros)) { throw new Exception( __('Error retrieving the module plugin macros data') ); } // Get the new module plugin macros $result_macros = array_map( function ($item) use ($macros, $module_macros) { $result = [ 'macro' => $item['macro'], 'desc' => $item['desc'], 'help' => $item['help'], 'hide' => $item['hide'], ]; // Get the default value os the module plugin macro $default = array_reduce( $module_macros, function ($carry, $module_macro) use ($result) { if (isset($module_macro['macro']) && $module_macro['macro'] == $result['macro']) { $carry = $module_macro['value']; } return $carry; }, '' ); set_if_defined($result['value'], $macros[$item['macro']]); set_unless_defined($result['value'], $default); return $result; }, $plugin_macros ); // Error if (empty($result_macros)) { throw new Exception(__('Error building the new macros')); } $module_macros = io_json_mb_encode($result_macros, JSON_FORCE_OBJECT); if (empty($module_macros)) { $module_macros = $module_macros_str; } $values = ['macros' => $module_macros]; $where = ['id_agente_modulo' => $module_id]; // $result = db_process_sql_update('tagente_modulo', $values, $where, 'AND', false); $result = db_process_sql_update('tagente_modulo', $values, $where); if (!$result) { $errors++; } else { $count += $result; } } // if (!$errors) { // db_process_sql_commit(); // } // else { // db_process_sql_rollback(); // } // Result message ui_print_info_message(sprintf(__('%d modules updated'), $count)); } catch (Exception $e) { ui_print_error_message($e->getMessage()); } } $table = new StdClass(); $table->id = 'massive_plugin_edition'; $table->width = '100%'; $table->rowstyle = []; $table->data = []; // Plugins $filter = ['order' => 'name']; $fields = [ 'id', 'name', ]; $plugins = db_get_all_rows_filter('tplugin', $filter, $fields); if (empty($plugins)) { ui_print_empty_data(__('There are not registered plugins')); return; } $plugins_aux = []; foreach ($plugins as $plugin) { $plugins_aux[$plugin['id']] = $plugin['name']; } $plugins = $plugins_aux; unset($plugins_aux); $plugins_select = html_print_select( $plugins, 'plugin_id', $plugin_id, '', __('None'), 0, true, false, false ); $row = []; $row[] = ''.__('Plugin').''; $row[] = $plugins_select; $table->data['plugin-ids-row'] = $row; // Agents & modules $row = []; // Agents $agents_select = html_print_select( $agent_ids, 'agent_ids[]', false, '', '', 0, true, true, false ); $row[] = ''.__('Agents').''; $row[] = $agents_select; // Modules // $modules_select = html_print_select ($module_ids, 'module_ids', // false, '', '', 0, true, true, false); $modules_select = html_print_select( $module_names, 'module_names[]', false, '', '', 0, true, true, false ); $row[] = ''._('Modules').''; $row[] = $modules_select; $table->rowstyle['agents-modules-row'] = 'vertical-align: top; display: none'; $table->data['agents-modules-row'] = $row; echo '
'; ?>