Ejemplo n.º 1
0
/**
 * Shortcut method for retriving single lang value
 *
 * @access public
 * @param string $neme
 * @return string
 */
function lang($name)
{
    // Get function arguments and remove first one.
    $args = func_get_args();
    if (is_array($args)) {
        array_shift($args);
    }
    return langA($name, $args);
}
Ejemplo n.º 2
0
 static function objectNotification($object, $people, $sender, $notification, $description = null, $descArgs = null, $properties = array(), $links = array())
 {
     if (!is_array($people) || !count($people)) {
         return;
     }
     if ($sender instanceof Contact) {
         $sendername = $sender->getObjectName();
         $senderemail = $sender->getEmailAddress();
         $senderid = $sender->getId();
     } else {
         $sendername = owner_company()->getObjectName();
         $senderemail = owner_company()->getEmailAddress();
         if (!is_valid_email($senderemail)) {
             $senderemail = '*****@*****.**';
         }
         $senderid = 0;
     }
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     $name = $object instanceof Comment ? $object->getRelObject()->getObjectName() : $object->getObjectName();
     $assigned_to = "";
     $assigned_by = "";
     if ($object instanceof ProjectTask) {
         if ($object->getAssignedTo() instanceof Contact) {
             $assigned_to = $object->getAssignedToName();
             if ($object->getAssignedBy() instanceof Contact) {
                 $assigned_by = $object->getAssignedBy()->getObjectName();
             }
         }
     }
     $text = "";
     //text, descripction or revision comment
     if ($object->columnExists('text') && trim($object->getColumnValue('text'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('text')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
         }
     }
     if ($object->columnExists('description') && trim($object->getColumnValue('description'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('description')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
         }
     }
     $text_comment = "";
     if ($object instanceof ProjectFile && $object->getType() == ProjectFiles::TYPE_DOCUMENT) {
         $revision = $object->getLastRevision();
         if (trim($revision->getComment())) {
             $text_comment = escape_html_whitespace("\n" . $revision->getComment());
         }
     }
     //context
     $contexts = array();
     $members = $object instanceof Comment ? $object->getRelObject()->getMembers() : $object->getMembers();
     // Do not send context when edit a user
     if (!($object instanceof Contact && $notification == 'modified' && $object->getUserType() > 0)) {
         if (count($members) > 0) {
             foreach ($members as $member) {
                 $dim = $member->getDimension();
                 if ($dim->getIsManageable()) {
                     /* @var $member Member */
                     $parent_members = $member->getAllParentMembersInHierarchy();
                     $parents_str = '';
                     foreach ($parent_members as $pm) {
                         /* @var $pm Member */
                         if (!$pm instanceof Member) {
                             continue;
                         }
                         $parents_str .= '<span style="' . get_workspace_css_properties($pm->getMemberColor()) . '">' . $pm->getName() . '</span>';
                     }
                     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()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                         }
                     } else {
                         $contexts[$dim->getCode()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>';
                     }
                 }
             }
         }
     }
     $attachments = array();
     try {
         if ($object instanceof ProjectFile && ($object->getAttachToNotification() || $object->getFileType() && $object->getFileType()->getIsImage() && config_option('show images in document notifications') && in_array($object->getTypeString(), ProjectFiles::$image_types))) {
             if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
                 $file_path = FileRepository::getBackend()->getFilePath($object->getLastRevision()->getRepositoryId());
             } else {
                 $file_path = ROOT . "/tmp/" . $object->getFilename();
                 $handle = fopen($file_path, 'wb');
                 fwrite($handle, $object->getLastRevision()->getFileContent(), $object->getLastRevision()->getFilesize());
                 fclose($handle);
             }
             $att_disposition = 'attachment';
             if (config_option('show images in document notifications') && in_array($object->getTypeString(), ProjectFiles::$image_types)) {
                 $att_disposition = 'inline';
             }
             $attachments[] = array('cid' => gen_id() . substr($senderemail, strpos($senderemail, '@')), 'path' => $file_path, 'type' => $object->getTypeString(), 'disposition' => $att_disposition, 'name' => $object->getFilename());
         }
     } catch (FileNotInRepositoryError $e) {
         // don't interrupt notifications.
     }
     if (trim($name) == "") {
         $name = lang($object->getObjectTypeName()) . " (" . lang('id') . ": " . $object->getId() . ")";
     }
     tpl_assign('object', $object);
     tpl_assign('title', $name);
     //title
     tpl_assign('by', $assigned_by);
     //by
     tpl_assign('asigned', $assigned_to);
     //assigned to
     tpl_assign('description', $text);
     //descripction
     tpl_assign('revision_comment', $text_comment);
     //revision_comment
     tpl_assign('contexts', $contexts);
     //contexts
     $emails = array();
     $grouped_people = self::buildPeopleGroups($people);
     foreach ($grouped_people as $pgroup) {
         $lang = array_var($pgroup, 'lang');
         $timezone = array_var($pgroup, 'tz');
         $group_users = array_var($pgroup, 'groups');
         // contains arrays of users, with max size = 20 each one, a single email is sent foreach user group
         foreach ($group_users as $users) {
             $to_addresses = array();
             foreach ($users as $user) {
                 if (logged_user() instanceof Contact && logged_user()->getId() == $user->getId()) {
                     $user->notify_myself = logged_user()->notify_myself;
                 }
                 if (($user->getId() != $senderid || $user->notify_myself) && ($object->canView($user) || $user->ignore_permissions_for_notifications)) {
                     $to_addresses[$user->getId()] = self::prepareEmailAddress($user->getEmailAddress(), $user->getObjectName());
                 }
             }
             // build notification
             if (count($to_addresses) > 0) {
                 if ($object instanceof Comment) {
                     $subscribers = $object->getRelObject()->getSubscribers();
                 } else {
                     $subscribers = $object->getSubscribers();
                 }
                 //ALL SUBSCRIBERS
                 if (count($subscribers) > 0) {
                     $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
                 }
                 // send notification on user's locale and with user info
                 Localization::instance()->loadSettings($lang, ROOT . '/language');
                 if ($object instanceof Comment) {
                     $object_comment = Objects::findObject($object->getRelObjectId());
                     $object_type_name = $object_comment->getObjectTypeName();
                 } else {
                     $object_type_name = '';
                 }
                 $object_type = strtolower(lang($object_type_name));
                 if ($object_type_name != "") {
                     tpl_assign('object_comment_name', lang("the " . strtolower($object_type_name) . " notification"));
                     //object_comment_name
                 }
                 if (!isset($description)) {
                     $descArgs = array(clean($name), $sendername, $object_type, $object->getCreatedByDisplayName());
                     $description = "{$notification} notification {$type} desc";
                 } else {
                     //reminders
                     $date = "";
                     //due
                     if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                         if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                     }
                     //start
                     if ($object->columnExists('start') && $object->getColumnValue('start')) {
                         if ($object->getColumnValue('start') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('start'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                     }
                     $descArgs = array(clean($name), $date != "" ? $date : $sendername, $object_type, $object->getCreatedByDisplayName(), $date);
                 }
                 tpl_assign('description_title', langA($description, $descArgs));
                 //description_title
                 tpl_assign('priority', '');
                 //priority
                 if ($object->columnExists('priority') && trim($object->getColumnValue('priority'))) {
                     if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_URGENT) {
                         $priorityColor = "#FF0000";
                         $priority = lang('urgent priority');
                     } else {
                         if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_HIGH) {
                             $priorityColor = "#FF9088";
                             $priority = lang('high priority');
                         } else {
                             if ($object->getColumnValue('priority') <= ProjectTasks::PRIORITY_LOW) {
                                 $priorityColor = "white";
                                 $priority = lang('low priority');
                             } else {
                                 $priorityColor = "#DAE3F0";
                                 $priority = lang('normal priority');
                             }
                         }
                     }
                     tpl_assign('priority', array($priority, $priorityColor));
                     //priority
                 }
                 //ESPECIAL ASSIGNED FOR EVENTS
                 tpl_assign('start', '');
                 //start
                 tpl_assign('time', '');
                 //time
                 tpl_assign('duration', '');
                 //duration
                 tpl_assign('guests', '');
                 // invitations
                 tpl_assign('start_date', '');
                 //start_date
                 tpl_assign('due_date', '');
                 //due_date
                 $event_ot = ObjectTypes::findByName('event');
                 if ($object->getObjectTypeId() == $event_ot->getId()) {
                     //start
                     if ($object->getStart() instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getStart(), $timezone);
                         $time = Localization::instance()->formatTime($object->getStart(), $timezone);
                         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
                     }
                     //invitations
                     $guests = "";
                     $send_link = array();
                     $invitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $object->getId()));
                     if (isset($invitations) && is_array($invitations)) {
                         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
                 } else {
                     //start date, due date or start
                     if ($object->columnExists('start_date') && $object->getColumnValue('start_date')) {
                         if ($object->getColumnValue('start_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('start_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                         tpl_assign('start_date', $date);
                         //start_date
                     }
                     if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                         if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                             $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $timezone);
                             $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $timezone);
                             if ($time > 0) {
                                 $date .= " " . $time;
                             }
                         }
                         tpl_assign('due_date', $date);
                         //due_date
                     }
                 }
                 $toemail = $user->getEmailAddress();
                 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($toemail, strpos($toemail, '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
                         }
                     }
                 } catch (FileNotInRepositoryError $e) {
                     unset($attachments['logo']);
                 }
                 tpl_assign('attachments', $attachments);
                 // attachments
                 $from = self::prepareEmailAddress($senderemail, $sendername);
                 if (!$toemail) {
                     continue;
                 }
                 $subject = htmlspecialchars_decode(langA("{$notification} notification {$type}", $descArgs));
                 if ($object instanceof ProjectFile && $object->getDefaultSubject() != "") {
                     $subject = $object->getDefaultSubject();
                     tpl_assign('description_title', $subject);
                 }
                 $recipients_field = config_option('notification_recipients_field', 'to');
                 $emails[] = array("{$recipients_field}" => $to_addresses, "from" => self::prepareEmailAddress($senderemail, $sendername), "subject" => $subject, "body" => tpl_fetch(get_template_path('general', 'notifier')), "attachments" => $attachments);
             }
         }
     }
     self::queueEmails($emails);
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
 }
