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
);
174 $columns = scorm_get_aicc_columns($rows[0],'course_element');
175 $regexp = scorm_forge_cols_regexp($columns->columns
,'(.+)?,');
176 for ($i=1;$i<count($rows);$i++
) {
177 if (preg_match($regexp,$rows[$i],$matches)) {
178 for ($j=0;$j<count($matches)-1;$j++
) {
179 if ($j != $columns->mastercol
) {
180 $courses[$courseid]->elements
[substr(trim($matches[$j+
1]),1,-1)]->parent
= substr(trim($matches[$columns->mastercol+
1]),1,-1);
186 if (isset($id->pre
)) {
187 $rows = file($pkgdir.'/'.$id->pre
);
188 $columns = scorm_get_aicc_columns($rows[0],'structure_element');
189 $regexp = scorm_forge_cols_regexp($columns->columns
,'(.+),');
190 for ($i=1;$i<count($rows);$i++
) {
191 if (preg_match($regexp,$rows[$i],$matches)) {
192 $courses[$courseid]->elements
[$columns->mastercol+
1]->prerequisites
= substr(trim($matches[1-$columns->mastercol+
1]),1,-1);
196 if (isset($id->cmp
)) {
197 $rows = file($pkgdir.'/'.$id->cmp
);
202 $oldscoes = get_records('scorm_scoes','scorm',$scormid);
205 if (isset($courses)) {
206 foreach ($courses as $course) {
208 $sco->identifier
= $course->id
;
209 $sco->scorm
= $scormid;
210 $sco->organization
= '';
211 $sco->title
= $course->title
;
214 $sco->scormtype
= '';
217 if (get_record('scorm_scoes','scorm',$scormid,'identifier',$sco->identifier
)) {
218 $id = update_record('scorm_scoes',$sco);
219 unset($oldscoes[$id]);
221 $id = insert_record('scorm_scoes',$sco);
227 if (isset($course->elements
)) {
228 foreach($course->elements
as $element) {
230 $sco->identifier
= $element->system_id
;
231 $sco->scorm
= $scormid;
232 $sco->organization
= $course->id
;
233 $sco->title
= $element->title
;
235 if (!isset($element->parent
) ||
strtolower($element->parent
) == 'root') {
238 $sco->parent
= $element->parent
;
240 if (isset($element->file_name
)) {
241 $sco->launch
= $element->file_name
;
242 $sco->scormtype
= 'sco';
246 if ($oldscoid = scorm_array_search('identifier',$sco->identifier
,$oldscoes)) {
247 $sco->id
= $oldscoid;
248 $id = update_record('scorm_scoes',$sco);
249 delete_records('scorm_scoes_data','scoid',$oldscoid);
250 unset($oldscoes[$oldscoid]);
252 $id = insert_record('scorm_scoes',$sco);
256 $scodata->scoid
= $id;
257 if (isset($element->web_launch
)) {
258 $scodata->name
= 'parameters';
259 $scodata->value
= $element->web_launch
;
260 $dataid = insert_record('scorm_scoes_data',$scodata);
262 if (isset($element->prerequisites
)) {
263 $scodata->name
= 'prerequisites';
264 $scodata->value
= $element->prerequisites
;
265 $dataid = insert_record('scorm_scoes_data',$scodata);
267 if (isset($element->max_time_allowed
)) {
268 $scodata->name
= 'max_time_allowed';
269 $scodata->value
= $element->max_time_allowed
;
270 $dataid = insert_record('scorm_scoes_data',$scodata);
272 if (isset($element->time_limit_action
)) {
273 $scodata->name
= 'time_limit_action';
274 $scodata->value
= $element->time_limit_action
;
275 $dataid = insert_record('scorm_scoes_data',$scodata);
277 if (isset($element->mastery_score
)) {
278 $scodata->name
= 'mastery_score';
279 $scodata->value
= $element->mastery_score
;
280 $dataid = insert_record('scorm_scoes_data',$scodata);
282 if (isset($element->core_vendor
)) {
283 $scodata->name
= 'datafromlms';
284 $scodata->value
= eregi_replace('<cr>', "\r\n", $element->core_vendor
);
285 $dataid = insert_record('scorm_scoes_data',$scodata);
296 if (!empty($oldscoes)) {
297 foreach($oldscoes as $oldsco) {
298 delete_records('scorm_scoes','id',$oldsco->id
);
299 delete_records('scorm_scoes_track','scoid',$oldsco->id
);
302 set_field('scorm','version','AICC','id',$scormid);
306 function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
309 $strexpand = get_string('expcoll','scorm');
311 if ($mode == 'browse') {
312 $modestr = '&mode='.$mode;
314 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
316 $result = new stdClass();
317 $result->toc
= "<ul id='s0' class='$liststyle'>\n";
319 $result->prerequisites
= true;
323 // Get the current organization infos
325 if (!empty($currentorg)) {
326 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id
,'identifier',$currentorg)) != '') {
327 $result->toc
.= "\t<li>$organizationtitle</li>\n";
328 $tocmenus[] = $organizationtitle;
332 // If not specified retrieve the last attempt number
334 if (empty($attempt)) {
335 $attempt = scorm_get_last_attempt($scorm->id
, $user->id
);
337 $result->attemptleft
= $scorm->maxattempt
- $attempt;
338 if ($scoes = scorm_get_scoes($scorm->id
, $currentorg)){
340 // Retrieve user tracking data for each learning object
342 $usertracks = array();
343 foreach ($scoes as $sco) {
344 if (!empty($sco->launch
)) {
345 if ($usertrack = scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
346 if ($usertrack->status
== '') {
347 $usertrack->status
= 'notattempted';
349 $usertracks[$sco->identifier
] = $usertrack;
359 $parents[$level]='/';
361 foreach ($scoes as $pos => $sco) {
363 $sco->title
= stripslashes($sco->title
);
364 if (!isset($sco->isvisible
) ||
(isset($sco->isvisible
) && ($sco->isvisible
== 'true'))) {
367 if ($parents[$level]!=$sco->parent
) {
368 if ($newlevel = array_search($sco->parent
,$parents)) {
369 for ($i=0; $i<($level-$newlevel); $i++
) {
370 $result->toc
.= "\t\t</ul></li>\n";
376 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
377 $closelist .= "\t\t</ul></li>\n";
380 if (($i == 0) && ($sco->parent
!= $currentorg)) {
382 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
383 $style = ' style="display: none;"';
385 $result->toc
.= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
388 $result->toc
.= $closelist;
391 $parents[$level]=$sco->parent
;
395 $result->toc
.= "\t\t<li>";
397 if (isset($scoes[$pos+
1])) {
398 $nextsco = $scoes[$pos+
1];
402 $nextisvisible = false;
403 if (!isset($nextsco->isvisible
) ||
(isset($nextsco->isvisible
) && ($nextsco->isvisible
== 'true'))) {
404 $nextisvisible = true;
406 if ($nextisvisible && ($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) && (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
409 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
412 $result->toc
.= '<a href="javascript:expandCollide(\'img'.$sublist.'\',\'s'.$sublist.'\','.$nextsco->id
.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
413 } else if ($isvisible) {
414 $result->toc
.= '<img src="'.$scormpixdir.'/spacer.gif" />';
416 if (empty($sco->title
)) {
417 $sco->title
= $sco->identifier
;
419 if (!empty($sco->launch
)) {
424 if (empty($scoid) && ($mode != 'normal')) {
427 if (isset($usertracks[$sco->identifier
])) {
428 $usertrack = $usertracks[$sco->identifier
];
429 $strstatus = get_string($usertrack->status
,'scorm');
430 if ($sco->scormtype
== 'sco') {
431 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
433 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
436 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
438 if ($play && empty($scoid)) {
442 if ($usertrack->score_raw
!= '') {
443 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
445 $strsuspended = get_string('suspended','scorm');
446 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
447 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
450 if ($play && empty($scoid)) {
454 if ($sco->scormtype
== 'sco') {
455 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
457 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
460 if ($sco->id
== $scoid) {
464 $shownext = isset($sco->next
) ?
$sco->next
: 0;
465 $showprev = isset($sco->previous
) ?
$sco->previous
: 0;
468 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
469 if (!empty($sco->launch
)) {
473 if (empty($sco->prerequisites
) ||
scorm_eval_prerequisites($sco->prerequisites
,$usertracks)) {
474 if ($sco->id
== $scoid) {
475 $result->prerequisites
= true;
477 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
478 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
479 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
481 if ($sco->id
== $scoid) {
482 $result->prerequisites
= false;
484 $result->toc
.= $statusicon.' '.format_string($sco->title
)."</li>\n";
488 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
490 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
491 if (!empty($nextsco->launch
)) {
492 $nextid = $nextsco->id
;
496 for ($i=0;$i<$level;$i++
) {
497 $result->toc
.= "\t\t</ul></li>\n";
501 $sco = scorm_get_sco($scoid);
502 $sco->previd
= $previd;
503 $sco->nextid
= $nextid;
505 $result->incomplete
= $incomplete;
507 $result->incomplete
= $incomplete;
510 $result->toc
.= "\t</ul>\n";
511 if ($scorm->hidetoc
== 0) {
513 <script type="text/javascript">
515 function expandCollide(which,list,item) {
516 var el = document.ids ? document.ids[list] : document.getElementById ? document.getElementById(list) : document.all[list];
517 which = which.substring(0,(which.length));
518 var el2 = document.ids ? document.ids[which] : document.getElementById ? document.getElementById(which) : document.all[which];
519 if (el.style.display != "none") {
520 el2.src = "'.$scormpixdir.'/plus.gif";
521 el.style.display=\'none\';
522 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
524 el2.src = "'.$scormpixdir.'/minus.gif";
525 el.style.display=\'block\';
526 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
533 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
534 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);