Exemple #1
0
 function add_interested_parties($commentID, $ip = array(), $op = array())
 {
     // We send this email to the default from address, so that a copy of the
     // original email is kept. The receiveEmail.php script will see that this
     // email is *from* the same address, and will then skip over it, when going
     // through the new emails.
     if (defined("ALLOC_DEFAULT_FROM_ADDRESS") && ALLOC_DEFAULT_FROM_ADDRESS) {
         list($from_address, $from_name) = parse_email_address(ALLOC_DEFAULT_FROM_ADDRESS);
         $emailRecipients[] = $from_address;
     }
     interestedParty::make_interested_parties("comment", $commentID, $ip);
     $emailRecipients[] = "interested";
     // Other parties that are added on-the-fly
     foreach ((array) $op as $email => $info) {
         if ($email && in_str("@", $email)) {
             unset($lt, $gt);
             // used above
             $str = $info["name"];
             $str and $str .= " ";
             $str and $lt = "<";
             $str and $gt = ">";
             $str .= $lt . str_replace(array("<", ">"), "", $email) . $gt;
             $emailRecipients[] = $str;
             // Add a new client contact
             if ($info["addContact"] && $info["clientID"]) {
                 $q = prepare("SELECT * FROM clientContact WHERE clientID = %d AND clientContactEmail = '%s'", $info["clientID"], trim($email));
                 $db = new db_alloc();
                 if (!$db->qr($q)) {
                     $cc = new clientContact();
                     $cc->set_value("clientContactName", trim($info["name"]));
                     $cc->set_value("clientContactEmail", trim($email));
                     $cc->set_value("clientID", sprintf("%d", $info["clientID"]));
                     $cc->save();
                 }
             }
             // Add the person to the interested parties list
             if ($info["addIP"] && !interestedParty::exists("comment", $commentID, trim($email))) {
                 $interestedParty = new interestedParty();
                 $interestedParty->set_value("fullName", trim($info["name"]));
                 $interestedParty->set_value("emailAddress", trim($email));
                 $interestedParty->set_value("entityID", $commentID);
                 $interestedParty->set_value("entity", "comment");
                 $interestedParty->set_value("external", $info["internal"] ? "0" : "1");
                 $interestedParty->set_value("interestedPartyActive", "1");
                 if (is_object($cc) && $cc->get_id()) {
                     $interestedParty->set_value("clientContactID", $cc->get_id());
                 }
                 $interestedParty->save();
             }
         }
     }
     return $emailRecipients;
 }
 function adjust_by_email_subject($email_receive, $e)
 {
     $current_user =& singleton("current_user");
     $entity = $e->classname;
     $entityID = $e->get_id();
     $subject = trim($email_receive->mail_headers["subject"]);
     $body = $email_receive->get_converted_encoding();
     $msg_uid = $email_receive->msg_uid;
     list($emailAddress, $fullName) = parse_email_address($email_receive->mail_headers["from"]);
     list($personID, $clientContactID, $fullName) = comment::get_person_and_client($emailAddress, $fullName, $e->get_project_id());
     // Load up the parent object that this comment refers to, be it task or timeSheet etc
     if ($entity == "comment" && $entityID) {
         $c = new comment();
         $c->set_id($entityID);
         $c->select();
         $object = $c->get_parent_object();
     } else {
         if (class_exists($entity) && $entityID) {
             $object = new $entity();
             $object->set_id($entityID);
             $object->select();
         }
     }
     // If we're doing subject line magic, then we're only going to do it with
     // subject lines that have a {Key:fdsFFeSD} in them.
     preg_match("/\\{Key:[A-Za-z0-9]{8}\\}(.*)\\s*\$/i", $subject, $m);
     $commands = explode(" ", trim($m[1]));
     foreach ((array) $commands as $command) {
         $command = strtolower($command);
         list($command, $command2) = explode(":", $command);
         // for eg: duplicate:1234
         // If "quiet" in the subject line, then the email/comment won't be re-emailed out again
         if ($command == "quiet") {
             $quiet = true;
             // To unsubscribe from this conversation
         } else {
             if ($command == "unsub" || $command == "unsubscribe") {
                 if (interestedParty::active($entity, $entityID, $emailAddress)) {
                     interestedParty::delete_interested_party($entity, $entityID, $emailAddress);
                 }
                 // To subscribe to this conversation
             } else {
                 if ($command == "sub" || $command == "subscribe") {
                     $ip = interestedParty::exists($entity, $entityID, $emailAddress);
                     if (!$ip) {
                         $data = array("entity" => $entity, "entityID" => $entityID, "fullName" => $fullName, "emailAddress" => $emailAddress, "personID" => $personID, "clientContactID" => $clientContactID);
                         interestedParty::add_interested_party($data);
                         // Else reactivate existing IP
                     } else {
                         if (!interestedParty::active($entity, $entityID, $emailAddress)) {
                             $interestedParty = new interestedParty();
                             $interestedParty->set_id($ip["interestedPartyID"]);
                             $interestedParty->select();
                             $interestedParty->set_value("interestedPartyActive", 1);
                             $interestedParty->save();
                         }
                     }
                     // If there's a number/duration then add some time to a time sheet
                 } else {
                     if (is_object($current_user) && $current_user->get_id() && preg_match("/([\\.\\d]+)/i", $command, $m)) {
                         $duration = $m[1];
                         if (is_numeric($duration)) {
                             if (is_object($object) && $object->classname == "task" && $object->get_id() && $current_user->get_id()) {
                                 $timeSheet = new timeSheet();
                                 $tsi_row = $timeSheet->add_timeSheetItem(array("taskID" => $object->get_id(), "duration" => $duration, "comment" => $body, "msg_uid" => $msg_uid, "msg_id" => $email_receive->mail_headers["message-id"], "multiplier" => 1));
                                 $timeUnit = new timeUnit();
                                 $units = $timeUnit->get_assoc_array("timeUnitID", "timeUnitLabelA");
                                 $unitLabel = $units[$tsi_row["timeSheetItemDurationUnitID"]];
                             }
                         }
                         // Otherwise assume it's a status change
                     } else {
                         if (is_object($current_user) && $current_user->get_id() && $command) {
                             if (is_object($object) && $object->get_id()) {
                                 $object->set_value("taskStatus", $command);
                                 if ($command2 && preg_match("/dup/i", $command)) {
                                     $object->set_value("duplicateTaskID", $command2);
                                 } else {
                                     if ($command2 && preg_match("/tasks/i", $command)) {
                                         $object->add_pending_tasks($command2);
                                     }
                                 }
                                 $object->save();
                             }
                         }
                     }
                 }
             }
         }
     }
     return $quiet;
 }