function add_comment_via_email($commands, $email_receive) { // If there's Key in the email, then add a comment with the contents of the email. $token = new token(); if ($commands["key"] && $token->set_hash($commands["key"])) { $db = new db_alloc(); $comment = $token->get_value("tokenEntity"); $commentID = $token->get_value("tokenEntityID"); list($entity, $method) = $token->execute(); if (is_object($entity) && $method == "add_comment_from_email") { $c = comment::add_comment_from_email($email_receive, $entity); if (is_object($c) && $c->get_id()) { $quiet = interestedParty::adjust_by_email_subject($email_receive, $entity); if ($commands["ip"]) { $rtn = interestedParty::add_remove_ips($commands["ip"], $entity->classname, $entity->get_id(), $entity->get_project_id()); } if (!$quiet) { comment::send_comment($c->get_id(), array("interested"), $email_receive); } } } // Bad or missing key, then error } else { if ($email_receive) { alloc_error("Bad or missing key. Unable to process email."); } } return array($status, $message); }
function mail_reminder() { // check for a reminder.reminderHash that links off to a token.tokenHash // this lets us trigger reminders on complex actions, for example create // a reminder that sends when a task status changes from pending to open // Note this->reminderTime is going to always be null for the token that // link to task->moved_from_pending_to_open(). // Whereas the task->reopen_pending_task() will have a reminderTime set. $ok = true; if ($this->get_value("reminderHash")) { $token = new token(); if ($token->set_hash($this->get_value("reminderHash"))) { list($entity, $method) = $token->execute(); if (is_object($entity) && $entity->get_id()) { if (!$entity->{$method}()) { $token->decrement_tokenUsed(); // next time, gadget $ok = false; } } } } if ($ok) { $recipients = $this->get_all_recipients(); # Reminders can be clients, tasks, projects or "general" - comment threads don't exist for general if ($this->get_value('reminderType') != 'general') { # Nowhere to put the subject? $commentID = comment::add_comment($this->get_value('reminderType'), $this->get_value('reminderLinkID'), $this->get_value('reminderContent'), $this->get_value('reminderType'), $this->get_value('reminderLinkID')); # Repackage the recipients to become IPs of the new comment $ips = array(); foreach ((array) $recipients as $id => $person) { $ip = array(); $ip['name'] = $person['name']; $ip['addIP'] = true; $ip['addContact'] = false; $ip['internal'] = true; $ips[$person['emailAddress']] = $ip; } comment::add_interested_parties($commentID, false, $ips); # email_receive false or true? false for now... maybe true is better? comment::send_comment($commentID, array("interested")); } else { foreach ((array) $recipients as $person) { if ($person['emailAddress']) { $email = sprintf("%s %s <%s>", $person['firstName'], $person['surname'], $person['emailAddress']); $subject = $this->get_value('reminderSubject'); $content = $this->get_value('reminderContent'); $e = new email_send($email, $subject, $content, "reminder"); $e->send(); } } } // Update reminder (reminderTime can be blank for task->moved_from_pending_to_open) if ($this->get_value('reminderRecuringInterval') == "No") { $this->deactivate(); } else { if ($this->get_value('reminderRecuringValue') != 0) { $interval = $this->get_value('reminderRecuringValue'); $intervalUnit = $this->get_value('reminderRecuringInterval'); $newtime = $this->get_next_reminder_time(strtotime($this->get_value('reminderTime')), $interval, $intervalUnit); $this->set_value('reminderTime', date("Y-m-d H:i:s", $newtime)); $this->set_value('reminderAdvNoticeSent', 0); $this->save(); } } } }