/**
  * Returns all events for the given date, tag and considers the active project
  *
  * @param DateTimeValue $date
  * @param String $tags
  * @return unknown
  */
 static function getDayProjectEvents(DateTimeValue $date, $context = null, $user = -1, $inv_state = '-1', $archived = false)
 {
     $day = $date->getDay();
     $month = $date->getMonth();
     $year = $date->getYear();
     if (!is_numeric($day) or !is_numeric($month) or !is_numeric($year)) {
         return NULL;
     }
     $tz_hm = "'" . floor(logged_user()->getTimezone()) . ":" . abs(logged_user()->getTimezone()) % 1 * 60 . "'";
     $date = new DateTimeValue($date->getTimestamp() - logged_user()->getTimezone() * 3600);
     $next_date = new DateTimeValue($date->getTimestamp() + 24 * 3600);
     $start_date_str = $date->format("Y-m-d H:i:s");
     $nextday_date_str = $next_date->format("Y-m-d H:i:s");
     // fix any date issues
     $year = date("Y", mktime(0, 0, 1, $month, $day, $year));
     $month = date("m", mktime(0, 0, 1, $month, $day, $year));
     $day = date("d", mktime(0, 0, 1, $month, $day, $year));
     //permission check
     $first_d = $day;
     while ($first_d > 7) {
         $first_d -= 7;
     }
     $week_of_first_day = date("W", mktime(0, 0, 0, $month, $first_d, $year));
     $conditions = "\tAND (\n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t`duration` > `start` AND (`start` >= '{$start_date_str}' AND `start` < '{$nextday_date_str}' OR `duration` <= '{$nextday_date_str}' AND `duration` > '{$start_date_str}' OR `start` < '{$start_date_str}' AND `duration` > '{$nextday_date_str}')\n\t\t\t\t\t\tOR \n\t\t\t\t\t\t`type_id` = 2 AND `start` >= '{$start_date_str}' AND `start` < '{$nextday_date_str}'\n\t\t\t\t\t)\n\t\t\t\t) \n\t\t\t\tOR \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}' \n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( DATEDIFF(ADDDATE(`start`, INTERVAL " . logged_user()->getTimezone() . " HOUR), '{$year}-{$month}-{$day}') ,repeat_d) = 0\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_d` DAY) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n                                                        repeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( PERIOD_DIFF(DATE_FORMAT(`start`,'%Y%m'),DATE_FORMAT('{$start_date_str}','%Y%m')) ,repeat_m) = 0\n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t`start` <= '{$start_date_str}' AND DAY(`start`) = {$day} \n\t\t\t\t\t\t\tAND\t\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_m` MONTH) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n                                                        repeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( (YEAR(DATE(`start`))-YEAR('{$start_date_str}')) ,repeat_y) = 0\n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t`start` <= '{$start_date_str}' AND DAY(`start`) = {$day} AND MONTH(`start`) = {$month} \n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_y` YEAR) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n                                                        repeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\t\t\n\t\t\t\t)\n\t\t\t\t)\n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_h` = 1 \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_dow` = DAYOFWEEK('{$start_date_str}') \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_wnum` + {$week_of_first_day} - 1 = WEEK('{$start_date_str}', 3) \n\t\t\t\t\tAND\n\t\t\t\t\tMOD( ABS(PERIOD_DIFF(DATE_FORMAT(`start`, '%Y%m'), DATE_FORMAT('{$start_date_str}', '%Y%m'))), `repeat_mjump`) = 0\n\t\t\t\t)\n\t\t\t)";
     $start = null;
     $limit = null;
     //$result_events = self::getContentObjects(active_context(), ObjectTypes::findById(self::instance()->getObjectTypeId()), '`start`', 'ASC', $conditions,null,false,false,$start, $limit)->objects;
     $result_events = self::instance()->listing(array("order" => 'start', "order_dir" => 'ASC', "extra_conditions" => $conditions, "start" => $start, "limit" => $limit))->objects;
     // Find invitations for events and logged user
     if (is_array($result_events) && count($result_events)) {
         ProjectEvents::addInvitations($result_events, $user);
         if (!($user == null && $inv_state == null)) {
             foreach ($result_events as $k => $event) {
                 $conditions = '`event_id` = ' . $event->getId();
                 if ($user != -1) {
                     $conditions .= ' AND `contact_id` = ' . $user;
                 }
                 $inv = EventInvitations::findAll(array('conditions' => $conditions));
                 if (!is_array($inv)) {
                     if ($inv == null || trim($inv_state) != '-1' && !strstr($inv_state, '' . $inv->getInvitationState()) && $inv->getContactId() == logged_user()->getId()) {
                         unset($result_events[$k]);
                     }
                 } else {
                     if (count($inv) > 0) {
                         foreach ($inv as $key => $v) {
                             if ($v == null || trim($inv_state) != '-1' && !strstr($inv_state, '' . $v->getInvitationState()) && $v->getContactId() == logged_user()->getId()) {
                                 unset($result_events[$k]);
                                 break;
                             }
                         }
                     } else {
                         unset($result_events[$k]);
                     }
                 }
             }
         }
     }
     return $result_events;
 }
