diff --git a/mod/scorm/aicc.php b/mod/scorm/aicc.php index dc107e8501f..79b60e2ecac 100755 --- a/mod/scorm/aicc.php +++ b/mod/scorm/aicc.php @@ -1,350 +1,351 @@ -scorm_scoid)) { - $scoid = $SESSION->scorm_scoid; - } else { - error('Invalid script call'); - } - $mode = 'normal'; - if (isset($SESSION->scorm_mode)) { - $mode = $SESSION->scorm_mode; - } - $status = 'Not Initialized'; - if (isset($SESSION->scorm_status)) { - $status = $SESSION->scorm_status; - } - if (isset($SESSION->attempt)) { - $attempt = $SESSION->attempt; - } else { - $attempt = 1; - } - - if ($sco = get_record('scorm_scoes','id',$scoid)) { - if (!$scorm = get_record('scorm','id',$sco->scorm)) { - error('Invalid script call'); - } - } else { - error('Invalid script call'); - } - - if ($scorm = get_record('scorm','id',$sco->scorm)) { - switch ($command) { - case 'getparam': - if ($status == 'Not Initialized') { - $SESSION->scorm_status = 'Running'; - $status = 'Running'; - } - if ($status != 'Running') { - echo "error = 101\nerror_text = Terminated\n"; - } else { - if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) { - $userdata = $usertrack; - } else { - $userdata->status = ''; - $userdata->score_raw = ''; - } - $userdata->student_id = $USER->username; - $userdata->student_name = $USER->lastname .', '. $USER->firstname; - $userdata->mode = $mode; - if ($userdata->mode == 'normal') { - $userdata->credit = 'credit'; - } else { - $userdata->credit = 'no-credit'; - } - - if ($sco = get_record('scorm_scoes','id',$scoid)) { - $userdata->course_id = $sco->identifier; - $userdata->datafromlms = $sco->datafromlms; - $userdata->masteryscore = $sco->masteryscore; - $userdata->maxtimeallowed = $sco->maxtimeallowed; - $userdata->timelimitaction = $sco->timelimitaction; - - echo "error = 0\nerror_text = Successful\naicc_data=\n"; - echo "[Core]\n"; - echo 'Student_ID = '.$userdata->student_id."\n"; - echo 'Student_Name = '.$userdata->student_name."\n"; - if (isset($userdata->{'cmi.core.lesson_location'})) { - echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n"; - } else { - echo 'Lesson_Location = '."\n"; - } - echo 'Credit = '.$userdata->credit."\n"; - if (isset($userdata->status)) { - if ($userdata->status == '') { - $userdata->entry = ', ab-initio'; - } else { - if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) { - $userdata->entry = ', resume'; - } else { - $userdata->entry = ''; - } - } - } - if (isset($userdata->{'cmi.core.lesson_status'})) { - echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\n"; - $SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'}; - } else { - echo 'Lesson_Status = not attempted'.$userdata->entry."\n"; - $SESSION->scorm_lessonstatus = 'not attempted'; - } - if (isset($userdata->{'cmi.core.score.raw'})) { - $max = ''; - $min = ''; - if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) { - $max = ', '.$userdata->{'cmi.core.score.max'}; - if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) { - $min = ', '.$userdata->{'cmi.core.score.min'}; - } - } - echo 'Score = '.$userdata->{'cmi.core.score.raw'}.$max.$min."\n"; - } else { - echo 'Score = '."\n"; - } - if (isset($userdata->{'cmi.core.total_time'})) { - echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n"; - } else { - echo 'Time = '.'00:00:00'."\n"; - } - echo 'Lesson_Mode = '.$userdata->mode."\n"; - if (isset($userdata->{'cmi.suspend_data'})) { - echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n"; - } else { - echo "[Core_Lesson]\n"."\n"; - } - echo "[Core_Vendor]\n".$userdata->datafromlms."\n"; - echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n"; - echo "[Student_Data]\n"; - echo 'Mastery_Score = '.$userdata->masteryscore."\n"; - echo 'Max_Time_Allowed = '.$userdata->maxtimeallowed."\n"; - echo 'Time_Limit_Action = '.$userdata->timelimitaction."\n"; - } else { - error('Sco not found'); - } - } - break; - case 'putparam': - if ($status == 'Running') { - if (!empty($aiccdata) && isstudent($scorm->course)) { - $initlessonstatus = 'not attempted'; - $lessonstatus = 'not attempted'; - if (isset($SESSION->scorm_lessonstatus)) { - $initlessonstatus = $SESSION->scorm_lessonstatus; - } - $score = ''; - $datamodel['lesson_location'] = 'cmi.core.lesson_location'; - $datamodel['lesson_status'] = 'cmi.core.lesson_status'; - $datamodel['score'] = 'cmi.core.score.raw'; - $datamodel['time'] = 'cmi.core.session_time'; - $datamodel['[core_lesson]'] = 'cmi.suspend_data'; - $datamodel['[comments]'] = 'cmi.comments'; - $datarows = explode("\n",$aiccdata); - reset($datarows); - while ((list(,$datarow) = each($datarows)) !== false) { - if (($equal = strpos($datarow, '=')) !== false) { - $element = strtolower(trim(substr($datarow,0,$equal))); - $value = trim(substr($datarow,$equal+1)); - if (isset($datamodel[$element])) { - $element = $datamodel[$element]; - switch ($element) { - case 'cmi.core.lesson_location': - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); - break; - case 'cmi.core.lesson_status': - $statuses = array( - 'passed' => 'passed', - 'completed' => 'completed', - 'failed' => 'failed', - 'incomplete' => 'incomplete', - 'browsed' => 'browsed', - 'not attempted' => 'not attempted', - 'p' => 'passed', - 'c' => 'completed', - 'f' => 'failed', - 'i' => 'incomplete', - 'b' => 'browsed', - 'n' => 'not attempted' - ); - $exites = array( - 'logout' => 'logout', - 'time-out' => 'time-out', - 'suspend' => 'suspend', - 'l' => 'logout', - 't' => 'time-out', - 's' => 'suspend', - ); - $values = explode(',',$value); - $value = ''; - if (count($values) > 1) { - $value = trim(strtolower($values[1])); - if (isset($exites[$value])) { - $value = $exites[$value]; - } - } - if (empty($value) || isset($exites[$value])) { - $subelement = 'cmi.core.exit'; - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); - } - $value = trim(strtolower($values[0])); - if (isset($statuses[$value]) && ($mode == 'normal')) { - $value = $statuses[$value]; - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); - } - $lessonstatus = $value; - break; - case 'cmi.core.score.raw': - $values = explode(',',$value); - if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) { - $subelement = 'cmi.core.score.max'; - $value = trim($values[1]); - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); - if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) { - $subelement = 'cmi.core.score.min'; - $value = trim($values[2]); - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); - } - } - - $value = ''; - if (is_numeric($values[0])) { - $value = trim($values[0]); - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); - } - $score = $value; - break; - case 'cmi.core.session_time': - $SESSION->scorm_session_time = $value; - break; - } - } - } else { - if (isset($datamodel[strtolower(trim($datarow))])) { - $element = $datamodel[strtolower(trim($datarow))]; - $value = ''; - while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) { - $value .= scorm_utf8_to_entities(datarow); - next($datarows); - } - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); - } - } - } - if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){ - $lessonstatus = 'browsed'; - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed'); - } - if ($mode == 'normal') { - if ($lessonstatus == 'completed') { - if (!empty($sco->masteryscore) && !empty($score) && ($score >= $sco->masteryscore)) { - $lessonstatus = 'passed'; - } else { - $lessonstatus = 'failed'; - } - $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus); - } - } - } - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'putcomments': - if ($status == 'Running') { - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'putinteractions': - if ($status == 'Running') { - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'putobjectives': - if ($status == 'Running') { - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'putpath': - if ($status == 'Running') { - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'putperformance': - if ($status == 'Running') { - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - case 'exitau': - if ($status == 'Running') { - if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) { - if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$sco->id' AND element='cmi.core.total_time'")) { - // Add session_time to total_time - $value = scorm_add_time($track->value, $SESSION->scorm_session_time); - $track->value = $value; - $track->timemodified = time(); - $id = update_record('scorm_scoes_track',$track); - } else { - $track->userid = $USER->id; - $track->scormid = $scorm->id; - $track->scoid = $sco->id; - $track->element = 'cmi.core.total_time'; - $track->value = $SESSION->scorm_session_time; - $track->timemodified = time(); - $id = insert_record('scorm_scoes_track',$track); - } - } - - $SESSION->scorm_status = 'Terminated'; - $SESSION->scorm_session_time = ''; - echo "error = 0\nerror_text = Successful\n"; - } else if ($status == 'Terminated') { - echo "error = 1\nerror_text = Terminated\n"; - } else { - echo "error = 1\nerror_text = Not Initialized\n"; - } - break; - default: - echo "error = 1\nerror_text = Invalid Command\n"; - break; - } - } - } else { - if (empty($command)) { - echo "error = 1\nerror_text = Invalid Command\n"; - } else { - echo "error = 3\nerror_text = Invalid Session ID\n"; - } - } -?> +scorm_scoid)) { + $scoid = $SESSION->scorm_scoid; + } else { + error('Invalid script call'); + } + $mode = 'normal'; + if (isset($SESSION->scorm_mode)) { + $mode = $SESSION->scorm_mode; + } + $status = 'Not Initialized'; + if (isset($SESSION->scorm_status)) { + $status = $SESSION->scorm_status; + } + if (isset($SESSION->attempt)) { + $attempt = $SESSION->attempt; + } else { + $attempt = 1; + } + + if ($sco = get_record('scorm_scoes','id',$scoid)) { + if (!$scorm = get_record('scorm','id',$sco->scorm)) { + error('Invalid script call'); + } + } else { + error('Invalid script call'); + } + + if ($scorm = get_record('scorm','id',$sco->scorm)) { + switch ($command) { + case 'getparam': + if ($status == 'Not Initialized') { + $SESSION->scorm_status = 'Running'; + $status = 'Running'; + } + if ($status != 'Running') { + echo "error = 101\nerror_text = Terminated\n"; + } else { + if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) { + $userdata = $usertrack; + } else { + $userdata->status = ''; + $userdata->score_raw = ''; + } + $userdata->student_id = $USER->username; + $userdata->student_name = $USER->lastname .', '. $USER->firstname; + $userdata->mode = $mode; + if ($userdata->mode == 'normal') { + $userdata->credit = 'credit'; + } else { + $userdata->credit = 'no-credit'; + } + + if ($sco = get_record('scorm_scoes','id',$scoid)) { + $userdata->course_id = $sco->identifier; + $userdata->datafromlms = $sco->datafromlms; + $userdata->masteryscore = $sco->masteryscore; + $userdata->maxtimeallowed = $sco->maxtimeallowed; + $userdata->timelimitaction = $sco->timelimitaction; + + echo "error = 0\nerror_text = Successful\naicc_data=\n"; + echo "[Core]\n"; + echo 'Student_ID = '.$userdata->student_id."\n"; + echo 'Student_Name = '.$userdata->student_name."\n"; + if (isset($userdata->{'cmi.core.lesson_location'})) { + echo 'Lesson_Location = '.$userdata->{'cmi.core.lesson_location'}."\n"; + } else { + echo 'Lesson_Location = '."\n"; + } + echo 'Credit = '.$userdata->credit."\n"; + if (isset($userdata->status)) { + if ($userdata->status == '') { + $userdata->entry = ', ab-initio'; + } else { + if (isset($userdata->{'cmi.core.exit'}) && ($userdata->{'cmi.core.exit'} == 'suspend')) { + $userdata->entry = ', resume'; + } else { + $userdata->entry = ''; + } + } + } + if (isset($userdata->{'cmi.core.lesson_status'})) { + echo 'Lesson_Status = '.$userdata->{'cmi.core.lesson_status'}.$userdata->entry."\n"; + $SESSION->scorm_lessonstatus = $userdata->{'cmi.core.lesson_status'}; + } else { + echo 'Lesson_Status = not attempted'.$userdata->entry."\n"; + $SESSION->scorm_lessonstatus = 'not attempted'; + } + if (isset($userdata->{'cmi.core.score.raw'})) { + $max = ''; + $min = ''; + if (isset($userdata->{'cmi.core.score.max'}) && !empty($userdata->{'cmi.core.score.max'})) { + $max = ', '.$userdata->{'cmi.core.score.max'}; + if (isset($userdata->{'cmi.core.score.min'}) && !empty($userdata->{'cmi.core.score.min'})) { + $min = ', '.$userdata->{'cmi.core.score.min'}; + } + } + echo 'Score = '.$userdata->{'cmi.core.score.raw'}.$max.$min."\n"; + } else { + echo 'Score = '."\n"; + } + if (isset($userdata->{'cmi.core.total_time'})) { + echo 'Time = '.$userdata->{'cmi.core.total_time'}."\n"; + } else { + echo 'Time = '.'00:00:00'."\n"; + } + echo 'Lesson_Mode = '.$userdata->mode."\n"; + if (isset($userdata->{'cmi.suspend_data'})) { + echo "[Core_Lesson]\n".$userdata->{'cmi.suspend_data'}."\n"; + } else { + echo "[Core_Lesson]\n"."\n"; + } + echo "[Core_Vendor]\n".$userdata->datafromlms."\n"; + echo "[Evaluation]\nCourse_ID = {".$userdata->course_id."}\n"; + echo "[Student_Data]\n"; + echo 'Mastery_Score = '.$userdata->masteryscore."\n"; + echo 'Max_Time_Allowed = '.$userdata->maxtimeallowed."\n"; + echo 'Time_Limit_Action = '.$userdata->timelimitaction."\n"; + } else { + error('Sco not found'); + } + } + break; + case 'putparam': + if ($status == 'Running') { + if (!empty($aiccdata) && isstudent($scorm->course)) { + $initlessonstatus = 'not attempted'; + $lessonstatus = 'not attempted'; + if (isset($SESSION->scorm_lessonstatus)) { + $initlessonstatus = $SESSION->scorm_lessonstatus; + } + $score = ''; + $datamodel['lesson_location'] = 'cmi.core.lesson_location'; + $datamodel['lesson_status'] = 'cmi.core.lesson_status'; + $datamodel['score'] = 'cmi.core.score.raw'; + $datamodel['time'] = 'cmi.core.session_time'; + $datamodel['[core_lesson]'] = 'cmi.suspend_data'; + $datamodel['[comments]'] = 'cmi.comments'; + $datarows = explode("\n",$aiccdata); + reset($datarows); + while ((list(,$datarow) = each($datarows)) !== false) { + if (($equal = strpos($datarow, '=')) !== false) { + $element = strtolower(trim(substr($datarow,0,$equal))); + $value = trim(substr($datarow,$equal+1)); + if (isset($datamodel[$element])) { + $element = $datamodel[$element]; + switch ($element) { + case 'cmi.core.lesson_location': + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); + break; + case 'cmi.core.lesson_status': + $statuses = array( + 'passed' => 'passed', + 'completed' => 'completed', + 'failed' => 'failed', + 'incomplete' => 'incomplete', + 'browsed' => 'browsed', + 'not attempted' => 'not attempted', + 'p' => 'passed', + 'c' => 'completed', + 'f' => 'failed', + 'i' => 'incomplete', + 'b' => 'browsed', + 'n' => 'not attempted' + ); + $exites = array( + 'logout' => 'logout', + 'time-out' => 'time-out', + 'suspend' => 'suspend', + 'l' => 'logout', + 't' => 'time-out', + 's' => 'suspend', + ); + $values = explode(',',$value); + $value = ''; + if (count($values) > 1) { + $value = trim(strtolower($values[1])); + if (isset($exites[$value])) { + $value = $exites[$value]; + } + } + if (empty($value) || isset($exites[$value])) { + $subelement = 'cmi.core.exit'; + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); + } + $value = trim(strtolower($values[0])); + if (isset($statuses[$value]) && ($mode == 'normal')) { + $value = $statuses[$value]; + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); + } + $lessonstatus = $value; + break; + case 'cmi.core.score.raw': + $values = explode(',',$value); + if ((count($values) > 1) && ($values[1] >= $values[0]) && is_numeric($values[1])) { + $subelement = 'cmi.core.score.max'; + $value = trim($values[1]); + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); + if ((count($values) == 3) && ($values[2] <= $values[0]) && is_numeric($values[2])) { + $subelement = 'cmi.core.score.min'; + $value = trim($values[2]); + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $subelement, $value); + } + } + + $value = ''; + if (is_numeric($values[0])) { + $value = trim($values[0]); + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); + } + $score = $value; + break; + case 'cmi.core.session_time': + $SESSION->scorm_session_time = $value; + break; + } + } + } else { + if (isset($datamodel[strtolower(trim($datarow))])) { + $element = $datamodel[strtolower(trim($datarow))]; + $value = ''; + while ((($datarow = current($datarows)) !== false) && (substr($datarow,0,1) != '[')) { + $value .= $datarow; + next($datarows); + } + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); + } + } + } + if (($mode == 'browse') && ($initlessonstatus == 'not attempted')){ + $lessonstatus = 'browsed'; + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', 'browsed'); + } + if ($mode == 'normal') { + if ($lessonstatus == 'completed') { + if (!empty($sco->masteryscore) && !empty($score) && ($score >= $sco->masteryscore)) { + $lessonstatus = 'passed'; + } else { + $lessonstatus = 'failed'; + } + $id = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, 'cmi.core.lesson_status', $lessonstatus); + } + } + } + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'putcomments': + if ($status == 'Running') { + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'putinteractions': + if ($status == 'Running') { + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'putobjectives': + if ($status == 'Running') { + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'putpath': + if ($status == 'Running') { + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'putperformance': + if ($status == 'Running') { + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + case 'exitau': + if ($status == 'Running') { + if (isset($SESSION->scorm_session_time) && ($SESSION->scorm_session_time != '')) { + if ($track = get_record_select('scorm_scoes_track',"userid='$USER->id' AND scormid='$scorm->id' AND scoid='$sco->id' AND element='cmi.core.total_time'")) { + // Add session_time to total_time + $value = scorm_add_time($track->value, $SESSION->scorm_session_time); + $track->value = $value; + $track->timemodified = time(); + $id = update_record('scorm_scoes_track',$track); + } else { + $track->userid = $USER->id; + $track->scormid = $scorm->id; + $track->scoid = $sco->id; + $track->element = 'cmi.core.total_time'; + $track->value = $SESSION->scorm_session_time; + $track->timemodified = time(); + $id = insert_record('scorm_scoes_track',$track); + } + } + + $SESSION->scorm_status = 'Terminated'; + $SESSION->scorm_session_time = ''; + echo "error = 0\nerror_text = Successful\n"; + } else if ($status == 'Terminated') { + echo "error = 1\nerror_text = Terminated\n"; + } else { + echo "error = 1\nerror_text = Not Initialized\n"; + } + break; + default: + echo "error = 1\nerror_text = Invalid Command\n"; + break; + } + } + } else { + if (empty($command)) { + echo "error = 1\nerror_text = Invalid Command\n"; + } else { + echo "error = 3\nerror_text = Invalid Session ID\n"; + } + } +?> diff --git a/mod/scorm/api.php b/mod/scorm/api.php index 2d47e1bcb0e..5223fe66e36 100644 --- a/mod/scorm/api.php +++ b/mod/scorm/api.php @@ -1,83 +1,84 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } else { - error('A required parameter is missing'); - } - - require_login($course->id, false, $cm); - - if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) { - $userdata = $usertrack; - } else { - $userdata->status = ''; - $userdata->score_raw = ''; - } - $userdata->student_id = addslashes($USER->username); - $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname); - $userdata->mode = 'normal'; - if (isset($mode)) { - $userdata->mode = $mode; - } - if ($userdata->mode == 'normal') { - $userdata->credit = 'credit'; - } else { - $userdata->credit = 'no-credit'; - } - if ($sco = get_record('scorm_scoes','id',$scoid)) { - $userdata->datafromlms = $sco->datafromlms; - $userdata->masteryscore = $sco->masteryscore; - $userdata->maxtimeallowed = $sco->maxtimeallowed; - $userdata->timelimitaction = $sco->timelimitaction; - } else { - error('Sco not found'); - } - - switch ($scorm->version) { - case 'SCORM_1.2': - include_once ('datamodels/scorm1_2.js.php'); - break; - case 'SCORM_1.3': - include_once ('datamodels/scorm1_3.js.php'); - break; - case 'AICC': - include_once ('datamodels/aicc.js.php'); - break; - default: - include_once ('datamodels/scorm1_2.js.php'); - break; - } -?> - -var errorCode = "0"; -function underscore(str) { - return str.replace(/\./g,"__"); -} +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } else { + error('A required parameter is missing'); + } + + require_login($course->id, false, $cm); + + if ($usertrack=scorm_get_tracks($scoid,$USER->id,$attempt)) { + $userdata = $usertrack; + } else { + $userdata->status = ''; + $userdata->score_raw = ''; + } + $userdata->student_id = addslashes($USER->username); + $userdata->student_name = addslashes($USER->lastname .', '. $USER->firstname); + $userdata->mode = 'normal'; + if (isset($mode)) { + $userdata->mode = $mode; + } + if ($userdata->mode == 'normal') { + $userdata->credit = 'credit'; + } else { + $userdata->credit = 'no-credit'; + } + if ($sco = get_record('scorm_scoes','id',$scoid)) { + $userdata->datafromlms = $sco->datafromlms; + $userdata->masteryscore = $sco->masteryscore; + $userdata->maxtimeallowed = $sco->maxtimeallowed; + $userdata->timelimitaction = $sco->timelimitaction; + } else { + error('Sco not found'); + } + + switch ($scorm->version) { + case 'SCORM_1.2': + include_once ('datamodels/scorm1_2.js.php'); + break; + case 'SCORM_1.3': + include_once ('datamodels/scorm1_3.js.php'); + break; + case 'AICC': + include_once ('datamodels/aicc.js.php'); + break; + default: + include_once ('datamodels/scorm1_2.js.php'); + break; + } +?> + +var errorCode = "0"; +function underscore(str) { + return str.replace(/\./g,"__"); +} diff --git a/mod/scorm/backuplib.php b/mod/scorm/backuplib.php index 33294d7685c..ff049dc4295 100755 --- a/mod/scorm/backuplib.php +++ b/mod/scorm/backuplib.php @@ -61,7 +61,6 @@ fwrite ($bf,full_tag("VERSION",4,false,$scorm->version)); fwrite ($bf,full_tag("MAXGRADE",4,false,$scorm->maxgrade)); fwrite ($bf,full_tag("GRADEMETHOD",4,false,$scorm->grademethod)); - fwrite ($bf,full_tag("MAXATTEMPT",4,false,$scorm->maxattempt)); fwrite ($bf,full_tag("LAUNCH",4,false,$scorm->launch)); fwrite ($bf,full_tag("SUMMARY",4,false,$scorm->summary)); fwrite ($bf,full_tag("HIDEBROWSE",4,false,$scorm->hidebrowse)); @@ -150,7 +149,6 @@ fwrite ($bf,full_tag("ID",6,false,$sco_track->id)); fwrite ($bf,full_tag("USERID",6,false,$sco_track->userid)); fwrite ($bf,full_tag("SCOID",6,false,$sco_track->scoid)); - fwrite ($bf,full_tag("ATTEMPT",6,false,$sco_track->attempt)); fwrite ($bf,full_tag("ELEMENT",6,false,$sco_track->element)); fwrite ($bf,full_tag("VALUE",6,false,$sco_track->value)); //End sco track diff --git a/mod/scorm/coefficientconfirm.php b/mod/scorm/coefficientconfirm.php new file mode 100755 index 00000000000..bc41c389921 --- /dev/null +++ b/mod/scorm/coefficientconfirm.php @@ -0,0 +1,113 @@ +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else { + if (!empty($b)) { + if (! $sco = get_record("scorm_scoes", "id", $b)) { + error("Scorm activity is incorrect"); + } + $a = $sco->scorm; + } + if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + } + + require_login($course->id, false, $cm); + + if (!isteacher($course->id)) { + error("You are not allowed to use this script"); + } + + add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id"); + +/// Print the page header + if (empty($noheader)) { + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } else { + $navigation = ''; + } + + $strscorms = get_string("modulenameplural", "scorm"); + $strscorm = get_string("modulename", "scorm"); + $strreport = get_string("report", "scorm"); + $strname = get_string('name'); + $strcoefficient = get_string('coefficient',"scorm"); + $strcoefficient = "Thiet lap he so"; + if (empty($b)) { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." -> $strcoefficient", + "", "", true); + } else { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." + -> id\">$strreport -> $sco->title", + "", "", true); + } + print_heading(format_string($scorm->name)); + } + + $scormpixdir = $CFG->modpixpath.'/scorm/pix'; + + //Phan trinh bay chinh +?> + + id).' and minnormalizedmeasure > -1'); + foreach ($examScoes as $examSco){ + $newcoefficient = optional_param($examSco->id,'',PARAM_INT); + $sco = get_record('scorm_scoes','scorm',$scorm->id,'id',$examSco->id,'',''); + $sco->score_coefficient = $newcoefficient; + $ketqua = update_record('scorm_scoes',$sco); + //echo "Cap nhat $examSco->id voi he so diem ".$newcoefficient."
"; + } + + if ($ketqua) + { + echo "".get_string('updatesuccess','scorm'); + } + else + { + echo "".get_string('updatefail','scorm'); + } + + echo "

".get_string('back','scorm')."" +?> + diff --git a/mod/scorm/coefficientsetting.php b/mod/scorm/coefficientsetting.php new file mode 100755 index 00000000000..ba949f9b972 --- /dev/null +++ b/mod/scorm/coefficientsetting.php @@ -0,0 +1,120 @@ +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else { + if (!empty($b)) { + if (! $sco = get_record("scorm_scoes", "id", $b)) { + error("Scorm activity is incorrect"); + } + $a = $sco->scorm; + } + if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + } + + require_login($course->id, false, $cm); + + if (!isteacher($course->id)) { + error("You are not allowed to use this script"); + } + + add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id"); + +/// Print the page header + if (empty($noheader)) { + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } else { + $navigation = ''; + } + + $strscorms = get_string("modulenameplural", "scorm"); + $strscorm = get_string("modulename", "scorm"); + $strreport = get_string("report", "scorm"); + $strname = get_string('name'); + $strcoefficient = get_string('coefficient','scorm'); + if (empty($b)) { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." -> $strcoefficient", + "", "", true); + } else { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." + -> id\">$strreport -> $sco->title", + "", "", true); + } + print_heading(format_string($scorm->name)); + } + + $scormpixdir = $CFG->modpixpath.'/scorm/pix'; + + //Phan trinh bay chinh +?> + +
+ + + + + + + id).' and minnormalizedmeasure > -1'); + if(!empty($examScoes)) + { + + foreach ($examScoes as $examSco){ + echo "
"; + } + } + +?> +
"; + echo "$examSco->identifier.score_coefficient />
+
+ + +
+ diff --git a/mod/scorm/datamodel.php b/mod/scorm/datamodel.php index a253d98e873..7adc6b7ccff 100755 --- a/mod/scorm/datamodel.php +++ b/mod/scorm/datamodel.php @@ -1,54 +1,67 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } else { - error('A required parameter is missing'); - } - - require_login($course->id, false, $cm); - - if (confirm_sesskey() && (!empty($scoid))) { - $result = true; - if (isstudent($course->id) || (isteacher($course->id) && !isadmin())) { - foreach ($_POST as $element => $value) { - if (substr($element,0,3) == 'cmi') { - $element = str_replace('__','.',$element); - $element = preg_replace('/_(\d+)/',".\$1",$element); - $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value) && $result; - } - } - } - if ($result) { - echo "true\n0"; - } else { - echo "false\n101"; - } - } -?> - +attempt; + //fwrite($ft,"\n --------Gia tri attempt thu duoc tu datamodel.php-------- : ".$attempt); + + + if (!empty($id)) { + if (! $cm = get_record("course_modules", "id", $id)) { + error("Course Module ID was incorrect"); + } + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } else { + error('A required parameter is missing'); + } + + require_login($course->id, false, $cm); + + if (confirm_sesskey() && (!empty($scoid))) { + //fwrite($ft," --Ghi du lieu--- \n"); + $result = true; + if (isstudent($course->id) || (isteacher($course->id) && !isadmin())) { + foreach ($_POST as $element => $value) { + if (substr($element,0,3) == 'cmi') { + $element = str_replace('__','.',$element); + $element = preg_replace('/_(\d+)/',".\$1",$element); + $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $element, $value) && $result; + //fwrite($ft,"\n Ghi xong mot phan tu tai Datamodel.php-- ".$scoid); + + } + } + } + if ($result) { + echo "true\n0"; + //fwrite($ft,"Ghi thanh cong trong Datamodel.php-"); + } else { + echo "false\n101"; + //fwrite($ft,"Ghi that bai trong Datamodel.php-"); + } + } +?> + diff --git a/mod/scorm/index.php b/mod/scorm/index.php index faffd41b8fc..34c1489412c 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -1,94 +1,96 @@ -id, "scorm", "view all", "index.php?id=$course->id", ""); - - $strscorm = get_string("modulename", "scorm"); - $strscorms = get_string("modulenameplural", "scorm"); - $strweek = get_string("week"); - $strtopic = get_string("topic"); - $strname = get_string("name"); - $strsummary = get_string("summary"); - $strreport = get_string("report",'scorm'); - $strlastmodified = get_string("lastmodified"); - - print_header_simple("$strscorms", "", "$strscorms", - "", "", true, "", navmenu($course)); - - if ($course->format == "weeks" or $course->format == "topics") { - $sortorder = "cw.section ASC"; - } else { - $sortorder = "m.timemodified DESC"; - } - - if (! $scorms = get_all_instances_in_course("scorm", $course)) { - notice("There are no scorms", "../../course/view.php?id=$course->id"); - exit; - } - - if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strsummary, $strreport); - $table->align = array ("center", "left", "left", "left"); - } else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strsummary, $strreport); - $table->align = array ("center", "left", "left", "left"); - } else { - $table->head = array ($strlastmodified, $strname, $strsummary, $strreport); - $table->align = array ("left", "left", "left", "left"); - } - - foreach ($scorms as $scorm) { - - $tt = ""; - if ($course->format == "weeks" or $course->format == "topics") { - if ($scorm->section) { - $tt = "$scorm->section"; - } - } else { - $tt = userdate($scorm->timemodified); - } - $report = ' '; - if (isteacher($course->id)) { - $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); - if ($trackedusers->c > 0) { - $report = ''.get_string('viewallreports','scorm',$trackedusers->c).''; - } else { - $report = get_string('noreports','scorm'); - } - } else if (isstudent($course->id)) { - require_once('locallib.php'); - $report = scorm_grade_user(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod); - } - if (!$scorm->visible) { - //Show dimmed if the mod is hidden - $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", - format_text($scorm->summary), $report); - } else { - //Show normal if the mod is visible - $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", - format_text($scorm->summary), $report); - } - } - - echo "
"; - - print_table($table); - - print_footer($course); - - -?> - +id, "scorm", "view all", "index.php?id=$course->id", ""); + + $strscorm = get_string("modulename", "scorm"); + $strscorms = get_string("modulenameplural", "scorm"); + $strweek = get_string("week"); + $strtopic = get_string("topic"); + $strname = get_string("name"); + $strsummary = get_string("summary"); + $strreport = get_string("report",'scorm'); + $strlastmodified = get_string("lastmodified"); + + print_header_simple("$strscorms", "", "$strscorms", + "", "", true, "", navmenu($course)); + + if ($course->format == "weeks" or $course->format == "topics") { + $sortorder = "cw.section ASC"; + } else { + $sortorder = "m.timemodified DESC"; + } + + if (! $scorms = get_all_instances_in_course("scorm", $course)) { + notice("There are no scorms", "../../course/view.php?id=$course->id"); + exit; + } + + if ($course->format == "weeks") { + $table->head = array ($strweek, $strname, $strsummary, $strreport); + $table->align = array ("center", "left", "left", "left"); + } else if ($course->format == "topics") { + $table->head = array ($strtopic, $strname, $strsummary, $strreport); + $table->align = array ("center", "left", "left", "left"); + } else { + $table->head = array ($strlastmodified, $strname, $strsummary, $strreport); + $table->align = array ("left", "left", "left", "left"); + } + + foreach ($scorms as $scorm) { + + $tt = ""; + if ($course->format == "weeks" or $course->format == "topics") { + if ($scorm->section) { + $tt = "$scorm->section"; + } + } else { + $tt = userdate($scorm->timemodified); + } + $report = ' '; + if (isteacher($course->id)) { + $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); + if ($trackedusers->c > 0) { + $reportshow = ''.get_string('viewallreports','scorm',$trackedusers->c).''; + } else { + $reportshow = get_string('noreports','scorm'); + } + } else if (isstudent($course->id)) { + require_once('locallib.php'); + $report = scorm_grade_user_new(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod); + $sco_count = scorm_get_user_sco_count($scorm->id,$USER->id); + $reportshow = get_string('implement','scorm').$sco_count.get_string('lesson','scorm') ."
".get_string('scoreRate','scorm').": ".($report*100)."%"; } + if (!$scorm->visible) { + //Show dimmed if the mod is hidden + $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", + format_text($scorm->summary),$reportshow); + } else { + //Show normal if the mod is visible + $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", + format_text($scorm->summary), $reportshow); + } + } + + echo "
"; + + print_table($table); + + print_footer($course); + + +?> + diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 8fe635a23fe..be729b8212d 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1,532 +1,565 @@ - get_string('gradescoes', 'scorm'), - GRADEHIGHEST => get_string('gradehighest', 'scorm'), - GRADEAVERAGE => get_string('gradeaverage', 'scorm'), - GRADESUM => get_string('gradesum', 'scorm')); - -define('VALUEHIGHEST', '0'); -define('VALUEAVERAGE', '1'); -define('VALUEFIRST', '2'); -define('VALUELAST', '3'); -$SCORM_WHAT_GRADE = array (VALUEHIGHEST => get_string('highestattempt', 'scorm'), - VALUEAVERAGE => get_string('averageattempt', 'scorm'), - VALUEFIRST => get_string('firstattempt', 'scorm'), - VALUELAST => get_string('lastattempt', 'scorm')); - -$SCORM_POPUP_OPTIONS = array('resizable'=>1, - 'scrollbars'=>1, - 'directories'=>0, - 'location'=>0, - 'menubar'=>0, - 'toolbar'=>0, - 'status'=>0); -$stdoptions = ''; -foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) { - $stdoptions .= $popupopt.'='.$value; - if ($popupopt != 'status') { - $stdoptions .= ','; - } -} - -if (!isset($CFG->scorm_maxattempts)) { - set_config('scorm_maxattempts','6'); -} - -if (!isset($CFG->scorm_frameheight)) { - set_config('scorm_frameheight','500'); -} - -if (!isset($CFG->scorm_framewidth)) { - set_config('scorm_framewidth','100%'); -} - -/** -* Given an object containing all the necessary data, -* (defined by the form in mod.html) this function -* will create a new instance and return the id number -* of the new instance. -* -* @param mixed $scorm Form data -* @return int -*/ -function scorm_add_instance($scorm) { - - global $CFG; - $scorm->timemodified = time(); - - $scorm = scorm_option2text($scorm); - $scorm->width = str_replace('%','',$scorm->width); - $scorm->height = str_replace('%','',$scorm->height); - - $id = insert_record('scorm', $scorm); - - if (basename($scorm->reference) != 'imsmanifest.xml') { - // Rename temp scorm dir to scorm id - $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; - rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id); - } - - // Parse scorm manifest - if ($scorm->launch == 0) { - require_once('locallib.php'); - $scorm->id = $id; - $scorm->launch = scorm_parse($scorm); - set_field('scorm','launch',$scorm->launch,'id',$scorm->id); - } - - return $id; -} - -/** -* Given an object containing all the necessary data, -* (defined by the form in mod.html) this function -* will update an existing instance with new data. -* -* @param mixed $scorm Form data -* @return int -*/ -function scorm_update_instance($scorm) { - - global $CFG; - - $scorm->timemodified = time(); - $scorm->id = $scorm->instance; - - $scorm = scorm_option2text($scorm); - $scorm->width = str_replace('%','',$scorm->width); - $scorm->height = str_replace('%','',$scorm->height); - - // Check if scorm manifest needs to be reparsed - if ($scorm->launch == 0) { - // Delete old related records - delete_records('scorm_scoes','scorm',$scorm->id); - delete_records('scorm_scoes_track','scormid',$scorm->id); - - $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; - if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) { - scorm_delete_files($scorm->dir.'/'.$scorm->id); - rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id); - } - - require_once('locallib.php'); - $scorm->launch = scorm_parse($scorm); - } - - return update_record('scorm', $scorm); -} - -/** -* Given an ID of an instance of this module, -* this function will permanently delete the instance -* and any data that depends on it. -* -* @param int $id Scorm instance id -* @return boolean -*/ -function scorm_delete_instance($id) { - - global $CFG; - - if (! $scorm = get_record('scorm', 'id', $id)) { - return false; - } - - $result = true; - - // Delete any dependent files - scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id); - - // Delete any dependent records - if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) { - $result = false; - } - if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) { - $result = false; - } - if (! delete_records('scorm', 'id', $scorm->id)) { - $result = false; - } - - return $result; -} - -/** -* Return a small object with summary information about what a -* user has done with a given particular instance of this module -* Used for user activity reports. -* -* @param int $course Course id -* @param int $user User id -* @param int $mod -* @param int $scorm The scorm id -* @return mixed -*/ -function scorm_user_outline($course, $user, $mod, $scorm) { - - $return = NULL; - $scores->values = 0; - $scores->sum = 0; - $scores->max = 0; - $scores->lastmodify = 0; - $scores->count = 0; - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { - require_once('locallib.php'); - foreach ($scoes as $sco) { - if ($sco->launch!='') { - $scores->count++; - if ($userdata = scorm_get_tracks($sco->id, $user->id)) { - if (!isset($scores->{$userdata->status})) { - $scores->{$userdata->status} = 1; - } else { - $scores->{$userdata->status}++; - } - if (!empty($userdata->score_raw)) { - $scores->values++; - $scores->sum += $userdata->score_raw; - $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; - } - if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) { - $scores->lastmodify = $userdata->timemodified; - } - } - } - } - switch ($scorm->grademethod) { - case VALUEHIGHEST: - if ($scores->values > 0) { - $return->info = get_string('score','scorm').': '.$scores->max; - $return->time = $scores->lastmodify; - } - break; - case VALUEAVERAGE: - if ($scores->values > 0) { - $return->info = get_string('score','scorm').': '.$scores->sum/$scores->values; - $return->time = $scores->lastmodify; - } - break; - case VALUESUM: - if ($scores->values > 0) { - $return->info = get_string('score','scorm').': '.$scores->sum; - $return->time = $scores->lastmodify; - } - break; - case VALUESCOES: - $return->info = ''; - $scores->notattempted = $scores->count; - if (isset($scores->completed)) { - $return->info .= get_string('completed','scorm').': '.$scores->completed.'
'; - $scores->notattempted -= $scores->completed; - } - if (isset($scores->passed)) { - $return->info .= get_string('passed','scorm').': '.$scores->passed.'
'; - $scores->notattempted -= $scores->passed; - } - if (isset($scores->failed)) { - $return->info .= get_string('failed','scorm').': '.$scores->failed.'
'; - $scores->notattempted -= $scores->failed; - } - if (isset($scores->incomplete)) { - $return->info .= get_string('incomplete','scorm').': '.$scores->incomplete.'
'; - $scores->notattempted -= $scores->incomplete; - } - if (isset($scores->browsed)) { - $return->info .= get_string('browsed','scorm').': '.$scores->browsed.'
'; - $scores->notattempted -= $scores->browsed; - } - $return->time = $scores->lastmodify; - if ($return->info == '') { - $return = NULL; - } else { - $return->info .= get_string('notattempted','scorm').': '.$scores->notattempted.'
'; - } - break; - } - } - return $return; -} - -/** -* Print a detailed representation of what a user has done with -* a given particular instance of this module, for user activity reports. -* -* @param int $course Course id -* @param int $user User id -* @param int $mod -* @param int $scorm The scorm id -* @return boolean -*/ -function scorm_user_complete($course, $user, $mod, $scorm) { - global $CFG; - - $liststyle = 'structlist'; - $scormpixdir = $CFG->modpixpath.'/scorm/pix'; - $now = time(); - $firstmodify = $now; - $lastmodify = 0; - $sometoreport = false; - $report = ''; - - if ($orgs = get_records_select('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,identifier,title')) { - if (count($orgs) <= 1) { - unset($orgs); - $orgs[]->identifier = ''; - } - $report .= '
'."\n"; - foreach ($orgs as $org) { - $organizationsql = ''; - $currentorg = ''; - if (!empty($org->identifier)) { - $report .= '
'.$org->title.'
'; - $currentorg = $org->identifier; - $organizationsql = "AND organization='$currentorg'"; - } - $report .= "\n"; - $level--; - } else { - $i = $level; - $closelist = ''; - while (($i > 0) && ($parents[$level] != $sco->parent)) { - $closelist .= "\t\t\n"; - $i--; - } - if (($i == 0) && ($sco->parent != $currentorg)) { - $report .= "\t\t
  • \n"; - } - } - $report .= "\t
    \n"; - } - $report .= "
    \n"; - } - if ($sometoreport) { - if ($firstmodify < $now) { - $timeago = format_time($now - $firstmodify); - echo get_string('firstaccess','scorm').': '.userdate($firstmodify).' ('.$timeago.")
    \n"; - } - if ($lastmodify > 0) { - $timeago = format_time($now - $lastmodify); - echo get_string('lastaccess','scorm').': '.userdate($lastmodify).' ('.$timeago.")
    \n"; - } - echo get_string('report','scorm').":
    \n"; - echo $report; - } else { - print_string('noactivity','scorm'); - } - - return true; -} - -/** -* Given a list of logs, assumed to be those since the last login -* this function prints a short list of changes related to this module -* If isteacher is true then perhaps additional information is printed. -* This function is called from course/lib.php: print_recent_activity() -* -* @param reference $logs Logs reference -* @param boolean $isteacher -* @return boolean -*/ -function scorm_print_recent_activity(&$logs, $isteacher=false) { - return false; // True if anything was printed, otherwise false -} - -/** -* Function to be run periodically according to the moodle cron -* This function searches for things that need to be done, such -* as sending out mail, toggling flags etc ... -* -* @return boolean -*/ -function scorm_cron () { - - global $CFG; - - return true; -} - -/** -* Given a scorm id return all the grades of that activity -* -* @param int $scormid Scorm instance id -* @return mixed -*/ -function scorm_grades($scormid) { - - global $CFG; - - if (!$scorm = get_record('scorm', 'id', $scormid)) { - return NULL; - } - if (!$scoes = get_records('scorm_scoes','scorm',$scormid)) { - return NULL; - } - - if ($scorm->grademethod == GRADESCOES) { - if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) { - return NULL; - } - } else { - $return->maxgrade = $scorm->maxgrade; - } - - $return->grades = NULL; - if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scormid' GROUP BY userid", "", "userid,null")) { - require_once('locallib.php'); - foreach ($scousers as $scouser) { - $return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod); - } - } - return $return; -} - -function scorm_get_view_actions() { - return array('pre-view','view','view all','report'); -} - -function scorm_get_post_actions() { - return array(); -} - -/** -* This function will permanently delete the given -* directory and all files and subdirectories. -* -* @param string $directory The directory to remove -* @return boolean -*/ -function scorm_delete_files($directory) { - if (is_dir($directory)) { - $files=scorm_scandir($directory); - foreach($files as $file) { - if (($file != '.') && ($file != '..')) { - if (!is_dir($directory.'/'.$file)) { - unlink($directory.'/'.$file); - } else { - scorm_delete_files($directory.'/'.$file); - } - } - } - rmdir($directory); - return true; - } - return false; -} - -/** -* Given a diretory path returns the file list -* -* @param string $directory -* @return array -*/ -function scorm_scandir($directory) { - if (version_compare(phpversion(),'5.0.0','>=')) { - return scandir($directory); - } else { - $files = array(); - if ($dh = opendir($directory)) { - while (($file = readdir($dh)) !== false) { - $files[] = $file; - } - closedir($dh); - } - return $files; - } -} - -function scorm_option2text($scorm) { - global $SCORM_POPUP_OPTIONS; - - if (isset($scorm->popup)) { - if ($scorm->popup) { - $optionlist = array(); - foreach ($SCORM_POPUP_OPTIONS as $option) { - if (isset($scorm->$option)) { - $optionlist[] = $option.'='.$scorm->$option; - } else { - $optionlist[] = $option.'=0'; - } - } - $scorm->options = implode(',', $optionlist); - } else { - $scorm->options = ''; - } - } else { - $scorm->popup = 0; - $scorm->options = ''; - } - return $scorm; -} - -?> + get_string('gradescoes', 'scorm'), + GRADEHIGHEST => get_string('gradehighest', 'scorm'), + GRADEAVERAGE => get_string('gradeaverage', 'scorm'), + GRADESUM => get_string('gradesum', 'scorm')); + +define('VALUEHIGHEST', '0'); +define('VALUEAVERAGE', '1'); +define('VALUEFIRST', '2'); +define('VALUELAST', '3'); +$SCORM_WHAT_GRADE = array (VALUEHIGHEST => get_string('highestattempt', 'scorm'), + VALUEAVERAGE => get_string('averageattempt', 'scorm'), + VALUEFIRST => get_string('firstattempt', 'scorm'), + VALUELAST => get_string('lastattempt', 'scorm')); + +$SCORM_POPUP_OPTIONS = array('resizable'=>1, + 'scrollbars'=>1, + 'directories'=>0, + 'location'=>0, + 'menubar'=>0, + 'toolbar'=>0, + 'status'=>0); +$stdoptions = ''; +foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) { + $stdoptions .= $popupopt.'='.$value; + if ($popupopt != 'status') { + $stdoptions .= ','; + } +} + +if (!isset($CFG->scorm_maxattempts)) { + set_config('scorm_maxattempts','6'); +} + +if (!isset($CFG->scorm_frameheight)) { + set_config('scorm_frameheight','500'); +} + +if (!isset($CFG->scorm_framewidth)) { + set_config('scorm_framewidth','100%'); +} + +/** +* Given an object containing all the necessary data, +* (defined by the form in mod.html) this function +* will create a new instance and return the id number +* of the new instance. +* +* @param mixed $scorm Form data +* @return int +*/ +function scorm_add_instance($scorm) { + + global $CFG; + $scorm->timemodified = time(); + + $scorm = scorm_option2text($scorm); + $scorm->width = str_replace('%','',$scorm->width); + $scorm->height = str_replace('%','',$scorm->height); + + $id = insert_record('scorm', $scorm); + + if (basename($scorm->reference) != 'imsmanifest.xml') { + // Rename temp scorm dir to scorm id + $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; + rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id); + } + + // Parse scorm manifest + if ($scorm->launch == 0) { + require_once('locallib.php'); + $scorm->id = $id; + $scorm->launch = scorm_parse($scorm); + set_field('scorm','launch',$scorm->launch,'id',$scorm->id); + } + + return $id; +} + +/** +* Given an object containing all the necessary data, +* (defined by the form in mod.html) this function +* will update an existing instance with new data. +* +* @param mixed $scorm Form data +* @return int +*/ +function scorm_update_instance($scorm) { + + global $CFG; + + $scorm->timemodified = time(); + $scorm->id = $scorm->instance; + + $scorm = scorm_option2text($scorm); + $scorm->width = str_replace('%','',$scorm->width); + $scorm->height = str_replace('%','',$scorm->height); + + // Check if scorm manifest needs to be reparsed + if ($scorm->launch == 0) { + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //fwrite($ft,"\n Xu ly trong update trong lib.php \n"); + //fwrite($ft,"\n Lauch co gia tri \n".($scorm->launch)); + + // Delete old related records + delete_records('scorm_scoes','scorm',$scorm->id); + delete_records('scorm_scoes_track','scormid',$scorm->id); + delete_records('scorm_sequencing_controlmode','scormid',$scorm->id); + delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id); + delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id); + delete_records('scorm_sequencing_rollupruleconditions','scormid',$scorm->id); + delete_records('scorm_sequencing_rolluprulecondition','scormid',$scorm->id); + delete_records('scorm_sequencing_ruleconditions','scormid',$scorm->id); + delete_records('scorm_sequencing_rulecondition','scormid',$scorm->id); + + + $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; + if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) { + scorm_delete_files($scorm->dir.'/'.$scorm->id); + rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id); + } + + require_once('locallib.php'); + $scorm->launch = scorm_parse($scorm); + } + + return update_record('scorm', $scorm); +} + +/** +* Given an ID of an instance of this module, +* this function will permanently delete the instance +* and any data that depends on it. +* +* @param int $id Scorm instance id +* @return boolean +*/ +function scorm_delete_instance($id) { + + global $CFG; + + if (! $scorm = get_record('scorm', 'id', $id)) { + return false; + } + + $result = true; + + // Delete any dependent files + scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id); + + // Delete any dependent records + if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm', 'id', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_rolluprule', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_rollupruleconditions', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_rolluprulecondition', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_rulecondition', 'scormid', $scorm->id)) { + $result = false; + } + if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) { + $result = false; + } + return $result; +} + +/** +* Return a small object with summary information about what a +* user has done with a given particular instance of this module +* Used for user activity reports. +* +* @param int $course Course id +* @param int $user User id +* @param int $mod +* @param int $scorm The scorm id +* @return mixed +*/ +function scorm_user_outline($course, $user, $mod, $scorm) { + + $return = NULL; + $scores->values = 0; + $scores->sum = 0; + $scores->max = 0; + $scores->lastmodify = 0; + $scores->count = 0; + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { + require_once('locallib.php'); + foreach ($scoes as $sco) { + if ($sco->launch!='') { + $scores->count++; + if ($userdata = scorm_get_tracks($sco->id, $user->id)) { + if (!isset($scores->{$userdata->status})) { + $scores->{$userdata->status} = 1; + } else { + $scores->{$userdata->status}++; + } + if (!empty($userdata->score_raw)) { + $scores->values++; + $scores->sum += $userdata->score_raw; + $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; + } + if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) { + $scores->lastmodify = $userdata->timemodified; + } + } + } + } + switch ($scorm->grademethod) { + case VALUEHIGHEST: + if ($scores->values > 0) { + $return->info = get_string('score','scorm').': '.$scores->max; + $return->time = $scores->lastmodify; + } + break; + case VALUEAVERAGE: + if ($scores->values > 0) { + $return->info = get_string('score','scorm').': '.$scores->sum/$scores->values; + $return->time = $scores->lastmodify; + } + break; + case VALUESUM: + if ($scores->values > 0) { + $return->info = get_string('score','scorm').': '.$scores->sum; + $return->time = $scores->lastmodify; + } + break; + case VALUESCOES: + $return->info = ''; + $scores->notattempted = $scores->count; + if (isset($scores->completed)) { + $return->info .= get_string('completed','scorm').': '.$scores->completed.'
    '; + $scores->notattempted -= $scores->completed; + } + if (isset($scores->passed)) { + $return->info .= get_string('passed','scorm').': '.$scores->passed.'
    '; + $scores->notattempted -= $scores->passed; + } + if (isset($scores->failed)) { + $return->info .= get_string('failed','scorm').': '.$scores->failed.'
    '; + $scores->notattempted -= $scores->failed; + } + if (isset($scores->incomplete)) { + $return->info .= get_string('incomplete','scorm').': '.$scores->incomplete.'
    '; + $scores->notattempted -= $scores->incomplete; + } + if (isset($scores->browsed)) { + $return->info .= get_string('browsed','scorm').': '.$scores->browsed.'
    '; + $scores->notattempted -= $scores->browsed; + } + $return->time = $scores->lastmodify; + if ($return->info == '') { + $return = NULL; + } else { + $return->info .= get_string('notattempted','scorm').': '.$scores->notattempted.'
    '; + } + break; + } + } + return $return; +} + +/** +* Print a detailed representation of what a user has done with +* a given particular instance of this module, for user activity reports. +* +* @param int $course Course id +* @param int $user User id +* @param int $mod +* @param int $scorm The scorm id +* @return boolean +*/ +function scorm_user_complete($course, $user, $mod, $scorm) { + global $CFG; + + $liststyle = 'structlist'; + $scormpixdir = $CFG->modpixpath.'/scorm/pix'; + $now = time(); + $firstmodify = $now; + $lastmodify = 0; + $sometoreport = false; + $report = ''; + + if ($orgs = get_records_select('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,identifier,title')) { + if (count($orgs) <= 1) { + unset($orgs); + $orgs[]->identifier = ''; + } + $report .= '
    '."\n"; + foreach ($orgs as $org) { + $organizationsql = ''; + $currentorg = ''; + if (!empty($org->identifier)) { + $report .= '
    '.$org->title.'
    '; + $currentorg = $org->identifier; + $organizationsql = "AND organization='$currentorg'"; + } + $report .= "\n"; + $level--; + } else { + $i = $level; + $closelist = ''; + while (($i > 0) && ($parents[$level] != $sco->parent)) { + $closelist .= "\t\t\n"; + $i--; + } + if (($i == 0) && ($sco->parent != $currentorg)) { + $report .= "\t\t
  • \n"; + } + } + $report .= "\t
    \n"; + } + $report .= "
    \n"; + } + if ($sometoreport) { + if ($firstmodify < $now) { + $timeago = format_time($now - $firstmodify); + echo get_string('firstaccess','scorm').': '.userdate($firstmodify).' ('.$timeago.")
    \n"; + } + if ($lastmodify > 0) { + $timeago = format_time($now - $lastmodify); + echo get_string('lastaccess','scorm').': '.userdate($lastmodify).' ('.$timeago.")
    \n"; + } + echo get_string('report','scorm').":
    \n"; + echo $report; + } else { + print_string('noactivity','scorm'); + } + + return true; +} + +/** +* Given a list of logs, assumed to be those since the last login +* this function prints a short list of changes related to this module +* If isteacher is true then perhaps additional information is printed. +* This function is called from course/lib.php: print_recent_activity() +* +* @param reference $logs Logs reference +* @param boolean $isteacher +* @return boolean +*/ +function scorm_print_recent_activity(&$logs, $isteacher=false) { + return false; // True if anything was printed, otherwise false +} + +/** +* Function to be run periodically according to the moodle cron +* This function searches for things that need to be done, such +* as sending out mail, toggling flags etc ... +* +* @return boolean +*/ +function scorm_cron () { + + global $CFG; + + return true; +} + +/** +* Given a scorm id return all the grades of that activity +* +* @param int $scormid Scorm instance id +* @return mixed +*/ +function scorm_grades($scormid) { + + global $CFG; + + if (!$scorm = get_record('scorm', 'id', $scormid)) { + return NULL; + } + if (!$scoes = get_records('scorm_scoes','scorm',$scormid)) { + return NULL; + } + + if ($scorm->grademethod == VALUESCOES) { + if (!$return->maxgrade = count_records_select('scorm_scoes',"scorm='$scormid' AND launch<>''")) { + return NULL; + } + } else { + $return->maxgrade = $scorm->maxgrade; + } + + $return->grades = NULL; + if ($scousers=get_records_select('scorm_scoes_track', "scormid='$scormid' GROUP BY userid", "", "userid,null")) { + require_once('locallib.php'); + foreach ($scousers as $scouser) { + $return->grades[$scouser->userid] = scorm_grade_user($scoes, $scouser->userid, $scorm->grademethod); + } + } + return $return; +} + +function scorm_get_view_actions() { + return array('pre-view','view','view all','report'); +} + +function scorm_get_post_actions() { + return array(); +} + +/** +* This function will permanently delete the given +* directory and all files and subdirectories. +* +* @param string $directory The directory to remove +* @return boolean +*/ +function scorm_delete_files($directory) { + if (is_dir($directory)) { + $files=scorm_scandir($directory); + foreach($files as $file) { + if (($file != '.') && ($file != '..')) { + if (!is_dir($directory.'/'.$file)) { + unlink($directory.'/'.$file); + } else { + scorm_delete_files($directory.'/'.$file); + } + } + } + rmdir($directory); + return true; + } + return false; +} + +/** +* Given a diretory path returns the file list +* +* @param string $directory +* @return array +*/ +function scorm_scandir($directory) { + if (version_compare(phpversion(),'5.0.0','>=')) { + return scandir($directory); + } else { + $files = array(); + if ($dh = opendir($directory)) { + while (($file = readdir($dh)) !== false) { + $files[] = $file; + } + closedir($dh); + } + return $files; + } +} + +function scorm_option2text($scorm) { + global $SCORM_POPUP_OPTIONS; + + if (isset($scorm->popup)) { + if ($scorm->popup) { + $optionlist = array(); + foreach ($SCORM_POPUP_OPTIONS as $option) { + if (isset($scorm->$option)) { + $optionlist[] = $option.'='.$scorm->$option; + } else { + $optionlist[] = $option.'=0'; + } + } + $scorm->options = implode(',', $optionlist); + } else { + $scorm->options = ''; + } + } else { + $scorm->popup = 0; + $scorm->options = ''; + } + return $scorm; +} + +?> diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index 2b303b432c2..bce2b6f4fa0 100755 --- a/mod/scorm/loadSCO.php +++ b/mod/scorm/loadSCO.php @@ -1,110 +1,111 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } else { - error('A required parameter is missing'); - } - - require_login($course->id, false, $cm); - if (!empty($scoid)) { - // - // Direct sco request - // - if ($sco = get_record("scorm_scoes","id",$scoid)) { - if ($sco->launch == '') { - // Search for the next launchable sco - if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) { - $sco = current($scoes); - } - } - } - } - // - // If no sco was found get the first of SCORM package - // - if (!isset($sco)) { - $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC"); - $sco = current($scoes); - } - - // - // Forge SCO URL - // - $connector = ''; - $version = substr($scorm->version,0,4); - if (!empty($sco->parameters) || ($version == 'AICC')) { - if (stripos($sco->launch,'?') !== false) { - $connector = '&'; - } else { - $connector = '?'; - } - if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) { - $sco->parameters = substr($sco->parameters,1); - } - } - - if ($version == 'AICC') { - if (!empty($sco->parameters)) { - $sco->parameters = '&'. $sco->parameters; - } - $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters; - } else { - $launcher = $sco->launch.$connector.$sco->parameters; - } - - if (scorm_external_link($sco->launch)) { - $result = $launcher; - } else { - if (basename($scorm->reference) == 'imsmanifest.xml') { - $basedir = dirname($scorm->reference); - } else { - $basedir = 'moddata/scorm/'.$scorm->id; - } - if ($CFG->slasharguments) { - $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher; - } else { - $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher; - } - } -?> - - - LoadSCO - - - - -   - - +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } else { + error('A required parameter is missing'); + } + + require_login($course->id, false, $cm); + if (!empty($scoid)) { + // + // Dinh huong yeu cau cua SCO + // + if ($sco = get_record("scorm_scoes","id",$scoid)) { + if ($sco->launch == '') { + // Tim kiem SCO co the trien khai tiep theo + if ($scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>'' AND id>".$sco->id,"id ASC")) { + $sco = current($scoes); + } + } + } + } + // + // If no sco was found get the first of SCORM package + // + if (!isset($sco)) { + $scoes = get_records_select("scorm_scoes","scorm=".$scorm->id." AND launch<>''","id ASC"); + $sco = current($scoes); + } + + // + // Forge SCO URL + // + $connector = ''; + $version = substr($scorm->version,0,4); + if (!empty($sco->parameters) || ($version == 'AICC')) { + if (stripos($sco->launch,'?') !== false) { + $connector = '&'; + } else { + $connector = '?'; + } + if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) { + $sco->parameters = substr($sco->parameters,1); + } + } + + if ($version == 'AICC') { + if (!empty($sco->parameters)) { + $sco->parameters = '&'. $sco->parameters; + } + $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$sco->parameters; + } else { + $launcher = $sco->launch.$connector.$sco->parameters; + } + + if (scorm_external_link($sco->launch)) { + $result = $launcher; + } else { + if (basename($scorm->reference) == 'imsmanifest.xml') { + $basedir = dirname($scorm->reference); + } else { + $basedir = 'moddata/scorm/'.$scorm->id; + } + if ($CFG->slasharguments) { + $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher; + } else { + $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher; + } + } +?> + + + LoadSCO + + + + +   + + diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 6093981f24b..720544316a4 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -1,1350 +1,2065 @@ -directorypermissions); - @chmod($strPath.$datadir, $CFG->directorypermissions); // Just in case mkdir didn't do it - return $strPath.$datadir; - } else { - return false; - } -} - -/** -* Given a package directory, this function will check if the package is valid -* -* @param string $packagedir The package directory -* @return mixed -*/ -function scorm_validate($packagedir) { - $validation = new stdClass(); - if (is_file($packagedir.'/imsmanifest.xml')) { - $validation->result = 'found'; - $validation->pkgtype = 'SCORM'; - } else { - if ($handle = opendir($packagedir)) { - while (($file = readdir($handle)) !== false) { - $ext = substr($file,strrpos($file,'.')); - if (strtolower($ext) == '.cst') { - $validation->result = 'found'; - $validation->pkgtype = 'AICC'; - break; - } - } - closedir($handle); - } - if (!isset($validation)) { - $validation->result = 'nomanifest'; - $validation->pkgtype = 'SCORM'; - } - } - return $validation; -} - -function scorm_get_user_data($userid) { -/// Gets user info required to display the table of scorm results -/// for report.php - - return get_record('user','id',$userid,'','','','','firstname, lastname, picture'); -} - -function scorm_string_wrap($stringa, $len=15) { -// Crop the given string into max $len characters lines - $textlib = textlib_get_instance(); - if ($textlib->strlen($stringa, current_charset()) > $len) { - $words = explode(' ', $stringa); - $newstring = ''; - $substring = ''; - foreach ($words as $word) { - if (($textlib->strlen($substring, current_charset())+$textlib->strlen($word, current_charset())+1) < $len) { - $substring .= ' '.$word; - } else { - $newstring .= ' '.$substring.'
    '; - $substring = $word; - } - } - if (!empty($substring)) { - $newstring .= ' '.$substring; - } - return $newstring; - } else { - return $stringa; - } -} - -function scorm_eval_prerequisites($prerequisites,$usertracks) { - $element = ''; - $stack = array(); - $statuses = array( - 'passed' => 'passed', - 'completed' => 'completed', - 'failed' => 'failed', - 'incomplete' => 'incomplete', - 'browsed' => 'browsed', - 'not attempted' => 'notattempted', - 'p' => 'passed', - 'c' => 'completed', - 'f' => 'failed', - 'i' => 'incomplete', - 'b' => 'browsed', - 'n' => 'notattempted' - ); - $i=0; - while ($istatus.'\' == \'completed\') || '. - '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; - } else if (($operator = strpos($element,'=')) !== false) { - $item = trim(substr($element,0,$operator)); - if (!isset($usertracks[$item])) { - return false; - } - - $value = trim(trim(substr($element,$operator+1)),'"'); - if (isset($statuses[$value])) { - $status = $statuses[$value]; - } else { - return false; - } - - $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')'; - } else if (($operator = strpos($element,'<>')) !== false) { - $item = trim(substr($element,0,$operator)); - if (!isset($usertracks[$item])) { - return false; - } - - $value = trim(trim(substr($element,$operator+2)),'"'); - if (isset($statuses[$value])) { - $status = $statuses[$value]; - } else { - return false; - } - - $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')'; - } else if (is_numeric($element)) { - if ($symbol == '*') { - $symbol = ''; - $open = strpos($prerequisites,'{',$i); - $opened = 1; - $closed = 0; - for ($close=$open+1; (($opened > $closed) && ($close= $element) { - $element = 'true'; - } else { - $element = 'false'; - } - } - } else { - return false; - } - - array_push($stack,$element); - $element = ''; - } - if ($symbol == '~') { - $symbol = '!'; - } - if (!empty($symbol)) { - array_push($stack,$symbol); - } - break; - default: - $element .= $symbol; - break; - } - $i++; - } - if (!empty($element)) { - $element = trim($element); - if (isset($usertracks[$element])) { - $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '. - '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; - } else if (($operator = strpos($element,'=')) !== false) { - $item = trim(substr($element,0,$operator)); - if (!isset($usertracks[$item])) { - return false; - } - - $value = trim(trim(substr($element,$operator+1)),'"'); - if (isset($statuses[$value])) { - $status = $statuses[$value]; - } else { - return false; - } - - $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')'; - } else if (($operator = strpos($element,'<>')) !== false) { - $item = trim(substr($element,0,$operator)); - if (!isset($usertracks[$item])) { - return false; - } - - $value = trim(trim(substr($element,$operator+1)),'"'); - if (isset($statuses[$value])) { - $status = $statuses[$value]; - } else { - return false; - } - - $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')'; - } else { - return false; - } - - array_push($stack,$element); - } - return eval('return '.implode($stack).';'); -} - - -function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) { - $id = null; - if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND attempt='$attempt' AND element='$element'")) { - $track->value = $value; - $track->timemodified = time(); - $id = update_record('scorm_scoes_track',$track); - } else { - $track->userid = $userid; - $track->scormid = $scormid; - $track->scoid = $scoid; - $track->attempt = $attempt; - $track->element = $element; - $track->value = addslashes($value); - $track->timemodified = time(); - $id = insert_record('scorm_scoes_track',$track); - } - return $id; -} - - -function scorm_add_time($a, $b) { - $aes = explode(':',$a); - $bes = explode(':',$b); - $aseconds = explode('.',$aes[2]); - $bseconds = explode('.',$bes[2]); - $change = 0; - - $acents = 0; //Cents - if (count($aseconds) > 1) { - $acents = $aseconds[1]; - } - $bcents = 0; - if (count($bseconds) > 1) { - $bcents = $bseconds[1]; - } - $cents = $acents + $bcents; - $change = floor($cents / 100); - $cents = $cents - ($change * 100); - if (floor($cents) < 10) { - $cents = '0'. $cents; - } - - $secs = $aseconds[0] + $bseconds[0] + $change; //Seconds - $change = floor($secs / 60); - $secs = $secs - ($change * 60); - if (floor($secs) < 10) { - $secs = '0'. $secs; - } - - $mins = $aes[1] + $bes[1] + $change; //Minutes - $change = floor($mins / 60); - $mins = $mins - ($change * 60); - if ($mins < 10) { - $mins = '0' . $mins; - } - - $hours = $aes[0] + $bes[0] + $change; //Hours - if ($hours < 10) { - $hours = '0' . $hours; - } - - if ($cents != '0') { - return $hours . ":" . $mins . ":" . $secs . '.' . $cents; - } else { - return $hours . ":" . $mins . ":" . $secs; - } -} - -function scorm_external_link($link) { -// check if a link is external - $result = false; - $link = strtolower($link); - if (substr($link,0,7) == 'http://') { - $result = true; - } else if (substr($link,0,8) == 'https://') { - $result = true; - } else if (substr($link,0,4) == 'www.') { - $result = true; - } - return $result; -} - -function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) { - $scores = NULL; - $scores->scoes = 0; - $scores->values = 0; - $scores->max = 0; - $scores->sum = 0; - - if (!$scoes) { - return ''; - } - - $current = current($scoes); - $attempt = scorm_get_last_attempt($current->scorm, $userid); - foreach ($scoes as $sco) { - if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) { - if (($userdata->status == 'completed') || ($userdata->status == 'passed')) { - $scores->scoes++; - } - if (!empty($userdata->score_raw)) { - $scores->values++; - $scores->sum += $userdata->score_raw; - $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; - } - } - } - switch ($grademethod) { - case VALUEHIGHEST: - return $scores->max; - break; - case VALUEAVERAGE: - if ($scores->values > 0) { - return $scores->sum/$scores->values; - } else { - return 0; - } - break; - case VALUESUM: - return $scores->sum; - break; - case VALUESCOES: - return $scores->scoes; - break; - } -} - -function scorm_count_launchable($scormid,$organization) { - return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''"); -} - -function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) { - global $CFG; - - $strexpand = get_string('expcoll','scorm'); - $modestr = ''; - if ($mode == 'browse') { - $modestr = '&mode='.$mode; - } - $scormpixdir = $CFG->modpixpath.'/scorm/pix'; - - $result = new stdClass(); - $result->toc = "\n"; - } - $level = $newlevel; - } else { - $i = $level; - $closelist = ''; - while (($i > 0) && ($parents[$level] != $sco->parent)) { - $closelist .= "\t\t\n"; - $i--; - } - if (($i == 0) && ($sco->parent != $currentorg)) { - $style = ''; - if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) { - $style = ' style="display: none;"'; - } - $result->toc .= "\t\t
    • \n"; - $level++; - } else { - $result->toc .= $closelist; - $level = $i; - } - $parents[$level]=$sco->parent; - } - } - $result->toc .= "\t\t
    • "; - $nextsco = next($scoes); - if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) { - $sublist++; - $icon = 'minus'; - if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) { - $icon = 'plus'; - } - $result->toc .= ''.$strexpand.''; - } else { - $result->toc .= ''; - } - if (empty($sco->title)) { - $sco->title = $sco->identifier; - } - if (!empty($sco->launch)) { - $startbold = ''; - $endbold = ''; - $score = ''; - if (empty($scoid) && ($mode != 'normal')) { - $scoid = $sco->id; - } - if (isset($usertracks[$sco->identifier])) { - $usertrack = $usertracks[$sco->identifier]; - $strstatus = get_string($usertrack->status,'scorm'); - $result->toc .= ''.$strstatus.''; - if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) { - $incomplete = true; - if ($play && empty($scoid)) { - $scoid = $sco->id; - } - } - if ($usertrack->score_raw != '') { - $score = '('.get_string('score','scorm').': '.$usertrack->score_raw.')'; - } - } else { - if ($play && empty($scoid)) { - $scoid = $sco->id; - } - if ($sco->scormtype == 'sco') { - $result->toc .= ''.get_string('notattempted','scorm').''; - $incomplete = true; - } else { - $result->toc .= ''.get_string('asset','scorm').''; - } - } - if ($sco->id == $scoid) { - $startbold = ''; - $endbold = ''; - $findnext = true; - $shownext = $sco->next; - $showprev = $sco->previous; - } - - if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) { - if (!empty($sco->launch)) { - $previd = $sco->id; - } - } - if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) { - if ($sco->id == $scoid) { - $result->prerequisites = true; - } - $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id; - $result->toc .= ' '.$startbold.''.format_string($sco->title).''.$score.$endbold."
    • \n"; - $tocmenus[$sco->id] = scorm_repeater('−',$level) . '>' . format_string($sco->title); - } else { - if ($sco->id == $scoid) { - $result->prerequisites = false; - } - $result->toc .= ' '.$sco->title."\n"; - } - } else { - $result->toc .= ' '.$sco->title."\n"; - } - if (($nextsco !== false) && ($nextid == 0) && ($findnext)) { - if (!empty($nextsco->launch)) { - $nextid = $nextsco->id; - } - } - } - for ($i=0;$i<$level;$i++) { - $result->toc .= "\t\t
  • \n"; - } - - if ($play) { - $sco = get_record('scorm_scoes','id',$scoid); - $sco->previd = $previd; - $sco->nextid = $nextid; - $result->sco = $sco; - $result->incomplete = $incomplete; - } else { - $result->incomplete = $incomplete; - } - } - $result->toc .= "\t\n"; - if ($scorm->hidetoc == 0) { - $result->toc .= ' - '."\n"; - } - - $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='; - $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true); - - return $result; -} - -function scorm_get_last_attempt($scormid, $userid) { -/// Find the last attempt number for the given user id and scorm id - if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scormid', $scormid, '', '', 'max(attempt) as a')) { - if (empty($lastattempt->a)) { - return '1'; - } else { - return $lastattempt->a; - } - } -} - -function scorm_get_tracks($scoid,$userid,$attempt='') { -/// Gets all tracks of specified sco and user - global $CFG; - - if (empty($attempt)) { - if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) { - $attempt = scorm_get_last_attempt($scormid,$userid); - } else { - $attempt = 1; - } - } - $attemptsql = ' AND attempt=' . $attempt; - if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) { - $usertrack->userid = $userid; - $usertrack->scoid = $scoid; - $usertrack->score_raw = ''; - $usertrack->status = ''; - $usertrack->total_time = '00:00:00'; - $usertrack->session_time = '00:00:00'; - $usertrack->timemodified = 0; - foreach ($tracks as $track) { - $element = $track->element; - $usertrack->{$element} = $track->value; - switch ($element) { - case 'cmi.core.lesson_status': - case 'cmi.completion_status': - if ($track->value == 'not attempted') { - $track->value = 'notattempted'; - } - $usertrack->status = $track->value; - break; - case 'cmi.core.score.raw': - case 'cmi.score.raw': - $usertrack->score_raw = $track->value; - break; - case 'cmi.core.session_time': - case 'cmi.session_time': - $usertrack->session_time = $track->value; - break; - case 'cmi.core.total_time': - case 'cmi.total_time': - $usertrack->total_time = $track->value; - break; - } - if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) { - $usertrack->timemodified = $track->timemodified; - } - } - return $usertrack; - } else { - return false; - } -} - - -/// Library of functions and constants for parsing packages - -function scorm_parse($scorm) { - global $CFG; - - // Parse scorm manifest - if ($scorm->pkgtype == 'AICC') { - $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id); - } else { - if (basename($scorm->reference) != 'imsmanifest.xml') { - $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id); - } else { - $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id); - } - } - - return $scorm->launch; -} - -/** -* Take the header row of an AICC definition file -* and returns sequence of columns and a pointer to -* the sco identifier column. -* -* @param string $row AICC header row -* @param string $mastername AICC sco identifier column -* @return mixed -*/ -function scorm_get_aicc_columns($row,$mastername='system_id') { - $tok = strtok(strtolower($row),"\",\n\r"); - $result->columns = array(); - $i=0; - while ($tok) { - if ($tok !='') { - $result->columns[] = $tok; - if ($tok == $mastername) { - $result->mastercol = $i; - } - $i++; - } - $tok = strtok("\",\n\r"); - } - return $result; -} - -/** -* Given a colums array return a string containing the regular -* expression to match the columns in a text row. -* -* @param array $column The header columns -* @param string $remodule The regular expression module for a single column -* @return string -*/ -function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') { - $regexp = '/^'; - foreach ($columns as $column) { - $regexp .= $remodule; - } - if (substr($regexp,-1) == ',') { - $regexp = substr($regexp,0,-1); - } - $regexp .= '/'; - return $regexp; -} - -function scorm_parse_aicc($pkgdir,$scormid){ - $version = 'AICC'; - $ids = array(); - $courses = array(); - if ($handle = opendir($pkgdir)) { - while (($file = readdir($handle)) !== false) { - $ext = substr($file,strrpos($file,'.')); - $extension = strtolower(substr($ext,1)); - $id = strtolower(basename($file,$ext)); - $ids[$id]->$extension = $file; - } - closedir($handle); - } - foreach ($ids as $courseid => $id) { - if (isset($id->crs)) { - if (is_file($pkgdir.'/'.$id->crs)) { - $rows = file($pkgdir.'/'.$id->crs); - foreach ($rows as $row) { - if (preg_match("/^(.+)=(.+)$/",$row,$matches)) { - switch (strtolower(trim($matches[1]))) { - case 'course_id': - $courses[$courseid]->id = trim($matches[2]); - break; - case 'course_title': - $courses[$courseid]->title = trim($matches[2]); - break; - case 'version': - $courses[$courseid]->version = 'AICC_'.trim($matches[2]); - break; - } - } - } - } - } - if (isset($id->des)) { - $rows = file($pkgdir.'/'.$id->des); - $columns = scorm_get_aicc_columns($rows[0]); - $regexp = scorm_forge_cols_regexp($columns->columns); - for ($i=1;$icolumns[$j]; - $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); - } - } - } - } - if (isset($id->au)) { - $rows = file($pkgdir.'/'.$id->au); - $columns = scorm_get_aicc_columns($rows[0]); - $regexp = scorm_forge_cols_regexp($columns->columns); - for ($i=1;$icolumns[$j]; - $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); - } - } - } - } - if (isset($id->cst)) { - $rows = file($pkgdir.'/'.$id->cst); - $columns = scorm_get_aicc_columns($rows[0],'block'); - $regexp = scorm_forge_cols_regexp($columns->columns,'("[\w]+")?,?'); - for ($i=1;$imastercol) { - $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1); - } - } - } - } - } - if (isset($id->ort)) { - $rows = file($pkgdir.'/'.$id->ort); - } - if (isset($id->pre)) { - $rows = file($pkgdir.'/'.$id->pre); - $columns = scorm_get_aicc_columns($rows[0],'structure_element'); - $regexp = scorm_forge_cols_regexp($columns->columns,'(.+),'); - for ($i=1;$ielements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]),1,-1); - } - } - } - if (isset($id->cmp)) { - $rows = file($pkgdir.'/'.$id->cmp); - } - } - //print_r($courses); - $launch = 0; - if (isset($courses)) { - foreach ($courses as $course) { - unset($sco); - $sco->identifier = $course->id; - $sco->scorm = $scormid; - $sco->organization = ''; - $sco->title = $course->title; - $sco->parent = '/'; - $sco->launch = ''; - $sco->scormtype = ''; - //print_r($sco); - $id = insert_record('scorm_scoes',$sco); - if ($launch == 0) { - $launch = $id; - } - if (isset($course->elements)) { - foreach($course->elements as $element) { - unset($sco); - $sco->identifier = $element->system_id; - $sco->scorm = $scormid; - $sco->organization = $course->id; - $sco->title = $element->title; - if (strtolower($element->parent) == 'root') { - $sco->parent = '/'; - } else { - $sco->parent = $element->parent; - } - if (isset($element->file_name)) { - $sco->launch = $element->file_name; - $sco->scormtype = 'sco'; - } else { - $element->file_name = ''; - $sco->scormtype = ''; - } - if (!isset($element->prerequisites)) { - $element->prerequisites = ''; - } - $sco->prerequisites = $element->prerequisites; - if (!isset($element->max_time_allowed)) { - $element->max_time_allowed = ''; - } - $sco->maxtimeallowed = $element->max_time_allowed; - if (!isset($element->time_limit_action)) { - $element->time_limit_action = ''; - } - $sco->timelimitaction = $element->time_limit_action; - if (!isset($element->mastery_score)) { - $element->mastery_score = ''; - } - $sco->masteryscore = $element->mastery_score; - $sco->previous = 0; - $sco->next = 0; - $id = insert_record('scorm_scoes',$sco); - if ($launch==0) { - $launch = $id; - } - } - } - } - } - set_field('scorm','version','AICC','id',$scormid); - return $launch; -} - -function scorm_get_resources($blocks) { - foreach ($blocks as $block) { - if ($block['name'] == 'RESOURCES') { - foreach ($block['children'] as $resource) { - if ($resource['name'] == 'RESOURCE') { - $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs']; - } - } - } - } - return $resources; -} - -function scorm_get_manifest($blocks,$scoes) { - static $parents = array(); - static $resources; - - static $manifest; - static $organization; - - if (count($blocks) > 0) { - foreach ($blocks as $block) { - switch ($block['name']) { - case 'METADATA': - if (isset($block['children'])) { - foreach ($block['children'] as $metadata) { - if ($metadata['name'] == 'SCHEMAVERSION') { - if (empty($scoes->version)) { - if (isset($metadata['tagData']) && (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches))) { - $scoes->version = 'SCORM_'.$matches[count($matches)-1]; - } else { - $scoes->version = 'SCORM_1.2'; - } - } - } - } - } - break; - case 'MANIFEST': - $manifest = addslashes($block['attrs']['IDENTIFIER']); - $organization = ''; - $resources = array(); - $resources = scorm_get_resources($block['children']); - $scoes = scorm_get_manifest($block['children'],$scoes); - if (count($scoes->elements) <= 0) { - foreach ($resources as $item => $resource) { - if (!empty($resource['HREF'])) { - $sco = new stdClass(); - $sco->identifier = $item; - $sco->title = $item; - $sco->parent = '/'; - $sco->launch = addslashes($resource['HREF']); - $sco->scormtype = addslashes($resource['ADLCP:SCORMTYPE']); - $scoes->elements[$manifest][$organization][$item] = $sco; - } - } - } - break; - case 'ORGANIZATIONS': - if (!isset($scoes->defaultorg)) { - $scoes->defaultorg = addslashes($block['attrs']['DEFAULT']); - } - $scoes = scorm_get_manifest($block['children'],$scoes); - break; - case 'ORGANIZATION': - $identifier = addslashes($block['attrs']['IDENTIFIER']); - $organization = ''; - $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier; - $scoes->elements[$manifest][$organization][$identifier]->parent = '/'; - $scoes->elements[$manifest][$organization][$identifier]->launch = ''; - $scoes->elements[$manifest][$organization][$identifier]->scormtype = ''; - - $parents = array(); - $parent = new stdClass(); - $parent->identifier = $identifier; - $parent->organization = $organization; - array_push($parents, $parent); - $organization = $identifier; - - $scoes = scorm_get_manifest($block['children'],$scoes); - - array_pop($parents); - break; - case 'ITEM': - $parent = array_pop($parents); - array_push($parents, $parent); - - $identifier = addslashes($block['attrs']['IDENTIFIER']); - $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier; - $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier; - if (!isset($block['attrs']['ISVISIBLE'])) { - $block['attrs']['ISVISIBLE'] = 'true'; - } - $scoes->elements[$manifest][$organization][$identifier]->isvisible = addslashes($block['attrs']['ISVISIBLE']); - if (!isset($block['attrs']['PARAMETERS'])) { - $block['attrs']['PARAMETERS'] = ''; - } - $scoes->elements[$manifest][$organization][$identifier]->parameters = addslashes($block['attrs']['PARAMETERS']); - if (!isset($block['attrs']['IDENTIFIERREF'])) { - $scoes->elements[$manifest][$organization][$identifier]->launch = ''; - $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset'; - } else { - $idref = addslashes($block['attrs']['IDENTIFIERREF']); - $base = ''; - if (isset($resources[$idref]['XML:BASE'])) { - $base = $resources[$idref]['XML:BASE']; - } - $scoes->elements[$manifest][$organization][$identifier]->launch = addslashes($base.$resources[$idref]['HREF']); - if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) { - $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset'; - } - $scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']); - } - - $parent = new stdClass(); - $parent->identifier = $identifier; - $parent->organization = $organization; - array_push($parents, $parent); - - $scoes = scorm_get_manifest($block['children'],$scoes); - - array_pop($parents); - break; - case 'TITLE': - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = addslashes($block['tagData']); - break; - case 'ADLCP:PREREQUISITES': - if ($block['attrs']['TYPE'] == 'aicc_script') { - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']); - } - break; - case 'ADLCP:MAXTIMEALLOWED': - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']); - break; - case 'ADLCP:TIMELIMITACTION': - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']); - break; - case 'ADLCP:DATAFROMLMS': - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']); - break; - case 'ADLCP:MASTERYSCORE': - $parent = array_pop($parents); - array_push($parents, $parent); - if (!isset($block['tagData'])) { - $block['tagData'] = ''; - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = addslashes($block['tagData']); - break; - } - } - } - - return $scoes; -} - -function scorm_parse_scorm($pkgdir,$scormid) { - global $CFG; - - $launch = 0; - $manifestfile = $pkgdir.'/imsmanifest.xml'; - - if (is_file($manifestfile)) { - - $xmlstring = file_get_contents($manifestfile); - $objXML = new xml2Array(); - $manifests = $objXML->parse($xmlstring); - - $scoes = new stdClass(); - $scoes->version = ''; - $scoes = scorm_get_manifest($manifests,$scoes); - - if (count($scoes->elements) > 0) { - foreach ($scoes->elements as $manifest => $organizations) { - foreach ($organizations as $organization => $items) { - foreach ($items as $identifier => $item) { - $item->scorm = $scormid; - $item->manifest = $manifest; - $item->organization = $organization; - $id = insert_record('scorm_scoes',$item); - - if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) { - $launch = $id; - } - } - } - } - set_field('scorm','version',$scoes->version,'id',$scormid); - } - } - - return $launch; -} - -function scorm_course_format_display($user,$course) { - global $CFG; - - $strupdate = get_string('update'); - $strmodule = get_string('modulename','scorm'); - - echo '
    '; - if ($scorms = get_all_instances_in_course('scorm', $course)) { - // The module SCORM activity with the least id is the course - $scorm = current($scorms); - if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - $colspan = ''; - $headertext = ''; - // Display report link - $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); - if ($trackedusers->c > 0) { - $headertext .= ''.format_text(get_string('summary').':
    '.$scorm->summary).'
    '.get_string('name').': '.format_string($scorm->name).''; - if (isteacher($course->id, $user->id, true)) { - if (isediting($course->id)) { - // Display update icon - $path = $CFG->wwwroot.'/course'; - $headertext .= ''. - ''. - ''.$strupdate.''; - } - $headertext .= '
    '; - print_simple_box($headertext,'','100%'); - scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%'); - } else { - if (isteacheredit($course->id, $user->id)) { - // Create a new activity - redirect('mod.php?id='.$course->id.'&section=0&sesskey='.sesskey().'&add=scorm'); - } else { - notify('Could not find a scorm course here'); - } - } - echo '
    '; -} - -function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') { - global $CFG; - - $organization = optional_param('organization', '', PARAM_INT); - - print_simple_box_start('center',$blockwidth); -?> -
    -launch; - } - if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) { - if (count($orgs) > 1) { - ?> -
    - -
    - -
    -
    -organization == '') && ($org->launch == '')) { - $orgidentifier = $org->identifier; - } else { - $orgidentifier = $org->organization; - } - } - $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier); - $incomplete = $result->incomplete; - echo $result->toc; - print_simple_box_end(); -?> -
    -
    popup == 1?' target="newwin"':'' ?>> - hidebrowse == 0) { - print_string("mode","scorm"); - echo ': '."\n"; - if ($incomplete === true) { - echo '\n"; - } else { - echo '\n"; - } - } else { - if ($incomplete === true) { - echo ''."\n"; - } else { - echo ''."\n"; - } - } - if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) { -?> -
    - - - -
    - - - -
    -
    -unicodedb)) { // If Unicode DB support enable does not convert string - $textlib = textlib_get_instance(); - for ($i = 0; $i < $textlib->strlen($str,'utf-8'); $i++) { - $thisvalue = ord($str[$i]); - if ($thisvalue < 128) { - $entities .= $str[$i]; // Leave ASCII chars unchanged - } else { - if (count($values) == 0) { - $lookingfor = ($thisvalue < 224) ? 2 : 3; - } - $values[] = $thisvalue; - if (count($values) == $lookingfor) { - $number = ($lookingfor == 3) ? - (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64): - (($values[0] % 32) * 64) + ($values[1] % 64); - $entities .= '&#' . $number . ';'; - $values = array(); - $lookingfor = 1; - } - } - } - return $entities; - } else { - return $str; - } -} - -/* Usage - Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML; - - $objXML = new xml2Array(); - $arrOutput = $objXML->parse($strYourXML); - print_r($arrOutput); //print it out, or do whatever! - -*/ -class xml2Array { - - var $arrOutput = array(); - var $resParser; - var $strXmlData; - - /** - * Parse an XML text string and create an array tree that rapresent the XML structure - * - * @param string $strInputXML The XML string - * @return array - */ - function parse($strInputXML) { - /*if (($start = strpos($strInputXML,'encoding=')) !== false) { - $endchr = substr($strInputXML,$start+9,1); - if (($end = strpos($strInputXML,$endchr,$start+10)) !== false) { - $charset = strtolower(substr($strInputXML,$start+10,$end-$start-10)); - if ($charset != 'utf-8') { - $strInputXML = str_ireplace('encoding='.$endchr.$charset.$endchr,'encoding='.$endchr.'UTF-8'.$endchr,$strInputXML); - $textlib = textlib_get_instance(); - } - } - }*/ - $this->resParser = xml_parser_create ('UTF-8'); - xml_set_object($this->resParser,$this); - xml_set_element_handler($this->resParser, "tagOpen", "tagClosed"); - - xml_set_character_data_handler($this->resParser, "tagData"); - - $this->strXmlData = xml_parse($this->resParser,$strInputXML ); - if(!$this->strXmlData) { - die(sprintf("XML error: %s at line %d", - xml_error_string(xml_get_error_code($this->resParser)), - xml_get_current_line_number($this->resParser))); - } - - xml_parser_free($this->resParser); - - return $this->arrOutput; - } - - function tagOpen($parser, $name, $attrs) { - $tag=array("name"=>$name,"attrs"=>$attrs); - array_push($this->arrOutput,$tag); - } - - function tagData($parser, $tagData) { - if(trim($tagData)) { - if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) { - $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= scorm_utf8_to_entities($tagData); - } else { - $this->arrOutput[count($this->arrOutput)-1]['tagData'] = scorm_utf8_to_entities($tagData); - } - } - } - - function tagClosed($parser, $name) { - $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1]; - array_pop($this->arrOutput); - } -} -?> + +directorypermissions); + @chmod($strPath.$datadir, $CFG->directorypermissions); // Just in case mkdir didn't do it + return $strPath.$datadir; + } else { + return false; + } +} + +/** +* Given a package directory, this function will check if the package is valid +* +* @param string $packagedir The package directory +* @return mixed +*/ +function scorm_validate($packagedir) { + + ////$f = "D:\\test.txt"; + ////@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_validate \n"); + + + $validation = new stdClass(); + if (is_file($packagedir.'/imsmanifest.xml')) { + $validation->result = 'found'; + $validation->pkgtype = 'SCORM'; + } else { + if ($handle = opendir($packagedir)) { + while (($file = readdir($handle)) !== false) { + $ext = substr($file,strrpos($file,'.')); + if (strtolower($ext) == '.cst') { + $validation->result = 'found'; + $validation->pkgtype = 'AICC'; + break; + } + } + closedir($handle); + } + if (!isset($validation)) { + $validation->result = 'nomanifest'; + $validation->pkgtype = 'SCORM'; + } + } + return $validation; +} + +function scorm_get_user_data($userid) { +/// Gets user info required to display the table of scorm results +/// for report.php + + return get_record('user','id',$userid,'','','','','firstname, lastname, picture'); +} + +function scorm_string_wrap($stringa, $len=15) { +// Crop the given string into max $len characters lines + $textlib = textlib_get_instance(); + if ($textlib->strlen($stringa, current_charset()) > $len) { + $words = explode(' ', $stringa); + $newstring = ''; + $substring = ''; + foreach ($words as $word) { + if (($textlib->strlen($substring, current_charset())+$textlib->strlen($word, current_charset())+1) < $len) { + $substring .= ' '.$word; + } else { + $newstring .= ' '.$substring.'
    '; + $substring = $word; + } + } + if (!empty($substring)) { + $newstring .= ' '.$substring; + } + return $newstring; + } else { + return $stringa; + } +} + +function scorm_eval_prerequisites($prerequisites,$usertracks) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_eval_prerequisites \n"); + + + $element = ''; + $stack = array(); + $statuses = array( + 'passed' => 'passed', + 'completed' => 'completed', + 'failed' => 'failed', + 'incomplete' => 'incomplete', + 'browsed' => 'browsed', + 'not attempted' => 'notattempted', + 'p' => 'passed', + 'c' => 'completed', + 'f' => 'failed', + 'i' => 'incomplete', + 'b' => 'browsed', + 'n' => 'notattempted' + ); + $i=0; + while ($istatus.'\' == \'completed\') || '. + '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; + } else if (($operator = strpos($element,'=')) !== false) { + $item = trim(substr($element,0,$operator)); + if (!isset($usertracks[$item])) { + return false; + } + + $value = trim(trim(substr($element,$operator+1)),'"'); + if (isset($statuses[$value])) { + $status = $statuses[$value]; + } else { + return false; + } + + $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')'; + } else if (($operator = strpos($element,'<>')) !== false) { + $item = trim(substr($element,0,$operator)); + if (!isset($usertracks[$item])) { + return false; + } + + $value = trim(trim(substr($element,$operator+2)),'"'); + if (isset($statuses[$value])) { + $status = $statuses[$value]; + } else { + return false; + } + + $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')'; + } else if (is_numeric($element)) { + if ($symbol == '*') { + $symbol = ''; + $open = strpos($prerequisites,'{',$i); + $opened = 1; + $closed = 0; + for ($close=$open+1; (($opened > $closed) && ($close= $element) { + $element = 'true'; + } else { + $element = 'false'; + } + } + } else { + return false; + } + + array_push($stack,$element); + $element = ''; + } + if ($symbol == '~') { + $symbol = '!'; + } + if (!empty($symbol)) { + array_push($stack,$symbol); + } + break; + default: + $element .= $symbol; + break; + } + $i++; + } + if (!empty($element)) { + $element = trim($element); + if (isset($usertracks[$element])) { + $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '. + '(\''.$usertracks[$element]->status.'\' == \'passed\'))'; + } else if (($operator = strpos($element,'=')) !== false) { + $item = trim(substr($element,0,$operator)); + if (!isset($usertracks[$item])) { + return false; + } + + $value = trim(trim(substr($element,$operator+1)),'"'); + if (isset($statuses[$value])) { + $status = $statuses[$value]; + } else { + return false; + } + + $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')'; + } else if (($operator = strpos($element,'<>')) !== false) { + $item = trim(substr($element,0,$operator)); + if (!isset($usertracks[$item])) { + return false; + } + + $value = trim(trim(substr($element,$operator+1)),'"'); + if (isset($statuses[$value])) { + $status = $statuses[$value]; + } else { + return false; + } + + $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')'; + } else { + return false; + } + + array_push($stack,$element); + } + return eval('return '.implode($stack).';'); +} + +function scorm_insert_statistic($statisticInput){ + + $id = null; + if ($statistic = get_record_select('scorm_statistic',"userid='$statisticInput->userid' AND scormid='$statisticInput->scormid'")) { + + $statistic->durationtime = $statisticInput->duration; + $statistic->accesstime = $statisticInput->accesstime; + $statistic->status = $statisticInput->status; + $statistic->attemptnumber = $statisticInput->attemptnumber; + $id = update_record('scorm_statistic',$statistic); + } else { + ////fwrite($ft,"Insert trong ham scorm_insert_track \n"); + $id = insert_record('scorm_statistic',$statisticInput); + } + return $id; + +} +function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) { + +// //$f = "D:\\test.txt"; +// //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_insert_track \n"); + + $id = null; + if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND attempt='$attempt' AND element='$element'")) { + $track->value = $value; + $track->timemodified = time(); + ////fwrite($ft,$userid."Update trong ham scorm_insert_track voi cac gia tri userid = "); + $id = update_record('scorm_scoes_track',$track); + } else { + $track->userid = $userid; + $track->scormid = $scormid; + $track->scoid = $scoid; + $track->attempt = $attempt; + $track->element = $element; + $track->value = addslashes($value); + $track->timemodified = time(); + ////fwrite($ft,"Insert trong ham scorm_insert_track \n"); + $id = insert_record('scorm_scoes_track',$track); + } + return $id; +} + +function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) { + +// //$f = "D:\\test.txt"; +// //@$ft = fopen($f,"a"); + + $id = null; + if ($suspendtrack = get_record_select('scorm_suspendtrack',"userid='$userid' AND scormid='$scormid'")) { + $suspendtrack->suspendscoid = $scoid; + $suspendtrack->attempt = $attempt; + + $id = update_record('scorm_suspendtrack',$suspendtrack); + } else { + $suspendtrack->scormid = $scormid; + $suspendtrack->suspendscoid = $scoid; + $suspendtrack->userid = $userid; + $suspendtrack->attempt = $attempt; + $id = insert_record('scorm_suspendtrack',$suspendtrack); + } + return $id; +} + +function scorm_get_suspendscoid($scormid,$userid) +{ + $sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid); + $suspendscoid = $sco->suspendscoid; + return $suspendscoid; +} +function scorm_add_time($a, $b) { + $aes = explode(':',$a); + $bes = explode(':',$b); + $aseconds = explode('.',$aes[2]); + $bseconds = explode('.',$bes[2]); + $change = 0; + + $acents = 0; //Cents + if (count($aseconds) > 1) { + $acents = $aseconds[1]; + } + $bcents = 0; + if (count($bseconds) > 1) { + $bcents = $bseconds[1]; + } + $cents = $acents + $bcents; + $change = floor($cents / 100); + $cents = $cents - ($change * 100); + if (floor($cents) < 10) { + $cents = '0'. $cents; + } + + $secs = $aseconds[0] + $bseconds[0] + $change; //Seconds + $change = floor($secs / 60); + $secs = $secs - ($change * 60); + if (floor($secs) < 10) { + $secs = '0'. $secs; + } + + $mins = $aes[1] + $bes[1] + $change; //Minutes + $change = floor($mins / 60); + $mins = $mins - ($change * 60); + if ($mins < 10) { + $mins = '0' . $mins; + } + + $hours = $aes[0] + $bes[0] + $change; //Hours + if ($hours < 10) { + $hours = '0' . $hours; + } + + if ($cents != '0') { + return $hours . ":" . $mins . ":" . $secs . '.' . $cents; + } else { + return $hours . ":" . $mins . ":" . $secs; + } +} + +function scorm_external_link($link) { +// check if a link is external + $result = false; + $link = strtolower($link); + if (substr($link,0,7) == 'http://') { + $result = true; + } else if (substr($link,0,8) == 'https://') { + $result = true; + } else if (substr($link,0,4) == 'www.') { + $result = true; + } + return $result; +} + +function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //fwrite($ft,"\n Xu ly trong ham scorm_grade_user \n"); + + $scores = NULL; + $scores->scoes = 0; + $scores->values = 0; + $scores->max = 0; + $scores->sum = 0; + + if (!$scoes) { + return ''; + } + + $current = current($scoes); + $attempt = scorm_get_last_attempt($current->scorm, $userid); + foreach ($scoes as $sco) { + if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) { + if (($userdata->status == 'completed') || ($userdata->status == 'passed')) { + $scores->scoes++; + } + if (!empty($userdata->score_raw)) { + $scores->values++; + $scores->sum += $userdata->score_raw; + $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; + } + } + } + switch ($grademethod) { + case VALUEHIGHEST: + return $scores->max; + break; + case VALUEAVERAGE: + if ($scores->values > 0) { + return $scores->sum/$scores->values; + } else { + return 0; + } + break; + case VALUESUM: + return $scores->sum; + break; + case VALUESCOES: + return $scores->scoes; + break; + } +} + +//Lay diem theo Sco cha.. Thuc chat la theo bai kiem tra +function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES) +{ + + $scores = NULL; + $scores->scoes = 0; + $scores->values = 0; + $scores->scaled = 0; + $scores->max = 0; + $scores->sum = 0; + + $scoes_total = 0; + $scoes_count = 0; + $attempt = scorm_get_last_attempt($sco->scorm, $userid); + $scoes = get_records('scorm_scoes', 'parent', $sco->identifier); + foreach ($scoes as $sco) + { + $scoes_total++; + if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) { + if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) { + $scoes_count++; + } + + + $scoreraw = $userdata->score_raw; + + if (!empty($userdata->score_raw)) { + $scores->values++; + $scores->sum += $userdata->score_raw; + $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; + } + if (!empty($userdata->score_scaled)) { + $scores->scaled = $scores->scaled + $userdata->score_scaled; + } + + } + } + if ($scoes_count > 0) + { + $scores->scaled = ($scores->scaled)/($scoes_count); + } + switch ($grademethod) { + case VALUEHIGHEST: + return $scores->max; + break; + case VALUEAVERAGE: + if ($scores->values > 0) { + return $scores->sum/$scores->values; + } else { + return 0; + } + break; + case VALUESUM: + return $scores->sum; + break; + case VALUESCOES: + return $scores->scaled; + break; + } + +} + +// Lay ra so luong cac scoes duoc user thuc hien xong +function scorm_get_user_sco_count($scormid, $userid) +{ + $scoes_count = 0; + $attempt = scorm_get_last_attempt($current->scorm, $userid); + $scoes = get_records('scorm_scoes', 'scorm', $scormid); + + + + foreach ($scoes as $sco) + { + if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) { + + if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) { + $scoes_count++; + } + } + + } + return $scoes_count; + +} + +function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //fwrite($ft,"\n Xu ly trong ham scorm_grade_user \n"); + + $scores = NULL; + $scores->scoes = 0; + $scores->values = 0; + $scores->scaled = 0; + $scores->max = 0; + $scores->sum = 0; + + if (!$scoes) { + //fwrite($ft,"\n Khong xuat hien mot SCO duoc tinh diem \n"); + return ''; + } + + $current = current($scoes); + $attempt = scorm_get_last_attempt($current->scorm, $userid); + //fwrite($ft,"\n ---------------------------------------\n"); + foreach ($scoes as $sco) { + if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) { + if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) { + $scores->scoes++; + //fwrite($ft,"\n Them mot khoa hoan thanh co id la ".$sco->id." co gia tri scaled la ".$userdata->score_scaled." \n"); + + } + $scaled = $userdata->score_scaled; + $scoreraw = $userdata->score_raw; + if ($scaled ==0){ + $scores->scaled = $scores->scaled / $scores->scoes; + //fwrite($ft,"\n Ti le chinh xac ".($scores->scaled*100)." phan tram"); + + } + + if (!empty($userdata->score_raw)) { + $scores->values++; + $scores->sum += $userdata->score_raw; + $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max; + } + + if (!empty($scaled)) { + //fwrite($ft,"\n go ---->>> \n"); + $scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes); + //fwrite($ft,"\n Ti le chinh xac ".($scores->scaled*100)." phan tram"); + + } + + } + } + //fwrite($ft,"\n ----+++++++++++------\n"); + //fwrite($ft,"\n Kieu gia tri tra ve la ".$grademethod); + switch ($grademethod) { + case VALUEHIGHEST: + //fwrite($ft,"\n Gia tri tra ve thouoc loai cao nhat"); + return $scores->max; + break; + case VALUEAVERAGE: + //fwrite($ft,"\n Gia tri tra ve thouoc loai trung binh"); + if ($scores->values > 0) { + return $scores->sum/$scores->values; + } else { + return 0; + } + break; + case VALUESUM: + //fwrite($ft,"\n Gia tri tra ve thouoc loai tong cong"); + return $scores->sum; + break; + case VALUESCOES: + //fwrite($ft,"\n Gia tri tra ve thouoc loai scoes co gia tri".$scores->scaled); + return $scores->scaled; + break; + } +} + +function scorm_count_launchable($scormid,$organization) { + return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''"); +} + +function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) { + global $CFG; + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //fwrite($ft,"\n Xu ly trong ham scorm_get_toc \n"); + + // + $suspendscoid = scorm_get_suspendscoid($scorm->id,$user->id); + // + + $strexpand = get_string('expcoll','scorm'); + $modestr = ''; + if ($mode == 'browse') { + $modestr = '&mode='.$mode; + } + $scormpixdir = $CFG->modpixpath.'/scorm/pix'; + + $result = new stdClass(); + $result->toc = "
      \n"; + $tocmenus = array(); + $result->prerequisites = true; + $incomplete = false; + + // + // Get the current organization infos + // + $organizationsql = ''; + if (!empty($currentorg)) { + if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') { + $result->toc .= "\t
    • $organizationtitle
    • \n"; + $tocmenus[] = $organizationtitle; + } + $organizationsql = "AND organization='$currentorg'"; + } + // + // If not specified retrieve the last attempt number + // + if (empty($attempt)) { + $attempt = scorm_get_last_attempt($scorm->id, $user->id); + } + $result->attemptleft = $scorm->maxattempt - $attempt; + + //fwrite($ft,"\n So lan attempt con lai la \n".$result->attemptleft); + + if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){ + // + // Lay du lieu da duoc tracking cho moi doi tuong hoc tap + // + $usertracks = array(); + foreach ($scoes as $sco) { + //Kiem tra xem $sco co phai la phan muc khong. Neu la trang Asset hoac SCO thi xu ly tiep + if (!empty($sco->launch)) { + if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) { + if ($usertrack->status == '') { + $usertrack->status = 'notattempted'; + } + // Ghi lai thong tin $usertracks theo tung doi tuong sco + $usertracks[$sco->identifier] = $usertrack; + } + } + } + + $level=0; + $sublist=1; + $previd = 0; + $nextid = 0; + $findnext = false; + $parents[$level]='/'; + + foreach ($scoes as $sco) { + if ($parents[$level]!=$sco->parent) { + if ($newlevel = array_search($sco->parent,$parents)) { + for ($i=0; $i<($level-$newlevel); $i++) { + $result->toc .= "\t\t
    \n"; + } + $level = $newlevel; + } else { + $i = $level; + $closelist = ''; + while (($i > 0) && ($parents[$level] != $sco->parent)) { + $closelist .= "\t\t\n"; + $i--; + } + if (($i == 0) && ($sco->parent != $currentorg)) { + $style = ''; + if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) { + $style = ' style="display: none;"'; + } + $result->toc .= "\t\t
    • \n"; + $level++; + } else { + $result->toc .= $closelist; + $level = $i; + } + $parents[$level]=$sco->parent; + } + } + $result->toc .= "\t\t
    • "; + $nextsco = next($scoes); + if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) { + $sublist++; + $icon = 'minus'; + if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) { + $icon = 'plus'; + } + $result->toc .= ''.$strexpand.''; + } else { + $result->toc .= ''; + } + if (empty($sco->title)) { + $sco->title = $sco->identifier; + } + if (!empty($sco->launch)) { + $startbold = ''; + $endbold = ''; + $score = ''; + if (empty($scoid) && ($mode != 'normal')) { + $scoid = $sco->id; + } + //Neu la sco suspend thi hien thi anh khac + if ($suspendscoid == $sco->id){ + $result->toc .= 'Dang tam dung o day'; + } + else{ + //----------------------- + if (isset($usertracks[$sco->identifier])) { + $usertrack = $usertracks[$sco->identifier]; + $strstatus = get_string($usertrack->status,'scorm'); + $result->toc .= ''.$strstatus.''; + + if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) { + //Neu khoa hoc chua duoc attempted hoac chua hoan thanh hoac la chi browsed + $incomplete = true; + if ($play && empty($scoid)) { + $scoid = $sco->id; + } + } + if ($usertrack->score_raw != '') { + $score = '('.get_string('score','scorm').': '.$usertrack->score_raw.')'; + } + } else { + if ($play && empty($scoid)) { + $scoid = $sco->id; + } + if ($sco->scormtype == 'sco') { + $result->toc .= ''.get_string('notattempted','scorm').''; + $incomplete = true; + } else { + $result->toc .= ''.get_string('asset','scorm').''; + } + } + } + if ($sco->id == $scoid) { + $startbold = ''; + $endbold = ''; + $findnext = true; + $shownext = $sco->next; + $showprev = $sco->previous; + } + + if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) { + if (!empty($sco->launch)) { + $previd = $sco->id; + } + } + if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) { + if ($sco->id == $scoid) { + $result->prerequisites = true; + } + if (scorm_isChoice($scorm->id,$sco->id) == 1) + { + $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id; + $result->toc .= ' '.$startbold.''.format_string($sco->title).''.$score.$endbold."
    • \n"; + $tocmenus[$sco->id] = scorm_repeater('−',$level) . '>' . format_string($sco->title); + } + else + { + $result->toc .= ' '.$startbold.format_string($sco->title).$score.$endbold."\n"; + $tocmenus[$sco->id] = scorm_repeater('−',$level) . '>' . format_string($sco->title); + } + } else { + if ($sco->id == $scoid) { + $result->prerequisites = false; + } + $result->toc .= ' '.$sco->title."\n"; + } + } else { + $result->toc .= ' '.$sco->title."\n"; + } + if (($nextsco !== false) && ($nextid == 0) && ($findnext)) { + if (!empty($nextsco->launch)) { + $nextid = $nextsco->id; + } + } + } + for ($i=0;$i<$level;$i++) { + $result->toc .= "\t\t
  • \n"; + } + + if ($play) { + $sco = get_record('scorm_scoes','id',$scoid); + $sco->previd = $previd; + $sco->nextid = $nextid; + $result->sco = $sco; + $result->incomplete = $incomplete; + } else { + $result->incomplete = $incomplete; + } + } + $result->toc .= "\t\n"; + if ($scorm->hidetoc == 0) { + $result->toc .= ' + '."\n"; + } + + $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='; + $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true); + + return $result; +} + +function scorm_get_last_attempt($scormid, $userid) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_get_last_attempt \n"); + +/// Find the last attempt number for the given user id and scorm id + if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scormid', $scormid, '', '', 'max(attempt) as a')) { + if (empty($lastattempt->a)) { + return '1'; + } else { + return $lastattempt->a; + } + } +} + +// Khi mot nguoi truy nhap vao mot SCO thi se thiet lap +// nguoi do da no luc thuc hien no +function scorm_set_attempt($scoid,$userid) +{ + //Lay gia tri last attempt + if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) { + $attempt = scorm_get_last_attempt($scormid,$userid); + } else { + $attempt = 1; + } + //Chi set attempt cho cac SCO + $scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ; + if ($scormtype == 'sco'){ + $element = 'cmi.attempt_status'; + $value = 'attempted'; + scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value); + } +} +function scorm_get_tracks($scoid,$userid,$attempt='') { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_get_tracks \n"); + +/// Gets all tracks of specified sco and user + global $CFG; + + if (empty($attempt)) { + if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) { + $attempt = scorm_get_last_attempt($scormid,$userid); + } else { + $attempt = 1; + } + } + $attemptsql = ' AND attempt=' . $attempt; + if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) { + $usertrack->userid = $userid; + $usertrack->scoid = $scoid; + $usertrack->score_raw = ''; + $usertrack->score_scaled = ''; + $usertrack->status = ''; + $usertrack->success_status = ''; + $usertrack->attempt_status = ''; + $usertrack->satisfied_status = ''; + $usertrack->total_time = '00:00:00'; + $usertrack->session_time = '00:00:00'; + $usertrack->timemodified = 0; + foreach ($tracks as $track) { + $element = $track->element; + $usertrack->{$element} = $track->value; + switch ($element) { + case 'cmi.core.lesson_status': + case 'cmi.attempt_status': + $usertrack->status = $track->value; + $usertrack->attempt_status = $track->value; + break; + case 'cmi.completion_status': + if ($track->value == 'not attempted') { + $track->value = 'notattempted'; + $usertrack->attempt_status = $track->value; + } + $usertrack->status = $track->value; + break; + case 'cmi.success_status': + $usertrack->success_status = $track->value; + if ($track->value=='passed'){ + $usertrack->satisfied_status = 'satisfied'; + } + if ($track->value=='failed'){ + $usertrack->satisfied_status = 'notSatisfied'; + } + break; + case 'cmi.core.score.raw': + case 'cmi.score.raw': + $usertrack->score_raw = $track->value; + break; + case 'cmi.score.scaled': + $usertrack->score_scaled = $track->value; + break; + case 'cmi.core.session_time': + case 'cmi.session_time': + $usertrack->session_time = $track->value; + break; + case 'cmi.core.total_time': + case 'cmi.total_time': + $usertrack->total_time = $track->value; + break; + } + if (isset($track->timemodified) && ($track->timemodified > $usertrack->timemodified)) { + $usertrack->timemodified = $track->timemodified; + } + } + return $usertrack; + } else { + return false; + } +} + + +function scorm_get_AbsoluteTimeLimit($scoid){ + $sco = get_record("scorm_scoes","id",$scoid); + if (!empty($sco)){ + return $sco->attemptAbsoluteDurationLimit; + } + return 0; +} +//----------------------------------------------------- +/// Library of functions and constants for parsing packages + +function scorm_parse($scorm) { + global $CFG; + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse \n"); + + // Parse scorm manifest + if ($scorm->pkgtype == 'AICC') { + $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id); + } else { + if (basename($scorm->reference) != 'imsmanifest.xml') { + $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id); + } else { + $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id); + } + } + + return $scorm->launch; +} + +/** +* Take the header row of an AICC definition file +* and returns sequence of columns and a pointer to +* the sco identifier column. +* +* @param string $row AICC header row +* @param string $mastername AICC sco identifier column +* @return mixed +*/ +function scorm_get_aicc_columns($row,$mastername='system_id') { + $tok = strtok(strtolower($row),"\",\n\r"); + $result->columns = array(); + $i=0; + while ($tok) { + if ($tok !='') { + $result->columns[] = $tok; + if ($tok == $mastername) { + $result->mastercol = $i; + } + $i++; + } + $tok = strtok("\",\n\r"); + } + return $result; +} + +/** +* Given a colums array return a string containing the regular +* expression to match the columns in a text row. +* +* @param array $column The header columns +* @param string $remodule The regular expression module for a single column +* @return string +*/ +function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') { + $regexp = '/^'; + foreach ($columns as $column) { + $regexp .= $remodule; + } + $regexp = substr($regexp,0,-1) . '/'; + return $regexp; +} + +function scorm_parse_aicc($pkgdir,$scormid){ + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse_aicc \n"); + + $version = 'AICC'; + $ids = array(); + $courses = array(); + if ($handle = opendir($pkgdir)) { + while (($file = readdir($handle)) !== false) { + $ext = substr($file,strrpos($file,'.')); + $extension = strtolower(substr($ext,1)); + $id = strtolower(basename($file,$ext)); + $ids[$id]->$extension = $file; + } + closedir($handle); + } + foreach ($ids as $courseid => $id) { + if (isset($id->crs)) { + if (is_file($pkgdir.'/'.$id->crs)) { + $rows = file($pkgdir.'/'.$id->crs); + foreach ($rows as $row) { + if (preg_match("/^(.+)=(.+)$/",$row,$matches)) { + switch (strtolower(trim($matches[1]))) { + case 'course_id': + $courses[$courseid]->id = trim($matches[2]); + break; + case 'course_title': + $courses[$courseid]->title = trim($matches[2]); + break; + case 'version': + $courses[$courseid]->version = 'AICC_'.trim($matches[2]); + break; + } + } + } + } + } + if (isset($id->des)) { + $rows = file($pkgdir.'/'.$id->des); + $columns = scorm_get_aicc_columns($rows[0]); + $regexp = scorm_forge_cols_regexp($columns->columns); + for ($i=1;$icolumns);$j++) { + $column = $columns->columns[$j]; + $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); + } + } + } + } + if (isset($id->au)) { + $rows = file($pkgdir.'/'.$id->au); + $columns = scorm_get_aicc_columns($rows[0]); + $regexp = scorm_forge_cols_regexp($columns->columns); + for ($i=1;$icolumns);$j++) { + $column = $columns->columns[$j]; + $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); + } + } + } + } + if (isset($id->cst)) { + $rows = file($pkgdir.'/'.$id->cst); + $columns = scorm_get_aicc_columns($rows[0],'block'); + $regexp = scorm_forge_cols_regexp($columns->columns,'(.+)?,'); + for ($i=1;$icolumns);$j++) { + if ($j != $columns->mastercol) { + $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1); + } + } + } + } + } + if (isset($id->ort)) { + $rows = file($pkgdir.'/'.$id->ort); + } + if (isset($id->pre)) { + $rows = file($pkgdir.'/'.$id->pre); + $columns = scorm_get_aicc_columns($rows[0],'structure_element'); + $regexp = scorm_forge_cols_regexp($columns->columns,'(.+),'); + for ($i=1;$ielements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]),1,-1); + } + } + } + if (isset($id->cmp)) { + $rows = file($pkgdir.'/'.$id->cmp); + } + } + //print_r($courses); + $launch = 0; + if (isset($courses)) { + foreach ($courses as $course) { + unset($sco); + $sco->identifier = $course->id; + $sco->scorm = $scormid; + $sco->organization = ''; + $sco->title = $course->title; + $sco->parent = '/'; + $sco->launch = ''; + $sco->scormtype = ''; + //print_r($sco); + $id = insert_record('scorm_scoes',$sco); + if ($launch == 0) { + $launch = $id; + } + if (isset($course->elements)) { + foreach($course->elements as $element) { + unset($sco); + $sco->identifier = $element->system_id; + $sco->scorm = $scormid; + $sco->organization = $course->id; + $sco->title = $element->title; + if (strtolower($element->parent) == 'root') { + $sco->parent = '/'; + } else { + $sco->parent = $element->parent; + } + if (isset($element->file_name)) { + $sco->launch = $element->file_name; + $sco->scormtype = 'sco'; + } else { + $element->file_name = ''; + $sco->scormtype = ''; + } + if (!isset($element->prerequisites)) { + $element->prerequisites = ''; + } + $sco->prerequisites = $element->prerequisites; + if (!isset($element->max_time_allowed)) { + $element->max_time_allowed = ''; + } + $sco->maxtimeallowed = $element->max_time_allowed; + if (!isset($element->time_limit_action)) { + $element->time_limit_action = ''; + } + $sco->timelimitaction = $element->time_limit_action; + if (!isset($element->mastery_score)) { + $element->mastery_score = ''; + } + $sco->masteryscore = $element->mastery_score; + $sco->previous = 0; + $sco->next = 0; + $id = insert_record('scorm_scoes',$sco); + if ($launch==0) { + $launch = $id; + } + } + } + } + } + set_field('scorm','version','AICC','id',$scormid); + return $launch; +} + +function scorm_get_resources($blocks) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly trong ham scorm_get_resources \n"); + + foreach ($blocks as $block) { + if ($block['name'] == 'RESOURCES') { + foreach ($block['children'] as $resource) { + if ($resource['name'] == 'RESOURCE') { + $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs']; + } + } + } + } + return $resources; +} + +function scorm_get_manifest($blocks,$scoes) { + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_get_manifest. \n"); + ////////fwrite($ft,$blocks." la gia tri block la \n"); + + static $parents = array(); + static $resources; + + static $manifest; + static $organization; + + if (count($blocks) > 0) { + foreach ($blocks as $block) { + switch ($block['name']) { + case 'METADATA': + if (isset($block['children'])) { + foreach ($block['children'] as $metadata) { + if ($metadata['name'] == 'SCHEMAVERSION') { + if (empty($scoes->version)) { + if (isset($metadata['tagData']) && (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches))) { + $scoes->version = 'SCORM_'.$matches[count($matches)-1]; + } else { + $scoes->version = 'SCORM_1.2'; + } + } + } + } + } + break; + case 'MANIFEST': + $manifest = addslashes($block['attrs']['IDENTIFIER']); //Lay thuoc tinh IDENTFIER cua MANIFEST + $organization = ''; + $resources = array(); + $resources = scorm_get_resources($block['children']); + $scoes = scorm_get_manifest($block['children'],$scoes); + if (count($scoes->elements) <= 0) { + foreach ($resources as $item => $resource) { + if (!empty($resource['HREF'])) { + $sco = new stdClass(); + $sco->identifier = $item; + $sco->title = $item; + $sco->parent = '/'; + $sco->launch = addslashes($resource['HREF']); + $sco->scormtype = addslashes($resource['ADLCP:SCORMTYPE']); + $scoes->elements[$manifest][$organization][$item] = $sco; + } + } + } + break; + case 'ORGANIZATIONS': + if (!isset($scoes->defaultorg)) { + $scoes->defaultorg = addslashes($block['attrs']['DEFAULT']); + } + $scoes = scorm_get_manifest($block['children'],$scoes); + break; + case 'ORGANIZATION': + $identifier = addslashes($block['attrs']['IDENTIFIER']); + $organization = ''; + $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier; + $scoes->elements[$manifest][$organization][$identifier]->parent = '/'; + $scoes->elements[$manifest][$organization][$identifier]->launch = ''; + $scoes->elements[$manifest][$organization][$identifier]->scormtype = ''; + + $parents = array(); + $parent = new stdClass(); + $parent->identifier = $identifier; + $parent->organization = $organization; + array_push($parents, $parent); + $organization = $identifier; + + $scoes = scorm_get_manifest($block['children'],$scoes); + + array_pop($parents); + break; + case 'ITEM': + $parent = array_pop($parents); + array_push($parents, $parent); + + $identifier = addslashes($block['attrs']['IDENTIFIER']); + $scoes->elements[$manifest][$organization][$identifier]->identifier = $identifier; + $scoes->elements[$manifest][$organization][$identifier]->parent = $parent->identifier; + if (!isset($block['attrs']['ISVISIBLE'])) { + $block['attrs']['ISVISIBLE'] = 'true'; + } + $scoes->elements[$manifest][$organization][$identifier]->isvisible = addslashes($block['attrs']['ISVISIBLE']); + if (!isset($block['attrs']['PARAMETERS'])) { + $block['attrs']['PARAMETERS'] = ''; + } + $scoes->elements[$manifest][$organization][$identifier]->parameters = addslashes($block['attrs']['PARAMETERS']); + if (!isset($block['attrs']['IDENTIFIERREF'])) { + $scoes->elements[$manifest][$organization][$identifier]->launch = ''; + $scoes->elements[$manifest][$organization][$identifier]->scormtype = 'asset'; + } else { + $idref = addslashes($block['attrs']['IDENTIFIERREF']); + $base = ''; + if (isset($resources[$idref]['XML:BASE'])) { + $base = $resources[$idref]['XML:BASE']; + } + $scoes->elements[$manifest][$organization][$identifier]->launch = addslashes($base.$resources[$idref]['HREF']); + if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) { + $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset'; + } + $scoes->elements[$manifest][$organization][$identifier]->scormtype = addslashes($resources[$idref]['ADLCP:SCORMTYPE']); + } + + //////fwrite($ft,"---Dang lam viec voi ITEM co Identifier = ".$identifier); + $parent = new stdClass(); + $parent->identifier = $identifier; + $parent->organization = $organization; + array_push($parents, $parent); + + $scoes = scorm_get_manifest($block['children'],$scoes); + + array_pop($parents); + break; + case 'TITLE': + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->title = addslashes($block['tagData']); + break; + case 'ADLCP:PREREQUISITES': + if ($block['attrs']['TYPE'] == 'aicc_script') { + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->prerequisites = addslashes($block['tagData']); + } + break; + case 'ADLCP:MAXTIMEALLOWED': + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->maxtimeallowed = addslashes($block['tagData']); + break; + case 'ADLCP:TIMELIMITACTION': + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->timelimitaction = addslashes($block['tagData']); + break; + case 'ADLCP:DATAFROMLMS': + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->datafromlms = addslashes($block['tagData']); + break; + case 'ADLCP:MASTERYSCORE': + $parent = array_pop($parents); + array_push($parents, $parent); + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->masteryscore = addslashes($block['tagData']); + break; + case 'ADLNAV:PRESENTATION': + $parent = array_pop($parents); + array_push($parents, $parent); + foreach ($block['children'] as $adlnav) { + if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') { //////fwrite($ft,$scoes->elements[$manifest][$parent->organization][$parent->identifier]->title." Xuat hien dieu khien NAV \n"); + foreach ($adlnav['children'] as $adlnavInterface){ + if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI'){ + //////fwrite($ft,$scoes->elements[$manifest][$parent->organization][$parent->identifier]->title." Xuat hien dieu khien NAV HIDELMSUI\n"); + //////fwrite($ft," Gia tri thuoc tinh an la ".$adlnavInterface['tagData']); + if ($adlnavInterface['tagData'] == 'continue') { + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->next = 1; +// //////fwrite($ft," Thiet lap thuoc tinh an OK "); + } + if ($adlnavInterface['tagData'] == 'previous') { + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->previous = 1; +// //////fwrite($ft," Thiet lap thuoc tinh an OK "); + } + } + + } + + } + } + break; + + case 'IMSSS:SEQUENCING': + $parent = array_pop($parents); + array_push($parents, $parent); + foreach ($block['children'] as $sequencing) { + //////fwrite($ft,"\n Xuat hien IMSSS:SEQUENCING cua ".$parent->identifier); + if ($sequencing['name']=='IMSSS:CONTROLMODE'){ + //Xu ly cac Control Mode voi mot Item trong SCO + if ($sequencing['attrs']['CHOICE'] == 'false'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choice = 0; + //////fwrite($ft,"\n Xuat hien lua chon choice \n"); + } + if ($sequencing['attrs']['CHOICEEXIT'] == 'false'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choiceexit = 0; + } + if ($sequencing['attrs']['FLOW'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->flow = 1; + } + if ($sequencing['attrs']['FORWARDONLY'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->forwardonly = 1; + } + if ($sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptobjectinfo = 1; + } + if ($sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptprogressinfo = 1; + } + } + if ($sequencing['name']=='ADLSEQ:CONSTRAINEDCHOICECONSIDERATIONS'){ + //Xu ly cac dieu kien rang buoc thu tu + if ($sequencing['attrs']['CONSTRAINCHOICE'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->constrainChoice = 1; + } + if ($sequencing['attrs']['PREVENTACTIVATION'] == 'true'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->preventactivation = 1; + } + + } + if ($sequencing['name']=='IMSSS:OBJECTIVES'){ + //Xu ly cac cac gia tri muc tieu + foreach ($sequencing['children'] as $objective){ + if($objective['name']=='IMSSS:PRIMARYOBJECTIVE'){ + //Xac dinh primary objective de lay thong so + foreach ($objective['children'] as $primaryobjective){ + if($primaryobjective['name']=='IMSSS:MINNORMALIZEDMEASURE'){ $scoes->elements[$manifest][$parent->organization][$parent->identifier]->minnormalizedmeasure = $primaryobjective['tagData']; + } + } + } + } + } + if ($sequencing['name']=='IMSSS:LIMITCONDITIONS'){ + //Xu ly cac cac gia tri cac dieu kien gioi han + if (!empty($sequencing['attrs']['ATTEMPTLIMIT'])){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptLimit = $sequencing['attrs']['ATTEMPTLIMIT']; + } + if (!empty($sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'])){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptAbsoluteDurationLimit = $sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT']; + } + } + if ($sequencing['name']=='IMSSS:ROLLUPRULES'){ + $rolluprules = array(); + //Phan danh cho RollupRule + if (!empty($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'])){ + if ($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED']== 'false'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupobjectivesatisfied = 0; + } + } + if (!empty($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'])){ + if ($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION']== 'false'){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupprogresscompletion = 0; + } + } + if (!empty($sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'])){ + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->objectivemeasureweight = $sequencing['attrs']['OBJECTIVEMEASUREWEIGHT']; + } + + if (!empty($sequencing['children'])){ + foreach ($sequencing['children'] as $sequencingrolluprule){ + if ($sequencingrolluprule['name']=='IMSSS:ROLLUPRULE' ){ + $rolluprule = new stdClass(); + if ($sequencingrolluprule['attrs']['CHILDACTIVITYSET'] !=' '){ + $rolluprule->childactivityset = $sequencingrolluprule['attrs']['CHILDACTIVITYSET']; + ////fwrite($ft,"\n Thiet lap them 1 childActivitySet la ".$rolluprule->childactivityset); + + //Phan xu ly danh sach condition + if (!empty($sequencingrolluprule['children'])){ + foreach ($sequencingrolluprule['children'] as $rolluproleconditions) + { + if ($rolluproleconditions['name']=='IMSSS:ROLLUPCONDITIONS'){ + $conditions = array(); + if (!empty($rolluproleconditions['attrs']['conditionCombination'])){ + $rolluprule->conditionCombination = $rolluproleconditions['attrs']['conditionCombination']; + } + foreach ($rolluproleconditions['children'] as $rolluprulecondition){ + if ($rolluprulecondition['name']=='IMSSS:ROLLUPCONDITION'){ + $condition = new stdClass(); + if (!empty($rolluprulecondition['attrs']['OPERATOR'])){ + $condition->operator = $rolluprulecondition['attrs']['OPERATOR']; + } + if (!empty($rolluprulecondition['attrs']['CONDITION'])){ + $condition->condition = $rolluprulecondition['attrs']['CONDITION']; + } + array_push($conditions,$condition); + ////fwrite($ft,"Da them mot rolluprulecondition"); + } + + } + $rolluprule->conditions = $conditions; + } + if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION'){ + $rolluprule->rollupruleaction = $rolluproleconditions['attrs']['ACTION']; + } + } + } + //Ket thuc xu ly danh sach condition + + } + ////fwrite($ft,"\n Dua them 1 rule vao \n"); + array_push($rolluprules, $rolluprule); + ////fwrite($ft,"\n Dua them 1 rule vao mang \n"); + } + + } + } + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules = $rolluprules; + +// ////fwrite($ft,"\n >>>>NOW TEST "); +// foreach ($scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules as $rolluptest){ +// ////fwrite($ft,"\n >>>> Gia tri Test thu duoc la:".$rolluptest->childactivityset); + + } + + + + if ($sequencing['name']=='IMSSS:SEQUENCINGRULES'){ + //Xu ly cac dieu kien Rules cua Sequencing + //////fwrite($ft,"\n Xuat hien SEQUENCINGRULES >>>>>>>>>>"); + $sequencingrules = array(); + foreach ($sequencing['children'] as $conditionrules){ + if($conditionrules['name']=='IMSSS:EXITCONDITIONRULE'){ + $sequencingrule = new stdClass(); + //Phan xu ly danh sach condition + //////fwrite($ft,"\n Xuat hien exitrule >>>>>>>>>>"); + if (!empty($conditionrules['children'])){ + foreach ($conditionrules['children'] as $conditionrule) + { + if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){ + $ruleconditions = array(); + if (!empty($conditionrule['attrs']['conditionCombination'])){ + $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination']; + } + foreach ($conditionrule['children'] as $rulecondition){ + if ($rulecondition['name']=='IMSSS:RULECONDITION'){ + $condition = new stdClass(); + if (!empty($rulecondition['attrs']['OPERATOR'])){ + $condition->operator = $rulecondition['attrs']['OPERATOR']; + } + if (!empty($rulecondition['attrs']['CONDITION'])){ + $condition->condition = $rulecondition['attrs']['CONDITION']; + } + if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){ + $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD']; + } + if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){ + $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE']; + } + array_push($ruleconditions,$condition); + ////fwrite($ft,"\n Da them mot rulecondition trong exitrule"); + } + + } + $sequencingrule->ruleconditions = $ruleconditions; + } + if ($conditionrule['name']=='IMSSS:RULEACTION'){ + $sequencingrule->exitconditionruleaction = $conditionrule['attrs']['ACTION']; + } + } + } + //Ket thuc xu ly danh sach condition + array_push($sequencingrules,$sequencingrule); + } + if ($conditionrules['name']=='IMSSS:PRECONDITIONRULE'){ + $sequencingrule = new stdClass(); + //Phan xu ly danh sach condition + if (!empty($conditionrules['children'])){ + foreach ($conditionrules['children'] as $conditionrule) + { + if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){ + $ruleconditions = array(); + if (!empty($conditionrule['attrs']['conditionCombination'])){ + $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination']; + } + foreach ($conditionrule['children'] as $rulecondition){ + if ($rulecondition['name']=='IMSSS:RULECONDITION'){ + $condition = new stdClass(); + if (!empty($rulecondition['attrs']['OPERATOR'])){ + $condition->operator = $rulecondition['attrs']['OPERATOR']; + } + if (!empty($rulecondition['attrs']['CONDITION'])){ + $condition->condition = $rulecondition['attrs']['CONDITION']; + } + if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){ + $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD']; + } + if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){ + $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE']; + } + array_push($ruleconditions,$condition); + ////fwrite($ft,"\n Da them mot rulecondition trong prerule"); + } + + } + $sequencingrule->ruleconditions = $ruleconditions; + } + if ($conditionrule['name']=='IMSSS:RULEACTION'){ + $sequencingrule->preconditionruleaction = $conditionrule['attrs']['ACTION']; + } + } + } + //Ket thuc xu ly danh sach condition + array_push($sequencingrules,$sequencingrule); + } + if($conditionrules['name']=='IMSSS:POSTCONDITIONRULE'){ + $sequencingrule = new stdClass(); + //Phan xu ly danh sach condition + if (!empty($conditionrules['children'])){ + foreach ($conditionrules['children'] as $conditionrule) + { + if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){ + $ruleconditions = array(); + if (!empty($conditionrule['attrs']['conditionCombination'])){ + $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination']; + } + foreach ($conditionrule['children'] as $rulecondition){ + if ($rulecondition['name']=='IMSSS:RULECONDITION'){ + $condition = new stdClass(); + if (!empty($rulecondition['attrs']['OPERATOR'])){ + $condition->operator = $rulecondition['attrs']['OPERATOR']; + } + if (!empty($rulecondition['attrs']['CONDITION'])){ + $condition->condition = $rulecondition['attrs']['CONDITION']; + } + if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){ + $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD']; + } + if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){ + $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE']; + } + array_push($ruleconditions,$condition); + ////fwrite($ft,"\n Da them mot rulecondition trong postrule"); + } + + } + $sequencingrule->ruleconditions = $ruleconditions; + } + if ($conditionrule['name']=='IMSSS:RULEACTION'){ + $sequencingrule->postconditionruleaction = $conditionrule['attrs']['ACTION']; + } + } + } + //Ket thuc xu ly danh sach condition + array_push($sequencingrules,$sequencingrule); + } + $scoes->elements[$manifest][$parent->organization][$parent->identifier]->sequencingrules = $sequencingrules; + } + } + } + + break; + + } + } + } + + return $scoes; +} + +function scorm_parse_scorm($pkgdir,$scormid) { + global $CFG; + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_parse_scorm \n"); + + $launch = 0; + $manifestfile = $pkgdir.'/imsmanifest.xml'; + + if (is_file($manifestfile)) { + + $xmlstring = file_get_contents($manifestfile); + $objXML = new xml2Array(); + $manifests = $objXML->parse($xmlstring); + + $scoes = new stdClass(); + $scoes->version = ''; + $scoes = scorm_get_manifest($manifests,$scoes); + + if (count($scoes->elements) > 0) { + foreach ($scoes->elements as $manifest => $organizations) { + foreach ($organizations as $organization => $items) { + foreach ($items as $identifier => $item) { + $item->scorm = $scormid; + $item->manifest = $manifest; + $item->organization = $organization; + //////fwrite($ft,"\n ---- Item chuan bi dua vao la ".$item->identifier); + $id = insert_record('scorm_scoes',$item); + //////fwrite($ft,"\n Lay duoc ScoID la ".$id); + $item->scormid = $scormid; + $item->scoid = $id; + $idControlMode = insert_record('scorm_sequencing_controlmode',$item); + + if (!empty($item->sequencingrules)){ + ////fwrite($ft,"\n ++++++++Them SequencingRules cho SCO: ".$item->scoid) ; + foreach($item->sequencingrules as $sequencingrule){ + ////fwrite($ft,"\n ----Chuan bi them 1 sequencingrule vao CSDL: "); + $sequencingrule->scormid = $scormid; + $sequencingrule->scoid = $item->scoid; + ////fwrite($ft,"\n ----Thong tin Scormid: ".$sequencingrule->scormid); + ////fwrite($ft,"\n ----Thong tin Scoid: ".$sequencingrule->scoid); + $idruleconditions = insert_record('scorm_sequencing_ruleconditions',$sequencingrule); + foreach($sequencingrule->ruleconditions as $rulecondition){ + $rulecondition->scormid = $sequencingrule->scormid; + $rulecondition->scoid = $sequencingrule->scoid; + $rulecondition->ruleconditionsid = $idruleconditions; + $idrulecondition = insert_record('scorm_sequencing_rulecondition',$rulecondition); + ////fwrite($ft,"\n ----Da them 1 sequencingrulecondition vao CSDL: "); + } + + } + } + + if (!empty($item->rolluprules)){ + ////fwrite($ft,"\n ++++++++Them RollupRules cho SCO: ".$item->scoid) ; + $idControlMode = insert_record('scorm_sequencing_rolluprules',$item); + ////fwrite($ft,"\n ----Gia tri idRollupRules \n"); + foreach($item->rolluprules as $rollup) + { + ////fwrite($ft,"\n ----Chuan bi them 1 rule vao CSDL "); + $rollup->rolluprulesid =$idControlMode; + $rollup->scormid = $scormid; + $rollup->scoid = $item->scoid; + + ////fwrite($ft,"\n ----Cac thong tin cua Rule: \n "); + ////fwrite($ft,"\n ----rolluprulesid: ".$rollup->rolluprulesid); + ////fwrite($ft,"\n ----scormid: ".$rollup->scormid ); + ////fwrite($ft,"\n ----scoid: ".$rollup->scoid); + ////fwrite($ft,"\n ----activichild: ".$rollup->childactivityset); + ////fwrite($ft,"\n ----rollupaction: ".$rollup->rollupruleaction); + $idRollupRule = insert_record('scorm_sequencing_rolluprule',$rollup); + ////fwrite($ft,"\n ----Dua them 1 rule vao CSDL -- Chuan bi them condition vao rule".$idRollupRule); + $rollup->rollupruleid = $idRollupRule; + $idconditions = insert_record('scorm_sequencing_rollupruleconditions',$rollup); + ////fwrite($ft,"\n --Dua cac condition con vao CSDL"); + foreach($rollup->conditions as $condition){ + $condition->ruleconditionsid = $idconditions; + $condition->scormid = $rollup->scormid; + $condition->scoid = $rollup->scoid; + $idcondition = insert_record('scorm_sequencing_rolluprulecondition',$condition); + ////fwrite($ft,"\n --Da dua them 1 condition vao CSDL"); + } + + + } + } + if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) { + $launch = $id; + } + } + } + } + set_field('scorm','version',$scoes->version,'id',$scormid); + } + } + + return $launch; +} + +function scorm_course_format_display($user,$course) { + global $CFG; + + $strupdate = get_string('update'); + $strmodule = get_string('modulename','scorm'); + + echo '
    '; + if ($scorms = get_all_instances_in_course('scorm', $course)) { + // The module SCORM activity with the least id is the course + $scorm = current($scorms); + if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + $colspan = ''; + $headertext = ''; + // Display report link + $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); + if ($trackedusers->c > 0) { + $headertext .= ''.format_text(get_string('summary').':
    '.$scorm->summary).'
    '.get_string('name').': '.format_string($scorm->name).''; + if (isteacher($course->id, $user->id, true)) { + if (isediting($course->id)) { + // Display update icon + $path = $CFG->wwwroot.'/course'; + $headertext .= ''. + ''. + ''.$strupdate.''; + } + $headertext .= '
    '; + print_simple_box($headertext,'','100%'); + scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%'); + } else { + if (isteacheredit($course->id, $user->id)) { + // Create a new activity + redirect('mod.php?id='.$course->id.'&section=0&sesskey='.sesskey().'&add=scorm'); + } else { + notify('Could not find a scorm course here'); + } + } + echo '
    '; +} + +function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') { + global $CFG; + $organization = optional_param('organization', '', PARAM_INT); + + print_simple_box_start('center',$blockwidth); +?> +
    +launch; + } + if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) { + if (count($orgs) > 1) { + ?> +
    + +
    + +
    +
    +organization == '') && ($org->launch == '')) { + $orgidentifier = $org->identifier; + } else { + $orgidentifier = $org->organization; + } + } + $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier); + $incomplete = $result->incomplete; +// echo ("Toc ---"); + echo $result->toc; +// echo ("Ket thuc"); + print_simple_box_end(); +?> +
    +
    popup == 1?' target="newwin"':'' ?>> + id,"userid",$user->id); + +//------------------ + if ($scorm->hidebrowse == 0) { + print_string("mode","scorm"); + echo ': '."\n"; + if ($incomplete === true) { + echo '\n"; + + //Neu co luu tru thi co the chon continue de tiep tu + if (!empty($suspend)) + { + echo '\n"; + } + + } else { + echo '\n"; + } + } else { + if ($incomplete === true) { + echo ''."\n"; + } else { + echo ''."\n"; + } + } + if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) { +?> +
    + + + +
    + + + +
    +
    +parent); +// ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_isChoice scoparent scormid la ".$scormid." scoid la: ".$scoparent->scoid); + + +// ////fwrite($ft,"\n Xu ly doc thong tin trong ham scorm_isChoice gia tri la: ".$scoparent->choice); + return $scoparent->choice; +} + +//Xac dinh xem doi tuong do co cho phep lua chon thoat khong +function scorm_isChoiceexit($scormid,$scoid) +{ + $sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid); + $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent); + + return $scoparent->choiceexit; +} +/* Usage + Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML; + + $objXML = new xml2Array(); + $arrOutput = $objXML->parse($strYourXML); + print_r($arrOutput); //print it out, or do whatever! + +*/ +class xml2Array { + + var $arrOutput = array(); + var $resParser; + var $strXmlData; + + /** + * Convert a utf-8 string to html entities + * + * @param string $str The UTF-8 string + * @return string + */ + function utf8_to_entities($str) { + $entities = ''; + $values = array(); + $lookingfor = 1; + + for ($i = 0; $i < strlen($str); $i++) { + $thisvalue = ord($str[$i]); + if ($thisvalue < 128) { + $entities .= $str[$i]; // Leave ASCII chars unchanged + } else { + if (count($values) == 0) { + $lookingfor = ($thisvalue < 224) ? 2 : 3; + } + $values[] = $thisvalue; + if (count($values) == $lookingfor) { + $number = ($lookingfor == 3) ? + (($values[0] % 16) * 4096) + (($values[1] % 64) * 64) + ($values[2] % 64): + (($values[0] % 32) * 64) + ($values[1] % 64); + $entities .= '&#' . $number . ';'; + $values = array(); + $lookingfor = 1; + } + } + } + return $entities; + } + + /** + * Parse an XML text string and create an array tree that rapresent the XML structure + * + * @param string $strInputXML The XML string + * @return array + */ + function parse($strInputXML) { + $this->resParser = xml_parser_create ('UTF-8'); + xml_set_object($this->resParser,$this); + xml_set_element_handler($this->resParser, "tagOpen", "tagClosed"); + + xml_set_character_data_handler($this->resParser, "tagData"); + + $this->strXmlData = xml_parse($this->resParser,$strInputXML ); + if(!$this->strXmlData) { + die(sprintf("XML error: %s at line %d", + xml_error_string(xml_get_error_code($this->resParser)), + xml_get_current_line_number($this->resParser))); + } + + xml_parser_free($this->resParser); + + return $this->arrOutput; + } + + function tagOpen($parser, $name, $attrs) { + $tag=array("name"=>$name,"attrs"=>$attrs); + array_push($this->arrOutput,$tag); + } + + function tagData($parser, $tagData) { + if(trim($tagData)) { + if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) { + $this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $this->utf8_to_entities($tagData); + } else { + $this->arrOutput[count($this->arrOutput)-1]['tagData'] = $this->utf8_to_entities($tagData); + } + } + } + + function tagClosed($parser, $name) { + $this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1]; + array_pop($this->arrOutput); + } + +} +?> diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index 1baeb7b2fb6..8c5b7724491 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -1,426 +1,431 @@ -dirroot.'/mod/scorm/lib.php'); - if (!isset($form->name)) { - $form->name = ''; - } - if (!isset($form->reference)) { - $form->reference = ''; - } - if (!isset($form->summary)) { - $form->summary = ''; - } - if (!isset($form->launch)) { - $form->launch = ''; - } - if (!isset($form->auto)) { - $form->auto = ''; - } - if (!isset($form->popup)) { - $form->popup = 0; - } - if (!isset($form->datadir)) { - $form->datadir = ''; - } - if (!isset($form->maxgrade)) { - $form->maxgrade = ''; - } - if (!isset($form->grademethod)) { - $form->grademethod = 0; - } - if (!isset($form->maxattempt)) { - $form->maxattempt = 1; - } - if (!isset($form->whatgrade)) { - $form->whatgrade = 0; - } - if (!isset($form->hidebrowse)) { - $form->hidebrowse = 0; - } - if (!isset($form->hidetoc)) { - $form->hidetoc = 0; - } - if (!isset($form->hidenav)) { - $form->hidenav = 0; - } - if (!isset($form->width)) { - $form->width = $CFG->scorm_framewidth; - } - if ((strpos($form->width,'%') === false) && ($form->width <= 100)) { - $form->width .= '%'; - } - if (!isset($form->height)) { - $form->height = $CFG->scorm_frameheight; - } - if ((strpos($form->height,'%') === false) && ($form->height <= 100)) { - $form->height .= '%'; - } - if (!isset($form->options) || empty($form->options)) { - $form->options = $stdoptions; - } - $options = explode(',',$form->options); - $window = new stdClass(); - foreach ($options as $option) { - list($element,$value) = explode('=',$option); - $element = trim($element); - $window->$element = trim($value)==1?'checked':''; - } - $scormid = ''; - if (!empty($form->instance)) { - $scormid = '&instance='.$form->instance; - } - $datadir = ''; - if (!empty($form->datadir)) { - $datadir = '&datadir='.$form->datadir; - } - $sessionkey = ''; - if (!empty($form->sesskey)) { - $sessionkey = '&sesskey='.$form->sesskey; - } - - $strfilename = get_string('coursepacket', 'scorm'); - $strchooseafile = get_string('chooseapacket', 'scorm'); - $striframe = get_string('iframe', 'scorm'); - $striframedisplay = get_string('iframedisplay', 'scorm'); - $strnewwindow = get_string('popup', 'scorm'); - $strnewwindowopen = get_string('popupopen', 'scorm'); - $strheight = get_string('height', 'scorm'); - $strwidth = get_string('width', 'scorm'); - $strresizable = get_string('resizable', 'scorm'); - $strscrollbars = get_string('scrollbars', 'scorm'); - $strdirectories = get_string('directories', 'scorm'); - $strlocation = get_string('location', 'scorm'); - $strmenubar = get_string('menubar', 'scorm'); - $strtoolbar = get_string('toolbar', 'scorm'); - $strstatus = get_string('statusbar', 'scorm'); -?> - - - - -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    : - -
    :
    - -
    - summary); ?> -
    - : - -   - id.'&choose=form.reference', - 'coursefiles', $strchooseafile, 500, 750, $strchooseafile); - helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true); - ?> -
    : - grademethod, '','checkscormform(this,0,document.form.maxgrade);'); - helpbutton('grademethod', get_string('grademethod','scorm'), 'scorm'); - ?> -
    : - =1; $i--) { - $grades[$i] = $i; - } - $disabled = $form->grademethod=='0'; - choose_from_menu($grades, 'maxgrade', (int) $form->maxgrade, '','','0',false,$disabled); - helpbutton('maxgrade', get_string('maximumgrade'), 'scorm'); - ?> -
    : - scorm_maxattempts; $i++) { - if ($i == 1) { - $attempts[$i] = $i . ' ' . get_string('attempt','scorm'); - } else { - $attempts[$i] = $i . ' ' . get_string('attempts','scorm'); - } - } - choose_from_menu($attempts, 'maxattempt', (int) $form->maxattempt, get_string('nolimit','scorm'),'checkscormform(this,1,document.form.whatgrade);'); - helpbutton('maxattempt', get_string('maximumattempts','scorm'), 'scorm'); - ?> -
    : - maxattempt === 1; - choose_from_menu($SCORM_WHAT_GRADE, 'whatgrade', (int) $form->whatgrade, '','','0',false,$disabled); - helpbutton('whatgrade', get_string('whatgrade','scorm'), 'scorm'); - ?> -

    : - - - -
    -
    - - - - - - - - - - - - - - - - - -
    : - auto,''); - helpbutton('autocontinue', get_string('autocontinue','scorm'), 'scorm', true); - ?> -
    : - hidebrowse, ''); - helpbutton('browsemode', get_string('hidebrowse','scorm'), 'scorm', true); - ?> -
    : - hidetoc, ''); - ?> -
    : - hidenav, ''); - ?> -
    -
    -
    : - - - -
    -
    - - - - - - - - - - -
    - -
    - -
    - - -
    - -
    :
    - popup == 0) ? "checked=\"checked\"" : "" ?> - onclick="return lockoptions('form', 'popup[1]', popupitems);" - /> - -
    - popup == 1) ? 'checked="checked"' : '' ?> - onclick="return lockoptions('form', 'popup[1]', popupitems);" - /> - -
    - $value) { - echo "\n"; - echo "$name." alt=\"$name\" />\n"; - $stringname = "str$name"; - echo $$stringname."
    \n"; - } - ?> - -
    -
    -
    - -
    - - - - format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) { - ?> - - - - - - - - - - - -
    - - -
    -
    +dirroot.'/mod/scorm/lib.php'); + if (!isset($form->name)) { + $form->name = ''; + } + if (!isset($form->reference)) { + $form->reference = ''; + } + if (!isset($form->summary)) { + $form->summary = ''; + } + if (!isset($form->launch)) { + $form->launch = ''; + } + if (!isset($form->auto)) { + $form->auto = ''; + } + if (!isset($form->popup)) { + $form->popup = 0; + } + if (!isset($form->datadir)) { + $form->datadir = ''; + } + if (!isset($form->maxgrade)) { + $form->maxgrade = ''; + } + if (!isset($form->grademethod)) { + $form->grademethod = 0; + } + if (!isset($form->maxattempt)) { + $form->maxattempt = 1; + } + if (!isset($form->whatgrade)) { + $form->whatgrade = 0; + } + if (!isset($form->hidebrowse)) { + $form->hidebrowse = 0; + } + if (!isset($form->hidetoc)) { + $form->hidetoc = 0; + } + if (!isset($form->hidenav)) { + $form->hidenav = 0; + } + if (!isset($form->width)) { + $form->width = $CFG->scorm_framewidth; + } + if ((strpos($form->width,'%') === false) && ($form->width <= 100)) { + $form->width .= '%'; + } + if (!isset($form->height)) { + $form->height = $CFG->scorm_frameheight; + } + if ((strpos($form->height,'%') === false) && ($form->height <= 100)) { + $form->height .= '%'; + } + if (!isset($form->options) || empty($form->options)) { + $form->options = $stdoptions; + } + $options = explode(',',$form->options); + $window = new stdClass(); + foreach ($options as $option) { + list($element,$value) = explode('=',$option); + $element = trim($element); + $window->$element = trim($value)==1?'checked':''; + } + $scormid = ''; + if (!empty($form->instance)) { + $scormid = '&instance='.$form->instance; + } + $datadir = ''; + if (!empty($form->datadir)) { + $datadir = '&datadir='.$form->datadir; + } + $sessionkey = ''; + if (!empty($form->sesskey)) { + $sessionkey = '&sesskey='.$form->sesskey; + } + + $strfilename = get_string('coursepacket', 'scorm'); + $strchooseafile = get_string('chooseapacket', 'scorm'); + $striframe = get_string('iframe', 'scorm'); + $striframedisplay = get_string('iframedisplay', 'scorm'); + $strnewwindow = get_string('popup', 'scorm'); + $strnewwindowopen = get_string('popupopen', 'scorm'); + $strheight = get_string('height', 'scorm'); + $strwidth = get_string('width', 'scorm'); + $strresizable = get_string('resizable', 'scorm'); + $strscrollbars = get_string('scrollbars', 'scorm'); + $strdirectories = get_string('directories', 'scorm'); + $strlocation = get_string('location', 'scorm'); + $strmenubar = get_string('menubar', 'scorm'); + $strtoolbar = get_string('toolbar', 'scorm'); + $strstatus = get_string('statusbar', 'scorm'); +?> + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    : + +
    :
    + +
    + summary); ?> +
    + : + +   + id.'&choose=form.reference', + 'coursefiles', $strchooseafile, 500, 750, $strchooseafile); + helpbutton('package', get_string('coursepacket', 'scorm'), 'scorm', true); + ?> +
    : + grademethod, '','checkscormform(this,0,document.form.maxgrade);'); + helpbutton('grademethod', get_string('grademethod','scorm'), 'scorm'); + ?> +
    : + =1; $i--) { + $grades[$i] = $i; + } + $disabled = $form->grademethod=='0'; + choose_from_menu($grades, 'maxgrade', (int) $form->maxgrade, '','','0',false,$disabled); + helpbutton('maxgrade', get_string('maximumgrade'), 'scorm'); + ?> +
    : + scorm_maxattempts; $i++) { + if ($i == 1) { + $attempts[$i] = $i . ' ' . get_string('attempt','scorm'); + } else { + $attempts[$i] = $i . ' ' . get_string('attempts','scorm'); + } + } + choose_from_menu($attempts, 'maxattempt', (int) $form->maxattempt, get_string('nolimit','scorm'),'checkscormform(this,1,document.form.whatgrade);'); + helpbutton('maxattempt', get_string('maximumattempts','scorm'), 'scorm'); + ?> +
    : + maxattempt === 1; + choose_from_menu($SCORM_WHAT_GRADE, 'whatgrade', (int) $form->whatgrade, '','','0',false,$disabled); + helpbutton('whatgrade', get_string('whatgrade','scorm'), 'scorm'); + ?> +

    : + + + +
    +
    + + + + + + + + + + + + + + + + + +
    : + auto,''); + helpbutton('autocontinue', get_string('autocontinue','scorm'), 'scorm', true); + ?> +
    : + hidebrowse, ''); + helpbutton('browsemode', get_string('hidebrowse','scorm'), 'scorm', true); + ?> +
    : + hidetoc, ''); + ?> +
    : + hidenav, ''); + ?> +
    +
    +
    : + + + +
    +
    + + + + + + + + + + +
    + +
    + +
    + + +
    + +
    :
    + popup == 0) ? "checked=\"checked\"" : "" ?> + onclick="return lockoptions('form', 'popup[1]', popupitems);" + /> + +
    + popup == 1) ? 'checked="checked"' : '' ?> + onclick="return lockoptions('form', 'popup[1]', popupitems);" + /> + +
    + $value) { + echo "\n"; + echo "$name." alt=\"$name\" />\n"; + $stringname = "str$name"; + echo $$stringname."
    \n"; + } + ?> + +
    +
    +
    + +
    + + + + format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) { + ?> + + + + + + + + + + + +
    + + +
    +
    diff --git a/mod/scorm/player.php b/mod/scorm/player.php index 2a4b7d55d51..17dc67327e0 100755 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -1,307 +1,436 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } else { - error('A required parameter is missing'); - } - - require_login($course->id, false, $cm); - - $strscorms = get_string('modulenameplural', 'scorm'); - $strscorm = get_string('modulename', 'scorm'); - $strpopup = get_string('popup','scorm'); - - if ($course->category != 0) { - $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname ->"; - if ($scorms = get_all_instances_in_course('scorm', $course)) { - // The module SCORM activity with the least id is the course - $firstscorm = current($scorms); - if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) { - $navigation .= "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; - } - } - } else { - $navigation = "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; - } - - $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name)); - - if (!$cm->visible and !isteacher($course->id)) { - print_header($pagetitle, "$course->fullname", - "$navigation ".format_string($scorm->name,true)."", - '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false); - notice(get_string("activityiscurrentlyhidden")); - } - - // - // TOC processing - // - $attempt = scorm_get_last_attempt($scorm->id, $USER->id); - if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) { - $attempt++; - } - $attemptstr = '&attempt=' . $attempt; - - $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true); - $sco = $result->sco; - - if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { - $mode = 'normal'; - } - if ($mode != 'browse') { - if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) { - if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) { - $mode = 'review'; - } else { - $mode = 'normal'; - } - } - } - - add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id"); - - $scoidstr = '&scoid='.$sco->id; - $scoidpop = '&scoid='.$sco->id; - $modestr = '&mode='.$mode; - if ($mode == 'browse') { - $modepop = '&mode='.$mode; - } else { - $modepop = ''; - } - $orgstr = '¤torg='.$currentorg; - - $SESSION->scorm_scoid = $sco->id; - $SESSION->scorm_status = 'Not Initialized'; - $SESSION->scorm_mode = $mode; - $SESSION->attempt = $attempt; - - // - // Print the page header - // - $bodyscript = ''; - if ($scorm->popup == 1) { - $bodyscript = 'onunload="main.close();"'; - } - $exitlink = '('.get_string('exit','scorm').') '; - print_header($pagetitle, "$course->fullname", - "$navigation ".format_string($scorm->name,true)."", - '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript); - if ($sco->scormtype == 'sco') { -?> - - -previd != 0) && ($sco->previous == 0)) { - $scostr = '&scoid='.$sco->previd; - echo ' \n"; - } else { - echo ' \n"; - } - if (($sco->nextid != 0) && ($sco->next == 0)) { - $scostr = '&scoid='.$sco->nextid; - echo ' \n"; - } else { - echo ' \n"; - } -?> -
    -hidetoc == 0) { -?> -
    -
    -
    - toc; ?> -
    -
    - -
    > -hidenav == 0) && // Teacher want to display navigation links - ( - ( - ($sco->previd != 0) && // This is not the first learning object of the package - ($sco->previous == 0) // Moodle must manage the previous link - ) || - ( - ($sco->nextid != 0) && // This is not the last learning object of the package - ($sco->next == 0) // Moodle must manage the next link - ) - ) - ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small popup menu - ) { -?> -
    - '.get_string('browsemode','scorm')."
    \n" : ''; ?> - '.get_string('reviewmode','scorm')."
    \n" : ''; ?> -hidenav == 0) || ($scorm->hidetoc == 2)) { -?> -
    - hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) { - /// Print the prev LO link - $scostr = '&scoid='.$sco->previd; - $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr; - echo '< '.get_string('prev','scorm').''; - } - if ($scorm->hidetoc == 2) { - echo $result->tocmenu; - } - if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) { - /// Print the next LO link - $scostr = '&scoid='.$sco->nextid; - $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr; - echo '  '.get_string('next','scorm').' >'; - } - ?> - -
    - -
    - -
    - -prerequisites) { - if ($scorm->popup == 0) { - if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { - /// Internet Explorer does not has full support to objects -?> - - - - - - - - - -
    - - - - - - - +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } else { + error('A required parameter is missing'); + } + + require_login($course->id, false, $cm); + + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + //fwrite($ft,"\n ++ Thong tin quyen set attempt ".$USER->setAttempt); + $strscorms = get_string('modulenameplural', 'scorm'); + $strscorm = get_string('modulename', 'scorm'); + $strpopup = get_string('popup','scorm'); + + + $attempt = scorm_get_last_attempt($scorm->id,$USER->id); + + //Kiem tra xem co phai la tiep tuc khong + if ($mode=='continue') + { + $scoid = scorm_get_suspendscoid($scorm->id,$USER->id); + $USER->setAttempt = 'set'; + $mode = 'normal'; + } + if (($mode == 'normal') && ($USER->setAttempt == 'notset')){ + $attempt++; + $USER->setAttempt = 'set'; + } + //Thuc hien Sequencing + + if ($mode!='review') + { + $sequencingResult = scorm_sequecingrule_implement($scorm->id,$scoid,$USER->id); + //echo ""; + } + if (($sequencingResult->rule == 'exit') && ($sequencingResult->action == 'exit')){ + $exitscoid = get_sco_after_exit($scoid,$scorm->id); + //fwrite($ft,"\n ++ Thong tin exit sco la ".$exitscoid); + $orgstr = '¤torg='.$currentorg; + $modepop = '&mode='.$mode; + $scostr = '&scoid='.$exitscoid; + echo ""; + + } + } + + //Thiet lap attempt_status cho scoid + scorm_set_attempt($scoid,$USER->id); + //Ket thuc thiet lap attemp_status + if ($mode!='review') + { + //Update trang thai + scorm_rollup_updatestatus($scorm->id,$scoid,$USER->id); + //------------------------------ + } + //Thiet lap thong tin lien quan truy xuat Scorm + $statistic = get_record('scorm_statistic',"scormid",$scorm->id,"userid",$USER->id); + if (empty($statistic)){ + $statisticInput->accesstime = time(); + $statisticInput->durationtime = 0; + $statisticInput->status = 'during'; + $statisticInput->attemptnumber = $attempt; + $statisticInput->scormid = $scorm->id; + $statisticInput->userid = $USER->id; + $statisticid = scorm_insert_statistic($statisticInput); + } + else{ + if ($statistic->status=='suspend'){ + $statisticInput->accesstime = time(); + $statisticInput->durationtime = $statistic->durationtime; + $statisticInput->status = 'during'; + $statisticInput->attemptnumber = $attempt; + $statisticInput->scormid = $scorm->id; + $statisticInput->userid = $USER->id; + } + } + + //---------------------Ket thuc thiet lap thoi gian --------------- + + //Lay thoi gian toi da cho phep + $absoluteTimeLimit = scorm_get_AbsoluteTimeLimit($scoid); + if ($absoluteTimeLimit > 0) + { + echo ""; + } + //-------------------------------- + + + if ($course->category != 0) { + $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname ->"; + if ($scorms = get_all_instances_in_course('scorm', $course)) { + // The module SCORM activity with the least id is the course + $firstscorm = current($scorms); + if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) { + $navigation .= "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; + } + } + } else { + $navigation = "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; + } + + $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name)); + + if (!$cm->visible and !isteacher($course->id)) { + print_header($pagetitle, "$course->fullname", + "$navigation ".format_string($scorm->name,true)."", + '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false); + notice(get_string("activityiscurrentlyhidden")); + } + + // + // TOC processing + // + //$attempt = scorm_get_last_attempt($scorm->id, $USER->id); + //$f = "D:\\test.txt"; + //@$ft = fopen($f,"a"); + ////fwrite($ft,"\n ++ ++ + ++ Gia tri $attempt lay duoc la ".$attempt); + + //if ($mode=='normal'){ + // $newattempt = 'on'; + //} + if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) { + $attempt++; + $f = "D:\\test.txt"; + @$ft = fopen($f,"a"); + //fwrite($ft,"\n ----New attempt------- ".$attempt); + + } + $attemptstr = '&attempt=' . $attempt; + + //fwrite($ft,"\n ----Gia tri attempt bay gio la------- ".$attempt); + $result = scorm_get_toc($USER,$scorm,'structurelist',$currentorg,$scoid,$mode,$attempt,true); + $sco = $result->sco; + + if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { + $mode = 'normal'; + } + if ($mode != 'browse') { + ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode khac browser ".$mode); + if ($trackdata = scorm_get_tracks($sco->id,$USER->id,$attempt)) { + if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) { + $mode = 'review'; + ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode); + } else { + $mode = 'normal'; + ////fwrite($ft,"\n ++ ++ + ++ Gia tri $mode ".$mode); + + } + } + } + + add_to_log($course->id, 'scorm', 'view', "player.php?id=$cm->id&scoid=$sco->id", "$scorm->id"); + + $scoidstr = '&scoid='.$sco->id; + $scoidpop = '&scoid='.$sco->id; + $modestr = '&mode='.$mode; + if ($mode == 'browse') { + $modepop = '&mode='.$mode; + } else { + $modepop = ''; + } + $orgstr = '¤torg='.$currentorg; + + $SESSION->scorm_scoid = $sco->id; + $SESSION->scorm_status = 'Not Initialized'; + $SESSION->scorm_mode = $mode; + $SESSION->attempt = $attempt; + + // Doan code them + ////fwrite($ft,"\n ++ ++ + ++ Gia tri attempt duoc gan cho user la ".$attempt); + $USER->attempt = $attempt; + //------------Ket thuc doan them + + // + // Print the page header + // + $bodyscript = ''; + if ($scorm->popup == 1) { + $bodyscript = 'onunload="main.close();"'; + } + + // Kiem tra xem co duoc exit khong + if (scorm_isChoiceexit($sco->scorm,$sco->id)){ + $exitlink = '('.get_string('exit','scorm').') '; + } + else + { + $exitlink = get_string('exitisnotallowed','scorm'); + } + + //Luu giu khoa hoc thoat ra + $suspend = '('.get_string('suspend','scorm').') '; + + print_header($pagetitle, "$course->fullname", + "$navigation ".format_string($scorm->name,true)."", + '', '', true, $exitlink.$suspend.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript); + if ($sco->scormtype == 'sco') { +?> + + +previd != 0) && ($sco->previous == 0)) { + $scostr = '&scoid='.$sco->previd; + echo ' \n"; + } else { + echo ' \n"; + } + if (($sco->nextid != 0) && ($sco->next == 0)) { + $scostr = '&scoid='.$sco->nextid; + echo ' \n"; + } else { + echo ' \n"; + } +?> +
    +hidetoc == 0) { +?> +
    +
    +
    + toc; ?> +
    +
    + +
    > +hidenav == 0) && // Teacher want to display navigation links + ( + ( + ($sco->previd != 0) && // This is not the first learning object of the package + ($sco->previous == 0) // Moodle must manage the previous link + ) || + ( + ($sco->nextid != 0) && // This is not the last learning object of the package + ($sco->next == 0) // Moodle must manage the next link + ) + ) + ) || ($scorm->hidetoc == 2) // Teacher want to display toc in a small dropdown menu + ) { +?> +
    + '.get_string('browsemode','scorm')."
    \n" : ''; ?> + '.get_string('reviewmode','scorm')."
    \n" : ''; ?> +hidenav == 0) || ($scorm->hidetoc == 2)) { +?> +
    + hidenav == 0) && ($sco->previd != 0) && ($sco->previous == 0)) { + /// Print the prev LO link + $scostr = '&scoid='.$sco->previd; + $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr; + echo '< '.get_string('prev','scorm').''; + } + if ($scorm->hidetoc == 2) { + echo $result->tocmenu; + } + if (($scorm->hidenav == 0) && ($sco->nextid != 0) && ($sco->next == 0)) { + /// Print the next LO link + $scostr = '&scoid='.$sco->nextid; + $url = $CFG->wwwroot.'/mod/scorm/player.php?id='.$cm->id.$orgstr.$modestr.$scostr; + echo '  '.get_string('next','scorm').' >'; + } + ?> + +
    + +
    + +
    + +prerequisites) { + if ($scorm->popup == 0) { + if (strpos('MSIE',$_SERVER['HTTP_USER_AGENT']) === false) { + /// Internet Explorer does not has full support to objects +?> + + + + + + + + + +
    + + + + + + + + diff --git a/mod/scorm/report.php b/mod/scorm/report.php index 59f56688aed..6145e401543 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -1,320 +1,369 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else { - if (!empty($b)) { - if (! $sco = get_record("scorm_scoes", "id", $b)) { - error("Scorm activity is incorrect"); - } - $a = $sco->scorm; - } - if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } - } - - require_login($course->id, false, $cm); - - if (!isteacher($course->id)) { - error("You are not allowed to use this script"); - } - - add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id"); - -/// Print the page header - if (empty($noheader)) { - if ($course->category) { - $navigation = "id\">$course->shortname ->"; - } else { - $navigation = ''; - } - - $strscorms = get_string("modulenameplural", "scorm"); - $strscorm = get_string("modulename", "scorm"); - $strreport = get_string("report", "scorm"); - $strname = get_string('name'); - if (empty($b)) { - print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", - "$navigation id\">$strscorms - -> id\">".format_string($scorm->name,true)." -> $strreport", - "", "", true); - } else { - print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", - "$navigation id\">$strscorms - -> id\">".format_string($scorm->name,true)." - -> id\">$strreport -> $sco->title", - "", "", true); - } - print_heading(format_string($scorm->name)); - } - - $scormpixdir = $CFG->modpixpath.'/scorm/pix'; - - if (empty($b) ) { - if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { - if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) { - $table = new stdClass(); - $table->head = array(' ', $strname); - $table->align = array('center', 'left'); - $table->wrap = array('nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array(10, '*'); - foreach ($scoes as $sco) { - if ($sco->launch!='') { - $table->head[]=scorm_string_wrap($sco->title); - //$table->head[]=$sco->title; - $table->align[] = 'center'; - $table->wrap[] = 'nowrap'; - $table->size[] = '*'; - } - } - - foreach ($scousers as $scouser) { - if ($userdata = scorm_get_user_data($scouser->userid)) { - $row = array(); - $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); - $row[] = "wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". - "$userdata->firstname $userdata->lastname"; - foreach ($scoes as $sco) { - if ($sco->launch!='') { - $anchorstart = ''; - $anchorend = ''; - $scoreview = ''; - if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) { - if ($trackdata->score_raw != '') { - $scoreview = '
    '.get_string('score','scorm').': '.$trackdata->score_raw; - } - if ($trackdata->status == '') { - $trackdata->status = 'notattempted'; - } else { - $anchorstart = ''; - $anchorend = ''; - } - } else { - $trackdata->status = 'notattempted'; - $trackdata->total_time = ''; - } - $strstatus = get_string($trackdata->status,'scorm'); - $row[] = $anchorstart.''.$strstatus.' '.$trackdata->total_time.$scoreview.$anchorend; - } - } - $table->data[] = $row; - } - } - print_table($table); - } else { - notice('No users to report'); - } - } - } else { - if (!empty($user)) { - if ($userdata = scorm_get_user_data($user)) { - print_simple_box_start('center'); - print_heading(format_string($sco->title)); - echo '
    '."\n"; - print_user_picture($user, $course->id, $userdata->picture, false, false); - echo "wwwroot/user/view.php?id=$user&course=$course->id\">". - "$userdata->firstname $userdata->lastname
    "; - $scoreview = ''; - if ($trackdata = scorm_get_tracks($sco->id,$user)) { - if ($trackdata->score_raw != '') { - $scoreview = get_string('score','scorm').': '.$trackdata->score_raw; - } - if ($trackdata->status == '') { - $trackdata->status = 'notattempted'; - } - } else { - $trackdata->status = 'notattempted'; - $trackdata->total_time = ''; - } - $strstatus = get_string($trackdata->status,'scorm'); - echo ''.$strstatus.' '.$trackdata->total_time.'
    '.$scoreview.'
    '; - echo '
    '."\n"; - echo '

    '.get_string('details','scorm').'

    '; - - // Print general score data - $table = new stdClass(); - $table->head = array(get_string('element','scorm'), get_string('value','scorm')); - $table->align = array('left', 'left'); - $table->wrap = array('nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*'); - - $existelements = false; - if ($scorm->version == 'SCORM_1.3') { - $elements = array('raw' => 'cmi.score.raw', - 'min' => 'cmi.score.min', - 'max' => 'cmi.score.max', - 'status' => 'cmi.completition_status', - 'time' => 'cmi.total_time'); - } else { - $elements = array('raw' => 'cmi.core.score.raw', - 'min' => 'cmi.core.score.min', - 'max' => 'cmi.core.score.max', - 'status' => 'cmi.core.lesson_status', - 'time' => 'cmi.core.total_time'); - } - foreach ($elements as $key => $element) { - if (isset($trackdata->$element)) { - $existelements = true; - $printedelements[]=$element; - $row = array(); - $row[] = get_string($key,'scorm'); - $row[] = $trackdata->$element; - $table->data[] = $row; - } - } - if ($existelements) { - echo '

    '.get_string('general','scorm').'

    '; - print_table($table); - } - - // Print Interactions data - $table = new stdClass(); - $table->head = array(get_string('identifier','scorm'), - get_string('type','scorm'), - get_string('result','scorm'), - get_string('student_response','scorm')); - $table->align = array('center', 'center', 'center', 'center'); - $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*', '*', '*', '*'); - - $existinteraction = false; - - $i = 0; - $interactionid = 'cmi.interactions.'.$i.'.id'; - - while (isset($trackdata->$interactionid)) { - $existinteraction = true; - $printedelements[]=$interactionid; - $elements = array($interactionid, - 'cmi.interactions.'.$i.'.type', - 'cmi.interactions.'.$i.'.result', - 'cmi.interactions.'.$i.'.student_response'); - $row = array(); - foreach ($elements as $element) { - if (isset($trackdata->$element)) { - $row[] = $trackdata->$element; - $printedelements[]=$element; - } else { - $row[] = ' '; - } - } - $table->data[] = $row; - - $i++; - $interactionid = 'cmi.interactions.'.$i.'.id'; - } - if ($existinteraction) { - echo '

    '.get_string('interactions','scorm').'

    '; - print_table($table); - } - - // Print Objectives data - $table = new stdClass(); - $table->head = array(get_string('identifier','scorm'), - get_string('status','scorm'), - get_string('raw','scorm'), - get_string('min','scorm'), - get_string('max','scorm')); - $table->align = array('center', 'center', 'center', 'center', 'center'); - $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap'); - $table->width = '100%'; - $table->size = array('*', '*', '*', '*', '*'); - - $existobjective = false; - - $i = 0; - $objectiveid = 'cmi.objectives.'.$i.'.id'; - - while (isset($trackdata->$objectiveid)) { - $existobjective = true; - $printedelements[]=$objectiveid; - $elements = array($objectiveid, - 'cmi.objectives.'.$i.'.status', - 'cmi.objectives.'.$i.'.score.raw', - 'cmi.objectives.'.$i.'.score.min', - 'cmi.objectives.'.$i.'.score.max'); - $row = array(); - foreach ($elements as $element) { - if (isset($trackdata->$element)) { - $row[] = $trackdata->$element; - $printedelements[]=$element; - } else { - $row[] = ' '; - } - } - $table->data[] = $row; - - $i++; - $objectiveid = 'cmi.objectives.'.$i.'.id'; - } - if ($existobjective) { - echo '

    '.get_string('objectives','scorm').'

    '; - print_table($table); - } - $table = new stdClass(); - $table->head = array(get_string('element','scorm'), get_string('value','scorm')); - $table->align = array('left', 'left'); - $table->wrap = array('nowrap', 'wrap'); - $table->width = '100%'; - $table->size = array('*', '*'); - - $existelements = false; - - foreach($trackdata as $element => $value) { - if (substr($element,0,3) == 'cmi') { - if (!(in_array ($element, $printedelements))) { - $existelements = true; - $row = array(); - $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element; - $row[] = $value; - $table->data[] = $row; - } - } - } - if ($existelements) { - echo '

    '.get_string('othertracks','scorm').'

    '; - print_table($table); - } - print_simple_box_end(); - } - } else { - error('Missing script parameter'); - } - } - if (empty($noheader)) { - print_footer($course); - } -?> +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else { + if (!empty($b)) { + if (! $sco = get_record("scorm_scoes", "id", $b)) { + error("Scorm activity is incorrect"); + } + $a = $sco->scorm; + } + if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } + } + + require_login($course->id, false, $cm); + + if (!isteacher($course->id)) { + error("You are not allowed to use this script"); + } + + add_to_log($course->id, "scorm", "report", "report.php?id=$cm->id", "$scorm->id"); + +/// Print the page header + if (empty($noheader)) { + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } else { + $navigation = ''; + } + + $strscorms = get_string("modulenameplural", "scorm"); + $strscorm = get_string("modulename", "scorm"); + $strreport = get_string("report", "scorm"); + $strname = get_string('name'); + if (empty($b)) { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." -> $strreport", + "", "", true); + } else { + print_header("$course->shortname: ".format_string($scorm->name), "$course->fullname", + "$navigation id\">$strscorms + -> id\">".format_string($scorm->name,true)." + -> id\">$strreport -> $sco->title", + "", "", true); + } + print_heading(format_string($scorm->name)); + } + + $scormpixdir = $CFG->modpixpath.'/scorm/pix'; + + if (empty($b) ) { + if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) { + if ($scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid")) { + $table = new stdClass(); + $table->head = array(' ', $strname); + $table->align = array('center', 'left'); + $table->wrap = array('nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array(10, '*'); + foreach ($scoes as $sco) { + if ($sco->launch!='') { + $table->head[]=scorm_string_wrap($sco->title); + //$table->head[]=$sco->title; + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + } + } + + foreach ($scousers as $scouser) { + if ($userdata = scorm_get_user_data($scouser->userid)) { + $row = array(); + $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); + $row[] = "wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". + "$userdata->firstname $userdata->lastname"; + foreach ($scoes as $sco) { + if ($sco->launch!='') { + $anchorstart = ''; + $anchorend = ''; + $scoreview = ''; + if ($trackdata = scorm_get_tracks($sco->id,$scouser->userid)) { + if ($trackdata->score_raw != '') { + $scoreview = '
    '.get_string('score','scorm').': '.$trackdata->score_raw; + } + if ($trackdata->status == '') { + $trackdata->status = 'notattempted'; + } else { + $anchorstart = ''; + $anchorend = ''; + } + } else { + $trackdata->status = 'notattempted'; + $trackdata->total_time = ''; + } + $strstatus = get_string($trackdata->status,'scorm'); + $row[] = $anchorstart.''.$strstatus.' '.$trackdata->total_time.$scoreview.$anchorend; + } + } + $table->data[] = $row; + } + } + print_table($table); + } else { + notice('No users to report'); + } + } + } else { + if (!empty($user)) { + if ($userdata = scorm_get_user_data($user)) { + print_simple_box_start('center'); + print_heading(format_string($sco->title)); + echo '
    '."\n"; + print_user_picture($user, $course->id, $userdata->picture, false, false); + echo "wwwroot/user/view.php?id=$user&course=$course->id\">". + "$userdata->firstname $userdata->lastname
    "; + $scoreview = ''; + if ($trackdata = scorm_get_tracks($sco->id,$user)) { + if ($trackdata->score_raw != '') { + $scoreview = get_string('score','scorm').': '.$trackdata->score_raw; + } + if ($trackdata->status == '') { + $trackdata->status = 'notattempted'; + } + } else { + $trackdata->status = 'notattempted'; + $trackdata->total_time = ''; + } + $strstatus = get_string($trackdata->status,'scorm'); + echo ''.$strstatus.' '.$trackdata->total_time.'
    '.$scoreview.'
    '; + echo '
    '."\n"; + echo '

    '.get_string('details','scorm').'

    '; + + // Print general score data + $table = new stdClass(); + $table->head = array(get_string('element','scorm'), get_string('value','scorm')); + $table->align = array('left', 'left'); + $table->wrap = array('nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*'); + + $existelements = false; + if ($scorm->version == 'SCORM_1.3') { + $elements = array('raw' => 'cmi.score.raw', + 'min' => 'cmi.score.min', + 'max' => 'cmi.score.max', + 'status' => 'cmi.completition_status', + 'time' => 'cmi.total_time'); + } else { + $elements = array('raw' => 'cmi.core.score.raw', + 'min' => 'cmi.core.score.min', + 'max' => 'cmi.core.score.max', + 'status' => 'cmi.core.lesson_status', + 'time' => 'cmi.core.total_time'); + } + foreach ($elements as $key => $element) { + if (isset($trackdata->$element)) { + $existelements = true; + $printedelements[]=$element; + $row = array(); + $row[] = get_string($key,'scorm'); + $row[] = $trackdata->$element; + $table->data[] = $row; + } + } + if ($existelements) { + echo '

    '.get_string('general','scorm').'

    '; + print_table($table); + } + + // Print Interactions data + $table = new stdClass(); + $table->head = array(get_string('identifier','scorm'), + get_string('type','scorm'), + get_string('result','scorm'), + get_string('student_response','scorm')); + $table->align = array('center', 'center', 'center', 'center'); + $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*', '*', '*', '*'); + + $existinteraction = false; + + $i = 0; + $interactionid = 'cmi.interactions.'.$i.'.id'; + + while (isset($trackdata->$interactionid)) { + $existinteraction = true; + $printedelements[]=$interactionid; + $elements = array($interactionid, + 'cmi.interactions.'.$i.'.type', + 'cmi.interactions.'.$i.'.result', + 'cmi.interactions.'.$i.'.student_response'); + $row = array(); + foreach ($elements as $element) { + if (isset($trackdata->$element)) { + $row[] = $trackdata->$element; + $printedelements[]=$element; + } else { + $row[] = ' '; + } + } + $table->data[] = $row; + + $i++; + $interactionid = 'cmi.interactions.'.$i.'.id'; + } + if ($existinteraction) { + echo '

    '.get_string('interactions','scorm').'

    '; + print_table($table); + } + + // Print Objectives data + $table = new stdClass(); + $table->head = array(get_string('identifier','scorm'), + get_string('status','scorm'), + get_string('raw','scorm'), + get_string('min','scorm'), + get_string('max','scorm')); + $table->align = array('center', 'center', 'center', 'center', 'center'); + $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array('*', '*', '*', '*', '*'); + + $existobjective = false; + + $i = 0; + $objectiveid = 'cmi.objectives.'.$i.'.id'; + + while (isset($trackdata->$objectiveid)) { + $existobjective = true; + $printedelements[]=$objectiveid; + $elements = array($objectiveid, + 'cmi.objectives.'.$i.'.status', + 'cmi.objectives.'.$i.'.score.raw', + 'cmi.objectives.'.$i.'.score.min', + 'cmi.objectives.'.$i.'.score.max'); + $row = array(); + foreach ($elements as $element) { + if (isset($trackdata->$element)) { + $row[] = $trackdata->$element; + $printedelements[]=$element; + } else { + $row[] = ' '; + } + } + $table->data[] = $row; + + $i++; + $objectiveid = 'cmi.objectives.'.$i.'.id'; + } + if ($existobjective) { + echo '

    '.get_string('objectives','scorm').'

    '; + print_table($table); + } + $table = new stdClass(); + $table->head = array(get_string('element','scorm'), get_string('value','scorm')); + $table->align = array('left', 'left'); + $table->wrap = array('nowrap', 'wrap'); + $table->width = '100%'; + $table->size = array('*', '*'); + + $existelements = false; + + foreach($trackdata as $element => $value) { + if (substr($element,0,3) == 'cmi') { + if (!(in_array ($element, $printedelements))) { + $existelements = true; + $row = array(); + $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element; + $row[] = $value; + $table->data[] = $row; + } + } + } + if ($existelements) { + echo '

    '.get_string('othertracks','scorm').'

    '; + print_table($table); + } + print_simple_box_end(); + } + } else { + error('Missing script parameter'); + } + } + + print_heading(format_string(get_string('timestatistic','scorm'))); + $scousers=get_records_select("scorm_scoes_track", "scormid='$scorm->id' GROUP BY userid,scormid", "", "userid,scormid"); + $attempt = scorm_get_last_attempt($scorm->id,$USER->id); + + foreach($scousers as $scouser){ + $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc'; + $endtrack = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified'); + + } + +//Phan trinh bay thong ke theo thoi gian + $table = new stdClass(); + $table->head = array(' ', get_string('name','scorm')); + $table->align = array('center', 'left'); + $table->wrap = array('nowrap', 'nowrap'); + $table->width = '100%'; + $table->size = array(10, '*'); + + $table->head[]=scorm_string_wrap(get_string('beginTime','scorm')); + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + + $table->head[]=scorm_string_wrap(get_string('endTime','scorm')); + $table->align[] = 'center'; + $table->wrap[] = 'nowrap'; + $table->size[] = '*'; + + $row = array(); + $row[] = ""; + $row[] = "(".get_string('coefficient','scorm').")"; + foreach($scousers as $scouser){ + $userdata = scorm_get_user_data($scouser->userid); + $row = array(); + $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true); + $row[] = "wwwroot/user/view.php?id=$scouser->userid&course=$course->id\">". + "$userdata->firstname $userdata->lastname"; + $str = 'scormid ='.($scorm->id).' and userid = '.$scouser->userid.' and attempt = '.$attempt.' ORDER BY timemodified asc'; + $begintrack = get_record_select("scorm_scoes_track", $str,'min(timemodified) as mintimemodified'); + $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $begintrack->mintimemodified); + $endtrack = get_record_select("scorm_scoes_track", $str,'max(timemodified) as maxtimemodified'); + $row[] = strftime( "%H h -%M ' - %S s - %d -%m-%Y", $endtrack->maxtimemodified); + $table->data[] = $row; + } + print_table($table); + + echo "
    ".format_string(get_string('viewscore','scorm')).""; + if (empty($noheader)) { + print_footer($course); + } +?> diff --git a/mod/scorm/restorelib.php b/mod/scorm/restorelib.php index 9a2e7e29a3a..748d6485697 100755 --- a/mod/scorm/restorelib.php +++ b/mod/scorm/restorelib.php @@ -56,10 +56,6 @@ if (!is_int($scorm->grademethod)) { $scorm->grademethod = 0; } - $scorm->maxattempt = backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']); - if (!is_int($scorm->maxattempt)) { - $scorm->maxattempt = 1; - } if ($restore->backup_version < 2005041500) { $scorm->datadir = substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1); } else { @@ -234,10 +230,6 @@ $scotrack->scormid = $scorm_id; $scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']); $scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']); - $scotrack->attempt = backup_todb($sub_info['#']['ATTEMPT']['0']['#']); - if (!is_int($scotrack->attempt)) { - $scotrack->attempt = 1; - } $scotrack->element = backup_todb($sub_info['#']['ELEMENT']['0']['#']); $scotrack->value = backup_todb($sub_info['#']['VALUE']['0']['#']); @@ -492,7 +484,7 @@ $status = update_record("scorm",$scorm); if ($CFG->debug>7) { if (!defined('RESTORE_SILENTLY')) { - echo '

    '.s($content).'
    changed to
    '.s($result).'

    '; + echo '

    '.htmlentities($content).'
    changed to
    '.htmlentities($result).'

    '; } } } diff --git a/mod/scorm/sequencinglib.php b/mod/scorm/sequencinglib.php new file mode 100755 index 00000000000..bd0c321d96c --- /dev/null +++ b/mod/scorm/sequencinglib.php @@ -0,0 +1,513 @@ +>>>> SCO goi Rollup la ".$scoidchild); + $scochild = get_record("scorm_scoes","id",$scoidchild); + $scoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scochild->parent); + //Danh sach cac con cua cha + $scochildren = get_records_select("scorm_scoes","scorm =".$scormid." and parent ='".$scoparent->identifier."'"); + //Lay gia tri last attempt + //fwrite($ft,"\n >>>>> Bat dau xu ly Rollup SCO cha ".$scoparent->id); + $attempt = scorm_get_last_attempt($scormid,$userid); + + if(!empty($scoparent)){ + $scoid = $scoparent->id; + $rolluprules = get_record("scorm_sequencing_rolluprules","scormid",$scormid,"scoid",$scoid); + if (!empty($rolluprules)){ + $idrolluprules = $rolluprules->id; + $rules = get_records_select('scorm_sequencing_rolluprule','scoid ='.$scoid.' and rolluprulesid ='. $idrolluprules); + + foreach ($rules as $rule){ + $ruleid = $rule->id; + $ruleConditions = get_record("scorm_sequencing_rollupruleconditions","scoid",$scoid,"rollupruleid",$ruleid); + $idruleConditions = $ruleConditions->id; + $conditions = get_records_select('scorm_sequencing_rolluprulecondition','scoid ='.$scoid.' and ruleconditionsid ='.$idruleConditions); + + //Truong hop 1: childactivitySet = all + // conditioncombination = any + if (($rule->childactivityset == 'all') && ($ruleConditions->conditioncombination=='any')){ + foreach($conditions as $condition){ + $conditionOK = false; + //Condition 1: condition = attempted operator = 'noOp' + // Thuc hien rollupaction + if (($condition->condition == 'attempted') && ($condition->operator=='noOp')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + //fwrite($ft,"\n >>>>> Xu ly Rollup voi dieu kien attempt \n"); + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->attempt_status != 'attempted'){ + //fwrite($ft,"\n >>>>> Co SCO con chua attempted \n"); + $conditionOK = false; + } + } + } + //Condition 2: condition = attempted operator = 'not' + // Thuc hien rollupaction + if (($condition->condition == 'attempted') && ($condition->operator=='not')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + //fwrite($ft,"\n >>>>> Xu ly Rollup voi dieu kien not attempt \n"); + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->attempt_status != 'notattempted'){ + $conditionOK = false; + } + } + } + //Condition 3: condition = satisfied operator = 'noOp' + // Thuc hien rollupaction + if (($condition->condition == 'satisfied') && ($condition->operator=='noOp')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->satisfied_status != 'satisfied'){ + $conditionOK = false; + } + } + } + //Condition 4: condition = satisfied operator = 'not' + // Thuc hien rollupaction + if (($condition->condition == 'satisfied') && ($condition->operator=='not')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->satisfied_status != 'notSatisfied'){ + $conditionOK = false; + } + } + } + //Condition 5: condition = completed operator = 'noOp' + // Thuc hien rollupaction + if (($condition->condition == 'completed') && ($condition->operator=='noOp')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->attempt_status != 'completed'){ + $conditionOK = false; + } + } + } + //Condition 6: condition = completed operator = 'not' + // Thuc hien rollupaction + if (($condition->condition == 'completed') && ($condition->operator=='not')){ + $conditionOK = true; + foreach ($scochildren as $sco){ + $usertrack = scorm_get_tracks($sco->id,$userid); + if ($usertrack->attempt_status != 'notcompleted'){ + $conditionOK = false; + } + } + } + //Neu dieu kien van dung sau khi xem xet thi thuc hien action + if ($conditionOK == true){ + if ($ruleConditions->rollupruleaction == 'completed') + { + scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.completion_status','completed'); + //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi completed cho SCO ".$scoid); + } + if ($ruleConditions->rollupruleaction == 'satisfied') + { + scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','passed'); + //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi satisfied\n"); + } + if ($ruleConditions->rollupruleaction == 'notSatisfied') + { + scorm_insert_track($userid,$scormid,$scoid,$attempt,'cmi.success_status','failed'); + //fwrite($ft,"\n >>>>> Xu ly Rollup thanh cong voi notSatisfied\n"); + } + //echo ""; + $sequencingResult->rule = 'exit'; + $sequencingResult->action = 'exit'; + } + if ($sequencingrule->preconditionruleaction=='disabled') + { + //fwrite($ft,"\n >>>>> Xu ly Sequencing thanh cong -- Thuc hien su kien disable \n"); + echo ""; + $sequencingResult->rule = 'pre'; + $sequencingResult->action = 'disable'; + + } + + } + } + } + } + return $sequencingResult; +} +function get_sco_after_exit($scoid,$scormid){ + $scochild = get_record("scorm_scoes","id",$scoid); + $scoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$scochild->parent); + $exitscoid = $scoid++; + $exitscochild = get_record("scorm_scoes","id",$exitscoid,"scorm",$scormid); + if (empty($exitscochild)){ + //Da ra ngoai vung scoid. Hay day chinh la sco cuoi cung + return 0; + } + else{ + $exitscoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$exitscochild->parent); + //Neu chua ra khoi activity do thi tiep tuc + while ($exitscoparent->id == $scoparent->id){ + $exitscoid++; + $exitscochild = get_record("scorm_scoes","id",$exitscoid); + if (empty($exitscochild)){ + //Da ra ngoai vung scoid. Hay day chinh la sco cuoi cung + return 0; + } + else{ + $exitscoparent = get_record("scorm_scoes","scorm",$scormid,"identifier",$exitscochild->parent); + } + } + } + return $exitscoid; +} + +?> diff --git a/mod/scorm/styles.php b/mod/scorm/styles.php index 409a5196bc0..6950c457ad6 100644 --- a/mod/scorm/styles.php +++ b/mod/scorm/styles.php @@ -1,83 +1,93 @@ -.structlist { - list-style-type: none; - white-space: nowrap; - font-size: small; -} -.orgtitle { - font-weight: bold; - font-size: small; -} -.mod-scorm .top { - vertical-align: top; -} -.mod-scorm .left { - text-align: left; -} -.mod-scorm .center { - text-align: center; -} -.mod-scorm .right { - text-align: right; -} -.mod-scorm .scoframe { - -} - -#mod-scorm-player #scormpage { - position: relative; - width: 100%; -} -#mod-scorm-player #tocbox { - position: absolute; - left: 0px; - top: 0px; - width: 19%; -} -#mod-scorm-player #tochead { - text-align: center; - font-weight: bold; -} -#mod-scorm-player #scormbox { - position: absolute; - right: 0px; - top: 0px; -} -#mod-scorm-player .toc { - width: 80%; - margin-left: 20%; -} -#mod-scorm-player .no-toc { - width: 100%; -} -#mod-scorm-player #scormobject { - /* border: 1px solid black; */ -} -#mod-scorm-player #scormtop { - position: relative; - width: 100%; - height: 30px; -} -#mod-scorm-player #scormbrowse { - position: absolute; - left: 5px; - top: 0px; -} -#mod-scorm-player #scormnav { - position: absolute; - right: 5px; - top: 0px; -} -#mod-scorm-player .structurelist { - list-style-type: none; - text-indent:-4ex; - font-size: small; -} - -#mod-scorm-view .structurehead { - font-weight: bold; - text-align: center; -} -#mod-scorm-view .structurelist { - list-style-type: none; - white-space: nowrap; -} +.structlist { + list-style-type: none; + white-space: nowrap; + font-size: small; +} +.orgtitle { + font-weight: bold; + font-size: small; +} +.mod-scorm .top { + vertical-align: top; +} +.mod-scorm .left { + text-align: left; +} +.mod-scorm .center { + text-align: center; +} +.mod-scorm .right { + text-align: right; +} +.mod-scorm .scoframe { + +} + +#mod-scorm-player #scormpage { + position: relative; + width: 100%; +} +#mod-scorm-player #tocbox { + position: absolute; + left: 0px; + top: 0px; + width: 19%; +} +#mod-scorm-player #tochead { + text-align: center; + font-weight: bold; +} +#mod-scorm-player #scormbox { + position: absolute; + right: 0px; + top: 0px; +} +#mod-scorm-player .toc { + width: 80%; + margin-left: 20%; +} +#mod-scorm-player .no-toc { + width: 100%; +} +#mod-scorm-player #scormobject { + /* border: 1px solid black; */ +} +#mod-scorm-player #scormtop { + position: relative; + width: 100%; + height: 30px; +} +#mod-scorm-player #scormbrowse { + position: absolute; + left: 5px; + top: 0px; +} +#mod-scorm-player #scormnav { + position: absolute; + right: 5px; + top: 0px; +} +#mod-scorm-player .structurelist { + list-style-type: none; + text-indent:-4ex; + font-size: small; +} + +#mod-scorm-view .structurehead { + font-weight: bold; + text-align: center; +} +#mod-scorm-view .structurelist { + list-style-type: none; + white-space: nowrap; +} +.scormtextbox { +border-style: solid; +border-width: 1; +padding-left: 5; +} +.scormtableheader{ +font-face: Arial; +color: #000066; +font-weight: bold; +} diff --git a/mod/scorm/suspend.php b/mod/scorm/suspend.php new file mode 100755 index 00000000000..e32dbebb82d --- /dev/null +++ b/mod/scorm/suspend.php @@ -0,0 +1,36 @@ +accesstime = $statistic->accesstime; + $statisticInput->durationtime = $statistic->durationtime + time()- $statistic->accesstime; + $statisticInput->status = 'suspend'; + $statisticInput->attemptnumber = $attempt; + $statisticInput->scormid = $statistic->scormid; + $statisticInput->userid = $statistic->userid; + $statisticid = scorm_insert_statistic($statisticInput); + + $result = scorm_insert_trackmodel($userid, $scormid, $scoid,$attempt); + if ($result) { + echo ""; + } + else { + echo "Suspend failed"; + } + +?> + diff --git a/mod/scorm/timePassReport.htm b/mod/scorm/timePassReport.htm new file mode 100755 index 00000000000..8c0e3a04fe8 --- /dev/null +++ b/mod/scorm/timePassReport.htm @@ -0,0 +1,10 @@ + + + + + + + +Thời gian làm bài đã hết... Mời bạn chọn bài khác. + + diff --git a/mod/scorm/validate.php b/mod/scorm/validate.php index d1a6988d75c..ab06ff7d04a 100755 --- a/mod/scorm/validate.php +++ b/mod/scorm/validate.php @@ -1,121 +1,122 @@ -result = "packagefile"; - } - if (!empty($scormid)) { - // - // SCORM Update - // - if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) { - $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r"); - $fstat = fstat($fp); - fclose($fp); - if ($scorm = get_record("scorm","id",$scormid)) { - $launch = $scorm->launch; - if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) { - // This is a new package - $launch = 0; - } else { - // Old package already validated - $validation->result = 'found'; - if (strpos($scorm->version,'AICC') !== false) { - $validation->pkgtype = 'AICC'; - } else { - $validation->pkgtype = 'SCORM'; - } - } - } else { - $validation->result = 'badinstance'; - $launch = -1; - } - } else { - $validation->result = 'badreference'; - $launch = -1; - } - } - //$launch = 0; - if ($launch == 0) { - // - // Package must be validated - // - - $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.'))); - switch ($ext) { - case '.pif': - case '.zip': - // Create a temporary directory to unzip package and validate package - $tempdir = ''; - $scormdir = ''; - if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { - if ($tempdir = scorm_datadir($scormdir)) { - copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference)); - unzip_file($tempdir."/".basename($reference), $tempdir, false); - unlink ($tempdir."/".basename($reference)); - $validation = scorm_validate($tempdir); - } else { - $validation->result = "packagedir"; - } - } else { - $validation->result = "datadir"; - } - break; - case '.xml': - if (basename($reference) == 'imsmanifest.xml') { - $validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference)); - } else { - $validation->result = "manifestfile"; - } - break; - default: - $validation->result = "packagefile"; - break; - } - if (($validation->result != "regular") && ($validation->result != "found")) { - $validation->result = get_string($validation->result,'scorm'); - if (is_dir($tempdir)) { - // Delete files and temporary directory - scorm_delete_files($tempdir); - } - } else { - if ($ext == '.xml') { - $datadir = dirname($reference); - } else { - $datadir = substr($tempdir,strlen($scormdir)); - } - } - } - // - // Print validation result - // - echo 'result=' . $validation->result . "\n"; - echo 'launch=' . $launch . "\n"; - if (isset($validation->pkgtype)) { - echo 'pkgtype=' . $validation->pkgtype . "\n"; - } - if (isset($datadir)) { - echo 'datadir=' . $datadir . "\n"; - } - if (isset($validation->errors[1])) { - echo 'errorlogs='."\n"; - foreach($validation->errors as $error) { - echo get_string($error->type,"scorm",$error->data) . "\n"; - } - } -} else { - echo 'result=' . get_string('badrequest','scorm') . "\n"; -} -?> +result = "packagefile"; + } + if (!empty($scormid)) { + // + // SCORM Update + // + if (is_file($CFG->dataroot.'/'.$courseid.'/'.$reference)) { + $fp = fopen($CFG->dataroot.'/'.$courseid.'/'.$reference,"r"); + $fstat = fstat($fp); + fclose($fp); + if ($scorm = get_record("scorm","id",$scormid)) { + $launch = $scorm->launch; + if ((($scorm->timemodified < $fstat["mtime"]) && ($scorm->reference == $reference)) || ($scorm->reference != $reference)) { + // This is a new package + $launch = 0; + } else { + // Old package already validated + $validation->result = 'found'; + if (strpos($scorm->version,'AICC') !== false) { + $validation->pkgtype = 'AICC'; + } else { + $validation->pkgtype = 'SCORM'; + } + } + } else { + $validation->result = 'badinstance'; + $launch = -1; + } + } else { + $validation->result = 'badreference'; + $launch = -1; + } + } + //$launch = 0; + if ($launch == 0) { + // + // Package must be validated + // + + $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.'))); + switch ($ext) { + case '.pif': + case '.zip': + // Create a temporary directory to unzip package and validate package + $tempdir = ''; + $scormdir = ''; + if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { + if ($tempdir = scorm_datadir($scormdir)) { + copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference)); + unzip_file($tempdir."/".basename($reference), $tempdir, false); + unlink ($tempdir."/".basename($reference)); + $validation = scorm_validate($tempdir); + } else { + $validation->result = "packagedir"; + } + } else { + $validation->result = "datadir"; + } + break; + case '.xml': + if (basename($reference) == 'imsmanifest.xml') { + $validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference)); + } else { + $validation->result = "manifestfile"; + } + break; + default: + $validation->result = "packagefile"; + break; + } + if (($validation->result != "regular") && ($validation->result != "found")) { + $validation->result = get_string($validation->result,'scorm'); + if (is_dir($tempdir)) { + // Delete files and temporary directory + scorm_delete_files($tempdir); + } + } else { + if ($ext == '.xml') { + $datadir = dirname($reference); + } else { + $datadir = substr($tempdir,strlen($scormdir)); + } + } + } + // + // Print validation result + // + echo 'result=' . $validation->result . "\n"; + echo 'launch=' . $launch . "\n"; + if (isset($validation->pkgtype)) { + echo 'pkgtype=' . $validation->pkgtype . "\n"; + } + if (isset($datadir)) { + echo 'datadir=' . $datadir . "\n"; + } + if (isset($validation->errors[1])) { + echo 'errorlogs='."\n"; + foreach($validation->errors as $error) { + echo get_string($error->type,"scorm",$error->data) . "\n"; + } + } +} else { + echo 'result=' . get_string('badrequest','scorm') . "\n"; +} +?> diff --git a/mod/scorm/version.php b/mod/scorm/version.php index 863842fd2f6..bd600fcb8b6 100755 --- a/mod/scorm/version.php +++ b/mod/scorm/version.php @@ -1,12 +1,12 @@ -version = 2006021401; // The (date) version of this module -$module->requires = 2005060200; // The version of Moodle that is required -$module->cron = 0; // How often should cron check this module (seconds)? - -?> +version = 2006050502; // The (date) version of this module +$module->requires = 2005060200; // The version of Moodle that is required +$module->cron = 0; // How often should cron check this module (seconds)? + +?> diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 64dd861fa78..ea17ce03e7e 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -1,91 +1,101 @@ -course)) { - error("Course is misconfigured"); - } - if (! $scorm = get_record("scorm", "id", $cm->instance)) { - error("Course module is incorrect"); - } - } else if (!empty($a)) { - if (! $scorm = get_record("scorm", "id", $a)) { - error("Course module is incorrect"); - } - if (! $course = get_record("course", "id", $scorm->course)) { - error("Course is misconfigured"); - } - if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); - } - } else { - error('A required parameter is missing'); - } - - require_login($course->id, false, $cm); - - if (isset($SESSION->scorm_scoid)) { - unset($SESSION->scorm_scoid); - } - - $strscorms = get_string("modulenameplural", "scorm"); - $strscorm = get_string("modulename", "scorm"); - - if ($course->category != 0) { - $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname ->"; - if ($scorms = get_all_instances_in_course('scorm', $course)) { - // The module SCORM activity with the least id is the course - $firstscorm = current($scorms); - if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) { - $navigation .= "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; - } - } - } else { - $navigation = "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; - } - - $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name)); - - add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id"); - - // - // Print the page header - // - if (!$cm->visible and !isteacher($course->id)) { - print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name), '', '', true, - update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); - notice(get_string('activityiscurrentlyhidden')); - } else { - print_header($pagetitle, "$course->fullname", - "$navigation framename}\" href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."", - '', '', true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); - - if (isteacher($course->id)) { - $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); - if ($trackedusers->c > 0) { - echo "'; - } else { - echo ''; - } - } - // Print the main part of the page - - print_heading(format_string($scorm->name)); - - print_simple_box(format_text($scorm->summary), 'center', '70%', '', 5, 'generalbox', 'intro'); - scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm); - print_footer($course); - } -?> +course)) { + error("Course is misconfigured"); + } + if (! $scorm = get_record("scorm", "id", $cm->instance)) { + error("Course module is incorrect"); + } + } else if (!empty($a)) { + if (! $scorm = get_record("scorm", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $scorm->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) { + error("Course Module ID was incorrect"); + } + } else { + error('A required parameter is missing'); + } + + require_login($course->id, false, $cm); + + if (isset($SESSION->scorm_scoid)) { + unset($SESSION->scorm_scoid); + } + + $strscorms = get_string("modulenameplural", "scorm"); + $strscorm = get_string("modulename", "scorm"); + + if ($course->category != 0) { + $navigation = "framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname ->"; + if ($scorms = get_all_instances_in_course('scorm', $course)) { + // The module SCORM activity with the least id is the course + $firstscorm = current($scorms); + if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) { + $navigation .= "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; + } + } + } else { + $navigation = "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; + } + + $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name)); + + add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id"); + + // + // Print the page header + // + if (!$cm->visible and !isteacher($course->id)) { + print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name), '', '', true, + update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); + notice(get_string('activityiscurrentlyhidden')); + } else { + print_header($pagetitle, "$course->fullname", + "$navigation framename}\" href=\"view.php?id=$cm->id\">".format_string($scorm->name,true)."", + '', '', true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm)); + + if (isteacher($course->id)) { + + //Phan thiet lap he so diem + $examNumber = get_record_select('scorm_scoes', 'scorm ='.($scorm->id).' and minnormalizedmeasure > -1','count(id) as examCount'); + //fwrite($ft,"\n So bai kiem tra la ".($examNumber->examCount)); + if ($examNumber->examCount > 0){ + echo "'; + } + + //----------------------- + $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); + if ($trackedusers->c > 0) { + echo "'; + } else { + echo ''; + } + } + + $USER->setAttempt = 'notset'; + // Print the main part of the page + print_heading(format_string($scorm->name)); + print_simple_box(format_text($scorm->summary), 'center', '70%', '', 5, 'generalbox', 'intro'); + scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm); + print_footer($course); + } +?>