📄 aicclib.php
字号:
<?php // $Id: aicclib.php,v 1.5.2.9 2008/12/22 07:04:37 danmarsden Exp $function scorm_add_time($a, $b) { $aes = explode(':',$a); $bes = explode(':',$b); $aseconds = explode('.',$aes[2]); $bseconds = explode('.',$bes[2]); $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; }}/*** 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"); $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;}/*** 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='(".*")?,') { $regexp = '/^'; foreach ($columns as $column) { $regexp .= $remodule; } $regexp = substr($regexp,0,-1) . '/'; return $regexp;}function scorm_parse_aicc($pkgdir,$scormid) { $version = 'AICC'; $ids = array(); $courses = array(); $extaiccfiles = array('crs','des','au','cst','ort','pre','cmp'); if ($handle = opendir($pkgdir)) { while (($file = readdir($handle)) !== false) { if ($file[0] != '.') { $ext = substr($file,strrpos($file,'.')); $extension = strtolower(substr($ext,1)); if (in_array($extension,$extaiccfiles)) { $id = strtolower(basename($file,$ext)); $ids[$id]->$extension = $file; } } } closedir($handle); } foreach ($ids as $courseid => $id) { if (isset($id->crs)) { if (is_file($pkgdir.'/'.$id->crs)) { $rows = file($pkgdir.'/'.$id->crs); foreach ($rows as $row) { if (preg_match("/^(.+)=(.+)$/",$row,$matches)) { 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; } } } } } if (isset($id->des)) { $rows = file($pkgdir.'/'.$id->des); $columns = scorm_get_aicc_columns($rows[0]); $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++) { $column = $columns->columns[$j]; $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); } } } } if (isset($id->au)) { $rows = file($pkgdir.'/'.$id->au); $columns = scorm_get_aicc_columns($rows[0]); $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++) { $column = $columns->columns[$j]; $courses[$courseid]->elements[substr(trim($matches[$columns->mastercol+1]),1,-1)]->$column = substr(trim($matches[$j+1]),1,-1); } } } } if (isset($id->cst)) { $rows = file($pkgdir.'/'.$id->cst); $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++) { if ($j != $columns->mastercol) { $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1); } } } } } if (isset($id->ort)) { $rows = file($pkgdir.'/'.$id->ort); $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++) { if ($j != $columns->mastercol) { $courses[$courseid]->elements[substr(trim($matches[$j+1]),1,-1)]->parent = substr(trim($matches[$columns->mastercol+1]),1,-1); } } } } } if (isset($id->pre)) { $rows = file($pkgdir.'/'.$id->pre); $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); } } } if (isset($id->cmp)) { $rows = file($pkgdir.'/'.$id->cmp); } } //print_r($courses); $oldscoes = get_records('scorm_scoes','scorm',$scormid); $launch = 0; if (isset($courses)) { foreach ($courses as $course) { $sco = new object(); $sco->identifier = $course->id; $sco->scorm = $scormid; $sco->organization = ''; $sco->title = $course->title; $sco->parent = '/'; $sco->launch = ''; $sco->scormtype = ''; //print_r($sco); if (get_record('scorm_scoes','scorm',$scormid,'identifier',$sco->identifier)) { $id = update_record('scorm_scoes',$sco); unset($oldscoes[$id]); } else { $id = insert_record('scorm_scoes',$sco); } if ($launch == 0) { $launch = $id; } if (isset($course->elements)) { foreach($course->elements as $element) { unset($sco); $sco->identifier = $element->system_id; $sco->scorm = $scormid; $sco->organization = $course->id; $sco->title = $element->title; if (!isset($element->parent) || strtolower($element->parent) == 'root') { $sco->parent = '/'; } else { $sco->parent = $element->parent; } if (isset($element->file_name)) { $sco->launch = $element->file_name; $sco->scormtype = 'sco'; $sco->previous = 0; $sco->next = 0; $id = null; if ($oldscoid = scorm_array_search('identifier',$sco->identifier,$oldscoes)) { $sco->id = $oldscoid; $id = update_record('scorm_scoes',$sco); delete_records('scorm_scoes_data','scoid',$oldscoid); unset($oldscoes[$oldscoid]); } else { $id = insert_record('scorm_scoes',$sco); } if (!empty($id)) { unset($scodata); $scodata->scoid = $id; if (isset($element->web_launch)) { $scodata->name = 'parameters'; $scodata->value = $element->web_launch; $dataid = insert_record('scorm_scoes_data',$scodata); } if (isset($element->prerequisites)) { $scodata->name = 'prerequisites'; $scodata->value = $element->prerequisites; $dataid = insert_record('scorm_scoes_data',$scodata); } if (isset($element->max_time_allowed)) { $scodata->name = 'max_time_allowed'; $scodata->value = $element->max_time_allowed; $dataid = insert_record('scorm_scoes_data',$scodata);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -