예제 #1
0
 /**
  * Send event notification to the list of users ($people)
  *
  * @param ProjectEvent $event Event
  * @param array $people
  * @return boolean
  * @throws NotifierConnectionError
  */
 static function notifEvent(ProjectEvent $object, $people, $notification, $sender)
 {
     if (!is_array($people) || !count($people) || !$sender instanceof Contact) {
         return;
         // nothing here...
     }
     // if
     $name = $object->getObjectName();
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     tpl_assign('object', $object);
     tpl_assign('title', $name);
     tpl_assign('description', escape_html_whitespace(convert_to_links(clean($object->getDescription()))));
     //descripction
     //context
     $contexts = array();
     $members = $object->getMembers();
     if (count($members) > 0) {
         foreach ($members as $member) {
             $dim = $member->getDimension();
             if ($dim->getIsManageable()) {
                 if ($dim->getCode() == "customer_project" || $dim->getCode() == "customers") {
                     $obj_type = ObjectTypes::findById($member->getObjectTypeId());
                     if ($obj_type instanceof ObjectType) {
                         $contexts[$dim->getCode()][$obj_type->getName()][] = '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                     }
                 } else {
                     $contexts[$dim->getCode()][] = '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                 }
             }
         }
     }
     tpl_assign('contexts', $contexts);
     //folders
     $attachments = array();
     try {
         $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
         if ($content) {
             $file_path = ROOT . "/tmp/logo_empresa.png";
             $handle = fopen($file_path, 'wb');
             if ($handle) {
                 fwrite($handle, $content);
                 fclose($handle);
                 $attachments['logo'] = array('cid' => gen_id() . substr($sender->getEmailAddress(), strpos($sender->getEmailAddress(), '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
             }
         }
     } catch (FileNotInRepositoryError $e) {
         unset($attachments['logo']);
     }
     tpl_assign('attachments', $attachments);
     // attachments
     //invitations
     $invitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $object->getId()));
     if (isset($invitations) && is_array($invitations)) {
         $guests = "";
         $send_link = array();
         foreach ($invitations as $inv) {
             $inv_user = Contacts::findById($inv->getContactId());
             if ($inv_user instanceof Contact) {
                 if (can_access($inv_user, $object->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                     $state_desc = lang('pending response');
                     if ($inv->getInvitationState() == 1) {
                         $state_desc = lang('yes');
                     } else {
                         if ($inv->getInvitationState() == 2) {
                             $state_desc = lang('no');
                         } else {
                             if ($inv->getInvitationState() == 3) {
                                 $state_desc = lang('maybe');
                             }
                         }
                     }
                     $guests .= '<div style="line-height: 20px; clear:both;">';
                     $guests .= '<div style="width: 35%;line-height: 20px; float: left;">' . clean($inv_user->getObjectName()) . '</div>';
                     $guests .= '<div style="line-height: 20px; float: left;">' . $state_desc . '</div></div>';
                 }
                 if ($inv->getInvitationState() == 0) {
                     $send_link[] = $inv_user->getId();
                 }
             }
         }
     }
     tpl_assign('guests', $guests);
     // invitations
     $emails = array();
     foreach ($people as $user) {
         if ($user->getId() != $sender->getId() && !$user->getDisabled()) {
             // send notification on user's locale and with user info
             $locale = $user->getLocale();
             Localization::instance()->loadSettings($locale, ROOT . '/language');
             //ALL SUBSCRIBERS
             if ($object->getSubscribers()) {
                 $subscribers = $object->getSubscribers();
                 $string_subscriber = '';
                 $total_s = count($subscribers);
                 $c = 0;
                 foreach ($subscribers as $subscriber) {
                     $c++;
                     if ($c == $total_s && $total_s > 1) {
                         $string_subscriber .= lang('and');
                     } else {
                         if ($c > 1) {
                             $string_subscriber .= ", ";
                         }
                     }
                     $string_subscriber .= $subscriber->getFirstName();
                     if ($subscriber->getSurname() != "") {
                         $string_subscriber .= " " . $subscriber->getSurname();
                     }
                 }
                 tpl_assign('subscribers', $string_subscriber);
                 // subscribers
             }
             //start
             if ($object->getStart() instanceof DateTimeValue) {
                 $date = Localization::instance()->formatDescriptiveDate($object->getStart(), $user->getTimezone());
                 $time = Localization::instance()->formatTime($object->getStart(), $user->getTimezone());
                 tpl_assign('start', $date);
                 //start
                 if ($object->getTypeId() != 2) {
                     tpl_assign('time', $time);
                     //time
                 }
             }
             if ($object->getTypeId() != 2) {
                 //duration
                 if ($object->getDuration() instanceof DateTimeValue) {
                     $durtime = $object->getDuration()->getTimestamp() - $object->getStart()->getTimestamp();
                     $durhr = $durtime / 3600 % 24;
                     //seconds per hour
                     tpl_assign('duration', $durhr . " hs");
                     //duration
                 }
             } else {
                 tpl_assign('duration', lang('all day event'));
                 //duration
             }
             $links = array();
             if (in_array($user->getId(), $send_link)) {
                 $links = array(array('img' => get_image_url("/16x16/complete.png"), 'text' => lang('accept invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 1, 'e' => $object->getId(), 'u' => $user->getId()))), array('img' => get_image_url("/16x16/del.png"), 'text' => lang('reject invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 2, 'e' => $object->getId(), 'u' => $user->getId()))));
                 $description_title = lang("new notification event invitation", $object->getObjectName(), $sender->getObjectName());
                 $subject_mail = lang("new notification event", $name, $sender->getObjectName());
             } else {
                 $description_title = lang("{$notification} notification event desc", $object->getObjectName(), $sender->getObjectName());
                 $subject_mail = lang("{$notification} notification {$type}", $name, $typename);
             }
             tpl_assign('links', $links);
             tpl_assign('description_title', $description_title);
             //description_title
             $toemail = $user->getEmailAddress();
             if (!$toemail) {
                 continue;
             }
             $emails[] = array("to" => array(self::prepareEmailAddress($toemail, $user->getObjectName())), "from" => self::prepareEmailAddress($sender->getEmailAddress(), $sender->getObjectName()), "subject" => $subject = $subject_mail, "body" => tpl_fetch(get_template_path('general', 'notifier')), "attachments" => $attachments);
         }
     }
     // foreach
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
     self::queueEmails($emails);
 }
예제 #2
0
 /**
  * Send event notification to the list of users ($people)
  *
  * @param ProjectEvent $event Event
  * @param array $people
  * @return boolean
  * @throws NotifierConnectionError
  */
 static function notifEvent(ProjectEvent $object, $people, $notification, $sender)
 {
     if (!is_array($people) || !count($people) || !$sender instanceof User) {
         return;
         // nothing here...
     }
     // if
     $uid = $object->getUniqueObjectId();
     $name = $object->getObjectName();
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     $description = lang("{$notification} notification event desc", $object->getObjectName(), $sender->getDisplayName());
     $properties = array();
     $second_properties = array();
     $second_properties['unique id'] = $uid;
     //$properties['view event'] = str_replace('&amp;', '&', $object->getViewUrl());
     tpl_assign('object', $object);
     tpl_assign('description', $description);
     tpl_assign('properties', $properties);
     $emails = array();
     foreach ($people as $user) {
         if ($user->getId() != $sender->getId()) {
             // send notification on user's locale and with user info
             $locale = $user->getLocale();
             Localization::instance()->loadSettings($locale, ROOT . '/language');
             $workspaces = $object->getUserWorkspaces($user);
             $ws = "";
             foreach ($workspaces as $w) {
                 if ($ws) {
                     $ws .= ", ";
                 }
                 $css = get_workspace_css_properties($w->getColor());
                 $ws .= "<span style=\"{$css}\">" . $w->getPath() . "</span>";
             }
             $properties['workspace'] = $ws;
             $properties['date'] = Localization::instance()->formatDescriptiveDate($object->getStart(), $user->getTimezone());
             if ($object->getTypeId() != 2) {
                 $properties['meeting_time'] = Localization::instance()->formatTime($object->getStart(), $user->getTimezone());
             }
             $properties['accept or reject invitation help, click on one of the links below'] = '';
             //	$properties['accept invitation'] = get_url('event', 'change_invitation_state', array('at' => 1, 'e' => $object->getId(), 'u' => $user->getId()));
             //	$properties['reject invitation'] = get_url('event', 'change_invitation_state', array('at' => 2, 'e' => $object->getId(), 'u' => $user->getId()));
             $links = array(array('img' => get_image_url("/16x16/complete.png"), 'text' => lang('accept invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 1, 'e' => $object->getId(), 'u' => $user->getId()))), array('img' => get_image_url("/16x16/del.png"), 'text' => lang('reject invitation'), 'url' => get_url('event', 'change_invitation_state', array('at' => 2, 'e' => $object->getId(), 'u' => $user->getId()))));
             tpl_assign('links', $links);
             tpl_assign('properties', $properties);
             tpl_assign('second_properties', $second_properties);
             $from = self::prepareEmailAddress($sender->getEmail(), $sender->getDisplayName());
             $emails[] = array("to" => array(self::prepareEmailAddress($user->getEmail(), $user->getDisplayName())), "from" => self::prepareEmailAddress($sender->getEmail(), $sender->getDisplayName()), "subject" => $subject = lang("{$notification} notification {$type}", $name, $uid, $typename, $ws), "body" => tpl_fetch(get_template_path('general', 'notifier')));
         }
     }
     // foreach
     $locale = logged_user() instanceof User ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
     self::queueEmails($emails);
 }