'.html_print_image('images/setup.png', true, ['title' => __('Configure Integria IMS'), 'class' => 'invert_filter']).''; $list_tab['text'] = ''.html_print_image('images/list.png', true, ['title' => __('Ticket list'), 'class' => 'invert_filter']).''; $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('New ticket'), 'class' => 'invert_filter']).''; switch ($active_tab) { case 'setup_tab': $setup_tab['active'] = true; $list_tab['active'] = false; $create_tab['active'] = false; break; case 'list_tab': $setup_tab['active'] = false; $list_tab['active'] = true; $create_tab['active'] = false; break; case 'create_tab': $setup_tab['active'] = false; $list_tab['active'] = false; $create_tab['active'] = true; break; default: $setup_tab['active'] = false; $list_tab['active'] = false; $create_tab['active'] = false; break; } if ($view) { $create_tab['text'] = ''.html_print_image('images/pencil.png', true, ['title' => __('Edit ticket'), 'class' => 'invert_filter']).''; $view_tab['text'] = ''.html_print_image('images/operation.png', true, ['title' => __('View ticket'), 'class' => 'invert_filter']).''; // When the current page is the View page. if (!$active_tab) { $view_tab['active'] = true; } } $onheader = []; $onheader['view'] = $view_tab; $onheader['configure'] = $setup_tab; $onheader['list'] = $list_tab; $onheader['create'] = $create_tab; return $onheader; } /** * Gets all the details of Integria IMS API * * @param string $details Type of API call. * @param number $detail_index Send index if you want return the text. * * @return string or array with result of API call. */ function integriaims_get_details($details, $detail_index=false) { global $config; switch ($details) { case 'status': $operation = 'get_incidents_status'; break; case 'group': $operation = 'get_groups'; break; case 'priority': $operation = 'get_incident_priorities'; break; case 'resolution': $operation = 'get_incidents_resolutions'; break; case 'type': $operation = 'get_types'; break; default: // code... break; } $api_call = integria_api_call(null, null, null, null, $operation); $result = []; get_array_from_csv_data_pair($api_call, $result); if ($detail_index !== false) { if ($result[$detail_index] == '' || $result[$detail_index] === null) { return __('None'); } else { return $result[$detail_index]; } } else { return $result; } } /** * Perform an API call to Integria IMS. * * @param string|null $api_hostname API host URL. * @param string|null $user User name. * @param string|null $user_pass User password. * @param string|null $api_pass API password. * @param string|null $operation API Operation. * @param mixed $params String or array with parameters required by the API function. * @param mixed $show_credentials_error_msg Show_credentials_error_msg. * @param mixed $return_type Return_type. * @param mixed $token Token. * @param mixed $user_level_conf User_level_conf. * * @return boolean True if API request succeeded, false if API request failed. */ function integria_api_call( $api_hostname=null, $user=null, $user_pass=null, $api_pass=null, $operation=null, $params='', $show_credentials_error_msg=false, $return_type='', $token='', $user_level_conf=null ) { global $config; if (is_metaconsole()) { $servers = metaconsole_get_connection_names(); foreach ($servers as $key => $server) { $connection = metaconsole_get_connection($server); if (metaconsole_connect($connection) != NOERR) { continue; } $integria_enabled = db_get_sql( 'SELECT `value` FROM tconfig WHERE `token` = "integria_enabled"' ); if (!$integria_enabled) { metaconsole_restore_db(); continue; } // integria_user_level_conf, integria_hostname, integria_api_pass, integria_user, integria_user_level_user, integria_pass, integria_user_level_pass $config_aux = db_get_all_rows_sql('SELECT `token`, `value` FROM `tconfig` WHERE `token` IN ("integria_user_level_conf", "integria_hostname", "integria_api_pass", "integria_user", "integria_user_level_user", "integria_pass", "integria_user_level_pass")'); $user_info = users_get_user_by_id($config['id_user']); foreach ($config_aux as $key => $conf) { if ($conf['token'] === 'integria_user_level_conf') { $user_level_conf = $conf['value']; } if ($conf['token'] === 'integria_hostname') { $api_hostname = $conf['value']; } if ($conf['token'] === 'integria_api_pass') { $api_pass = $conf['value']; } if ($conf['token'] === 'integria_user') { $user = $conf['value']; } if ($conf['token'] === 'integria_pass') { $user_pass = $conf['value']; } } if ($user_level_conf == true) { $user = $user_info['integria_user_level_user']; $user_pass = $user_info['integria_user_level_pass']; } metaconsole_restore_db(); } } else { if ($user_level_conf === null) { $user_level_conf = (bool) $config['integria_user_level_conf']; } $user_info = users_get_user_by_id($config['id_user']); // API access data. if ($api_hostname === null) { $api_hostname = $config['integria_hostname']; } if ($api_pass === null) { $api_pass = $config['integria_api_pass']; } // Integria user and password. if ($user === null || $user_level_conf === true) { $user = $config['integria_user']; if ($user_level_conf === true) { $user = $user_info['integria_user_level_user']; } } if ($user_pass === null || $user_level_conf === true) { $user_pass = $config['integria_pass']; if ($user_level_conf === true) { $user_pass = $user_info['integria_user_level_pass']; } } } if (is_array($params)) { $params = implode($token, $params); } $url_data = [ 'user' => $user, 'user_pass' => $user_pass, 'pass' => $api_pass, 'op' => $operation, 'params' => io_safe_output($params), ]; if ($return_type !== '') { $url_data['return_type'] = $return_type; } if ($token !== '') { $url_data['token'] = $token; } // Build URL for API request. $url = $api_hostname.'/include/api.php'; // ob_start(); // $out = fopen('php://output', 'w'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $url_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_STDERR, $out); $result = curl_exec($ch); // fclose($out); // $debug = ob_get_clean(); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = false; if ($result === false) { $error = curl_error($ch); } curl_close($ch); if ($error === true || $http_status !== 200) { if ($show_credentials_error_msg === true) { ui_print_error_message(__('API request failed. Please check Integria IMS\' access credentials in Pandora setup.')); } return false; } else { return $result; } } // Parse CSV consisting of one or more lines of the form key-value pair into an array. function get_array_from_csv_data_pair($csv_data, &$array_values) { $csv_array = explode("\n", $csv_data); foreach ($csv_array as $csv_value) { if (empty($csv_value)) { continue; } $new_csv_value = str_getcsv($csv_value); $array_values[$new_csv_value[0]] = $new_csv_value[1]; } } /** * Parse CSV consisting of all lines into an array. * * @param string $csv_data Data returned of csv api call. * @param string $array_values Returned array. * @param array $index Array to create an associative index (opcional). */ function get_array_from_csv_data_all($csv_data, &$array_values, $index=false) { $csv_array = explode("\n", $csv_data); foreach ($csv_array as $csv_value) { if (empty($csv_value)) { continue; } $new_csv_value = str_getcsv($csv_value); if ($index !== false) { foreach ($new_csv_value as $key => $value) { $new_csv_value_index[$index[$key]] = str_replace(':::', ',', $value); ; } $array_values[$new_csv_value[0]] = $new_csv_value_index; } else { $new_csv_value_comma = array_map( function ($item) { return str_replace(':::', ',', $item); }, $new_csv_value ); $array_values[$new_csv_value[0]] = $new_csv_value_comma; } } } /** * Print priority for Integria IMS with colors. * * @param string $priority value of priority in Integria IMS. * @param string $priority_label text shown in color box. * * @return string HTML code. code to print the color box. */ function ui_print_integria_incident_priority($priority, $priority_label) { global $config; $output = ''; switch ($priority) { case 0: $color = COL_UNKNOWN; break; case 1: $color = COL_NORMAL; break; case 10: $color = COL_NOTINIT; break; case 2: $color = COL_WARNING; break; case 3: $color = COL_ALERTFIRED; break; case 4: $color = COL_CRITICAL; break; } $output = '