$description = get_parameter ("description", "");

// 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"];
Example #2
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);
}
Example #3
0
/** Clean FLASH string strips non-valid characters for flashchart
*/
function clean_flash_string($string)
{
    $string = ascii_output($string);
    $temp = str_replace("&", "", $string);
    return str_replace("\"", "", $temp);
}
Example #4
0
function run_mail_queue()
{
    global $config;
    include_once $config["homedir"] . "/include/functions.php";
    require_once $config["homedir"] . "/include/swiftmailer/swift_required.php";
    $utimestamp = date("U");
    // $current_date = date ("Y/m/d H:i:s");
    if (isset($config["batch_newsletter"])) {
        $limit = " LIMIT " . $config['batch_newsletter'];
    } else {
        $limit = "";
    }
    // get pending mails
    $mails = get_db_all_rows_sql("SELECT * FROM tpending_mail WHERE status = 0" . $limit);
    if ($mails) {
        foreach ($mails as $email) {
            // Use local mailer if host not provided - Attach not supported !!
            //Headers must be comma separated
            if (isset($email["extra_headers"])) {
                $extra_headers = explode(",", $email["extra_headers"]);
            } else {
                $extra_headers = array();
            }
            if ($config["smtp_host"] == "") {
                // Use internal mail() function
                $headers = array();
                $headers[] = "MIME-Version: 1.0";
                $headers[] = "Content-type: text/plain; charset=utf-8";
                $headers = array_merge($headers, $extra_headers);
                if ($email["from"] == "") {
                    $from = $config["mail_from"];
                } else {
                    $from = $email["from"];
                }
                $headers[] = "From: " . $from;
                $headers[] = "Subject: " . safe_output($email["subject"]);
                if ($email["cc"]) {
                    $aux_cc = implode(",", $email["cc"]);
                    $headers[] = "Cc: " . $aux_cc;
                }
                $dest_email = trim(ascii_output($email['recipient']));
                $body = safe_output($email['body']);
                $error = mail($dest_email, safe_output($email["subject"]), $body, implode("\r\n", $headers));
                if (!$error) {
                    process_sql("UPDATE tpending_mail SET status = {$status}, attempts = {$retries} WHERE id = " . $email["id"]);
                } else {
                    // no errors found
                    process_sql("DELETE FROM tpending_mail WHERE id = " . $email["id"]);
                }
            } else {
                // Use swift mailer library to connect to external SMTP
                try {
                    // If SMTP port is not configured, abort mails directly!
                    if ($config["smtp_port"] == 0) {
                        return;
                    }
                    $transport = Swift_SmtpTransport::newInstance($config["smtp_host"], $config["smtp_port"]);
                    $transport->setUsername($config["smtp_user"]);
                    $transport->setPassword($config["smtp_pass"]);
                    $mailer = Swift_Mailer::newInstance($transport);
                    $message = Swift_Message::newInstance($email["subject"]);
                    if ($email["from"] == "") {
                        $message->setFrom($config["mail_from"]);
                    } else {
                        $message->setFrom($email["from"]);
                    }
                    if ($email["cc"]) {
                        $message->setCc($email["cc"]);
                    }
                    $to = trim(ascii_output($email['recipient']));
                    $toArray = array_map('trim', explode(",", $to));
                    if ($toArray) {
                        $to = $toArray;
                    }
                    $message->setTo($to);
                    $message->setBody($email['body'], 'text/plain', 'utf-8');
                    if ($email["attachment_list"] != "") {
                        $attachments = explode(",", $email["attachment_list"]);
                        foreach ($attachments as $attachment) {
                            if (is_file($attachment)) {
                                $message->attach(Swift_Attachment::fromPath($attachment));
                            }
                        }
                    }
                    $message->setContentType("text/plain");
                    $headers = $message->getHeaders();
                    foreach ($extra_headers as $eh) {
                        $aux_header = explode(":", $eh);
                        $headers->addTextHeader($aux_header[0], $aux_header[1]);
                    }
                    //Check if the email was sent at least once
                    if ($mailer->send($message) >= 1) {
                        process_sql("DELETE FROM tpending_mail WHERE id = " . $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);
                    } else {
                        $status = 0;
                    }
                    process_sql("UPDATE tpending_mail SET status = {$status}, attempts = {$retries} WHERE id = " . $email["id"]);
                    integria_logwrite(sprintf("SMTP error sending to %s (%s)"), implode(',', $toArray), $e);
                }
            }
        }
    }
}
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");
                }
            }
        }
    }
}
Example #6
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()));
        }
    }
}
             if ($res['num_employee'] == $num_employee) {
                 $already_exists = true;
             }
         }
     }
 }
 if ($password != $password2) {
     echo "<h3 class='error'>" . __('Passwords don\'t match.') . "</h3>";
 } else {
     if ($already_exists) {
         echo "<h3 class='error'>" . __('Number employee already exists.') . "</h3>";
     } else {
         if (isset($_POST["nivel"])) {
             $nivel = get_parameter("nivel");
         }
         $direccion = trim(ascii_output(get_parameter("direccion")));
         $telefono = get_parameter("telefono");
         $comentarios = get_parameter("comentarios");
         $avatar = get_parameter("avatar");
         $avatar = substr($avatar, 0, strlen($avatar) - 4);
         if (dame_password($nombre_viejo) != $password) {
             $password = md5($password);
             $sql = "UPDATE tusuario SET disabled= {$disabled}, `lang` = '{$lang}', nombre_real ='" . safe_output($nombre_real) . "', password = '******', telefono ='" . $telefono . "', direccion ='" . $direccion . "', nivel = '{$nivel}', comentarios = '{$comentarios}', avatar = '{$avatar}', id_company = '{$id_company}', num_employee = '{$num_employee}', enable_login = {$enable_login}, location = '{$location}' WHERE id_usuario = '{$nombre_viejo}'";
         } else {
             $sql = "UPDATE tusuario SET disabled= {$disabled}, lang = '{$lang}', nombre_real ='" . $nombre_real . "', telefono ='" . $telefono . "', direccion ='" . $direccion . "', nivel = '" . $nivel . "', comentarios = '" . $comentarios . "', avatar = '{$avatar}', id_company = '{$id_company}', num_employee = '{$num_employee}', enable_login = {$enable_login}, location = '{$location}' WHERE id_usuario = '" . $nombre_viejo . "'";
         }
         $resq2 = process_sql($sql);
         // Add group / to profile
         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         if (isset($_POST["grupo"])) {
             if ($_POST["grupo"] != "") {
Example #8
0
/**
 * Sends an email.
 *
 * @param Swift_Transport $email 
 * @param Swift_Mailer $mailer Mailer (optional).
 *   If the mailer is empty, a mailer will be created using
 *   the $config values.
 *
 * @return int Number of sent messages.
 *
 * @throws Swift_TransportException if the transport can't connect
 * @throws Exception Unexpected excptions
 */
function mail_send($email, $mailer = null)
{
    global $config;
    if (empty($email)) {
        return;
    }
    if (empty($mailer)) {
        $mailer = mail_get_mailer();
    }
    // Headers must be comma separated
    $extra_headers = isset($email["extra_headers"]) ? explode(",", $email["extra_headers"]) : array();
    $message = Swift_Message::newInstance($email['subject']);
    if (empty($email['from'])) {
        $message->setFrom($config['mail_from']);
    } else {
        $message->setFrom($email['from']);
    }
    if (!empty($email['cc'])) {
        $message->setCc($email['cc']);
    }
    $to = trim(ascii_output($email['recipient']));
    $toArray = array_map('trim', explode(',', $to));
    if ($toArray) {
        $to = $toArray;
    }
    $message->setTo($to);
    if (!empty($email['image_list'])) {
        $images = explode(',', $email['image_list']);
        $body_images = '';
        foreach ($images as $image) {
            if (!file_exists($image)) {
                continue;
            }
            $data = file_get_contents($image);
            if ($data) {
                $embed_image = $message->embed(Swift_Image::fromPath($image));
                $body_images .= '<br><img src="' . $embed_image . '"/>';
            }
        }
    }
    $message->setBody('<html><body>' . $email['body'] . $body_images . '</body></html>', 'text/html');
    if (!empty($email['attachment_list'])) {
        $attachments = explode(',', $email['attachment_list']);
        foreach ($attachments as $attachment) {
            if (is_file($attachment)) {
                $message->attach(Swift_Attachment::fromPath($attachment));
            }
        }
    }
    return $mailer->send($message);
}