Ejemplo n.º 3
0
 static function objectNotification($object, $people, $sender, $notification, $description = null, $descArgs = null, $properties = array(), $links = array())
 {
     if (!is_array($people) || !count($people)) {
         return;
     }
     if ($sender instanceof Contact) {
         $sendername = $sender->getObjectName();
         $senderemail = $sender->getEmailAddress();
         $senderid = $sender->getId();
     } else {
         $sendername = owner_company()->getObjectName();
         $senderemail = owner_company()->getEmailAddress();
         if (!is_valid_email($senderemail)) {
             $senderemail = '*****@*****.**';
         }
         $senderid = 0;
     }
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     $name = $object instanceof Comment ? $object->getRelObject()->getObjectName() : $object->getObjectName();
     $assigned_to = "";
     $assigned_by = "";
     if ($object instanceof ProjectTask) {
         if ($object->getAssignedTo()) {
             $assigned_to = $object->getAssignedTo()->getObjectName();
             $assigned_by = $object->getAssignedBy()->getObjectName();
         }
     }
     $text = "";
     //text, descripction or revision comment
     if ($object->columnExists('text') && trim($object->getColumnValue('text'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('text')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('text'));
         }
     }
     if ($object->columnExists('description') && trim($object->getColumnValue('description'))) {
         if ($object->getObjectTypeId() == "3" || $object->getObjectTypeId() == "5") {
             if (config_option("wysiwyg_tasks") || config_option("wysiwyg_messages")) {
                 $text = purify_html(nl2br($object->getColumnValue('description')));
             } else {
                 $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
             }
         } else {
             $text = escape_html_whitespace("\n" . $object->getColumnValue('description'));
         }
     }
     $text_comment = "";
     if ($object instanceof ProjectFile && $object->getType() == ProjectFiles::TYPE_DOCUMENT) {
         $revision = $object->getLastRevision();
         if (trim($revision->getComment())) {
             $text_comment = escape_html_whitespace("\n" . $revision->getComment());
         }
     }
     //context
     $contexts = array();
     if ($object->getMembersToDisplayPath()) {
         $members = $object->getMembersToDisplayPath();
         foreach ($members as $key => $member) {
             $dim = Dimensions::getDimensionById($key);
             if ($dim->getCode() == "customer_project") {
                 foreach ($members[$key] as $member) {
                     $obj_type = ObjectTypes::findById($member['ot']);
                     $contexts[$dim->getCode()][$obj_type->getName()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>';
                 }
             } else {
                 foreach ($members[$key] as $member) {
                     $contexts[$dim->getCode()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>';
                 }
             }
         }
     }
     $attachments = array();
     if (config_option('show images in document notifications') && $object instanceof ProjectFile && in_array($object->getTypeString(), ProjectFiles::$image_types)) {
         if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
             $file_path = FileRepository::getBackend()->getFilePath($object->getLastRevision()->getRepositoryId());
         } else {
             $file_path = ROOT . "/tmp/" . $object->getFilename();
             $handle = fopen($file_path, 'wb');
             fwrite($handle, $object->getLastRevision()->getFileContent(), $object->getLastRevision()->getFilesize());
             fclose($handle);
         }
         $attachments[] = array('cid' => gen_id() . substr($senderemail, strpos($senderemail, '@')), 'path' => $file_path, 'type' => $object->getTypeString(), 'disposition' => 'inline', 'name' => $object->getFilename());
     }
     tpl_assign('object', $object);
     tpl_assign('title', $name);
     //title
     tpl_assign('by', $assigned_by);
     //by
     tpl_assign('asigned', $assigned_to);
     //assigned to
     tpl_assign('description', $text);
     //descripction
     tpl_assign('revision_comment', $text_comment);
     //revision_comment
     tpl_assign('contexts', $contexts);
     //contexts
     $emails = array();
     foreach ($people as $user) {
         if ($user instanceof Contact && $user->getId() != $senderid && $object->canView($user)) {
             // send notification on user's locale and with user info
             $locale = $user->getLocale();
             Localization::instance()->loadSettings($locale, ROOT . '/language');
             if ($object instanceof Comment) {
                 $object_comment = Objects::findObject($object->getRelObjectId());
                 $object_type_name = $object_comment->getObjectTypeName();
             } else {
                 $object_type_name = '';
             }
             $object_type = strtolower(lang($object_type_name));
             if ($object_type_name != "") {
                 tpl_assign('object_comment_name', lang("the " . strtolower($object_type_name) . " notification"));
                 //object_comment_name
             }
             if (!isset($description)) {
                 $descArgs = array(clean($name), $sendername, $object_type, $object->getCreatedBy()->getObjectName());
                 $description = "{$notification} notification {$type} desc";
             } else {
                 //reminders
                 $date = "";
                 //due
                 if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                     if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $user->getTimezone());
                         $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $user->getTimezone());
                         if ($time > 0) {
                             $date .= " " . $time;
                         }
                     }
                 }
                 //start
                 if ($object->columnExists('start') && $object->getColumnValue('start')) {
                     if ($object->getColumnValue('start') instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start'), $user->getTimezone());
                         $time = Localization::instance()->formatTime($object->getColumnValue('start'), $user->getTimezone());
                         if ($time > 0) {
                             $date .= " " . $time;
                         }
                     }
                 }
                 $descArgs = array(clean($name), $sendername, $object_type, $object->getCreatedBy()->getObjectName(), $date);
             }
             tpl_assign('description_title', langA($description, $descArgs));
             //description_title
             tpl_assign('priority', '');
             //priority
             if ($object->columnExists('priority') && trim($object->getColumnValue('priority'))) {
                 if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_URGENT) {
                     $priorityColor = "#FF0000";
                     $priority = lang('urgent priority');
                 } else {
                     if ($object->getColumnValue('priority') >= ProjectTasks::PRIORITY_HIGH) {
                         $priorityColor = "#FF9088";
                         $priority = lang('high priority');
                     } else {
                         if ($object->getColumnValue('priority') <= ProjectTasks::PRIORITY_LOW) {
                             $priorityColor = "white";
                             $priority = lang('low priority');
                         } else {
                             $priorityColor = "#DAE3F0";
                             $priority = lang('normal priority');
                         }
                     }
                 }
                 tpl_assign('priority', array($priority, $priorityColor));
                 //priority
             }
             //ESPECIAL ASSIGNED FOR EVENTS
             tpl_assign('start', '');
             //start
             tpl_assign('time', '');
             //time
             tpl_assign('duration', '');
             //duration
             tpl_assign('guests', '');
             // invitations
             tpl_assign('start_date', '');
             //start_date
             tpl_assign('due_date', '');
             //due_date
             if ($object->getObjectTypeId() == 11) {
                 //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
                 }
                 //invitations
                 $guests = "";
                 $send_link = array();
                 $invitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $object->getId()));
                 if (isset($invitations) && is_array($invitations)) {
                     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 .= '<span style="line-height: 20px; display: block;">
                                                         <div style="width: 15%;line-height: 20px; float: left;">
                                                             ' . clean($inv_user->getObjectName()) . '
                                                         </div>            
                                                         <div style="width: 85%; line-height: 20px; float: left;">
                                                             ' . $state_desc . '
                                                         </div>
                                                     </span>';
                             }
                             if ($inv->getInvitationState() == 0) {
                                 $send_link[] = $inv_user->getId();
                             }
                         }
                     }
                 }
                 tpl_assign('guests', $guests);
                 // invitations
             } else {
                 //start date, due date or start
                 if ($object->columnExists('start_date') && $object->getColumnValue('start_date')) {
                     if ($object->getColumnValue('start_date') instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('start_date'), $user->getTimezone());
                         $time = Localization::instance()->formatTime($object->getColumnValue('start_date'), $user->getTimezone());
                         if ($time > 0) {
                             $date .= " " . $time;
                         }
                     }
                     tpl_assign('start_date', $date);
                     //start_date
                 }
                 if ($object->columnExists('due_date') && $object->getColumnValue('due_date')) {
                     if ($object->getColumnValue('due_date') instanceof DateTimeValue) {
                         $date = Localization::instance()->formatDescriptiveDate($object->getColumnValue('due_date'), $user->getTimezone());
                         $time = Localization::instance()->formatTime($object->getColumnValue('due_date'), $user->getTimezone());
                         if ($time > 0) {
                             $date .= " " . $time;
                         }
                     }
                     tpl_assign('due_date', $date);
                     //due_date
                 }
             }
             $toemail = $user->getEmailAddress();
             try {
                 $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile());
                 $file_path = ROOT . "/upload/logo_empresa.png";
                 $handle = fopen($file_path, 'wb');
                 fwrite($handle, $content);
                 fclose($handle);
                 if ($content != "") {
                     $attachments['logo'] = array('cid' => gen_id() . substr($toemail, strpos($toemail, '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png');
                 }
             } catch (FileNotInRepositoryError $e) {
                 // If no logo is set, don't interrupt notifications.
             }
             tpl_assign('attachments', $attachments);
             // attachments
             $from = self::prepareEmailAddress($senderemail, $sendername);
             if (!$toemail) {
                 continue;
             }
             $emails[] = array("to" => array(self::prepareEmailAddress($toemail, $user->getObjectName())), "from" => self::prepareEmailAddress($senderemail, $sendername), "subject" => $subject = htmlspecialchars_decode(langA("{$notification} notification {$type}", $descArgs)), "body" => tpl_fetch(get_template_path('general', 'notifier')), "attachments" => $attachments);
         }
     }
     $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION;
     Localization::instance()->loadSettings($locale, ROOT . '/language');
     self::queueEmails($emails);
 }
