예제 #1
0
 private function processResult(&$data, $date_field, $issue_field)
 {
     $timezone = Date_Helper::getPreferredTimezone($this->usr_id);
     foreach ($data as &$res) {
         if (!Issue::canAccess($res[$issue_field], $this->usr_id)) {
             continue;
         }
         $res['customer'] = null;
         if ($this->crm) {
             try {
                 $customer = $this->crm->getCustomer(Issue::getCustomerID($res[$issue_field]));
                 $res['customer'] = $customer->getName();
             } catch (CRMException $e) {
             }
         }
         $res['date'] = Date_Helper::getFormattedDate($res[$date_field], $timezone);
         // need to decode From:, To: mail headers
         if (isset($res['sup_from'])) {
             $res['sup_from'] = Mime_Helper::fixEncoding($res['sup_from']);
         }
         if (isset($res['sup_to'])) {
             $res['sup_to'] = Mime_Helper::fixEncoding($res['sup_to']);
         }
     }
 }
예제 #2
0
 /**
  * Method used to add a new time entry in the system.
  *
  * @param int $iss_id issue id the time entry is associated with
  * @param int $ttc_id time tracking category id
  * @param int $time_spent time spent in minutes
  * @param array $date date structure
  * @param string $summary summary about time tracking entry
  * @return int 1 if the update worked, -1 otherwise
  */
 public static function addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary)
 {
     if ($date) {
         // format the date from the form
         $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $date['Year'], $date['Month'], $date['Day'], $date['Hour'], $date['Minute'], 0);
         // convert the date to GMT timezone
         $created_date = Date_Helper::convertDateGMT($created_date . ' ' . Date_Helper::getPreferredTimezone());
     } else {
         $created_date = Date_Helper::getCurrentDateGMT();
     }
     $usr_id = Auth::getUserID();
     $stmt = 'INSERT INTO
                 {{%time_tracking}}
              (
                 ttr_ttc_id,
                 ttr_iss_id,
                 ttr_usr_id,
                 ttr_created_date,
                 ttr_time_spent,
                 ttr_summary
              ) VALUES (
                 ?, ?, ?, ?, ?, ?
              )';
     $params = array($ttc_id, $iss_id, $usr_id, $created_date, $time_spent, $summary);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     Issue::markAsUpdated($iss_id, 'time added');
     History::add($iss_id, $usr_id, 'time_added', 'Time tracking entry submitted by {user}', array('user' => User::getFullName($usr_id)));
     return 1;
 }
