public function get_feed_data_struct($idcat = 0, $name = '')
    {
        if (CalendarService::get_categories_manager()->get_categories_cache()->category_exists($idcat)) {
            $now = new Date();
            $lang = LangLoader::get('common', 'calendar');
            $querier = PersistenceContext::get_querier();
            $category = CalendarService::get_categories_manager()->get_categories_cache()->get_category($idcat);
            $site_name = GeneralConfig::load()->get_site_name();
            $site_name = $idcat != Category::ROOT_CATEGORY ? $site_name . ' : ' . $category->get_name() : $site_name;
            $feed_module_name = $lang['calendar.feed.name'];
            $data = new FeedData();
            $data->set_title($feed_module_name . ' - ' . $site_name);
            $data->set_date(new Date());
            $data->set_link(SyndicationUrlBuilder::rss('calendar', $idcat));
            $data->set_host(HOST);
            $data->set_desc($feed_module_name . ' - ' . $site_name);
            $data->set_lang(LangLoader::get_message('xml_lang', 'main'));
            $data->set_auth_bit(Category::READ_AUTHORIZATIONS);
            $categories = CalendarService::get_categories_manager()->get_childrens($idcat, new SearchCategoryChildrensOptions(), true);
            $ids_categories = array_keys($categories);
            $result = $querier->select('SELECT *
			FROM ' . CalendarSetup::$calendar_events_table . ' event
			LEFT JOIN ' . CalendarSetup::$calendar_events_content_table . ' event_content ON event_content.id = event.content_id
			LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = event_content.author_id
			LEFT JOIN ' . CalendarSetup::$calendar_cats_table . ' cat ON cat.id = event_content.id_category
			WHERE approved = 1
			AND id_category IN :cats_ids
			ORDER BY start_date DESC', array('cats_ids' => $ids_categories));
            while ($row = $result->fetch()) {
                $event = new CalendarEvent();
                $event->set_properties($row);
                $category = $categories[$event->get_content()->get_category_id()];
                $link = CalendarUrlBuilder::display_event($category->get_id(), $category->get_rewrited_name() ? $category->get_rewrited_name() : 'root', $event->get_id(), $event->get_content()->get_rewrited_title());
                $item = new FeedItem();
                $item->set_title($event->get_content()->get_title());
                $item->set_link($link);
                $item->set_guid($link);
                $item->set_desc(FormatingHelper::second_parse($event->get_content()->get_contents()) . ($event->get_content()->get_location() ? '<br />' . $lang['calendar.labels.location'] . ' : ' . $event->get_content()->get_location() . '<br />' : '') . '<br />' . $lang['calendar.labels.start_date'] . ' : ' . $event->get_start_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE) . '<br />' . $lang['calendar.labels.end_date'] . ' : ' . $event->get_end_date()->format(Date::FORMAT_DAY_MONTH_YEAR_HOUR_MINUTE));
                $item->set_date($event->get_start_date());
                $item->set_auth(CalendarService::get_categories_manager()->get_heritated_authorizations($category->get_id(), Category::READ_AUTHORIZATIONS, Authorizations::AUTH_PARENT_PRIORITY));
                $data->add_item($item);
            }
            $result->dispose();
            return $data;
        }
    }
 private function get_category()
 {
     if ($this->category === null) {
         $id = AppContext::get_request()->get_getint('id_category', 0);
         if (!empty($id)) {
             try {
                 $this->category = CalendarService::get_categories_manager()->get_categories_cache()->get_category($id);
             } catch (CategoryNotFoundException $e) {
                 $error_controller = PHPBoostErrors::unexisting_page();
                 DispatchManager::redirect($error_controller);
             }
         } else {
             $this->category = CalendarService::get_categories_manager()->get_categories_cache()->get_category(Category::ROOT_CATEGORY);
         }
     }
     return $this->category;
 }
 public function get_category()
 {
     return CalendarService::get_categories_manager()->get_categories_cache()->get_category($this->category_id);
 }
 protected function get_categories_manager()
 {
     return CalendarService::get_categories_manager();
 }
 private function save()
 {
     $this->config->set_items_number_per_page($this->form->get_value('items_number_per_page'));
     if ($this->form->get_value('comments_enabled')) {
         $this->config->enable_comments();
     } else {
         $this->config->disable_comments();
     }
     $this->config->set_event_color($this->form->get_value('event_color'));
     if ($this->form->get_value('members_birthday_enabled')) {
         $this->config->enable_members_birthday();
         $this->config->set_birthday_color($this->form->get_value('birthday_color'));
     } else {
         $this->config->disable_members_birthday();
     }
     $this->config->set_authorizations($this->form->get_value('authorizations')->build_auth_array());
     CalendarConfig::save();
     CalendarService::get_categories_manager()->regenerate_cache();
     CalendarCurrentMonthEventsCache::invalidate();
 }
 public function __construct()
 {
     parent::__construct(CalendarService::get_categories_manager());
 }
 private function is_authorized($bit)
 {
     $auth = CalendarService::get_categories_manager()->get_heritated_authorizations($this->id_category, $bit, Authorizations::AUTH_PARENT_PRIORITY);
     return AppContext::get_current_user()->check_auth($auth, $bit);
 }
    private function build_view(HTTPRequestCustom $request)
    {
        $config = CalendarConfig::load();
        $categories = CalendarService::get_categories_manager()->get_categories_cache()->get_categories();
        $year = $this->year ? $this->year : min($request->get_int('calendar_ajax_year', date('Y')), 2037);
        $month = $this->month ? $this->month : min($request->get_int('calendar_ajax_month', date('n')), 12);
        $bissextile = date("L", mktime(0, 0, 0, 1, 1, $year)) == 1 ? 29 : 28;
        $array_month = array(31, $bissextile, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        $array_l_month = array($this->lang['january'], $this->lang['february'], $this->lang['march'], $this->lang['april'], $this->lang['may'], $this->lang['june'], $this->lang['july'], $this->lang['august'], $this->lang['september'], $this->lang['october'], $this->lang['november'], $this->lang['december']);
        $month_days = $array_month[$month - 1];
        $previous_month = $month == 1 ? 12 : $month - 1;
        $previous_year = $month == 1 ? $year - 1 : $year;
        $next_month = $month == 12 ? 1 : $month + 1;
        $next_year = $month == 12 ? $year + 1 : $year;
        //Months
        for ($i = 1; $i <= 12; $i++) {
            $this->view->assign_block_vars('months', array('VALUE' => $i, 'NAME' => $array_l_month[$i - 1], 'SELECTED' => $month == $i));
        }
        //Years
        for ($i = 1970; $i <= 2037; $i++) {
            $this->view->assign_block_vars('years', array('VALUE' => $i, 'NAME' => $i, 'SELECTED' => $year == $i));
        }
        //Retrieve all the events of the selected month
        $events = $month == date('n') && $year == date('Y') ? CalendarCurrentMonthEventsCache::load()->get_events() : CalendarService::get_all_current_month_events($month, $year, $month_days);
        $events_legends_list = array();
        foreach ($events as $event) {
            $start_date = new Date($event['start_date'], Timezone::SERVER_TIMEZONE);
            $end_date = new Date($event['end_date'], Timezone::SERVER_TIMEZONE);
            if (($end_date->get_month() > $start_date->get_month() || $end_date->get_year() > $start_date->get_year()) && $month == $start_date->get_month()) {
                $first_event_day = $start_date->get_day();
                $last_event_day = $array_month[$month - 1];
            } else {
                if (($end_date->get_month() > $start_date->get_month() || $end_date->get_year() > $start_date->get_year()) && $month == $end_date->get_month()) {
                    $first_event_day = 1;
                    $last_event_day = $end_date->get_day();
                } else {
                    if (($end_date->get_month() > $start_date->get_month() || $end_date->get_year() > $start_date->get_year()) && $month > $start_date->get_month() && $month < $end_date->get_month()) {
                        $first_event_day = 1;
                        $last_event_day = $array_month[$month - 1];
                    } else {
                        $first_event_day = $start_date->get_day();
                        $last_event_day = $end_date->get_day();
                    }
                }
            }
            for ($j = $first_event_day; $j <= $last_event_day; $j++) {
                if ($event['type'] == 'EVENT' || $event['type'] == 'BIRTHDAY') {
                    $title = isset($array_events[$j]['title']) ? $array_events[$j]['title'] : '';
                    $array_events[$j] = array('title' => $title . (!empty($title) ? '
' : '') . ($event['type'] != 'BIRTHDAY' ? $j == $start_date->get_day() && $month == $start_date->get_month() && $year == $start_date->get_year() ? $start_date->get_hours() . 'h' . $start_date->get_minutes() . ' : ' : '' : LangLoader::get_message('calendar.labels.birthday_title', 'common', 'calendar') . ' ') . $event['title'], 'type' => $event['type'], 'color' => $event['type'] == 'BIRTHDAY' ? $config->get_birthday_color() : ($event['id_category'] != Category::ROOT_CATEGORY && $categories[$event['id_category']]->get_color() ? $categories[$event['id_category']]->get_color() : $config->get_event_color()), 'id_category' => $event['id_category']);
                    if ($event['type'] == 'BIRTHDAY') {
                        $events_legends_list[$j] = array('name' => LangLoader::get_message('calendar.labels.birthday', 'common', 'calendar'), 'color' => $config->get_birthday_color());
                    } else {
                        if ($event['type'] == 'EVENT' && $event['id_category'] == Category::ROOT_CATEGORY) {
                            $events_legends_list[$j] = array('name' => LangLoader::get_message('calendar.titles.event', 'common', 'calendar'), 'color' => $config->get_event_color());
                        } else {
                            if (!isset($events_legends_list[$event['id_category']])) {
                                $events_legends_list[$j] = array('name' => $categories[$event['id_category']]->get_name(), 'color' => $categories[$event['id_category']]->get_color());
                            }
                        }
                    }
                }
            }
        }
        $this->view->put_all(array('C_MINI_MODULE' => $this->is_mini_calendar(), 'C_DISPLAY_LEGEND' => !empty($events_legends_list) && !$this->is_mini_calendar(), 'DATE' => $array_l_month[$month - 1] . ' ' . $year, 'MINI_MODULE' => (int) $this->is_mini_calendar(), 'PREVIOUS_MONTH_TITLE' => $month == 1 ? $array_l_month[11] . ' ' . ($year - 1) : $array_l_month[$month - 2] . ' ' . $year, 'PREVIOUS_YEAR' => $previous_year, 'PREVIOUS_MONTH' => $previous_month, 'NEXT_MONTH_TITLE' => $month == 12 ? $array_l_month[0] . ' ' . ($year + 1) : $array_l_month[$month] . ' ' . $year, 'NEXT_YEAR' => $next_year, 'NEXT_MONTH' => $next_month, 'LEGEND' => self::build_legend($events_legends_list), 'U_AJAX_CALENDAR' => CalendarUrlBuilder::ajax_month_calendar()->rel(), 'U_AJAX_EVENTS' => CalendarUrlBuilder::ajax_month_events()->rel()));
        //First day of the month
        $first_day = date('w', @mktime(1, 0, 0, $month, 1, $year));
        if ($first_day == 0) {
            $first_day = 7;
        }
        //Calendar generation
        $day = 1;
        $last_day = $month_days + $first_day;
        for ($i = 1; $i <= 56; $i++) {
            $birthday_day = $color = false;
            if ($i % 8 == 1 && $i < $last_day) {
                $content = date('W', mktime(0, 0, 0, $month, $day, $year));
                $class = 'calendar-week';
                $last_day++;
            } else {
                if ($i >= $first_day + 1 && $i < $last_day) {
                    if ($day == date("j") && $month == date("m") && $year == date("Y")) {
                        $class = 'calendar-today';
                    } else {
                        if (!empty($array_events[$day])) {
                            $birthday_day = $array_events[$day]['type'] == 'BIRTHDAY';
                            $color = $array_events[$day]['color'];
                            $class = '';
                        } else {
                            if ($i % 8 == 7 || $i % 8 == 0) {
                                $class = 'calendar-weekend';
                            } else {
                                $class = 'calendar-other';
                            }
                        }
                    }
                    $content = $day;
                    $day++;
                } else {
                    if (($i % 8 == 7 || $i % 8 == 0) && $i > $first_day && $day <= $month_days) {
                        $class = 'calendar-weekend';
                    } else {
                        $class = 'calendar-none';
                    }
                }
            }
            if ($day > $month_days && $i % 8 == 0) {
                $i = 56;
            }
            $today = $day - 1;
            $this->view->assign_block_vars('day', array('C_MONTH_DAY' => $i % 8 != 1 && $class != 'calendar-none', 'C_COLOR' => $color || $birthday_day, 'C_WEEK_LABEL' => $i % 8 == 1, 'DAY' => $content, 'TITLE' => !empty($array_events[$today]) ? $array_events[$today]['title'] : '', 'COLOR' => $color, 'CLASS' => $class, 'CHANGE_LINE' => $i % 8 == 0 && $i != 56, 'U_DAY_EVENTS' => CalendarUrlBuilder::home($year, $month, $today, true)->rel()));
        }
    }
 private function contribution_actions(CalendarEvent $event, $id_event)
 {
     if ($event->get_id() === null) {
         if ($this->is_contributor_member()) {
             $contribution = new Contribution();
             $contribution->set_id_in_module($id_event);
             $contribution->set_description(stripslashes($this->form->get_value('contribution_description')));
             $contribution->set_entitled($event->get_content()->get_title());
             $contribution->set_fixing_url(CalendarUrlBuilder::edit_event($id_event)->relative());
             $contribution->set_poster_id(AppContext::get_current_user()->get_id());
             $contribution->set_module('calendar');
             $contribution->set_auth(Authorizations::capture_and_shift_bit_auth(CalendarService::get_categories_manager()->get_heritated_authorizations($event->get_content()->get_category_id(), Category::MODERATION_AUTHORIZATIONS, Authorizations::AUTH_CHILD_PRIORITY), Category::MODERATION_AUTHORIZATIONS, Contribution::CONTRIBUTION_AUTH_BIT));
             ContributionService::save_contribution($contribution);
         }
     } else {
         $corresponding_contributions = ContributionService::find_by_criteria('calendar', $id_event);
         if (count($corresponding_contributions) > 0) {
             $event_contribution = $corresponding_contributions[0];
             $event_contribution->set_status(Event::EVENT_STATUS_PROCESSED);
             ContributionService::save_contribution($event_contribution);
         }
     }
     $event->set_id($id_event);
 }