Exemplo n.º 1
0
 function send_emails($selected_option, $email_receive = false, $hash = "", $is_a_reply_comment = false, $files = array())
 {
     $current_user =& singleton("current_user");
     $e = $this->get_parent_object();
     $type = $e->classname . "_comments";
     $body = $this->get_value("comment");
     if (is_object($email_receive)) {
         list($from_address, $from_name) = parse_email_address($email_receive->mail_headers["from"]);
     }
     if ($is_a_reply_comment) {
         $id = $this->get_value("commentLinkID");
     } else {
         $id = $this->get_id();
     }
     $recipients = comment::get_email_recipients($selected_option, "comment", $id);
     list($to_address, $bcc, $successful_recipients) = comment::get_email_recipient_headers($recipients, $from_address);
     if ($to_address || $bcc || $successful_recipients) {
         $email = new email_send();
         if ($email_receive) {
             list($email_receive_header, $email_receive_body) = $email_receive->get_raw_header_and_body();
             $email->set_headers($email_receive_header);
             $email->set_body($email_receive_body, $email_receive->mail_text);
             // Remove any existing To/Cc header, to prevent the email getting sent to the same recipients again.
             $email->del_header("To");
             $email->del_header("Cc");
             $subject = $email->get_header("subject");
             $subject = trim(preg_replace("/{Key:[^}]*}.*\$/i", "", $subject));
         } else {
             $email->set_body($body);
             if ($files) {
                 // (if we're bouncing a complete email body the attachments are already included, else do this...)
                 foreach ((array) $files as $file) {
                     $email->add_attachment($file["fullpath"]);
                 }
             } else {
                 $email->set_content_type();
             }
         }
         $bcc && $email->add_header("Bcc", $bcc);
         // nuke bounce headers - mail won't send properly otherwise
         $email->del_header("Resent-From");
         $email->del_header("Resent-Date");
         $email->del_header("Resent-Message-ID");
         $email->del_header("Resent-To");
         $email->add_header("X-Alloc-CommentID", $this->get_id());
         if (is_object($e) && method_exists($e, "get_name")) {
             $email->add_header("X-Alloc-" . ucwords($e->classname), $e->get_name());
             $email->add_header("X-Alloc-" . ucwords($e->key_field->get_name()), $e->get_id());
         }
         // Add project header too, if possible
         if (has("project") && $e->classname != "project" && isset($e->data_fields["projectID"])) {
             $p = $e->get_foreign_object("project");
             $email->add_header("X-Alloc-Project", $p->get_value("projectName"));
             $email->add_header("X-Alloc-ProjectID", $p->get_id());
         }
         $email->set_to_address($to_address);
         $messageid = $email->set_message_id($hash);
         $subject_extra = "{Key:" . $hash . "}";
         $email->set_date();
         if (!$subject) {
             $tpl = config::get_config_item("emailSubject_" . $e->classname . "Comment");
             $tpl and $subject = commentTemplate::populate_string($tpl, $e->classname, $e->get_id());
             $e->classname != "task" and $prefix = ucwords($e->classname) . " Comment: ";
             $subject or $subject = $prefix . $e->get_id() . " " . $e->get_name(DST_VARIABLE);
         }
         $email->set_subject($subject . " " . $subject_extra);
         $email->set_message_type($type);
         // If from name is empty, then use the email address instead
         // eg: From: jon@jonny.com -> From: "jon@jonny.com via allocPSA" <*****@*****.**>
         $from_name or $from_name = $from_address;
         is_object($current_user) && !$from_name and $from_name = $current_user->get_name();
         if (defined("ALLOC_DEFAULT_FROM_ADDRESS") && ALLOC_DEFAULT_FROM_ADDRESS) {
             if (config::for_cyber()) {
                 $email->set_reply_to('"All parties via allocPSA" ' . ALLOC_DEFAULT_FROM_ADDRESS);
                 $email->set_from('"' . str_replace('"', '', $from_name) . ' via allocPSA" ' . ALLOC_DEFAULT_FROM_ADDRESS);
             } else {
                 $email->set_reply_to('"All parties" ' . ALLOC_DEFAULT_FROM_ADDRESS);
                 $email->set_from('"' . str_replace('"', '', $from_name) . '" ' . ALLOC_DEFAULT_FROM_ADDRESS);
             }
         } else {
             if (is_object($current_user) && $current_user->get_from()) {
                 $f = $current_user->get_from();
             } else {
                 $f = config::get_config_item("allocEmailAdmin");
             }
             $email->set_reply_to($f);
             $email->set_from($f);
         }
         if ($email->send(false)) {
             return array($successful_recipients, $messageid);
         }
     }
 }
