From 2b3447c38ad25640edf06793c67b69b3ebd1b73b Mon Sep 17 00:00:00 2001 From: bobopinna Date: Thu, 31 Aug 2006 08:34:13 +0000 Subject: [PATCH] Added capability support --- mod/scorm/aicc.php | 2 +- mod/scorm/api.php | 21 +- mod/scorm/datamodel.php | 4 +- mod/scorm/db/access.php | 31 +- mod/scorm/index.php | 12 +- mod/scorm/lib.php | 71 +- mod/scorm/loadSCO.php | 6 +- mod/scorm/locallib.php | 1783 +++-------------------------------- mod/scorm/mod.html | 5 +- mod/scorm/player.php | 169 +--- mod/scorm/report.php | 2 +- mod/scorm/sequencinglib.php | 1 + mod/scorm/view.php | 57 +- 13 files changed, 231 insertions(+), 1933 deletions(-) diff --git a/mod/scorm/aicc.php b/mod/scorm/aicc.php index fd5c58b778..de03f5e489 100755 --- a/mod/scorm/aicc.php +++ b/mod/scorm/aicc.php @@ -135,7 +135,7 @@ break; case 'putparam': if ($status == 'Running') { - if (!empty($aiccdata) && isstudent($scorm->course)) { + if (!empty($aiccdata) && has_capability('mod/scorm:savetrack', $context)) { $initlessonstatus = 'not attempted'; $lessonstatus = 'not attempted'; if (isset($SESSION->scorm_lessonstatus)) { diff --git a/mod/scorm/api.php b/mod/scorm/api.php index 3b15f4b459..6d37834cea 100644 --- a/mod/scorm/api.php +++ b/mod/scorm/api.php @@ -5,7 +5,7 @@ $id = optional_param('id', '', PARAM_INT); // Course Module ID, or $a = optional_param('a', '', PARAM_INT); // scorm ID - $scoid = required_param('scoid', PARAM_INT); // sco ID + $scoid = required_param('scoid', PARAM_INT); // sco ID $mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode $attempt = required_param('attempt', PARAM_INT); // new attempt @@ -60,20 +60,11 @@ } 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; + $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe + if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) { + include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php'); + } else { + include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php'); } ?> diff --git a/mod/scorm/datamodel.php b/mod/scorm/datamodel.php index 676fbcfdda..c3086701b0 100755 --- a/mod/scorm/datamodel.php +++ b/mod/scorm/datamodel.php @@ -6,7 +6,7 @@ $a = optional_param('a', '', PARAM_INT); // scorm ID $scoid = required_param('scoid', PARAM_INT); // sco ID // $attempt = required_param('attempt', PARAM_INT); // attempt number - $attempt = $USER->attempt; + $attempt = $SESSION->scorm_attempt; if (!empty($id)) { @@ -37,7 +37,7 @@ if (confirm_sesskey() && (!empty($scoid))) { $result = true; - if (isstudent($course->id) || (isteacher($course->id) && !isadmin())) { + if (has_capability('mod/scorm:savetrack', $context)) { foreach ($_POST as $element => $value) { if (substr($element,0,3) == 'cmi') { $element = str_replace('__','.',$element); diff --git a/mod/scorm/db/access.php b/mod/scorm/db/access.php index 3c82185d7e..5bba04ecce 100644 --- a/mod/scorm/db/access.php +++ b/mod/scorm/db/access.php @@ -38,7 +38,7 @@ $mod_scorm_capabilities = array( 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'legacy' => array( - 'guest' => CAP_PREVENT, + 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, @@ -47,20 +47,35 @@ $mod_scorm_capabilities = array( ) ), - 'mod/scorm:viewgrades' => array( + 'mod/scorm:savetrack' => array( - 'captype' => 'read', + 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, 'legacy' => array( 'guest' => CAP_PREVENT, - 'student' => CAP_PREVENT, + 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, - 'editingteacher' => CAP_ALLOW, - 'coursecreator' => CAP_ALLOW, - 'admin' => CAP_ALLOW + 'editingteacher' => CAP_PREVENT, + 'coursecreator' => CAP_PREVENT, + 'admin' => CAP_PREVENT + ) + ), + + 'mod/scorm:viewscores' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_ALLOW, + 'teacher' => CAP_PREVENT, + 'editingteacher' => CAP_PREVENT, + 'coursecreator' => CAP_PREVENT, + 'admin' => CAP_PREVENT ) ) + ); -?> \ No newline at end of file +?> diff --git a/mod/scorm/index.php b/mod/scorm/index.php index adb7fad9f2..becdcd2bc6 100755 --- a/mod/scorm/index.php +++ b/mod/scorm/index.php @@ -61,18 +61,18 @@ $tt = userdate($scorm->timemodified); } $report = ' '; - if (isteacher($course->id)) { + if (has_capability('moodle/user:viewuseractivitiesreport', $context)) { $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)."%"; } + } else if (has_capability('mod/scorm:viewscores', $context)) { + require_once('locallib.php'); + $report = scorm_grade_user(get_records('scorm_scoes','scorm',$scorm->id), $USER->id, $scorm->grademethod); + $reportshow = get_string('score','scorm').": ".$report; + } if (!$scorm->visible) { //Show dimmed if the mod is hidden $table->data[] = array ($tt, "coursemodule\">".format_string($scorm->name,true)."", diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 52490d3f09..064c0a5551 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -1,58 +1,5 @@ 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%'); -} - -// -// Repository configurations -// -$repositoryconfigfile = $CFG->dirroot.'/mod/resource/type/ims/repository_config.php'; -$repositorybrowser = '/mod/resource/type/ims/finder.php'; - /** * Given an object containing all the necessary data, * (defined by the form in mod.html) this function @@ -127,10 +74,7 @@ function scorm_update_instance($scorm) { (basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) { rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id); } - /* // 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_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); @@ -161,9 +105,12 @@ function scorm_delete_instance($id) { $result = true; - // Delete any dependent files - require_once('locallib.php'); - scorm_delete_files($CFG->dataroot.'/'.$scorm->course.'/moddata/scorm/'.$scorm->id); + $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; + if (is_dir($scorm->dir.'/'.$scorm->id)) { + // Delete any dependent files + require_once('locallib.php'); + scorm_delete_files($scorm->dir.'/'.$scorm->id); + } // Delete any dependent records if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) { @@ -175,7 +122,7 @@ function scorm_delete_instance($id) { if (! delete_records('scorm', 'id', $scorm->id)) { $result = false; } - if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) { + /*if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) { $result = false; } if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) { @@ -195,7 +142,7 @@ function scorm_delete_instance($id) { } if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) { $result = false; - } + }*/ return $result; } diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index b538a5fd0b..c1361fc3de 100755 --- a/mod/scorm/loadSCO.php +++ b/mod/scorm/loadSCO.php @@ -72,7 +72,7 @@ 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; + $launcher = $sco->launch.$connector.'aicc_sid='.sesskey().'&aicc_url='.$CFG->wwwroot.'/mod/scorm/type/aicc/aicc.php'.$sco->parameters; } else { $launcher = $sco->launch.$connector.$sco->parameters; } @@ -100,11 +100,11 @@ LoadSCO diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index 8507ded5e0..d34f398e7a 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -1,18 +1,6 @@ dirroot.'/mod/resource/type/ims/repository_config.php'; -$repositorybrowser = '/mod/resource/type/ims/finder.php'; - - -/// Local Library of functions and constants for module scorm +/// Local Library of functions for module scorm /** * This function will permanently delete the given @@ -96,42 +84,46 @@ function scorm_datadir($strPath) } } -/** -* 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; +function scorm_array_search($item, $needle, $haystacks, $strict=false) { + if (!empty($haystacks)) { + foreach ($haystacks as $key => $element) { + if ($strict) { + if ($element->{$item} === $needle) { + return $key; + } + } else { + if ($element->{$item} == $needle) { + return $key; } } - closedir($handle); - } - if (!isset($validation->result)) { - $validation->result = 'nomanifest'; - $validation->pkgtype = 'SCORM'; } } - return $validation; + return false; } -function scorm_get_user_data($userid) { -/// Gets user info required to display the table of scorm results -/// for report.php +function scorm_repeater($what, $times) { + if ($times <= 0) { + return null; + } + $return = ''; + for ($i=0; $i<$times;$i++) { + $return .= $what; + } + return $return; +} - return get_record('user','id',$userid,'','','','','firstname, lastname, picture'); +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_string_wrap($stringa, $len=15) { @@ -158,158 +150,35 @@ function scorm_string_wrap($stringa, $len=15) { } } -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); +/** +* 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; } - 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; + closedir($handle); + } + if (!isset($validation->result)) { + $validation->result = 'nomanifest'; + $validation->pkgtype = 'SCORM'; } - - array_push($stack,$element); } - return eval('return '.implode($stack).';'); + return $validation; } function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) { @@ -331,357 +200,6 @@ function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) { 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; - - // Added by Pham Minh Duc - $suspendscoid = scorm_get_suspendscoid($scorm->id,$user->id); - // End add - - $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; - if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){ - // - // Retrieve user tracking data for each learning object - // - $usertracks = array(); - foreach ($scoes as $sco) { - if (!empty($sco->launch)) { - if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) { - if ($usertrack->status == '') { - $usertrack->status = 'notattempted'; - } - $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; - } - // Modified by Pham Minh Duc - 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')) { - $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').''; - } - } - } - // End Modify - 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; - } - // Modified by Pham Minh Duc - 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); - } - // End modify - } 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; @@ -760,787 +278,97 @@ function scorm_get_tracks($scoid,$userid,$attempt='') { } } -/// Library of functions and constants for parsing packages +function scorm_get_user_data($userid) { +/// Gets user info required to display the table of scorm results +/// for report.php -function scorm_parse($scorm) { - global $CFG,$repositoryconfigfile; + return get_record('user','id',$userid,'','','','','firstname, lastname, picture'); +} - // Parse scorm manifest - if ($scorm->pkgtype == 'AICC') { - $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id); - } else { - $reference = $scorm->reference; - if ($scorm->reference[0] == '#') { - require_once($repositoryconfigfile); - $reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml'; - } else if (substr($reference,0,7) != 'http://') { - $reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference; - } - - if (basename($reference) != 'imsmanifest.xml') { - $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id); - } else { - $scorm->launch = scorm_parse_scorm(dirname($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; -} +function scorm_grade_user($scoes, $userid, $grademethod=VALUESCOES) { + $scores = NULL; + $scores->scoes = 0; + $scores->values = 0; + $scores->max = 0; + $scores->sum = 0; -/** -* 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 (!$scoes) { + return ''; } - $regexp = substr($regexp,0,-1) . '/'; - return $regexp; -} -function scorm_parse_aicc($pkgdir,$scormid) { - $version = 'AICC'; - $ids = array(); - $courses = array(); - $extaiccfiles = array('crs','des','au','cst','ort','pre','cmp'); - if ($handle = opendir($pkgdir)) { - while (($file = readdir($handle)) !== false) { - if ($file[0] != '.') { - $ext = substr($file,strrpos($file,'.')); - $extension = strtolower(substr($ext,1)); - if (in_array($extension,$extaiccfiles)) { - $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); - } + $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; + } + } } - //print_r($courses); - - $oldscoes = get_records('scorm_scoes','scorm',$scormid); - - $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); - if (get_record('scorm_scoes','scorm',$scormid,'identifier',$sco->identifier)) { - $id = update_record('scorm_scoes',$sco); - unset($oldscoes[$id]); + switch ($grademethod) { + case VALUEHIGHEST: + return $scores->max; + break; + case VALUEAVERAGE: + if ($scores->values > 0) { + return $scores->sum/$scores->values; } else { - $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; - if ($oldscoid = scorm_array_search('identifier',$sco->identifier,$oldscoes)) { - $sco->id = $oldscoid; - $id = update_record('scorm_scoes',$sco); - unset($oldscoes[$oldscoid]); - } else { - $id = insert_record('scorm_scoes',$sco); - } - if ($launch==0) { - $launch = $id; - } - } - } - } - } - if (!empty($oldscoes)) { - foreach($oldscoes as $oldsco) { - delete_records('scorm_scoes','id',$oldsco->id); - delete_records('scorm_scoes_track','scoid',$oldsco->id); - } + return 0; + } + break; + case VALUESUM: + return $scores->sum; + break; + case VALUESCOES: + return $scores->scoes; + break; } - set_field('scorm','version','AICC','id',$scormid); - return $launch; } -function scorm_get_resources($blocks) { - $resources = array(); - 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_count_launchable($scormid,$organization) { + return count_records_select('scorm_scoes',"scorm=$scormid AND organization='$organization' AND launch<>''"); } -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; - // Added by Pham Minh Duc - case 'ADLNAV:PRESENTATION': - $parent = array_pop($parents); - array_push($parents, $parent); - foreach ($block['children'] as $adlnav) { - if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') { - foreach ($adlnav['children'] as $adlnavInterface) { - if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI') { - if ($adlnavInterface['tagData'] == 'continue') { - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->next = 1; - } - if ($adlnavInterface['tagData'] == 'previous') { - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->previous = 1; - } - } - - } - } - } - break; - case 'IMSSS:SEQUENCING': - $parent = array_pop($parents); - array_push($parents, $parent); - foreach ($block['children'] as $sequencing) { - if ($sequencing['name']=='IMSSS:CONTROLMODE') { - if ($sequencing['attrs']['CHOICE'] == 'false') { - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choice = 0; - } - 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') { - 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') { - foreach ($sequencing['children'] as $objective) { - if ($objective['name']=='IMSSS:PRIMARYOBJECTIVE') { - 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') { - 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(); - 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']; - 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); - } - } - $rolluprule->conditions = $conditions; - } - if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION') { - $rolluprule->rollupruleaction = $rolluproleconditions['attrs']['ACTION']; - } - } - } - } - array_push($rolluprules, $rolluprule); - } - } - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules = $rolluprules; - } - - if ($sequencing['name']=='IMSSS:SEQUENCINGRULES') { - $sequencingrules = array(); - foreach ($sequencing['children'] as $conditionrules) { - if ($conditionrules['name']=='IMSSS:EXITCONDITIONRULE') { - $sequencingrule = new stdClass(); - 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); - } - } - $sequencingrule->ruleconditions = $ruleconditions; - } - if ($conditionrule['name']=='IMSSS:RULEACTION') { - $sequencingrule->exitconditionruleaction = $conditionrule['attrs']['ACTION']; - } - } - } - array_push($sequencingrules,$sequencingrule); - } - if ($conditionrules['name']=='IMSSS:PRECONDITIONRULE') { - $sequencingrule = new stdClass(); - 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); - } - } - $sequencingrule->ruleconditions = $ruleconditions; - } - if ($conditionrule['name']=='IMSSS:RULEACTION') { - $sequencingrule->preconditionruleaction = $conditionrule['attrs']['ACTION']; - } - } - } - array_push($sequencingrules,$sequencingrule); - } - if ($conditionrules['name']=='IMSSS:POSTCONDITIONRULE') { - $sequencingrule = new stdClass(); - 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); - } - } - $sequencingrule->ruleconditions = $ruleconditions; - } - if ($conditionrule['name']=='IMSSS:RULEACTION'){ - $sequencingrule->postconditionruleaction = $conditionrule['attrs']['ACTION']; - } - } - } - array_push($sequencingrules,$sequencingrule); - } - $scoes->elements[$manifest][$parent->organization][$parent->identifier]->sequencingrules = $sequencingrules; - } - } - } - break; - // End Add - } +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; } } - 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); - // print_r($manifests); - $scoes = new stdClass(); - $scoes->version = ''; - $scoes = scorm_get_manifest($manifests,$scoes); - - if (count($scoes->elements) > 0) { - $olditems = get_records('scorm_scoes','scorm',$scormid); - 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; - if ($olditemid = scorm_array_search('identifier',$item->identifier,$olditems)) { - $item->id = $olditemid; - $id = update_record('scorm_scoes',$item); - unset($olditems[$olditemid]); - } else { - $id = insert_record('scorm_scoes',$item); - } - // Added by Pham Minh Duc - $item->scormid = $scormid; - $item->scoid = $id; - $idControlMode = insert_record('scorm_sequencing_controlmode',$item); - - if (!empty($item->sequencingrules)) { - foreach($item->sequencingrules as $sequencingrule) { - $sequencingrule->scormid = $scormid; - $sequencingrule->scoid = $item->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); - } - } - } - - if (!empty($item->rolluprules)) { - $idControlMode = insert_record('scorm_sequencing_rolluprules',$item); - foreach($item->rolluprules as $rollup) { - $rollup->rolluprulesid =$idControlMode; - $rollup->scormid = $scormid; - $rollup->scoid = $item->scoid; +function scorm_parse($scorm) { + global $CFG,$repositoryconfigfile; - $idRollupRule = insert_record('scorm_sequencing_rolluprule',$rollup); - $rollup->rollupruleid = $idRollupRule; - $idconditions = insert_record('scorm_sequencing_rollupruleconditions',$rollup); - foreach($rollup->conditions as $condition){ - $condition->ruleconditionsid = $idconditions; - $condition->scormid = $rollup->scormid; - $condition->scoid = $rollup->scoid; - $idcondition = insert_record('scorm_sequencing_rolluprulecondition',$condition); - } - } - } - // End Add - if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) { - $launch = $id; - } - } - } - } - if (!empty($olditems)) { - foreach($olditems as $olditem) { - delete_records('scorm_scoes','id',$olditem->id); - delete_records('scorm_scoes_track','scoid',$olditem->id); - } - } - set_field('scorm','version',$scoes->version,'id',$scormid); + // Parse scorm manifest + if ($scorm->pkgtype == 'AICC') { + require_once('datamodels/aicclib.php'); + $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id); + } else { + require_once('datamodels/scormlib.php'); + $reference = $scorm->reference; + if ($scorm->reference[0] == '#') { + require_once($repositoryconfigfile); + $reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml'; + } else if (substr($reference,0,7) != 'http://') { + $reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference; } - } - - return $launch; -} -function scorm_array_search($item, $needle, $haystacks, $strict=false) { - if (!empty($haystacks)) { - foreach ($haystacks as $key => $element) { - if ($strict) { - if ($element->{$item} === $needle) { - return $key; - } - } else { - if ($element->{$item} == $needle) { - return $key; - } - } + if (basename($reference) != 'imsmanifest.xml') { + $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id); + } else { + $scorm->launch = scorm_parse_scorm(dirname($reference),$scorm->id); } } - return false; + return $scorm->launch; } function scorm_course_format_display($user,$course) { @@ -1558,7 +386,7 @@ function scorm_course_format_display($user,$course) { } $colspan = ''; $headertext = '
    '.get_string('name').': '.format_string($scorm->name).''; - if (isteacher($course->id, $user->id, true)) { + if (has_capability('moodle/course:manageactivities', $context)) { if (isediting($course->id)) { // Display update icon $path = $CFG->wwwroot.'/course'; @@ -1582,9 +410,9 @@ function scorm_course_format_display($user,$course) { print_simple_box($headertext,'','100%'); scorm_view_display($user, $scorm, 'view.php?id='.$course->id, $cm, '100%'); } else { - if (isteacheredit($course->id, $user->id)) { + if (has_capability('moodle/course:', $context)) { // Create a new activity - redirect('mod.php?id='.$course->id.'&section=0&sesskey='.sesskey().'&add=scorm'); + redirect($CFG->wwwroot.'/course/mod.php?id='.$course->id.'&section=0&sesskey='.sesskey().'&add=scorm'); } else { notify('Could not find a scorm course here'); } @@ -1592,12 +420,12 @@ function scorm_course_format_display($user,$course) { echo ''; } -function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') { +function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') { global $CFG; $organization = optional_param('organization', '', PARAM_INT); - print_simple_box_start('center',$blockwidth); + print_simple_box_start('center',$boxwidth); ?>
    organization; } } + $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe + require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); + $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier); $incomplete = $result->incomplete; echo $result->toc; @@ -1632,22 +463,12 @@ function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') {
    popup == 1?' target="newwin"':'' ?>> id,"userid",$user->id); - // End Add if ($scorm->hidebrowse == 0) { print_string("mode","scorm"); echo ': '."\n"; if ($incomplete === true) { echo '\n"; - // Added by Pham Minh Duc - if (!empty($suspend)) { - echo '\n"; - } - // End Add - } else { - echo '\n"; } } else { if ($incomplete === true) { @@ -1673,334 +494,4 @@ function scorm_view_display ($user, $scorm, $action, $cm, $blockwidth='') { 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) { - global $CFG; - - $entities = ''; - $values = array(); - $lookingfor = 1; - - if (empty($CFG->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; - } - } - - /** - * 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); - } - -} - -// -// Functions added by Pham Minh Duc -// -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; - } -} - -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) { - $scores = NULL; - $scores->scoes = 0; - $scores->values = 0; - $scores->scaled = 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->success_status == 'passed')) { - $scores->scoes++; - } - $scaled = $userdata->score_scaled; - $scoreraw = $userdata->score_raw; - if ($scaled ==0){ - $scores->scaled = $scores->scaled / $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; - } - if (!empty($scaled)) { - $scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes); - } - } - } - 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; - } -} - -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 { - $id = insert_record('scorm_statistic',$statisticInput); - } - return $id; -} - -function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) { - $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) { - if ($sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid)) { - $suspendscoid = $sco->suspendscoid; - return $suspendscoid; - } else { - return 0; - } -} - -function scorm_set_attempt($scoid,$userid) { - if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) { - $attempt = scorm_get_last_attempt($scormid,$userid); - } else { - $attempt = 1; - } - $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_AbsoluteTimeLimit($scoid){ - $sco = get_record("scorm_scoes","id",$scoid); - if (!empty($sco)){ - return $sco->attemptAbsoluteDurationLimit; - } - return 0; -} - -function scorm_update_status($scormid,$scoid) -{ - -} - -function scorm_get_nextsco($scormid,$scoid) -{ - -} - -function scorm_get_presco($scormid,$scoid) -{ - -} - -function scorm_isChoice($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->choice; -} - -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; -} -// End add ?> diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index 0e0f55121a..66a8de0f67 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -1,5 +1,5 @@ dirroot.'/mod/scorm/lib.php'); + require_once($CFG->dirroot.'/mod/scorm/configurations.php'); if (!isset($form->name)) { $form->name = ''; } @@ -64,6 +64,9 @@ $element = trim($element); $window->$element = trim($value)==1?'checked':''; } + if (!isset($form->pkgtype)) { + $form->pkgtype = ''; + } $scormid = ''; if (!empty($form->instance)) { $scormid = '&instance='.$form->instance; diff --git a/mod/scorm/player.php b/mod/scorm/player.php index 85fc733f2f..ec9cce6345 100755 --- a/mod/scorm/player.php +++ b/mod/scorm/player.php @@ -4,8 +4,7 @@ require_once('../../config.php'); require_once('locallib.php'); - require_once('sequencinglib.php'); - + // // Checkin' script parameters // @@ -42,101 +41,14 @@ 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 + // The module SCORM/AICC activity with the first id is the course $firstscorm = current($scorms); if (!(($course->format == 'scorm') && ($firstscorm->id == $scorm->id))) { $navigation .= "framename}\" href=\"index.php?id=$course->id\">$strscorms ->"; @@ -148,7 +60,7 @@ $pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name)); - if (!$cm->visible and !isteacher($course->id)) { + if (!$cm->visible and !has_capability('moodle/user:viewhiddenactivities',$context)) { print_header($pagetitle, "$course->fullname", "$navigation ".format_string($scorm->name,true)."", '', '', true, update_module_button($cm->id, $course->id, $strscorm), '', false); @@ -158,24 +70,14 @@ // // 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'; - //} + $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe + require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); + $attempt = scorm_get_last_attempt($scorm->id, $USER->id); 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; @@ -183,14 +85,11 @@ $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); } } } @@ -210,12 +109,7 @@ $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 + $SESSION->scorm_attempt = $attempt; // // Print the page header @@ -224,20 +118,10 @@ 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').') '; - + $exitlink = '('.get_string('exit','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); + '', '', true, $exitlink.update_module_button($cm->id, $course->id, $strscorm), '', false, $bodyscript); if ($sco->scormtype == 'sco') { ?> @@ -337,28 +221,14 @@ 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 c2df9bb7c5..12724d56aa 100755 --- a/mod/scorm/report.php +++ b/mod/scorm/report.php @@ -42,7 +42,7 @@ require_login($course->id, false, $cm); - if (!isteacher($course->id)) { + if (!has_capability('moodle/user:viewuseractivitiesreport',$context)) { error("You are not allowed to use this script"); } diff --git a/mod/scorm/sequencinglib.php b/mod/scorm/sequencinglib.php index bd0c321d96..ed08701583 100755 --- a/mod/scorm/sequencinglib.php +++ b/mod/scorm/sequencinglib.php @@ -483,6 +483,7 @@ function scorm_sequecingrule_implement($scormid,$scoidchild, $userid) } 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); diff --git a/mod/scorm/view.php b/mod/scorm/view.php index f97bf11d89..626e1b22f4 100755 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -60,38 +60,37 @@ // // 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)) { + 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)); - //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 "'; - } + if (empty($cm->visible) and !has_capability('moodle/course:manageactivities', $context)) { + notice(get_string("activityiscurrentlyhidden")); + } - //----------------------- - $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); - if ($trackedusers->c > 0) { - echo "'; - } else { - echo ''; - } + if (has_capability('moodle/course:manageactivities', $context)) { + // Added by Pham Minh Duc + $examNumber = get_record_select('scorm_scoes', 'scorm ='.($scorm->id).' and minnormalizedmeasure > -1','count(id) as examCount'); + if ($examNumber->examCount > 0){ + echo "'; } + // End Add - $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); + $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c'); + if ($trackedusers->c > 0) { + echo "'; + } else { + echo ''; + } } + + // Added by Pham Minh Duc + $USER->setAttempt = 'notset'; + // End Add + + // 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); ?> -- 2.39.5