/** * Get list of all announcements in the given or current course. * * @param array $thisCourse * @param int $limit number of records to return * @param int $startTime * @param bool $visibleOnly * @return array of array(id, title, content, time, visibility, rank) * @since 1.7 */ function announcement_get_course_item_list_portlet($thisCourse, $limit = null, $startTime = null, $visibleOnly = true) { // **** Caution: has to get fixed ! $tableAnn = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'announcement'; // **** $curdate = claro_mktime(); $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`, \n" . "'" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`, \n" . "'CLANN' AS `toolLabel`, \n" . "CONCAT(`temps`, ' ', '00:00:00') AS `date`, \n" . "`id` AS `id`, \n" . "`title` AS `title`, \n" . "`contenu` AS `content`, \n" . "`visibility`, \n" . "`visibleFrom`, \n" . "`visibleUntil` \n" . "FROM `" . $tableAnn . "` \n" . "WHERE CONCAT(`title`, `contenu`) != '' \n" . ($startTime ? '' : "AND DATE_FORMAT( `temps`, '%Y %m %d') >= '" . date('Y m d', (double) $startTime) . "' \n") . ($visibleOnly ? " AND visibility = 'SHOW' \n" : '') . " AND (UNIX_TIMESTAMP(`visibleFrom`) < '" . $curdate . "'\n OR `visibleFrom` IS NULL OR UNIX_TIMESTAMP(`visibleFrom`)=0\n )\n AND ('" . $curdate . "' < UNIX_TIMESTAMP(`visibleUntil`) OR `visibleUntil` IS NULL)" . "ORDER BY `date` DESC \n" . ($limit ? "LIMIT " . (int) $limit : ''); return claro_sql_query_fetch_all_rows($sql); }
public function render() { // Select current course's datas $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_courses = $tbl_mdb_names['course']; $curdate = claro_mktime(); $sql = "SELECT course.cours_id,\n course.code AS `sysCode`,\n course.directory AS `directory`,\n course.administrativeNumber AS `officialCode`,\n course.dbName AS `db`,\n course.intitule AS `title`,\n course.titulaires AS `titular`,\n course.language AS `language`,\n course.access AS `access`,\n course.status,\n course.sourceCourseId,\n UNIX_TIMESTAMP(course.expirationDate) AS expirationDate,\n UNIX_TIMESTAMP(course.creationDate) AS creationDate\n FROM `" . $tbl_courses . "` AS course\n WHERE course.code = " . Claroline::getDatabase()->quote($this->courseCode); $result = Claroline::getDatabase()->query($sql); $courseData = $result->fetch(Database_ResultSet::FETCH_ASSOC); $courseEventList = get_agenda_next_items_list($courseData, 10, $this->month, $this->year); if (is_array($courseEventList)) { $courseDigestList = array(); foreach ($courseEventList as $thisEvent) { $eventLine = trim(strip_tags($thisEvent['title'])); if ($eventLine == '') { $eventContent = trim(strip_tags($thisEvent['content'])); $eventLine = substr($eventContent, 0, 60) . (strlen($eventContent) > 60 ? ' (...)' : ''); } $eventDate = $thisEvent['day']; if (!array_key_exists($eventDate, $courseDigestList)) { $courseDigestList[$eventDate] = array(); $courseDigestList[$eventDate]['eventList'] = array(); $courseDigestList[$eventDate]['date'] = $eventDate; } $courseDigestList[$eventDate]['eventList'][] = array('id' => $thisEvent['id'], 'hour' => $thisEvent['hour'], 'location' => $thisEvent['location'], 'courseOfficialCode' => $courseData['officialCode'], 'courseSysCode' => $courseData['sysCode'], 'content' => $eventLine, 'url' => get_path('url') . '/claroline/calendar/agenda.php?cidReq=' . $courseData['sysCode']); } } $output = ''; //$output .= '<div class="calendar">'.$this->ajaxMiniCalendar($agendaItemList).'</div>'; $output .= '<div class="details">' . "\n" . '<dl>' . "\n"; if ($courseDigestList) { foreach ($courseDigestList as $agendaItem) { $output .= '<dt>' . "\n" . '<h2>' . claro_html_localised_date(get_locale('dateFormatLong'), strtotime($agendaItem['date'])) . '</h2>' . "\n" . '</dt>' . "\n"; foreach ($agendaItem['eventList'] as $agendaEvent) { $output .= '<dd>' . '<b>' . $agendaEvent['content'] . '</b>' . "\n" . (!empty($agendaEvent['hour']) ? ' – ' . ucfirst(strftime(get_locale('timeNoSecFormat'), strtotime($agendaEvent['hour']))) : '') . (!empty($agendaEvent['location']) ? ' | ' . $agendaEvent['location'] : '') . ' (<a href="' . $agendaEvent['url'] . '#item' . $agendaEvent['id'] . '">' . get_lang('more details') . '</a>)' . "\n" . '</dd>' . "\n"; } } } else { $output .= '<dt>' . "\n" . get_lang('No event to display') . "\n" . '</dt>' . "\n"; } $output .= '' . '</dl>' . "\n" . '</div>' . "\n"; return $output; }
$portletiterator = new CourseHomePagePortletIterator(ClaroCourse::getIdFromCode($cidReq)); // Fetch the session courses (if any) if (ClaroCourse::isSourceCourse($thisCourse->id)) { $sessionCourses = $thisCourse->getSessionCourses(); } else { $sessionCourses = array(); } // Notices for course managers if (claro_is_allowed_to_edit()) { if ($thisCourse->status == 'pending') { $dialogBox->warning(get_lang('This course is deactivated: you can reactive it from your course list')); } elseif ($thisCourse->status == 'date') { if (!empty($thisCourse->publicationDate) && $thisCourse->publicationDate > claro_mktime()) { $dialogBox->warning(get_lang('This course will be enabled on the %date', array('%date' => claro_date('d/m/Y', $thisCourse->publicationDate)))); } if (!empty($thisCourse->expirationDate) && $thisCourse->expirationDate > claro_mktime()) { $dialogBox->warning(get_lang('This course will be disable on the %date', array('%date' => claro_date('d/m/Y', $thisCourse->expirationDate)))); } } if ($thisCourse->userLimit > 0) { $dialogBox->warning(get_lang('This course is limited to %userLimit users', array('%userLimit' => $thisCourse->userLimit))); } if ($thisCourse->registration == 'validation') { $courseUserList = new Claro_CourseUserList(claro_get_current_course_id()); if ($courseUserList->has_registrationPending()) { $usersPanelUrl = claro_htmlspecialchars(Url::Contextualize($toolRepository . 'user/user.php')); $dialogBox->warning(get_lang('You have to validate users to give them access to this course through the <a href="%url">course user list</a>', array('%url' => $usersPanelUrl))); } } } // Get the portlets buttons
/** * Return if course status is enable */ function claro_is_course_enable() { $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $courseId = claro_get_current_course_id(); $curdate = claro_mktime(); if (claro_is_course_manager()) { $sql = " SELECT c.`code`\n FROM `" . $tbl_course . "` c\n WHERE (c.`status` != 'trash')\n AND c.`code` = '" . $courseId . "';"; } else { $sql = " SELECT c.`code`\n FROM `" . $tbl_course . "` c\n WHERE (c.`status` = 'enable'\n OR (c.`status` = 'date'\n AND (UNIX_TIMESTAMP(`creationDate`) <= '" . $curdate . "'\n OR `creationDate` IS NULL OR UNIX_TIMESTAMP(`creationDate`) = 0\n )\n AND ('" . $curdate . "' <= UNIX_TIMESTAMP(`expirationDate`)\n OR `expirationDate` IS NULL\n )\n )\n )\n AND c.`code` = '" . $courseId . "';"; } $result = claro_sql_query_get_single_value($sql); if (isset($result) or claro_is_platform_admin()) { $return = true; } else { $return = false; } return $return; }
/** * Returns a courses list for the current user. * * @return string list of courses (HTML format) * @deprecated use UserCourseList and CourseTreeView instead */ function render_user_course_list() { // Get the list of personnal courses marked as contening new events $date = Claroline::getInstance()->notification->get_notification_date(claro_get_current_user_id()); $modified_course = Claroline::getInstance()->notification->get_notified_courses($date, claro_get_current_user_id()); // Get all the user's courses $userCourseList = claro_get_user_course_list(); // Use the course id as array index, exclude disable courses // and flag hot courses $reorganizedUserCourseList = array(); $tempSessionCourses = array(); foreach ($userCourseList as $course) { // Do not include "disable", "pending", "trash" or "date" courses // (if we're not in the date limits) $curdate = claro_mktime(); $courseIsEnable = (bool) ($course['status'] == 'enable' || $course['status'] == 'date' && (!isset($course['creationDate']) || strtotime($course['creationDate']) <= $curdate) && (!isset($course['expirationDate']) || strtotime($course['expirationDate']) >= $curdate)); // Flag hot courses $course['hot'] = (bool) in_array($course['sysCode'], $modified_course); if (!isset($reorganizedUserCourseList[$course['courseId']]) && $courseIsEnable) { // If it's not a session course, include it in the final list if (empty($course['sourceCourseId'])) { $reorganizedUserCourseList[$course['courseId']] = $course; } else { $tempSessionCourses[$course['sourceCourseId']][] = $course; } } } unset($userCourseList); // Merge courses and their session courses (if any) foreach ($tempSessionCourses as $sourceCourseId => $sessionCourses) { /* * Sometimes, a session course could not find its associated source * course in the user course list. Simply because, for some reason, * this user isn't registered to the source course anymore, but is * still registered in the session course. */ if (!empty($reorganizedUserCourseList[$sourceCourseId])) { $reorganizedUserCourseList[$sourceCourseId]['sessionCourses'] = $sessionCourses; } else { foreach ($sessionCourses as $course) { $reorganizedUserCourseList[$course['courseId']] = $course; } } } unset($tempSessionCourses); // Now, $reorganizedUserCourseList contains all user's courses and, for // each course, its eventual session courses. // Display $out = ''; // Courses organized by categories if (get_conf('userCourseListGroupByCategories')) { // Get all the categories names (used to build trails) $categoryList = ClaroCategory::getAllCategories(0, 0, 1); // Get the categories informations for these courses $userCategoryList = ClaroCategory::getCoursesCategories($reorganizedUserCourseList); // Use the category id as array index $reorganizedUserCategoryList = array(); foreach ($userCategoryList as $category) { // Flag root courses and put it aside $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 0; if ($category['rootCourse']) { $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 1; } if (!isset($reorganizedUserCategoryList[$category['categoryId']])) { $reorganizedUserCategoryList[$category['categoryId']] = $category; //We won't need that key anymore unset($reorganizedUserCategoryList[$category['categoryId']]['courseId']); } // Initialise the category's course list $reorganizedUserCategoryList[$category['categoryId']]['courseList'] = array(); } // Place courses in the right categories and build categories' trails $currentCategoryId = null; foreach ($userCategoryList as $category) { // Build the full trail for each category (excepted root category) if ($category['categoryId'] == 0) { $trail = $category['name']; } else { $trail = build_category_trail($categoryList, $category['categoryId']); } $reorganizedUserCategoryList[$category['categoryId']]['trail'] = $trail; // Put root courses aside if ($reorganizedUserCourseList[$category['courseId']]['rootCourse']) { $reorganizedUserCategoryList[$category['categoryId']]['rootCourse'] = $reorganizedUserCourseList[$category['courseId']]; } else { // Do not include source courses (only display session courses) // (excepted if the user is manager of the course) if (!$reorganizedUserCourseList[$category['courseId']]['isSourceCourse'] || $reorganizedUserCourseList[$category['courseId']]['isCourseManager']) { $reorganizedUserCategoryList[$category['categoryId']]['courseList'][] = $reorganizedUserCourseList[$category['courseId']]; } } } unset($userCategoryList); if (count($reorganizedUserCategoryList) > 0) { $out .= '<dl class="courseList">'; foreach ($reorganizedUserCategoryList as $category) { if (!empty($category['courseList']) || !empty($category['rootCourse'])) { $out .= '<dt>' . "\n" . '<h4 id="' . $category['categoryId'] . '">' . $category['trail'] . (!empty($category['rootCourse']) ? ' [<a href="' . get_path('url') . '/claroline/course/index.php?cid=' . claro_htmlspecialchars($category['rootCourse']['sysCode']) . '">' . get_lang('Infos') . '</a>]' : '') . '</h4>' . "\n" . '</dt>' . "\n"; if (!empty($category['courseList'])) { foreach ($category['courseList'] as $course) { $out .= render_course_in_dl_list($course, $course['hot']); } } else { $out .= '<dt>' . get_lang('There are no courses in this category') . '</dt>'; } } } } $out .= '</dl>'; } else { if (count($reorganizedUserCourseList) > 0) { $out .= '<dl class="courseList">'; foreach ($reorganizedUserCourseList as $course) { $displayIconAccess = $course['isCourseManager'] || claro_is_platform_admin() ? true : false; $out .= render_course_in_dl_list($course, $course['hot'], $displayIconAccess); } $out .= '</dl>' . "\n"; } } return $out; }
/** * Add a platform access event to the tracking system * @param Event $event * @return boolean */ public function trackPlatformAccess($event) { // tool_id will be recorded too if user enters via a tool directly if (!get_conf('is_trackingEnabled')) { return false; } // count access only if user was not already on the platform if (!isset($_SESSION['tracking']['platformAccessed'])) { // we don't have a trace saying that user was already on the platform // so check its referer if (!empty($_SERVER['HTTP_REFERER'])) { if (false === strpos($_SERVER['HTTP_REFERER'], get_path('rootWeb'))) { // http referer is different user probably comes from outside $externalReferer = true; } else { $externalReferer = false; $_SESSION['tracking']['platformAccessed'] = claro_mktime(); } } else { // referer not set so we take the guess that user was not on the platform // and access it directly $externalReferer = true; } if ($externalReferer) { $this->trackInPlatform($event); $_SESSION['tracking']['platformAccessed'] = claro_mktime(); return true; } } return false; }
/** * Get courses datas in data base. * * @param int category identifier (default: null) * @param int identifier of the user * @return array array of courses ordered by label (asc) * @author Antonin Bourguignon <*****@*****.**> * @since 1.10 */ function claro_get_restricted_courses($categoryId, $userId) { $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_rel_course_category = $tbl_mdb_names['rel_course_category']; $tbl_rel_course_user = $tbl_mdb_names['rel_course_user']; $curdate = claro_mktime(); $sql = "SELECT c.cours_id AS id,\n c.titulaires AS titular,\n c.code AS sysCode,\n c.isSourceCourse AS isSourceCourse,\n c.sourceCourseId AS sourceCourseId,\n c.intitule AS title,\n c.administrativeNumber AS officialCode,\n c.dbName AS db,\n c.intitule AS title,\n UNIX_TIMESTAMP(c.expirationDate) AS expirationDate,\n UNIX_TIMESTAMP(c.creationDate) AS creationDate,\n c.language,\n c.directory,\n c.visibility,\n c.access,\n c.registration,\n c.email,\n c.status,\n c.userLimit"; if (!is_null($categoryId)) { $sql .= ",\n rcc.categoryId AS categoryId,\n rcc.rootCourse AS rootCourse"; } if (!is_null($userId)) { $sql .= ",\n rcu.isCourseManager,\n rcu.isPending,\n rcu.user_id AS enroled"; } $sql .= "\n FROM `" . $tbl_course . "` AS c"; if (!is_null($userId)) { $sql .= "\n \n LEFT JOIN `" . $tbl_rel_course_user . "` AS rcu\n ON c.code = rcu.code_cours AND rcu.user_id = " . (int) $userId; } if (!is_null($categoryId)) { $sql .= "\n \n LEFT JOIN `" . $tbl_rel_course_category . "` AS rcc\n ON c.cours_id = rcc.courseId"; } $sql .= "\n \n WHERE visibility = 'visible' "; if (!is_null($categoryId)) { $sql .= "\n AND rcc.rootCourse != 1"; } // User logged can't see source courses if (!is_null($userId)) { $sql .= "\n AND (isSourceCourse = 0 OR rcu.isCourseManager = 1)"; } else { $sql .= "\n AND sourceCourseId IS NULL"; } $sql .= "\n AND (\n (c.status = 'enable'\n OR (c.status = 'date'\n AND (UNIX_TIMESTAMP(c.creationDate) < '" . $curdate . "'\n OR c.creationDate IS NULL OR UNIX_TIMESTAMP(c.creationDate) = 0)\n AND ('" . $curdate . "' < UNIX_TIMESTAMP(c.expirationDate) OR c.expirationDate IS NULL)\n )\n )"; if (!is_null($userId)) { $sql .= "\n OR NOT (rcu.user_id IS NULL)"; } $sql .= "\n )"; if (!is_null($categoryId)) { $sql .= "\n AND ( rcc.categoryId = " . (int) $categoryId . ")"; } if (!get_conf('userCourseListGroupByCategories')) { $sql .= " GROUP BY c.code"; } if (get_conf('course_order_by') == 'official_code') { $sql .= " ORDER BY UPPER(c.`administrativeNumber`), c.`intitule`"; } else { $sql .= " ORDER BY c.`intitule`, UPPER(c.`administrativeNumber`)"; } return claro_sql_query_fetch_all($sql); }