/** * Class constructor. Based on the parent constructor. * @param string Course code * @param integer Learnpath ID in DB * @param integer User ID */ public function __construct($course_code = null, $resource_id = null, $user_id = null) { if ($this->debug > 0) { error_log('New LP - scorm::scorm(' . $course_code . ',' . $resource_id . ',' . $user_id . ') - In scorm constructor', 0); } parent::__construct($course_code, $resource_id, $user_id); }
/** * Class constructor. Based on the parent constructor. * @param string Course code * @param integer Learnpath ID in DB * @param integer User ID */ public function __construct($course_code = null, $resource_id = null, $user_id = null) { if ($this->debug > 0) { error_log('In aicc::aicc()', 0); } if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) { parent::__construct($course_code, $resource_id, $user_id); } else { //do nothing but still build the aicc object } }
/** * Class constructor. Based on the parent constructor. * @param string $course_code * @param integer $resource_id Learnpath ID in DB * @param integer $user_id */ public function __construct($course_code = null, $resource_id = null, $user_id = null) { if ($this->debug > 0) { error_log('In aicc::aicc()', 0); } if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) { parent::__construct($course_code, $resource_id, $user_id); } }
/** * Class constructor. Based on the parent constructor. * @param string Course code * @param integer Learnpath ID in DB * @param integer User ID */ function __construct($course_code = null, $resource_id = null, $user_id = null) { if ($this->debug > 0) { error_log('New LP - scorm::scorm(' . $course_code . ',' . $resource_id . ',' . $user_id . ') - In scorm constructor', 0); } if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) { parent::__construct($course_code, $resource_id, $user_id); } else { // Do nothing but still build the scorm object. } }
/** * Class constructor. Based on the parent constructor. * @param string Course code * @param integer Learnpath ID in DB * @param integer User ID */ function aicc($course_code = null, $resource_id = null, $user_id = null) { if ($this->debug > 0) { error_log('In aicc::aicc()', 0); } if (!empty($course_code) and !empty($resource_id) and !empty($user_id)) { parent::learnpath($course_code, $resource_id, $user_id); } else { //do nothing but still build the aicc object } }
/** * Writes an item's new values into the database and returns the operation result * @param integer Learnpath ID * @param integer User ID * @param integer View ID * @param integer Item ID * @param array Objectives array */ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array()) { $debug = 0; $return = ''; if ($debug > 0) { error_log('In xajax_save_objectives(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $item_id . ',"' . (count($objectives) > 0 ? count($objectives) : '') . '")', 0); } $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $mylpi =& $mylp->items[$item_id]; if (is_array($objectives) && count($objectives) > 0) { foreach ($objectives as $index => $objective) { $mylpi->add_objective($index, $objectives[$index]); } $mylpi->write_objectives_to_db(); } return $return; }
/** * Writes the current data to the database * @return boolean Query result */ public function write_to_db() { if (self::debug > 0) { error_log('learnpathItem::write_to_db()', 0); } // Check the session visibility. if (!api_is_allowed_to_session_edit()) { if (self::debug > 0) { error_log('return false api_is_allowed_to_session_edit'); } return false; } $course_id = api_get_course_int_id(); $mode = $this->get_lesson_mode(); $credit = $this->get_credit(); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" '; $rs_verified = Database::query($sql); $row_verified = Database::fetch_array($rs_verified); $my_case_completed = array('completed', 'passed', 'browsed', 'failed'); $save = true; if (isset($row_verified) && isset($row_verified['status'])) { if (in_array($row_verified['status'], $my_case_completed)) { $save = false; } } if (($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' || $mode == 'review' || $mode == 'browse')) && ($this->seriousgame_mode != 1 && $this->type == 'sco')) { if (self::debug > 1) { error_log("This info shouldn't be saved as the credit or lesson mode info prevent it"); error_log('learnpathItem::write_to_db() - credit(' . $credit . ') or' . ' lesson_mode(' . $mode . ') prevent recording!', 0); } } else { // Check the row exists. $inserted = false; // This a special case for multiple attempts and Chamilo exercises. if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') { // We force the item to be restarted. $this->restart(); $params = array("c_id" => $course_id, "total_time" => $this->get_total_time(), "start_time" => $this->current_start_time, "score" => $this->get_score(), "status" => $this->get_status(false), "max_score" => $this->get_max(), "lp_item_id" => $this->db_id, "lp_view_id" => $this->view_id, "view_count" => $this->get_attempt_id(), "suspend_data" => $this->current_data, "lesson_location" => $this->lesson_location); if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1), 0); } $this->db_item_view_id = Database::insert($item_view_table, $params); if ($this->db_item_view_id) { $sql = "UPDATE {$item_view_table} SET id = iid\n WHERE iid = " . $this->db_item_view_id; Database::query($sql); $inserted = true; } } $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = "SELECT * FROM {$item_view_table}\n WHERE\n c_id = {$course_id} AND\n lp_item_id = " . $this->db_id . " AND\n lp_view_id = " . $this->view_id . " AND\n view_count = " . intval($this->get_attempt_id()); if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Querying item_view: ' . $sql, 0); } $check_res = Database::query($sql); // Depending on what we want (really), we'll update or insert a new row // now save into DB. if (!$inserted && Database::num_rows($check_res) < 1) { $params = array("c_id" => $course_id, "total_time" => $this->get_total_time(), "start_time" => $this->current_start_time, "score" => $this->get_score(), "status" => $this->get_status(false), "max_score" => $this->get_max(), "lp_item_id" => $this->db_id, "lp_view_id" => $this->view_id, "view_count" => $this->get_attempt_id(), "suspend_data" => $this->current_data, "lesson_location" => $this->lesson_location); if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1), 0); } $this->db_item_view_id = Database::insert($item_view_table, $params); if ($this->db_item_view_id) { $sql = "UPDATE {$item_view_table} SET id = iid\n WHERE iid = " . $this->db_item_view_id; Database::query($sql); } } else { if ($this->type == 'hotpotatoes') { $params = array('total_time' => $this->get_total_time(), 'start_time' => $this->get_current_start_time(), 'score' => $this->get_score(), 'status' => $this->get_status(false), 'max_score' => $this->get_max(), 'suspend_data' => $this->current_data, 'lesson_location' => $this->lesson_location); $where = array('c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' => array($course_id, $this->db_id, $this->view_id, $this->get_attempt_id())); Database::update($item_view_table, $params, $where); } else { // For all other content types... $my_status = ' '; $total_time = ' '; if ($this->type == 'quiz') { if (!empty($_REQUEST['exeId'])) { $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $safe_exe_id = intval($_REQUEST['exeId']); $sql = "SELECT start_date,exe_date\n FROM {$TBL_TRACK_EXERCICES}\n WHERE exe_id = {$safe_exe_id}"; $res = Database::query($sql); $row_dates = Database::fetch_array($res); $time_start_date = convert_sql_date($row_dates['start_date']); $time_exe_date = convert_sql_date($row_dates['exe_date']); $mytime = (int) $time_exe_date - (int) $time_start_date; $total_time = " total_time = " . $mytime . ", "; } } else { $my_type_lp = learnpath::get_type_static($this->lp_id); // This is a array containing values finished $case_completed = array('completed', 'passed', 'browsed', 'failed'); // Is not multiple attempts if ($this->seriousgame_mode == 1 && $this->type == 'sco') { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif ($this->get_prevent_reinit() == 1) { // Process of status verified into data base. $sql = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" '; $rs_verified = Database::query($sql); $row_verified = Database::fetch_array($rs_verified); // Get type lp: 1=lp dokeos and 2=scorm. // If not is completed or passed or browsed and learning path is scorm. if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { // Verified into database. if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { if ($my_type_lp == 3 && $this->type == 'au' || $my_type_lp == 1 && $this->type != 'chapter') { // Is AICC or Chamilo LP $total_time = " total_time = total_time + " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } } } } else { // Multiple attempts are allowed. if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { // Reset zero new attempt ? $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { $total_time = " total_time = " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { // It is chamilo LP. $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } // This code line fixes the problem of wrong status. if ($my_type_lp == 2) { // Verify current status in multiples attempts. $sql = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" '; $rs_status = Database::query($sql); $current_status = Database::result($rs_status, 0, 'status'); if (in_array($current_status, $case_completed)) { $my_status = ''; $total_time = ''; } else { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; } } } } if ($this->type == 'sco') { //IF scorm scorm_update_time has already updated total_time in db //" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it ////" max_time_allowed = '".$this->get_max_time_allowed()."'," . $sql = "UPDATE {$item_view_table} SET\n score = " . $this->get_score() . ",\n {$my_status}\n max_score = '" . $this->get_max() . "',\n suspend_data = '" . Database::escape_string($this->current_data) . "',\n lesson_location = '" . $this->lesson_location . "'\n WHERE\n c_id = {$course_id} AND\n lp_item_id = " . $this->db_id . " AND\n lp_view_id = " . $this->view_id . " AND\n view_count = " . $this->get_attempt_id(); } else { //" max_time_allowed = '".$this->get_max_time_allowed()."'," . $sql = "UPDATE {$item_view_table} SET\n {$total_time}\n start_time = " . $this->get_current_start_time() . ",\n score = " . $this->get_score() . ",\n {$my_status}\n max_score = '" . $this->get_max() . "',\n suspend_data = '" . Database::escape_string($this->current_data) . "',\n lesson_location = '" . $this->lesson_location . "'\n WHERE\n c_id = {$course_id} AND\n lp_item_id = " . $this->db_id . " AND\n lp_view_id = " . $this->view_id . " AND\n view_count = " . $this->get_attempt_id(); } $this->current_start_time = time(); } if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0); } Database::query($sql); } if (is_array($this->interactions) && count($this->interactions) > 0) { // Save interactions. $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = "SELECT id FROM {$tbl}\n WHERE\n c_id = {$course_id} AND\n lp_item_id = " . $this->db_id . " AND\n lp_view_id = " . $this->view_id . " AND\n view_count = " . $this->get_attempt_id(); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $lp_iv_id = $row[0]; if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0); } foreach ($this->interactions as $index => $interaction) { $correct_resp = ''; if (is_array($interaction[4]) && !empty($interaction[4][0])) { foreach ($interaction[4] as $resp) { $correct_resp .= $resp . ','; } $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1); } $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION); //also check for the interaction ID as it must be unique for this SCO view $iva_sql = "SELECT id FROM {$iva_table}\n WHERE\n c_id = {$course_id} AND\n lp_iv_id = {$lp_iv_id} AND\n (\n order_id = {$index} OR\n interaction_id = '" . Database::escape_string($interaction[0]) . "'\n )\n "; $iva_res = Database::query($iva_sql); // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7) if (Database::num_rows($iva_res) > 0) { // Update (or don't). $iva_row = Database::fetch_array($iva_res); $iva_id = $iva_row[0]; // Insert new one. $params = array('interaction_id' => $interaction[0], 'interaction_type' => $interaction[1], 'weighting' => $interaction[3], 'completion_time' => $interaction[2], 'correct_responses' => $correct_resp, 'student_response' => $interaction[5], 'result' => $interaction[6], 'latency' => $interaction[7]); Database::update($iva_table, $params, array('c_id = ? AND id = ?' => array($course_id, $iva_id))); } else { // Insert new one. $params = array('c_id' => $course_id, 'order_id' => $index, 'lp_iv_id' => $lp_iv_id, 'interaction_id' => $interaction[0], 'interaction_type' => $interaction[1], 'weighting' => $interaction[3], 'completion_time' => $interaction[2], 'correct_responses' => $correct_resp, 'student_response' => $interaction[5], 'result' => $interaction[6], 'latency' => $interaction[7]); $insertId = Database::insert($iva_table, $params); if ($insertId) { $sql = "UPDATE {$iva_table} SET id = iid\n WHERE iid = {$insertId}"; Database::query($sql); } } } } } } if (self::debug > 2) { error_log('End of learnpathItem::write_to_db()', 0); } return true; }
/** * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) * This method can be used as abstract and is recursive * @param integer Learnpath ID * @param integer Parent ID of the items to look for * @return mixed Ordered list of item IDs or false on error */ public static function get_flat_ordered_items_list($lp, $parent = 0, $course_id = null) { if (empty($course_id)) { $course_id = api_get_course_int_id(); } else { $course_id = intval($course_id); } $list = array(); if (empty($lp)) { return false; } $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $sql = "SELECT id FROM {$tbl_lp_item} WHERE c_id = {$course_id} AND lp_id = {$lp} AND parent_item_id = {$parent} ORDER BY display_order"; $res = Database::query($sql); while ($row = Database::fetch_array($res)) { $sublist = learnpath::get_flat_ordered_items_list($lp, $row['id'], $course_id); $list[] = $row['id']; foreach ($sublist as $item) { $list[] = $item; } } return $list; }
/** * @param array $course_info * @param bool $lp_id * @param string $target * @param int $session_id * @param bool $add_move_button * @param string $filter_by_folder * @param string $overwrite_url * @param bool $showInvisibleFiles * @param bool $showOnlyFolders * @param int $folderId * @return string */ public static function get_document_preview($course_info, $lp_id = false, $target = '', $session_id = 0, $add_move_button = false, $filter_by_folder = null, $overwrite_url = null, $showInvisibleFiles = false, $showOnlyFolders = false, $folderId = false) { if (empty($course_info['real_id']) || empty($course_info['code']) || !is_array($course_info)) { return ''; } $overwrite_url = Security::remove_XSS($overwrite_url); $user_id = api_get_user_id(); $user_in_course = false; if (api_is_platform_admin()) { $user_in_course = true; } if (!$user_in_course) { if (CourseManager::is_course_teacher($user_id, $course_info['code'])) { $user_in_course = true; } } // Condition for the session $session_id = intval($session_id); if (!$user_in_course) { if (empty($session_id)) { if (CourseManager::is_user_subscribed_in_course($user_id, $course_info['code'])) { $user_in_course = true; } // Check if course is open then we can consider that the student is registered to the course if (isset($course_info) && in_array($course_info['visibility'], array(2, 3))) { $user_in_course = true; } } else { $user_status = SessionManager::get_user_status_in_course_session($user_id, $course_info['real_id'], $session_id); //is true if is an student, course session teacher or coach if (in_array($user_status, array('0', '2', '6'))) { $user_in_course = true; } } } $tbl_doc = Database::get_course_table(TABLE_DOCUMENT); $tbl_item_prop = Database::get_course_table(TABLE_ITEM_PROPERTY); $condition_session = " AND (last.session_id = '{$session_id}' OR last.session_id = '0' OR last.session_id IS NULL)"; $add_folder_filter = null; if (!empty($filter_by_folder)) { $add_folder_filter = " AND docs.path LIKE '" . Database::escape_string($filter_by_folder) . "%'"; } // If we are in LP display hidden folder https://support.chamilo.org/issues/6679 $lp_visibility_condition = null; if ($lp_id) { // $lp_visibility_condition = " OR filetype='folder'"; if ($showInvisibleFiles) { $lp_visibility_condition .= ' OR last.visibility = 0'; } } $showOnlyFoldersCondition = null; if ($showOnlyFolders) { //$showOnlyFoldersCondition = " AND docs.filetype = 'folder' "; } $folderCondition = " AND docs.path LIKE '/%' "; if (!api_is_allowed_to_edit()) { $protectedFolders = self::getProtectedFolderFromStudent(); foreach ($protectedFolders as $folder) { $folderCondition .= " AND docs.path NOT LIKE '{$folder}' "; } } $parentData = []; if ($folderId !== false) { $parentData = self::get_document_data_by_id($folderId, $course_info['code']); if (!empty($parentData)) { $cleanedPath = $parentData['path']; $num = substr_count($cleanedPath, '/'); $notLikeCondition = null; for ($i = 1; $i <= $num; $i++) { $repeat = str_repeat('/%', $i + 1); $notLikeCondition .= " AND docs.path NOT LIKE '" . Database::escape_string($cleanedPath . $repeat) . "' "; } $folderCondition = " AND\n docs.id <> {$folderId} AND\n docs.path LIKE '" . $cleanedPath . "/%'\n {$notLikeCondition}\n "; } else { $folderCondition = " AND\n docs.filetype = 'file' "; } } $levelCondition = null; if ($folderId === false) { $levelCondition = " AND docs.path NOT LIKE'/%/%'"; } $sql = "SELECT last.visibility, docs.*\n FROM {$tbl_item_prop} AS last INNER JOIN {$tbl_doc} AS docs\n ON (docs.id = last.ref AND docs.c_id = last.c_id)\n WHERE\n docs.path NOT LIKE '%_DELETED_%' AND\n last.tool = '" . TOOL_DOCUMENT . "' {$condition_session} AND\n (last.visibility = '1' {$lp_visibility_condition}) AND\n last.visibility <> 2 AND\n docs.c_id = {$course_info['real_id']} AND\n last.c_id = {$course_info['real_id']}\n {$showOnlyFoldersCondition}\n {$folderCondition}\n {$levelCondition}\n {$add_folder_filter}\n ORDER BY docs.filetype DESC, docs.title ASC"; $res_doc = Database::query($sql); $resources = Database::store_result($res_doc, 'ASSOC'); $return = ''; if ($lp_id) { $learnPath = learnpath::getCurrentLpFromSession(); if ($folderId === false) { $return .= '<div class="lp_resource_element">'; $return .= Display::return_icon('new_doc.gif', '', array(), ICON_SIZE_SMALL); $return .= Display::url(get_lang('NewDocument'), api_get_self() . '?' . api_get_cidreq() . '&action=add_item&type=' . TOOL_DOCUMENT . '&lp_id=' . $learnPath->lp_id); $return .= '</div>'; } } else { $return .= Display::div(Display::url(Display::return_icon('close.png', get_lang('Close'), array(), ICON_SIZE_SMALL), ' javascript:void(0);', array('id' => 'close_div_' . $course_info['real_id'] . '_' . $session_id, 'class' => 'close_div')), array('style' => 'position:absolute;right:10px')); } // If you want to debug it, I advise you to do "echo" on the eval statements. $newResources = array(); if (!empty($resources) && $user_in_course) { foreach ($resources as $resource) { $is_visible = self::is_visible_by_id($resource['id'], $course_info, $session_id, api_get_user_id()); if (!$is_visible) { continue; } $newResources[] = $resource; } } $label = get_lang('Documents'); $documents = []; if ($folderId === false) { $documents[$label] = array('id' => 0, 'files' => $newResources); } else { if (!empty($parentData)) { $documents[$parentData['title']] = array('id' => intval($folderId), 'files' => $newResources); } } $write_result = self::write_resources_tree($course_info, $session_id, $documents, $lp_id, $target, $add_move_button, $overwrite_url, $folderId); $return .= $write_result; $img_path = api_get_path(WEB_IMG_PATH); if ($lp_id == false) { $url = api_get_path(WEB_AJAX_PATH) . 'lp.ajax.php?a=get_documents&url=' . $overwrite_url . '&lp_id=' . $lp_id . '&cidReq=' . $course_info['code']; $return .= "<script>\n \$('.doc_folder').click(function() {\n var realId = this.id;\n var my_id = this.id.split('_')[2];\n var tempId = 'temp_'+my_id;\n \$('#res_'+my_id).show();\n\n var tempDiv = \$('#'+realId).find('#'+tempId);\n if (tempDiv.length == 0) {\n \$.ajax({\n async: false,\n type: 'GET',\n url: '" . $url . "',\n data: 'folder_id='+my_id,\n success: function(data) {\n \$('#'+realId).append('<div id='+tempId+'>'+data+'</div>');\n }\n });\n }\n });\n\n \$('.close_div').click(function() {\n var course_id = this.id.split('_')[2];\n var session_id = this.id.split('_')[3];\n \$('#document_result_'+course_id+'_'+session_id).hide();\n \$('.lp_resource').remove();\n \$('.document_preview_container').html('');\n });\n\n </script>"; } else { //For LPs $url = api_get_path(WEB_AJAX_PATH) . 'lp.ajax.php?a=get_documents&lp_id=' . $lp_id . '&' . api_get_cidreq(); $return .= "<script>\n\n function testResources(id, img) {\n var numericId = id.split('_')[1];\n var parentId = 'doc_id_'+numericId;\n var tempId = 'temp_'+numericId;\n var image = \$('#'+img);\n\n if (image.hasClass('open')) {\n image.removeClass('open');\n image.attr('src', '" . $img_path . "nolines_plus.gif');\n \$('#'+id).show();\n \$('#'+tempId).hide();\n } else {\n image.addClass('open');\n image.attr('src', '" . $img_path . "nolines_minus.gif');\n \$('#'+id).hide();\n \$('#'+tempId).show();\n\n var tempDiv = \$('#'+parentId).find('#'+tempId);\n if (tempDiv.length == 0) {\n \$.ajax({\n type: 'GET',\n async: false,\n url: '" . $url . "',\n data: 'folder_id='+numericId,\n success: function(data) {\n tempDiv = \$('#doc_id_'+numericId).append('<div id='+tempId+'>'+data+'</div>');\n }\n });\n }\n }\n }\n </script>"; } if (!$user_in_course) { $return = ''; } return $return; }
$form->addElement('hidden', 'action', 'add_lp_category'); $form->addElement('hidden', 'c_id', api_get_course_int_id()); $form->addElement('hidden', 'id', 0); $form->addButtonSave(get_lang('Save')); if ($form->validate()) { $values = $form->getSubmitValues(); if (!empty($values['id'])) { learnpath::updateCategory($values); $url = api_get_self() . '?action=list&' . api_get_cidreq(); header('Location: ' . $url); exit; } else { learnpath::createCategory($values); $url = api_get_self() . '?action=list&' . api_get_cidreq(); header('Location: ' . $url); exit; } } else { $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; if ($id) { $item = learnpath::getCategory($id); $defaults = array('id' => $item->getId(), 'name' => $item->getName()); $form->setDefaults($defaults); } } Display::display_header(get_lang('LearnpathAddLearnpath'), 'Path'); echo '<div class="actions">'; echo '<a href="lp_controller.php?' . api_get_cidreq() . '">' . Display::return_icon('back.png', get_lang('ReturnToLearningPaths'), '', ICON_SIZE_MEDIUM) . '</a>'; echo '</div>'; $form->display(); Display::display_footer();
$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;
/** * Manages page splitting * @param string Page header * @param string Page body * @return void */ function dealPerPage($header, $body) { $_course = api_get_course_info(); // Split document to pages. $pages = explode('||page_break||', $body); $first_item = 0; foreach ($pages as $key => $page_content) { // For every pages, we create a new file. $key += 1; $page_content = $this->format_page_content($header, $page_content, $this->base_work_dir . $this->created_dir); $html_file = $this->created_dir . '-' . $key . '.html'; $handle = fopen($this->base_work_dir . $this->created_dir . '/' . $html_file, 'w+'); fwrite($handle, $page_content); fclose($handle); $document_id = add_document($_course, $this->created_dir . $html_file, 'file', filesize($this->base_work_dir . $this->created_dir . $html_file), $html_file); $slide_name = ''; if ($document_id) { // Put the document in item_property update. api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $_SESSION['_uid'], 0, 0, null, null, api_get_session_id()); $infos = pathinfo($this->filepath); $slide_name = 'Page ' . str_repeat('0', 2 - strlen($key)) . $key; $previous = learnpath::add_item(0, $previous, 'document', $document_id, $slide_name, ''); if ($this->first_item == 0) { $this->first_item = $previous; } // Code for text indexing. if (isset($_POST['index_document']) && $_POST['index_document']) { //Display::display_normal_message(print_r($_POST)); $di = new ChamiloIndexer(); isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : ($lang = 'english'); $di->connectDb(NULL, NULL, $lang); $ic_slide = new IndexableChunk(); $ic_slide->addValue('title', $slide_name); $specific_fields = get_specific_field_list(); $all_specific_terms = ''; foreach ($specific_fields as $specific_field) { if (isset($_REQUEST[$specific_field['code']])) { $sterms = trim($_REQUEST[$specific_field['code']]); $all_specific_terms .= ' ' . $sterms; if (!empty($sterms)) { $sterms = explode(',', $sterms); foreach ($sterms as $sterm) { $ic_slide->addTerm(trim($sterm), $specific_field['code']); } } } } $page_content = $all_specific_terms . ' ' . $page_content; $ic_slide->addValue('content', $page_content); // Add a comment to say terms separated by commas. $courseid = api_get_course_id(); $ic_slide->addCourseId($courseid); $ic_slide->addToolId(TOOL_LEARNPATH); $lp_id = $this->lp_id; $xapian_data = array(SE_COURSE_ID => $courseid, SE_TOOL_ID => TOOL_LEARNPATH, SE_DATA => array('lp_id' => $lp_id, 'lp_item' => $previous, 'document_id' => $document_id), SE_USER => (int) api_get_user_id()); $ic_slide->xapian_data = serialize($xapian_data); $di->addChunk($ic_slide); // Index and return search engine document id. $did = $di->index(); if ($did) { // Save it to db. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did) VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)'; $sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did); Database::query($sql); } } } } }
<?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();
/** * Writes the current data to the database * @return boolean Query result */ public function write_to_db() { if (self::debug > 0) { error_log('learnpathItem::write_to_db()', 0); } // Check the session visibility. if (!api_is_allowed_to_session_edit()) { if (self::debug > 0) { error_log('return false api_is_allowed_to_session_edit'); } return false; } $course_id = api_get_course_int_id(); $mode = $this->get_lesson_mode(); $credit = $this->get_credit(); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql_verified = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;'; $rs_verified = Database::query($sql_verified); $row_verified = Database::fetch_array($rs_verified); $my_case_completed = array('completed', 'passed', 'browsed', 'failed'); $save = true; if (isset($row_verified) && isset($row_verified['status'])) { if (in_array($row_verified['status'], $my_case_completed)) { $save = false; } } if (($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' or $mode == 'review' or $mode == 'browse')) && ($this->seriousgame_mode != 1 && $this->type == 'sco')) { if (self::debug > 1) { error_log("This info shouldn't be saved as the credit or lesson mode info prevent it"); error_log('learnpathItem::write_to_db() - credit(' . $credit . ') or lesson_mode(' . $mode . ') prevent recording!', 0); } } else { // Check the row exists. $inserted = false; // This a special case for multiple attempts and Chamilo exercises. if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') { // We force the item to be restarted. $this->restart(); $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')"; if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql, 0); } $res = Database::query($sql); $this->db_item_view_id = Database::insert_id(); $inserted = true; } $check_attempts = self::check_attempts($this->get_attempt_id()); if (!$check_attempts) { return false; } $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $check = "SELECT * FROM {$item_view_table}\n WHERE\n c_id = {$course_id} AND\n lp_item_id = " . $this->db_id . " AND\n lp_view_id = " . $this->view_id . " AND\n view_count = " . $this->get_attempt_id(); if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Querying item_view: ' . $check, 0); } $check_res = Database::query($check); // Depending on what we want (really), we'll update or insert a new row // now save into DB. $res = 0; if (!$inserted && Database::num_rows($check_res) < 1) { $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')"; if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view: ' . $sql, 0); } $res = Database::query($sql); $this->db_item_view_id = Database::insert_id(); } else { $sql = ''; if ($this->type == 'hotpotatoes') { $sql = "UPDATE {$item_view_table} " . "SET total_time = " . $this->get_total_time() . ", " . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . " status = '" . $this->get_status(false) . "'," . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id(); } else { // For all other content types... if ($this->type == 'quiz') { $my_status = ' '; $total_time = ' '; if (!empty($_REQUEST['exeId'])) { $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $safe_exe_id = Database::escape_string($_REQUEST['exeId']); $sql = 'SELECT start_date,exe_date FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . (int) $safe_exe_id; $res = Database::query($sql); $row_dates = Database::fetch_array($res); $time_start_date = api_convert_sql_date($row_dates['start_date']); $time_exe_date = api_convert_sql_date($row_dates['exe_date']); $mytime = (int) $time_exe_date - (int) $time_start_date; $total_time = " total_time = " . $mytime . ", "; } } else { $my_type_lp = learnpath::get_type_static($this->lp_id); // This is a array containing values finished $case_completed = array('completed', 'passed', 'browsed', 'failed'); //is not multiple attempts if ($this->seriousgame_mode == 1 && $this->type == 'sco') { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif ($this->get_prevent_reinit() == 1) { // Process of status verified into data base. $sql_verified = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id = "' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;'; $rs_verified = Database::query($sql_verified); $row_verified = Database::fetch_array($rs_verified); // Get type lp: 1=lp dokeos and 2=scorm. // If not is completed or passed or browsed and learning path is scorm. if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { // Verified into data base. if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { //&& !in_array($row_verified['status'], $case_completed) //is lp dokeos if ($my_type_lp == 1 && $this->type != 'chapter') { $total_time = " total_time = total_time + " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } } } } else { // Multiple attempts are allowed. if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { // Reset zero new attempt ? $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { $total_time = " total_time = " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { // It is dokeos LP. $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } // Code added by Isaac Flores. // This code line fixes the problem of wrong status. if ($my_type_lp == 2) { // Verify current status in multiples attempts. $sql_status = 'SELECT status FROM ' . $item_view_table . ' WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" '; $rs_status = Database::query($sql_status); $current_status = Database::result($rs_status, 0, 'status'); if (in_array($current_status, $case_completed)) { $my_status = ''; $total_time = ''; } else { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; } } } } if ($this->type == 'sco') { //IF scorm scorm_update_time has already updated total_tim in db $sql = "UPDATE {$item_view_table} " . " SET " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id(); } else { $sql = "UPDATE {$item_view_table} " . "SET " . $total_time . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id(); } $this->current_start_time = time(); } if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0); } $res = Database::query($sql); } if (is_array($this->interactions) && count($this->interactions) > 0) { // Save interactions. $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = "SELECT id FROM {$tbl} " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id(); $res = Database::query($sql); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $lp_iv_id = $row[0]; if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0); } foreach ($this->interactions as $index => $interaction) { $correct_resp = ''; if (is_array($interaction[4]) && !empty($interaction[4][0])) { foreach ($interaction[4] as $resp) { $correct_resp .= $resp . ','; } $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1); } $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION); $iva_sql = "SELECT id FROM {$iva_table} " . "WHERE c_id = {$course_id} AND lp_iv_id = {$lp_iv_id} " . "AND (order_id = {$index} " . "OR interaction_id = '" . Database::escape_string($interaction[0]) . "')"; $iva_res = Database::query($iva_sql); // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7) if (Database::num_rows($iva_res) > 0) { // Update (or don't). $iva_row = Database::fetch_array($iva_res); $iva_id = $iva_row[0]; $ivau_sql = "UPDATE {$iva_table} " . "SET interaction_id = '" . Database::escape_string($interaction[0]) . "'," . "interaction_type = '" . Database::escape_string($interaction[1]) . "'," . "weighting = '" . Database::escape_string($interaction[3]) . "'," . "completion_time = '" . Database::escape_string($interaction[2]) . "'," . "correct_responses = '" . Database::escape_string($correct_resp) . "'," . "student_response = '" . Database::escape_string($interaction[5]) . "'," . "result = '" . Database::escape_string($interaction[6]) . "'," . "latency = '" . Database::escape_string($interaction[7]) . "'" . "WHERE c_id = {$course_id} AND id = {$iva_id}"; Database::query($ivau_sql); } else { // Insert new one. $ivai_sql = "INSERT INTO {$iva_table} (c_id, order_id, lp_iv_id, interaction_id, interaction_type, " . "weighting, completion_time, correct_responses, " . "student_response, result, latency)" . "VALUES" . "({$course_id}, " . $index . "," . $lp_iv_id . ",'" . Database::escape_string($interaction[0]) . "','" . Database::escape_string($interaction[1]) . "'," . "'" . Database::escape_string($interaction[3]) . "','" . Database::escape_string($interaction[2]) . "','" . Database::escape_string($correct_resp) . "'," . "'" . Database::escape_string($interaction[5]) . "','" . Database::escape_string($interaction[6]) . "','" . Database::escape_string($interaction[7]) . "'" . ")"; Database::query($ivai_sql); } } } } } if (self::debug > 2) { error_log('End of learnpathItem::write_to_db()', 0); } return true; }
* @author Yannick Warnier <*****@*****.**> (extended and maintained - 2005-2014) * @version v 1.2 * @access public * @package chamilo.learnpath.scorm */ // If you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js // of Maritime Navigation when trying to execute this row // var result = api.LMSInitialize(""); // get the error response : you are not authorized to call this function // Flag to allow for anonymous user - needs to be set before global.inc.php. $use_anonymous = true; //require_once '../inc/global.inc.php'; \Chamilo\CoreBundle\Framework\Container::$legacyTemplate = 'layout_empty.html.twig'; $file = Session::read('file'); /** @var learnpath $oLP */ $oLP = learnpath::getCurrentLpFromSession(); /** @var learnpathItem $oItem */ $oItem = isset($oLP->items[$oLP->current]) ? $oLP->items[$oLP->current] : null; if (!is_object($oItem)) { error_log('New LP - scorm_api - Could not load oItem item', 0); exit; } $autocomplete_when_80pct = 0; $user = api_get_user_info(); $userId = api_get_user_id(); header('Content-type: text/javascript'); ?> var scorm_logs=<?php echo (empty($oLP->scorm_debug) or !api_is_course_admin() && !api_is_platform_admin()) ? '0' : '3'; ?> ; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
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)) {
if (!isset($_POST['file_name'])) { return false; } // Escape path with basename so it can only be directly into the archive/ directory. $s = api_get_path(SYS_ARCHIVE_PATH) . basename($_POST['file_name']); // Get name of the zip file without the extension $info = pathinfo($s); $filename = $info['basename']; $extension = $info['extension']; $file_base_name = str_replace('.' . $extension, '', $filename); $new_dir = api_replace_dangerous_char(trim($file_base_name)); $result = learnpath::verify_document_size($s); if ($result == true) { throw new \Exception(get_lang('UplFileTooBig')); } $type = learnpath::get_package_type($s, basename($s)); switch ($type) { case 'scorm': require_once 'scorm.class.php'; $oScorm = new scorm(); $manifest = $oScorm->import_local_package($s, $current_dir); if ($manifest === false) { throw new \Exception('Error import local package'); } if (!empty($manifest)) { $oScorm->parse_manifest($manifest); $oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']); } $proximity = ''; if (!empty($_REQUEST['content_proximity'])) { $proximity = Database::escape_string($_REQUEST['content_proximity']);
/** * Writes the current data to the database * @return boolean Query result */ function write_to_db() { if ($this->debug > 0) { error_log('New LP - In learnpathItem::write_to_db()', 0); } $mode = $this->get_lesson_mode(); $credit = $this->get_credit(); $my_verified_status = $this->get_status(false); $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql_verified = 'SELECT status FROM ' . $item_view_table . ' WHERE lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->attempt_id . '" ;'; $rs_verified = Database::query($sql_verified, __FILE__, __LINE__); $row_verified = Database::fetch_array($rs_verified); $my_case_completed = array('completed', 'passed', 'browsed', 'failed'); //added by isaac flores if (in_array($sql_verified['status'], $my_case_completed)) { $save = false; } else { $save = true; } if ($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' or $mode == 'review' or $mode == 'browse')) { //this info shouldn't be saved as the credit or lesson mode info prevent it if ($this->debug > 1) { error_log('New LP - In learnpathItem::write_to_db() - credit(' . $credit . ') or lesson_mode(' . $mode . ') prevent recording!', 0); } } else { //check the row exists $inserted = false; // this a special case for multiple attempts and Dokeos exercises if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') { // we force the item to be restarted $this->restart(); $sql = "INSERT INTO {$item_view_table} " . "(total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "(" . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')"; if ($this->debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql, 0); } $res = Database::query($sql, __FILE__, __LINE__); $this->db_item_view_id = Database::insert_id(); $inserted = true; } $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $check = "SELECT * FROM {$item_view_table} " . "WHERE lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id; if ($this->debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Querying item_view: ' . $check, 0); } $check_res = Database::query($check); //depending on what we want (really), we'll update or insert a new row //now save into DB $res = 0; if ($inserted == false && Database::num_rows($check_res) < 1) { /*$my_status = ''; if ($this->type!=TOOL_QUIZ) { $my_status = $this->get_status(false); }*/ $sql = "INSERT INTO {$item_view_table} " . "(total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "(" . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')"; if ($this->debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view: ' . $sql, 0); } $res = Database::query($sql, __FILE__, __LINE__); $this->db_item_view_id = Database::insert_id(); } else { $sql = ''; if ($this->type == 'hotpotatoes') { //make an exception for HotPotatoes, don't update the score //because it has been saved outside of this tool $sql = "UPDATE {$item_view_table} " . "SET total_time = " . $this->get_total_time() . ", " . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . " status = '" . $this->get_status(false) . "'," . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id; } else { //for all other content types... if ($this->type == 'quiz') { $my_status = ' '; $total_time = ' '; if (!empty($_REQUEST['exeId'])) { $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $safe_exe_id = Database::escape_string($_REQUEST['exeId']); $sql = 'SELECT start_date,exe_date FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . (int) $safe_exe_id; $res = Database::query($sql, __FILE__, __LINE__); $row_dates = Database::fetch_array($res); $time_start_date = convert_mysql_date($row_dates['start_date']); $time_exe_date = convert_mysql_date($row_dates['exe_date']); $mytime = (int) $time_exe_date - (int) $time_start_date; $total_time = " total_time = " . $mytime . ", "; } } else { $my_type_lp = learnpath::get_type_static($this->lp_id); // this is a array containing values finished $case_completed = array('completed', 'passed', 'browsed'); //is not multiple attempts if ($this->get_prevent_reinit() == 1) { // process of status verified into data base $sql_verified = 'SELECT status FROM ' . $item_view_table . ' WHERE lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->attempt_id . '" ;'; $rs_verified = Database::query($sql_verified, __FILE__, __LINE__); $row_verified = Database::fetch_array($rs_verified); //get type lp: 1=lp dokeos and 2=scorm // if not is completed or passed or browsed and learning path is scorm if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { //verified into data base if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') { //&& $this->type!='dir' $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { //&& !in_array($row_verified['status'],$case_completed) //is lp dokeos or aicc if ($my_type_lp == 1 && $this->type != 'chapter') { $total_time = " total_time = total_time + " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { if ($my_type_lp == 3) { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } } } } } else { // is multiple attempts if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { //reset zero new attempt ? $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) { $total_time = " total_time = " . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { //is dokeos LP $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; $my_status = " status = '" . $this->get_status(false) . "' ,"; } //code added by isaac flores //this code line fix the problem of wrong status if ($my_type_lp == 2) { //verify current status in multiples attempts $sql_status = 'SELECT status FROM ' . $item_view_table . ' WHERE lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->attempt_id . '" '; $rs_status = Database::query($sql_status, __FILE__, __LINE__); $current_status = Database::result($rs_status, 0, 'status'); if (in_array($current_status, $case_completed)) { $my_status = ''; $total_time = ''; } else { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; } } } /*if ($my_type_lp==1 && !in_array($row_verified['status'],$case_completed)) { $total_time =" total_time = total_time + ".$this->get_total_time().", "; }*/ } // if $this->force_scorm_time is set to true, then we need to add the session time to the initial time if ($this->force_scorm_time) { $total_time = ' total_time = ' . ($this->time_before_session + $this->get_total_time()) . ' , '; $this->force_scorm_time = false; } $my_view_count = 'view_count=' . ($this->get_attempt_id() + 1) . ','; $sql = "UPDATE {$item_view_table} " . "SET " . $total_time . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . $my_status . $my_view_count . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE lp_item_id = " . $this->db_id; //." " . //"AND lp_view_id = ".$this->view_id." " $this->current_start_time = time(); } if ($this->debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0); } $res = Database::query($sql, __FILE__, __LINE__); } //if(!$res) //{ // $this->error = 'Could not update item_view table...'.mysql_error(); //} if (is_array($this->interactions) && count($this->interactions) > 0) { //save interactions $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = "SELECT id FROM {$tbl} " . "WHERE lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->attempt_id; $res = Database::query($sql, __FILE__, __LINE__); if (Database::num_rows($res) > 0) { $row = Database::fetch_array($res); $lp_iv_id = $row[0]; if ($this->debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0); } foreach ($this->interactions as $index => $interaction) { $correct_resp = ''; if (is_array($interaction[4]) && !empty($interaction[4][0])) { foreach ($interaction[4] as $resp) { $correct_resp .= $resp . ','; } $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1); } $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION); $iva_sql = "SELECT id FROM {$iva_table} " . "WHERE lp_iv_id = {$lp_iv_id} " . "AND (order_id = {$index} " . "OR interaction_id = '" . Database::escape_string($interaction[0]) . "')"; $iva_res = Database::query($iva_sql, __FILE__, __LINE__); //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7) if (Database::num_rows($iva_res) > 0) { //update (or don't) $iva_row = Database::fetch_array($iva_res); $iva_id = $iva_row[0]; $ivau_sql = "UPDATE {$iva_table} " . "SET interaction_id = '" . Database::escape_string($interaction[0]) . "'," . "interaction_type = '" . Database::escape_string($interaction[1]) . "'," . "weighting = '" . Database::escape_string($interaction[3]) . "'," . "completion_time = '" . Database::escape_string($interaction[2]) . "'," . "correct_responses = '" . Database::escape_string($correct_resp) . "'," . "student_response = '" . Database::escape_string($interaction[5]) . "'," . "result = '" . Database::escape_string($interaction[6]) . "'," . "latency = '" . Database::escape_string($interaction[7]) . "'" . "WHERE id = {$iva_id}"; $ivau_res = Database::query($ivau_sql, __FILE__, __LINE__); } else { //insert new one $ivai_sql = "INSERT INTO {$iva_table} " . "(order_id, lp_iv_id, interaction_id, interaction_type, " . "weighting, completion_time, correct_responses, " . "student_response, result, latency)" . "VALUES" . "(" . $index . "," . $lp_iv_id . ",'" . Database::escape_string($interaction[0]) . "','" . Database::escape_string($interaction[1]) . "'," . "'" . Database::escape_string($interaction[3]) . "','" . Database::escape_string($interaction[2]) . "','" . Database::escape_string($correct_resp) . "'," . "'" . Database::escape_string($interaction[5]) . "','" . Database::escape_string($interaction[6]) . "','" . Database::escape_string($interaction[7]) . "'" . ")"; $ivai_res = Database::query($ivai_sql, __FILE__, __LINE__); } } } } } if ($this->debug > 2) { error_log('New LP - End of learnpathItem::write_to_db()', 0); } return true; }
/** * 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); }
<img src="../img/scormbuilder.gif" align="absbottom"> ' . get_lang('AverageProgressInLearnpath') . ' </h4> <table class="data_table">'; $list = new LearnpathList($student); $flat_list = $list->get_flat_list(); if ($export_csv) { $temp = array(get_lang('AverageProgressInLearnpath'), ''); $csv_content[] = array('', ''); $csv_content[] = $temp; } if (count($flat_list) > 0) { foreach ($flat_list as $lp_id => $lp) { $lp_avg_progress = 0; foreach ($a_students as $student_id => $student) { // get the progress in learning pathes $lp_avg_progress += learnpath::get_db_progress($lp_id, $student_id); } if ($nbStudents > 0) { $lp_avg_progress = $lp_avg_progress / $nbStudents; } echo '<tr><td>' . $lp['lp_name'] . '</td><td align="right">' . round($lp_avg_progress, 1) . ' %</td>'; if (api_get_setting('enableScormCloud', 'enableScormCloud') == 'true') { echo '<td>'; require_once '../scorm_cloud/scorm_cloud.lib.php'; $cid = $_REQUEST['cidReq']; if (cloud_isCloudCourse($cid, $lp_id)) { echo '<center><a href="../scorm_cloud/cloudReport_course.php?' . api_get_cidreq() . '&lp_id=' . $lp_id . '"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a></center>'; } echo '</td>'; } echo '</tr>';
/** * @param int $user_id * @param array $courseInfo * @param int $session_id * @param string $origin * @param bool $export_csv * @param int $lp_id * @param int $lp_item_id * @param int $extendId * @param int $extendAttemptId * @param string $extendedAttempt * @param string $extendedAll * @param string $type classic or simple * @param boolean $allowExtend Optional. Allow or not extend te results * @return null|string */ public static function getLpStats($user_id, $courseInfo, $session_id, $origin, $export_csv, $lp_id, $lp_item_id = null, $extendId = null, $extendAttemptId = null, $extendedAttempt = null, $extendedAll = null, $type = 'classic', $allowExtend = true) { if (empty($courseInfo) || empty($lp_id)) { return null; } $lp_id = intval($lp_id); $lp_item_id = intval($lp_item_id); $user_id = intval($user_id); $session_id = intval($session_id); $origin = Security::remove_XSS($origin); $list = learnpath::get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']); $is_allowed_to_edit = api_is_allowed_to_edit(null, true); $course_id = $courseInfo['real_id']; $courseCode = $courseInfo['code']; $session_condition = api_get_session_condition($session_id); // Extend all button $output = null; $extend_all = 0; if ($origin == 'tracking') { $url_suffix = '&session_id=' . $session_id . '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . $lp_id . '&origin=' . $origin; } else { $url_suffix = '&lp_id=' . $lp_id; } if (!empty($extendedAll)) { $extend_all_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $url_suffix); $extend_all = 1; } else { $extend_all_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')), api_get_self() . '?action=stats&extend_all=1' . $url_suffix); } if ($origin != 'tracking') { $output .= '<div class="section-status">'; $output .= Display::page_header(get_lang('ScormMystatus')); $output .= '</div>'; } $actionColumn = null; if ($type == 'classic') { $actionColumn = ' <th>' . get_lang('Actions') . '</th>'; } $output .= '<div class="table-responsive">'; $output .= '<table class="table tracking"> <thead> <tr class="table-header"> <th width="16">' . ($allowExtend == true ? $extend_all_link : ' ') . '</th> <th colspan="4"> ' . get_lang('ScormLessonTitle') . ' </th> <th colspan="2"> ' . get_lang('ScormStatus') . ' </th> <th colspan="2"> ' . get_lang('ScormScore') . ' </th> <th colspan="2"> ' . get_lang('ScormTime') . ' </th> ' . $actionColumn . ' </tr> </thead> <tbody> '; // Going through the items using the $items[] array instead of the database order ensures // we get them in the same order as in the imsmanifest file, which is rather random when using // the database table. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM); $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW); $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW); $tbl_quiz_questions = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_TEST); $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); $tbl_stats_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $sql = "SELECT max(view_count)\n FROM {$TBL_LP_VIEW}\n WHERE\n c_id = {$course_id} AND\n lp_id = {$lp_id} AND\n user_id = {$user_id}\n {$session_condition}"; $res = Database::query($sql); $view = ''; if (Database::num_rows($res) > 0) { $myrow = Database::fetch_array($res); $view = $myrow[0]; } $counter = 0; $total_time = 0; $h = get_lang('h'); if (!empty($export_csv)) { $csv_content[] = array(get_lang('ScormLessonTitle'), get_lang('ScormStatus'), get_lang('ScormScore'), get_lang('ScormTime')); } $result_disabled_ext_all = true; $chapterTypes = learnpath::getChapterTypes(); // Show lp items if (is_array($list) && count($list) > 0) { foreach ($list as $my_item_id) { $extend_this = 0; $order = 'DESC'; if (!empty($extendId) && $extendId == $my_item_id || $extend_all) { $extend_this = 1; $order = 'ASC'; } // Prepare statement to go through each attempt. $viewCondition = null; if (!empty($view)) { $viewCondition = " AND v.view_count = {$view} "; } $sql = "SELECT\n iv.status as mystatus,\n v.view_count as mycount,\n iv.score as myscore,\n iv.total_time as mytime,\n i.id as myid,\n i.lp_id as mylpid,\n iv.lp_view_id as mylpviewid,\n i.title as mytitle,\n i.max_score as mymaxscore,\n iv.max_score as myviewmaxscore,\n i.item_type as item_type,\n iv.view_count as iv_view_count,\n iv.id as iv_id,\n path\n FROM {$TBL_LP_ITEM} as i\n INNER JOIN {$TBL_LP_ITEM_VIEW} as iv\n ON (i.id = iv.lp_item_id AND i.c_id = iv.c_id)\n INNER JOIN {$TBL_LP_VIEW} as v\n ON (iv.lp_view_id = v.id AND v.c_id = iv.c_id)\n WHERE\n v.c_id = {$course_id} AND\n i.id = {$my_item_id} AND\n i.lp_id = {$lp_id} AND\n v.user_id = {$user_id} AND\n v.session_id = {$session_id}\n {$viewCondition}\n ORDER BY iv.view_count {$order} "; $result = Database::query($sql); $num = Database::num_rows($result); $time_for_total = 'NaN'; // Extend all if (($extend_this || $extend_all) && $num > 0) { $row = Database::fetch_array($result); $result_disabled_ext_all = false; if ($row['item_type'] == 'quiz') { // Check results_disabled in quiz table. $my_path = Database::escape_string($row['path']); $sql = "SELECT results_disabled\n FROM {$TBL_QUIZ}\n WHERE\n c_id = {$course_id} AND\n id ='" . $my_path . "'"; $res_result_disabled = Database::query($sql); $row_result_disabled = Database::fetch_row($res_result_disabled); if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) { $result_disabled_ext_all = true; } } // If there are several attempts, and the link to extend has been clicked, show each attempt... if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $extend_link = ''; if (!empty($inter_num)) { $extend_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix); } $title = $row['mytitle']; if (empty($title)) { $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']); } if (in_array($row['item_type'], $chapterTypes)) { $title = "<h4> {$title} </h4>"; } $lesson_status = $row['mystatus']; $title = Security::remove_XSS($title); $counter++; $action = null; if ($type == 'classic') { $action = '<td></td>'; } if (in_array($row['item_type'], $chapterTypes)) { $output .= '<tr class="' . $oddclass . '"> <td>' . $extend_link . '</td> <td colspan="4"> ' . $title . ' </td> <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td> <td colspan="2"></td> <td colspan="2"></td> ' . $action . ' </tr>'; continue; } else { $output .= '<tr class="' . $oddclass . '"> <td>' . $extend_link . '</td> <td colspan="4"> ' . $title . ' </td> <td colspan="2"></td> <td colspan="2"></td> <td colspan="2"></td> ' . $action . ' </tr>'; } $attemptCount = 1; do { // Check if there are interactions below. $extend_attempt_link = ''; $extend_this_attempt = 0; if ((learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && !$extend_all) { if ($extendAttemptId == $row['iv_id']) { // The extend button for this attempt has been clicked. $extend_this_attempt = 1; $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix); } else { // Same case if fold_attempt_id is set, so not implemented explicitly. // The extend button for this attempt has not been clicked. $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix); } } if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $lesson_status = $row['mystatus']; $score = $row['myscore']; $time_for_total = $row['mytime']; $time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']); if ($score == 0) { $maxscore = $row['mymaxscore']; } else { if ($row['item_type'] == 'sco') { if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) { $maxscore = $row['myviewmaxscore']; } elseif ($row['myviewmaxscore'] === '') { $maxscore = 0; } else { $maxscore = $row['mymaxscore']; } } else { $maxscore = $row['mymaxscore']; } } // Remove "NaN" if any (@todo: locate the source of these NaN) $time = str_replace('NaN', '00' . $h . '00\'00"', $time); if ($row['item_type'] != 'dokeos_chapter') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { switch ($row['item_type']) { case 'sco': if ($maxscore == 0) { $view_score = $score; } else { $view_score = ExerciseLib::show_score($score, $maxscore, false); } break; case 'document': $view_score = $score == 0 ? '/' : ExerciseLib::show_score($score, $maxscore, false); break; default: $view_score = ExerciseLib::show_score($score, $maxscore, false); break; } } $action = null; if ($type == 'classic') { $action = '<td></td>'; } $output .= '<tr class="' . $oddclass . '"> <td></td> <td>' . $extend_attempt_link . '</td> <td colspan="3">' . get_lang('Attempt') . ' ' . $attemptCount . '</td> <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td> <td colspan="2">' . $view_score . '</td> <td colspan="2">' . $time . '</td> ' . $action . ' </tr>'; $attemptCount++; if (!empty($export_csv)) { $temp = array(); $temp[] = $title = Security::remove_XSS($title); $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false, $type)); if ($row['item_type'] == 'quiz') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $temp[] = '/'; } else { $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)); } } else { $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)); } $temp[] = $time; $csv_content[] = $temp; } } $counter++; $action = null; if ($type == 'classic') { $action = '<td></td>'; } if ($extend_this_attempt || $extend_all) { $list1 = learnpath::get_iv_interactions_array($row['iv_id']); foreach ($list1 as $id => $interaction) { if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $student_response = urldecode($interaction['student_response']); $content_student_response = explode('__|', $student_response); if (count($content_student_response) > 0) { if (count($content_student_response) >= 3) { // Pop the element off the end of array. array_pop($content_student_response); } $student_response = implode(',', $content_student_response); } $output .= '<tr class="' . $oddclass . '"> <td></td> <td></td> <td></td> <td>' . $interaction['order_id'] . '</td> <td>' . $interaction['id'] . '</td> <td colspan="2">' . $interaction['type'] . '</td> <td>' . $student_response . '</td> <td>' . $interaction['result'] . '</td> <td>' . $interaction['latency'] . '</td> <td>' . $interaction['time'] . '</td> ' . $action . ' </tr>'; $counter++; } $list2 = learnpath::get_iv_objectives_array($row['iv_id']); foreach ($list2 as $id => $interaction) { if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $output .= '<tr class="' . $oddclass . '"> <td></td> <td></td> <td></td> <td>' . $interaction['order_id'] . '</td> <td colspan="2">' . $interaction['objective_id'] . '</td> <td colspan="2">' . $interaction['status'] . '</td> <td>' . $interaction['score_raw'] . '</td> <td>' . $interaction['score_max'] . '</td> <td>' . $interaction['score_min'] . '</td> ' . $action . ' </tr>'; $counter++; } } } while ($row = Database::fetch_array($result)); } elseif ($num > 0) { // Not extended. $row = Database::fetch_array($result, 'ASSOC'); $my_id = $row['myid']; $my_lp_id = $row['mylpid']; $my_lp_view_id = $row['mylpviewid']; $my_path = $row['path']; $result_disabled_ext_all = false; if ($row['item_type'] == 'quiz') { // Check results_disabled in quiz table. $my_path = Database::escape_string($my_path); $sql = "SELECT results_disabled\n FROM {$TBL_QUIZ}\n WHERE c_id = {$course_id} AND id ='" . $my_path . "'"; $res_result_disabled = Database::query($sql); $row_result_disabled = Database::fetch_row($res_result_disabled); if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) { $result_disabled_ext_all = true; } } // Check if there are interactions below $extend_this_attempt = 0; $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id); $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id); $extend_attempt_link = ''; if ($inter_num > 0 || $objec_num > 0) { if (!empty($extendAttemptId) && $extendAttemptId == $row['iv_id']) { // The extend button for this attempt has been clicked. $extend_this_attempt = 1; $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix); } else { // Same case if fold_attempt_id is set, so not implemented explicitly. // The extend button for this attempt has not been clicked. $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix); } } if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $extend_link = ''; if ($inter_num > 1) { $extend_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix); } $lesson_status = $row['mystatus']; $score = $row['myscore']; $subtotal_time = $row['mytime']; while ($tmp_row = Database::fetch_array($result)) { $subtotal_time += $tmp_row['mytime']; } $title = $row['mytitle']; // Selecting the exe_id from stats attempts tables in order to look the max score value. $sql = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND c_id = ' . $course_id . ' AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC LIMIT 1'; $resultLastAttempt = Database::query($sql); $num = Database::num_rows($resultLastAttempt); $id_last_attempt = null; if ($num > 0) { while ($rowLA = Database::fetch_array($resultLastAttempt)) { $id_last_attempt = $rowLA['exe_id']; } } if ($score == 0) { $maxscore = $row['mymaxscore']; } else { if ($row['item_type'] == 'sco') { if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) { $maxscore = $row['myviewmaxscore']; } elseif ($row['myviewmaxscore'] === '') { $maxscore = 0; } else { $maxscore = $row['mymaxscore']; } } else { if ($row['item_type'] == 'quiz') { // Get score and total time from last attempt of a exercise en lp. $sql = "SELECT score\n FROM {$TBL_LP_ITEM_VIEW}\n WHERE\n c_id = {$course_id} AND\n lp_item_id = '" . (int) $my_id . "' AND\n lp_view_id = '" . (int) $my_lp_view_id . "'\n ORDER BY view_count DESC limit 1"; $res_score = Database::query($sql); $row_score = Database::fetch_array($res_score); $sql = "SELECT SUM(total_time) as total_time\n FROM {$TBL_LP_ITEM_VIEW}\n WHERE\n c_id = {$course_id} AND\n lp_item_id = '" . (int) $my_id . "' AND\n lp_view_id = '" . (int) $my_lp_view_id . "'"; $res_time = Database::query($sql); $row_time = Database::fetch_array($res_time); if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) { $score = (double) $row_score['score']; $subtotal_time = (int) $row_time['total_time']; } else { $score = 0; $subtotal_time = 0; } // Selecting the max score from an attempt. $sql = "SELECT SUM(t.ponderation) as maxscore\n FROM (\n SELECT DISTINCT\n question_id, marks, ponderation\n FROM {$tbl_stats_attempts} as at\n INNER JOIN {$tbl_quiz_questions} as q\n ON (q.id = at.question_id AND q.c_id = {$course_id})\n WHERE exe_id ='{$id_last_attempt}'\n ) as t"; $result = Database::query($sql); $row_max_score = Database::fetch_array($result); $maxscore = $row_max_score['maxscore']; } else { $maxscore = $row['mymaxscore']; } } } $time_for_total = $subtotal_time; $time = learnpathItem::getScormTimeFromParameter('js', $subtotal_time); if (empty($title)) { $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']); } $action = null; if ($type == 'classic') { $action = '<td></td>'; } if (in_array($row['item_type'], $chapterTypes)) { $title = Security::remove_XSS($title); $output .= '<tr class="' . $oddclass . '"> <td>' . $extend_link . '</td> <td colspan="4"> <h4>' . $title . '</h4> </td> <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td> <td colspan="2"></td> <td colspan="2"></td> ' . $action . ' </tr>'; } else { $correct_test_link = '-'; if ($row['item_type'] == 'quiz') { $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . $origin; $sql = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND c_id = ' . $course_id . ' AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC '; $resultLastAttempt = Database::query($sql); $num = Database::num_rows($resultLastAttempt); if ($num > 0) { if ($extendedAttempt == 1 && $lp_id == $my_lp_id && $lp_item_id == $my_id) { $correct_test_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id); } else { $correct_test_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttemptsByExercise')), api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id); } } } $title = Security::remove_XSS($title); $action = null; if ($type == 'classic') { $action = '<td>' . $correct_test_link . '</td>'; } if ($lp_id == $my_lp_id && false) { $output .= '<tr class =' . $oddclass . '> <td>' . $extend_link . '</td> <td colspan="4">' . $title . '</td> <td colspan="2"> </td> <td colspan="2"> </td> <td colspan="2"> </td> ' . $action . ' </tr>'; $output .= '</tr>'; } else { if ($lp_id == $my_lp_id && $lp_item_id == $my_id) { $output .= "<tr class='{$oddclass}'>"; } else { $output .= "<tr class='{$oddclass}'>"; } $scoreItem = null; if ($row['item_type'] == 'quiz') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $scoreItem .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { $scoreItem .= ExerciseLib::show_score($score, $maxscore, false); } } else { $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore); } $output .= ' <td>' . $extend_link . '</td> <td colspan="4">' . $title . '</td> <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td> <td colspan="2">' . $scoreItem . '</td> <td colspan="2">' . $time . '</td> ' . $action . ' '; $output .= '</tr>'; } if (!empty($export_csv)) { $temp = array(); $temp[] = api_html_entity_decode($title, ENT_QUOTES); $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES); if ($row['item_type'] == 'quiz') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $temp[] = '/'; } else { $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)); } } else { $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)); } $temp[] = $time; $csv_content[] = $temp; } } $counter++; $action = null; if ($type == 'classic') { $action = '<td></td>'; } if ($extend_this_attempt || $extend_all) { $list1 = learnpath::get_iv_interactions_array($row['iv_id']); foreach ($list1 as $id => $interaction) { if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $output .= '<tr class="' . $oddclass . '"> <td></td> <td></td> <td></td> <td>' . $interaction['order_id'] . '</td> <td>' . $interaction['id'] . '</td> <td colspan="2">' . $interaction['type'] . '</td> <td>' . urldecode($interaction['student_response']) . '</td> <td>' . $interaction['result'] . '</td> <td>' . $interaction['latency'] . '</td> <td>' . $interaction['time'] . '</td> ' . $action . ' </tr>'; $counter++; } $list2 = learnpath::get_iv_objectives_array($row['iv_id']); foreach ($list2 as $id => $interaction) { if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $output .= '<tr class="' . $oddclass . '"> <td></td> <td></td> <td></td> <td>' . $interaction['order_id'] . '</td> <td colspan="2">' . $interaction['objective_id'] . '</td> <td colspan="2">' . $interaction['status'] . '</td> <td>' . $interaction['score_raw'] . '</td> <td>' . $interaction['score_max'] . '</td> <td>' . $interaction['score_min'] . '</td> ' . $action . ' </tr>'; $counter++; } } // Attempts listing by exercise. if ($lp_id == $my_lp_id && $lp_item_id == $my_id && $extendedAttempt) { // Get attempts of a exercise. if (!empty($lp_id) && !empty($lp_item_id) && $row['item_type'] === 'quiz') { $sql = "SELECT path FROM {$TBL_LP_ITEM}\n WHERE\n c_id = {$course_id} AND\n id = '{$lp_item_id}' AND\n lp_id = '{$lp_id}'"; $res_path = Database::query($sql); $row_path = Database::fetch_array($res_path); if (Database::num_rows($res_path) > 0) { $sql = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int) $row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "' . (int) $lp_id . '" AND orig_lp_item_id = "' . (int) $lp_item_id . '" AND c_id = ' . $course_id . ' AND session_id = ' . $session_id . ' ORDER BY exe_date'; $res_attempts = Database::query($sql); $num_attempts = Database::num_rows($res_attempts); if ($num_attempts > 0) { $n = 1; while ($row_attempts = Database::fetch_array($res_attempts)) { $my_score = $row_attempts['exe_result']; $my_maxscore = $row_attempts['exe_weighting']; $my_exe_id = $row_attempts['exe_id']; $my_orig_lp = $row_attempts['orig_lp_id']; $my_orig_lp_item = $row_attempts['orig_lp_item_id']; $my_exo_exe_id = $row_attempts['exe_exo_id']; $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC'); $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC'); if ($mktime_start_date && $mktime_exe_date) { $mytime = (int) $mktime_exe_date - (int) $mktime_start_date; $time_attemp = learnpathItem::getScormTimeFromParameter('js', $mytime); $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp); } else { $time_attemp = ' - '; } if (!$is_allowed_to_edit && $result_disabled_ext_all) { $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { // Show only float when need it if ($my_score == 0) { $view_score = ExerciseLib::show_score(0, $my_maxscore, false); } else { if ($my_maxscore == 0) { $view_score = $my_score; } else { $view_score = ExerciseLib::show_score($my_score, $my_maxscore, false); } } } $my_lesson_status = $row_attempts['status']; if ($my_lesson_status == '') { $my_lesson_status = learnpathitem::humanize_status('completed'); } elseif ($my_lesson_status == 'incomplete') { $my_lesson_status = learnpathitem::humanize_status('incomplete'); } $output .= '<tr class="' . $oddclass . '" > <td></td> <td>' . $extend_attempt_link . '</td> <td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td> <td colspan="2">' . $my_lesson_status . '</td> <td colspan="2">' . $view_score . '</td> <td colspan="2">' . $time_attemp . '</td>'; if ($action == 'classic') { if ($origin != 'tracking') { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $output .= '<td> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"> </td>'; } else { $output .= '<td> <a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $courseCode . '" target="_parent"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"> </a></td>'; } } else { if (!$is_allowed_to_edit && $result_disabled_ext_all) { $output .= '<td> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>'; } else { $output .= '<td> <a href="../exercice/exercise_show.php?cidReq=' . $courseCode . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>'; } } } $output .= '</tr>'; $n++; } } $output .= '<tr><td colspan="12"> </td></tr>'; } } } } $total_time += $time_for_total; // QUIZZ IN LP $a_my_id = array(); if (!empty($my_lp_id)) { $a_my_id[] = $my_lp_id; } } } // NOT Extend all "left green cross" if (!empty($a_my_id)) { if ($extendedAttempt) { // "Right green cross" extended $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, false); } else { // "Left green cross" extended $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, true); } } else { // Extend all "left green cross" $total_score = self::get_avg_student_score($user_id, $course_id, array($lp_id), $session_id, false, false); } $total_time = learnpathItem::getScormTimeFromParameter('js', $total_time); $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time); if (!$is_allowed_to_edit && $result_disabled_ext_all) { $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { if (is_numeric($total_score)) { $final_score = $total_score . '%'; } else { $final_score = $total_score; } } $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id); if ($counter % 2 == 0) { $oddclass = 'row_odd'; } else { $oddclass = 'row_even'; } $action = null; if ($type == 'classic') { $action = '<td></td>'; } $output .= '<tr class="' . $oddclass . '"> <td></td> <td colspan="4"> <i>' . get_lang('AccomplishedStepsTotal') . '</i> </td> <td colspan="2">' . $progress . '%</td> <td colspan="2"> ' . $final_score . ' </td> <td colspan="2">' . $total_time . '</div> ' . $action . ' </tr>'; $output .= ' </tbody> </table> </div> '; if (!empty($export_csv)) { $temp = array('', '', '', ''); $csv_content[] = $temp; $temp = array(get_lang('AccomplishedStepsTotal'), '', $final_score, $total_time); $csv_content[] = $temp; ob_end_clean(); Export::arrayToCsv($csv_content, 'reporting_learning_path_details'); exit; } return $output; }
/** * 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; }
/** * @param string $file * @param string $action_after_conversion * @return bool|int */ public function convert_document($file, $action_after_conversion = 'make_lp') { $_course = api_get_course_info(); $this->file_name = pathinfo($file['name'], PATHINFO_FILENAME); // Create the directory $result = $this->generate_lp_folder($_course, $this->file_name); // Create the directory $this->base_work_dir = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document'; ///learning_path/ppt_dirname directory $this->created_dir = substr($result['dir'], 0, strlen($result['dir']) - 1); $this->file_path = $this->created_dir . '/' . api_replace_dangerous_char($file['name']); //var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir); /* * Original code global $_course, $_user, $_configuration; $this->file_name = (strrpos($file['name'], '.') > 0 ? substr($file['name'], 0, strrpos($file['name'], '.')) : $file['name']); $this->file_name = api_replace_dangerous_char($this->file_name, 'strict'); $this->file_name = strtolower($this->file_name); $visio_dir = ($action_after_conversion == 'add_docs_to_visio') ? VIDEOCONF_UPLOAD_PATH : ''; $this->file_path = $visio_dir.'/'.$this->file_name.'.'.pathinfo($file['name'], PATHINFO_EXTENSION); $dir_name = $visio_dir.'/'.$this->file_name; // Create the directory. $this->base_work_dir = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; $this->created_dir = create_unexisting_directory($_course, $_user['user_id'], api_get_session_id(), 0, 0, $this->base_work_dir, $dir_name); var_dump($this->file_name, $this->file_path, $this->base_work_dir, $this->created_dir); */ $ppt2lp_host = api_get_setting('ppt_to_lp.host'); if ($ppt2lp_host == 'localhost') { move_uploaded_file($file['tmp_name'], $this->base_work_dir . '/' . $this->file_path); //var_dump( $this->base_work_dir.$this->created_dir.$this->file_path); $perm = api_get_setting('permissions_for_new_files'); if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php $converter_path = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png'); $class_path = $converter_path . ';' . $converter_path . '/jodconverter-2.2.2.jar;' . $converter_path . '/jodconverter-cli-2.2.2.jar'; //$cmd = 'java -cp "'.$class_path.'" DokeosConverter'; $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $class_path . '" DokeosConverter'; } else { $converter_path = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png'; //$class_path = '-cp .:jodconverter-2.2.1.jar:jodconverter-cli-2.2.1.jar'; $class_path = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar'; $cmd = 'cd ' . $converter_path . ' && java ' . $class_path . ' DokeosConverter'; } $cmd .= ' -p ' . api_get_setting('ppt_to_lp.port'); // Call to the function implemented by child. $cmd .= $this->add_command_parameters(); // To allow openoffice to manipulate docs. @chmod($this->base_work_dir, 0777); @chmod($this->base_work_dir . $this->created_dir, 0777); @chmod($this->base_work_dir . $this->file_path, 0777); $locale = $this->original_locale; // TODO: Improve it because we're not sure this locale is present everywhere. putenv('LC_ALL=' . $locale); $files = array(); $return = 0; $shell = exec($cmd, $files, $return); if ($return != 0) { // If the java application returns an error code. switch ($return) { // Can't connect to openoffice. case 1: $this->error = get_lang('CannotConnectToOpenOffice'); break; // Conversion failed in openoffice. // Conversion failed in openoffice. case 2: $this->error = get_lang('OogieConversionFailed'); break; // Conversion can't be launch because command failed. // Conversion can't be launch because command failed. case 255: $this->error = get_lang('OogieUnknownError'); break; } DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir); return false; } } else { // get result from webservices $result = $this->_get_remote_ppt2lp_files($file); $result = unserialize($result); // Save remote images to server chmod($this->base_work_dir . $this->created_dir, api_get_permissions_for_new_directories()); if (!empty($result['images'])) { foreach ($result['images'] as $image => $img_data) { $image_path = $this->base_work_dir . $this->created_dir; @file_put_contents($image_path . '/' . $image, base64_decode($img_data)); @chmod($image_path . '/' . $image, 0777); } } // files info $files = $result['files']; } if (!empty($files)) { // Create lp $this->lp_id = learnpath::add_lp($_course['id'], $this->file_name, '', 'guess', 'manual'); // make sure we have a course code available for later $this->cc = $_course['id']; // Call to the function implemented by child following action_after_conversion parameter. switch ($action_after_conversion) { case 'make_lp': $this->make_lp($files); break; case 'add_docs_to_visio': $this->add_docs_to_visio($files); break; } chmod($this->base_work_dir, api_get_permissions_for_new_directories()); } return $this->first_item; }
/** * Get one item's details * @param integer LP ID * @param integer user ID * @param integer View ID * @param integer Current item ID * @param integer New item ID */ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_item) { $debug = 0; $return = ''; if ($debug > 0) { error_log('In xajax_switch_item_details(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $current_item . ',' . $next_item . ')', 0); } //$objResponse = new xajaxResponse(); /*$item_id may be one of: * -'next' * -'previous' * -'first' * -'last' * - a real item ID */ $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $new_item_id = 0; switch ($next_item) { case 'next': $mylp->set_current_item($current_item); $mylp->next(); $new_item_id = $mylp->get_current_item_id(); if ($debug > 1) { error_log('In {next} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0); } break; case 'previous': $mylp->set_current_item($current_item); $mylp->previous(); $new_item_id = $mylp->get_current_item_id(); if ($debug > 1) { error_log('In {previous} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0); } break; case 'first': $mylp->set_current_item($current_item); $mylp->first(); $new_item_id = $mylp->get_current_item_id(); if ($debug > 1) { error_log('In {first} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0); } break; case 'last': break; default: // Should be filtered to check it's not hacked. if ($next_item == $current_item) { // If we're opening the same item again. $mylp->items[$current_item]->restart(); } $new_item_id = $next_item; $mylp->set_current_item($new_item_id); if ($debug > 1) { error_log('In {default} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0); } break; } $mylp->start_current_item(true); if ($mylp->force_commit) { $mylp->save_current(); } if (is_object($mylp->items[$new_item_id])) { $mylpi = $mylp->items[$new_item_id]; } else { if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); } $mylpi = new learnpathItem($new_item_id, $user_id); $mylpi->set_lp_view($view_id); } /* * now get what's needed by the SCORM API: * -score * -max * -min * -lesson_status * -session_time * -suspend_data */ $myscore = $mylpi->get_score(); $mymax = $mylpi->get_max(); if ($mymax === '') { $mymax = "''"; } $mymin = $mylpi->get_min(); $mylesson_status = $mylpi->get_status(); $mylesson_location = $mylpi->get_lesson_location(); $mytotal_time = $mylpi->get_scorm_time('js'); $mymastery_score = $mylpi->get_mastery_score(); $mymax_time_allowed = $mylpi->get_max_time_allowed(); $mylaunch_data = $mylpi->get_launch_data(); /* if ($mylpi->get_type() == 'asset') { // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed) $mylesson_status = 'completed'; $mylpi->set_status('completed'); $mylpi->save(); } */ $mysession_time = $mylpi->get_total_time(); $mysuspend_data = $mylpi->get_suspend_data(); $mylesson_location = $mylpi->get_lesson_location(); $myic = $mylpi->get_interactions_count(); $myistring = ''; for ($i = 0; $i < $myic; $i++) { $myistring .= ",[" . $i . ",'','','','','','','']"; } if (!empty($myistring)) { $myistring = substr($myistring, 1); } /* * The following lines should reinitialize the values for the SCO * However, due to many complications, we are now relying more on the * LMSInitialize() call and its underlying lp_ajax_initialize.php call * so this code is technically deprecated (but the change of item_id should * remain). However, due to numerous technical issues with SCORM, we prefer * leaving it as a double-lock security. If removing, please test carefully * with both SCORM and proper learning path tracking. */ $return .= "olms.score=" . $myscore . ";" . "olms.max=" . $mymax . ";" . "olms.min=" . $mymin . ";" . "olms.lesson_status='" . $mylesson_status . "';" . "olms.lesson_location='" . $mylesson_location . "';" . "olms.session_time='" . $mysession_time . "';" . "olms.suspend_data='" . $mysuspend_data . "';" . "olms.total_time = '" . $mytotal_time . "';" . "olms.mastery_score = '" . $mymastery_score . "';" . "olms.max_time_allowed = '" . $mymax_time_allowed . "';" . "olms.launch_data = '" . $mylaunch_data . "';" . "olms.interactions = new Array(" . $myistring . ");" . "olms.item_objectives = new Array();" . "olms.G_lastError = 0;" . "olms.G_LastErrorMessage = 'No error';" . "olms.finishSignalReceived = 0;"; /* * and re-initialise the rest * -lms_lp_id * -lms_item_id * -lms_old_item_id * -lms_new_item_id * -lms_initialized * -lms_progress_bar_mode * -lms_view_id * -lms_user_id */ $mytotal = $mylp->get_total_items_count_without_chapters(); $mycomplete = $mylp->get_complete_items_count(); $myprogress_mode = $mylp->get_progress_bar_mode(); $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode; $mynext = $mylp->get_next_item_id(); $myprevious = $mylp->get_previous_item_id(); $myitemtype = $mylpi->get_type(); $mylesson_mode = $mylpi->get_lesson_mode(); $mycredit = $mylpi->get_credit(); $mylaunch_data = $mylpi->get_launch_data(); $myinteractions_count = $mylpi->get_interactions_count(); $myobjectives_count = $mylpi->get_objectives_count(); $mycore_exit = $mylpi->get_core_exit(); $return .= "olms.lms_lp_id=" . $lp_id . ";" . "olms.lms_item_id=" . $new_item_id . ";" . "olms.lms_old_item_id=0;" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $view_id . ";" . "olms.lms_user_id=" . $user_id . ";" . "olms.next_item=" . $new_item_id . ";" . "olms.lms_next_item=" . $mynext . ";" . "olms.lms_previous_item=" . $myprevious . ";" . "olms.lms_item_type = '" . $myitemtype . "';" . "olms.lms_item_credit = '" . $mycredit . "';" . "olms.lms_item_lesson_mode = '" . $mylesson_mode . "';" . "olms.lms_item_launch_data = '" . $mylaunch_data . "';" . "olms.lms_item_interactions_count = '" . $myinteractions_count . "';" . "olms.lms_item_objectives_count = '" . $myinteractions_count . "';" . "olms.lms_item_core_exit = '" . $mycore_exit . "';" . "olms.asset_timer = 0;"; $return .= "update_toc('unhighlight','" . $current_item . "');" . "update_toc('highlight','" . $new_item_id . "');" . "update_toc('{$mylesson_status}','" . $new_item_id . "');" . "update_progress_bar('{$mycomplete}','{$mytotal}','{$myprogress_mode}');"; $return .= 'updateGamificationValues(); '; $mylp->set_error_msg(''); $mylp->prerequisites_match(); // Check the prerequisites are all complete. if ($debug > 1) { error_log('Prereq_match() returned ' . htmlentities($mylp->error), 0); } // Save the new item ID for the exercise tool to use. Session::write('scorm_item_id', $new_item_id); Session::write('lpobject', serialize($mylp)); return $return; }
require 'lp_list.php'; } break; case 'move_lp_down': //change lp published status (visibility on homepage) if (!api_is_allowed_to_edit()) { api_not_allowed(true); } if ($debug > 0) { error_log('New LP - publish action triggered', 0); } if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; } else { learnpath::move_down($_REQUEST['lp_id']); require 'lp_list.php'; } break; case 'edit': if (!api_is_allowed_to_edit()) { api_not_allowed(true); } if ($debug > 0) { error_log('New LP - edit action triggered', 0); } if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; } else { $_SESSION['refresh'] = 1;
$show_learnpath = true; api_protect_course_script(); $lp_id = intval($_GET['lp_id']); $sessionId = api_get_session_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(), $sessionId); if (!api_is_allowed_to_edit(false, true, false, false) && intval($visibility) == 0) { api_not_allowed(true); } $learnPath = learnpath::getCurrentLpFromSession(); if (empty($learnPath)) { api_not_allowed(true); } $debug = 0; if ($debug) { error_log('------ Entering lp_view.php -------'); } $learnPath->error = ''; $lp_item_id = $learnPath->get_current_item_id(); $lpType = $learnPath->get_type(); $course_code = api_get_course_id(); $course_id = api_get_course_int_id(); $user_id = api_get_user_id(); $platform_theme = api_get_setting('stylesheets'); // Platform's css.
/** * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) * This method can be used as abstract and is recursive * @param integer Learnpath ID * @param integer Parent ID of the items to look for * @return mixed Ordered list of item IDs or false on error */ function get_flat_ordered_items_list($lp, $parent = 0) { //if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);} $list = array(); if (empty($lp)) { return false; } $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $sql = "SELECT * FROM {$tbl_lp_item} WHERE lp_id = {$lp} AND parent_item_id = {$parent} ORDER BY display_order"; $res = Database::query($sql, __FILE__, __LINE__); while ($row = Database::fetch_array($res)) { $sublist = learnpath::get_flat_ordered_items_list($lp, $row['id']); $list[] = $row['id']; foreach ($sublist as $item) { $list[] = $item; } } return $list; }
/** * 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); }
} </script>'; $gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : null; $defaults = array(); $form = new FormValidator('form1', 'post', 'lp_controller.php'); // Form title $form->addElement('header', get_lang('EditLPSettings')); // Title $form->addElement('text', 'lp_name', api_ucfirst(get_lang('LearnpathTitle')), array('class' => 'span5')); $form->applyFilter('lp_name', 'html_filter'); $form->addRule('lp_name', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('hidden', 'lp_encoding'); $referer = isset($_REQUEST['referer']) ? Security::remove_XSS($_REQUEST['referer']) : null; $form->addElement('hidden', 'referer', $referer); $items = learnpath::get_category_from_course_into_select(api_get_course_int_id(), true); $form->addElement('select', 'category_id', get_lang('Category'), $items); //Hide toc frame $hide_toc_frame = $form->addElement('checkbox', 'hide_toc_frame', null, get_lang('HideTocFrame'), array('onclick' => '$("#lp_layout_column").toggle()')); if (api_get_setting('allow_course_theme') == 'true') { $mycourselptheme = api_get_course_setting('allow_learning_path_theme'); if (!empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) { //LP theme picker $theme_select = $form->addElement('select_theme', 'lp_theme', get_lang('Theme')); $form->applyFilter('lp_theme', 'trim'); $s_theme = $_SESSION['oLP']->get_theme(); $theme_select->setSelected($s_theme); //default } } // Author
/** * 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; }