Ejemplo n.º 4
0
 static function objectNotification($object, $people, $sender, $notification, $description = null, $descArgs = null, $properties = array(), $links = array())
 {
     if (!is_array($people) || !count($people)) {
         return;
         // nothing here...
     }
     // if
     if ($sender instanceof User) {
         $sendername = $sender->getDisplayName();
         $senderemail = $sender->getEmail();
         $senderid = $sender->getId();
     } else {
         $sendername = owner_company()->getName();
         $senderemail = owner_company()->getEmail();
         if (!is_valid_email($senderemail)) {
             $senderemail = '*****@*****.**';
         }
         $senderid = 0;
     }
     $type = $object->getObjectTypeName();
     $typename = lang($object->getObjectTypeName());
     $uid = $object->getUniqueObjectId();
     $name = $object instanceof Comment ? $object->getObject()->getObjectName() : $object->getObjectName();
     if (!isset($description)) {
         $description = "{$notification} notification {$type} desc";
         $descArgs = array(clean($object->getObjectName()), $sendername);
     }
     if (!isset($descArgs)) {
         $descArgs = array();
     }
     if ($object->columnExists('text') && trim($object->getColumnValue('text'))) {
         $text = escape_html_whitespace(convert_to_links(clean("\n" . $object->getColumnValue('text'))));
         $properties['text'] = $text;
     }
     $second_properties = array();
     //$properties['unique id'] = $uid;
     if ($object->columnExists('description') && trim($object->getColumnValue('description'))) {
         $text = escape_html_whitespace(convert_to_links(clean("\n" . $object->getColumnValue('description'))));
         $properties['description'] = $text;
     }
     if ($object instanceof ProjectFile && $object->getType() == ProjectFiles::TYPE_DOCUMENT) {
         $revision = $object->getLastRevision();
         if (trim($revision->getComment())) {
             $text = escape_html_whitespace(convert_to_links(clean("\n" . $revision->getComment())));
             $properties['revision comment'] = $text;
         }
     }
     tpl_assign('object', $object);
     tpl_assign('properties', $properties);
     tpl_assign('second_properties', $second_properties);
     $emails = array();
     foreach ($people as $user) {
         if ($user->getId() != $senderid && $object->canView($user)) {
             // send notification on user's locale and with user info
             $locale = $user->getLocale();
             Localization::instance()->loadSettings($locale, ROOT . '/language');
             $workspaces = $object->getUserWorkspaces($user);
             $ws = "";
             $plain_ws = "";
             foreach ($workspaces as $w) {
                 if ($ws) {
                     $ws .= ", ";
                 }
                 if ($plain_ws) {
                     $plain_ws .= ", ";
                 }
                 $css = get_workspace_css_properties($w->getColor());
                 $ws .= "<span style=\"{$css}\">" . $w->getPath() . "</span>";
                 $plain_ws .= $w->getPath();
             }
             $properties['workspace'] = $ws;
             tpl_assign('links', $links);
             tpl_assign('properties', $properties);
             tpl_assign('description', langA($description, $descArgs));
             $from = self::prepareEmailAddress($senderemail, $sendername);
             $emails[] = array("to" => array(self::prepareEmailAddress($user->getEmail(), $user->getDisplayName())), "from" => self::prepareEmailAddress($senderemail, $sendername), "subject" => $subject = lang("{$notification} notification {$type}", $name, $uid, $typename, $plain_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);
 }