Example #1
0
     $idParentValue = null;
 } else {
     $idParentValue = sprintf('%d', $id_parent);
 }
 // DONT use MySQL NOW() or UNIXTIME_NOW() because
 // Integria can override localtime zone by a user-specified timezone.
 if ($config["change_incident_datetime"] && $creation_date && $creation_time) {
     $timestamp = "{$creation_date} {$creation_time}";
 } else {
     $timestamp = print_mysql_timestamp();
 }
 $values = array('inicio' => $timestamp, 'actualizacion' => $timestamp, 'titulo' => $titulo, 'descripcion' => $description, 'id_usuario' => $usuario, 'closed_by' => $closed_by, 'estado' => $estado, 'prioridad' => $priority, 'id_grupo' => $grupo, 'id_creator' => $id_creator, 'notify_email' => $email_notify, 'id_task' => $id_task, 'resolution' => $resolution, 'id_incident_type' => $id_incident_type, 'id_parent' => $idParentValue, 'sla_disabled' => $sla_disabled, 'email_copy' => $email_copy, 'editor' => $editor, 'id_group_creator' => $id_group_creator, 'blocked' => $blocked, 'old_status' => $old_status, 'old_resolution' => $old_resolution);
 $id = process_sql_insert('tincidencia', $values);
 if ($id !== false) {
     /* 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);
     }
Example #2
0
/**
 * 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;
    }
}
Example #3
0
        $idParentValue = sprintf('%d', $id_parent);
    }
    // DONT use MySQL NOW() or UNIXTIME_NOW() because
    // Integria can override localtime zone by a user-specified timezone.
    $timestamp = print_mysql_timestamp();
    $sql = sprintf('INSERT INTO tincidencia
			(inicio, actualizacion, titulo, descripcion,
			id_usuario, estado, prioridad,
			id_grupo, id_creator, notify_email, id_task,
			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) {
Example #4
0
 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;
     }
 }