示例#1
0
 /**
  * Creates an issue with the given email information.
  *
  * @access  public
  * @param   integer $prj_id The project ID
  * @param   integer $usr_id The user responsible for this action
  * @param   string $sender The original sender of this email
  * @param   string $summary The issue summary
  * @param   string $description The issue description
  * @param   integer $category The category ID
  * @param   integer $priority The priority ID
  * @param   array $assignment The list of users to assign this issue to
  * @param   string $date The date the email was originally sent.
  * @param   string $msg_id The message ID of the email we are creating this issue from.
  * @return  void
  */
 function createFromEmail($prj_id, $usr_id, $sender, $summary, $description, $category, $priority, $assignment, $date, $msg_id)
 {
     $exclude_list = array();
     $sender_email = Mail_API::getEmailAddress($sender);
     $sender_usr_id = User::getUserIDByEmail($sender_email);
     if (!empty($sender_usr_id)) {
         $reporter = $sender_usr_id;
         $exclude_list[] = $sender_usr_id;
     } else {
         $reporter = APP_SYSTEM_USER_ID;
     }
     if (Customer::hasCustomerIntegration($prj_id)) {
         list($customer_id, $customer_contact_id) = Customer::getCustomerIDByEmails($prj_id, array($sender_email));
         if (!empty($customer_id)) {
             $contact = Customer::getContactDetails($prj_id, $customer_contact_id);
             // overwrite the reporter with the customer contact
             $reporter = User::getUserIDByContactID($customer_contact_id);
             $contact_timezone = Date_API::getPreferredTimezone($reporter);
         }
     } else {
         $customer_id = FALSE;
     }
     $initial_status = Project::getInitialStatus($prj_id);
     // add new issue
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                 (\n                    iss_prj_id,\n";
     if (!empty($category)) {
         $stmt .= "iss_prc_id,\n";
     }
     $stmt .= "iss_pri_id,\n                    iss_usr_id,";
     if (!empty($initial_status)) {
         $stmt .= "iss_sta_id,";
     }
     if (!empty($customer_id)) {
         $stmt .= "\n                    iss_customer_id,\n                    iss_customer_contact_id,\n                    iss_contact_person_lname,\n                    iss_contact_person_fname,\n                    iss_contact_email,\n                    iss_contact_phone,\n                    iss_contact_timezone,";
     }
     $stmt .= "\n                    iss_created_date,\n                    iss_last_public_action_date,\n                    iss_last_public_action_type,\n                    iss_summary,\n                    iss_description,\n                    iss_root_message_id\n                 ) VALUES (\n                    " . $prj_id . ",\n";
     if (!empty($category)) {
         $stmt .= Misc::escapeInteger($category) . ",\n";
     }
     $stmt .= Misc::escapeInteger($priority) . ",\n                    " . Misc::escapeInteger($reporter) . ",";
     if (!empty($initial_status)) {
         $stmt .= Misc::escapeInteger($initial_status) . ",";
     }
     if (!empty($customer_id)) {
         $stmt .= "\n                    " . Misc::escapeInteger($customer_id) . ",\n                    " . Misc::escapeInteger($customer_contact_id) . ",\n                    '" . Misc::escapeString($contact['last_name']) . "',\n                    '" . Misc::escapeString($contact['first_name']) . "',\n                    '" . Misc::escapeString($sender_email) . "',\n                    '" . Misc::escapeString($contact['phone']) . "',\n                    '" . Misc::escapeString($contact_timezone) . "',";
     }
     $stmt .= "\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    'created',\n                    '" . Misc::escapeString($summary) . "',\n                    '" . Misc::escapeString($description) . "',\n                    '" . Misc::escapeString($msg_id) . "'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         $new_issue_id = $GLOBALS["db_api"]->get_last_insert_id();
         $has_TAM = false;
         $has_RR = false;
         // log the creation of the issue
         History::add($new_issue_id, $usr_id, History::getTypeID('issue_opened'), 'Issue opened by ' . $sender);
         $emails = array();
         $manager_usr_ids = array();
         if (Customer::hasCustomerIntegration($prj_id) && !empty($customer_id)) {
             // if there are any technical account managers associated with this customer, add these users to the notification list
             $managers = Customer::getAccountManagers($prj_id, $customer_id);
             $manager_usr_ids = array_keys($managers);
             $manager_emails = array_values($managers);
             $emails = array_merge($emails, $manager_emails);
         }
         // add the reporter to the notification list
         $emails[] = $sender;
         $emails = array_unique($emails);
         // COMPAT: version >= 4.0.1
         $actions = Notification::getDefaultActions();
         foreach ($emails as $address) {
             Notification::subscribeEmail($reporter, $new_issue_id, $address, $actions);
         }
         // only assign the issue to an user if the associated customer has any technical account managers
         $users = array();
         if (Customer::hasCustomerIntegration($prj_id) && count($manager_usr_ids) > 0) {
             foreach ($manager_usr_ids as $manager_usr_id) {
                 $users[] = $manager_usr_id;
                 Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $manager_usr_id, false);
                 History::add($new_issue_id, $usr_id, History::getTypeID('issue_auto_assigned'), 'Issue auto-assigned to ' . User::getFullName($manager_usr_id) . ' (TAM)');
             }
             $has_TAM = true;
         }
         // now add the user/issue association
         if (@count($assignment) > 0) {
             for ($i = 0; $i < count($assignment); $i++) {
                 Notification::subscribeUser($reporter, $new_issue_id, $assignment[$i], $actions);
                 Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $assignment[$i]);
                 if ($assignment[$i] != $usr_id) {
                     $users[] = $assignment[$i];
                 }
             }
         } else {
             // only use the round-robin feature if this new issue was not
             // already assigned to a customer account manager
             if (@count($manager_usr_ids) < 1) {
                 $assignee = Round_Robin::getNextAssignee($prj_id);
                 // assign the issue to the round robin person
                 if (!empty($assignee)) {
                     Issue::addUserAssociation(APP_SYSTEM_USER_ID, $new_issue_id, $assignee, false);
                     History::add($new_issue_id, APP_SYSTEM_USER_ID, History::getTypeID('rr_issue_assigned'), 'Issue auto-assigned to ' . User::getFullName($assignee) . ' (RR)');
                     $users[] = $assignee;
                     $has_RR = true;
                 }
             }
         }
         if (count($users) > 0) {
             $has_assignee = true;
         }
         // send special 'an issue was auto-created for you' notification back to the sender
         Notification::notifyAutoCreatedIssue($prj_id, $new_issue_id, $sender, $date, $summary);
         // also notify any users that want to receive emails anytime a new issue is created
         Notification::notifyNewIssue($prj_id, $new_issue_id, $exclude_list);
         Workflow::handleNewIssue($prj_id, $new_issue_id, $has_TAM, $has_RR);
         return $new_issue_id;
     }
 }
