/**
 * Sends an email to a group.
 *
 * If the group doesn't have an email configured, the email is only sent
 * to the default user.
 *
 * @param int Group id.
 * @param string Email subject.
 * @param string Email body.
 */
function send_group_email($id_group, $subject, $body)
{
    $group = get_db_row("tgrupo", "id_grupo", $id_group);
    $name = $group['nombre'];
    $email = $group['email'];
    /* If the group has no email, use the email of the risponsable */
    if ($email == '') {
        $email = get_user_email($group['id_user_default']);
    }
    integria_sendmail($email, $subject, $body);
}
/**
 * Sends an email to a group.
 *
 * If the group doesn't have an email configured, the email is only sent
 * to the default user.
 *
 * @param int Group id.
 * @param string Email subject.
 * @param string Email body.
 */
function send_group_email($id_group, $subject, $body)
{
    $group = get_db_row("tgrupo", "id_grupo", $id_group);
    $name = $group['nombre'];
    $emails_group = $group['email_group'];
    $emails_forced_email = $group['forced_email'];
    /* If the group has no email, use the email of the risponsable */
    $email = get_user_email($group['id_user_default']);
    integria_sendmail($email, $subject, $body, false, "", $group['email_from']);
    if ($emails_group == '') {
        $email_group = explode(',', $emails_group);
        foreach ($email_group as $k) {
            integria_sendmail($k, $subject, $body, false, "", $group['email_from']);
        }
    }
}
Beispiel #3
0
$lead = get_db_row('tlead', 'id', $id);
$user = get_db_row("tusuario", "id_usuario", $config["id_user"]);
$company_user = get_db_sql("select name FROM tcompany where id = " . $user["id_company"]);
$from = get_parameter("from", $user["direccion"]);
$to = get_parameter("to", "");
$subject = get_parameter("subject", "");
$mail = get_parameter("mail", "");
$send = (int) get_parameter("send", 0);
$cco = get_parameter("cco", "");
// Send mail
if ($send) {
    if ($subject != "" and $from != "" and $to != "") {
        echo "<h3 class='suc'>" . __('Mail queued') . "</h3>";
        integria_sendmail($to, $subject, $mail, false, "", $from, true);
        if ($cco != "") {
            integria_sendmail($cco, $subject, $mail, false, "", $from, true);
        }
        $datetime = date("Y-m-d H:i:s");
        // Update tracking
        $sql = sprintf('INSERT INTO tlead_history (id_lead, id_user, timestamp, description) VALUES (%d, "%s", "%s", "%s")', $id, $config["id_user"], $datetime, "Forwarded lead by mail to {$to}");
        process_sql($sql);
        // Update activity
        $comments = __("Forwarded lead by mail to {$to}") . "&#x0d;&#x0a;" . $mail;
        // this adds &#x0d;&#x0a;
        $sql = sprintf('INSERT INTO tlead_activity (id_lead, written_by, creation, description) VALUES (%d, "%s", "%s", "%s")', $id, $config["id_user"], $datetime, $comments);
        process_sql($sql);
    } else {
        echo "<h3 class='error'>" . __('Could not be created') . "</h3>";
    }
}
// Mark with case ID
Beispiel #4
0
    $email = get_parameter("email");
    $now = date("Y-m-d H:i:s");
    echo "<h3>" . __("Thanks for your subscription. You should receive an email to confirm you have been subscribed to this newsletter") . "</h3>";
    if ($validation1 == md5($config["dbpass"] . $validation2)) {
        // check if already subscribed
        $count = get_db_sql("SELECT COUNT(id) FROM tnewsletter_address WHERE email = '" . $email . "' AND id_newsletter = {$newsletter}");
        if ($count == 0 && check_email_address(safe_output($email))) {
            $sql = "INSERT INTO tnewsletter_address (id_newsletter, email, name, datetime, status) VALUES ({$newsletter}, '{$email}', '{$name}', '{$now}',0)";
            $result = mysql_query($sql);
            if ($result) {
                $newsletter_name = get_db_sql("SELECT name FROM tnewsletter WHERE id = {$newsletter}");
                $text .= __("Welcome to") . " " . $newsletter_name . " " . __("newsletter") . "\n\n";
                $text .= __("Please use this URL to de-subscribe yourself from this newsletter:") . "\n\n";
                $text .= $config["base_url"] . "/include/newsletter.php?operation=desubscribe&id={$newsletter}";
                $text .= "\n\n" . __("Thank you");
                integria_sendmail($email, "Newsletter subscription - {$newsletter_name}", $text);
            }
        }
    }
    return;
}
if ($operation == "desubscribe") {
    $newsletter = get_db_row("tnewsletter", "id", $id);
    // safe exit
    if (!isset($newsletter["id"])) {
        return;
    }
    $now = date("Y-m-d H:i:s");
    echo "<form method=post action='" . $config["base_url"] . "/include/newsletter.php'>";
    if (!$clean) {
        echo "<h3>";
// ACL
$task_permission = get_project_access ($config["id_user"], $id_project, $id_task, false, true);
if (!$task_permission["manage"]) {
	audit_db($config["id_user"], $config["REMOTE_ADDR"], "ACL Violation", "Trying to access to task email report  without permission");
	no_permission();
}

if ($operation == "generate_email") {
	$task_participants = get_db_all_rows_sql ("SELECT direccion, nombre_real FROM tusuario, trole_people_task WHERE tusuario.id_usuario = trole_people_task.id_user AND trole_people_task.id_task = $id_task");
	$participants ="";
	foreach ($task_participants as $participant){
		$participant["direccion"];
		$text = ascii_output ($description);
		$subject = ascii_output ($title);
		integria_sendmail ($participant["direccion"], $subject, $text);
	}
	echo ui_print_success_message (__("Operation successfully completed"), '', true, 'h3', true);
}

// Get names
if ($id_project)
	$project_name = get_db_value ('name', 'tproject', 'id', $id_project);
else
	$project_name = '';

if ($id_task)
	$task = get_db_row ('ttask', 'id', $id_task);

$task_days = $task["hours"] / $config["hours_perday"];
$task_cost = $task['estimated_cost']. $config["currency"];
function mail_workorder($id_wo, $mode, $id_note = false, $wo_info = false, $note_info = false)
{
    global $config;
    $wo = $wo_info;
    if (!$wo_info) {
        $wo = get_db_row("ttodo", "id", $id_wo);
    }
    // Only send mails when creator is different than owner
    if ($wo['assigned_user'] == $wo['created_by_user']) {
        return;
    }
    $MACROS["_sitename_"] = $config['sitename'];
    $MACROS["_wo_id_"] = $wo['id'];
    $MACROS["_wo_name_"] = $wo['name'];
    $MACROS["_wo_last_update_"] = $wo['last_update'];
    $MACROS["_wo_created_by_user_"] = $wo['created_by_user'];
    $MACROS["_wo_assigned_user_"] = $wo['assigned_user'];
    $MACROS["_wo_progress_"] = translate_wo_status($wo['progress']);
    $MACROS["_wo_priority_"] = get_priority_name($wo['priority']);
    $MACROS["_wo_description_"] = wordwrap($wo["description"], 70, "\n");
    $MACROS["_wo_url_"] = $config["base_url"] . "/index.php?sec=projects&sec2=operation/workorders/wo&operation=view&id={$id_wo}";
    $MACROS["_wo_title_"] = $wo['name'];
    $MACROS["_wo_delete_user_"] = $config["id_user"];
    //Replace note macros if needed
    if ($id_note) {
        if (!$note_info) {
            $note_info = get_db_row('ttodo_notes', 'id', $id_note);
        }
        $MACROS["_wo_note_created_by_user_"] = $note_info["written_by"];
        $MACROS["_wo_notes_url_"] = $config["base_url"] . "/index.php?sec=projects&sec2=operation/workorders/wo&operation=view&tab=notes&id={$id_wo}";
        $MACROS["_wo_note_info_"] = $note_info["description"];
        $MACROS["_wo_note_delete_user_"] = $config["id_user"];
    }
    // Send email for assigned and creator of this workorder
    $email_creator = get_user_email($wo['created_by_user']);
    $email_assigned = get_user_email($wo['assigned_user']);
    switch ($mode) {
        case 0:
            // WO update
            $text = template_process($config["homedir"] . "/include/mailtemplates/wo_update.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/wo_subject_update.tpl", $MACROS);
            break;
        case 1:
            // WO creation
            $text = template_process($config["homedir"] . "/include/mailtemplates/wo_create.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/wo_subject_create.tpl", $MACROS);
            break;
        case 3:
            // WO deleted
            $text = template_process($config["homedir"] . "/include/mailtemplates/wo_delete.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/wo_subject_delete.tpl", $MACROS);
            break;
        case 4:
            //New note
            $text = template_process($config["homedir"] . "/include/mailtemplates/wo_new_note.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/wo_subject_new_note.tpl", $MACROS);
            break;
        case 5:
            //Delete note
            $text = template_process($config["homedir"] . "/include/mailtemplates/wo_delete_note.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/wo_subject_delete_note.tpl", $MACROS);
            break;
    }
    $msg_code = "WO#{$id_wo}";
    $msg_code .= "/" . substr(md5($id_wo . $config["smtp_pass"] . $wo["assigned_user"]), 0, 5);
    $msg_code .= "/" . $wo["assigned_user"];
    integria_sendmail($email_assigned, $subject, $text, false, $msg_code);
    $msg_code = "WO#{$id_wo}";
    $msg_code .= "/" . substr(md5($id_wo . $config["smtp_pass"] . $wo["created_by_user"]), 0, 5);
    $msg_code .= "/" . $wo["created_by_user"];
    integria_sendmail($email_creator, $subject, $text, false, $msg_code);
}
Beispiel #7
0
             if (!$disabled && !empty($email)) {
                 if (!in_array($email, $carry)) {
                     $carry[] = $email;
                 }
             }
             return $carry;
         }, array());
     } else {
         array_unshift($emails, $email);
     }
     $attachments = $full_filename;
     foreach ($emails as $email) {
         if (empty($id)) {
             integria_sendmail($email, "[" . $config["sitename"] . "] " . __("New calendar event"), $mail_description, $attachments);
         } else {
             integria_sendmail($email, "[" . $config["sitename"] . "] " . __("Updated calendar event"), $mail_description, $attachments);
         }
     }
     // unlink ($full_filename);
     if (empty($id)) {
         echo "<h3 class='suc'>" . __('The event was added to calendar') . "</h3>";
     } else {
         echo "<h3 class='suc'>" . __('The event was updated') . "</h3>";
     }
     echo "<br>";
     print_button(__('OK'), 'OK', false, '', 'class="sub blank"');
 } else {
     if (empty($id)) {
         echo "<h3 class='error'>" . __('An error ocurred. Event not inserted.') . "</h3>";
     } else {
         echo "<h3 class='error'>" . __('An error ocurred. Event not updated.') . "</h3>";
Beispiel #8
0
function mail_todo($mode, $id_todo)
{
    global $config;
    $todo = get_db_row("ttodo", "id", $id_todo);
    $tcreated = $todo["created_by_user"];
    $tassigned = $todo["assigned_user"];
    // Only send mails when creator is different than owner
    if ($tassigned == $tcreated) {
        return;
    }
    $tlastupdate = $todo["last_update"];
    $tdescription = wordwrap($todo["description"], 70, "\n");
    $tprogress = translate_wo_status($todo["progress"]);
    $tpriority = get_priority_name($todo["priority"]);
    $tname = $todo["name"];
    $url = $config["base_url"] . "/index.php?sec=todo&sec2=operation/todo/todo&operation=update&id={$id_todo}";
    switch ($mode) {
        case 0:
            // Add
            $text = "TO-DO '{$tname}' has been CREATED by user {$tcreated}. You could track this todo in the following URL (need to use your credentials): {$url}\n\n";
            $subject = "[" . $config["sitename"] . "] New TO-DO from '{$tcreated}' : {$tname}";
            break;
        case 1:
            // Update
            $text = "TO-DO '{$tname}' has been UPDATED by user {$tassigned}. This TO-DO was created by user {$tcreated}. You could track this todo in the following URL (need to use your credentials): {$url}\n\n";
            $subject = "[" . $config["sitename"] . "] Updated TO-DO from '{$tcreated}' : {$tname}";
            break;
        case 2:
            // Delete
            $text = "TO-DO '{$tname}' has been DELETED by user {$tassigned}. This TO-DO was created by user {$tcreated}. You could track this todo in the following URL (need to use your credentials): {$url}\n\n";
            $subject = "[" . $config["sitename"] . "] Deleted TO-DO from '{$tcreated}' : {$tname}";
    }
    $text .= "\n\t\t---------------------------------------------------------------------\n\t\tTO-DO NAME  : {$tname}\n\t\tDATE / TIME : {$tlastupdate}\n\t\tCREATED BY  : {$tcreated}\n\t\tASSIGNED TO : {$tassigned}\n\t\tPROGRESS    : {$tprogress}\n\t\tPRIORITY    : {$tpriority}\n\t\tDESCRIPTION\n\t\t---------------------------------------------------------------------\n\t\t{$tdescription}\n\n";
    $text = ascii_output($text);
    $subject = ascii_output($subject);
    // Send an email to both
    integria_sendmail(get_user_email($tcreated), $subject, $text);
    integria_sendmail(get_user_email($tassigned), $subject, $text);
}
Beispiel #9
0
/**
 * Check an SLA inactivity value on an incident and send email (to incident owner) if needed.
 *
 * @param array Incident to check
 */
function check_sla_inactivity($incident)
{
    global $compare_timestamp;
    global $config;
    $id_sla = check_incident_sla_max_inactivity($incident['id_incidencia']);
    if (!$id_sla) {
        return false;
    }
    $sla = get_db_row("tsla", "id", $id_sla);
    /* Check if it was already notified in a specified time interval */
    $sql = sprintf('SELECT COUNT(id) FROM tevent
		WHERE type = "SLA_MAX_INACTIVITY_NOTIFY"
		AND id_item = %d
		AND timestamp > "%s"', $incident['id_incidencia'], $compare_timestamp);
    $notified = get_db_sql($sql);
    if ($notified > 0) {
        return true;
    }
    /* We need to notify via email to the owner user */
    $user = get_user($incident['id_usuario']);
    $MACROS["_sitename_"] = $config["sitename"];
    $MACROS["_username_"] = $incident['id_usuario'];
    $MACROS["_fullname_"] = dame_nombre_real($incident['id_usuario']);
    $MACROS["_group_"] = dame_nombre_grupo($incident['id_grupo']);
    $MACROS["_incident_id_"] = $incident["id_incidencia"];
    $MACROS["_incident_title_"] = $incident['titulo'];
    $MACROS["_data1_"] = give_human_time($sla['max_inactivity'] * 3600);
    $access_dir = empty($config['access_public']) ? $config["base_url"] : $config['public_url'];
    $MACROS["_access_url_"] = $access_dir . "/index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=" . $incident['id_incidencia'];
    $text = template_process($config["homedir"] . "/include/mailtemplates/incident_sla_max_inactivity_time.tpl", $MACROS);
    $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_sla_max_inactivity_time_subject.tpl", $MACROS);
    if ($sla['enforced'] == 1) {
        integria_sendmail($user['direccion'], $subject, $text);
        insert_event('SLA_MAX_INACTIVITY_NOTIFY', $incident['id_incidencia']);
    } else {
        insert_event('SLA_MAX_INACTIVITY_NOTIFY', $incident['id_incidencia']);
    }
}
function mail_incident($id_inc, $id_usuario, $nota, $timeused, $mode, $public = 1)
{
    global $config;
    include_once $config["homedir"] . '/include/functions_user.php';
    clean_cache_db();
    $row = get_db_row("tincidencia", "id_incidencia", $id_inc);
    $group_name = get_db_sql("SELECT nombre FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $email_from = get_db_sql("SELECT email_from FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $titulo = $row["titulo"];
    $description = wordwrap(ascii_output($row["descripcion"]), 70, "\n");
    $prioridad = get_priority_name($row["prioridad"]);
    $nota = wordwrap($nota, 75, "\n");
    $estado = render_status($row["estado"]);
    $resolution = render_resolution($row["resolution"]);
    $create_timestamp = $row["inicio"];
    $update_timestamp = $row["actualizacion"];
    $usuario = $row["id_usuario"];
    $creator = $row["id_creator"];
    $email_copy = $row["email_copy"];
    // Send email for owner and creator of this incident
    $email_creator = get_user_email($creator);
    $company_creator = get_user_company($creator, true);
    if (empty($company_creator)) {
        $company_creator = "";
    } else {
        $company_creator = " (" . reset($company_creator) . ")";
    }
    $email_owner = get_user_email($usuario);
    $company_owner = get_user_company($usuario, true);
    if (empty($company_owner)) {
        $company_owner = "";
    } else {
        $company_owner = " (" . reset($company_owner) . ")";
    }
    //check if user is disabled
    $owner_disabled = user_is_disabled($usuario);
    $creator_disabled = user_is_disabled($creator);
    $ticket_score = '';
    if ($row["estado"] == 7 and $row['score'] == 0) {
        $ticket_score = $config["base_url"] . "/index.php?sec=incidents&sec2=operation/incidents/incident_detail&id={$id_inc}";
        //$ticket_score =  '<a href="'.$config["base_url"].'"/index.php?sec=incidents&sec2=operation/incidents/incident_detail&id="'.$id_inc.'">'."Click hear to scoring".'</a>';
    }
    $MACROS["_sitename_"] = $config["sitename"];
    $MACROS["_fullname_"] = dame_nombre_real($usuario);
    $MACROS["_username_"] = $usuario;
    $MACROS["_incident_id_"] = $id_inc;
    $MACROS["_incident_title_"] = $titulo;
    $MACROS["_creation_timestamp_"] = $create_timestamp;
    $MACROS["_update_timestamp_"] = $update_timestamp;
    $MACROS["_group_"] = $group_name;
    $MACROS["_author_"] = dame_nombre_real($creator) . $company_creator;
    $MACROS["_owner_"] = dame_nombre_real($usuario) . $company_owner;
    $MACROS["_priority_"] = $prioridad;
    $MACROS["_status_"] = $estado;
    $MACROS["_resolution_"] = $resolution;
    $MACROS["_time_used_"] = $timeused;
    $MACROS["_incident_main_text_"] = $description;
    $access_dir = empty($config['access_public']) ? $config["base_url"] : $config['public_url'];
    $MACROS["_access_url_"] = $access_dir . "/index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id={$id_inc}";
    $MACROS["_incident_epilog_"] = $row["epilog"];
    $MACROS["_incident_closed_by_"] = $row["closed_by"];
    // Resolve code for its name
    switch ($mode) {
        case 10:
            // Add Workunit
            //$subject = "[".$config["sitename"]."] Incident #$id_inc ($titulo) has a new workunit from [$id_usuario]";
            $company_wu = get_user_company($id_usuario, true);
            if (empty($company_wu)) {
                $company_wu = "";
            } else {
                $company_wu = " (" . reset($company_wu) . ")";
            }
            $MACROS["_wu_user_"] = dame_nombre_real($id_usuario) . $company_wu;
            $MACROS["_wu_text_"] = $nota;
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update_wu.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_new_wu.tpl", $MACROS);
            break;
        case 0:
            // Incident update
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_update.tpl", $MACROS);
            break;
        case 1:
            // Incident creation
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_create.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_create.tpl", $MACROS);
            break;
        case 2:
            // New attach
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_attach.tpl", $MACROS);
            break;
        case 3:
            // Incident deleted
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_delete.tpl", $MACROS);
            break;
        case 5:
            // Incident closed
            $MACROS["_ticket_score_"] = $ticket_score;
            $text = template_process($config["homedir"] . "/include/mailtemplates/incident_close.tpl", $MACROS);
            $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_close.tpl", $MACROS);
            break;
    }
    // Create the TicketID for have a secure reference to incident hidden
    // in the message. Will be used for POP automatic processing to add workunits
    // to the incident automatically.
    $msg_code = "TicketID#{$id_inc}";
    $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row["id_usuario"]), 0, 5);
    $msg_code .= "/" . $row["id_usuario"];
    if ((!$config['email_ticket_on_creation_and_closing'] || $mode == 5 || $mode == 1) && !$owner_disabled) {
        integria_sendmail($email_owner, $subject, $text, false, $msg_code, $email_from, 0, "", "X-Integria: no_process");
    }
    // Send a copy to each address in "email_copy"
    //if ($email_copy != ""){
    if ($email_copy != "" && !$config['email_ticket_on_creation_and_closing']) {
        $emails = explode(",", $email_copy);
        foreach ($emails as $em) {
            integria_sendmail($em, $subject, $text, false, "", $email_from, 0, "", "X-Integria: no_process");
        }
    }
    // Incident owner
    if ($email_owner != $email_creator and !$config['email_ticket_on_creation_and_closing'] and !$creator_disabled) {
        $msg_code = "TicketID#{$id_inc}";
        $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row["id_creator"]), 0, 5);
        $msg_code .= "/" . $row["id_creator"];
        integria_sendmail($email_creator, $subject, $text, false, $msg_code, $email_from, "", 0, "", "X-Integria: no_process");
    }
    //if ($public == 1){
    if ($public == 1 and !$config['email_ticket_on_creation_and_closing']) {
        // Send email for all users with workunits for this incident
        $sql1 = "SELECT DISTINCT(tusuario.direccion), tusuario.id_usuario FROM tusuario, tworkunit, tworkunit_incident WHERE tworkunit_incident.id_incident = {$id_inc} AND tworkunit_incident.id_workunit = tworkunit.id AND tworkunit.id_user = tusuario.id_usuario AND tusuario.disabled=0";
        if ($result = mysql_query($sql1)) {
            while ($row = mysql_fetch_array($result)) {
                if ($row[0] != $email_owner and $row[0] != $email_creator) {
                    $msg_code = "TicketID#{$id_inc}";
                    $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row[1]), 0, 5);
                    $msg_code .= "/" . $row[1];
                    integria_sendmail($row[0], $subject, $text, false, $msg_code, $email_from, "", 0, "", "X-Integria: no_process");
                }
            }
        }
        // Send email to incident reporters associated to this incident
        if ($config['incident_reporter'] == 1) {
            $contacts = get_incident_contact_reporters($id_inc, true);
            if ($contats) {
                foreach ($contacts as $contact) {
                    $contact_email = get_db_sql("SELECT email FROM tcompany_contact WHERE fullname = '{$contact}'");
                    integria_sendmail($contact_email, $subject, $text, false, $msg_code, $email_from, "", 0, "", "X-Integria: no_process");
                }
            }
        }
    }
}
$validated = false;
echo '<h3>';
echo __('Password recovery');
echo '</h3>';
if ($recover == "" and $hash == "") {
    // This NEVER should happen. Anyway, a nice msg for hackers ;)
    echo __("Don't try to hack this form. All information is sent to the user by mail");
    audit_db($config["id_user"], $config["REMOTE_ADDR"], "HACK_ATTEMPT", "Something dirty happen in password recovery");
} elseif ($hash == "") {
    $randomhash = md5($config["sitename"] . rand(0, 100) . $recover);
    $email = get_db_sql("SELECT direccion FROM tusuario WHERE disabled = 0 AND id_usuario = '{$recover}'");
    $subject = "Password recovery for " . $config["sitename"];
    $text = "Integria has received a request for password reset from IP Address " . $_SERVER['REMOTE_ADDR'] . ". Enter this validation code for reset your password: {$randomhash}";
    if ($email != "") {
        audit_db($config["id_user"], $config["REMOTE_ADDR"], "PASSWD_RECOVERY", "User: {$recover}");
        integria_sendmail($email, $subject, $text);
        process_sql("UPDATE tusuario SET pwdhash = '{$randomhash}' WHERE id_usuario = '{$recover}'");
    }
    // Doesnt show a error message (not valid email or not valid user
    // to don't give any clues on valid users
    echo '<div class="databox_login_msg" >';
    echo __("Don't close this window, you will receive an email with instructions on how to change your password.");
    echo "<br><br>";
    echo __("Enter here the validation code you should have received by mail");
    echo '</div>';
} else {
    $check = get_db_sql("SELECT id_usuario FROM tusuario WHERE id_usuario = '{$recover}' AND pwdhash = '{$hash}'");
    if (strtolower($check) == strtolower($recover)) {
        $newpass = substr(md5($config["sitename"] . rand(0, 100) . $recover), 0, 6);
        echo '<div class="databox_login_msg_green" >';
        echo __("Your new password is");
function mail_incident($id_inc, $id_usuario, $nota, $timeused, $mode, $public = 1)
{
    global $config;
    include_once $config["homedir"] . '/include/functions_user.php';
    include_once $config["homedir"] . '/include/functions_db.php';
    include_once $config["homedir"] . '/include/functions_db.mysql.php';
    clean_cache_db();
    $row = get_db_row("tincidencia", "id_incidencia", $id_inc);
    $group_name = get_db_sql("SELECT nombre FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $email_group = get_db_sql("SELECT email_group FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $forced_email = get_db_sql("SELECT forced_email FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $user_defect_group = get_db_sql("SELECT id_user_default FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $email_from = get_db_sql("SELECT email_from FROM tgrupo WHERE id_grupo = " . $row["id_grupo"]);
    $type_ticket = get_db_sql("SELECT name FROM tincident_type WHERE id = " . $row["id_incident_type"]);
    $titulo = $row["titulo"];
    $description = $row["descripcion"];
    $prioridad = get_priority_name($row["prioridad"]);
    $estado = render_status($row["estado"]);
    $resolution = render_resolution($row["resolution"]);
    $create_timestamp = $row["inicio"];
    $update_timestamp = $row["actualizacion"];
    $usuario = $row["id_usuario"];
    $creator = $row["id_creator"];
    $email_copy = $row["email_copy"];
    // Send email for owner and creator of this incident
    $email_creator = get_user_email($creator);
    $company_creator = get_user_company($creator, true);
    if (empty($company_creator)) {
        $company_creator = "";
    } else {
        $company_creator = " (" . reset($company_creator) . ")";
    }
    $email_owner = get_user_email($usuario);
    $company_owner = get_user_company($usuario, true);
    if (empty($company_owner)) {
        $company_owner = "";
    } else {
        $company_owner = " (" . reset($company_owner) . ")";
    }
    //check if user is disabled
    $owner_disabled = user_is_disabled($usuario);
    $creator_disabled = user_is_disabled($creator);
    $ticket_score = '';
    if ($row["estado"] == 7 and $row['score'] == 0) {
        $ticket_score = $config["base_url"] . "/index.php?sec=incidents&sec2=operation/incidents/incident_detail&id={$id_inc}";
        //$ticket_score =  '<a href="'.$config["base_url"].'"/index.php?sec=incidents&sec2=operation/incidents/incident_detail&id="'.$id_inc.'">'."Click hear to scoring".'</a>';
    }
    //name for fields
    $sql_name_custom = 'select ttf.label from tincident_field_data tfd, tincident_type_field ttf 
						where tfd.id_incident_field = ttf.id and tfd.id_incident=' . $id_inc . ';';
    $name_custom = get_db_all_rows_sql($sql_name_custom);
    if ($name_custom === false) {
        $name_custom = array();
    }
    foreach ($name_custom as $p) {
        //value according to the name of the custom fields
        $sql_value_custom = "select tfd.data from tincident_field_data tfd, tincident_type_field ttf \n\t\t\t\t\t\t\t where tfd.id_incident_field = ttf.id and tfd.id_incident=" . $id_inc . " and ttf.label='" . $p['label'] . "';";
        $value_custom = get_db_sql($sql_value_custom);
        $MACROS['_' . $p['label'] . '_'] = $value_custom;
    }
    $MACROS["_sitename_"] = $config["sitename"];
    $MACROS["_fullname_"] = dame_nombre_real($usuario);
    $MACROS["_username_"] = $usuario;
    $MACROS["_incident_id_"] = $id_inc;
    $MACROS["_incident_title_"] = $titulo;
    $MACROS["_creation_timestamp_"] = $create_timestamp;
    $MACROS["_update_timestamp_"] = $update_timestamp;
    $MACROS["_group_"] = $group_name;
    $MACROS["_author_"] = dame_nombre_real($creator) . $company_creator;
    $MACROS["_owner_"] = dame_nombre_real($usuario) . $company_owner;
    $MACROS["_priority_"] = $prioridad;
    $MACROS["_status_"] = $estado;
    $MACROS["_resolution_"] = $resolution;
    $MACROS["_time_used_"] = $timeused;
    $MACROS["_incident_main_text_"] = $description;
    $access_dir = empty($config['access_public']) ? $config["base_url"] : $config['public_url'];
    $MACROS["_access_url_"] = $access_dir . "/index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id={$id_inc}";
    $MACROS["_incident_epilog_"] = $row["epilog"];
    $MACROS["_incident_closed_by_"] = $row["closed_by"];
    $MACROS["_type_tickets_"] = $type_ticket;
    // Resolve code for its name
    switch ($mode) {
        case 10:
            // Add Workunit
            //$subject = "[".$config["sitename"]."] Incident #$id_inc ($titulo) has a new workunit from [$id_usuario]";
            $company_wu = get_user_company($id_usuario, true);
            if (empty($company_wu)) {
                $company_wu = "";
            } else {
                $company_wu = " (" . reset($company_wu) . ")";
            }
            $MACROS["_wu_user_"] = dame_nombre_real($id_usuario) . $company_wu;
            $MACROS["_wu_text_"] = $nota;
            // Do not pass to safe_output. $nota is already HTML Safe in this point
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 7 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 6 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update_wu.tpl", $MACROS);
            } else {
                $text = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_new_wu.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            break;
        case 0:
            // Incident update
            $attachments = "";
            $images = "";
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 9 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 8 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text .= template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            } else {
                $text .= template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_update.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            $attached_files = get_db_all_rows_sql("SELECT * FROM tattachment WHERE id_incidencia=" . $id_inc);
            if ($attached_files === false) {
                $attached_files = array();
            }
            $i = 0;
            $j = 0;
            foreach ($attached_files as $file) {
                $file_name = $file['id_attachment'] . '_' . $file['filename'];
                $access_public = get_db_value("value", "tconfig", "token", "access_public");
                $access_protocol = get_db_value("value", "tconfig", "token", "access_protocol");
                if ($access_protocol) {
                    $protocol = "https://";
                } else {
                    $protocol = "http://";
                }
                $ext = strtolower(substr($file['filename'], -3, 3));
                if ($ext == "jpg" || $ext == "png" || $ext == "gif") {
                    $path_file = $protocol . $access_public . '/' . $config['baseurl'] . '/attachment/' . $file_name;
                    if ($j == 0) {
                        $images = $path_file;
                    } else {
                        $images .= ',' . $path_file;
                    }
                    $j++;
                } else {
                    $path_file = $config['homedir'] . "attachment/" . $file_name;
                    if ($i == 0) {
                        $attachments = $path_file;
                    } else {
                        $attachments .= ',' . $path_file;
                    }
                    $i++;
                }
            }
            break;
        case 1:
            // Incident creation
            $attachments = "";
            $images = "";
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 0 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 1 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text .= template_process($config["homedir"] . "/include/mailtemplates/incident_create.tpl", $MACROS);
            } else {
                $text .= template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_create.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            $attached_files = get_db_all_rows_sql("SELECT * FROM tattachment WHERE id_incidencia=" . $id_inc);
            if ($attached_files === false) {
                $attached_files = array();
            }
            $i = 0;
            $j = 0;
            foreach ($attached_files as $file) {
                $file_name = $file['id_attachment'] . '_' . $file['filename'];
                $access_public = get_db_value("value", "tconfig", "token", "access_public");
                $access_protocol = get_db_value("value", "tconfig", "token", "access_protocol");
                if ($access_protocol) {
                    $protocol = "https://";
                } else {
                    $protocol = "http://";
                }
                $ext = strtolower(substr($file['filename'], -3, 3));
                if ($ext == "jpg" || $ext == "png" || $ext == "gif") {
                    $path_file = $protocol . $access_public . '/' . $config['baseurl'] . '/attachment/' . $file_name;
                    if ($j == 0) {
                        $images = $path_file;
                    } else {
                        $images .= ',' . $path_file;
                    }
                    $j++;
                } else {
                    $path_file = $config['homedir'] . "attachment/" . $file_name;
                    if ($i == 0) {
                        $attachments = $path_file;
                    } else {
                        $attachments .= ',' . $path_file;
                    }
                    $i++;
                }
            }
            break;
        case 2:
            // New attach
            $attachments = "";
            $images = "";
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 9 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 4 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            } else {
                $text = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_attach.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            $attached_files = get_db_all_rows_sql("SELECT * FROM tattachment WHERE id_incidencia=" . $id_inc);
            if ($attached_files === false) {
                $attached_files = array();
            }
            $i = 0;
            $j = 0;
            foreach ($attached_files as $file) {
                $file_name = $file['id_attachment'] . '_' . $file['filename'];
                $access_public = get_db_value("value", "tconfig", "token", "access_public");
                $access_protocol = get_db_value("value", "tconfig", "token", "access_protocol");
                if ($access_protocol) {
                    $protocol = "https://";
                } else {
                    $protocol = "http://";
                }
                $ext = strtolower(substr($file['filename'], -3, 3));
                if ($ext == "jpg" || $ext == "png" || $ext == "gif") {
                    $path_file = $protocol . $access_public . '/' . $config['baseurl'] . '/attachment/' . $file_name;
                    if ($j == 0) {
                        $images = $path_file;
                    } else {
                        $images .= ',' . $path_file;
                    }
                    $j++;
                } else {
                    $path_file = $config['homedir'] . "attachment/" . $file_name;
                    if ($i == 0) {
                        $attachments = $path_file;
                    } else {
                        $attachments .= ',' . $path_file;
                    }
                    $i++;
                }
            }
            break;
        case 3:
            // Incident deleted
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 9 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 5 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text = template_process($config["homedir"] . "/include/mailtemplates/incident_update.tpl", $MACROS);
            } else {
                $text = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_delete.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            break;
        case 5:
            // Incident closed
            $MACROS["_ticket_score_"] = $ticket_score;
            $temp_group = get_db_value('id_grupo', 'tgrupo', 'nombre', $group_name);
            $sql_body = "SELECT name FROM temail_template WHERE template_action = 2 AND id_group =" . $temp_group . ";";
            $sql_subject = "SELECT name FROM temail_template WHERE template_action = 3 AND id_group =" . $temp_group . ";";
            $templa_body = get_db_sql($sql_body);
            $templa_subj = get_db_sql($sql_subject);
            if (!$templa_body) {
                $text = template_process($config["homedir"] . "/include/mailtemplates/incident_close.tpl", $MACROS);
            } else {
                $text = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_body . ".tpl", $MACROS);
            }
            if (!$templa_subj) {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/incident_subject_close.tpl", $MACROS);
            } else {
                $subject = template_process($config["homedir"] . "/include/mailtemplates/" . $templa_subj . ".tpl", $MACROS);
            }
            break;
    }
    // Create the TicketID for have a secure reference to incident hidden
    // in the message. Will be used for POP automatic processing to add workunits
    // to the incident automatically.
    if ($public != 7) {
        //owner
        $msg_code = "TicketID#{$id_inc}";
        $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row["id_usuario"]), 0, 5);
        $msg_code .= "/" . $row["id_usuario"];
        integria_sendmail($email_owner, $subject, $text, $attachments, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
        //creator
        if ($email_owner != $email_creator) {
            $msg_code = "TicketID#{$id_inc}";
            $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row["id_creator"]), 0, 5);
            $msg_code .= "/" . $row["id_creator"];
            integria_sendmail($email_creator, $subject, $text, $attachments, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
        }
        // Send emails to the people in the group added
        if ($forced_email != 0) {
            $email_default = get_user_email($user_defect_group);
            integria_sendmail($email_default, $subject, $text, $attachments, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
            if ($email_group) {
                $email_g = explode(',', $email_group);
                foreach ($email_g as $k) {
                    integria_sendmail($k, $subject, $text, $attachments, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
                }
            }
        }
    }
    if ($public == 7) {
        // Send a copy to each address in "email_copy"
        if ($email_copy != "") {
            $emails = explode(",", $email_copy);
            foreach ($emails as $em) {
                integria_sendmail($em, $subject, $text, $attachments, "", $email_from, 0, "", "X-Integria: no_process", $images);
            }
        }
    }
    if ($public == 1) {
        // Send email for all users with workunits for this incident
        $sql1 = "SELECT DISTINCT(tusuario.direccion), tusuario.id_usuario FROM tusuario, tworkunit, tworkunit_incident WHERE tworkunit_incident.id_incident = {$id_inc} AND tworkunit_incident.id_workunit = tworkunit.id AND tworkunit.id_user = tusuario.id_usuario AND tusuario.disabled=0";
        if ($result = mysql_query($sql1)) {
            while ($row = mysql_fetch_array($result)) {
                if ($row[0] != $email_owner and $row[0] != $email_creator) {
                    $msg_code = "TicketID#{$id_inc}";
                    $msg_code .= "/" . substr(md5($id_inc . $config["smtp_pass"] . $row[1]), 0, 5);
                    $msg_code .= "/" . $row[1];
                    integria_sendmail($row[0], $subject, $text, false, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
                }
            }
        }
        // Send email to incident reporters associated to this incident
        if ($config['incident_reporter'] == 1) {
            $contacts = get_incident_contact_reporters($id_inc, true);
            if ($contats) {
                foreach ($contacts as $contact) {
                    $contact_email = get_db_sql("SELECT email FROM tcompany_contact WHERE fullname = '{$contact}'");
                    integria_sendmail($contact_email, $subject, $text, false, $msg_code, $email_from, 0, "", "X-Integria: no_process", $images);
                }
            }
        }
    }
}
Beispiel #13
0
					unlink ($attachment);
				}
			}
			foreach ($bad_files as $index) {
				unset($upfiles[$index]);
			}

			$upfiles = implode( ",", $upfiles);
		} else {
			$upfiles = false;
		}

		integria_sendmail ($to, $subject_mail, html_entity_decode($mail), $upfiles, "", $from, true, $cc, "X-Integria: no_process");

		if ($cco != "")
			integria_sendmail ($cco, $subject_mail, html_entity_decode($mail), $upfiles, "", $from, true);

		// Lead update
		if ($lead["progress"] == 0 ){
			//Update lead progress is was on 0%
			$sql = sprintf ('UPDATE tlead SET modification = "%s", progress = %d WHERE id = %d',
		date('Y-m-d H:i:s'), 10, $id);
		} else {
			$sql = sprintf ('UPDATE tlead SET modification = "%s" WHERE id = %d',
		date('Y-m-d H:i:s'), $id);
		}
		process_sql ($sql);		

		// Update tracking
		$sql = sprintf ('INSERT INTO tlead_history (id_lead, id_user, timestamp, description) VALUES (%d, "%s", "%s", "%s")', $id, $config["id_user"], $datetime, "Send mail from CRM");
		process_sql ($sql);
Beispiel #14
0
             }
         } else {
             $bad_files[] = $key;
             unlink($attachment);
         }
     }
     foreach ($bad_files as $index) {
         unset($upfiles[$index]);
     }
     $upfiles = implode(",", $upfiles);
 } else {
     $upfiles = false;
 }
 integria_sendmail($to, $subject_mail, $mail, $upfiles, "", $from, true, $cc, "X-Integria: no_process");
 if ($cco != "") {
     integria_sendmail($cco, $subject_mail, $mail, $upfiles, "", $from, true);
 }
 // Lead update
 if ($lead["progress"] == 0) {
     //Update lead progress is was on 0%
     $sql = sprintf('UPDATE tlead SET modification = "%s", progress = %d WHERE id = %d', date('Y-m-d H:i:s'), 10, $id);
 } else {
     $sql = sprintf('UPDATE tlead SET modification = "%s" WHERE id = %d', date('Y-m-d H:i:s'), $id);
 }
 process_sql($sql);
 // Update tracking
 $sql = sprintf('INSERT INTO tlead_history (id_lead, id_user, timestamp, description) VALUES (%d, "%s", "%s", "%s")', $id, $config["id_user"], $datetime, "Send mail from CRM");
 process_sql($sql);
 // Update activity
 $datetime = date("Y-m-d H:i:s");
 $comments = __("Send email from CRM") . "&#x0d;&#x0a;" . __("Subject") . " : " . $subject . "&#x0d;&#x0a;" . $mail;