/** * 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; require_once $CFG->dirroot . '/mod/scorm/locallib.php'; $scorm->parse = 0; if (($packagedata = scorm_check_package($scorm)) != null) { $scorm->pkgtype = $packagedata->pkgtype; if ($packagedata->launch == 0) { $scorm->launch = $packagedata->launch; $scorm->datadir = $packagedata->datadir; $scorm->parse = 1; if (!scorm_external_link($scorm->reference) && $scorm->reference[0] != '#') { //dont set md5hash if this is from a repo. $scorm->md5hash = md5_file($CFG->dataroot . '/' . $scorm->course . '/' . $scorm->reference); } elseif ($scorm->reference[0] != '#') { //dont set md5hash if this is from a repo. $scorm->dir = $CFG->dataroot . '/' . $scorm->course . '/moddata/scorm'; $scorm->md5hash = md5_file($scorm->dir . $scorm->datadir . '/' . basename($scorm->reference)); } } } $scorm->timemodified = time(); $scorm->id = $scorm->instance; if (empty($scorm->options)) { $scorm = scorm_option2text($scorm); } $scorm->width = str_replace('%', '', $scorm->width); $scorm->height = str_replace('%', '', $scorm->height); if (!isset($scorm->whatgrade)) { $scorm->whatgrade = 0; } // Check if scorm manifest needs to be reparsed if ($scorm->parse == 1) { $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 && (scorm_external_link($scorm->reference) || basename($scorm->reference) != 'imsmanifest.xml' && $scorm->reference[0] != '#')) { rename($scorm->dir . $scorm->datadir, $scorm->dir . '/' . $scorm->id); } $scorm->launch = scorm_parse($scorm); } else { $oldscorm = get_record('scorm', 'id', $scorm->id); $scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question } if ($result = update_record('scorm', $scorm)) { scorm_grade_item_update(stripslashes_recursive($scorm)); //scorm_grade_item_update($scorm); // John Macklins fix - dont think this is needed } return $result; }
/** * 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; require_once 'locallib.php'; if (($packagedata = scorm_check_package($scorm)) != null) { $scorm->pkgtype = $packagedata->pkgtype; if ($packagedata->launch == 0) { $scorm->launch = $packagedata->launch; $scorm->datadir = $packagedata->datadir; $scorm->parse = 1; if (!scorm_external_link($scorm->reference)) { $scorm->md5hash = md5_file($CFG->dataroot . '/' . $scorm->course . '/' . $scorm->reference); } else { $scorm->dir = $CFG->dataroot . '/' . $scorm->course . '/moddata/scorm'; $scorm->md5hash = md5_file($scorm->dir . $scorm->datadir . '/' . basename($scorm->reference)); } } else { $scorm->parse = 0; } } $scorm->timemodified = time(); $scorm->id = $scorm->instance; $scorm = scorm_option2text($scorm); $scorm->width = str_replace('%', '', $scorm->width); $scorm->height = str_replace('%', '', $scorm->height); if (!isset($scorm->whatgrade)) { $scorm->whatgrade = 0; } $scorm->grademethod = $scorm->whatgrade * 10 + $scorm->grademethod; // Check if scorm manifest needs to be reparsed if ($scorm->parse == 1) { $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 && (scorm_external_link($scorm->reference) || basename($scorm->reference) != 'imsmanifest.xml' && $scorm->reference[0] != '#')) { rename($scorm->dir . $scorm->datadir, $scorm->dir . '/' . $scorm->id); } $scorm->launch = scorm_parse($scorm); } else { $oldscorm = get_record('scorm', 'id', $scorm->id); $scorm->reference = $oldscorm->reference; // This fix a problem with Firefox when the teacher choose Cancel on overwrite question } return update_record('scorm', $scorm); }