function processResult($res, $date_field, $issue_field)
{
    global $prj_id;
    global $usr_id;
    $data = array();
    for ($i = 0; $i < count($res); $i++) {
        if (!Issue::canAccess($res[$i][$issue_field], $usr_id)) {
            continue;
        }
        if (Customer::hasCustomerIntegration($prj_id)) {
            $details = Customer::getDetails($prj_id, Issue::getCustomerID($res[$i][$issue_field]));
            $res[$i]["customer"] = @$details['customer_name'];
        }
        $res[$i]["date"] = Date_API::getFormattedDate($res[$i][$date_field], Date_API::getPreferredTimezone($usr_id));
        // need to decode From:, To: mail headers
        if (isset($res[$i]["sup_from"])) {
            $res[$i]["sup_from"] = Mime_Helper::fixEncoding($res[$i]["sup_from"]);
        }
        if (isset($res[$i]["sup_to"])) {
            $res[$i]["sup_to"] = Mime_Helper::fixEncoding($res[$i]["sup_to"]);
        }
        $data[] = $res[$i];
    }
    return $data;
}
示例#3
0
 /**
  * Method used to convert the user date (that might be in a
  * specific timezone) to a GMT date.
  *
  * @access  public
  * @param   string $date The user based date
  * @return  string The date in the GMT timezone
  */
 function getDateGMT($date)
 {
     $dt = new Date($date);
     $dt->setTZbyID(Date_API::getPreferredTimezone());
     $dt->toUTC();
     return $dt->format('%Y-%m-%d %H:%M:%S');
 }