2009-11-01 15:24:58 +00:00
|
|
|
<?php
|
2011-06-30 14:59:08 +12:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-26 18:19:05 +00:00
|
|
|
|
2006-09-26 08:00:16 +00:00
|
|
|
function scorm_add_time($a, $b) {
|
2011-06-30 14:59:08 +12:00
|
|
|
$aes = explode(':', $a);
|
|
|
|
$bes = explode(':', $b);
|
|
|
|
$aseconds = explode('.', $aes[2]);
|
|
|
|
$bseconds = explode('.', $bes[2]);
|
2006-09-26 08:00:16 +00:00
|
|
|
$change = 0;
|
|
|
|
|
|
|
|
$acents = 0; //Cents
|
|
|
|
if (count($aseconds) > 1) {
|
|
|
|
$acents = $aseconds[1];
|
|
|
|
}
|
|
|
|
$bcents = 0;
|
|
|
|
if (count($bseconds) > 1) {
|
|
|
|
$bcents = $bseconds[1];
|
|
|
|
}
|
|
|
|
$cents = $acents + $bcents;
|
|
|
|
$change = floor($cents / 100);
|
|
|
|
$cents = $cents - ($change * 100);
|
|
|
|
if (floor($cents) < 10) {
|
|
|
|
$cents = '0'. $cents;
|
|
|
|
}
|
|
|
|
|
|
|
|
$secs = $aseconds[0] + $bseconds[0] + $change; //Seconds
|
|
|
|
$change = floor($secs / 60);
|
|
|
|
$secs = $secs - ($change * 60);
|
|
|
|
if (floor($secs) < 10) {
|
|
|
|
$secs = '0'. $secs;
|
|
|
|
}
|
|
|
|
|
|
|
|
$mins = $aes[1] + $bes[1] + $change; //Minutes
|
|
|
|
$change = floor($mins / 60);
|
|
|
|
$mins = $mins - ($change * 60);
|
|
|
|
if ($mins < 10) {
|
|
|
|
$mins = '0' . $mins;
|
|
|
|
}
|
|
|
|
|
|
|
|
$hours = $aes[0] + $bes[0] + $change; //Hours
|
|
|
|
if ($hours < 10) {
|
|
|
|
$hours = '0' . $hours;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cents != '0') {
|
|
|
|
return $hours . ":" . $mins . ":" . $secs . '.' . $cents;
|
|
|
|
} else {
|
|
|
|
return $hours . ":" . $mins . ":" . $secs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-30 14:59:08 +12:00
|
|
|
* Take the header row of an AICC definition file
|
|
|
|
* and returns sequence of columns and a pointer to
|
|
|
|
* the sco identifier column.
|
|
|
|
*
|
|
|
|
* @param string $row AICC header row
|
|
|
|
* @param string $mastername AICC sco identifier column
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function scorm_get_aicc_columns($row, $mastername='system_id') {
|
|
|
|
$tok = strtok(strtolower($row), "\",\n\r");
|
2010-09-21 08:37:36 +00:00
|
|
|
$result = new stdClass();
|
2006-09-26 08:00:16 +00:00
|
|
|
$result->columns = array();
|
|
|
|
$i=0;
|
|
|
|
while ($tok) {
|
|
|
|
if ($tok !='') {
|
|
|
|
$result->columns[] = $tok;
|
|
|
|
if ($tok == $mastername) {
|
|
|
|
$result->mastercol = $i;
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$tok = strtok("\",\n\r");
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-30 14:59:08 +12:00
|
|
|
* Given a colums array return a string containing the regular
|
|
|
|
* expression to match the columns in a text row.
|
|
|
|
*
|
|
|
|
* @param array $column The header columns
|
|
|
|
* @param string $remodule The regular expression module for a single column
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function scorm_forge_cols_regexp($columns, $remodule='(".*")?,') {
|
2006-09-26 08:00:16 +00:00
|
|
|
$regexp = '/^';
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
$regexp .= $remodule;
|
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
$regexp = substr($regexp, 0, -1) . '/';
|
2006-09-26 08:00:16 +00:00
|
|
|
return $regexp;
|
|
|
|
}
|
|
|
|
|
2008-09-09 08:30:00 +00:00
|
|
|
|
|
|
|
function scorm_parse_aicc($scorm) {
|
2008-06-05 10:02:26 +00:00
|
|
|
global $DB;
|
|
|
|
|
2011-11-05 21:51:24 +13:00
|
|
|
if ($scorm->scormtype == SCORM_TYPE_AICCURL) {
|
|
|
|
return scorm_aicc_generate_simple_sco($scorm);
|
|
|
|
}
|
2008-09-09 08:30:00 +00:00
|
|
|
if (!isset($scorm->cmid)) {
|
|
|
|
$cm = get_coursemodule_from_instance('scorm', $scorm->id);
|
|
|
|
$scorm->cmid = $cm->id;
|
|
|
|
}
|
2012-07-24 16:56:57 +08:00
|
|
|
$context = context_module::instance($scorm->cmid);
|
2008-09-09 08:30:00 +00:00
|
|
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
|
2012-05-29 16:44:28 +12:00
|
|
|
$files = $fs->get_area_files($context->id, 'mod_scorm', 'content', 0, 'sortorder, itemid, filepath, filename', false);
|
2008-09-09 08:30:00 +00:00
|
|
|
|
2006-09-26 08:00:16 +00:00
|
|
|
$version = 'AICC';
|
|
|
|
$ids = array();
|
|
|
|
$courses = array();
|
2011-06-30 14:59:08 +12:00
|
|
|
$extaiccfiles = array('crs', 'des', 'au', 'cst', 'ort', 'pre', 'cmp');
|
2008-09-09 08:30:00 +00:00
|
|
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$filename = $file->get_filename();
|
2011-06-30 14:59:08 +12:00
|
|
|
$ext = substr($filename, strrpos($filename, '.'));
|
|
|
|
$extension = strtolower(substr($ext, 1));
|
|
|
|
if (in_array($extension, $extaiccfiles)) {
|
|
|
|
$id = strtolower(basename($filename, $ext));
|
2013-06-15 08:52:50 +02:00
|
|
|
if (!isset($ids[$id])) {
|
|
|
|
$ids[$id] = new stdClass();
|
|
|
|
}
|
2008-09-09 08:30:00 +00:00
|
|
|
$ids[$id]->$extension = $file;
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-09 08:30:00 +00:00
|
|
|
|
2006-09-26 08:00:16 +00:00
|
|
|
foreach ($ids as $courseid => $id) {
|
2013-06-15 08:52:50 +02:00
|
|
|
if (!isset($courses[$courseid])) {
|
|
|
|
$courses[$courseid] = new stdClass();
|
|
|
|
}
|
2006-09-26 08:00:16 +00:00
|
|
|
if (isset($id->crs)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->crs->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
|
|
|
if (is_array($rows)) {
|
|
|
|
foreach ($rows as $row) {
|
2011-06-30 14:59:08 +12:00
|
|
|
if (preg_match("/^(.+)=(.+)$/", $row, $matches)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
switch (strtolower(trim($matches[1]))) {
|
|
|
|
case 'course_id':
|
|
|
|
$courses[$courseid]->id = trim($matches[2]);
|
|
|
|
break;
|
|
|
|
case 'course_title':
|
|
|
|
$courses[$courseid]->title = trim($matches[2]);
|
|
|
|
break;
|
|
|
|
case 'version':
|
|
|
|
$courses[$courseid]->version = 'AICC_'.trim($matches[2]);
|
|
|
|
break;
|
|
|
|
}
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($id->des)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->des->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2006-09-26 08:00:16 +00:00
|
|
|
$columns = scorm_get_aicc_columns($rows[0]);
|
|
|
|
$regexp = scorm_forge_cols_regexp($columns->columns);
|
2011-06-30 14:59:08 +12:00
|
|
|
for ($i=1; $i<count($rows); $i++) {
|
|
|
|
if (preg_match($regexp, $rows[$i], $matches)) {
|
|
|
|
for ($j=0; $j<count($columns->columns); $j++) {
|
2006-09-26 08:00:16 +00:00
|
|
|
$column = $columns->columns[$j];
|
2013-06-15 08:52:50 +02:00
|
|
|
if (!isset($courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]), 1 , -1)])) {
|
|
|
|
$courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]), 1 , -1)] = new stdClass();
|
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
$courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]), 1 , -1)]->$column = substr(trim($matches[$j+1]), 1, -1);
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($id->au)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->au->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2006-09-26 08:00:16 +00:00
|
|
|
$columns = scorm_get_aicc_columns($rows[0]);
|
|
|
|
$regexp = scorm_forge_cols_regexp($columns->columns);
|
2011-06-30 14:59:08 +12:00
|
|
|
for ($i=1; $i<count($rows); $i++) {
|
|
|
|
if (preg_match($regexp, $rows[$i], $matches)) {
|
|
|
|
for ($j=0; $j<count($columns->columns); $j++) {
|
2006-09-26 08:00:16 +00:00
|
|
|
$column = $columns->columns[$j];
|
2011-06-30 14:59:08 +12:00
|
|
|
$courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]), 1, -1)]->$column = substr(trim($matches[$j+1]), 1, -1);
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($id->cst)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->cst->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2011-06-30 14:59:08 +12:00
|
|
|
$columns = scorm_get_aicc_columns($rows[0], 'block');
|
|
|
|
$regexp = scorm_forge_cols_regexp($columns->columns, '(.+)?,');
|
|
|
|
for ($i=1; $i<count($rows); $i++) {
|
|
|
|
if (preg_match($regexp, $rows[$i], $matches)) {
|
|
|
|
for ($j=0; $j<count($columns->columns); $j++) {
|
2006-09-26 08:00:16 +00:00
|
|
|
if ($j != $columns->mastercol) {
|
2012-05-22 00:47:01 +02:00
|
|
|
$element = substr(trim($matches[$j+1]), 1 , -1);
|
|
|
|
if (!empty($element)) {
|
|
|
|
$courses[$courseid]->elements[$element]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
|
|
|
|
}
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($id->ort)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->ort->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2011-06-30 14:59:08 +12:00
|
|
|
$columns = scorm_get_aicc_columns($rows[0], 'course_element');
|
|
|
|
$regexp = scorm_forge_cols_regexp($columns->columns, '(.+)?,');
|
|
|
|
for ($i=1; $i<count($rows); $i++) {
|
|
|
|
if (preg_match($regexp, $rows[$i], $matches)) {
|
|
|
|
for ($j=0; $j<count($matches)-1; $j++) {
|
2007-11-14 09:52:16 +00:00
|
|
|
if ($j != $columns->mastercol) {
|
2011-06-30 14:59:08 +12:00
|
|
|
$courses[$courseid]->elements[substr(trim($matches[$j+1]), 1, -1)]->parent = substr(trim($matches[$columns->mastercol+1]), 1, -1);
|
2007-11-14 09:52:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
if (isset($id->pre)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->pre->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2011-06-30 14:59:08 +12:00
|
|
|
$columns = scorm_get_aicc_columns($rows[0], 'structure_element');
|
|
|
|
$regexp = scorm_forge_cols_regexp($columns->columns, '(.+),');
|
|
|
|
for ($i=1; $i<count($rows); $i++) {
|
|
|
|
if (preg_match($regexp, $rows[$i], $matches)) {
|
|
|
|
$courses[$courseid]->elements[$columns->mastercol+1]->prerequisites = substr(trim($matches[1-$columns->mastercol+1]), 1, -1);
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($id->cmp)) {
|
2009-02-26 18:19:05 +00:00
|
|
|
$contents = $id->cmp->get_content();
|
|
|
|
$rows = explode("\r\n", $contents);
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 08:30:00 +00:00
|
|
|
$oldscoes = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id));
|
2013-08-27 12:55:10 +12:00
|
|
|
$sortorder = 0;
|
2006-09-26 08:00:16 +00:00
|
|
|
$launch = 0;
|
|
|
|
if (isset($courses)) {
|
|
|
|
foreach ($courses as $course) {
|
2013-08-27 12:55:10 +12:00
|
|
|
$sortorder++;
|
2010-09-21 08:37:36 +00:00
|
|
|
$sco = new stdClass();
|
2006-09-26 08:00:16 +00:00
|
|
|
$sco->identifier = $course->id;
|
2008-09-09 08:30:00 +00:00
|
|
|
$sco->scorm = $scorm->id;
|
2006-09-26 08:00:16 +00:00
|
|
|
$sco->organization = '';
|
|
|
|
$sco->title = $course->title;
|
|
|
|
$sco->parent = '/';
|
|
|
|
$sco->launch = '';
|
|
|
|
$sco->scormtype = '';
|
2013-08-27 12:55:10 +12:00
|
|
|
$sco->sortorder = $sortorder;
|
2006-09-26 08:00:16 +00:00
|
|
|
|
2011-06-30 14:59:08 +12:00
|
|
|
if ($ss = $DB->get_record('scorm_scoes', array('scorm'=>$scorm->id,
|
|
|
|
'identifier'=>$sco->identifier))) {
|
2008-06-05 10:02:26 +00:00
|
|
|
$id = $ss->id;
|
2011-11-11 20:02:19 +13:00
|
|
|
$sco->id = $id;
|
2013-08-27 12:55:10 +12:00
|
|
|
$DB->update_record('scorm_scoes', $sco);
|
2006-09-26 08:00:16 +00:00
|
|
|
unset($oldscoes[$id]);
|
|
|
|
} else {
|
2011-06-30 14:59:08 +12:00
|
|
|
$id = $DB->insert_record('scorm_scoes', $sco);
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($launch == 0) {
|
|
|
|
$launch = $id;
|
|
|
|
}
|
|
|
|
if (isset($course->elements)) {
|
2011-06-30 14:59:08 +12:00
|
|
|
foreach ($course->elements as $element) {
|
2006-09-26 08:00:16 +00:00
|
|
|
unset($sco);
|
2013-06-15 08:52:50 +02:00
|
|
|
$sco = new stdClass();
|
2006-09-26 08:00:16 +00:00
|
|
|
$sco->identifier = $element->system_id;
|
2008-09-09 08:30:00 +00:00
|
|
|
$sco->scorm = $scorm->id;
|
2006-09-26 08:00:16 +00:00
|
|
|
$sco->organization = $course->id;
|
|
|
|
$sco->title = $element->title;
|
2008-12-22 07:03:09 +00:00
|
|
|
|
2013-01-11 21:57:32 +13:00
|
|
|
if (!isset($element->parent)) {
|
2006-09-26 08:00:16 +00:00
|
|
|
$sco->parent = '/';
|
2013-01-11 21:57:32 +13:00
|
|
|
} else if (strtolower($element->parent) == 'root') {
|
|
|
|
$sco->parent = $course->id;
|
2006-09-26 08:00:16 +00:00
|
|
|
} else {
|
|
|
|
$sco->parent = $element->parent;
|
|
|
|
}
|
2012-05-22 00:47:01 +02:00
|
|
|
$sco->launch = '';
|
|
|
|
$sco->scormtype = '';
|
|
|
|
$sco->previous = 0;
|
|
|
|
$sco->next = 0;
|
|
|
|
$id = null;
|
|
|
|
// Is it an Assignable Unit (AU)?
|
2006-09-26 08:00:16 +00:00
|
|
|
if (isset($element->file_name)) {
|
|
|
|
$sco->launch = $element->file_name;
|
|
|
|
$sco->scormtype = 'sco';
|
2012-05-22 00:47:01 +02:00
|
|
|
}
|
|
|
|
if ($oldscoid = scorm_array_search('identifier', $sco->identifier, $oldscoes)) {
|
|
|
|
$sco->id = $oldscoid;
|
|
|
|
$DB->update_record('scorm_scoes', $sco);
|
|
|
|
$id = $oldscoid;
|
|
|
|
$DB->delete_records('scorm_scoes_data', array('scoid'=>$oldscoid));
|
|
|
|
unset($oldscoes[$oldscoid]);
|
|
|
|
} else {
|
|
|
|
$id = $DB->insert_record('scorm_scoes', $sco);
|
|
|
|
}
|
|
|
|
if (!empty($id)) {
|
|
|
|
$scodata = new stdClass();
|
|
|
|
$scodata->scoid = $id;
|
|
|
|
if (isset($element->web_launch)) {
|
|
|
|
$scodata->name = 'parameters';
|
|
|
|
$scodata->value = $element->web_launch;
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
2007-11-14 09:52:16 +00:00
|
|
|
}
|
2012-05-22 00:47:01 +02:00
|
|
|
if (isset($element->prerequisites)) {
|
|
|
|
$scodata->name = 'prerequisites';
|
|
|
|
$scodata->value = $element->prerequisites;
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
|
|
|
}
|
|
|
|
if (isset($element->max_time_allowed)) {
|
|
|
|
$scodata->name = 'max_time_allowed';
|
|
|
|
$scodata->value = $element->max_time_allowed;
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
2007-11-14 09:52:16 +00:00
|
|
|
}
|
2012-05-22 00:47:01 +02:00
|
|
|
if (isset($element->time_limit_action)) {
|
|
|
|
$scodata->name = 'time_limit_action';
|
|
|
|
$scodata->value = $element->time_limit_action;
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
2007-11-14 09:52:16 +00:00
|
|
|
}
|
2012-05-22 00:47:01 +02:00
|
|
|
if (isset($element->mastery_score)) {
|
|
|
|
$scodata->name = 'mastery_score';
|
|
|
|
$scodata->value = $element->mastery_score;
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
|
|
|
}
|
|
|
|
if (isset($element->core_vendor)) {
|
|
|
|
$scodata->name = 'datafromlms';
|
|
|
|
$scodata->value = preg_replace('/<cr>/i', "\r\n", $element->core_vendor);
|
|
|
|
$dataid = $DB->insert_record('scorm_scoes_data', $scodata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($launch==0) {
|
|
|
|
$launch = $id;
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($oldscoes)) {
|
2011-06-30 14:59:08 +12:00
|
|
|
foreach ($oldscoes as $oldsco) {
|
2008-06-05 10:02:26 +00:00
|
|
|
$DB->delete_records('scorm_scoes', array('id'=>$oldsco->id));
|
|
|
|
$DB->delete_records('scorm_scoes_track', array('scoid'=>$oldsco->id));
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-09 08:30:00 +00:00
|
|
|
|
|
|
|
$scorm->version = 'AICC';
|
|
|
|
|
|
|
|
$scorm->launch = $launch;
|
|
|
|
|
|
|
|
return true;
|
2006-09-26 08:00:16 +00:00
|
|
|
}
|
2011-11-05 15:21:19 +13:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a scormid creates an AICC Session record to allow HACP
|
|
|
|
*
|
|
|
|
* @param int $scormid - id from scorm table
|
|
|
|
* @return string hacpsession
|
|
|
|
*/
|
|
|
|
function scorm_aicc_get_hacp_session($scormid) {
|
|
|
|
global $USER, $DB, $SESSION;
|
|
|
|
$cfg_scorm = get_config('scorm');
|
|
|
|
if (empty($cfg_scorm->allowaicchacp)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$now = time();
|
|
|
|
|
|
|
|
$hacpsession = $SESSION->scorm;
|
|
|
|
$hacpsession->scormid = $scormid;
|
2011-11-07 14:34:13 +13:00
|
|
|
$hacpsession->hacpsession = random_string(20);
|
2011-11-05 15:21:19 +13:00
|
|
|
$hacpsession->userid = $USER->id;
|
|
|
|
$hacpsession->timecreated = $now;
|
|
|
|
$hacpsession->timemodified = $now;
|
|
|
|
$DB->insert_record('scorm_aicc_session', $hacpsession);
|
|
|
|
|
|
|
|
return $hacpsession->hacpsession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the hacp_session for whether it is valid.
|
|
|
|
*
|
|
|
|
* @param string $hacpsession The hacpsession value to check (optional). Normally leave this blank
|
|
|
|
* and this function will do required_param('sesskey', ...).
|
|
|
|
* @return mixed - false if invalid, otherwise returns record from scorm_aicc_session table.
|
|
|
|
*/
|
|
|
|
function scorm_aicc_confirm_hacp_session($hacpsession) {
|
|
|
|
global $DB;
|
|
|
|
$cfg_scorm = get_config('scorm');
|
|
|
|
if (empty($cfg_scorm->allowaicchacp)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$time = time()-($cfg_scorm->aicchacptimeout * 60);
|
|
|
|
$sql = "hacpsession = ? AND timemodified > ?";
|
|
|
|
$hacpsession = $DB->get_record_select('scorm_aicc_session', $sql, array($hacpsession, $time));
|
|
|
|
if (!empty($hacpsession)) { //update timemodified as this is still an active session - resets the timeout.
|
|
|
|
$hacpsession->timemodified = time();
|
|
|
|
$DB->update_record('scorm_aicc_session', $hacpsession);
|
|
|
|
}
|
|
|
|
return $hacpsession;
|
2011-11-05 21:51:24 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generate a simple single activity AICC object
|
|
|
|
* structure to wrap around and externally linked
|
|
|
|
* AICC package URL
|
|
|
|
*
|
|
|
|
* @param object $scorm package record
|
|
|
|
*/
|
|
|
|
function scorm_aicc_generate_simple_sco($scorm) {
|
|
|
|
global $DB;
|
2013-08-27 12:55:10 +12:00
|
|
|
// Find the oldest one.
|
|
|
|
$scos = $DB->get_records('scorm_scoes', array('scorm' => $scorm->id), 'id');
|
2011-11-05 21:51:24 +13:00
|
|
|
if (!empty($scos)) {
|
|
|
|
$sco = array_shift($scos);
|
|
|
|
} else {
|
2013-08-27 12:55:10 +12:00
|
|
|
$sco = new stdClass();
|
2011-11-05 21:51:24 +13:00
|
|
|
}
|
2013-08-27 12:55:10 +12:00
|
|
|
// Get rid of old ones.
|
|
|
|
foreach ($scos as $oldsco) {
|
|
|
|
$DB->delete_records('scorm_scoes', array('id' => $oldsco->id));
|
|
|
|
$DB->delete_records('scorm_scoes_track', array('scoid' => $oldsco->id));
|
2011-11-05 21:51:24 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
$sco->identifier = 'A1';
|
|
|
|
$sco->scorm = $scorm->id;
|
|
|
|
$sco->organization = '';
|
|
|
|
$sco->title = $scorm->name;
|
|
|
|
$sco->parent = '/';
|
2013-08-27 12:55:10 +12:00
|
|
|
// Add the HACP signal to the activity launcher.
|
2011-11-05 21:51:24 +13:00
|
|
|
if (preg_match('/\?/', $scorm->reference)) {
|
|
|
|
$sco->launch = $scorm->reference.'&CMI=HACP';
|
2013-08-27 12:55:10 +12:00
|
|
|
} else {
|
2011-11-05 21:51:24 +13:00
|
|
|
$sco->launch = $scorm->reference.'?CMI=HACP';
|
|
|
|
}
|
|
|
|
$sco->scormtype = 'sco';
|
|
|
|
if (isset($sco->id)) {
|
|
|
|
$DB->update_record('scorm_scoes', $sco);
|
|
|
|
$id = $sco->id;
|
|
|
|
} else {
|
|
|
|
$id = $DB->insert_record('scorm_scoes', $sco);
|
|
|
|
}
|
|
|
|
return $id;
|
2011-11-05 15:21:19 +13:00
|
|
|
}
|