function core_dimensions_after_add_to_members($object, &$ignored)
{
    if ($object instanceof Report || $object instanceof Timeslot) {
        return;
    }
    // Add to persons and users dimensions
    $user_ids = array();
    if (logged_user() instanceof Contact) {
        $user_ids[] = logged_user()->getId();
    }
    if ($object instanceof ProjectTask) {
        /* @var $object ProjectTask */
        if ($object->getAssignedById() > 0) {
            $user_ids[] = $object->getAssignedById();
        }
        if ($object->getAssignedToContactId() > 0) {
            $user_ids[] = $object->getAssignedToContactId();
        }
    }
    if ($object instanceof ProjectEvent) {
        /* @var $object ProjectEvent */
        $invitations = EventInvitations::findAll(array("conditions" => "`event_id` = " . $object->getId()));
        foreach ($invitations as $inv) {
            $user_ids[] = $inv->getContactId();
        }
    }
    if ($object instanceof Contact && !$object->isUser()) {
        $member = Members::findOne(array("conditions" => "`object_id` = (" . $object->getId() . ") AND `dimension_id` = (SELECT `id` FROM `" . TABLE_PREFIX . "dimensions` WHERE `code` = 'feng_persons')"));
        if ($member instanceof Member) {
            $object->addToMembers(array($member));
        }
    }
    $context = active_context();
    if (count($context) > 0) {
        foreach ($context as $selection) {
            if ($selection instanceof Member && $selection->getDimension()->getCode() == 'feng_persons') {
                $object->addToMembers(array($selection));
            }
        }
    }
    core_dim_add_to_person_user_dimensions($object, $user_ids);
}
Beispiel #3
0
                 $options[] = option_tag(lang('decide later'), 0, $event_inv_state == 0 ? array('selected' => 'selected') : null);
             }
             $att_form = '<form style="height:100%;background-color:white" class="internalForm" action="' . get_url('event', 'change_invitation_state') . '" method="post">';
             $att_form .= '<table><tr><td style="padding-right:6px;"><b>' . lang('attendance') . '<b></td><td>';
             $att_form .= select_box('event_attendance', $options, array('id' => 'viewEventFormComboAttendance')) . '</td><td>';
             $att_form .= input_field('event_id', $event->getId(), array('type' => 'hidden'));
             $att_form .= input_field('user_id', logged_user()->getId(), array('type' => 'hidden'));
             $att_form .= submit_button(lang('Save'), null, array('style' => 'margin-top:0px;margin-left:10px')) . '</td></tr></table></form>';
         }
     }
     //if
 }
 // if
 $otherInvitationsTable = '';
 if (!$event->isNew()) {
     $otherInvitations = EventInvitations::findAll(array('conditions' => 'event_id = ' . $event->getId()));
     if (isset($otherInvitations) && is_array($otherInvitations)) {
         $otherInvitationsTable .= '<div class="coInputMainBlock adminMainBlock" style="width:70%;">';
         $otherInvitationsTable .= '<table style="width:100%;"><col width="50%" /><col width="50%" />';
         $otherInvitationsTable .= '<tr><th><b>' . lang('name') . '</b></th><th><b>' . lang('participate') . '</b></th></tr>';
         $isAlt = false;
         $cant = 0;
         foreach ($otherInvitations as $inv) {
             $inv_user = Contacts::findById($inv->getContactId());
             if ($inv_user instanceof Contact) {
                 if (can_access($inv_user, $event->getMembers(), ProjectEvents::instance()->getObjectTypeId(), ACCESS_LEVEL_READ)) {
                     if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_update_other_users_invitations')) {
                         // only show status
                         $state_desc = lang('pending response');
                         if ($inv->getInvitationState() == 1) {
                             $state_desc = lang('yes');
 /**
  * Returns all events for the given date, tag and considers the active project
  *
  * @param DateTimeValue $date
  * @param String $tags
  * @return unknown
  */
 static function getDayProjectEvents(DateTimeValue $date, $tags = '', $project = null, $user = -1, $inv_state = '-1', $archived = false)
 {
     $day = $date->getDay();
     $month = $date->getMonth();
     $year = $date->getYear();
     if (!is_numeric($day) or !is_numeric($month) or !is_numeric($year)) {
         return NULL;
     }
     $tz_hm = "'" . floor(logged_user()->getTimezone()) . ":" . abs(logged_user()->getTimezone()) % 1 * 60 . "'";
     $date = new DateTimeValue($date->getTimestamp() - logged_user()->getTimezone() * 3600);
     $next_date = new DateTimeValue($date->getTimestamp() + 24 * 3600);
     $start_date_str = $date->format("Y-m-d H:i:s");
     $nextday_date_str = $next_date->format("Y-m-d H:i:s");
     // fix any date issues
     $year = date("Y", mktime(0, 0, 1, $month, $day, $year));
     $month = date("m", mktime(0, 0, 1, $month, $day, $year));
     $day = date("d", mktime(0, 0, 1, $month, $day, $year));
     //permission check
     $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectEvents::instance(), ACCESS_LEVEL_READ, logged_user()) . ')';
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(!$archived);
         $wsstring = " AND " . self::getWorkspaceString($pids);
     } else {
         $wsstring = "";
     }
     if (isset($tags) && $tags && $tags != '') {
         $tag_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` IN (" . DB::escape($tags) . ") AND  `" . TABLE_PREFIX . "project_events`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'ProjectEvents') ";
     } else {
         $tag_str = "";
     }
     $first_d = $day;
     while ($first_d > 7) {
         $first_d -= 7;
     }
     $week_of_first_day = date("W", mktime(0, 0, 0, $month, $first_d, $year));
     if ($archived) {
         $archived_cond = " AND `archived_by_id` <> 0";
     } else {
         $archived_cond = " AND `archived_by_id` = 0";
     }
     $conditions = "\t(\n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS EVENTS ON THE ACTUAL DAY IT'S SET FOR (ONE TIME EVENTS)\n\t\t\t\t-- \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t`duration` > `start` AND (`start` >= '{$start_date_str}' AND `start` < '{$nextday_date_str}' OR `duration` <= '{$nextday_date_str}' AND `duration` > '{$start_date_str}' OR `start` < '{$start_date_str}' AND `duration` > '{$nextday_date_str}')\n\t\t\t\t\t\tOR \n\t\t\t\t\t\t`type_id` = 2 AND `start` >= '{$start_date_str}' AND `start` < '{$nextday_date_str}'\n\t\t\t\t\t)\n\t\t\t\t) \n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS REGULAR REPEATING EVENTS - DAILY, WEEKLY, MONTHLY, OR YEARLY.\n\t\t\t\t-- \n\t\t\t\tOR \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}' \n\t\t\t\t\tAND\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( DATEDIFF(ADDDATE(`start`, INTERVAL " . logged_user()->getTimezone() . " HOUR), '{$year}-{$month}-{$day}') ,repeat_d) = 0\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_d` DAY) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( PERIOD_DIFF(DATE_FORMAT(`start`,'%Y%m'),DATE_FORMAT('{$start_date_str}','%Y%m')) ,repeat_m) = 0\n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t`start` <= '{$start_date_str}' AND DAY(`start`) = {$day} \n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_m` MONTH) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tMOD( (YEAR(DATE(`start`))-YEAR('{$start_date_str}')) ,repeat_y) = 0\n\t\t\t\t\t\t\tAND \n\t\t\t\t\t\t\t`start` <= '{$start_date_str}' AND DAY(`start`) = {$day} AND MONTH(`start`) = {$month} \n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_y` YEAR) >= '{$start_date_str}'\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\trepeat_end >= '{$year}-{$month}-{$day}'\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t\t)\t\t\n\t\t\t\t)\n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS EVENTS SET TO BE A CERTAIN DAY OF THE WEEK IN A CERTAIN WEEK EVERY CERTAIN AMOUNT OF MONTHS\n\t\t\t\t-- \n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_h` = 1 \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_dow` = DAYOFWEEK('{$start_date_str}') \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_wnum` + {$week_of_first_day} - 1 = WEEK('{$start_date_str}', 3) \n\t\t\t\t\tAND\n\t\t\t\t\tMOD( PERIOD_DIFF(DATE_FORMAT(`start`, '%Y%m'), DATE_FORMAT('{$start_date_str}', '%Y%m')), `repeat_mjump`) = 0\n\t\t\t\t)\n\t\t\t)\n\t\t\t{$wsstring}\n\t\t\t{$permissions}\n\t\t\t{$tag_str} {$archived_cond}";
     $result_events = self::findAll(array('conditions' => $conditions, 'order' => '`start`'));
     // Find invitations for events and logged user
     if (is_array($result_events) && count($result_events)) {
         ProjectEvents::addInvitations($result_events, $user);
         if (!($user == null && $inv_state == null)) {
             foreach ($result_events as $k => $event) {
                 $conditions = '`event_id` = ' . $event->getId();
                 if ($user != -1) {
                     $conditions .= ' AND `user_id` = ' . $user;
                 }
                 $inv = EventInvitations::findAll(array('conditions' => $conditions));
                 if (!is_array($inv)) {
                     if ($inv == null || trim($inv_state) != '-1' && !strstr($inv_state, '' . $inv->getInvitationState()) && $inv->getUserId() == logged_user()->getId()) {
                         unset($result_events[$k]);
                     }
                 } else {
                     if (count($inv) > 0) {
                         foreach ($inv as $key => $v) {
                             if ($v == null || trim($inv_state) != '-1' && !strstr($inv_state, '' . $v->getInvitationState()) && $v->getUserId() == logged_user()->getId()) {
                                 unset($result_events[$k]);
                                 break;
                             }
                         }
                     } else {
                         unset($result_events[$k]);
                     }
                 }
             }
         }
     }
     return $result_events;
 }
 /**
  * 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);
 }
 function findSyncByEvent($event_id)
 {
     return EventInvitations::findAll(array('conditions' => array('`synced` = 1 AND `event_id` = ' . $event_id)));
 }
 function findByEvent($event_id)
 {
     return EventInvitations::findAll(array('conditions' => array('`event_id` = ?', $event_id)));
 }
	function delete() {
                $options = array_var($_GET, 'options');
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		//check auth
		$event = ProjectEvents::findById(get_id());
		if ($event != null) {
		    if(!$event->canDelete(logged_user())){	    	
				flash_error(lang('no access permissions'));
				//$this->redirectTo('event');
				ajx_current("empty");
				return ;
		    }
		    $events = array($event);
		} else {
			$ev_ids = explode(',', array_var($_GET, 'ids', ''));
			if (!is_array($ev_ids) || count($ev_ids) == 0) {
				flash_error(lang('no objects selected'));
				ajx_current("empty");
				return ;
			}
			$events = array();
			foreach($ev_ids as $id) {
				$e = ProjectEvents::findById($id);
				if ($e instanceof ProjectEvent) $events[] = $e;
			}
		}
	    
                $this->getUserPreferences($view_type, $user_filter, $status_filter, $task_filter);
		$this->setTemplate($view_type);
		
		try {
			foreach ($events as $event) {
				$notifications = array();
				$invs = EventInvitations::findAll(array ('conditions' => 'event_id = ' . $event->getId()));
				if (is_array($invs)) {
					foreach ($invs as $inv) {
						if ($inv->getContactId() != logged_user()->getId()) 
							$notifications[] = Contacts::findById(array('id' => $inv->getContactId()));
					}
				} else {
					if ($invs->getContactId() != logged_user()->getId()) 
						$notifications[] = Contacts::findById(array('id' => $invs->getContactId()));
				}
				//Notifier::notifEvent($event, $notifications, 'deleted', logged_user());
				
				DB::beginWork();
				// delete event
				$event->trash();
                                
                                if($event->getSpecialID() != ""){
                                    $this->delete_event_calendar_extern($event);
                                    $event->setSpecialID("");
                                    $event->save();
                                }       
                                
                                if($options == "news" || $options == "all"){
                                    $this->repetitive_event_related($event,"delete",$options);
                                }
                                
				ApplicationLogs::createLog($event, ApplicationLogs::ACTION_TRASH);
				DB::commit();
			}
			flash_success(lang('success delete event', ''));
			ajx_current("reload");			
          	ajx_add("overview-panel", "reload");
			          	
		} catch(Exception $e) {
			DB::rollback();
			flash_error(lang('error delete event'));
			ajx_current("empty");
		} // try
	}
 static function addInvitations(&$result_events, $user_id = -1)
 {
     if ($user_id == -1) {
         $user_id = logged_user()->getId();
     }
     if (isset($result_events) && is_array($result_events) && count($result_events)) {
         $event_ids = array();
         foreach ($result_events as $event) {
             $event_ids[] = $event->getId();
         }
         $invitations_res = EventInvitations::findAll(array('conditions' => 'contact_id = ' . $user_id));
         $invitations = array();
         foreach ($invitations_res as $i) {
             if (!isset($invitations[$i->getEventId()])) {
                 $invitations[$i->getEventId()] = array();
             }
             $invitations[$i->getEventId()][] = $i;
         }
         foreach ($result_events as $event) {
             $event_invitations = array_var($invitations, $event->getId(), array());
             foreach ($event_invitations as $inv) {
                 $event->addInvitation($inv);
             }
         }
     }
 }
 function delete()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     //check auth
     $event = ProjectEvents::findById(get_id());
     if ($event != null) {
         if (!$event->canDelete(logged_user())) {
             flash_error(lang('no access permissions'));
             //$this->redirectTo('event');
             ajx_current("empty");
             return;
         }
         $events = array($event);
     } else {
         $ev_ids = explode(',', array_var($_GET, 'ids', ''));
         if (!is_array($ev_ids) || count($ev_ids) == 0) {
             flash_error(lang('no objects selected'));
             ajx_current("empty");
             return;
         }
         $events = array();
         foreach ($ev_ids as $id) {
             $e = ProjectEvents::findById($id);
             if ($e instanceof ProjectEvent) {
                 $events[] = $e;
             }
         }
     }
     $this->getUserPreferences($view_type, $user_filter, $status_filter);
     $this->setTemplate($view_type);
     $tag = active_tag();
     tpl_assign('tags', $tag);
     try {
         foreach ($events as $event) {
             $notifications = array();
             $invs = EventInvitations::findAll(array('conditions' => 'event_id = ' . $event->getId()));
             if (is_array($invs)) {
                 foreach ($invs as $inv) {
                     if ($inv->getUserId() != logged_user()->getId()) {
                         $notifications[] = Users::findById(array('id' => $inv->getUserId()));
                     }
                 }
             } else {
                 if ($invs->getUserId() != logged_user()->getId()) {
                     $notifications[] = Users::findById(array('id' => $invs->getUserId()));
                 }
             }
             Notifier::notifEvent($event, $notifications, 'deleted', logged_user());
             DB::beginWork();
             // delete event
             $event->trash();
             ApplicationLogs::createLog($event, $event->getWorkspaces(), ApplicationLogs::ACTION_TRASH);
             DB::commit();
         }
         flash_success(lang('success delete event', ''));
         ajx_current("reload");
         ajx_add("overview-panel", "reload");
     } catch (Exception $e) {
         DB::rollback();
         //Logger::log($e->getTraceAsString());
         flash_error(lang('error delete event'));
         ajx_current("empty");
     }
     // try
 }
 function change_invitation_state($attendance = null, $event_id = null, $user_id = null)
 {
     $from_post_get = $attendance == null || $event_id == null;
     // Take variables from post
     if ($attendance == null) {
         $attendance = array_var($_POST, 'event_attendance');
     }
     if ($event_id == null) {
         $event_id = array_var($_POST, 'event_id');
     }
     if ($user_id == null) {
         $user_id = array_var($_POST, 'user_id');
     }
     // If post is empty, take variables from get
     if ($attendance == null) {
         $attendance = array_var($_GET, 'at');
     }
     if ($event_id == null) {
         $event_id = array_var($_GET, 'e');
     }
     if ($user_id == null) {
         $user_id = array_var($_GET, 'u');
     }
     $silent = array_var($_REQUEST, 'silent');
     if ($attendance == null || $event_id == null) {
         flash_error('Missing parameters');
         ajx_current("back");
     } else {
         $conditions = array('conditions' => "`event_id` = " . DB::escape($event_id) . " AND `contact_id` = " . DB::escape($user_id));
         $inv = EventInvitations::findOne($conditions);
         $conditions_all = array('conditions' => "`event_id` = " . DB::escape($event_id));
         $invs = EventInvitations::findAll($conditions_all);
         if ($inv != null) {
             if (!SystemPermissions::userHasSystemPermission(logged_user(), 'can_update_other_users_invitations') && $inv->getContactId() != logged_user()->getId()) {
                 flash_error(lang('no access permissions'));
                 self::view_calendar();
                 return;
             }
             try {
                 DB::beginWork();
                 $inv->setInvitationState($attendance);
                 $inv->save();
                 DB::commit();
             } catch (Exception $e) {
                 DB::rollback();
                 flash_error($e->getMessage());
                 ajx_current("empty");
                 return;
             }
         }
         if ($from_post_get) {
             // Notify creator (only when invitation is accepted or declined)
             $event = ProjectEvents::findById(array('id' => $event_id));
             if ($inv->getInvitationState() == 1 || $inv->getInvitationState() == 2) {
                 $user = Contacts::findById(array('id' => $user_id));
                 session_commit();
                 Notifier::notifEventAssistance($event, $inv, $user, $invs);
                 if (!$silent) {
                     if ($inv->getInvitationState() == 1) {
                         flash_success(lang('invitation accepted'));
                     } else {
                         flash_success(lang('invitation rejected'));
                     }
                 }
             } else {
                 if (!$silent) {
                     flash_success(lang('success edit event', $event instanceof ProjectEvent ? clean($event->getObjectName()) : ''));
                 }
             }
             if (array_var($_GET, 'at')) {
                 self::view_calendar();
             } else {
                 if (!$silent) {
                     ajx_current("reload");
                 } else {
                     ajx_current("empty");
                 }
             }
         }
     }
 }