Exemplo n.º 2
0
     $TPL["reminder_default_subject"] = $reminder->get_value('reminderSubject');
 } else {
     if ($parentType == "client") {
         $TPL["reminder_default_subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_reminderClient"), "client", $parentID);
         $TPL["reminder_default_content"] = config::get_config_item("allocURL") . "client/client.php?clientID=" . $parentID;
     } else {
         if ($parentType == "project") {
             $TPL["reminder_default_subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_reminderProject"), "project", $parentID);
             $TPL["reminder_default_content"] = config::get_config_item("allocURL") . "project/project.php?projectID=" . $parentID;
         } else {
             if ($parentType == "task") {
                 $TPL["reminder_default_subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_reminderTask"), "task", $parentID);
                 $TPL["reminder_default_content"] = config::get_config_item("allocURL") . "task/task.php?taskID=" . $parentID;
             } else {
                 if ($parentType == "general") {
                     $TPL["reminder_default_subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_reminderOther"), "");
                 }
             }
         }
     }
 }
 $TPL["reminder_default_content"] .= "\n" . $reminder->get_value('reminderContent');
 $TPL["parentType"] = $parentType;
 $TPL["parentID"] = $parentID;
 $TPL["reminderActive"] = $reminder->get_value("reminderActive");
 if (!is_object($reminder) || !$reminder->get_id()) {
     $TPL["reminderActive"] = true;
 }
 if ($reminder->get_value("reminderHash")) {
     $db = new db_alloc();
     $r = $db->qr("SELECT tokenAction\n                    FROM token \n               LEFT JOIN tokenAction ON token.tokenActionID = tokenAction.tokenActionID\n                   WHERE token.tokenHash = '%s'", $reminder->get_value("reminderHash"));
Exemplo n.º 3
0
     }
 }
 // If not found, append the comment to the mailbox
 if (!$found) {
     e("Appending this comment: " . $row["comment"]);
     $people_cache =& get_cached_table("person");
     $name = $people_cache[$row["commentCreatedUser"]]["name"];
     $email = add_brackets($people_cache[$row["commentCreatedUser"]]["emailAddress"]);
     $eml = array();
     $eml[] = "From: " . $name . " " . $email;
     $eml[] = "Date: " . date('D M  j G:i:s Y', strtotime($row["commentCreatedTime"]));
     $e = new $entity();
     $e->set_id($entityID);
     $e->select();
     $tpl = config::get_config_item("emailSubject_" . $entity . "Comment");
     $tpl and $subject = commentTemplate::populate_string($tpl, $entity, $entityID);
     $entity != "task" and $prefix = ucwords($entity) . " Comment: ";
     $subject or $subject = $prefix . $entityID . " " . $e->get_name(DST_VARIABLE);
     $r = $db->qr("SELECT tokenHash FROM token WHERE tokenEntity = 'comment' AND tokenEntityID = %d", $row["commentID"]);
     $subject_header = "Subject: " . $subject . " {Key:" . $r["tokenHash"] . "}";
     $eml[] = $subject_header;
     $recipients = comment::get_email_recipients(array("interested"), $entity, $entityID);
     list($to_address, $bcc, $successful_recipients) = comment::get_email_recipient_headers($recipients, $people_cache[$row["commentCreatedUser"]]["emailAddress"]);
     $eml[] = "To: " . $to_address;
     $eml[] = "";
     $eml[] = $row["comment"];
     $eml = implode("\n", $eml);
     //$eml = str_replace("\n","<br>",htmlentities($eml)); //TODO: remove
     //echo("<br><b style='font-size:70%'>".$eml."</b>");
     $mail->mail_headers["subject"] = $subject_header;
     // hack
Exemplo n.º 4
0
    function email_move_status_to_finished($direction, $info)
    {
        if ($direction == "forwards") {
            //requires INVOICE_TIMESHEETS
            if (!$this->have_perm(PERM_TIME_INVOICE_TIMESHEETS)) {
                //no permission, go away
                alloc_error("You do not have permission to change this timesheet.");
            }
            //transactions
            $q = prepare("SELECT DISTINCT transaction.transactionDate, transaction.product, transaction.status\n                      FROM transaction\n                      JOIN tf ON tf.tfID = transaction.tfID OR tf.tfID = transaction.fromTfID\n                RIGHT JOIN tfPerson ON tfPerson.personID = %d AND tfPerson.tfID = tf.tfID\n                     WHERE transaction.timeSheetID = %d\n                   ", $this->get_value('personID'), $this->get_id());
            $db = new db_alloc();
            $db->query($q);
            //the email itself
            $email = array();
            $email["type"] = "timesheet_finished";
            $email["to"] = $info["timeSheet_personID_email"];
            $email["subject"] = commentTemplate::populate_string(config::get_config_item("emailSubject_timeSheetCompleted"), "timeSheet", $this->get_id());
            $email["body"] = <<<EOD
         To: {$info["timeSheet_personID_name"]}
 Time Sheet: {$info["url"]}
For Project: {$info["projectName"]}

Your timesheet has been completed by {$info["current_user_name"]}.

EOD;
            if ($db->num_rows() > 0) {
                $email["body"] .= "Transaction summary:\n";
                $status_ops = array("pending" => "Pending", "approved" => "Approved", "rejected" => "Rejected");
                while ($db->next_record()) {
                    $email["body"] .= $db->f("transactionDate") . " for " . $db->f("product") . ": " . $status_ops[$db->f("status")] . "\n";
                }
            }
            $msg[] = $this->shootEmail($email);
            $this->set_value("status", "finished");
            return $msg;
        }
    }
Exemplo n.º 5
0
 function get_populated_template($entity, $entityID = false)
 {
     // Gets a populated template for this->commentTemplateName
     $str = $this->get_value("commentTemplateText");
     return commentTemplate::populate_string($str, $entity, $entityID);
 }
Exemplo n.º 6
0
    $person = new person();
    $person->read_db_record($db);
    $person->set_id($db->f("personID"));
    $person->load_prefs();
    if (!$person->prefs["dailyTaskEmail"]) {
        continue;
    }
    $msg = "";
    $tasks = "";
    $to = "";
    if ($announcement["heading"]) {
        $msg .= $announcement["heading"];
        $msg .= "\n" . $announcement["body"] . "\n";
        $msg .= "\n- - - - - - - - - -\n";
    }
    if ($person->get_value("emailAddress")) {
        $tasks = $person->get_tasks_for_email();
        $msg .= $tasks;
        $subject = commentTemplate::populate_string(config::get_config_item("emailSubject_dailyDigest", ""));
        $to = $person->get_value("emailAddress");
        if ($person->get_value("firstName") && $person->get_value("surname") && $to) {
            $to = $person->get_value("firstName") . " " . $person->get_value("surname") . " <" . $to . ">";
        }
        if ($tasks && $to) {
            $email = new email_send($to, $subject, $msg, "daily_digest");
            if ($email->send()) {
                echo "\n<br>Sent email to: " . $to;
            }
        }
    }
}