api_not_allowed(true); } if ($debug > 0) { error_log('New LP - export action triggered', 0); } if (!$lp_found) { error_log('New LP - No learnpath given for export', 0); require 'lp_list.php'; } else { $_SESSION['oLP']->scorm_export(); exit; //require 'lp_list.php'; } break; case 'export_to_pdf': if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) { api_not_allowed(); } if ($debug > 0) { error_log('New LP - export action triggered', 0); } if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php'; } else { $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']); if (!$result) { require 'lp_list.php'; } exit; }
<?php /* For licensing terms, see /license.txt */ /** * * @package chamilo.learnpath */ require_once '../inc/global.inc.php'; $_SESSION['whereami'] = 'lp/impress'; $this_section = SECTION_COURSES; //To prevent the template class $show_learnpath = true; api_protect_course_script(); $lp_id = intval($_GET['lp_id']); // Check if the learning path is visible for student - (LP requisites) if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) { api_not_allowed(); } //Checking visibility (eye icon) $visibility = api_get_item_visibility(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id(), api_get_session_id()); if (!api_is_allowed_to_edit(null, true) && intval($visibility) == 0) { api_not_allowed(); } if (empty($_SESSION['oLP'])) { api_not_allowed(true); } $debug = 0; if ($debug) { error_log('------ Entering lp_impress.php -------'); } $course_code = api_get_course_id();
session_cache_limiter('none'); require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; // Protection api_protect_course_script(); if (!isset($_course)) { api_not_allowed(true); } // If LP obj exists if (isset($_SESSION['oLP'])) { $obj = $_SESSION['oLP']; } else { api_not_allowed(); } //If is visible for the current user if (!learnpath::is_lp_visible_for_student($obj->get_id(), api_get_user_id())) { api_not_allowed(); } $doc_url = isset($_GET['doc_url']) ? $_GET['doc_url'] : null; // Change the '&' that got rewritten to '///' by mod_rewrite back to '&' $doc_url = str_replace('///', '&', $doc_url); // Still a space present? it must be a '+' (that got replaced by mod_rewrite) $doc_url = str_replace(' ', '+', $doc_url); $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url; if (strpos($doc_url, '../') or strpos($doc_url, '/..')) { $doc_url = ''; } $sys_course_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/scorm'; //var_dump($sys_course_path); if (is_dir($sys_course_path . $doc_url)) {
/** * Checks if the exercise is visible due a lot of conditions - visibility, time limits, student attempts * @return bool true if is active */ public function is_visible($lp_id = 0, $lp_item_id = 0, $lp_item_view_id = 0, $filter_by_admin = true) { // 1. By default the exercise is visible $is_visible = true; $message = null; // 1.1 Admins and teachers can access to the exercise if ($filter_by_admin) { if (api_is_platform_admin() || api_is_course_admin()) { return array('value' => true, 'message' => ''); } } // Deleted exercise. if ($this->active == -1) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)); } // Checking visibility in the item_property table. $visibility = api_get_item_visibility(api_get_course_info(), TOOL_QUIZ, $this->id, api_get_session_id()); if ($visibility == 0 || $visibility == 2) { $this->active = 0; } // 2. If the exercise is not active. if (empty($lp_id)) { // 2.1 LP is OFF if ($this->active == 0) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)); } } else { // 2.1 LP is loaded if ($this->active == 0 && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)); } } //3. We check if the time limits are on $limit_time_exists = !empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00' || !empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00' ? true : false; if ($limit_time_exists) { $time_now = time(); if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') { $is_visible = $time_now - api_strtotime($this->start_time, 'UTC') > 0 ? true : false; } if ($is_visible == false) { $message = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($this->start_time)); } if ($is_visible == true) { if ($this->end_time != '0000-00-00 00:00:00') { $is_visible = (api_strtotime($this->end_time, 'UTC') > $time_now) > 0 ? true : false; if ($is_visible == false) { $message = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($this->end_time)); } } } if ($is_visible == false && $this->start_time != '0000-00-00 00:00:00' && $this->end_time != '0000-00-00 00:00:00') { $message = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($this->start_time), api_convert_and_format_date($this->end_time)); } } // 4. We check if the student have attempts $exerciseAttempts = $this->selectAttempts(); if ($is_visible) { if ($exerciseAttempts > 0) { $attempt_count = Event::get_attempt_count_not_finished(api_get_user_id(), $this->id, $lp_id, $lp_item_id, $lp_item_view_id); if ($attempt_count >= $exerciseAttempts) { $message = sprintf(get_lang('ReachedMaxAttempts'), $this->name, $exerciseAttempts); $is_visible = false; } } } if (!empty($message)) { $message = Display::return_message($message, 'warning', false); } return array('value' => $is_visible, 'message' => $message); }
/** * Returns the "what's new" icon notifications * * The general logic of this function is to track the last time the user * entered the course and compare to what has changed inside this course * since then, based on the item_property table inside this course. Note that, * if the user never entered the course before, he will not see notification * icons. This function takes session ID into account (if any) and only shows * the corresponding notifications. * @param array Course information array, containing at least elements 'db' and 'k' * @return string The HTML link to be shown next to the course */ public static function show_notification($course_info) { $t_track_e_access = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_code = Database::escape_string($course_info['code']); $user_id = api_get_user_id(); $course_id = $course_info['real_id']; $course_info['id_session'] = intval($course_info['id_session']); // Get the user's last access dates to all tools of this course $sql = "SELECT *\n FROM {$t_track_e_access} USE INDEX (access_cours_code, access_user_id)\n WHERE\n access_cours_code = '" . $course_code . "' AND\n access_user_id = '{$user_id}' AND\n access_session_id ='" . $course_info['id_session'] . "'"; $resLastTrackInCourse = Database::query($sql); $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00'; while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) { $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date']; if ($oldestTrackDate > $lastTrackInCourse['access_date']) { $oldestTrackDate = $lastTrackInCourse['access_date']; } } if ($oldestTrackDate == $oldestTrackDateOrig) { //if there was no connexion to the course ever, then take the // course creation date as a reference $course_table = Database::get_main_table(TABLE_MAIN_COURSE); $sql = "SELECT course.creation_date " . "FROM {$course_table} course " . "WHERE course.code = '" . $course_code . "'"; $res = Database::query($sql); if ($res && Database::num_rows($res) > 0) { $row = Database::fetch_array($res); } $oldestTrackDate = $row['creation_date']; } // Get the last edits of all tools of this course. $sql = "SELECT\n tet.*,\n tet.lastedit_date last_date,\n tet.tool tool,\n tet.ref ref,\n tet.lastedit_type type,\n tet.to_group_id group_id,\n ctt.image image,\n ctt.link link\n FROM {$tool_edit_table} tet, {$course_tool_table} ctt\n WHERE\n tet.c_id = {$course_id} AND\n ctt.c_id = {$course_id} AND\n tet.lastedit_date > '{$oldestTrackDate}' " . " AND (ctt.name = tet.tool OR (ctt.name = 'student_publication' AND tet.tool = 'work')) " . " AND ctt.visibility = '1' " . " AND tet.lastedit_user_id != {$user_id} AND tet.id_session = '" . $course_info['id_session'] . "'\n ORDER BY tet.lastedit_date"; $res = Database::query($sql); // Get the group_id's with user membership. $group_ids = GroupManager::get_group_ids($course_info['real_id'], $user_id); $group_ids[] = 0; //add group 'everyone' $notifications = array(); // Filter all last edits of all tools of the course while ($res && ($item_property = Database::fetch_array($res))) { // First thing to check is if the user never entered the tool // or if his last visit was earlier than the last modification. if ((!isset($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) && (in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_DROPBOX && $item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)) && ($item_property['visibility'] == '1' || $course_info['status'] == '1' && $item_property['visibility'] == '0' || !isset($item_property['visibility']))) { if ($course_info['real_id'] == 1) { // var_dump($item_property); } // Also drop announcements and events that are not for the user or his group. if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && ($item_property['to_user_id'] != $user_id && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) { continue; } // If it's a survey, make sure the user's invited. Otherwise drop it. if ($item_property['tool'] == TOOL_SURVEY) { $survey_info = survey_manager::get_survey($item_property['ref'], 0, $course_code); if (!empty($survey_info)) { $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code); if (!in_array($user_id, $invited_users['course_users'])) { continue; } } } // If it's a learning path, ensure it is currently visible to the user if ($item_property['tool'] == TOOL_LEARNPATH) { require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php'; if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) { continue; } } if ($item_property['tool'] == 'work' && $item_property['type'] == 'DirectoryCreated') { $item_property['lastedit_type'] = 'WorkAdded'; } $notifications[$item_property['tool']] = $item_property; } } // Show all tool icons where there is something new. $retvalue = ' '; while (list($key, $notification) = each($notifications)) { $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date'])); $type = $notification['lastedit_type']; if (empty($course_info['id_session'])) { $my_course['id_session'] = 0; } else { $my_course['id_session'] = $course_info['id_session']; } $label = get_lang('TitleNotification') . ": " . get_lang($type) . " ({$lastDate})"; $retvalue .= '<a href="' . api_get_path(WEB_CODE_PATH) . $notification['link'] . '?cidReq=' . $course_code . '&ref=' . $notification['ref'] . '&gidReq=' . $notification['to_group_id'] . '&id_session=' . $my_course['id_session'] . '">' . Display::return_icon($notification['image'], $label) . '</a> '; } return $retvalue; }
$doc_url = str_replace(' ', '+', $doc_url); $doc_url = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), $doc_url); //echo $doc_url; if (strpos($doc_url, '../') or strpos($doc_url, '/..')) { $doc_url = ''; } $sys_course_path = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/scorm'; $user_id = api_get_user_id(); /** @var learnpath $learnPath */ $learnPath = Session::read('oLP'); if ($learnPath) { $lp_id = $learnPath->get_id(); $lp_item_id = $learnPath->current; $lp_item_info = new learnpathItem($lp_item_id); if (!empty($lp_item_info)) { //if (basename($lp_item_info->path) == basename($doc_url)) { $visible = learnpath::is_lp_visible_for_student($lp_id, $user_id); if ($visible) { Event::event_download($doc_url); if (Security::check_abs_path($sys_course_path . $doc_url, $sys_course_path . '/')) { $full_file_name = $sys_course_path . $doc_url; DocumentManager::file_send_for_download($full_file_name); exit; } } //} } } Display::display_error_message(get_lang('ProtectedDocument')); //api_not_allowed backbutton won't work. exit;
/** * Displays the tools of a certain category. * @param array $all_tools_list List of tools as returned by get_tools_category() * @param bool $rows * * @return void */ public static function show_tools_category($all_tools_list, $rows = false) { $_user = api_get_user_info(); $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($all_tools_list) && count($all_tools_list) > 0) { foreach ($all_tools_list as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $all_tools_list[$key]; } $all_tools_list = $my_temp_tool_array; } else { $all_tools_list = array(); } } $web_code_path = api_get_path(WEB_CODE_PATH); $session_id = api_get_session_id(); $is_platform_admin = api_is_platform_admin(); if ($session_id == 0) { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin(); } else { $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach(); } $i = 0; $items = array(); $app_plugin = new AppPlugin(); if (isset($all_tools_list)) { $lnk = ''; foreach ($all_tools_list as &$tool) { $item = array(); $studentview = false; $tool['original_link'] = $tool['link']; if ($tool['image'] == 'scormbuilder.gif') { // check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (api_is_allowed_to_edit(null, true)) { $studentview = true; } if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) { continue; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; if ($is_allowed_to_edit) { if (empty($session_id)) { if (isset($tool['id'])) { if ($tool['visibility'] == '1' && $toolAdmin != '1') { $link['name'] = Display::return_icon('visible.png', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'hide=yes'; $lnk[] = $link; } if ($tool['visibility'] == '0' && $toolAdmin != '1') { $link['name'] = Display::return_icon('invisible.png', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false); $link['cmd'] = 'restore=yes'; $lnk[] = $link; } } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($toolAdmin != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . api_get_self() . '?' . api_get_cidreq() . '&id=' . $tool['id'] . '&' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= ''; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if ($tool['visibility'] == '0' && $toolAdmin != '1' && !isset($tool['original_link'])) { $class = 'invisible'; $info = pathinfo($tool['image']); $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); $toolId = isset($tool["id"]) ? $tool["id"] : null; //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->getPluginInfo($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } if (!file_exists(api_get_path(SYS_CODE_PATH) . 'img/' . $tool['image']) && !file_exists(api_get_path(SYS_CODE_PATH) . 'img/icons/22/' . $tool['image'])) { $tool['image'] = 'plugins.png'; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } $icon = Display::return_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); /*if (!empty($tool['custom_icon'])) { $image = self::getCustomWebIconPath().$tool['custom_icon']; $icon = Display::img( $image, $tool['description'], array( 'class' => 'tool-icon', 'id' => 'toolimage_'.$tool['id'] ) ); }*/ // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], !empty($_user['status']) ? $_user['status'] : ''); if ($studentview) { $tool_link_params['href'] .= '&isStudentView=true'; } $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; $i++; } // end of foreach } $i = 0; $html = ''; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; $html .= '<div class="col-xs-6 col-md-3 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null; if (isset($item['tool']['custom_image'])) { $original_image = Display::img($item['tool']['custom_image'], $item['name'], array('id' => 'toolimage_' . $toolId)); } elseif (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) { $customIcon = $item['tool']['custom_icon']; if ($item['tool']['visibility'] == '0') { $fileInfo = pathinfo($item['tool']['custom_icon']); $customIcon = self::getDisableIcon($item['tool']['custom_icon']); } $original_image = Display::img(self::getCustomWebIconPath() . $customIcon, $item['name'], array('id' => 'toolimage_' . $toolId)); } else { $original_image = Display::return_icon($image, $item['name'], array('id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false); } $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; break; case 'activity': $html .= '<div class="offset2 col-md-4 course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</div>'; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return $html; }
/** * Checks if the exercise is visible due a lot of conditions * visibility, time limits, student attempts * Return associative array * value : true if execise visible * message : HTML formated message * rawMessage : text message * @param int $lpId * @param int $lpItemId * @param int $lpItemViewId * @param bool $filterByAdmin * @return array */ public function is_visible($lpId = 0, $lpItemId = 0, $lpItemViewId = 0, $filterByAdmin = true) { // 1. By default the exercise is visible $is_visible = true; $message = null; // 1.1 Admins and teachers can access to the exercise if ($filterByAdmin) { if (api_is_platform_admin() || api_is_course_admin()) { return array('value' => true, 'message' => ''); } } // Deleted exercise. if ($this->active == -1) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false), 'rawMessage' => get_lang('ExerciseNotFound')); } // Checking visibility in the item_property table. $visibility = api_get_item_visibility(api_get_course_info(), TOOL_QUIZ, $this->id, api_get_session_id()); if ($visibility == 0 || $visibility == 2) { $this->active = 0; } // 2. If the exercise is not active. if (empty($lpId)) { // 2.1 LP is OFF if ($this->active == 0) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false), 'rawMessage' => get_lang('ExerciseNotFound')); } } else { // 2.1 LP is loaded if ($this->active == 0 && !learnpath::is_lp_visible_for_student($lpId, api_get_user_id())) { return array('value' => false, 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false), 'rawMessage' => get_lang('ExerciseNotFound')); } } //3. We check if the time limits are on if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00' || !empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00') { $limitTimeExists = true; } else { $limitTimeExists = false; } if ($limitTimeExists) { $timeNow = time(); $existsStartDate = false; $nowIsAfterStartDate = true; $existsEndDate = false; $nowIsBeforeEndDate = true; if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') { $existsStartDate = true; } if (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00') { $existsEndDate = true; } // check if we are before-or-after end-or-start date if ($existsStartDate && $timeNow < api_strtotime($this->start_time, 'UTC')) { $nowIsAfterStartDate = false; } if ($existsEndDate & $timeNow >= api_strtotime($this->end_time, 'UTC')) { $nowIsBeforeEndDate = false; } // lets check all cases if ($existsStartDate && !$existsEndDate) { // exists start date and dont exists end date if ($nowIsAfterStartDate) { // after start date, no end date $isVisible = true; $message = sprintf(get_lang('ExerciseAvailableSinceX'), api_convert_and_format_date($this->start_time)); } else { // before start date, no end date $isVisible = false; $message = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($this->start_time)); } } else { if (!$existsStartDate && $existsEndDate) { // doesnt exist start date, exists end date if ($nowIsBeforeEndDate) { // before end date, no start date $isVisible = true; $message = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($this->end_time)); } else { // after end date, no start date $isVisible = false; $message = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($this->end_time)); } } elseif ($existsStartDate && $existsEndDate) { // exists start date and end date if ($nowIsAfterStartDate) { if ($nowIsBeforeEndDate) { // after start date and before end date $isVisible = true; $message = sprintf(get_lang('ExerciseIsActivatedFromXToY'), api_convert_and_format_date($this->start_time), api_convert_and_format_date($this->end_time)); } else { // after start date and after end date $isVisible = false; $message = sprintf(get_lang('ExerciseWasActivatedFromXToY'), api_convert_and_format_date($this->start_time), api_convert_and_format_date($this->end_time)); } } else { if ($nowIsBeforeEndDate) { // before start date and before end date $isVisible = false; $message = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($this->start_time), api_convert_and_format_date($this->end_time)); } // case before start date and after end date is impossible } } elseif (!$existsStartDate && !$existsEndDate) { // doesnt exist start date nor end date $isVisible = true; $message = ""; } } } // 4. We check if the student have attempts $exerciseAttempts = $this->selectAttempts(); if ($isVisible) { if ($exerciseAttempts > 0) { $attemptCount = Event::get_attempt_count_not_finished(api_get_user_id(), $this->id, $lpId, $lpItemId, $lpItemViewId); if ($attemptCount >= $exerciseAttempts) { $message = sprintf(get_lang('ReachedMaxAttempts'), $this->name, $exerciseAttempts); $isVisible = false; } } } $rawMessage = ""; if (!empty($message)) { $rawMessage = $message; $message = Display::return_message($message, 'warning', false); } return array('value' => $isVisible, 'message' => $message, 'rawMessage' => $rawMessage); }
require_once 'back_compat.inc.php'; require_once 'learnpath.class.php'; require_once 'learnpathItem.class.php'; //To prevent the template class $show_learnpath = true; api_protect_course_script(); $lp_id = intval($_GET['lp_id']); // Check if the learning path is visible for student - (LP requisites) if (!api_is_platform_admin()) { if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id()) ) { api_not_allowed(true); } } // Checking visibility (eye icon) $visibility = api_get_item_visibility( api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id(), api_get_session_id() ); if (!api_is_allowed_to_edit(false, true, false, false) && intval($visibility) == 0) {
/** * Returns the "what's new" icon notifications * * The general logic of this function is to track the last time the user * entered the course and compare to what has changed inside this course * since then, based on the item_property table inside this course. Note that, * if the user never entered the course before, he will not see notification * icons. This function takes session ID into account (if any) and only shows * the corresponding notifications. * @param array Course information array, containing at least elements 'db' and 'k' * @return string The HTML link to be shown next to the course */ public static function show_notification($course_info) { if (empty($course_info)) { return ''; } $t_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); $tool_edit_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_code = Database::escape_string($course_info['code']); $user_id = api_get_user_id(); $course_id = intval($course_info['real_id']); $sessionId = intval($course_info['id_session']); // Get the user's last access dates to all tools of this course $sql = "SELECT *\n FROM {$t_track_e_access}\n WHERE\n c_id = {$course_id} AND\n access_user_id = '{$user_id}' AND\n access_session_id ='" . $sessionId . "'"; $resLastTrackInCourse = Database::query($sql); $oldestTrackDate = $oldestTrackDateOrig = '3000-01-01 00:00:00'; while ($lastTrackInCourse = Database::fetch_array($resLastTrackInCourse)) { $lastTrackInCourseDate[$lastTrackInCourse['access_tool']] = $lastTrackInCourse['access_date']; if ($oldestTrackDate > $lastTrackInCourse['access_date']) { $oldestTrackDate = $lastTrackInCourse['access_date']; } } if ($oldestTrackDate == $oldestTrackDateOrig) { //if there was no connexion to the course ever, then take the // course creation date as a reference $oldestTrackDate = $course_info['creation_date']; } $sessionCondition = api_get_session_condition($sessionId, true, false, 'tet.session_id'); // Get the last edits of all tools of this course. $sql = "SELECT\n tet.*,\n tet.lastedit_date last_date,\n tet.tool tool,\n tet.ref ref,\n tet.lastedit_type type,\n tet.to_group_id group_id,\n ctt.image image,\n ctt.link link\n FROM {$tool_edit_table} tet\n INNER JOIN {$course_tool_table} ctt\n ON tet.c_id = ctt.c_id\n WHERE\n tet.c_id = {$course_id} AND\n tet.lastedit_date > '{$oldestTrackDate}' " . " AND (ctt.name = tet.tool OR (ctt.name = 'student_publication' AND tet.tool = 'work'))\n AND ctt.visibility = '1'\n AND tet.lastedit_user_id != {$user_id} {$sessionCondition}\n ORDER BY tet.lastedit_date"; $res = Database::query($sql); // Get the group_id's with user membership. $group_ids = GroupManager::get_group_ids($course_info['real_id'], $user_id); $group_ids[] = 0; //add group 'everyone' $notifications = array(); // Filter all last edits of all tools of the course while ($res && ($item_property = Database::fetch_array($res, 'ASSOC'))) { // First thing to check is if the user never entered the tool // or if his last visit was earlier than the last modification. if ((!isset($lastTrackInCourseDate[$item_property['tool']]) || $lastTrackInCourseDate[$item_property['tool']] < $item_property['lastedit_date']) && (in_array($item_property['to_group_id'], $group_ids) && ($item_property['tool'] != TOOL_NOTEBOOK && $item_property['tool'] != TOOL_CHAT)) && ($item_property['visibility'] == '1' || $course_info['status'] == '1' && $item_property['visibility'] == '0' || !isset($item_property['visibility']))) { // Also drop announcements and events that are not for the user or his group. if (($item_property['tool'] == TOOL_ANNOUNCEMENT || $item_property['tool'] == TOOL_CALENDAR_EVENT) && ($item_property['to_user_id'] != $user_id && (!isset($item_property['to_group_id']) || !in_array($item_property['to_group_id'], $group_ids)))) { continue; } // If it's a survey, make sure the user's invited. Otherwise drop it. if ($item_property['tool'] == TOOL_SURVEY) { $survey_info = SurveyManager::get_survey($item_property['ref'], 0, $course_code); if (!empty($survey_info)) { $invited_users = SurveyUtil::get_invited_users($survey_info['code'], $course_code); if (!in_array($user_id, $invited_users['course_users'])) { continue; } } } // If it's a learning path, ensure it is currently visible to the user if ($item_property['tool'] == TOOL_LEARNPATH) { if (!learnpath::is_lp_visible_for_student($item_property['ref'], $user_id, $course_code)) { continue; } } if ($item_property['tool'] == TOOL_DROPBOX) { $item_property['link'] = 'dropbox/dropbox_download.php?id=' . $item_property['ref']; } if ($item_property['tool'] == 'work' && $item_property['type'] == 'DirectoryCreated') { $item_property['lastedit_type'] = 'WorkAdded'; } $notifications[$item_property['tool']] = $item_property; } } // Show all tool icons where there is something new. $return = ' '; foreach ($notifications as $notification) { $lastDate = date('d/m/Y H:i', convert_sql_date($notification['lastedit_date'])); $type = $notification['lastedit_type']; $label = get_lang('TitleNotification') . ": " . get_lang($type) . " ({$lastDate})"; if (strpos($notification['link'], '?') === false) { $notification['link'] = $notification['link'] . '?notification=1'; } else { $notification['link'] = $notification['link'] . '¬ification=1'; } $return .= Display::url(Display::return_icon($notification['image'], $label), api_get_path(WEB_CODE_PATH) . $notification['link'] . '&cidReq=' . $course_code . '&ref=' . $notification['ref'] . '&gidReq=' . $notification['to_group_id'] . '&id_session=' . $sessionId) . ' '; } return $return; }
/** * Displays the tools of a certain category. * @param Symfony\Component\Routing\RouterInterface $urlGenerator * @param array List of tools as returned by get_tools_category() * @param bool rows * @return string */ public static function show_tools_category($urlGenerator, $toolList, $rows = false) { $rowDiv = '<div class="row">'; $theme = api_get_setting('homepage_view'); if ($theme == 'vertical_activity') { //ordering by get_lang name $order_tool_list = array(); if (is_array($toolList) && count($toolList) > 0) { foreach ($toolList as $key => $new_tool) { $tool_name = self::translate_tool_name($new_tool); $order_tool_list[$key] = $tool_name; } natsort($order_tool_list); $my_temp_tool_array = array(); foreach ($order_tool_list as $key => $new_tool) { $my_temp_tool_array[] = $toolList[$key]; } $toolList = $my_temp_tool_array; } else { $toolList = array(); } } $courseInfo = api_get_course_info(); $web_code_path = api_get_path(WEB_CODE_PATH); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_platform_admin = api_is_platform_admin(); $session_id = api_get_session_id(); $items = array(); $app_plugin = new AppPlugin(); if (isset($toolList)) { $lnk = ''; foreach ($toolList as &$tool) { $item = array(); $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null; $tool['id'] = isset($tool['id']) ? $tool['id'] : null; $tool['target'] = isset($tool['target']) ? $tool['target'] : null; if (isset($tool['link_id'])) { $tool['original_link'] = api_get_path(WEB_CODE_PATH) . 'link/link_goto.php?link_id=' . $tool['link_id'] . '&' . api_get_cidreq(); $tool['link'] = $tool['original_link']; } else { $tool['original_link'] = $tool['link']; } // Re-writing URL for new tools $newTools = array(TOOL_CURRICULUM); $toolName = isset($tool['name']) ? $tool['name'] : null; if (in_array($toolName, $newTools)) { $tool['link'] = $courseInfo['course_web_public_url'] . $tool['name'] . '/'; } if ($tool['image'] == 'scormbuilder.gif') { // Check if the published learnpath is visible for student $published_lp_id = self::get_published_lp_id_from_link($tool['link']); if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { continue; } } if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) { continue; } if ($tool['name'] == 'course_description') { $tool['link'] = 'course_description/index.php'; } // This part displays the links to hide or remove a tool. // These links are only visible by the course manager. unset($lnk); $item['extra'] = null; if ($is_allowed_to_edit && !api_is_coach()) { if (empty($session_id)) { if ($tool['visibility'] == '1' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:hideIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false); if (!empty($tool['id'])) { $link['cmd'] = $urlGenerator->generate('course_home.controller:showIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id'])); } $lnk[] = $link; } } if (!empty($tool['adminlink'])) { $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>'; } } // Both checks are necessary as is_platform_admin doesn't take student view into account if ($is_platform_admin && $is_allowed_to_edit) { if ($tool['admin'] != '1') { $link['cmd'] = 'hide=yes'; } } $item['visibility'] = null; if (isset($lnk) && is_array($lnk)) { foreach ($lnk as $this_link) { if (empty($tool['adminlink'])) { $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>'; } } } else { $item['visibility'] .= null; } // NOTE : Table contains only the image file name, not full path if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) { $tool['link'] = $web_code_path . $tool['link']; } if (!empty($tool['custom_icon'])) { $tool['image'] = self::getCustomIconPath($courseInfo) . $tool['custom_icon']; } if ($tool['visibility'] == '0' && $tool['admin'] != '1') { $class = 'invisible'; $info = pathinfo($tool['image']); $dirName = null; if ($info['dirname'] != '.') { $dirName = $info['dirname'] . '/'; } $basename = basename($tool['image'], '.' . $info['extension']); // $file is set to "index" $tool['image'] = $dirName . $basename . '_na.' . $info['extension']; } else { $class = ''; } $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; // If it's a link, we don't add the cidReq if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') { $tool['link'] = $tool['link'] . $qm_or_amp; } else { $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq(); } $tool_link_params = array(); //@todo this visio stuff should be removed if (strpos($tool['name'], 'visio_') !== false) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']); } else { if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => '_blank'); } else { $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']); } } $tool_name = self::translate_tool_name($tool); $toolTip = $tool_name; if (!empty($tool['description'])) { $toolTip = $tool['description']; } $tool_link_params['data-original-title'] = $toolTip; $tool_link_params['data-toggle'] = 'tooltip'; //$tool_link_params['title'] = $toolTip; // Including Courses Plugins // Creating title and the link if (isset($tool['category']) && $tool['category'] == 'plugin') { $plugin_info = $app_plugin->get_plugin_info($tool['name']); if (isset($plugin_info) && isset($plugin_info['title'])) { $tool_name = $plugin_info['title']; } $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq(); } if (!empty($tool['custom_icon'])) { //self::getCustomIconPath($courseInfo) $icon = Display::img($tool['image'], null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id'])); } else { $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png'; $icon = Display::return_icon($image, null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']), ICON_SIZE_BIG, false); } $userInfo = api_get_user_info(); $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null; // Validation when belongs to a session $session_img = api_get_session_image($tool['session_id'], $userStatus); $item['url_params'] = $tool_link_params; $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); $item['tool'] = $tool; $item['name'] = $tool_name; $tool_link_params['id'] = 'is' . $tool_link_params['id']; $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params); $items[] = $item; } // end of foreach } $i = 0; $html = ''; $counter = 0; if (!empty($items)) { foreach ($items as $item) { switch ($theme) { case 'activity_big': $data = ''; if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-xs-4 col-md-4 course-tool">'; $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png'; if (!empty($item['tool']['custom_icon'])) { $original_image = Display::img($item['tool']['image'], null, array('id' => 'toolimage_' . $item['tool']['id'])); } else { $original_image = Display::return_icon($image, null, array('id' => 'toolimage_' . $item['tool']['id']), ICON_SIZE_BIG, false); } switch ($image) { case 'scormbuilder.png': if (api_is_allowed_to_edit(null, true)) { $item['url_params']['href'] .= '&isStudentView=true'; } $image = $original_image; $lp_id = self::get_published_lp_id_from_link($item['link']); if ($lp_id) { $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id()); $path = $lp->get_preview_image_path(64); if ($path) { $image = '<img src="' . $path . '">'; } } break; default: $image = $original_image; } $data .= Display::url($image, $item['url_params']['href'], $item['url_params']); $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content')); $html .= '</div>'; if ($counter == 2) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'activity': if ($counter == 0) { $html .= $rowDiv; } $html .= '<div class="col-md-6 course-tool">'; $content = $item['extra']; $content .= $item['visibility']; $content .= $item['icon']; $content .= $item['link']; $html .= Display::div($content, array('class' => 'activity_content')); $html .= '</div>'; if ($counter == 1) { $html .= '</div>'; $counter = -1; } $counter++; break; case 'vertical_activity': if ($i == 0) { $html .= '<ul>'; } $html .= '<li class="course-tool">'; $html .= $item['extra']; $html .= $item['visibility']; $html .= $item['icon']; $html .= $item['link']; $html .= '</li>'; if ($i == count($items) - 1) { $html .= '</ul>'; } break; } $i++; } } return array('content' => $html, 'tool_list' => $items); }
} $counter++; if (($counter % 2) == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $url_start_lp = 'lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$id; $name = Security::remove_XSS($details['lp_name']); $extra = null; if ($is_allowed_to_edit) { $url_start_lp .= '&isStudentView=true'; $studentVisibility = learnpath::is_lp_visible_for_student($id, $userId); $dsp_desc = '<em>'.$details['lp_maker'].'</em> '.( $studentVisibility ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')'); $extra = '<div class ="lp_content_type_label">'.$dsp_desc.'</div>'; } $my_title = $name; $icon_learnpath = Display::return_icon('learnpath.png', get_lang('LPName'), '', ICON_SIZE_SMALL); if ($details['lp_visibility'] == 0) { $my_title = Display::tag('font', $name, array('class' => 'invisible')); $icon_learnpath = Display::return_icon('learnpath_na.png', get_lang('LPName'), '', ICON_SIZE_SMALL); } $dsp_line = '<tr align="center" class="'.$oddclass.'">'. '<td align="left" valign="top">'.$icon_learnpath.' <a href="'.$url_start_lp.'">'.$my_title.'</a>'.$session_img.$extra."</td>";
} if (!empty($details['expired_on'])) { $end_time = api_convert_and_format_date($details['expired_on'], DATE_TIME_FORMAT_LONG); } } $counter++; if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $url_start_lp = 'lp_controller.php?' . api_get_cidreq() . '&action=view&lp_id=' . $id; $name = Security::remove_XSS($details['lp_name']); if ($is_allowed_to_edit) { $url_start_lp .= '&isStudentView=true'; $dsp_desc = '<em>' . $details['lp_maker'] . '</em> ' . (learnpath::is_lp_visible_for_student($id, api_get_user_id()) ? '' : ' - (' . get_lang('LPNotVisibleToStudent') . ')'); $extra = '<div class ="lp_content_type_label">' . $dsp_desc . '</div>'; } /*$image = '<img src="../img/icons/22/learnpath.png" border="0" align="absmiddle" alt="' . $name . '">'; <div style="float: left; width: 35px; height: 22px;"><a href="'.$url_start_lp.'">' . $image . '</a></div>*/ $my_title = $name; if ($details['lp_visibility'] == 0) { $my_title = Display::tag('font', $name, array('style' => 'color:grey')); } $dsp_line = '<tr align="center" class="' . $oddclass . '">' . '<td align="left" valign="top">' . Display::return_icon('learnpath.png', get_lang('LPName'), '', ICON_SIZE_SMALL) . ' <a href="' . $url_start_lp . '">' . $my_title . '</a>' . $session_img . $extra . "</td>"; $dsp_desc = ''; $dsp_export = ''; $dsp_edit = ''; $dsp_build = '';