public function renderContent() { $output = ''; $course = claro_get_current_course_data(); $course['db'] = $course['dbName']; $toolId = get_tool_id_from_module_label('CLANN'); if (is_module_installed_in_course('CLANN', claro_get_current_course_id()) && is_tool_activated_in_course($toolId, claro_get_current_course_id()) && claro_is_tool_visible($toolId, claro_get_current_course_id())) { $announcementList = announcement_get_course_item_list_portlet($course); // Manage announcement's datas if ($announcementList) { $output .= '<dl id="portletAnnouncements">' . "\n"; $i = 0; foreach ($announcementList as $announcementItem) { // Generate announcement URL $announcementItem['url'] = get_path('url') . '/claroline/announcements/announcements.php?cidReq=' . $course['sysCode']; // Generate announcement title and content $announcementItem['title'] = trim(strip_tags($announcementItem['title'])); if ($announcementItem['title'] == '') { $announcementItem['title'] = substr($announcementItem['title'], 0, 60) . (strlen($announcementItem['title']) > 60 ? ' (...)' : ''); } $announcementItem['content'] = trim(strip_tags($announcementItem['content'])); if ($announcementItem['content'] == '') { $announcementItem['content'] = substr($announcementItem['content'], 0, 60) . (strlen($announcementItem['content']) > 60 ? ' (...)' : ''); } // Don't display hidden and expired elements $isVisible = (bool) ($announcementItem['visibility'] == 'SHOW') ? 1 : 0; $isOffDeadline = (bool) (isset($announcementItem['visibleFrom']) && strtotime($announcementItem['visibleFrom']) > time() || isset($announcementItem['visibleUntil']) && time() >= strtotime($announcementItem['visibleUntil'])) ? 1 : 0; // Prepare the render $displayChar = 250; if (strlen($announcementItem['content']) > $displayChar) { $content = substr($announcementItem['content'], 0, $displayChar) . '... <a href="' . claro_htmlspecialchars(Url::Contextualize($announcementItem['url'])) . '">' . '<b>' . get_lang('Read more »') . '</b></a>'; } else { $content = $announcementItem['content']; } if ($isVisible && !$isOffDeadline) { $output .= '<dt>' . "\n" . '<h2> ' . '<a href="' . $announcementItem['url'] . '#item' . $announcementItem['id'] . '">' . (!empty($announcementItem['title']) ? $announcementItem['title'] : get_lang('No title')) . '</a></h2>' . "\n" . '</dt>' . "\n" . '<dd' . ($i == count($announcementList) - 1 ? ' class="last"' : '') . '>' . "\n" . $content . "\n" . (claro_is_allowed_to_edit() ? '<div class="manageTools"><a href="' . claro_htmlspecialchars(Url::Contextualize(get_module_url('CLANN') . '/announcements.php?cmd=rqEdit&id=' . $announcementItem['id'])) . '" title="' . get_lang('Edit this item') . '"> <img src="' . get_icon_url('edit') . '" alt="' . get_lang('Edit') . '" /> </a> <a href="' . claro_htmlspecialchars(Url::Contextualize(get_module_url('CLANN') . '/announcements.php?cmd=exDelete&id=' . $announcementItem['id'])) . '" title="' . get_lang('Delete this item') . '"> <img src="' . get_icon_url('delete') . '" alt="' . get_lang('Delete') . '" /> </a></div>' : '') . '</dd>' . "\n"; } $i++; } $output .= '</dl>'; } else { $output .= "\n" . '<dl>' . "\n" . '<dt></dt>' . "\n" . '<dd class="last">' . ' ' . get_lang('No announcement') . "\n" . '</dd>' . "\n" . '</dl>' . "\n\n"; } } return $output; }
/** * build the rss file and place it in directory * * @param array $context context of claroline * @param string $calType : ics,xcs,rdf * @return string ical file path */ function buildICal($context, $calType = 'ics') { if (is_array($context) && count($context) > 0) { $iCalRepositorySys = get_path('rootSys') . get_conf('iCalRepositoryCache', 'tmp/cache/iCal/'); if (!file_exists($iCalRepositorySys)) { require_once dirname(__FILE__) . '/fileManage.lib.php'; claro_mkdir($iCalRepositorySys, CLARO_FILE_PERMISSIONS, true); if (!file_exists($iCalRepositorySys)) { claro_failure::set_failure('CANT_CREATE_ICAL_DIR'); } } $iCal = (object) new iCal('', 0, $iCalRepositorySys); // (ProgrammID, Method (1 = Publish | 0 = Request), Download Directory) $toolLabelList = ical_get_tool_compatible_list(); foreach ($toolLabelList as $toolLabel) { if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) { if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) { install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]); } $icalToolLibPath = get_module_path($toolLabel) . '/connector/ical.write.cnr.php'; $icalToolFuncName = $toolLabel . '_write_ical'; if (file_exists($icalToolLibPath)) { require_once $icalToolLibPath; if (function_exists($icalToolFuncName)) { $iCal = call_user_func($icalToolFuncName, $iCal, $context); } } } } $iCalFilePath = $iCalRepositorySys; if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) { $iCalFilePath .= $context[CLARO_CONTEXT_COURSE] . '.'; } if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) { $iCalFilePath .= 'g' . $context[CLARO_CONTEXT_GROUP] . '.'; } if ('ics' == $calType || get_conf('iCalGenStandard', true)) { $stdICalFilePath = $iCalFilePath . 'ics'; if (false !== ($fpICal = @fopen($stdICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('ics')); fclose($fpICal); } } if ('xcs' == $calType || get_conf('iCalGenXml', true)) { $xmlICalFilePath = $iCalFilePath . 'xml'; if (false !== ($fpICal = @fopen($xmlICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('xcs')); fclose($fpICal); } } if ('rdf' == $calType || get_conf('iCalGenRdf', false)) { $rdfICalFilePath = $iCalFilePath . 'rdf'; if (false !== ($fpICal = @fopen($rdfICalFilePath, 'w'))) { fwrite($fpICal, $iCal->getOutput('rdf')); fclose($fpICal); } } switch ($calType) { case 'xcs': return $xmlICalFilePath; break; case 'rdf': return $rdfICalFilePath; break; default: return $stdICalFilePath; break; } } return false; }
/** * Create a new group * * @param string $groupName - name of the group * @param integer $maxMember - max user allowed for this group * @return integer : id of the new group * * @copyright (c) 2001-2011, Universite catholique de Louvain (UCL) */ function create_group($prefixGroupName, $maxMember) { require_once dirname(__FILE__) . '/forum.lib.php'; require_once dirname(__FILE__) . '/fileManage.lib.php'; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_groups = $tbl_cdb_names['group_team']; // Check name of group $sql = "SELECT name FROM `" . $tbl_groups . "` WHERE name LIKE '" . claro_sql_escape($prefixGroupName) . "%'"; $existingGroupList = claro_sql_query_fetch_all_cols($sql); $existingGroupList = $existingGroupList['name']; $i = 1; do { $groupName = $prefixGroupName . str_pad($i, 4, ' ', STR_PAD_LEFT); $i++; if ($i - 2 > count($existingGroupList)) { die($groupName . 'infiniteloop'); } } while (in_array($groupName, $existingGroupList)); /** * Create a directory allowing group student to upload documents */ // Create a Unique ID path preventing other enter $globalPath = $GLOBALS['coursesRepositorySys'] . $GLOBALS['currentCourseRepository'] . '/group/'; do { $groupRepository = str_replace(' ', '_', substr(uniqid(substr($groupName, 0, 19) . ' ', ''), 0, 30)); } while (check_name_exist($globalPath . $groupRepository)); claro_mkdir($globalPath . $groupRepository, CLARO_FILE_PERMISSIONS); /* * Insert a new group in the course group table and keep its ID */ $sql = "INSERT INTO `" . $tbl_groups . "`\n SET name = '" . $groupName . "',\n `maxStudent` = " . (is_null($maxMember) ? 'NULL' : "'" . (int) $maxMember . "'") . ",\n secretDirectory = '" . claro_sql_escape($groupRepository) . "'"; $createdGroupId = claro_sql_query_insert_id($sql); /* * Create a forum for the group in the forum table */ if (is_tool_activated_in_course(get_tool_id_from_module_label('CLFRM'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLFRM')) { create_forum($groupName . ' - ' . strtolower(get_lang('Forum')), '', 2, (int) GROUP_FORUMS_CATEGORY, '', $createdGroupId); } if (is_tool_activated_in_course(get_tool_id_from_module_label('CLWIKI'), claro_get_current_course_id()) && is_tool_activated_in_groups(claro_get_current_course_id(), 'CLWIKI')) { require_once get_module_path('CLWIKI') . '/lib/lib.createwiki.php'; create_wiki($createdGroupId, $groupName . ' - Wiki'); } return $createdGroupId; }
/** * delete a list of user id from a list of courses * @param array $userIdList list of user id to remove * @param array|string $courseCodeList array of course codes or one single course code * @param bool $force forece the deletion * @param bool $delTrackData delete tracking data * @param bool $unregister_by_class unregister by class * @return int number of deleted users */ function user_remove_userlist_from_course($userIdList, $courseCodeList = array(), $force = false, $delTrackData = false, $unregister_by_class = false) { $tbl = claro_sql_get_main_tbl(); $userDeletedCount = 0; if (!is_array($courseCodeList)) { $courseCodeList = array($courseCodeList); } foreach ($userIdList as $userIdToProcess) { $userId = is_numeric($userIdToProcess) ? $userIdToProcess : $userIdToProcess['user_id']; if (!$force && $userId == $GLOBALS['_uid']) { // PREVIOUSLY CHECK THE USER IS NOT COURSE ADMIN OF THESE COURSES $sql = "SELECT COUNT(user_id)\n FROM `" . $tbl['rel_course_user'] . "`\n WHERE user_id = " . (int) $userId . "\n AND isCourseManager = 1\n AND code_cours IN ('" . implode("', '", array_map('claro_sql_escape', $courseCodeList)) . "') "; if (claro_sql_query_get_single_value($sql) > 0) { Claroline::getInstance()->log('DELETE_USER_FAILED', array('USER' => $userId, 'failure' => 'course_manager_cannot_unsubscribe_himself')); continue; } } $sql = "SELECT code_cours , count_user_enrol, count_class_enrol\n FROM `" . $tbl['rel_course_user'] . "`\n WHERE `code_cours` IN ('" . implode("', '", array_map('claro_sql_escape', $courseCodeList)) . "')\n AND `user_id` = " . $userId; $userEnrolCourseList = claro_sql_query_fetch_all($sql); foreach ($userEnrolCourseList as $thisUserEnrolCourse) { $thisCourseCode = $thisUserEnrolCourse['code_cours']; $count_user_enrol = $thisUserEnrolCourse['count_user_enrol']; $count_class_enrol = $thisUserEnrolCourse['count_class_enrol']; if ($count_user_enrol + $count_class_enrol <= 1) { // remove user from course if (user_remove_from_group($userId, $thisCourseCode) == false) { return false; } $dbNameGlued = claro_get_course_db_name_glued($thisCourseCode); $tbl_cdb_names = claro_sql_get_course_tbl($dbNameGlued); $tbl_bb_notify = $tbl_cdb_names['bb_rel_topic_userstonotify']; $tbl_group_team = $tbl_cdb_names['group_team']; $tbl_userinfo_content = $tbl_cdb_names['userinfo_content']; $sqlList = array(); $toolCLFRM = get_module_data('CLFRM'); if (is_tool_activated_in_course($toolCLFRM['id'], $thisUserEnrolCourse['code_cours'])) { $sqlList = array("DELETE FROM `" . $tbl_bb_notify . "` WHERE user_id = " . (int) $userId); } array_push($sqlList, "DELETE FROM `" . $tbl_userinfo_content . "` WHERE user_id = " . (int) $userId, "UPDATE `" . $tbl_group_team . "` SET `tutor` = NULL WHERE `tutor`='" . (int) $userId . "'"); foreach ($sqlList as $thisSql) { if (claro_sql_query($thisSql) == false) { continue; } } if ($delTrackData) { if (user_delete_course_tracking_data($userId, $thisCourseCode) == false) { continue; } } $sql = "DELETE FROM `" . $tbl['rel_course_user'] . "`\n WHERE user_id = " . (int) $userId . "\n AND code_cours = '" . claro_sql_escape($thisCourseCode) . "'"; if (claro_sql_query($sql) == false) { continue; } } else { // decrement the count of registration by the user or class if (!$unregister_by_class) { $count_user_enrol--; } else { $count_class_enrol--; } // update enrol count in table rel_course_user $sql = "UPDATE `" . $tbl['rel_course_user'] . "`\n SET `count_user_enrol` = '" . $count_user_enrol . "',\n `count_class_enrol` = '" . $count_class_enrol . "'\n WHERE `user_id` = " . (int) $userId . "\n AND `code_cours` = '" . claro_sql_escape($thisCourseCode) . "'"; if (!claro_sql_query($sql)) { continue; } } } $userDeletedCount++; } return $userDeletedCount; }
Upgrade 1.9 to 1.10 ---------------------------------------------------------------------*/ if (preg_match('/^1.9/', $currentCourseVersion)) { // Function to upgrade tool to 1.10 $function_list = array(); $toolCLANN = get_module_data('CLANN'); if (is_tool_activated_in_course($toolCLANN['id'], $currentCourseCode)) { $function_list[] = 'announcements_upgrade_to_110'; } $toolCLCAL = get_module_data('CLCAL'); if (is_tool_activated_in_course($toolCLCAL['id'], $currentCourseCode)) { $function_list[] = 'calendar_upgrade_to_110'; } $function_list[] = 'tool_intro_upgrade_to_110'; $toolCLQWZ = get_module_data('CLQWZ'); if (is_tool_activated_in_course($toolCLQWZ['id'], $currentCourseCode)) { $function_list[] = 'exercise_upgrade_to_110'; } foreach ($function_list as $function) { $step = $function($currentCourseCode); if ($step > 0) { echo 'Error : ' . $function . ' at step ' . $step . '<br />'; $error = true; } } if (!$error) { // Upgrade succeeded clean_upgrade_status($currentCourseCode); $currentCourseVersion = '1.10'; } else { // Upgrade failed
*/ if (is_tool_activated_in_course(get_tool_id_from_module_label('CLANN'), $thisCourse['sysCode'])) { $tableAnn = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'announcement'; $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 CONCAT(`title`,' - ',`contenu`) AS `content`\n \n FROM `" . $tableAnn . "`\n WHERE CONCAT(`title`, `contenu`) != ''\n AND DATE_FORMAT( `temps`, '%Y %m %d') >= '" . date('Y m d', claro_get_current_user_data('lastLogin')) . "'\n AND visibility = 'SHOW'\n ORDER BY `date` DESC\n LIMIT 1"; $resultList = claro_sql_query_fetch_all_cols($sql); foreach ($resultList as $colName => $colValue) { if (count($colValue) == 0) { break; } $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue); } } /* * AGENDA : get the next agenda entries of this course from now */ if (is_tool_activated_in_course(get_tool_id_from_module_label('CLCAL'), $thisCourse['sysCode'])) { $tableCal = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'calendar_event'; $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`,\n '" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`,\n 'CLCAL' AS `toolLabel`,\n CONCAT(`day`, ' ',`hour`) AS `date`,\n CONCAT(`titre`,' - ',`contenu`) AS `content`\n FROM `" . $tableCal . "`\n \n WHERE CONCAT(`day`, ' ',`hour`) >= CURDATE()\n AND CONCAT(`titre`, `contenu`) != ''\n AND visibility = 'SHOW'\n \n ORDER BY `date`\n LIMIT 1"; $resultList = claro_sql_query_fetch_all_cols($sql); foreach ($resultList as $colName => $colValue) { if (count($colValue) == 0) { break; } $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue); } } } // end foreach($personnalCourseList as $thisCourse) /* * Sort all these digest by date */
function build_rss($context) { if (is_array($context) && count($context) > 0) { $rss = new UniversalFeedCreator(); if (array_key_exists(CLARO_CONTEXT_COURSE, $context)) { // $rssFilePath .= $context[CLARO_CONTEXT_COURSE] . '.'; $_course = claro_get_course_data($context[CLARO_CONTEXT_COURSE]); $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode']; $rss->description = $_course['name']; $rss->editor = $_course['titular'] == '' ? get_conf('administrator_name') : $_course['titular']; $rss->editorEmail = $_course['email'] == '' ? get_conf('administrator_email') : $_course['email']; $rss->link = get_path('rootWeb') . get_path('coursesRepositoryAppend') . claro_get_course_path(); $rss->generator = 'Feedcreator'; if (array_key_exists(CLARO_CONTEXT_GROUP, $context)) { // $rssFilePath .= 'g'.$context[CLARO_CONTEXT_GROUP] . '.'; $rss->title .= '[' . get_lang('Group') . $context[CLARO_CONTEXT_GROUP] . ']'; $rss->description .= get_lang('Group') . $context[CLARO_CONTEXT_GROUP]; } } else { $rss->title = '[' . get_conf('siteName') . '] ' . $_course['officialCode']; $rss->description = $_course['name']; $rss->editor = get_conf('administrator_name'); $rss->editorEmail = get_conf('administrator_email'); $rss->link = get_path('rootWeb'); } $rss->language = get_locale('iso639_1_code'); $rss->docs = 'http://blogs.law.harvard.edu/tech/rss'; $rss->pubDate = date("r", time()); $toolLabelList = rss_get_tool_compatible_list(); //var_dump($toolLabelList); $rssItems = array(); foreach ($toolLabelList as $toolLabel) { /*var_dump(is_tool_activated_in_course( get_tool_id_from_module_label( $toolLabel ), $context[CLARO_CONTEXT_COURSE] ));*/ if (is_tool_activated_in_course(get_tool_id_from_module_label($toolLabel), $context[CLARO_CONTEXT_COURSE])) { if (!is_module_installed_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE])) { install_module_in_course($toolLabel, $context[CLARO_CONTEXT_COURSE]); } $rssToolLibPath = get_module_path($toolLabel) . '/connector/rss.write.cnr.php'; $rssToolFuncName = $toolLabel . '_write_rss'; if (file_exists($rssToolLibPath)) { include_once $rssToolLibPath; if (function_exists($rssToolFuncName)) { $rssItems = array_merge($rssItems, call_user_func($rssToolFuncName, $context)); } } } } $sortDate = array(); foreach ($rssItems as $key => $rssItem) { $sortDate[$key] = $rssItem['pubDate']; } // die(var_export($sortDate, true)); array_multisort($sortDate, SORT_DESC, $rssItems); foreach ($rssItems as $rssItem) { $item = new FeedItem(); $item->title = claro_utf8_encode($rssItem['title'], get_conf('charset')); $item->description = claro_utf8_encode($rssItem['description']); $item->category = $rssItem['category']; $item->guid = $rssItem['guid']; $item->link = $rssItem['link']; $item->date = $rssItem['pubDate']; $rss->addItem($item); } return $rss->outputFeed("RSS2.0"); } return false; }