function return_announcements($show_slide = true) { //// Display System announcements $hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected'); if ($hideAnnouncements == 'true' && empty($userId)) { return null; } $announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null; $announcement = intval($announcement); if (!api_is_anonymous() && $this->user_id) { $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT; if ($show_slide) { $announcements = SystemAnnouncementManager::display_announcements_slider($visibility, $announcement); } else { $announcements = SystemAnnouncementManager::display_all_announcements($visibility, $announcement); } } else { if ($show_slide) { $announcements = SystemAnnouncementManager::display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement); } else { $announcements = SystemAnnouncementManager::display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement); } } return $announcements; }
/** * * @return string */ public function indexAction(Application $app, $id) { $actions = null; if (api_is_platform_admin()) { $actions = '<a href="' . api_get_path(WEB_PATH) . 'main/admin/system_announcements.php">' . \Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32) . '</a>'; } if (api_is_anonymous()) { $visibility = \SystemAnnouncementManager::VISIBLE_GUEST; } else { $visibility = api_is_allowed_to_create_course() ? \SystemAnnouncementManager::VISIBLE_TEACHER : \SystemAnnouncementManager::VISIBLE_STUDENT; } $content = \SystemAnnouncementManager::display_announcements_slider($visibility, $id); $app['template']->assign('content', $content); $app['template']->assign('actions', $actions); $response = $app['template']->renderLayout('layout_1_col.tpl'); return new Response($response, 200, array()); }
} else { $show_announcement_list = false; $form->display(); } break; default: break; } $show_announcement_list = true; } else { $form->display(); $show_announcement_list = false; } } if ($show_announcement_list) { $announcements = SystemAnnouncementManager::get_all_announcements(); $announcement_data = array(); foreach ($announcements as $index => $announcement) { $row = array(); $row[] = $announcement->id; $row[] = Display::return_icon($announcement->visible ? 'accept.png' : 'exclamation.png', $announcement->visible ? get_lang('AnnouncementAvailable') : get_lang('AnnouncementNotAvailable')); $row[] = $announcement->title; $row[] = api_convert_and_format_date($announcement->date_start); $row[] = api_convert_and_format_date($announcement->date_end); $row[] = "<a href=\"?id=" . $announcement->id . "&person=" . SystemAnnouncementManager::VISIBLE_TEACHER . "&action=" . ($announcement->visible_teacher ? 'make_invisible' : 'make_visible') . "\">" . Display::return_icon($announcement->visible_teacher ? 'eyes.png' : 'eyes-close.png', get_lang('ShowOrHide')) . "</a>"; $row[] = "<a href=\"?id=" . $announcement->id . "&person=" . SystemAnnouncementManager::VISIBLE_STUDENT . "&action=" . ($announcement->visible_student ? 'make_invisible' : 'make_visible') . "\">" . Display::return_icon($announcement->visible_student ? 'eyes.png' : 'eyes-close.png', get_lang('ShowOrHide')) . "</a>"; $row[] = "<a href=\"?id=" . $announcement->id . "&person=" . SystemAnnouncementManager::VISIBLE_GUEST . "&action=" . ($announcement->visible_guest ? 'make_invisible' : 'make_visible') . "\">" . Display::return_icon($announcement->visible_guest ? 'eyes.png' : 'eyes-close.png', get_lang('ShowOrHide')) . "</a>"; $row[] = $announcement->lang; $row[] = "<a href=\"?action=edit&id=" . $announcement->id . "\">" . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . "</a> <a href=\"?action=delete&id=" . $announcement->id . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES)) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL) . "</a>"; $announcement_data[] = $row; }
/** * Updates an announcement to the database * @param integer $id : id of the announcement * @param string $title : title of the announcement * @param string $content : content of the announcement * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) * @return bool True on success, false on failure */ public static function update_announcement($id, $title, $content, $date_start, $date_end, $visible_teacher = 0, $visible_student = 0, $visible_guest = 0, $lang = null, $send_mail = 0, $sendEmailTest = false) { $a_dateS = explode(' ', $date_start); $a_arraySD = explode('-', $a_dateS[0]); $a_arraySH = explode(':', $a_dateS[1]); $date_start_to_compare = array_merge($a_arraySD, $a_arraySH); $a_dateE = explode(' ', $date_end); $a_arrayED = explode('-', $a_dateE[0]); $a_arrayEH = explode(':', $a_dateE[1]); $date_end_to_compare = array_merge($a_arrayED, $a_arrayEH); $langsql = is_null($lang) ? 'NULL' : "'" . Database::escape_string($lang) . "'"; $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { Display::display_normal_message(get_lang('InvalidStartDate')); return false; } if (($date_end_to_compare[1] || $date_end_to_compare[2] || $date_end_to_compare[0]) && !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0])) { Display::display_normal_message(get_lang('InvalidEndDate')); return false; } if (strlen(trim($title)) == 0) { Display::display_normal_message(get_lang('InvalidTitle')); return false; } $start = api_get_utc_datetime($date_start); $end = api_get_utc_datetime($date_end); $title = Database::escape_string($title); $content = Database::escape_string($content); //Fixing urls that are sent by email $content = str_replace('src=\\"/home/', 'src=\\"' . api_get_path(WEB_PATH) . 'home/', $content); $content = str_replace('file=/home/', 'file=' . api_get_path(WEB_PATH) . 'home/', $content); $id = intval($id); $sql = "UPDATE " . $db_table . " SET lang={$langsql},title='" . $title . "',content='" . $content . "',date_start='" . $start . "',date_end='" . $end . "', "; $sql .= " visible_teacher = '" . $visible_teacher . "', visible_student = '" . $visible_student . "', visible_guest = '" . $visible_guest . "' , access_url_id = '" . api_get_current_access_url_id() . "' WHERE id = " . $id; if ($sendEmailTest) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content, null, null, $lang, $sendEmailTest); } else { if ($send_mail == 1) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content, $visible_teacher, $visible_student, $lang); } } $res = Database::query($sql); if ($res === false) { return false; } return true; }
/** * Returns a list of announcements * @param int User ID * @param bool True: show the announcements as a slider. False: show them as a vertical list * @return string HTML list of announcements * @assert () != '' * @assert (1) != '' */ public function return_announcements($user_id = null, $show_slide = true) { // Display System announcements $announcement = isset($_GET['announcement']) ? intval($_GET['announcement']) : null; if (!api_is_anonymous() && $user_id) { $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT; if ($show_slide) { $announcements = SystemAnnouncementManager::display_announcements_slider($visibility, $announcement); } else { $announcements = SystemAnnouncementManager::display_all_announcements($visibility, $announcement); } } else { if ($show_slide) { $announcements = SystemAnnouncementManager::display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement); } else { $announcements = SystemAnnouncementManager::display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement); } } return $announcements; }
/** * Updates an announcement to the database * @param integer $id : id of the announcement * @param string $title : title of the announcement * @param string $content : content of the announcement * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) * @return bool True on success, false on failure */ public static function update_announcement($id, $title, $content, $date_start, $date_end, $visible_teacher = 0, $visible_student = 0, $visible_guest = 0, $lang = null, $send_mail = 0, $sendEmailTest = false) { $em = Database::getManager(); $a_dateS = explode(' ', $date_start); $a_arraySD = explode('-', $a_dateS[0]); $a_arraySH = explode(':', $a_dateS[1]); $date_start_to_compare = array_merge($a_arraySD, $a_arraySH); $a_dateE = explode(' ', $date_end); $a_arrayED = explode('-', $a_dateE[0]); $a_arrayEH = explode(':', $a_dateE[1]); $date_end_to_compare = array_merge($a_arrayED, $a_arrayEH); $lang = is_null($lang) ? '' : $lang; if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { Display::display_normal_message(get_lang('InvalidStartDate')); return false; } if (($date_end_to_compare[1] || $date_end_to_compare[2] || $date_end_to_compare[0]) && !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0])) { Display::display_normal_message(get_lang('InvalidEndDate')); return false; } if (strlen(trim($title)) == 0) { Display::display_normal_message(get_lang('InvalidTitle')); return false; } $start = api_get_utc_datetime($date_start); $end = api_get_utc_datetime($date_end); //Fixing urls that are sent by email //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); $content = str_replace('src=\\"' . api_get_path(REL_HOME_PATH), 'src=\\"' . api_get_path(WEB_PATH) . api_get_path(REL_HOME_PATH), $content); $content = str_replace('file=' . api_get_path(REL_HOME_PATH), 'file=' . api_get_path(WEB_PATH) . api_get_path(REL_HOME_PATH), $content); $id = intval($id); if ($sendEmailTest) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content, null, null, $lang, $sendEmailTest); } else { if ($send_mail == 1) { SystemAnnouncementManager::send_system_announcement_by_email($title, $content, $visible_teacher, $visible_student, $lang); } } $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); if (!$announcement) { return false; } $dateStart = new DateTime($start, new DateTimeZone('UTC')); $dateEnd = new DateTime($end, new DateTimeZone('UTC')); $announcement->setLang($lang)->setTitle($title)->setContent($content)->setDateStart($dateStart)->setDateEnd($dateEnd)->setVisibleTeacher($visible_teacher)->setVisibleStudent($visible_student)->setVisibleGuest($visible_guest)->setAccessUrlId(api_get_current_access_url_id()); $em->merge($announcement); $em->flush(); return true; }
/** * Set header parameters */ private function setHeaderParameters() { $_course = api_get_course_info(); $_configuration = $this->app->getConfiguration(); $this_section = $this->app['this_section']; $nameTools = $this->title; $navigation = $this->navigation_array; $this->menu_navigation = $navigation['menu_navigation']; $this->assign('system_charset', api_get_system_encoding()); $this->assign('online_button', Display::return_icon('online.png')); $this->assign('offline_button', Display::return_icon('offline.png')); // Get language iso-code for this page - ignore errors $this->assign('document_language', $this->translator->getLocale()); $course_title = isset($_course['name']) ? $_course['name'] : null; $title_list = array(); $title_list[] = api_get_setting('platform.institution'); $title_list[] = api_get_setting('platform.site_name'); if (!empty($course_title)) { $title_list[] = $course_title; } if ($nameTools != '') { $title_list[] = $nameTools; } $title_string = ''; for ($i = 0; $i < count($title_list); $i++) { $title_string .= $title_list[$i]; if (isset($title_list[$i + 1])) { $item = trim($title_list[$i + 1]); if (!empty($item)) { $title_string .= ' - '; } } } $this->assign('title_string', $title_string); // Setting the theme and CSS files. $this->setCssFiles(); $this->setJsFiles(); // Implementation of prefetch. // See http://cdn.chamilo.org/main/img/online.png for details $prefetch = ''; if (!empty($_configuration['cdn_enable'])) { $prefetch .= '<meta http-equiv="x-dns-prefetch-control" content="on">'; foreach ($_configuration['cdn'] as $host => $exts) { $prefetch .= '<link rel="dns-prefetch" href="' . $host . '">'; } } $this->assign('prefetch', $prefetch); $this->assign('text_direction', api_get_text_direction()); $this->assign('section_name', 'section-' . $this_section); $favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_PATH) . 'favicon.ico" type="image/x-icon" />'; /*if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) { $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $url_info = api_get_current_access_url_info(); $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); $clean_url = api_replace_dangerous_char($url); $clean_url = str_replace('/', '-', $clean_url); $clean_url .= '/'; $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path $icon_real_homep = api_get_path(SYS_PATH).'home/'.$clean_url; //we create the new dir for the new sites if (is_file($icon_real_homep.'favicon.ico')) { $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />'; } } }*/ //$this->assign('favico', $favico); $this->setHelp(); $notification = $this->returnNotificationMenu(); $this->assign('notification_menu', $notification); // Profile link. $this->assign('is_profile_editable', api_is_profile_readable()); $visibility = api_is_allowed_to_create_course() ? \SystemAnnouncementManager::VISIBLE_TEACHER : \SystemAnnouncementManager::VISIBLE_STUDENT; $announcements = \SystemAnnouncementManager::getAnnouncements($visibility, null, 'resumed', false, 50); $this->assign('news_counter', count($announcements)); $this->assign('news_list', $announcements); $profile_link = null; if (api_get_setting('social.allow_social_tool') == 'true') { $profile_link = $this->urlGenerator->generate('root') . 'social/home.php'; } else { if (api_is_profile_readable()) { $profile_link = $this->urlGenerator->generate('root') . 'auth/profile.php'; } } $this->assign('profile_link', $profile_link); $this->assign('settings_link', $this->urlGenerator->generate('root') . 'auth/profile.php'); // Message link. $messageUrl = null; if (api_get_setting('message.allow_message_tool') == 'true') { $messageUrl = $this->urlGenerator->generate('root') . 'messages/inbox.php'; } $this->assign('message_link', $messageUrl); $institution = api_get_setting('platform.institution'); $portal_name = empty($institution) ? api_get_setting('platform.site_name') : $institution; $this->assign('portal_name', $portal_name); // Menu. $menu = $this->returnMenu(); $this->assign('menu', $menu); // Breadcrumb if ($this->loadBreadcrumb) { //$this->loadBreadcrumbToTemplate(); } //$this->app['new_breadcrumb'] = // Extra content $extra_header = null; if (!api_is_platform_admin()) { //$extra_header = trim(api_get_setting('header_extra_content')); } $this->assign('header_extra_content', $extra_header); }
<?php /* For licensing terms, see /license.txt */ // including necessary files require_once 'main/inc/global.inc.php'; $tool_name = get_lang('SystemAnnouncements'); $actions = ''; if (api_is_platform_admin()) { $actions = '<a href="' . api_get_path(WEB_PATH) . 'main/admin/system_announcements.php">' . Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32) . '</a>'; } if (api_is_anonymous()) { $visibility = SystemAnnouncementManager::VISIBLE_GUEST; } else { $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT; } if (!isset($_GET['id']) || empty($_GET['id'])) { $content = SystemAnnouncementManager::display_announcements_slider($visibility, $_GET['id']); } else { $content = SystemAnnouncementManager::displayAnnouncement($_GET['id'], $visibility); } $tpl = new Template($tool_name); $tpl->assign('actions', $actions); //$tpl->assign('message', $message); $tpl->assign('content', $content); $tpl->display_one_col_template();
<?php /* For licensing terms, see /license.txt */ // name of the language file that needs to be included $language_file = array ('admin','courses', 'index', 'announcements', 'group'); // including necessary files require_once 'main/inc/global.inc.php'; $tool_name = get_lang('SystemAnnouncements'); $actions = ''; if (api_is_platform_admin()) { $actions = '<a href="'.api_get_path(WEB_PATH).'main/admin/system_announcements.php">'.Display::return_icon('edit.png', get_lang('EditSystemAnnouncement'), array(), 32).'</a>'; } if (api_is_anonymous()) { $visibility = SystemAnnouncementManager::VISIBLE_GUEST; } else { $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT; } $content = SystemAnnouncementManager ::display_announcements_slider($visibility, $_GET['id']); $tpl = new Template($tool_name); $tpl->assign('actions', $actions); //$tpl->assign('message', $message); $tpl->assign('content', $content); $tpl->display_one_col_template();