datadir)) { //check to make sure scorm object is valid BEFORE entering it in the database.
error(get_string('nomanifest', 'scorm'));
} else {
global $CFG;
$scorm->timemodified = time();
$scorm = scorm_option2text($scorm);
$scorm->width = str_replace('%','',$scorm->width);
$scorm->height = str_replace('%','',$scorm->height);
//sanitize submitted values a bit
$scorm->width = clean_param($scorm->width, PARAM_INT);
$scorm->height = clean_param($scorm->height, PARAM_INT);
$id = insert_record('scorm', $scorm);
if ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
// Rename temp scorm dir to scorm id
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
}
// Parse scorm manifest
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->id = $id;
$scorm->launch = scorm_parse($scorm);
set_field('scorm','launch',$scorm->launch,'id',$scorm->id);
}
return $id;
}
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will update an existing instance with new data.
*
* @param mixed $scorm Form data
* @return int
*/
function scorm_update_instance($scorm) {
global $CFG;
$scorm->timemodified = time();
$scorm->id = $scorm->instance;
$scorm = scorm_option2text($scorm);
$scorm->width = str_replace('%','',$scorm->width);
$scorm->height = str_replace('%','',$scorm->height);
// Check if scorm manifest needs to be reparsed
if ($scorm->parse == 1) {
require_once('locallib.php');
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
if (is_dir($scorm->dir.'/'.$scorm->id)) {
scorm_delete_files($scorm->dir.'/'.$scorm->id);
}
if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) &&
(basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) {
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
}
/* delete_records('scorm_sequencing_controlmode','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprules','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprule','scormid',$scorm->id);
delete_records('scorm_sequencing_rollupruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rolluprulecondition','scormid',$scorm->id);
delete_records('scorm_sequencing_ruleconditions','scormid',$scorm->id);
delete_records('scorm_sequencing_rulecondition','scormid',$scorm->id);
*/
$scorm->launch = scorm_parse($scorm);
}
return update_record('scorm', $scorm);
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id Scorm instance id
* @return boolean
*/
function scorm_delete_instance($id) {
global $CFG;
if (! $scorm = get_record('scorm', 'id', $id)) {
return false;
}
$result = true;
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
if (is_dir($scorm->dir.'/'.$scorm->id)) {
// Delete any dependent files
require_once('locallib.php');
scorm_delete_files($scorm->dir.'/'.$scorm->id);
}
// Delete any dependent records
if (! delete_records('scorm_scoes_track', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_scoes', 'scorm', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm', 'id', $scorm->id)) {
$result = false;
}
/*if (! delete_records('scorm_sequencing_controlmode', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_rolluprules', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_rolluprule', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_rollupruleconditions', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_rolluprulecondition', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_rulecondition', 'scormid', $scorm->id)) {
$result = false;
}
if (! delete_records('scorm_sequencing_ruleconditions', 'scormid', $scorm->id)) {
$result = false;
}*/
return $result;
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
*
* @param int $course Course id
* @param int $user User id
* @param int $mod
* @param int $scorm The scorm id
* @return mixed
*/
function scorm_user_outline($course, $user, $mod, $scorm) {
$return = NULL;
$scores->values = 0;
$scores->sum = 0;
$scores->max = 0;
$scores->lastmodify = 0;
$scores->count = 0;
if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' ORDER BY id")) {
require_once('locallib.php');
foreach ($scoes as $sco) {
if ($sco->launch!='') {
$scores->count++;
if ($userdata = scorm_get_tracks($sco->id, $user->id)) {
if (!isset($scores->{$userdata->status})) {
$scores->{$userdata->status} = 1;
} else {
$scores->{$userdata->status}++;
}
if (!empty($userdata->score_raw)) {
$scores->values++;
$scores->sum += $userdata->score_raw;
$scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
}
if (isset($userdata->timemodified) && ($userdata->timemodified > $scores->lastmodify)) {
$scores->lastmodify = $userdata->timemodified;
}
}
}
}
switch ($scorm->grademethod) {
case GRADEHIGHEST:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').': '.$scores->max;
$return->time = $scores->lastmodify;
}
break;
case GRADEAVERAGE:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').': '.$scores->sum/$scores->values;
$return->time = $scores->lastmodify;
}
break;
case GRADESUM:
if ($scores->values > 0) {
$return->info = get_string('score','scorm').': '.$scores->sum;
$return->time = $scores->lastmodify;
}
break;
case GRADESCOES:
$return->info = '';
$scores->notattempted = $scores->count;
if (isset($scores->completed)) {
$return->info .= get_string('completed','scorm').': '.$scores->completed.'
';
$scores->notattempted -= $scores->completed;
}
if (isset($scores->passed)) {
$return->info .= get_string('passed','scorm').': '.$scores->passed.'
';
$scores->notattempted -= $scores->passed;
}
if (isset($scores->failed)) {
$return->info .= get_string('failed','scorm').': '.$scores->failed.'
';
$scores->notattempted -= $scores->failed;
}
if (isset($scores->incomplete)) {
$return->info .= get_string('incomplete','scorm').': '.$scores->incomplete.'
';
$scores->notattempted -= $scores->incomplete;
}
if (isset($scores->browsed)) {
$return->info .= get_string('browsed','scorm').': '.$scores->browsed.'
';
$scores->notattempted -= $scores->browsed;
}
$return->time = $scores->lastmodify;
if ($return->info == '') {
$return = NULL;
} else {
$return->info .= get_string('notattempted','scorm').': '.$scores->notattempted.'
';
}
break;
}
}
return $return;
}
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
* @param int $course Course id
* @param int $user User id
* @param int $mod
* @param int $scorm The scorm id
* @return boolean
*/
function scorm_user_complete($course, $user, $mod, $scorm) {
global $CFG;
$liststyle = 'structlist';
$scormpixdir = $CFG->modpixpath.'/scorm/pix';
$now = time();
$firstmodify = $now;
$lastmodify = 0;
$sometoreport = false;
$report = '';
if ($orgs = get_records_select('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,identifier,title')) {
if (count($orgs) <= 1) {
unset($orgs);
$orgs[]->identifier = '';
}
$report .= '