Пример #1
0
 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;
 }