예제 #3
0
 /**
  * Creates an issue with the given email information.
  *
  * @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.
  * @param   integer $severity
  * @param   string $customer_id
  * @param   string $contact_id
  * @param   string $contract_id
  * @return int
  */
 public static function createFromEmail($prj_id, $usr_id, $sender, $summary, $description, $category, $priority, $assignment, $date, $msg_id, $severity, $customer_id, $contact_id, $contract_id)
 {
     $exclude_list = array();
     $managers = array();
     $sender_email = Mail_Helper::getEmailAddress($sender);
     $sender_usr_id = User::getUserIDByEmail($sender_email, true);
     if (!empty($sender_usr_id)) {
         $reporter = $sender_usr_id;
         $exclude_list[] = $sender_usr_id;
     }
     $data = array('category' => $category, 'priority' => $priority, 'severity' => $severity, 'description' => $description, 'summary' => $summary, 'msg_id' => $msg_id, 'customer' => false, 'contact' => false, 'contract' => false, 'contact_person_lname' => '', 'contact_person_fname' => '', 'contact_email' => '', 'contact_phone' => '', 'contact_timezone' => '');
     if (CRM::hasCustomerIntegration($prj_id)) {
         $crm = CRM::getInstance($prj_id);
         try {
             if ($contact_id != false) {
                 $contact = $crm->getContact($contact_id);
             } else {
                 $contact = $crm->getContactByEmail($sender_email);
             }
             // overwrite the reporter with the customer contact
             $reporter = User::getUserIDByContactID($contact->getContactID());
             $data['contact'] = $contact->getContactID();
             $data['contact_person_lname'] = $contact['last_name'];
             $data['contact_person_fname'] = $contact['first_name'];
             $data['contact_email'] = $sender_email;
             $data['contact_phone'] = $contact['phone'];
             $data['contact_timezone'] = Date_Helper::getPreferredTimezone($reporter);
         } catch (ContactNotFoundException $e) {
         }
         try {
             if ($contract_id != false) {
                 $contract = $crm->getContract($contract_id);
                 $data['contract'] = $contract->getContractID();
             } elseif (isset($contact)) {
                 // Just use first contract / customer for now.
                 $contracts = $contact->getContracts(array('active' => true));
                 $contract = $contracts[0];
                 $data['contract'] = $contract->getContractID();
             }
         } catch (ContractNotFoundException $e) {
         }
         try {
             if ($customer_id != false) {
                 $customer = $crm->getCustomer($customer_id);
                 $data['customer'] = $customer->getCustomerID();
             } elseif (isset($contract)) {
                 $customer = $contract->getCustomer();
                 $data['customer'] = $customer->getCustomerID();
             }
         } catch (CustomerNotFoundException $e) {
         }
     } else {
     }
     if (empty($reporter)) {
         $reporter = APP_SYSTEM_USER_ID;
     }
     $data['reporter'] = $reporter;
     $issue_id = self::insertIssue($prj_id, $data);
     if ($issue_id == -1) {
         return -1;
     }
     $has_RR = false;
     // log the creation of the issue
     History::add($issue_id, $usr_id, 'issue_opened', 'Issue opened by {sender}', array('sender' => $sender));
     $emails = array();
     // if there are any technical account managers associated with this customer, add these users to the notification list
     if ($data['customer']) {
         $managers = CRM::getAccountManagers($prj_id, $data['customer']);
         foreach ($managers as $manager) {
             $emails[] = $manager['usr_email'];
         }
     }
     // add the reporter to the notification list
     $emails[] = $sender;
     $emails = array_unique($emails);
     $actions = Notification::getDefaultActions($issue_id, false, 'issue_from_email');
     foreach ($emails as $address) {
         Notification::subscribeEmail($reporter, $issue_id, $address, $actions);
     }
     // only assign the issue to an user if the associated customer has any technical account managers
     $users = array();
     $has_TAM = false;
     if (CRM::hasCustomerIntegration($prj_id) && count($managers) > 0) {
         foreach ($managers as $manager) {
             if ($manager['cam_type'] == 'intpart') {
                 continue;
             }
             $users[] = $manager['cam_usr_id'];
             self::addUserAssociation($usr_id, $issue_id, $manager['cam_usr_id'], false);
             History::add($issue_id, $usr_id, 'issue_auto_assigned', 'Issue auto-assigned to {assignee} (TAM)', array('assignee' => User::getFullName($manager['cam_usr_id'])));
         }
         $has_TAM = true;
     }
     // now add the user/issue association
     if (@count($assignment) > 0) {
         foreach ($assignment as $ass_usr_id) {
             Notification::subscribeUser($reporter, $issue_id, $ass_usr_id, $actions);
             self::addUserAssociation(APP_SYSTEM_USER_ID, $issue_id, $ass_usr_id);
             if ($ass_usr_id != $usr_id) {
                 $users[] = $ass_usr_id;
             }
         }
     } else {
         // only use the round-robin feature if this new issue was not
         // already assigned to a customer account manager
         if (count($managers) < 1) {
             $assignee = Round_Robin::getNextAssignee($prj_id);
             // assign the issue to the round robin person
             if (!empty($assignee)) {
                 self::addUserAssociation(APP_SYSTEM_USER_ID, $issue_id, $assignee, false);
                 History::add($issue_id, APP_SYSTEM_USER_ID, 'rr_issue_assigned', 'Issue auto-assigned to {assignee} (RR)', array('assignee' => User::getFullName($assignee)));
                 $users[] = $assignee;
                 $has_RR = true;
             }
         }
     }
     Workflow::handleNewIssue($prj_id, $issue_id, $has_TAM, $has_RR);
     // send special 'an issue was auto-created for you' notification back to the sender
     Notification::notifyAutoCreatedIssue($prj_id, $issue_id, $sender, $date, $summary);
     // also notify any users that want to receive emails anytime a new issue is created
     Notification::notifyNewIssue($prj_id, $issue_id, $exclude_list);
     return $issue_id;
 }
