Ejemplo n.º 1
0
 public function notify($assignees, $update = false, $clash = false)
 {
     global $AppUI, $locale_char_set, $w2Pconfig;
     $mail_owner = $AppUI->getPref('MAILALL');
     $assignee_list = explode(',', $assignees);
     $owner_is_assigned = in_array($this->event_owner, $assignee_list);
     if ($mail_owner && !$owner_is_assigned && $this->event_owner) {
         array_push($assignee_list, $this->event_owner);
     }
     // Remove any empty elements otherwise implode has a problem
     foreach ($assignee_list as $key => $x) {
         if (!$x) {
             unset($assignee_list[$key]);
         }
     }
     if (!count($assignee_list)) {
         return;
     }
     $q = $this->_query;
     $q->addTable('users', 'u');
     $q->addTable('contacts', 'con');
     $q->addQuery('user_id, contact_first_name, contact_last_name, con.contact_id, contact_email');
     $q->addWhere('u.user_contact = con.contact_id');
     $q->addWhere('user_id in (' . implode(',', $assignee_list) . ')');
     $users = $q->loadHashList('user_id');
     $date_format = $AppUI->getPref('SHDATEFORMAT');
     $time_format = $AppUI->getPref('TIMEFORMAT');
     $fmt = $date_format . ' ' . $time_format;
     $start_date = new w2p_Utilities_Date($this->event_start_date);
     $end_date = new w2p_Utilities_Date($this->event_end_date);
     $mail = new w2p_Utilities_Mail();
     $type = $update ? $AppUI->_('Updated') : $AppUI->_('New');
     if ($clash) {
         $mail->Subject($AppUI->_('Requested Event') . ': ' . $this->event_title, $locale_char_set);
     } else {
         $mail->Subject($type . ' ' . $AppUI->_('Event') . ': ' . $this->event_title, $locale_char_set);
     }
     $body = '';
     if ($clash) {
         $emailManager = new w2p_Output_EmailManager();
         $body .= $emailManager->getCalendarConflictEmail($AppUI);
     }
     $body .= $AppUI->_('Event') . ":\t" . $this->event_title . "\n";
     if (!$clash) {
         $body .= $AppUI->_('URL') . ":\t" . w2PgetConfig('base_url') . "/index.php?m=calendar&a=view&event_id=" . $this->event_id . "\n";
     }
     $body .= $AppUI->_('Starts') . ":\t" . $start_date->format($fmt) . " GMT/UTC\n";
     $body .= $AppUI->_('Ends') . ":\t" . $end_date->format($fmt) . " GMT/UTC\n";
     // Find the project name.
     if ($this->event_project) {
         $project = new CProject();
         $project->load($this->event_project);
         $body .= $AppUI->_('Project') . ":\t" . $project->project_name . "\n";
     }
     $types = w2PgetSysVal('EventType');
     $body .= $AppUI->_('Type') . ":\t" . $AppUI->_($types[$this->event_type]) . "\n";
     $body .= $AppUI->_('Attendees') . ":\t";
     $body_attend = '';
     foreach ($users as $user) {
         $body_attend .= ($body_attend ? ', ' : '') . $user['contact_first_name'] . ' ' . $user['contact_last_name'];
     }
     $body .= $body_attend . "\n\n" . $this->event_description . "\n";
     $mail->Body($body, $locale_char_set);
     foreach ($users as $user) {
         if (!$mail_owner && $user['user_id'] == $this->event_owner) {
             continue;
         }
         $mail->To($user['contact_email'], true);
         $mail->Send();
     }
 }