3 /// Constants and settings for module scorm
4 define('UPDATE_NEVER', '0');
5 define('UPDATE_ONCHANGE', '1');
6 define('UPDATE_EVERYDAY', '2');
7 define('UPDATE_EVERYTIME', '3');
10 define('SCO_DATA', 1);
11 define('SCO_ONLY', 2);
13 define('GRADESCOES', '0');
14 define('GRADEHIGHEST', '1');
15 define('GRADEAVERAGE', '2');
16 define('GRADESUM', '3');
17 $SCORM_GRADE_METHOD = array (GRADESCOES
=> get_string('gradescoes', 'scorm'),
18 GRADEHIGHEST
=> get_string('gradehighest', 'scorm'),
19 GRADEAVERAGE
=> get_string('gradeaverage', 'scorm'),
20 GRADESUM
=> get_string('gradesum', 'scorm'));
22 define('HIGHESTATTEMPT', '0');
23 define('AVERAGEATTEMPT', '1');
24 define('FIRSTATTEMPT', '2');
25 define('LASTATTEMPT', '3');
26 $SCORM_WHAT_GRADE = array (HIGHESTATTEMPT
=> get_string('highestattempt', 'scorm'),
27 AVERAGEATTEMPT
=> get_string('averageattempt', 'scorm'),
28 FIRSTATTEMPT
=> get_string('firstattempt', 'scorm'),
29 LASTATTEMPT
=> get_string('lastattempt', 'scorm'));
31 $SCORM_POPUP_OPTIONS = array('resizable'=>1,
39 foreach ($SCORM_POPUP_OPTIONS as $popupopt => $value) {
40 $stdoptions .= $popupopt.'='.$value;
41 if ($popupopt != 'status') {
46 if (!isset($CFG->scorm_maxattempts
)) {
47 set_config('scorm_maxattempts','6');
50 if (!isset($CFG->scorm_frameheight
)) {
51 set_config('scorm_frameheight','500');
54 if (!isset($CFG->scorm_framewidth
)) {
55 set_config('scorm_framewidth','100%');
58 if (!isset($CFG->scorm_updatetime
)) {
59 set_config('scorm_updatetime','2');
62 if (!isset($CFG->scorm_advancedsettings
)) {
63 set_config('scorm_advancedsettings','0');
66 if (!isset($CFG->scorm_windowsettings
)) {
67 set_config('scorm_windowsettings','0');
71 // Repository configurations
73 $repositoryconfigfile = $CFG->dirroot
.'/mod/resource/type/ims/repository_config.php';
74 $repositorybrowser = '/mod/resource/type/ims/finder.php';
76 /// Local Library of functions for module scorm
79 * This function will permanently delete the given
80 * directory and all files and subdirectories.
82 * @param string $directory The directory to remove
85 function scorm_delete_files($directory) {
86 if (is_dir($directory)) {
87 $files=scorm_scandir($directory);
88 foreach($files as $file) {
89 if (($file != '.') && ($file != '..')) {
90 if (!is_dir($directory.'/'.$file)) {
91 unlink($directory.'/'.$file);
93 scorm_delete_files($directory.'/'.$file);
105 * Given a diretory path returns the file list
107 * @param string $directory
110 function scorm_scandir($directory) {
111 if (version_compare(phpversion(),'5.0.0','>=')) {
112 return scandir($directory);
115 if ($dh = opendir($directory)) {
116 while (($file = readdir($dh)) !== false) {
126 * Create a new temporary subdirectory with a random name in the given path
128 * @param string $strpath The scorm data directory
129 * @return string/boolean
131 function scorm_tempdir($strPath)
135 if (is_dir($strPath)) {
137 // Create a random string of 8 chars
141 for ($i=0; $i<$len; $i++
) {
142 $char = chr(rand(48,122));
143 while (!ereg('[a-zA-Z0-9]', $char)){
144 if ($char == $lchar) continue;
145 $char = chr(rand(48,90));
147 $randstring .= $char;
150 $datadir='/'.$randstring;
151 } while (file_exists($strPath.$datadir));
152 mkdir($strPath.$datadir, $CFG->directorypermissions
);
153 @chmod
($strPath.$datadir, $CFG->directorypermissions
); // Just in case mkdir didn't do it
154 return $strPath.$datadir;
160 function scorm_array_search($item, $needle, $haystacks, $strict=false) {
161 if (!empty($haystacks)) {
162 foreach ($haystacks as $key => $element) {
164 if ($element->{$item} === $needle) {
168 if ($element->{$item} == $needle) {
177 function scorm_repeater($what, $times) {
182 for ($i=0; $i<$times;$i++
) {
188 function scorm_external_link($link) {
189 // check if a link is external
191 $link = strtolower($link);
192 if (substr($link,0,7) == 'http://') {
194 } else if (substr($link,0,8) == 'https://') {
196 } else if (substr($link,0,4) == 'www.') {
203 * Returns an object containing all datas relative to the given sco ID
205 * @param integer $id The sco ID
206 * @return mixed (false if sco id does not exists)
208 function scorm_get_sco($id,$what=SCO_ALL
) {
209 if ($sco = get_record('scorm_scoes','id',$id)) {
210 $sco = ($what == SCO_DATA
) ?
new stdClass() : $sco;
211 if (($what != SCO_ONLY
) && ($scodatas = get_records('scorm_scoes_data','scoid',$id))) {
212 foreach ($scodatas as $scodata) {
213 $sco->{$scodata->name
} = $scodata->value
;
216 elseif (($what != SCO_ONLY
) && (!($scodatas = get_records('scorm_scoes_data','scoid',$id)))){
217 $sco->parameters
= '';
225 function scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value) {
227 if ($track = get_record_select('scorm_scoes_track',"userid='$userid' AND scormid='$scormid' AND scoid='$scoid' AND attempt='$attempt' AND element='$element'")) {
228 $track->value
= $value;
229 $track->timemodified
= time();
230 $id = update_record('scorm_scoes_track',$track);
232 $track->userid
= $userid;
233 $track->scormid
= $scormid;
234 $track->scoid
= $scoid;
235 $track->attempt
= $attempt;
236 $track->element
= $element;
237 $track->value
= addslashes($value);
238 $track->timemodified
= time();
239 $id = insert_record('scorm_scoes_track',$track);
244 function scorm_get_tracks($scoid,$userid,$attempt='') {
245 /// Gets all tracks of specified sco and user
248 if (empty($attempt)) {
249 if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
250 $attempt = scorm_get_last_attempt($scormid,$userid);
255 $attemptsql = ' AND attempt=' . $attempt;
256 if ($tracks = get_records_select('scorm_scoes_track',"userid=$userid AND scoid=$scoid".$attemptsql,'element ASC')) {
257 $usertrack->userid
= $userid;
258 $usertrack->scoid
= $scoid;
259 // Defined in order to unify scorm1.2 and scorm2004
260 $usertrack->score_raw
= '';
261 $usertrack->status
= '';
262 $usertrack->total_time
= '00:00:00';
263 $usertrack->session_time
= '00:00:00';
264 $usertrack->timemodified
= 0;
265 foreach ($tracks as $track) {
266 $element = $track->element
;
267 $usertrack->{$element} = $track->value
;
269 case 'cmi.core.lesson_status':
270 case 'cmi.completion_status':
271 if ($track->value
== 'not attempted') {
272 $track->value
= 'notattempted';
274 $usertrack->status
= $track->value
;
276 case 'cmi.core.score.raw':
277 case 'cmi.score.raw':
278 $usertrack->score_raw
= $track->value
;
280 case 'cmi.core.session_time':
281 case 'cmi.session_time':
282 $usertrack->session_time
= $track->value
;
284 case 'cmi.core.total_time':
285 case 'cmi.total_time':
286 $usertrack->total_time
= $track->value
;
289 if (isset($track->timemodified
) && ($track->timemodified
> $usertrack->timemodified
)) {
290 $usertrack->timemodified
= $track->timemodified
;
299 function scorm_get_user_data($userid) {
300 /// Gets user info required to display the table of scorm results
303 return get_record('user','id',$userid,'','','','','firstname, lastname, picture');
306 function scorm_grade_user_attempt($scorm, $userid, $attempt=1, $time=false) {
307 $attemptscore = NULL;
308 $attemptscore->scoes
= 0;
309 $attemptscore->values
= 0;
310 $attemptscore->max
= 0;
311 $attemptscore->sum
= 0;
312 $attemptscore->lastmodify
= 0;
314 if (!$scoes = get_records('scorm_scoes','scorm',$scorm->id
)) {
318 $grademethod = $scorm->grademethod %
10;
320 foreach ($scoes as $sco) {
321 if ($userdata=scorm_get_tracks($sco->id
, $userid,$attempt)) {
322 if (($userdata->status
== 'completed') ||
($userdata->status
== 'passed')) {
323 $attemptscore->scoes++
;
325 if (!empty($userdata->score_raw
)) {
326 $attemptscore->values++
;
327 $attemptscore->sum +
= $userdata->score_raw
;
328 $attemptscore->max
= ($userdata->score_raw
> $attemptscore->max
)?
$userdata->score_raw
:$attemptscore->max
;
329 if (isset($userdata->timemodified
) && ($userdata->timemodified
> $attemptscore->lastmodify
)) {
330 $attemptscore->lastmodify
= $userdata->timemodified
;
332 $attemptscore->lastmodify
= 0;
337 switch ($grademethod) {
339 $score = $attemptscore->max
;
342 if ($attemptscore->values
> 0) {
343 $score = $attemptscore->sum
/$attemptscore->values
;
349 $score = $attemptscore->sum
;
352 $score = $attemptscore->scoes
;
357 $result = new stdClass();
358 $result->score
= $score;
359 $result->time
= $attemptscore->lastmodify
;
367 function scorm_grade_user($scorm, $userid, $time=false) {
369 $whatgrade = intval($scorm->grademethod
/ 10);
371 switch ($whatgrade) {
373 return scorm_grade_user_attempt($scorm, $userid, 1, $time);
376 return scorm_grade_user_attempt($scorm, $userid, scorm_get_last_attempt($scorm->id
, $userid), $time);
379 $lastattempt = scorm_get_last_attempt($scorm->id
, $userid);
382 for ($attempt = 1; $attempt <= $lastattempt; $attempt++
) {
383 $attemptscore = scorm_grade_user_attempt($scorm, $userid, $attempt, $time);
385 if ($attemptscore->score
> $maxscore) {
386 $maxscore = $attemptscore->score
;
387 $attempttime = $attemptscore->time
;
390 $maxscore = $attemptscore > $maxscore ?
$attemptscore: $maxscore;
394 $result = new stdClass();
395 $result->score
= $maxscore;
396 $result->time
= $attempttime;
403 $lastattempt = scorm_get_last_attempt($scorm->id
, $userid);
405 for ($attempt = 1; $attempt <= $lastattempt; $attempt++
) {
406 $attemptscore = scorm_grade_user_attempt($scorm, $userid, $attempt, $time);
408 $sumscore +
= $attemptscore->score
;
410 $sumscore +
= $attemptscore;
414 if ($lastattempt > 0) {
415 $score = $sumscore / $lastattempt;
421 $result = new stdClass();
422 $result->score
= $score;
423 $result->time
= $attemptscore->time
;
432 function scorm_count_launchable($scormid,$organization='') {
433 $strorganization = '';
434 if (!empty($organization)) {
435 $strorganization = " AND organization='$organization'";
437 return count_records_select('scorm_scoes',"scorm=$scormid$strorganization AND launch<>''");
440 function scorm_get_last_attempt($scormid, $userid) {
441 /// Find the last attempt number for the given user id and scorm id
442 if ($lastattempt = get_record('scorm_scoes_track', 'userid', $userid, 'scormid', $scormid, '', '', 'max(attempt) as a')) {
443 if (empty($lastattempt->a
)) {
446 return $lastattempt->a
;
451 function scorm_course_format_display($user,$course) {
454 $strupdate = get_string('update');
455 $strmodule = get_string('modulename','scorm');
456 $context = get_context_instance(CONTEXT_COURSE
,$course->id
);
458 echo '<div class="mod-scorm">';
459 if ($scorms = get_all_instances_in_course('scorm', $course)) {
460 // The module SCORM activity with the least id is the course
461 $scorm = current($scorms);
462 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id
, $course->id
)) {
463 error('Course Module ID was incorrect');
466 $headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name
).'</b>';
467 if (has_capability('moodle/course:manageactivities', $context)) {
468 if (isediting($course->id
)) {
469 // Display update icon
470 $path = $CFG->wwwroot
.'/course';
471 $headertext .= '<span class="commands">'.
472 '<a title="'.$strupdate.'" href="'.$path.'/mod.php?update='.$cm->id
.'&sesskey='.sesskey().'">'.
473 '<img src="'.$CFG->pixpath
.'/t/edit.gif" class="iconsmall" alt="'.$strupdate.'" /></a></span>';
475 $headertext .= '</td>';
476 // Display report link
477 $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id
, '', '', '', '', 'count(distinct(userid)) as c');
478 if ($trackedusers->c
> 0) {
479 $headertext .= '<td class="reportlink">'.
480 '<a '.$CFG->frametarget
.'" href="'.$CFG->wwwroot
.'/mod/scorm/report.php?id='.$cm->id
.'">'.
481 get_string('viewallreports','scorm',$trackedusers->c
).'</a>';
483 $headertext .= '<td class="reportlink">'.get_string('noreports','scorm');
485 $colspan = ' colspan="2"';
487 $headertext .= '</td></tr><tr><td'.$colspan.'>'.format_text(get_string('summary').':<br />'.$scorm->summary
).'</td></tr></table>';
488 print_simple_box($headertext,'','100%');
489 scorm_view_display($user, $scorm, 'view.php?id='.$course->id
, $cm, '100%');
491 if (has_capability('moodle/course:update', $context)) {
492 // Create a new activity
493 redirect($CFG->wwwroot
.'/course/mod.php?id='.$course->id
.'&section=0&sesskey='.sesskey().'&add=scorm');
495 notify('Could not find a scorm course here');
501 function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
504 if ($scorm->updatefreq
== UPDATE_EVERYTIME
){
505 $scorm->instance
= $scorm->id
;
506 scorm_update_instance($scorm);
509 $organization = optional_param('organization', '', PARAM_INT
);
511 print_simple_box_start('center',$boxwidth);
513 <div
class="structurehead"><?php
print_string('contents','scorm') ?
></div
>
515 if (empty($organization)) {
516 $organization = $scorm->launch
;
518 if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
519 if (count($orgs) > 1) {
522 <?php
print_string('organizations','scorm') ?
>
523 <form id
='changeorg' method
='post' action
='<?php echo $action ?>'>
524 <?php
choose_from_menu($orgs, 'organization', "$organization", '','submit()') ?
>
531 if ($sco = scorm_get_sco($organization, SCO_ONLY
)) {
532 if (($sco->organization
== '') && ($sco->launch
== '')) {
533 $orgidentifier = $sco->identifier
;
535 $orgidentifier = $sco->organization
;
541 if ($org = get_record('scorm_scoes','id',$organization)) {
542 if (($org->organization == '') && ($org->launch == '')) {
543 $orgidentifier = $org->identifier;
545 $orgidentifier = $org->organization;
549 $scorm->version
= strtolower(clean_param($scorm->version
, PARAM_SAFEDIR
)); // Just to be safe
550 if (!file_exists($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php')) {
551 $scorm->version
= 'scorm_12';
553 require_once($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php');
555 $result = scorm_get_toc($user,$scorm,'structlist',$orgidentifier);
556 $incomplete = $result->incomplete
;
558 print_simple_box_end();
562 <form id
="theform" method
="post" action
="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?scoid=<?php echo $sco->id ?>&id=<?php echo $cm->id ?>"<?php
echo $scorm->popup
== 1?
' target="newwin"':'' ?
>>
564 if ($scorm->hidebrowse
== 0) {
565 print_string('mode','scorm');
566 echo '<input type="hidden" name="scoid" value="$sco->id" />'."\n";
567 echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
568 echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
570 echo '<input type="hidden" name="mode" value="normal" />'."\n";
572 if (($incomplete === false) && (($result->attemptleft
> 0)||
($scorm->maxattempt
== 0))) {
575 <input type
="checkbox" id
="a" name
="newattempt" />
576 <label
for="a"><?php
print_string('newattempt','scorm') ?
></label
>
581 <input type
="hidden" name
="scoid"/>
582 <input type
="hidden" name
="currentorg" value
="<?php echo $orgidentifier ?>" />
583 <input type
="submit" value
="<?php print_string('enter','scorm') ?>" />
588 function scorm_simple_play($scorm,$user) {
591 $scoes = get_records_select('scorm_scoes','scorm='.$scorm->id
.' AND launch<>\'\'');
593 if (count($scoes) == 1) {
594 if ($scorm->skipview
>= 1) {
595 $sco = current($scoes);
596 if (scorm_get_tracks($sco->id
,$user->id
) === false) {
597 header('Location: player.php?a='.$scorm->id
.'&scoid='.$sco->id
);
599 } else if ($scorm->skipview
== 2) {
600 header('Location: player.php?a='.$scorm->id
.'&scoid='.$sco->id
);
608 function scorm_simple_play($scorm,$user) {
610 if ($scoes = get_records_select('scorm_scoes','scorm='.$scorm->id.' AND launch<>""')) {
611 if (count($scoes) == 1) {
612 if ($scorm->skipview >= 1) {
613 $sco = current($scoes);
614 if (scorm_get_tracks($sco->id,$user->id) === false) {
615 header('Location: player.php?a='.$scorm->id.'&scoid='.$sco->id);
617 } else if ($scorm->skipview == 2) {
618 header('Location: player.php?a='.$scorm->id.'&scoid='.$sco->id);
627 function scorm_parse($scorm) {
628 global $CFG,$repositoryconfigfile;
630 if ($scorm->reference
[0] == '#') {
631 require_once($repositoryconfigfile);
632 if ($CFG->repositoryactivate
) {
633 $referencedir = $CFG->repository
.substr($scorm->reference
,1);
636 if ((!scorm_external_link($scorm->reference
)) && (basename($scorm->reference
) == 'imsmanifest.xml')) {
637 $referencedir = $CFG->dataroot
.'/'.$scorm->course
.'/'.$scorm->datadir
;
639 $referencedir = $CFG->dataroot
.'/'.$scorm->course
.'/moddata/scorm/'.$scorm->id
;
643 // Parse scorm manifest
644 if ($scorm->pkgtype
== 'AICC') {
645 require_once('datamodels/aicclib.php');
646 $scorm->launch
= scorm_parse_aicc($referencedir, $scorm->id
);
648 require_once('datamodels/scormlib.php');
649 if ($scorm->reference
[0] == '#') {
650 require_once($repositoryconfigfile);
652 $scorm->launch
= scorm_parse_scorm($referencedir,$scorm->id
);
654 return $scorm->launch
;
658 * Given a manifest path, this function will check if the manifest is valid
660 * @param string $manifest The manifest file
663 function scorm_validate_manifest($manifest) {
664 $validation = new stdClass();
665 if (is_file($manifest)) {
666 $validation->result
= true;
668 $validation->result
= false;
669 $validation->errors
['reference'] = get_string('nomanifest','scorm');
675 * Given a aicc package directory, this function will check if the course structure is valid
677 * @param string $packagedir The aicc package directory path
680 function scorm_validate_aicc($packagedir) {
681 $validation = new stdClass();
682 $validation->result
= false;
683 if (is_dir($packagedir)) {
684 if ($handle = opendir($packagedir)) {
685 while (($file = readdir($handle)) !== false) {
686 $ext = substr($file,strrpos($file,'.'));
687 if (strtolower($ext) == '.cst') {
688 $validation->result
= true;
695 if ($validation->result
== false) {
696 $validation->errors
['reference'] = get_string('nomanifest','scorm');
702 function scorm_validate($data) {
705 $validation = new stdClass();
706 $validation->errors
= array();
708 if (!isset($data['course']) ||
empty($data['course'])) {
709 $validation->errors
['reference'] = get_string('missingparam','scorm');
710 $validation->result
= false;
713 $courseid = $data['course']; // Course Module ID
715 if (!isset($data['reference']) ||
empty($data['reference'])) {
716 $validation->errors
['reference'] = get_string('packagefile','scorm');
717 $validation->result
= false;
720 $reference = $data['reference']; // Package/manifest path/location
722 $scormid = $data['instance']; // scorm ID
723 $scorm = new stdClass();
724 if (!empty($scormid)) {
725 if (!$scorm = get_record('scorm','id',$scormid)) {
726 $validation->errors
['reference'] = get_string('missingparam','scorm');
727 $validation->result
= false;
732 if ($reference[0] == '#') {
733 require_once($repositoryconfigfile);
734 if ($CFG->repositoryactivate
) {
735 $reference = $CFG->repository
.substr($reference,1).'/imsmanifest.xml';
737 $validation->errors
['reference'] = get_string('badpackage','scorm');
738 $validation->result
= false;
741 } else if (!scorm_external_link($reference)) {
742 $reference = $CFG->dataroot
.'/'.$courseid.'/'.$reference;
745 // Create a temporary directory to unzip package or copy manifest and validate package
748 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
749 if ($tempdir = scorm_tempdir($scormdir)) {
750 $localreference = $tempdir.'/'.basename($reference);
751 copy ("$reference", $localreference);
752 if (!is_file($localreference)) {
753 $validation->errors
['reference'] = get_string('badpackage','scorm');
754 $validation->result
= false;
756 $ext = strtolower(substr(basename($localreference),strrpos(basename($localreference),'.')));
760 if (!unzip_file($localreference, $tempdir, false)) {
761 $validation->errors
['reference'] = get_string('unziperror','scorm');
762 $validation->result
= false;
764 unlink ($localreference);
765 if (is_file($tempdir.'/imsmanifest.xml')) {
766 $validation = scorm_validate_manifest($tempdir.'/imsmanifest.xml');
767 $validation->pkgtype
= 'SCORM';
769 $validation = scorm_validate_aicc($tempdir);
770 if (($validation->result
== 'regular') ||
($validation->result
== 'found')) {
771 $validation->pkgtype
= 'AICC';
773 $validation->errors
['reference'] = get_string('nomanifest','scorm');
774 $validation->result
= false;
780 if (basename($localreference) == 'imsmanifest.xml') {
781 $validation = scorm_validate_manifest($localreference);
783 $validation->errors
['reference'] = get_string('nomanifest','scorm');
784 $validation->result
= false;
788 $validation->errors
['reference'] = get_string('badpackage','scorm');
789 $validation->result
= false;
793 if (is_dir($tempdir)) {
794 // Delete files and temporary directory
795 scorm_delete_files($tempdir);
798 $validation->errors
['reference'] = get_string('packagedir','scorm');
799 $validation->result
= false;
802 $validation->errors
['reference'] = get_string('datadir','scorm');
803 $validation->result
= false;
808 function scorm_check_package($data) {
809 global $CFG, $COURSE;
811 $courseid = $data->course
; // Course Module ID
812 $reference = $data->reference
; // Package path
813 $scormid = $data->instance
; // scorm ID
815 $validation = new stdClass();
817 if (!empty($courseid) && !empty($reference)) {
818 $externalpackage = scorm_external_link($reference);
820 $validation->launch
= 0;
821 $referencefield = $reference;
822 if (empty($reference)) {
824 } else if ($reference[0] == '#') {
825 require_once($repositoryconfigfile);
826 if ($CFG->repositoryactivate
) {
827 $referencefield = $reference.'/imsmanfest.xml';
828 $reference = $CFG->repository
.substr($reference,1).'/imsmanifest.xml';
832 } else if (!$externalpackage) {
833 $reference = $CFG->dataroot
.'/'.$courseid.'/'.$reference;
836 if (!empty($scormid)) {
840 if ((!empty($validation)) && (is_file($reference) ||
$externalpackage)){
842 if (!$externalpackage) {
843 $mdcheck = md5_file($reference);
844 } else if ($externalpackage){
845 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
846 if ($tempdir = scorm_tempdir($scormdir)) {
847 copy ("$reference", $tempdir.'/'.basename($reference));
848 $mdcheck = md5_file($tempdir.'/'.basename($reference));
849 scorm_delete_files($tempdir);
854 if ($scorm = get_record('scorm','id',$scormid)) {
855 if ($scorm->reference
[0] == '#') {
856 require_once($repositoryconfigfile);
857 if ($CFG->repositoryactivate
) {
858 $oldreference = $CFG->repository
.substr($scorm->reference
,1).'/imsmanifest.xml';
860 $oldreference = $scorm->reference
;
862 } else if (!scorm_external_link($scorm->reference
)) {
863 $oldreference = $CFG->dataroot
.'/'.$courseid.'/'.$scorm->reference
;
865 $oldreference = $scorm->reference
;
867 $validation->launch
= $scorm->launch
;
868 if ((($oldreference == $reference) && ($mdcheck != $scorm->md5hash
)) ||
($oldreference != $reference)) {
869 // This is a new or a modified package
870 $validation->launch
= 0;
872 // Old package already validated
873 if (strpos($scorm->version
,'AICC') !== false) {
874 $validation->pkgtype
= 'AICC';
876 $validation->pkgtype
= 'SCORM';
886 //$validation->launch = 0;
887 if (($validation != null) && ($validation->launch
== 0)) {
889 // Package must be validated
891 $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));
896 // Create a temporary directory to unzip package and validate package
898 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
899 if ($tempdir = scorm_tempdir($scormdir)) {
900 copy ("$reference", $tempdir.'/'.basename($reference));
901 unzip_file($tempdir.'/'.basename($reference), $tempdir, false);
902 if (!$externalpackage) {
903 unlink ($tempdir.'/'.basename($reference));
905 if (is_file($tempdir.'/imsmanifest.xml')) {
906 $validation = scorm_validate_manifest($tempdir.'/imsmanifest.xml');
907 $validation->pkgtype
= 'SCORM';
909 $validation = scorm_validate_aicc($tempdir);
910 $validation->pkgtype
= 'AICC';
920 if (basename($reference) == 'imsmanifest.xml') {
921 if ($externalpackage) {
922 if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
923 if ($tempdir = scorm_tempdir($scormdir)) {
924 copy ("$reference", $tempdir.'/'.basename($reference));
925 if (is_file($tempdir.'/'.basename($reference))) {
926 $validation = scorm_validate_manifest($tempdir.'/'.basename($reference));
933 $validation = scorm_validate_manifest($reference);
935 $validation->pkgtype
= 'SCORM';
944 if ($validation == null) {
945 if (is_dir($tempdir)) {
946 // Delete files and temporary directory
947 scorm_delete_files($tempdir);
950 if (($ext == '.xml') && (!$externalpackage)) {
951 $validation->datadir
= dirname($referencefield);
953 $validation->datadir
= substr($tempdir,strlen($scormdir));
955 $validation->launch
= 0;