예제 #4
0
 /**
  * Method used to add a phone support entry using the user
  * interface form available in the application.
  *
  * @return  integer 1 if the insert worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     $usr_id = Auth::getUserID();
     $iss_id = (int) $_POST['issue_id'];
     $date = $_POST['date'];
     // format the date from the form
     $created_date = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $date['Year'], $date['Month'], $date['Day'], $date['Hour'], $date['Minute'], 0);
     // convert the date to GMT timezone
     $created_date = Date_Helper::convertDateGMT($created_date . ' ' . Date_Helper::getPreferredTimezone());
     $stmt = 'INSERT INTO
                 {{%phone_support}}
              (
                 phs_iss_id,
                 phs_usr_id,
                 phs_phc_id,
                 phs_created_date,
                 phs_type,
                 phs_phone_number,
                 phs_description,
                 phs_phone_type,
                 phs_call_from_lname,
                 phs_call_from_fname,
                 phs_call_to_lname,
                 phs_call_to_fname
              ) VALUES (
                 ?, ?, ?, ?, ?,
                 ?, ?, ?, ?, ?,
                 ?, ?
              )';
     $params = array($iss_id, $usr_id, $_POST['phone_category'], $created_date, $_POST['type'], $_POST['phone_number'], $_POST['description'], $_POST['phone_type'], $_POST['from_lname'], $_POST['from_fname'], $_POST['to_lname'], $_POST['to_fname']);
     try {
         DB_Helper::getInstance()->query($stmt, $params);
     } catch (DbException $e) {
         return -1;
     }
     // enter the time tracking entry about this phone support entry
     $phs_id = DB_Helper::get_last_insert_id();
     $prj_id = Auth::getCurrentProject();
     $ttc_id = Time_Tracking::getCategoryId($prj_id, 'Telephone Discussion');
     $time_spent = (int) $_POST['call_length'];
     $summary = ev_gettext('Time entry inserted from phone call.');
     Time_Tracking::addTimeEntry($iss_id, $ttc_id, $time_spent, $date, $summary);
     $stmt = 'SELECT
                 max(ttr_id)
              FROM
                 {{%time_tracking}}
              WHERE
                 ttr_iss_id = ? AND
                 ttr_usr_id = ?';
     $ttr_id = DB_Helper::getInstance()->getOne($stmt, array($iss_id, $usr_id));
     Issue::markAsUpdated($iss_id, 'phone call');
     // need to save a history entry for this
     History::add($iss_id, $usr_id, 'phone_entry_added', 'Phone Support entry submitted by {user}', array('user' => User::getFullName($usr_id)));
     // XXX: send notifications for the issue being updated (new notification type phone_support?)
     // update phone record with time tracking ID.
     if (!empty($phs_id) && !empty($ttr_id)) {
         $stmt = 'UPDATE
                     {{%phone_support}}
                  SET
                     phs_ttr_id = ?
                  WHERE
                     phs_id = ?';
         try {
             DB_Helper::getInstance()->query($stmt, array($ttr_id, $phs_id));
         } catch (DbException $e) {
             return -1;
         }
     }
     return 1;
 }