2 function scorm_add_time($a, $b) {
3 $aes = explode(':',$a);
4 $bes = explode(':',$b);
5 $aseconds = explode('.',$aes[2]);
6 $bseconds = explode('.',$bes[2]);
10 if (count($aseconds) > 1) {
11 $acents = $aseconds[1];
14 if (count($bseconds) > 1) {
15 $bcents = $bseconds[1];
17 $cents = $acents +
$bcents;
18 $change = floor($cents / 100);
19 $cents = $cents - ($change * 100);
20 if (floor($cents) < 10) {
24 $secs = $aseconds[0] +
$bseconds[0] +
$change; //Seconds
25 $change = floor($secs / 60);
26 $secs = $secs - ($change * 60);
27 if (floor($secs) < 10) {
31 $mins = $aes[1] +
$bes[1] +
$change; //Minutes
32 $change = floor($mins / 60);
33 $mins = $mins - ($change * 60);
38 $hours = $aes[0] +
$bes[0] +
$change; //Hours
40 $hours = '0' . $hours;
44 return $hours . ":" . $mins . ":" . $secs . '.' . $cents;
46 return $hours . ":" . $mins . ":" . $secs;
51 * Take the header row of an AICC definition file
52 * and returns sequence of columns and a pointer to
53 * the sco identifier column.
55 * @param string $row AICC header row
56 * @param string $mastername AICC sco identifier column
59 function scorm_get_aicc_columns($row,$mastername='system_id') {
60 $tok = strtok(strtolower($row),"\",\n\r");
61 $result->columns
= array();
65 $result->columns
[] = $tok;
66 if ($tok == $mastername) {
67 $result->mastercol
= $i;
71 $tok = strtok("\",\n\r");
77 * Given a colums array return a string containing the regular
78 * expression to match the columns in a text row.
80 * @param array $column The header columns
81 * @param string $remodule The regular expression module for a single column
84 function scorm_forge_cols_regexp($columns,$remodule='(".*")?,') {
86 foreach ($columns as $column) {
89 $regexp = substr($regexp,0,-1) . '/';
93 function scorm_parse_aicc($pkgdir,$scormid) {
97 $extaiccfiles = array('crs','des','au','cst','ort','pre','cmp');
98 if ($handle = opendir($pkgdir)) {
99 while (($file = readdir($handle)) !== false) {
100 if ($file[0] != '.') {
101 $ext = substr($file,strrpos($file,'.'));
102 $extension = strtolower(substr($ext,1));
103 if (in_array($extension,$extaiccfiles)) {
104 $id = strtolower(basename($file,$ext));
105 $ids[$id]->$extension = $file;
111 foreach ($ids as $courseid => $id) {
112 if (isset($id->crs
)) {
113 if (is_file($pkgdir.'/'.$id->crs
)) {
114 $rows = file($pkgdir.'/'.$id->crs
);
115 foreach ($rows as $row) {
116 if (preg_match("/^(.+)=(.+)$/",$row,$matches)) {
117 switch (strtolower(trim($matches[1]))) {
119 $courses[$courseid]->id
= trim($matches[2]);
122 $courses[$courseid]->title
= trim($matches[2]);
125 $courses[$courseid]->version
= 'AICC_'.trim($matches[2]);
132 if (isset($id->des
)) {
133 $rows = file($pkgdir.'/'.$id->des
);
134 $columns = scorm_get_aicc_columns($rows[0]);
135 $regexp = scorm_forge_cols_regexp($columns->columns
);
136 for ($i=1;$i<count($rows);$i++
) {
137 if (preg_match($regexp,$rows[$i],$matches)) {
138 for ($j=0;$j<count($columns->columns
);$j++
) {
139 $column = $columns->columns
[$j];
140 $courses[$courseid]->elements
[substr(trim($matches[$columns->mastercol+
1]),1,-1)]->$column = substr(trim($matches[$j+
1]),1,-1);
145 if (isset($id->au
)) {
146 $rows = file($pkgdir.'/'.$id->au
);
147 $columns = scorm_get_aicc_columns($rows[0]);
148 $regexp = scorm_forge_cols_regexp($columns->columns
);
149 for ($i=1;$i<count($rows);$i++
) {
150 if (preg_match($regexp,$rows[$i],$matches)) {
151 for ($j=0;$j<count($columns->columns
);$j++
) {
152 $column = $columns->columns
[$j];
153 $courses[$courseid]->elements
[substr(trim($matches[$columns->mastercol+
1]),1,-1)]->$column = substr(trim($matches[$j+
1]),1,-1);
158 if (isset($id->cst
)) {
159 $rows = file($pkgdir.'/'.$id->cst
);
160 $columns = scorm_get_aicc_columns($rows[0],'block');
161 $regexp = scorm_forge_cols_regexp($columns->columns
,'(.+)?,');
162 for ($i=1;$i<count($rows);$i++
) {
163 if (preg_match($regexp,$rows[$i],$matches)) {
164 for ($j=0;$j<count($columns->columns
);$j++
) {
165 if ($j != $columns->mastercol
) {
166 $courses[$courseid]->elements
[substr(trim($matches[$j+
1]),1,-1)]->parent
= substr(trim($matches[$columns->mastercol+
1]),1,-1);
172 if (isset($id->ort
)) {
173 $rows = file($pkgdir.'/'.$id->ort
);
175 if (isset($id->pre
)) {
176 $rows = file($pkgdir.'/'.$id->pre
);
177 $columns = scorm_get_aicc_columns($rows[0],'structure_element');
178 $regexp = scorm_forge_cols_regexp($columns->columns
,'(.+),');
179 for ($i=1;$i<count($rows);$i++
) {
180 if (preg_match($regexp,$rows[$i],$matches)) {
181 $courses[$courseid]->elements
[$columns->mastercol+
1]->prerequisites
= substr(trim($matches[1-$columns->mastercol+
1]),1,-1);
185 if (isset($id->cmp
)) {
186 $rows = file($pkgdir.'/'.$id->cmp
);
191 $oldscoes = get_records('scorm_scoes','scorm',$scormid);
194 if (isset($courses)) {
195 foreach ($courses as $course) {
197 $sco->identifier
= $course->id
;
198 $sco->scorm
= $scormid;
199 $sco->organization
= '';
200 $sco->title
= $course->title
;
203 $sco->scormtype
= '';
206 if (get_record('scorm_scoes','scorm',$scormid,'identifier',$sco->identifier
)) {
207 $id = update_record('scorm_scoes',$sco);
208 unset($oldscoes[$id]);
210 $id = insert_record('scorm_scoes',$sco);
216 if (isset($course->elements
)) {
217 foreach($course->elements
as $element) {
219 $sco->identifier
= $element->system_id
;
220 $sco->scorm
= $scormid;
221 $sco->organization
= $course->id
;
222 $sco->title
= $element->title
;
223 if (strtolower($element->parent
) == 'root') {
226 $sco->parent
= $element->parent
;
228 if (isset($element->file_name
)) {
229 $sco->launch
= $element->file_name
;
230 $sco->scormtype
= 'sco';
232 $element->file_name
= '';
233 $sco->scormtype
= '';
235 if (!isset($element->prerequisites
)) {
236 $element->prerequisites
= '';
238 $sco->prerequisites
= $element->prerequisites
;
239 if (!isset($element->max_time_allowed
)) {
240 $element->max_time_allowed
= '';
242 $sco->maxtimeallowed
= $element->max_time_allowed
;
243 if (!isset($element->time_limit_action
)) {
244 $element->time_limit_action
= '';
246 $sco->timelimitaction
= $element->time_limit_action
;
247 if (!isset($element->mastery_score
)) {
248 $element->mastery_score
= '';
250 $sco->masteryscore
= $element->mastery_score
;
253 if ($oldscoid = scorm_array_search('identifier',$sco->identifier
,$oldscoes)) {
254 $sco->id
= $oldscoid;
255 $id = update_record('scorm_scoes',$sco);
256 unset($oldscoes[$oldscoid]);
258 $id = insert_record('scorm_scoes',$sco);
267 if (!empty($oldscoes)) {
268 foreach($oldscoes as $oldsco) {
269 delete_records('scorm_scoes','id',$oldsco->id
);
270 delete_records('scorm_scoes_track','scoid',$oldsco->id
);
273 set_field('scorm','version','AICC','id',$scormid);
277 function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
280 $strexpand = get_string('expcoll','scorm');
282 if ($mode == 'browse') {
283 $modestr = '&mode='.$mode;
285 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
287 $result = new stdClass();
288 $result->toc
= "<ul id='0' class='$liststyle'>\n";
290 $result->prerequisites
= true;
294 // Get the current organization infos
296 $organizationsql = '';
297 if (!empty($currentorg)) {
298 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id
,'identifier',$currentorg)) != '') {
299 $result->toc
.= "\t<li>$organizationtitle</li>\n";
300 $tocmenus[] = $organizationtitle;
302 $organizationsql = "AND organization='$currentorg'";
305 // If not specified retrieve the last attempt number
307 if (empty($attempt)) {
308 $attempt = scorm_get_last_attempt($scorm->id
, $user->id
);
311 $result->attemptleft
= $scorm->maxattempt
- $attempt;
312 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
314 // Retrieve user tracking data for each learning object
316 $usertracks = array();
317 foreach ($scoes as $sco) {
318 if (!empty($sco->launch
)) {
319 if ($usertrack=scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
320 if ($usertrack->status
== '') {
321 $usertrack->status
= 'notattempted';
323 $usertracks[$sco->identifier
] = $usertrack;
333 $parents[$level]='/';
335 foreach ($scoes as $sco) {
336 if ($parents[$level]!=$sco->parent
) {
337 if ($newlevel = array_search($sco->parent
,$parents)) {
338 for ($i=0; $i<($level-$newlevel); $i++
) {
339 $result->toc
.= "\t\t</ul></li>\n";
345 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
346 $closelist .= "\t\t</ul></li>\n";
349 if (($i == 0) && ($sco->parent
!= $currentorg)) {
351 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
352 $style = ' style="display: none;"';
354 $result->toc
.= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";
357 $result->toc
.= $closelist;
360 $parents[$level]=$sco->parent
;
363 $result->toc
.= "\t\t<li>";
364 $nextsco = next($scoes);
365 if (($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) && (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
368 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
371 $result->toc
.= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id
.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
373 $result->toc
.= '<img src="'.$scormpixdir.'/spacer.gif" />';
375 if (empty($sco->title
)) {
376 $sco->title
= $sco->identifier
;
378 if (!empty($sco->launch
)) {
382 if (empty($scoid) && ($mode != 'normal')) {
385 if (isset($usertracks[$sco->identifier
])) {
386 $usertrack = $usertracks[$sco->identifier
];
387 $strstatus = get_string($usertrack->status
,'scorm');
388 if ($sco->scormtype
== 'sco') {
389 $statusicon .= '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
391 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
394 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
396 if ($play && empty($scoid)) {
400 if ($usertrack->score_raw
!= '') {
401 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
403 $strsuspended = get_string('suspended','scorm');
404 if ($usertrack->{'cmi.core.exit'} == 'suspend') {
405 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
408 if ($play && empty($scoid)) {
412 if ($sco->scormtype
== 'sco') {
413 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
415 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
418 if ($sco->id
== $scoid) {
422 $shownext = $sco->next
;
423 $showprev = $sco->previous
;
426 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
427 if (!empty($sco->launch
)) {
431 if (empty($sco->prerequisites
) ||
scorm_eval_prerequisites($sco->prerequisites
,$usertracks)) {
432 if ($sco->id
== $scoid) {
433 $result->prerequisites
= true;
435 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
436 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
437 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
439 if ($sco->id
== $scoid) {
440 $result->prerequisites
= false;
442 $result->toc
.= ' '.$sco->title
."</li>\n";
445 $result->toc
.= ' '.$sco->title
."</li>\n";
447 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
448 if (!empty($nextsco->launch
)) {
449 $nextid = $nextsco->id
;
453 for ($i=0;$i<$level;$i++
) {
454 $result->toc
.= "\t\t</ul></li>\n";
458 $sco = get_record('scorm_scoes','id',$scoid);
459 $sco->previd
= $previd;
460 $sco->nextid
= $nextid;
462 $result->incomplete
= $incomplete;
464 $result->incomplete
= $incomplete;
467 $result->toc
.= "\t</ul>\n";
468 if ($scorm->hidetoc
== 0) {
470 <script type="text/javascript">
472 function expandCollide(which,list,item) {
473 var nn=document.ids?true:false
474 var w3c=document.getElementById?true:false
475 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
476 var mid=w3c?").style":".style";
478 if (eval(beg+list+mid+".display") != "none") {
479 which.src = "'.$scormpixdir.'/plus.gif";
480 eval(beg+list+mid+".display=\'none\';");
481 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
483 which.src = "'.$scormpixdir.'/minus.gif";
484 eval(beg+list+mid+".display=\'block\';");
485 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
492 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
493 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);