function create_workunit($incident_id, $wu_text, $user, $timeused = 0, $have_cost = 0, $profile = "", $public = 1, $send_email = 1, $work_home = 0, $workflow = false) { $fecha = print_mysql_timestamp(); $sql = sprintf('UPDATE tincidencia SET affected_sla_id = 0, actualizacion = "%s" WHERE id_incidencia = %d', $fecha, $incident_id); process_sql($sql); if (!$workflow) { incident_tracking($incident_id, INCIDENT_WORKUNIT_ADDED); } // Add work unit if enabled $sql = sprintf('INSERT INTO tworkunit (timestamp, duration, id_user, description, public, work_home) VALUES ("%s", %.2f, "%s", "%s", %d, %d)', $fecha, $timeused, $user, $wu_text, $public, $work_home); $id_workunit = process_sql($sql, "insert_id"); $sql = sprintf('INSERT INTO tworkunit_incident (id_incident, id_workunit) VALUES (%d, %d)', $incident_id, $id_workunit); $res = process_sql($sql); if ($res !== false) { // Email notify to all people involved in this incident $email_notify = get_db_value("notify_email", "tincidencia", "id_incidencia", $incident_id); if ($email_notify == 1 and $send_email == 1) { mail_incident($incident_id, $user, $wu_text, $timeused, 10, $public); } } else { //Delete workunit $sql = sprintf('DELETE FROM tworkunit WHERE id = %d', $id_workunit); return false; } return $id_workunit; }
function create_workunit($incident_id, $wu_text, $user, $timeused = 0, $have_cost = 0, $profile = "", $public = 1, $send_email = 1, $work_home = 0, $workflow = false) { global $config; $fecha = print_mysql_timestamp(); $sql = sprintf('UPDATE tincidencia SET affected_sla_id = 0, actualizacion = "%s" WHERE id_incidencia = %d', $fecha, $incident_id); process_sql($sql); $task_id = get_db_value('id_task', 'tincidencia', 'id_incidencia', $incident_id); if (!$workflow) { incident_tracking($incident_id, INCIDENT_WORKUNIT_ADDED); } // Add work unit if enabled $sql = sprintf('INSERT INTO tworkunit (timestamp, duration, id_user, description, public, work_home) VALUES ("%s", %.2f, "%s", "%s", %d, %d)', $fecha, $timeused, $user, $wu_text, $public, $work_home); $id_workunit = process_sql($sql, "insert_id"); $sql = sprintf('INSERT INTO tworkunit_incident (id_incident, id_workunit) VALUES (%d, %d)', $incident_id, $id_workunit); $res = process_sql($sql); if ($task_id) { $sql = sprintf('INSERT INTO tworkunit_task (id_task, id_workunit) VALUES (%d, %d)', $task_id, $id_workunit); $res = process_sql($sql); } if ($res !== false) { $email_copy_sql = 'select email_copy from tincidencia where id_incidencia =' . $incident_id . ';'; $email_copy = get_db_sql($email_copy_sql); if ($send_email == 1) { if ($email_copy != "") { mail_incident($incident_id, $user, $wu_text, $timeused, 10, 7); } if ($config["email_on_incident_update"] != 2 && $config["email_on_incident_update"] != 4) { mail_incident($incident_id, $user, $wu_text, $timeused, 10); } } } else { //Delete workunit $sql = sprintf('DELETE FROM tworkunit WHERE id = %d', $id_workunit); return false; } return $id_workunit; }
/* Update inventory objects in incident */ update_incident_inventories($id, get_parameter('inventories')); $result_msg = '<h3 class="suc">' . __('Successfully created') . ' (id #' . $id . ')</h3>'; $result_msg .= '<h4><a href="index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=' . $id . '">' . __('Please click here to continue working with incident #') . $id . "</a></h4>"; //Add traces and statistic information incidents_set_tracking($id, 'create', $priority, $estado, $resolution, $usuario, $grupo); audit_db($config["id_user"], $config["REMOTE_ADDR"], "Ticket created", "User " . $config['id_user'] . " created incident #" . $id); // Create automatically a WU with the editor ? if ($config["incident_creation_wu"] == 1) { $wu_text = __("WU automatically created by the editor on the incident creation."); // Do not send mail in this WU create_workunit($id, $wu_text, $editor, $config["iwu_defaultime"], 0, "", 1, 0); } // Email notify to all people involved in this incident if ($email_notify) { mail_incident($id, $usuario, "", 0, 1); } //insert data to incident type fields if ($id_incident_type != 0) { $sql_label = "SELECT `label` FROM `tincident_type_field` WHERE id_incident_type = {$id_incident_type}"; $labels = get_db_all_rows_sql($sql_label); if ($labels === false) { $labels = array(); } foreach ($labels as $label) { $id_incident_field = get_db_value_filter('id', 'tincident_type_field', array('id_incident_type' => $id_incident_type, 'label' => $label['label']), 'AND'); $values_insert['id_incident'] = $id; $values_insert['data'] = get_parameter(base64_encode($label['label'])); //~ $values_insert['data'] = str_replace('
', "",get_parameter (base64_encode($label['label']))); $values_insert['id_incident_field'] = $id_incident_field; $id_incident_field = get_db_value('id', 'tincident_type_field', 'id_incident_type', $id_incident_type);
resolution, id_incident_type, sla_disabled, email_copy, epilog) VALUES ("%s", "%s", "%s", "%s", "%s", %d, %d, %d, "%s", %d, %d, %d, %d, %d, "%s", "%s")', $timestamp, $timestamp, $title, $description, $id_user_responsible, $estado, $priority, $group_id, $id_creator, $email_notify, $id_task, $resolution, $id_incident_type, $sla_disabled, $email_copy, $epilog); $id = process_sql($sql, 'insert_id'); if ($id !== false) { /* Update inventory objects in incident */ update_incident_inventories($id, array($id_inventory)); $result_msg = ui_print_success_message(__('Successfully created') . ' (id #' . $id . ')', '', true); $result_msg .= '<h4><a href="index.php?sec=incidents&sec2=operation/incidents_simple/incident&id=' . $id . '">' . __('Please click here to continue working with ticket #') . $id . "</a></h4>"; audit_db($config["id_user"], $config["REMOTE_ADDR"], "Ticket created", "User " . $config['id_user'] . " created ticket #" . $id); incident_tracking($id, INCIDENT_CREATED); //Add traces and statistic information incidents_set_tracking($id, 'create', $priority, $estado, $resolution, $id_user_responsible, $group_id); // Email notify to all people involved in this incident if ($email_notify) { mail_incident($id, $id_user_responsible, "", 0, 1); } //insert data to incident type fields if ($id_incident_type > 0) { $sql_label = "SELECT `label` FROM `tincident_type_field` WHERE id_incident_type = {$id_incident_type}"; $labels = get_db_all_rows_sql($sql_label); if ($labels === false) { $labels = array(); } foreach ($labels as $label) { $id_incident_field = get_db_value_filter('id', 'tincident_type_field', array('id_incident_type' => $id_incident_type, 'label' => $label['label']), 'AND'); $values_insert['id_incident'] = $id; $values_insert['data'] = get_parameter(base64_encode($label['label'])); $values_insert['id_incident_field'] = $id_incident_field; $id_incident_field = get_db_value('id', 'tincident_type_field', 'id_incident_type', $id_incident_type); process_sql_insert('tincident_field_data', $values_insert);
/** * Create an incident * @param $return_type xml or csv * @param $user user who call function * @param $params array (title, group, priority, description) * @return unknown_type */ function api_create_incident($return_type, $user, $params) { global $config; $config['id_user'] = $user; // $id is the user who create the incident $group = $params[1]; if (!give_acl($user, $group, "IW")) { audit_db($user, $_SERVER['REMOTE_ADDR'], "ACL Forbidden from API", "User " . $user . " try to create ticket"); exit; } $timestamp = print_mysql_timestamp(); // Read input variables $title = $params[0]; $description = $params[3]; $source = 1; // User report $priority = $params[2]; $id_creator = $user; $id_inventory = $params[4]; $id_incident_type = (int) $params[5]; $email_copy = $params[6]; $owner = $params[7]; $id_parent = $params[8]; $status = $params[9]; $extra_data = $params[10]; $resolution = $params[11]; $extra_data2 = $params[12]; $inicio = $timestamp; $actualizacion = $timestamp; // Check if user and title is not empty and user exists if (empty($title)) { exit; } if ($owner == '') { $owner = get_db_sql("select id_user_default from tgrupo WHERE id_grupo = {$group}"); } if ($id_inventory == 0) { $id_inventory = get_db_sql("select id_inventory_default from tgrupo WHERE id_grupo = {$group}"); } $timestamp = print_mysql_timestamp(); $check_status = enterprise_hook("incidents_check_allowed_status", array($status, $status, true, true, false)); //incidents_check_allowed_status ($old_status, $new_status, $initial = false, $echo_message = false, $included_status = true) if ($check_status == ENTERPRISE_NOT_HOOK) { $check_status = true; } if ($status == STATUS_CLOSED) { $check_resolution = enterprise_hook("incidents_check_allowed_resolution", array($resolution, $status, 0, true)); if ($check_resolution == ENTERPRISE_NOT_HOOK) { $check_resolution = true; } } else { $check_resolution = true; $enterprise = enterprise_hook("incidents_check_allowed_resolution", array($resolution, $status, 0, true)); if ($enterprise != ENTERPRISE_NOT_HOOK) { $resolution = 0; } } if ($id_parent == 0) { $sql = sprintf('INSERT INTO tincidencia (inicio, actualizacion, titulo, descripcion, id_usuario, estado, prioridad, id_grupo, id_creator, resolution, email_copy, id_incident_type, extra_data, extra_data2) VALUES ("%s", "%s", "%s", "%s", "%s", %d, %d, %d, "%s", %d, "%s", %d, "%s", "%s")', $timestamp, $timestamp, $title, $description, $owner, $status, $priority, $group, $id_creator, $resolution, $email_copy, $id_incident_type, $extra_data, $extra_data2); } else { $sql = sprintf('INSERT INTO tincidencia (inicio, actualizacion, titulo, descripcion, id_usuario, estado, prioridad, id_grupo, id_creator, resolution, email_copy, id_incident_type, id_parent, extra_data, extra_data2) VALUES ("%s", "%s", "%s", "%s", "%s", %d, %d, %d, "%s", %d, "%s", %d, %d, "%s", "%s")', $timestamp, $timestamp, $title, $description, $owner, $status, $priority, $group, $id_creator, $resolution, $email_copy, $id_incident_type, $id_parent, $extra_data, $extra_data2); } if ($check_status && $check_resolution) { $id = process_sql($sql, 'insert_id'); } else { $id = false; } if ($id !== false) { $inventories = array(); $inventories[0] = $id_inventory; /* Update inventory objects in incident */ update_incident_inventories($id, $inventories); $result = $id; audit_db($id_creator, $_SERVER['REMOTE_ADDR'], "Incident created (From API)", "User " . $id_creator . " created ticket #" . $id); incident_tracking($id, INCIDENT_CREATED); // Email notify to all people involved in this incident if ($email_copy != "") { mail_incident($id, $user, "", 0, 1, 7); } if ($config["email_on_incident_update"] != 3 && $config["email_on_incident_update"] != 4) { mail_incident($id, $user, "", 0, 1); } //insert data to incident type fields if ($id_incident_type != 0) { $sql_label = "SELECT `label` FROM `tincident_type_field` WHERE id_incident_type = {$id_incident_type}"; $labels = get_db_all_rows_sql($sql_label); if ($labels === false) { $labels = array(); } $num_params = 13; foreach ($labels as $label) { $id_incident_field = get_db_value_filter('id', 'tincident_type_field', array('id_incident_type' => $id_incident_type, 'label' => $label['label']), 'AND'); $values_insert['id_incident'] = $id; $values_insert['data'] = $params[$num_params]; $values_insert['id_incident_field'] = $id_incident_field; $id_incident_field = get_db_value('id', 'tincident_type_field', 'id_incident_type', $id_incident_type); process_sql_insert('tincident_field_data', $values_insert); $num_params++; } } } else { $result = -1; } switch ($return_type) { case "xml": echo xml_node($result); break; case "csv": echo $result; break; case "int": return $result; break; } }
"timestamp" => date("Y-m-d") ); $id_attachment = process_sql_insert("tattachment", $values); if ($id_attachment) { incident_tracking ($id, INCIDENT_FILE_ADDED); // Email notify to all people involved in this incident // Email in list email-copy $email_copy_sql = 'select email_copy from tincidencia where id_incidencia ='.$id.';'; $email_copy = get_db_sql($email_copy_sql); if ($email_copy != "") { mail_incident ($id, $config['id_user'], 0, 0, 2, 7); } if (($config["email_on_incident_update"] != 2) && ($config["email_on_incident_update"] != 4)) { mail_incident ($id, $config['id_user'], 0, 0, 2); } $location = $config["homedir"]."/attachment/".$id_attachment."_".$filename; if (copy($file_tmp, $location)) { // Delete temporal file unlink ($file_tmp); $result["status"] = true; $result["id_attachment"] = $id_attachment; // Adding a WU noticing about this $link = "<a target=\"_blank\" href=\"operation/common/download_file.php?type=incident&id_attachment=".$id_attachment."\">".$filename."</a>"; $nota = "Automatic WU: Added a file to this issue. Filename uploaded: ". $link; $timestamp = print_mysql_timestamp();
/** * Auto close incidents mark as "pending to be deleted" and no activity in X hrs * Takes no parameters. Checked in the main loop.with the other tasks. */ function run_auto_incident_close() { global $config; if (empty($config["auto_incident_close"]) || $config["auto_incident_close"] <= 0) { return; } require_once $config["homedir"] . "/include/functions_incidents.php"; $utimestamp = date("U"); $limit = date("Y-m-d H:i:s", $utimestamp - $config["auto_incident_close"] * 86400); // For each incident $incidents = get_db_all_rows_sql("SELECT * FROM tincidencia WHERE estado IN (1,2,3,4,5) AND actualizacion < '{$limit}'"); $mailtext = __("This ticket has been closed automatically by Integria after waiting confirmation to close this ticket for \n") . $config["auto_incident_close"] . " " . __("days"); if ($incidents) { foreach ($incidents as $incident) { // Set status to "Closed" (# 7) and solution to 7 (Expired) process_sql("UPDATE tincidencia SET resolution = 7, estado = 7 WHERE id_incidencia = " . $incident["id_incidencia"]); // Add workunit create_workunit($incident["id_incidencia"], $mailtext, $incident["id_usuario"], 0, 0, "", 1); // Send mail warning about this autoclose if ($config["email_on_incident_update"] != 2 && $config["email_on_incident_update"] != 4) { mail_incident($incident["id_incidencia"], $incident["id_usuario"], $mailtext, 0, 10, 1); } } } }
$email_copy_sql = 'select email_copy from tincidencia where id_incidencia =' . $id_ticket . ';'; $email_copy = get_db_sql($email_copy_sql); if ($email_copy != "") { if ($values['estado'] == 7) { mail_incident($id_ticket, $owner, "", 0, 5, 7); } else { mail_incident($id_ticket, $owner, "", 0, 0, 7); } } if ($config["email_on_incident_update"] != 3 && $config["email_on_incident_update"] != 4 && $values['estado'] == 7) { //add emails only closed mail_incident($id_ticket, $owner, "", 0, 5); } else { if ($config["email_on_incident_update"] == 0) { //add emails updates mail_incident($id_ticket, $owner, "", 0, 0); } } if ($old_incident['prioridad'] != $values['prioridad']) { incident_tracking($id_ticket, INCIDENT_PRIORITY_CHANGED, $values['prioridad']); } if ($old_incident['resolution'] != $values['resolution']) { incident_tracking($id_ticket, INCIDENT_RESOLUTION_CHANGED, $values['resolution']); } if ($old_incident['estado'] != $values['estado']) { if ($values['estado'] == 7) { $values_close['closed_by'] = $config['id_user']; $values_close['cierre'] = date('Y:m:d H:i:s'); db_process_sql_update('tincidencia', $values_close, array('id_incidencia' => $id_ticket)); } incident_tracking($id_ticket, INCIDENT_STATUS_CHANGED, $values['estado']);
/** * Copy and insert in database a new file into incident * * @param int incident id * @param string file full path * @param string file description * */ function attach_incident_file($id, $file_temp, $file_description, $email_notify = false, $file_name = "") { global $config; $file_temp = safe_output($file_temp); // Decoding HTML entities $filesize = filesize($file_temp); // In bytes if ($file_name != "") { $filename = $file_name; } else { $filename = basename($file_temp); } $filename = str_replace(array(" ", "(", ")"), "_", $filename); // Replace blank spaces $filename = filter_var($filename, FILTER_SANITIZE_URL); // Replace conflictive characters $sql = sprintf('INSERT INTO tattachment (id_incidencia, id_usuario, filename, description, size) VALUES (%d, "%s", "%s", "%s", %d)', $id, $config['id_user'], $filename, $file_description, $filesize); $id_attachment = process_sql($sql, 'insert_id'); incident_tracking($id, INCIDENT_FILE_ADDED); $result_msg = ui_print_success_message(__('File added'), '', true); // Email notify to all people involved in this incident if ($email_notify) { if ($config["email_on_incident_update"] == 1) { mail_incident($id, $config['id_user'], 0, 0, 2); } } // Copy file to directory and change name $file_target = $config["homedir"] . "attachment/" . $id_attachment . "_" . $filename; $copy = copy($file_temp, $file_target); if (!$copy) { $result_msg = ui_print_error_message(__('File cannot be saved. Please contact Integria administrator about this error'), '', true); $sql = sprintf('DELETE FROM tattachment WHERE id_attachment = %d', $id_attachment); process_sql($sql); } else { // Delete temporal file unlink($file_temp); // Adding a WU noticing about this $link = "<a target='_blank' href='operation/common/download_file.php?type=incident&id_attachment=" . $id_attachment . "'>" . $filename . "</a>"; $note = "Automatic WU: Added a file to this issue. Filename uploaded: " . $link; $public = 1; $timeused = 0; create_workunit($id, $note, $config["id_user"], $timeused, 0, "", $public); $timestamp = print_mysql_timestamp(); $sql = sprintf('UPDATE tincidencia SET actualizacion = "%s" WHERE id_incidencia = %d', $timestamp, $id); process_sql($sql); } return $result_msg; }
public function insertIncident($title, $description, $group_id, $id_creator = "", $status = 1, $priority = 2, $resolution = 0, $id_task = 0, $sla_disabled = 0, $id_incident_type = 0, $email_copy = "", $email_notify = -1, $id_parent = 0, $epilog = "") { $system = System::getInstance(); if ($id_creator == "") { $id_creator = $system->getConfig('id_user'); } if ($email_notify == -1) { $email_notify = get_db_value("forced_email", "tgrupo", "id_grupo", $group_id); } if ($id_parent == 0) { $idParentValue = 'NULL'; } else { $idParentValue = sprintf('%d', $id_parent); } $user_responsible = get_group_default_user($group_id); $id_user_responsible = $user_responsible['id_usuario']; if ($id_user_responsible === false) { $id_user_responsible = $system->getConfig('id_user'); } $id_inventory = get_group_default_inventory($group_id, true); // DONT use MySQL NOW() or UNIXTIME_NOW() because // Integria can override localtime zone by a user-specified timezone. $timestamp = print_mysql_timestamp(); $sql = "INSERT INTO tincidencia\n\t\t\t\t(inicio, actualizacion, titulo, descripcion, id_usuario,\n\t\t\t\testado, prioridad, id_grupo, id_creator, notify_email, id_task,\n\t\t\t\tresolution, id_incident_type, sla_disabled, email_copy, epilog)\n\t\t\t\tVALUES ('{$timestamp}', '{$timestamp}', '{$title}', '{$description}',\n\t\t\t\t'{$id_user_responsible}', {$status}, {$priority}, {$group_id}, '{$id_creator}',\n\t\t\t\t{$email_notify}, {$id_task}, {$resolution}, {$id_incident_type}, {$sla_disabled},\n\t\t\t\t'{$email_copy}', '{$epilog}')"; $id_incident = process_sql($sql, 'insert_id'); if ($id_incident !== false) { if (include_once $system->getConfig('homedir') . "/include/functions_incidents.php") { /* Update inventory objects in incident */ update_incident_inventories($id_incident, array($id_inventory)); } audit_db($config["id_user"], $config["REMOTE_ADDR"], "Ticket created", "User " . $config['id_user'] . " created ticket #" . $id_incident); incident_tracking($id_incident, INCIDENT_CREATED); // Email notify to all people involved in this incident if ($email_notify) { mail_incident($id_incident, $usuario, "", 0, 1); } // Insert data of incident type fields if ($id_incident_type > 0) { $sql_label = "SELECT `label` FROM `tincident_type_field` WHERE id_incident_type = {$id_incident_type}"; $labels = get_db_all_rows_sql($sql_label); if ($labels === false) { $labels = array(); } foreach ($labels as $label) { $id_incident_field = get_db_value_filter('id', 'tincident_type_field', array('id_incident_type' => $id_incident_type, 'label' => $label['label']), 'AND'); $values_insert['id_incident'] = $id_incident; $values_insert['data'] = $system->getRequest(base64_encode($label['label'])); $values_insert['id_incident_field'] = $id_incident_field; $id_incident_field = get_db_value('id', 'tincident_type_field', 'id_incident_type', $id_incident_type); process_sql_insert('tincident_field_data', $values_insert); } } return $id_incident; } }