diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index d4cfc46505..1ff10f91b5 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5456,7 +5456,7 @@ if (!function_exists('getallheaders')) { function integria_api_call($api_hostname, $user, $user_pass, $api_pass, $operation, $params_array=[], $show_credentials_error_msg=false) { $params_string = implode(',', $params_array); - + hd($params_string, true); $url_data = [ 'user' => $user, 'user_pass' => $user_pass, diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 9c2feede2f..32efa75e8b 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -6651,7 +6651,6 @@ function events_get_field_value_by_event_id( ) { global $config; - $return = ''; $meta = false; $event = db_get_row('tevento', 'id_evento', $event_id); @@ -6674,11 +6673,11 @@ function events_get_field_value_by_event_id( $ip = __('N/A'); } - $return = str_replace('_agent_address_', $ip, $value); + $value = str_replace('_agent_address_', $ip, $value); } if (strpos($value, '_agent_id_') !== false) { - $return = str_replace('_agent_id_', $event['id_agente'], $value); + $value = str_replace('_agent_id_', $event['id_agente'], $value); } if (strpos($value, '_module_address_') !== false) { @@ -6693,7 +6692,7 @@ function events_get_field_value_by_event_id( $module['ip_target'] = __('N/A'); } - $return = str_replace('_module_address_', $module['ip_target'], $value); + $value = str_replace('_module_address_', $module['ip_target'], $value); if (empty($module['nombre'])) { $module['nombre'] = __('N/A'); } @@ -6702,7 +6701,7 @@ function events_get_field_value_by_event_id( metaconsole_restore_db(); } } else { - $return = str_replace('_module_address_', __('N/A'), $value); + $value = str_replace('_module_address_', __('N/A'), $value); } } @@ -6718,7 +6717,7 @@ function events_get_field_value_by_event_id( $module['ip_target'] = __('N/A'); } - $return = str_replace( + $value = str_replace( '_module_name_', io_safe_output($module['nombre']), $value @@ -6728,28 +6727,28 @@ function events_get_field_value_by_event_id( metaconsole_restore_db(); } } else { - $return = str_replace('_module_name_', __('N/A'), $value); + $value = str_replace('_module_name_', __('N/A'), $value); } } if (strpos($value, '_event_id_') !== false) { - $return = str_replace('_event_id_', $event['id_evento'], $value); + $value = str_replace('_event_id_', $event['id_evento'], $value); } if (strpos($value, '_user_id_') !== false) { if (!empty($event['id_usuario'])) { - $return = str_replace('_user_id_', $event['id_usuario'], $value); + $value = str_replace('_user_id_', $event['id_usuario'], $value); } else { - $return = str_replace('_user_id_', __('N/A'), $value); + $value = str_replace('_user_id_', __('N/A'), $value); } } if (strpos($value, '_group_id_') !== false) { - $return = str_replace('_group_id_', $event['id_grupo'], $value); + $value = str_replace('_group_id_', $event['id_grupo'], $value); } if (strpos($value, '_group_name_') !== false) { - $return = str_replace( + $value = str_replace( '_group_name_', groups_get_name($event['id_grupo'], true), $value @@ -6757,7 +6756,7 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_event_utimestamp_') !== false) { - $return = str_replace( + $value = str_replace( '_event_utimestamp_', $event['utimestamp'], $value @@ -6765,7 +6764,7 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_event_date_') !== false) { - $return = str_replace( + $value = str_replace( '_event_date_', date($config['date_format'], $event['utimestamp']), $value @@ -6773,7 +6772,7 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_event_text_') !== false) { - $return = str_replace( + $value = str_replace( '_event_text_', events_display_name($event['evento']), $value @@ -6781,7 +6780,7 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_event_type_') !== false) { - $return = str_replace( + $value = str_replace( '_event_type_', events_print_type_description($event['event_type'], true), $value @@ -6789,7 +6788,7 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_alert_id_') !== false) { - $return = str_replace( + $value = str_replace( '_alert_id_', empty($event['is_alert_am']) ? __('N/A') : $event['is_alert_am'], $value @@ -6797,11 +6796,11 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_event_severity_id_') !== false) { - $return = str_replace('_event_severity_id_', $event['criticity'], $value); + $value = str_replace('_event_severity_id_', $event['criticity'], $value); } if (strpos($value, '_event_severity_text_') !== false) { - $return = str_replace( + $value = str_replace( '_event_severity_text_', get_priority_name($event['criticity']), $value @@ -6809,27 +6808,27 @@ function events_get_field_value_by_event_id( } if (strpos($value, '_module_id_') !== false) { - $return = str_replace('_module_id_', $event['id_agentmodule'], $value); + $value = str_replace('_module_id_', $event['id_agentmodule'], $value); } if (strpos($value, '_event_tags_') !== false) { - $return = str_replace('_event_tags_', $event['tags'], $value); + $value = str_replace('_event_tags_', $event['tags'], $value); } if (strpos($value, '_event_extra_id_') !== false) { if (empty($event['id_extra'])) { - $return = str_replace('_event_extra_id_', __('N/A'), $value); + $value = str_replace('_event_extra_id_', __('N/A'), $value); } else { - $return = str_replace('_event_extra_id_', $event['id_extra'], $value); + $value = str_replace('_event_extra_id_', $event['id_extra'], $value); } } if (strpos($value, '_event_source_') !== false) { - $return = str_replace('_event_source_', $event['source'], $value); + $value = str_replace('_event_source_', $event['source'], $value); } if (strpos($value, '_event_instruction_') !== false) { - $return = str_replace( + $value = str_replace( '_event_instruction_', events_display_instructions($event['event_type'], $event, false), $value @@ -6838,15 +6837,15 @@ function events_get_field_value_by_event_id( if (strpos($value, '_owner_user_') !== false) { if (empty($event['owner_user'])) { - $return = str_replace('_owner_user_', __('N/A'), $value); + $value = str_replace('_owner_user_', __('N/A'), $value); } else { - $return = str_replace('_owner_user_', $event['owner_user'], $value); + $value = str_replace('_owner_user_', $event['owner_user'], $value); } } if (strpos($value, '_event_status_') !== false) { $event_st = events_display_status($event['estado']); - $return = str_replace('_event_status_', $event_st['title'], $value); + $value = str_replace('_event_status_', $event_st['title'], $value); } if (strpos($value, '_group_custom_id_') !== false) { @@ -6857,26 +6856,22 @@ function events_get_field_value_by_event_id( ) ); $event_st = events_display_status($event['estado']); - $return = str_replace('_group_custom_id_', $group_custom_id, $value); + $value = str_replace('_group_custom_id_', $group_custom_id, $value); } // Parse the event custom data. if (!empty($event['custom_data'])) { $custom_data = json_decode(base64_decode($event['custom_data'])); foreach ($custom_data as $key => $val) { - $return = str_replace('_customdata_'.$key.'_', $val, $value); + $value = str_replace('_customdata_'.$key.'_', $val, $value); } } // This will replace the macro with the current logged user. if (strpos($value, '_current_user_') !== false) { - $return = str_replace('_current_user_', $config['id_user'], $value); + $value = str_replace('_current_user_', $config['id_user'], $value); } - if (empty($return)) { - return $value; - } else { - return $return; - } + return $value; } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index e27b32b3f7..02ae758331 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -5904,7 +5904,11 @@ table.table_modal_alternate tr td:first-child { width: 100%; } -/* Class for integria incidents */ +/* + * --------------------------------------------------------------------- + * - INTEGRIA INCIDENTS + * --------------------------------------------------------------------- + */ div.priority { width: 80px; color: #fff; @@ -5914,3 +5918,13 @@ div.priority { display: table-cell; vertical-align: middle; } + +.comment_title { + padding: 5px 10px 5px 20px; + background-color: rgba(130, 185, 46, 0.16); + border-radius: 3px; +} + +.comment_body { + padding: 15px 20px 15px 20px; +} diff --git a/pandora_console/operation/incidents/configure_integriaims_incident.php b/pandora_console/operation/incidents/configure_integriaims_incident.php index 7b49cd2f63..4620fd8d02 100644 --- a/pandora_console/operation/incidents/configure_integriaims_incident.php +++ b/pandora_console/operation/incidents/configure_integriaims_incident.php @@ -16,14 +16,20 @@ global $config; check_login(); -if (! check_acl($config['id_user'], 0, 'IR') && ! check_acl($config['id_user'], 0, 'IW') && ! check_acl($config['id_user'], 0, 'IM')) { +if (!(check_acl($config['id_user'], 0, 'IW') && check_acl($config['id_user'], 0, 'IR'))) { // Doesn't have access to this page. db_pandora_audit('ACL Violation', 'Trying to access IntegriaIMS ticket creation'); include 'general/noaccess.php'; exit; } -ui_print_page_header(__('Create Integria IMS Incident'), '', false, '', false, ''); +$update = (isset($_GET['incident_id']) === true); + +if ($update) { + ui_print_page_header(__('Update Integria IMS Incident'), '', false, '', false, ''); +} else { + ui_print_page_header(__('Create Integria IMS Incident'), '', false, '', false, ''); +} // Check if Integria integration enabled. if ($config['integria_enabled'] == 0) { @@ -85,8 +91,6 @@ $incident_status = (int) get_parameter('status'); $incident_title = events_get_field_value_by_event_id($event_id, get_parameter('incident_title')); $incident_content = events_get_field_value_by_event_id($event_id, get_parameter('incident_content')); -$update = (isset($_GET['incident_id']) === true); - // If incident id is specified, retrieve incident values from api to populate combos with such values. if ($update) { // Call Integria IMS API method to get details of an incident given its id. @@ -148,7 +152,9 @@ $table->data[0][0] .= '
'.html_print_input_text( 100, true, false, - true + true, + '', + 'w100p' ).'
'; $table->data[1][0] = '

'.__('Type').':

'; @@ -174,7 +180,7 @@ $table->data[2][0] .= '
'.html_print_select( $update ? $incident_details[6] : $config['incident_status'], '', __('Select'), - 0, + 1, true, false, true, @@ -240,209 +246,241 @@ $table->data[3][0] .= '
'.html_print_textarea( true ).'
'; -// Here starts incident file management. -$upload_file = get_parameter('upload_file'); -$delete_file_id = get_parameter('delete_file'); +if ($update) { + // Here starts incident file management. + $upload_file = get_parameter('upload_file'); + $delete_file_id = get_parameter('delete_file'); + $download_file_id = get_parameter('download_file'); + $download_file_name = get_parameter('download_file_name'); -// Files section table. -$table_files_section = new stdClass(); -$table_files_section->width = '100%'; -$table_files_section->id = 'files_section_table'; -$table_files_section->class = 'databox filters'; -$table_files_section->head = []; + // Files section table. + $table_files_section = new stdClass(); + $table_files_section->width = '100%'; + $table_files_section->id = 'files_section_table'; + $table_files_section->class = 'databox filters'; + $table_files_section->head = []; -$table_files_section->data = []; -$table_files_section->size = []; -$table_files_section->colspan[2][0] = 3; + $table_files_section->data = []; + $table_files_section->size = []; + $table_files_section->colspan[2][0] = 3; -// Files list table. -$table_files = new stdClass(); -$table_files->width = '100%'; -$table_files->class = 'info_table'; -$table_files->head = []; + // Files list table. + $table_files = new stdClass(); + $table_files->width = '100%'; + $table_files->class = 'info_table'; + $table_files->head = []; -$table_files->head[0] = __('Filename'); -$table_files->head[1] = __('Timestamp'); -$table_files->head[2] = __('Description'); -$table_files->head[3] = __('User'); -$table_files->head[4] = __('Size'); -$table_files->head[5] = __('Delete'); + $table_files->head[0] = __('Filename'); + $table_files->head[1] = __('Timestamp'); + $table_files->head[2] = __('Description'); + $table_files->head[3] = __('User'); + $table_files->head[4] = __('Size'); + $table_files->head[5] = __('Delete'); -$table_files->data = []; + $table_files->data = []; -// Upload file. -if (check_acl($config['id_user'], 0, 'IW') && $upload_file && ($_FILES['userfile']['name'] != '')) { - $filedescription = get_parameter('file_description', __('No description available')); + // Upload file. + if (check_acl($config['id_user'], 0, 'IW') && $upload_file && ($_FILES['userfile']['name'] != '')) { + $filedescription = get_parameter('file_description', __('No description available')); - $filename = io_safe_input($_FILES['userfile']['name']); - $filesize = io_safe_input($_FILES['userfile']['size']); + $filename = io_safe_input($_FILES['userfile']['name']); + $filesize = io_safe_input($_FILES['userfile']['size']); - $extension = pathinfo($filename, PATHINFO_EXTENSION); - $invalid_extensions = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| - pif|vb|vbscript|wsf|asp|cer|csr|jsp|drv|sys|ade|adp|bas|chm|cpl|crt|csh|fxp|hlp|hta|inf|ins|isp|jse|htaccess| - htpasswd|ksh|lnk|mdb|mde|mdt|mdw|msc|msi|msp|mst|ops|pcd|prg|reg|scr|sct|shb|shs|url|vbe|vbs|wsc|wsf|wsh)$/i'; + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $invalid_extensions = '/^(bat|exe|cmd|sh|php|php1|php2|php3|php4|php5|pl|cgi|386|dll|com|torrent|js|app|jar|iso| + pif|vb|vbscript|wsf|asp|cer|csr|jsp|drv|sys|ade|adp|bas|chm|cpl|crt|csh|fxp|hlp|hta|inf|ins|isp|jse|htaccess| + htpasswd|ksh|lnk|mdb|mde|mdt|mdw|msc|msi|msp|mst|ops|pcd|prg|reg|scr|sct|shb|shs|url|vbe|vbs|wsc|wsf|wsh)$/i'; - if (!preg_match($invalid_extensions, $extension)) { - // The following is if you have clamavlib installed. - // (php5-clamavlib) and enabled in php.ini - // http://www.howtoforge.com/scan_viruses_with_php_clamavlib - if (extension_loaded('clamav')) { - cl_setlimits(5, 1000, 200, 0, 10485760); - $malware = cl_scanfile($_FILES['file']['tmp_name']); - if ($malware) { - $error = 'Malware detected: '.$malware.'
ClamAV version: '.clam_get_version(); - die($error); - // On malware, we die because it's not good to handle it + if (!preg_match($invalid_extensions, $extension)) { + // The following is if you have clamavlib installed. + // (php5-clamavlib) and enabled in php.ini + // http://www.howtoforge.com/scan_viruses_with_php_clamavlib + if (extension_loaded('clamav')) { + cl_setlimits(5, 1000, 200, 0, 10485760); + $malware = cl_scanfile($_FILES['file']['tmp_name']); + if ($malware) { + $error = 'Malware detected: '.$malware.'
ClamAV version: '.clam_get_version(); + die($error); + // On malware, we die because it's not good to handle it + } + } + + $filecontent = base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])); + + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'attach_file', [$incident_id_edit, $filename, $filesize, $filedescription, $filecontent]); + + // API method returns '0' string if success. + $file_added = ($result_api_call === '0') ? true : false; + + ui_print_result_message( + $file_added, + __('File successfully added'), + __('File could not be added') + ); + } + } + + // Delete file. + if (isset($_GET['delete_file'])) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'delete_file', [$delete_file_id]); + header('Location: index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&incident_id='.$incident_id_edit); + } + + // Download file. + if (isset($_GET['download_file'])) { + $file_base64 = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'download_file', [$download_file_id]); + ob_end_clean(); + + $decoded = base64_decode($file_base64); + + file_put_contents($download_file_name, $decoded); + ob_end_clean(); + + if (file_exists($download_file_name)) { + header('Content-Description: File Transfer'); + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="'.basename($download_file_name).'"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Content-Length: '.filesize($download_file_name)); + ob_end_clean(); + readfile($download_file_name); + exit; + } + + header('Location: index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&incident_id='.$incident_id_edit); + } + + // Retrieve files belonging to incident and create list table. + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_files', [$incident_id_edit]); + + if ($result_api_call != false && strlen($result_api_call) > 0) { + $files = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $files[] = explode(',', $csv_line); } } - - $filecontent = base64_encode(file_get_contents($_FILES['userfile']['tmp_name'])); - - $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'attach_file', [$incident_id_edit, $filename, $filesize, $filedescription, $filecontent]); - - // API method returns '0' string if success. - $file_added = ($result_api_call === '0') ? true : false; - - ui_print_result_message( - $file_added, - __('File successfully added'), - __('File could not be added') - ); } -} -// Delete file. -if (isset($_GET['delete_file']) && check_acl($config['id_user'], 0, 'IW')) { - $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'delete_file', [$delete_file_id]); - header('Location: index.php?sec=incident&sec2=operation/incidents/configure_integriaims_incident&incident_id='.$incident_id_edit); -} + $i = 0; -// Retrieve files belonging to incident and create list table. -$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_files', [$incident_id_edit]); - -if ($result_api_call != false && strlen($result_api_call) > 0) { - $files = []; - $csv_array = explode("\n", $result_api_call); - - foreach ($csv_array as $csv_line) { - if (!empty($csv_line)) { - $files[] = explode(',', $csv_line); - } - } -} - -$i = 0; - -foreach ($files as $key => $value) { - $table_files->data[$i][0] = $value[11]; - $table_files->data[$i][1] = $value[14]; - $table_files->data[$i][2] = $value[12]; - $table_files->data[$i][3] = $value[8]; - $table_files->data[$i][4] = $value[13]; - if (check_acl($config['id_user'], 0, 'IW')) { - $table_files->data[$i][5] .= ''; + foreach ($files as $key => $value) { + $table_files->data[$i][0] = ''.$value[11].''; + $table_files->data[$i][1] = $value[14]; + $table_files->data[$i][2] = $value[12]; + $table_files->data[$i][3] = $value[8]; + $table_files->data[$i][4] = $value[13]; + $table_files->data[$i][5] .= ''; $table_files->data[$i][5] .= html_print_image('images/cross.png', true, ['title' => __('Delete')]); $table_files->data[$i][5] .= ''; + + $i++; } - $i++; + $table_files_section->data[0][0] = '

'.__('File name').':

'; + $table_files_section->data[0][0] .= html_print_input_file('userfile', true); + $table_files_section->data[1][0] = '

'.__('Description').':

'; + $table_files_section->data[1][0] .= html_print_input_text( + 'file_description', + '', + __('Description'), + 50, + 100, + true, + false + ); + + $table_files_section->data[2][0] .= '
'.html_print_submit_button(__('Upload'), 'accion', false, 'class="sub wand"', true).'
'; + + $upload_file_form = '
'.'

'.__('Add attachment').'

'.html_print_table($table_files_section, true).html_print_input_hidden('upload_file', 1, true).'

'.__('Attached files').'

'.html_print_table($table_files, true).'
'; } - // header("Content-type: text/plain"); - // header("Content-Disposition: attachment; filename=savethis.txt"); - // do your Db stuff here to get the content into $content - // echo "This is some text...\n"; - // print $content; -$table_files_section->data[0][0] = '

'.__('File name').':

'; -$table_files_section->data[0][0] .= html_print_input_file('userfile', true); -$table_files_section->data[1][0] = '

'.__('Description').':

'; -$table_files_section->data[1][0] .= html_print_input_text( - 'file_description', - '', - __('Description'), - 50, - 100, - true, - false -); - -$table_files_section->data[2][0] .= '
'.html_print_submit_button(__('Upload'), 'accion', false, 'class="sub wand"', true).'
'; - -$upload_file_form = '

'.__('Add attachment').'

'.html_print_table($table_files_section, true).html_print_input_hidden('upload_file', 1, true).'

'.__('Attached files').'

'.html_print_table($table_files, true).'
'; - // Here starts incident comments management. -// Comments section table. -$table_comments_section = new stdClass(); -$table_comments_section->width = '100%'; -$table_comments_section->id = 'files_section_table'; -$table_comments_section->class = 'databox filters'; -$table_comments_section->head = []; +if ($update) { + $upload_comment = get_parameter('upload_comment'); + $comment_description = get_parameter('comment_description'); -$table_comments_section->data = []; -$table_comments_section->size = []; + // Comments section table. + $table_comments_section = new stdClass(); + $table_comments_section->width = '100%'; + $table_comments_section->id = 'files_section_table'; + $table_comments_section->class = 'databox filters'; + $table_comments_section->head = []; -// Comments list table. -$table_comments = new stdClass(); -$table_comments->width = '100%'; -$table_comments->class = 'info_table'; -$table_comments->head = []; + $table_comments_section->data = []; + $table_comments_section->size = []; -$table_comments->head[0] = __('Filename'); -$table_comments->head[1] = __('Timestamp'); -$table_comments->head[2] = __('Description'); -$table_comments->head[3] = __('User'); -$table_comments->head[4] = __('Size'); -$table_comments->head[5] = __('Delete'); + // Comments list table. + $table_comments = new stdClass(); + $table_comments->width = '100%'; + $table_comments->class = 'info_table'; + $table_comments->head = []; -$table_comments->data = []; + $table_comments->head[0] = __('Filename'); + $table_comments->head[1] = __('Timestamp'); + $table_comments->head[2] = __('Description'); + $table_comments->head[3] = __('User'); + $table_comments->head[4] = __('Size'); + $table_comments->head[5] = __('Delete'); -$table_comments_section->data[0][0] = '

'.__('Description').':

'; -$table_comments_section->data[0][0] .= html_print_input_text( - 'file_description', - '', - __('Description'), - 50, - 100, - true, - false -); + $table_comments->data = []; -$i = 0; + $table_comments_section->data[0][0] = '

'.__('Description').':

'; + $table_comments_section->data[0][0] .= html_print_textarea( + 'comment_description', + 3, + 20, + '', + '', + true + ); -// Retrieve comments belonging to incident and create comments table. -$result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_workunits', [$incident_id_edit]); + $table_comments_section->data[1][1] .= '
'.html_print_submit_button(__('Add'), 'accion', false, 'class="sub wand"', true).'
'; -if ($result_api_call != false && strlen($result_api_call) > 0) { - $comments = []; - $csv_array = explode("\n", $result_api_call); + // Upload comment. + if ($upload_comment) { + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'create_workunit', [$incident_id_edit, $comment_description, '0.00', 'no', 'no', '0']); - foreach ($csv_array as $csv_line) { - if (!empty($csv_line)) { - $comments[] = explode(',', $csv_line); + // API method returns id of new comment if success. + $comment_added = ($result_api_call >= '0') ? true : false; + + ui_print_result_message( + $comment_added, + __('Comment successfully added'), + __('Comment could not be added') + ); + } + + // Retrieve comments belonging to incident and create comments table. + $result_api_call = integria_api_call($config['integria_hostname'], $config['integria_user'], $config['integria_pass'], $config['integria_api_pass'], 'get_incident_workunits', [$incident_id_edit]); + + + + if ($result_api_call != false && strlen($result_api_call) > 0) { + $comments = []; + $csv_array = explode("\n", $result_api_call); + + foreach ($csv_array as $csv_line) { + if (!empty($csv_line)) { + $comments[] = explode(',', $csv_line); + } } } + + $upload_comment_form = ''; + foreach ($comments as $key => $value) { + $upload_comment_form .= '
'.$value[3].' said '.$value[1].''.$value[2].' Hours
'; + $upload_comment_form .= '
'.$value[4].'
'; + } + + $upload_comment_form = '

'.__('Add comment').'

'.html_print_table($table_comments_section, true).html_print_input_hidden('upload_comment', 1, true).'
'.'

'.__('Comments').'

'.$upload_comment_form.'
'; } -foreach ($comments as $key => $value) { - $table_comments->data[$i][0] = $value[11]; - $table_comments->data[$i][1] = $value[14]; - $table_comments->data[$i][2] = $value[12]; - $table_comments->data[$i][3] = $value[8]; - $table_comments->data[$i][4] = $value[13]; - - $i++; -} - -/* - $upload_file_form = '

'.__('Add comment').'

' - .html_print_table($table_comments_section, true) - .html_print_input_hidden('upload_file', 1, true) - .'
' - .'

'.__('Comments').'

' - .html_print_table($table_comments, true) - .'
';*/ -// // Print forms and stuff. echo '
'; html_print_table($table); @@ -453,20 +491,40 @@ if (!$update) { html_print_input_hidden('update_incident', 1); } -echo '
'; -echo '
'; -ui_toggle( - $upload_file_form, - __('Attached files'), - '', - '', - true, - false, - 'white_box white_box_opened', - 'no-border flex' -); -echo '
'; +if ($update) { + echo ''; + echo '
'; + ui_toggle( + $upload_file_form, + __('Attached files'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' + ); + echo '
'; + + echo '
'; + ui_toggle( + $upload_comment_form, + __('Comments'), + '', + '', + true, + false, + 'white_box white_box_opened', + 'no-border flex' + ); + echo '
'; +} echo '
'; -html_print_submit_button(__('Create'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +if ($update) { + html_print_submit_button(__('Update'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} else { + html_print_submit_button(__('Create'), 'accion', false, 'form="create_integria_incident_form" class="sub wand"'); +} + echo '
';