Esempio n. 1
0
/**
 * Calculate task completion porcentage and set on task
 *
 * @param int Id of the task to calculate.
 */
function set_task_completion($id_task)
{
    $hours_worked = get_task_workunit_hours($id_task);
    $hours_estimated = get_db_value('hours', 'ttask', 'id', $id_task);
    if ($hours_estimated == 0) {
        return 0;
    }
    $percentage_completed = $hours_worked * 100 / $hours_estimated;
    process_sql_update('ttask', array('completion' => $percentage_completed), array('id' => $id_task));
    return $percentage_completed;
}
Esempio n. 2
0
function mysql_session_write($SessionID, $val)
{
    $SessionID = addslashes($SessionID);
    $val = addslashes($val);
    $sql = "SELECT COUNT(*) FROM tsessions_php\n\t\tWHERE id_session = '{$SessionID}'";
    $SessionExists = process_sql($sql);
    $session_exists = $SessionExists[0]['COUNT(*)'];
    if ($session_exists == 0) {
        $now = time();
        $retval_write = process_sql_insert('tsessions_php', array('id_session' => $SessionID, 'last_active' => $now, 'data' => $val));
    } else {
        $now = time();
        $retval_write = process_sql_update('tsessions_php', array('last_active' => $now, 'data' => $val), array('id_session' => $SessionID));
    }
    return $retval_write;
}
Esempio n. 3
0
    $id = 0;
}
// UPDATE
if ($update) {
    $id = get_parameter("id", 1);
    $email_subject = get_parameter("email_subject");
    $status = get_parameter("status");
    $html = get_parameter("html");
    $plain = get_parameter("plain");
    $date = get_parameter("issue_date");
    $time = get_parameter("issue_time");
    $id_newsletter = get_parameter("id_newsletter");
    $campaign = get_parameter("campaign");
    $from_address = get_parameter("from_address");
    $values = array('id_newsletter' => $id_newsletter, 'email_subject' => $email_subject, 'html' => $html, 'plain' => $plain, 'status' => $status, 'datetime' => $date . " " . $time, 'id_campaign' => $campaign, 'from_address' => $from_address);
    $result = process_sql_update('tnewsletter_content', $values, array('id' => $id));
    if ($result === false) {
        echo "<h3 class='error'>" . __('Could not be updated') . "</h3>";
    } else {
        echo "<h3 class='suc'>" . __('Successfully updated') . "</h3>";
        audit_db($config["id_user"], $config["REMOTE_ADDR"], "NEWSLETTER UPDATED", "Updated newsletter issue {$email_subject}");
    }
    $id = 0;
}
// DELETE
if ($delete) {
    // if delete
    $id = (int) get_parameter('id');
    $id_newsletter = get_db_value("id_newsletter", "tnewsletter_content", "id", $id);
    $name = get_db_value('name', 'tnewsletter', 'id', $id_newsletter);
    $sql = sprintf('DELETE FROM tnewsletter_content WHERE id = %d', $id);
        echo "<h3 class='error'>" . __('There was a problem deleting row') . "</h3>";
    }
}
if ($update_row) {
    $key = get_parameter('key');
    $key_value = get_parameter('key_value');
    $fields = get_db_all_rows_sql("DESC " . $external_table);
    if ($fields == false) {
        $fields = array();
    }
    foreach ($fields as $field) {
        if ($field['Field'] != $key) {
            $values[$field['Field']] = get_parameter($field['Field']);
        }
    }
    $result = process_sql_update($external_table, $values, array($key => $key_value));
    if ($result) {
        echo "<h3 class='suc'>" . __('Updated row') . "</h3>";
    } else {
        echo "<h3 class='error'>" . __('There was a problem updating row') . "</h3>";
    }
}
if ($insert_row) {
    $fields = get_db_all_rows_sql("DESC " . $external_table);
    $key = get_parameter('key');
    if ($fields == false) {
        $fields = array();
    }
    foreach ($fields as $field) {
        if ($field['Field'] != $key) {
            $values[$field['Field']] = get_parameter($field['Field']);
$id = (int) get_parameter('id');
$create = (bool) get_parameter('create');
$update = (bool) get_parameter('update');
$delete = (bool) get_parameter('delete');
$validate_newsletter = (bool) get_parameter('validate_newsletter', 0);
if ($validate_newsletter) {
    $sql = "SELECT * FROM tnewsletter_address WHERE id_newsletter = {$id} AND validated = 0";
    $newsletter_emails = get_db_all_rows_sql($sql);
    if ($newsletter_emails === false) {
        $newsletter_emails = array();
    }
    $i = 0;
    foreach ($newsletter_emails as $email) {
        $values['validated'] = 1;
        $values['status'] = 0;
        process_sql_update('tnewsletter_address', $values, array('id' => $email['id']));
        $i++;
    }
    echo "<h3 class='suc'>" . __('Emails validated: ') . $i . "</h3>";
    $id = 0;
}
// CREATE
if ($create) {
    if (!$manager) {
        audit_db($config["id_user"], $config["REMOTE_ADDR"], "ACL Violation", "Trying to create a new newsletter");
        require "general/noaccess.php";
        exit;
    }
    $name = get_parameter("name");
    $id_group = get_parameter("id_group", 1);
    $from_desc = get_parameter("from_desc");
Esempio n. 6
0
			$result["message"] = $upload_result;
		}

		echo json_encode($result);
		return;
	}

	$update_file_description = (bool) get_parameter("update_file_description");
	if ($update_file_description) {
		$id_file = (int) get_parameter("id_attachment");
		$file_description = get_parameter("file_description");
		$result = array();
		$result["status"] = false;
		$result["message"] = "";

		$result['status'] = (bool) process_sql_update('tattachment',
			array('description' => $file_description), array('id_attachment' => $id_file));

		if (!$result['status'])
			$result['message'] = __('Description not updated');

		echo json_encode($result);
		return;
	}

	$get_file_row = (bool) get_parameter("get_file_row");
	if ($get_file_row) {
		$id_file = (int) get_parameter("id_attachment");
		$file = get_incident_file($id, $id_file);

		$html = "";
		if ($file) {
Esempio n. 7
0
/** 
 * Delete a tag.
 * 
 * @param int Id of the tag.
 * @param array Values of the tag.
 * 
 * @return mixed The number of the items updated (int) of false (bool) on error.
 */
function update_tag($id, $values)
{
    if (empty($id) || !is_numeric($id)) {
        throw new InvalidArgumentException(__('ID should be numeric'));
    }
    if ($id <= 0) {
        throw new RangeException(__('ID should be a number greater than 0'));
    }
    if (isset($values[TAGS_TABLE_NAME_COL]) && empty($values[TAGS_TABLE_NAME_COL])) {
        throw new InvalidArgumentException(__('The name cannot be empty'));
    }
    if (isset($values[TAGS_TABLE_NAME_COL]) && strlen($values[TAGS_TABLE_NAME_COL]) > 255) {
        throw new InvalidArgumentException(__('The name is too big'));
    }
    $where = array(TAGS_TABLE_ID_COL => $id);
    $result = process_sql_update(TAGS_TABLE, $values, $where);
    return $result;
}
Esempio n. 8
0
	$values['invoice_expiration_date'] = $invoice_expiration_date;
	
	$values['invoice_type'] = $invoice_type;
	$values['id_language'] = $language;
	$values['internal_note'] = $internal_note;
	
	$values['bill_id_variable'] = $bill_id_variable;
	$values['bill_id_pattern'] = $bill_id_pattern;
	$values['contract_number'] = $invoice_contract_number;
	$values['tax_name'] = json_encode($tax_name_array);
	$values['discount_before'] = $discount_before;
	$values['discount_concept'] = $discount_concept;

	$where = array('id' => $id_invoice);
	
	$ret = process_sql_update ('tinvoice', $values, $where);

	if ($create_calendar_event) { 
			$now = date('Y-m-d H:i:s');
			$time = substr($now, 11, 18);
			$title = __('Reminder: Invoice ').$bill_id.__(' payment date'); 
			
			$sql_event2 ="DELETE FROM tagenda WHERE title='".$title."';";
			
			process_sql ($sql_event2);
			
			$sql_event ="INSERT INTO tagenda (public, alarm, timestamp, id_user,
				title, duration, description)
				VALUES (0, '1440', '$invoice_payment_date $time', '".$config['id_user']."', '$title',
				0, '')";
			
Esempio n. 9
0
if ($update_field) {
    //update field to incident type
    $id_field = get_parameter('id_field');
    $value_update['label'] = get_parameter('label');
    $value_update['type'] = get_parameter('type');
    $value_update['combo_value'] = get_parameter('combo_value', '');
    $error_update = false;
    if ($value_update['type'] == "combo") {
        if ($value_update['combo_value'] == '') {
            $error_update = true;
        }
    }
    if ($error_update) {
        echo ui_print_error_message(__('Field could not be updated. Empty combo value'), '', true, 'h3', true);
    } else {
        $result_update = process_sql_update('tuser_field', $value_update, array('id' => $id_field));
        if ($result_update === false) {
            echo ui_print_error_message(__('Field could not be updated'), '', true, 'h3', true);
        } else {
            echo ui_print_success_message(__('Field updated successfully'), '', true, 'h3', true);
        }
    }
}
echo "<h2>" . __("User fields") . "</h2>";
echo "<h4>" . __("List fields") . "</h4>";
$user_fields = get_db_all_rows_sql("SELECT * FROM tuser_field");
if ($user_fields === false) {
    $user_fields = array();
}
$table = new StdClass();
$table->width = '100%';
Esempio n. 10
0
/**
 * Update the password in MD5 for user pass as id_user with
 * password in plain text.
 * 
 * @param string user User ID
 * @param string password Password in plain text.
 * 
 * @return mixed False in case of error or invalid values passed. Affected rows otherwise
 */
function update_user_password($user, $password_new)
{
    return process_sql_update('tusuario', array('password' => md5($password_new)), array('id_usuario' => $user));
}
Esempio n. 11
0
		}
	}
}

// Close
if ($close) {

	if (!$write_permission && !$manage_permission) {
		audit_db ($config["id_user"], $config["REMOTE_ADDR"], "ACL Violation", "Trying to close a lead");
		require ("general/noaccess.php");
		exit;
	}

	$values = array('progress' => 100);
	$where = array('id' => $id);
	$result = process_sql_update('tlead', $values, $where);

	if ($result > 0) {
		$values = array(
				'id_lead' => $id,
				'id_user' => $config["id_user"],
				'timestamp' => date ("Y-m-d H:i:s"),
				'description' => "Lead closed"
			);
		process_sql_insert('tlead_history', $values);

		echo ui_print_success_message (__('Successfully closed'), '', true, 'h3', true);
		$id = 0;

		if ($massive_leads_update && is_ajax()) {
			$total_result['closed'] = true;
Esempio n. 12
0
function um_db_update_auth($id_auth, $client_key, $subscription_limit, $description = '', $developer = false)
{
    if (!is_numeric($subscription_limit)) {
        echo '<strong>Error</strong>: Subscription must be numeric<br />';
        return false;
    }
    $values = array('client_key' => $client_key, 'subscription_limit' => $subscription_limit, 'description' => $description, 'developer' => $developer);
    $where = array('id' => $id_auth);
    $result = process_sql_update(DB_PREFIX . 'tupdate_auth', $values, $where);
    if ($result === false) {
        echo '<strong>Error updating authorization</strong><br />';
        return false;
    }
    return true;
}
Esempio n. 13
0
 public function quickIncidentUpdate($id_incident, $type, $value)
 {
     $system = System::getInstance();
     $column = "";
     switch ($type) {
         case 'priority':
             $column = "prioridad";
             break;
         case 'owner':
             $column = "id_usuario";
             break;
         case 'resolution':
             $column = "resolution";
             break;
         case 'status':
             $column = "estado";
             break;
     }
     if ($column) {
         $res = process_sql_update('tincidencia', array($column => $value), array("id_incidencia" => $id_incident));
         if ($res && (include_once $system->getConfig('homedir') . "/include/functions_incidents.php")) {
             switch ($type) {
                 case 'priority':
                     incident_tracking($id_incident, INCIDENT_PRIORITY_CHANGED, $value);
                     break;
                 case 'owner':
                     incident_tracking($id_incident, INCIDENT_USER_CHANGED, $value);
                     break;
                 case 'resolution':
                     incident_tracking($id_incident, INCIDENT_RESOLUTION_CHANGED, $value);
                     break;
                 case 'status':
                     incident_tracking($id_incident, INCIDENT_STATUS_CHANGED, $value);
                     break;
             }
         }
     }
     return $res;
 }
Esempio n. 14
0
    update_config_token("invoice_tax_name", $config["invoice_tax_name"]);
    update_config_token("lead_warning_time", $config["lead_warning_time"]);
    update_config_token("invoice_auto_id", $config["invoice_auto_id"]);
    update_config_token("invoice_id_pattern", $config["invoice_id_pattern"]);
    //Update lead progress names
    $progress["0"] = get_parameter("progress_0");
    $progress["20"] = get_parameter("progress_20");
    $progress["40"] = get_parameter("progress_40");
    $progress["60"] = get_parameter("progress_60");
    $progress["80"] = get_parameter("progress_80");
    $progress["100"] = get_parameter("progress_100");
    $progress["101"] = get_parameter("progress_101");
    $progress["102"] = get_parameter("progress_102");
    $progress["200"] = get_parameter("progress_200");
    foreach ($progress as $key => $value) {
        process_sql_update('tlead_progress', array('name' => $value), array('id' => $key));
    }
}
$table->width = '99%';
$table->class = 'search-table-button';
$table->colspan = array();
$table->data = array();
// Gets all .png, .jpg and .gif files from "images" directory
// and returns an array with their names
function get_logo_files()
{
    $base_dir = 'images/custom_logos';
    $files = list_files($base_dir, ".png", 1, 0);
    $files = array_merge($files, list_files($base_dir, ".jpg", 1, 0));
    $files = array_merge($files, list_files($base_dir, ".gif", 1, 0));
    $retval = array();
Esempio n. 15
0
    /* Auto fill values */
    $len = count($data);
    if ($len < $nfields) {
        $data = array_pad($data, $nfields, '');
    } elseif ($len > $nfields) {
        $data = array_slice($data, NULL, $nfields);
    }
    $values = array_combine($fields, $data);
    if (empty($values['name'])) {
        continue;
    }
    /* Check parent */
    if (is_int($values['id_parent'])) {
        $id_parent = (int) get_db_value('id', 'tinventory', 'id', $values['id_parent']);
    } else {
        $id_parent = (int) get_db_value('id', 'tinventory', 'name', (string) $values['id_parent']);
    }
    $values['id_parent'] = $id_parent ? $id_parent : NULL;
    /* Check if the inventory item already exists */
    $id_inventory = (int) get_db_value_filter('id', 'tinventory', array('name' => $values['name'], 'id_parent' => $values['id_parent']));
    process_values($values, $id_inventory);
    if ($id_inventory) {
        process_sql_update('tinventory', $values, array('id' => $id_inventory));
        echo 'Updated inventory "' . $values['name'] . '"';
    } else {
        process_sql_insert('tinventory', $values);
        echo 'Inserted inventory "' . $values['name'] . '"';
    }
    echo "\n";
}
fclose($file);
Esempio n. 16
0
function run_mail_queue()
{
    global $config;
    // Get pending mails
    $filter = array('status' => 0);
    $mails = get_db_all_rows_filter('tpending_mail', $filter);
    // No pending mails
    if ($mails === false) {
        return;
    }
    // Init mailer
    $mailer = null;
    try {
        // Use local mailer if host not provided - Attach not supported !!
        if (empty($config['smtp_host'])) {
            // Empty snmp conf. System sendmail transport
            $transport = mail_get_transport();
            $mailer = mail_get_mailer($transport);
        } else {
            $mailer = mail_get_mailer();
        }
    } catch (Exception $e) {
        integria_logwrite(sprintf("Mail transport failure: %s", $e->getMessage()));
        return;
    }
    foreach ($mails as $email) {
        try {
            //Check if the email was sent at least once
            if (mail_send($email, $mailer) > 0) {
                process_sql_delete('tpending_mail', array('id' => (int) $email['id']));
            } else {
                throw new Exception(__('The mail send failed'));
            }
        } catch (Exception $e) {
            $retries = $email['attempts'] + 1;
            if ($retries > $config['smtp_queue_retries']) {
                $status = 1;
                insert_event('MAIL_FAILURE', 0, 0, $email['recipient'] . ' - ' . $e->getMessage());
            } else {
                $status = 0;
            }
            $values = array('status' => $status, 'attempts' => $retries);
            $where = array('id' => (int) $email['id']);
            process_sql_update('tpending_mail', $values, $where);
            $to = trim(ascii_output($email['recipient']));
            integria_logwrite(sprintf('SMTP error sending to %s (%s)', $to, $e->getMessage()));
        }
    }
}
Esempio n. 17
0
    $values['title'] = (string) get_parameter("title");
    $values['content'] = (string) get_parameter("content");
    $values['date'] = date('Y-m-d H:i:s', time());
    //current datetime
    $values['id_group'] = (int) get_parameter("id_group", 0);
    $values['expire'] = (int) get_parameter("expire");
    $expire_date = get_parameter("expire_date");
    $expire_date = date('Y-m-d', strtotime($expire_date));
    $expire_time = get_parameter("expire_time");
    $values['expire_timestamp'] = "{$expire_date} {$expire_time}";
    //$creator = $config['id_user'];
    if (!isset($expire)) {
        $values['expire_timestamp'] = "0000-00-00 00:00:00";
    }
    $where = "id = {$id}";
    $result = process_sql_update('tnewsboard', $values, $where);
    if (!$result) {
        echo ui_print_error_message(__('Not Updated. Nothing to updated'), '', true, 'h3', true);
    } else {
        echo ui_print_success_message(__('Successfully updated'), '', true, 'h3', true);
    }
    $operation = "";
}
// ---------------
// DELETE newsboard
// ---------------
if ($operation == "delete") {
    $id = get_parameter("id");
    $sql_delete = "DELETE FROM tnewsboard WHERE id = {$id}";
    $result = mysql_query($sql_delete);
    if (!$result) {
Esempio n. 18
0
function crm_change_invoice_lock($id_user, $id_invoice)
{
    if (crm_check_lock_permission($id_user, $id_invoice)) {
        $lock_status = crm_is_invoice_locked($id_invoice);
        if ($lock_status == 1) {
            $values = array('locked' => 0, 'locked_id_user' => NULL);
            $where = array('id' => $id_invoice);
            if (process_sql_update('tinvoice', $values, $where) > 0) {
                return 0;
            }
            return 1;
        } elseif ($lock_status == 0) {
            $values = array('locked' => 1, 'locked_id_user' => $id_user);
            $where = array('id' => $id_invoice);
            if (process_sql_update('tinvoice', $values, $where) > 0) {
                return 1;
            }
            return 0;
        }
    }
    return -1;
}
Esempio n. 19
0
function cron_validate_all_newsletter_address()
{
    global $config;
    $sql = "SELECT id,email FROM tnewsletter_address WHERE status = 0 AND validated = 0 LIMIT " . $config["batch_email_validation"];
    $newsletter_emails = get_db_all_rows_sql($sql);
    if ($newsletter_emails === false) {
        $newsletter_emails = array();
    }
    foreach ($newsletter_emails as $email) {
        $values['validated'] = 1;
        $values['status'] = 0;
        process_sql_update('tnewsletter_address', $values, array('id' => $email['id']));
    }
    return;
}
Esempio n. 20
0
		$id_ms = mysql_insert_id();
	}
	
	$operation = "";
}
// ---------------
// UPDATE milestone
// ---------------
if ($operation == "update2") {
	$name = get_parameter ("name");
	$description = get_parameter ("description");
	$timestamp = get_parameter ("timestamp");
	$id_project = get_parameter ("id_project");
	$values = array("name" => $name, "description" => $description, "timestamp" => safe_output($timestamp), "id_project" => $id_project);
	
	$result = process_sql_update("tmilestone",$values, "id = $id_milestone");
	if (! $result)
		echo ui_print_error_message (__('Error to update or nothing to update'), '', true, 'h3', true);
	else {
		echo ui_print_success_message (__('Successfully update'), '', true, 'h3', true); 
	}
	
	$operation = "";
}

// ---------------
// DELETE new todo
// ---------------
if ($operation == "delete") {
	$id_milestone = get_parameter ("id");
	$sql_delete= "DELETE FROM tmilestone WHERE id = $id_milestone";
Esempio n. 21
0
 $duration = (int) get_parameter('duration');
 $public = (int) get_parameter('public');
 $alarm = (int) get_parameter('alarm');
 $groups = get_parameter('groups', array());
 // The 0 group is the 'none' option
 if (in_array(0, $groups)) {
     $groups = array();
 }
 $values = array('public' => $public, 'alarm' => $alarm, 'timestamp' => $date . ' ' . $time, 'id_user' => $config['id_user'], 'title' => $title, 'duration' => $duration, 'description' => $description);
 $result = false;
 if (empty($id)) {
     $old_entry = array();
     $result = process_sql_insert('tagenda', $values);
 } else {
     $old_entry = get_db_row('tagenda', 'id', $id);
     $result = process_sql_update('tagenda', $values, array('id' => $id));
 }
 if ($result !== false) {
     if (empty($id)) {
         $groups = agenda_process_privacy_groups($result, $public, $groups);
     } else {
         $groups = agenda_process_privacy_groups($id, $public, $groups);
     }
     $full_path = $config['homedir'] . '/attachment/tmp/';
     $ical_text = create_ical($date . ' ' . $time, $duration, $config['id_user'], $description, "Integria imported event: {$title}");
     $full_filename = $full_path . $config['id_user'] . '-' . microtime(true) . '.ics';
     $full_filename_h = fopen($full_filename, 'a');
     fwrite($full_filename_h, $ical_text);
     fclose($full_filename_h);
     $nombre = get_db_value('nombre_real', 'tusuario', 'id_usuario', $config['id_user']);
     $email = get_db_value('direccion', 'tusuario', 'id_usuario', $config['id_user']);
Esempio n. 22
0
$end_time = $now + 24 * 3600 * 7;
//A week later
$start_date = date("Y-m-d", $now);
$end_date = date("Y-m-d", $end_time);
$description = "";
$campaing = array();
$update = get_parameter("update");
//Update campaign
if ($update) {
    $title = get_parameter("title");
    $start_date = get_parameter("start_date");
    $end_date = get_parameter("end_date");
    $description = get_parameter("description");
    $expenses = get_parameter("expenses");
    $values = array("title" => $title, "start_date" => $start_date, "end_date" => $end_date, "description" => $description, "expenses" => $expenses);
    $res = process_sql_update("tcampaign", $values, array("id" => $id));
    if ($res) {
        echo "<h3 class='suc'>" . __("Campaign updated sucessfully") . "</h3>";
    } else {
        echo "<h3 class='error'>" . __("There was a problem updating campaign") . "</h3>";
    }
}
//Get campaign information
if ($id) {
    $campaign = get_db_row("tcampaign", "id", $id);
    $title = $campaign["title"];
    $start_date = $campaign["start_date"];
    $end_date = $campaign["end_date"];
    $description = $campaign["description"];
    $expenses = $campaign["expenses"];
    //Check if campaign exists
/**
 * The update copy entirire the tgz or fail (leave some parts copies and some part not).
 * This does make any thing with the BD.
 */
function update_manager_starting_update()
{
    global $config;
    $path_package = $config['attachment_store'] . "/downloads/last_package.tgz";
    try {
        $phar = new PharData($path_package);
        rrmdir($config['attachment_store'] . "/downloads/temp_update/trunk");
        $phar->extractTo($config['attachment_store'] . "/downloads/temp_update");
    } catch (Exception $e) {
        // handle errors
        process_sql_update('tconfig', array('value' => json_encode(array('status' => 'fail', 'message' => __('Failed extracting the package to temp directory.')))), array('token' => 'progress_update_status'));
    }
    process_sql_update('tconfig', array('value' => 50), array('token' => 'progress_update'));
    $full_path = $config['attachment_store'] . "/downloads/temp_update/trunk";
    $result = update_manager_recurse_copy($full_path, $config['homedir'], array('install.php'));
    if (!$result) {
        process_sql_update('tconfig', array('value' => json_encode(array('status' => 'fail', 'message' => __('Failed the copying of the files.')))), array('token' => 'progress_update_status'));
    } else {
        process_sql_update('tconfig', array('value' => 100), array('token' => 'progress_update'));
        process_sql_update('tconfig', array('value' => json_encode(array('status' => 'end', 'message' => __('Package extracted successfully.')))), array('token' => 'progress_update_status'));
    }
}
Esempio n. 24
0
function incidents_update_incident_stats_data($incident)
{
    $start_time = strtotime($incident["inicio"]);
    // Check valid date
    if ($start_time < strtotime('1970-01-01 00:00:00')) {
        return;
    }
    $id_incident = $incident["id_incidencia"];
    $last_incident_update = $incident["last_stat_check"];
    $last_incident_update_time = strtotime($last_incident_update);
    $now = time();
    $metrics = array(INCIDENT_METRIC_USER, INCIDENT_METRIC_STATUS, INCIDENT_METRIC_GROUP);
    foreach ($metrics as $metric) {
        $state = incidents_metric_to_state($metric);
        // Get the last updated item in the last incident update
        $sql = sprintf("SELECT timestamp, id_aditional\n\t\t\t\t\t\tFROM tincident_track\n\t\t\t\t\t\tWHERE id_incident = %d\n\t\t\t\t\t\t\tAND state = %d\n\t\t\t\t\t\t\tAND timestamp < '%s'\n\t\t\t\t\t\tORDER BY timestamp DESC\n\t\t\t\t\t\tLIMIT 1", $id_incident, $state, $last_incident_update);
        $last_updated_value = process_sql($sql);
        if ($last_updated_value === false) {
            $last_updated_value = array();
        }
        // Get the changes of the metric from the incident track table
        // Get only the changes produced before the last incident update
        // in ascending order
        $sql = sprintf("SELECT timestamp, id_aditional\n\t\t\t\t\t\tFROM tincident_track\n\t\t\t\t\t\tWHERE id_incident = %d\n\t\t\t\t\t\t\tAND state = %d\n\t\t\t\t\t\t\tAND timestamp > '%s'\n\t\t\t\t\t\tORDER BY timestamp ASC", $id_incident, $state, $last_incident_update);
        $track_values = process_sql($sql);
        if ($track_values === false) {
            $track_values = array();
        }
        // If there is no changes since the last incident update,
        // the actual value is updated
        if (count($track_values) < 1 && count($last_updated_value) > 0) {
            incidents_update_stats_item($id_incident, $last_updated_value[0]["id_aditional"], $metric, $last_incident_update_time, $now);
        }
        // Go over the changes to create the stat items and set the seconds
        // passed in every state
        for ($i = 0; $i < count($track_values); $i++) {
            $min_time = strtotime($track_values[$i]["timestamp"]);
            if ($track_values[$i + 1]) {
                // There was a change after this change
                $max_time = strtotime($track_values[$i + 1]["timestamp"]);
            } else {
                // The actual value
                $max_time = $now;
            }
            // Final update to the last metric item of the last incident update
            if (!$track_values[$i - 1] && count($last_updated_value) > 0) {
                incidents_update_stats_item($id_incident, $last_updated_value[0]["id_aditional"], $metric, $last_incident_update_time, $min_time);
            }
            incidents_update_stats_item($id_incident, $track_values[$i]["id_aditional"], $metric, $min_time, $max_time);
        }
    }
    // total_time
    $filter = array("metric" => INCIDENT_METRIC_STATUS, "status" => STATUS_CLOSED, "id_incident" => $id_incident);
    $closed_time = get_db_value_filter("seconds", "tincident_stats", $filter);
    if (!$closed_time) {
        $closed_time = 0;
    }
    $start_time = strtotime($incident["inicio"]);
    $holidays_seconds = incidents_get_holidays_seconds_by_timerange($start_time, $now);
    $total_time = $now - $start_time - $closed_time - $holidays_seconds;
    $sql = sprintf("SELECT id\n\t\t\t\t\tFROM tincident_stats\n\t\t\t\t\tWHERE id_incident = %d\n\t\t\t\t\t\tAND metric = '%s'", $id_incident, INCIDENT_METRIC_TOTAL_TIME);
    $row = get_db_row_sql($sql);
    //Check if we have a previous stat metric to update or create it
    if ($row) {
        $val_upd = array("seconds" => $total_time);
        $val_where = array("id" => $row["id"]);
        process_sql_update("tincident_stats", $val_upd, $val_where);
    } else {
        $val_new = array("seconds" => $total_time, "metric" => INCIDENT_METRIC_TOTAL_TIME, "id_incident" => $id_incident);
        process_sql_insert("tincident_stats", $val_new);
    }
    // total_w_third
    $filter = array("metric" => INCIDENT_METRIC_STATUS, "status" => STATUS_PENDING_THIRD_PERSON, "id_incident" => $id_incident);
    $third_time = get_db_value_filter("seconds", "tincident_stats", $filter);
    if (!$third_time || $third_time < 0) {
        $third_time = 0;
    }
    $total_time -= $third_time;
    $sql = sprintf("SELECT id\n\t\t\t\t\tFROM tincident_stats\n\t\t\t\t\tWHERE id_incident = %d\n\t\t\t\t\t\tAND metric = '%s'", $id_incident, INCIDENT_METRIC_TOTAL_TIME_NO_THIRD);
    $row = get_db_row_sql($sql);
    //Check if we have a previous stat metric to update or create it
    if ($row) {
        $val_upd = array("seconds" => $total_time);
        $val_where = array("id" => $row["id"]);
        process_sql_update("tincident_stats", $val_upd, $val_where);
    } else {
        $val_new = array("seconds" => $total_time, "metric" => INCIDENT_METRIC_TOTAL_TIME_NO_THIRD, "id_incident" => $id_incident);
        process_sql_insert("tincident_stats", $val_new);
    }
    //Update last_incident_update field from tincidencia
    $update_values = array("last_stat_check" => date("Y-m-d H:i:s", $now));
    process_sql_update("tincidencia", $update_values, array("id_incidencia" => $id_incident));
}
Esempio n. 25
0
function api_update_incident($return_type, $user, $params)
{
    $id_incident = $params[0];
    $values['titulo'] = $params[1];
    // Check if user and title is not empty and user exists
    if (empty($values['titulo'])) {
        return;
    }
    if (!check_user_incident($user, $id_incident)) {
        return;
    }
    $timestamp = print_mysql_timestamp();
    $values['descripcion'] = $params[2];
    $values['epilog'] = $params[3];
    $values['id_grupo'] = $params[4];
    $values['prioridad'] = $params[5];
    $values['resolution'] = $params[6];
    $values['estado'] = $params[7];
    $values['id_usuario'] = $params[8];
    $id_parent = $params[9];
    if ($id_parent != 0 && $id_parent != '') {
        $values['id_parent'] = $params[9];
    }
    $values['id_incident_type'] = $params[10];
    $values['extra_data'] = $params[11];
    $values['extra_data2'] = $params[12];
    $values['actualizacion'] = $timestamp;
    if ($values['estado'] == 7) {
        $values['cierre'] = $timestamp;
    }
    $id_incident_type = $values['id_incident_type'];
    $old_incident = get_incident($id_incident);
    if (!$old_incident['old_status2']) {
        $values['old_status'] = $old_incident["old_status"];
        $values['old_resolution'] = $old_incident["old_resolution"];
        $values['old_status2'] = $values['estado'];
        $values['old_resolution2'] = $values['resolution'];
    } else {
        if ($old_incident['old_status2'] == $values['estado'] && $old_incident['old_resolution2'] == $values['resolution']) {
            $values['old_status'] = $old_incident["old_status"];
            $values['old_resolution'] = $old_incident["old_resolution"];
            $values['old_status2'] = $old_incident["old_status2"];
            $values['old_resolution2'] = $old_incident["old_resolution2"];
        } else {
            $values['old_status'] = $old_incident["old_status2"];
            $values['old_resolution'] = $old_incident["old_resolution2"];
            $values['old_status2'] = $values['estado'];
            $values['old_resolution2'] = $values['resolution'];
        }
    }
    $old_status = api_get_status_incident($id_incident);
    $values['old_status'] = $old_status;
    $old_resolution = api_get_resolution_incident($id_incident);
    $values['old_resolution'] = $old_resolution;
    $new_status = $values['estado'];
    $check_status = enterprise_hook("incidents_check_allowed_status", array($old_status, $new_status, false, true, true, $old_resolution));
    if ($check_status == ENTERPRISE_NOT_HOOK) {
        $check_status = true;
    }
    if ($values['estado'] == STATUS_CLOSED) {
        //~ $check_resolution = enterprise_hook("incidents_check_allowed_resolution", array($resolution, $values['estado'], $id_incident, true));
        $check_resolution = enterprise_hook("incidents_check_allowed_resolution", array($values['resolution'], $values['estado'], $id_incident, true));
        if ($check_resolution == ENTERPRISE_NOT_HOOK) {
            $check_resolution = true;
        }
    } else {
        $check_resolution = true;
        //~ $enterprise = enterprise_hook("incidents_check_allowed_resolution", array($resolution, $values['estado'], $id_incident, true));
        $enterprise = enterprise_hook("incidents_check_allowed_resolution", array($values['resolution'], $values['estado'], $id_incident, true));
        if ($enterprise != ENTERPRISE_NOT_HOOK) {
            $values['resolution'] = 0;
        }
    }
    if ($check_status && $check_resolution) {
        $result = process_sql_update('tincidencia', $values, array('id_incidencia' => $id_incident));
        //Add traces and statistic information
        incidents_set_tracking($id_incident, 'update', $values['prioridad'], $values['estado'], $values['resolution'], $user, $values['id_grupo']);
        //Add only update info
        incident_tracking($id_incident, INCIDENT_UPDATED);
        if ($id_incident_type != 0) {
            //in the massive operations no change id_incident_type
            $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) {
                $values_type_field['data'] = $params[$num_params];
                $id_incident_field = get_db_value_filter('id', 'tincident_type_field', array('id_incident_type' => $id_incident_type, 'label' => $label['label']), 'AND');
                $values_type_field['id_incident_field'] = $id_incident_field;
                $values_type_field['id_incident'] = $id_incident;
                $exists_id = get_db_value_filter('id', 'tincident_field_data', array('id_incident' => $id_incident, 'id_incident_field' => $id_incident_field), 'AND');
                if ($exists_id) {
                    process_sql_update('tincident_field_data', $values_type_field, array('id_incident_field' => $id_incident_field, 'id_incident' => $id_incident), 'AND');
                } else {
                    process_sql_insert('tincident_field_data', $values_type_field);
                }
                $num_params++;
            }
        }
        switch ($return_type) {
            case "xml":
                echo xml_node($result);
                break;
            case "csv":
                echo $result;
                break;
        }
    }
}
Esempio n. 26
0
                    if ($move_to == 'after') {
                        $sorted_items[] = $id_unsort;
                    }
                    foreach ($ids as $id) {
                        $sorted_items[] = $id;
                    }
                    if ($move_to != 'after') {
                        $sorted_items[] = $id_unsort;
                    }
                } else {
                    $sorted_items[] = $id_unsort;
                }
            }
            $items = $sorted_items;
            foreach ($items as $order => $id) {
                process_sql_update('tincident_type_field', array('order' => $order + 1), array('id' => $id));
            }
            $result_operation = true;
        } else {
            $resul_operation = false;
        }
    }
}
echo '<h1>' . __('Ticket types') . '</h1>';
// FORM (Update / Create)
if ($id || $new_type) {
    if ($new_type) {
        $id = 0;
        $name = "";
        $description = "";
        //$id_wizard = "";
Esempio n. 27
0
 $values = array('email_copy' => $email_copy, 'actualizacion' => $timestamp, 'id_creator' => $id_creator, 'titulo' => $titulo, 'estado' => $estado, 'id_grupo' => $grupo, 'id_usuario' => $user, 'closed_by' => $closed_by, 'notify_email' => $email_notify, 'prioridad' => $priority, 'descripcion' => $description, 'epilog' => $epilog, 'id_task' => $id_task, 'resolution' => $resolution, 'id_incident_type' => $id_incident_type, 'id_parent' => $idParentValue, 'affected_sla_id' => 0, 'sla_disabled' => $sla_disabled, 'blocked' => $blocked, 'old_status' => $old_status, 'old_resolution' => $old_resolution, 'old_status2' => $old_status2, 'old_resolution2' => $old_resolution2);
 // When close incident set close date to current date
 if ($estado == 7) {
     $values['cierre'] = $timestamp;
 }
 $result = process_sql_update('tincidencia', $values, array('id_incidencia' => $id));
 //Add traces and statistic information
 incidents_set_tracking($id, 'update', $priority, $estado, $resolution, $user, $grupo);
 audit_db($id_author_inc, $config["REMOTE_ADDR"], "Ticket updated", "User " . $config['id_user'] . " ticket updated #" . $id);
 if ($estado == 7) {
     $values_childs['estado'] = $estado;
     $values_childs['closed_by'] = $closed_by;
     $childs = incidents_get_incident_childs($id);
     if (!empty($childs)) {
         foreach ($childs as $id_child => $name) {
             $result_child = process_sql_update('tincidencia', $values_childs, array('id_incidencia' => $id_child));
             audit_db($id_author_inc, $config["REMOTE_ADDR"], "Ticket updated", "User " . $config['id_user'] . " ticket updated #" . $id_child);
         }
     }
 }
 $old_incident_inventories = array_keys(get_inventories_in_incident($id));
 $incident_inventories = get_parameter("inventories");
 /* Update inventory objects in incident */
 update_incident_inventories($id, get_parameter('inventories', $incident_inventories));
 if ($result === false) {
     $result_msg = "<h3 class='error'>" . __('There was a problem updating ticket') . "</h3>";
 } else {
     $result_msg = "<h3 class='suc'>" . __('Ticket successfully updated') . "</h3>";
 }
 // Email notify to all people involved in this incident
 if ($email_notify == 1) {
Esempio n. 28
0
	$generic_6 = (string) get_parameter ('generic_6');
	$generic_7 = (string) get_parameter ('generic_7');
	$generic_8 = (string) get_parameter ('generic8');
	$has_permission = give_acl ($config['id_user'], $id_group, "VW");
	if (! $has_permission) {
		// Doesn't have access to this page
		audit_db ($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation", "Trying to 
			update inventory extras without permission#".$id);
		include ("general/noaccess.php");
		exit;
	}
	$result = process_sql_update ('tinventory',
                array ('generic_1' => $generic_1,
                        'generic_2' => $generic_2,
                        'generic_3' => $generic_3,
                        'generic_4' => $generic_4,
                        'generic_5' => $generic_5,
                        'generic_6' => $generic_6,
                        'generic_7' => $generic_7,
                        'generic_8' => $generic_8),
                array ('id' => $id));

	if ($result !== false) {
		$result_msg = ui_print_success_message (__('Successfully updated'), '', true, 'h3', true);
	} else {
		$result_msg = ui_print_error_message (__('There was an error updating inventory object'), '', true, 'h3', true);
	}
	echo $result_msg;
	
}

echo '<div class="result">';
		$result_msg = ui_print_success_message (__("Successfully created"), '', true, 'h3', true);
		$id = $result;
	} else {
		$result_msg = ui_print_error_message (__('Could not be created'), '', true, 'h3', true);
		$id = false;
	}
}

if ($update) {
	$values['name'] = (string) get_parameter ('name');
	$values['sql'] = (string) get_parameter ('sql');
	$values['id_group'] = get_parameter('id_group');
	
	$result = false;
	if (! empty ($values['name']))
		$result = process_sql_update ('tinventory_reports', $values, array ('id' => $id));
	if ($result) {
		$result_msg = ui_print_success_message (__("Successfully updated"), '', true, 'h3', true);
	} else {
		$result_msg = ui_print_error_message (__('Could not be updated'), '', true, 'h3', true);
	}
}

if ($id) {
	clean_cache_db();

	$report = get_db_row ('tinventory_reports', 'id', $id);
	if ($report === false)
		return;
	$name = $report['name'];
	$sql = $report['sql'];
Esempio n. 30
0
    $id = get_parameter('id', '');
    $update_values["name"] = substr(get_parameter('template_name', ''), 0, -4);
    $update_values["id_group"] = get_parameter('template_group', 0);
    $update_values['template_action'] = get_parameter('template_action', '');
    $template_name = $update_values["name"];
    $sql = "SELECT id FROM temail_template where name = '" . $update_values["name"] . "' AND id_group = " . $update_values["id_group"] . " AND template_action = " . $update_values['template_action'];
    $error_update = get_db_sql($sql);
    $data = unsafe_string(str_replace("\r\n", "\n", get_parameter("template_content", "")));
    $file = "include/mailtemplates/" . $template_name . ".tpl";
    $fileh = fopen($file, "wx");
    if (fwrite($fileh, $data)) {
        $predefined_templates = get_db_value('predefined_templates', 'temail_template', 'name', $update_values["name"]);
        if ($predefined_templates == 0) {
            if (!$error_update) {
                $id = get_db_value('id', 'temail_template', 'name', $update_values["name"]);
                $result = process_sql_update('temail_template', $update_values, array('id' => $id));
            }
        } else {
            $result = 1;
        }
        if ($result != false) {
            echo ui_print_success_message(__('File successfully updated'), '', true, 'h3', true);
        } else {
            echo ui_print_error_message(__('Problem updating file'), '', true, 'h3', true);
        }
    } else {
        echo ui_print_error_message(__('Problem updating file ff'), '', true, 'h3', true);
    }
    fclose($fileh);
}
//create template