Permalink
Browse files

Removed the scorm_string_wrap unused function

  • Loading branch information...
1 parent d6bddd4 commit 5679493192af6899f4e5054298b699addc21a51b bobopinna committed Sep 19, 2006
Showing with 611 additions and 635 deletions.
  1. +611 −635 mod/scorm/locallib.php
View
1,246 mod/scorm/locallib.php
@@ -1,6 +1,6 @@
<?php // $Id$
-/// Local Library of functions and constants for module scorm
+/// Constants and settings for module scorm
define('GRADESCOES', '0');
define('GRADEHIGHEST', '1');
@@ -61,7 +61,7 @@
$repositoryconfigfile = $CFG->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
@@ -145,6 +145,48 @@ function scorm_datadir($strPath)
}
}
+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;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+function scorm_repeater($what, $times) {
+ if ($times <= 0) {
+ return null;
+ }
+ $return = '';
+ for ($i=0; $i<$times;$i++) {
+ $return .= $what;
+ }
+ return $return;
+}
+
+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;
+}
+
/**
* Given a package directory, this function will check if the package is valid
*
@@ -176,191 +218,6 @@ function scorm_validate($packagedir) {
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.'<br />';
- $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 ($i<strlen($prerequisites)) {
- $symbol = $prerequisites[$i];
- switch ($symbol) {
- case '&':
- case '|':
- $symbol .= $symbol;
- case '~':
- case '(':
- case ')':
- case '*':
- $element = trim($element);
-
- 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+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<strlen($prerequisites))); $close++) {
- if ($prerequisites[$close] == '}') {
- $closed++;
- } else if ($prerequisites[$close] == '{') {
- $opened++;
- }
- }
- $i = $close;
-
- $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));
- $settrue = 0;
- foreach ($setelements as $setelement) {
- if (scorm_eval_prerequisites($setelement,$usertracks)) {
- $settrue++;
- }
- }
-
- if ($settrue >= $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'")) {
@@ -380,66 +237,66 @@ 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;
- }
+function scorm_get_tracks($scoid,$userid,$attempt='') {
+/// Gets all tracks of specified sco and user
+ global $CFG;
- $mins = $aes[1] + $bes[1] + $change; //Minutes
- $change = floor($mins / 60);
- $mins = $mins - ($change * 60);
- if ($mins < 10) {
- $mins = '0' . $mins;
+ if (empty($attempt)) {
+ if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
+ $attempt = scorm_get_last_attempt($scormid,$userid);
+ } else {
+ $attempt = 1;
+ }
}
-
- $hours = $aes[0] + $bes[0] + $change; //Hours
- if ($hours < 10) {
- $hours = '0' . $hours;
- }
-
- if ($cents != '0') {
- return $hours . ":" . $mins . ":" . $secs . '.' . $cents;
+ $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;
+ // Defined in order to unify scorm1.2 and scorm2004
+ $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 $hours . ":" . $mins . ":" . $secs;
+ return false;
}
}
-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_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_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
@@ -572,282 +429,137 @@ 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) {
+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_course_format_display($user,$course) {
global $CFG;
- $strexpand = get_string('expcoll','scorm');
- $modestr = '';
- if ($mode == 'browse') {
- $modestr = '&amp;mode='.$mode;
- }
- $scormpixdir = $CFG->modpixpath.'/scorm/pix';
-
- $result = new stdClass();
- $result->toc = "<ul id='0' class='$liststyle'>\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<li>$organizationtitle</li>\n";
- $tocmenus[] = $organizationtitle;
+ $strupdate = get_string('update');
+ $strmodule = get_string('modulename','scorm');
+
+ echo '<div class="mod-scorm">';
+ 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 = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>';
+ if (isteacher($course->id, $user->id, true)) {
+ if (isediting($course->id)) {
+ // Display update icon
+ $path = $CFG->wwwroot.'/course';
+ $headertext .= '<span class="commands">'.
+ '<a title="'.$strupdate.'" href="'.$path.'/mod.php?update='.$cm->id.'&amp;sesskey='.sesskey().'">'.
+ '<img src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" alt="'.$strupdate.'" /></a></span>';
+ }
+ $headertext .= '</td>';
+ // Display report link
+ $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
+ if ($trackedusers->c > 0) {
+ $headertext .= '<td class="reportlink">'.
+ '<a target="'.$CFG->framename.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
+ get_string('viewallreports','scorm',$trackedusers->c).'</a>';
+ } else {
+ $headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
+ }
+ $colspan = ' colspan="2"';
+ }
+ $headertext .= '</td></tr><tr><td'.$colspan.'>'.format_text(get_string('summary').':<br />'.$scorm->summary).'</td></tr></table>';
+ 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($CFG->wwwroot.'/course/mod.php?id='.$course->id.'&amp;section=0&sesskey='.sesskey().'&amp;add=scorm');
+ } else {
+ notify('Could not find a scorm course here');
}
- $organizationsql = "AND organization='$currentorg'";
}
- //
- // If not specified retrieve the last attempt number
- //
- if (empty($attempt)) {
- $attempt = scorm_get_last_attempt($scorm->id, $user->id);
+ echo '</div>';
+}
+
+function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
+ global $CFG;
+
+ $organization = optional_param('organization', '', PARAM_INT);
+
+ print_simple_box_start('center',$boxwidth);
+?>
+ <div class="structurehead"><?php print_string('coursestruct','scorm') ?></div>
+<?php
+ if (empty($organization)) {
+ $organization = $scorm->launch;
}
- $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;
- }
- }
+ if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
+ if (count($orgs) > 1) {
+ ?>
+ <div class='center'>
+ <?php print_string('organizations','scorm') ?>
+ <form name='changeorg' method='post' action='<?php echo $action ?>'>
+ <?php choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?>
+ </form>
+ </div>
+<?php
+ }
+ }
+ $orgidentifier = '';
+ if ($org = get_record('scorm_scoes','id',$organization)) {
+ if (($org->organization == '') && ($org->launch == '')) {
+ $orgidentifier = $org->identifier;
+ } else {
+ $orgidentifier = $org->organization;
}
-
- $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</ul></li>\n";
- }
- $level = $newlevel;
- } else {
- $i = $level;
- $closelist = '';
- while (($i > 0) && ($parents[$level] != $sco->parent)) {
- $closelist .= "\t\t</ul></li>\n";
- $i--;
- }
- if (($i == 0) && ($sco->parent != $currentorg)) {
- $style = '';
- if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
- $style = ' style="display: none;"';
- }
- $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";
- $level++;
- } else {
- $result->toc .= $closelist;
- $level = $i;
- }
- $parents[$level]=$sco->parent;
- }
- }
- $result->toc .= "\t\t<li>";
- $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 .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
- } else {
- $result->toc .= '<img src="'.$scormpixdir.'/spacer.gif" />';
- }
- 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 .= '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$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').':&nbsp;'.$usertrack->score_raw.')';
- }
- } else {
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- if ($sco->scormtype == 'sco') {
- $result->toc .= '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
- $incomplete = true;
- } else {
- $result->toc .= '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
- }
- }
- if ($sco->id == $scoid) {
- $startbold = '<b>';
- $endbold = '</b>';
- $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.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
- $result->toc .= '&nbsp'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
- $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
- } else {
- if ($sco->id == $scoid) {
- $result->prerequisites = false;
- }
- $result->toc .= '&nbsp;'.$sco->title."</li>\n";
- }
- } else {
- $result->toc .= '&nbsp;'.$sco->title."</li>\n";
- }
- if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
- if (!empty($nextsco->launch)) {
- $nextid = $nextsco->id;
- }
- }
- }
- for ($i=0;$i<$level;$i++) {
- $result->toc .= "\t\t</ul></li>\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</ul>\n";
- if ($scorm->hidetoc == 0) {
- $result->toc .= '
- <script language="javascript" type="text/javascript">
- <!--
- function expandCollide(which,list,item) {
- var nn=document.ids?true:false
- var w3c=document.getElementById?true:false
- var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
- var mid=w3c?").style":".style";
-
- if (eval(beg+list+mid+".display") != "none") {
- which.src = "'.$scormpixdir.'/plus.gif";
- eval(beg+list+mid+".display=\'none\';");
- new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
- } else {
- which.src = "'.$scormpixdir.'/minus.gif";
- eval(beg+list+mid+".display=\'block\';");
- new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
- }
- }
- -->
- </script>'."\n";
- }
-
- $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;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;
- // Defined in order to unify scorm1.2 and scorm2004
- $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;
- }
-}
+ }
+ $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier);
+ $incomplete = $result->incomplete;
+ echo $result->toc;
+ print_simple_box_end();
+?>
+ <div class="center">
+ <form name="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>
+ <?php
+ if ($scorm->hidebrowse == 0) {
+ print_string("mode","scorm");
+ echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
+ if ($incomplete === true) {
+ echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
+ } else {
+ echo '<input type="radio" id="r" name="mode" value="review" checked="checked" /><label for="r">'.get_string('review','scorm')."</label>\n";
+ }
+ } else {
+ if ($incomplete === true) {
+ echo '<input type="hidden" name="mode" value="normal" />'."\n";
+ } else {
+ echo '<input type="hidden" name="mode" value="review" />'."\n";
+ }
+ }
+ if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {
+?>
+ <br />
+ <input type="checkbox" id="a" name="newattempt" />
+ <label for="a"><?php print_string('newattempt','scorm') ?></label>
+<?php
+ }
+ ?>
+ <br />
+ <input type="hidden" name="scoid" />
+ <input type="hidden" name="currentorg" value="<?php echo $orgidentifier ?>" />
+ <input type="submit" value="<?php print_string('entercourse','scorm') ?>" />
+ </form>
+ </div>
+<?php
+}
/// Library of functions and constants for parsing packages
@@ -1336,153 +1048,417 @@ function scorm_parse_scorm($pkgdir,$scormid) {
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;
- }
- }
- }
+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;
}
- return false;
-}
-function scorm_course_format_display($user,$course) {
- global $CFG;
+ $secs = $aseconds[0] + $bseconds[0] + $change; //Seconds
+ $change = floor($secs / 60);
+ $secs = $secs - ($change * 60);
+ if (floor($secs) < 10) {
+ $secs = '0'. $secs;
+ }
- $strupdate = get_string('update');
- $strmodule = get_string('modulename','scorm');
+ $mins = $aes[1] + $bes[1] + $change; //Minutes
+ $change = floor($mins / 60);
+ $mins = $mins - ($change * 60);
+ if ($mins < 10) {
+ $mins = '0' . $mins;
+ }
- echo '<div class="mod-scorm">';
- 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");
+ $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_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 ($i<strlen($prerequisites)) {
+ $symbol = $prerequisites[$i];
+ switch ($symbol) {
+ case '&':
+ case '|':
+ $symbol .= $symbol;
+ case '~':
+ case '(':
+ case ')':
+ case '*':
+ $element = trim($element);
+
+ 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+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<strlen($prerequisites))); $close++) {
+ if ($prerequisites[$close] == '}') {
+ $closed++;
+ } else if ($prerequisites[$close] == '{') {
+ $opened++;
+ }
+ }
+ $i = $close;
+
+ $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));
+ $settrue = 0;
+ foreach ($setelements as $setelement) {
+ if (scorm_eval_prerequisites($setelement,$usertracks)) {
+ $settrue++;
+ }
+ }
+
+ if ($settrue >= $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;
}
- $colspan = '';
- $headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>';
- if (isteacher($course->id, $user->id, true)) {
- if (isediting($course->id)) {
- // Display update icon
- $path = $CFG->wwwroot.'/course';
- $headertext .= '<span class="commands">'.
- '<a title="'.$strupdate.'" href="'.$path.'/mod.php?update='.$cm->id.'&amp;sesskey='.sesskey().'">'.
- '<img src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" alt="'.$strupdate.'" /></a></span>';
+ $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;
}
- $headertext .= '</td>';
- // Display report link
- $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
- if ($trackedusers->c > 0) {
- $headertext .= '<td class="reportlink">'.
- '<a target="'.$CFG->framename.'" href="'.$CFG->wwwroot.'/mod/scorm/report.php?id='.$cm->id.'">'.
- get_string('viewallreports','scorm',$trackedusers->c).'</a>';
+
+ $value = trim(trim(substr($element,$operator+1)),'"');
+ if (isset($statuses[$value])) {
+ $status = $statuses[$value];
} else {
- $headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
+ return false;
}
- $colspan = ' colspan="2"';
- }
- $headertext .= '</td></tr><tr><td'.$colspan.'>'.format_text(get_string('summary').':<br />'.$scorm->summary).'</td></tr></table>';
- 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($CFG->wwwroot.'/course/mod.php?id='.$course->id.'&amp;section=0&sesskey='.sesskey().'&amp;add=scorm');
+
+ $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 {
- notify('Could not find a scorm course here');
+ return false;
}
+
+ array_push($stack,$element);
}
- echo '</div>';
+ return eval('return '.implode($stack).';');
}
-function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
+function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
global $CFG;
- $organization = optional_param('organization', '', PARAM_INT);
-
- print_simple_box_start('center',$boxwidth);
-?>
- <div class="structurehead"><?php print_string('coursestruct','scorm') ?></div>
-<?php
- if (empty($organization)) {
- $organization = $scorm->launch;
- }
- if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
- if (count($orgs) > 1) {
- ?>
- <div class='center'>
- <?php print_string('organizations','scorm') ?>
- <form name='changeorg' method='post' action='<?php echo $action ?>'>
- <?php choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?>
- </form>
- </div>
-<?php
+ $strexpand = get_string('expcoll','scorm');
+ $modestr = '';
+ if ($mode == 'browse') {
+ $modestr = '&amp;mode='.$mode;
+ }
+ $scormpixdir = $CFG->modpixpath.'/scorm/pix';
+
+ $result = new stdClass();
+ $result->toc = "<ul id='0' class='$liststyle'>\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<li>$organizationtitle</li>\n";
+ $tocmenus[] = $organizationtitle;
}
+ $organizationsql = "AND organization='$currentorg'";
}
- $orgidentifier = '';
- if ($org = get_record('scorm_scoes','id',$organization)) {
- if (($org->organization == '') && ($org->launch == '')) {
- $orgidentifier = $org->identifier;
+ //
+ // 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</ul></li>\n";
+ }
+ $level = $newlevel;
+ } else {
+ $i = $level;
+ $closelist = '';
+ while (($i > 0) && ($parents[$level] != $sco->parent)) {
+ $closelist .= "\t\t</ul></li>\n";
+ $i--;
+ }
+ if (($i == 0) && ($sco->parent != $currentorg)) {
+ $style = '';
+ if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
+ $style = ' style="display: none;"';
+ }
+ $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";
+ $level++;
+ } else {
+ $result->toc .= $closelist;
+ $level = $i;
+ }
+ $parents[$level]=$sco->parent;
+ }
+ }
+ $result->toc .= "\t\t<li>";
+ $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 .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
+ } else {
+ $result->toc .= '<img src="'.$scormpixdir.'/spacer.gif" />';
+ }
+ 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 .= '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$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').':&nbsp;'.$usertrack->score_raw.')';
+ }
+ } else {
+ if ($play && empty($scoid)) {
+ $scoid = $sco->id;
+ }
+ if ($sco->scormtype == 'sco') {
+ $result->toc .= '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
+ $incomplete = true;
+ } else {
+ $result->toc .= '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
+ }
+ }
+ if ($sco->id == $scoid) {
+ $startbold = '<b>';
+ $endbold = '</b>';
+ $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.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
+ $result->toc .= '&nbsp'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
+ $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
+ } else {
+ if ($sco->id == $scoid) {
+ $result->prerequisites = false;
+ }
+ $result->toc .= '&nbsp;'.$sco->title."</li>\n";
+ }
+ } else {
+ $result->toc .= '&nbsp;'.$sco->title."</li>\n";
+ }
+ if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
+ if (!empty($nextsco->launch)) {
+ $nextid = $nextsco->id;
+ }
+ }
+ }
+ for ($i=0;$i<$level;$i++) {
+ $result->toc .= "\t\t</ul></li>\n";
+ }
+
+ if ($play) {
+ $sco = get_record('scorm_scoes','id',$scoid);
+ $sco->previd = $previd;
+ $sco->nextid = $nextid;
+ $result->sco = $sco;
+ $result->incomplete = $incomplete;
} else {
- $orgidentifier = $org->organization;
+ $result->incomplete = $incomplete;
}
}
- $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier);
- $incomplete = $result->incomplete;
- echo $result->toc;
- print_simple_box_end();
-?>
- <div class="center">
- <form name="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>
- <?php
- if ($scorm->hidebrowse == 0) {
- print_string("mode","scorm");
- echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
- if ($incomplete === true) {
- echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
- } else {
- echo '<input type="radio" id="r" name="mode" value="review" checked="checked" /><label for="r">'.get_string('review','scorm')."</label>\n";
- }
+ $result->toc .= "\t</ul>\n";
+ if ($scorm->hidetoc == 0) {
+ $result->toc .= '
+ <script language="javascript" type="text/javascript">
+ <!--
+ function expandCollide(which,list,item) {
+ var nn=document.ids?true:false
+ var w3c=document.getElementById?true:false
+ var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
+ var mid=w3c?").style":".style";
+
+ if (eval(beg+list+mid+".display") != "none") {
+ which.src = "'.$scormpixdir.'/plus.gif";
+ eval(beg+list+mid+".display=\'none\';");
+ new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
} else {
- if ($incomplete === true) {
- echo '<input type="hidden" name="mode" value="normal" />'."\n";
- } else {
- echo '<input type="hidden" name="mode" value="review" />'."\n";
- }
- }
- if (($incomplete === false) && (($result->attemptleft > 0)||($scorm->maxattempt == 0))) {
-?>
- <br />
- <input type="checkbox" id="a" name="newattempt" />
- <label for="a"><?php print_string('newattempt','scorm') ?></label>
-<?php
+ which.src = "'.$scormpixdir.'/minus.gif";
+ eval(beg+list+mid+".display=\'block\';");
+ new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
}
- ?>
- <br />
- <input type="hidden" name="scoid" />
- <input type="hidden" name="currentorg" value="<?php echo $orgidentifier ?>" />
- <input type="submit" value="<?php print_string('entercourse','scorm') ?>" />
- </form>
- </div>
-<?php
-}
-
-function scorm_repeater($what, $times) {
- if ($times <= 0) {
- return null;
- }
- $return = '';
- for ($i=0; $i<$times;$i++) {
- $return .= $what;
+ }
+ -->
+ </script>'."\n";
}
- return $return;
+
+ $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
+ $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
+
+ return $result;
}
/**

0 comments on commit 5679493

Please sign in to comment.