Source for file importmanifest.php
Documentation is available at importmanifest.php
<?php /* <!-- Dokeos metadata/importmanifest.php -->
<!-- Copyright (C) 2006 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
==============================================================================
* Dokeos Metadata: create and manage table entries for SCORM package
* @package dokeos.metadata
==============================================================================
// PRELIMS -------------------------------------------------------------------->
$getpostvars = array('sdisub','workWith','sdi','smo'); require ('md_funcs.php');
define('EID_TYPE', 'Scorm'); define('TPLEN', strlen(EID_TYPE) + 1);
require ('md_' . strtolower(EID_TYPE) . '.php');
// name of the language file that needs to be included
include('../inc/global.inc.php');
if (!isset ($sdisub)) $sdisub = '';
// $sdisub is for split manifests - Scorm.NNN.$sdisub_xxx e.g. Scorm.3.1979_12
define('MFFNAME', 'imsmanifest'); define('MFFDEXT', '.xml');
define('HTF', 'mdp_scorm.htt');
'Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");
$is_allowed_to_edit = isset ($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
$baseWorkDir = get_course_path() . ($courseDir = $_course['path'] . '/scorm');
$mdStore = new mdstore($is_allowed_to_edit); // create table if needed
require (api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
require (api_get_path(LIBRARY_PATH) . 'xht.lib.php');
require (api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
require ('md_phpdig.php');
// SET CURRENT SCORM DIRECTORY - HEADER --------------------------------------->
if (isset ($workWith)) // explicit in URL, or selected at bottom of screen
if (isset ($sdi) && is_numeric($sdi) && $sdi > 0 && $sdi == (int) $sdi)
$mdObj = new mdobject($_course, $sdi); $workWith = $mdObj->mdo_path;
$hdrInfo = ' ' . get_lang('WorkOn') . ' ' .
unset ($sdi); $mdObj = new mdobject($_course, 0);
': ' . get_lang('NotInDB') . ')'; unset ($workWith);
define('UZYX', 'UZYX'); // magic word to repeat for all $sdisub
if (($sdiall = ($sdisub == UZYX)))
$sdisub = ''; $sdiall = array();
if (($dh = opendir($baseWorkDir . $workWith)))
while (FALSE !== ($file = readdir($dh)))
$originalHdrInfo = $hdrInfo;
global $baseWorkDir, $workWith, $sdisub, $mfContents, $xht_doc;
$fmff = $baseWorkDir . '/'. $workWith . '/' . MFFNAME . $sdisub . MFFDEXT;
if (($mfContents = @fgc($fmff)))
if (!$xht_doc->error) return ''; // keeping $mfContents and $xht_doc
if (isset ($workWith)) // now checked to be a valid path in scormdocument
if ($mdObj->mdo_filetype == 'folder') // a folder with a manifest?
$hdrInfo .= ' ' . get_lang('NotFolder'); unset ($sdi);
$mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
if (isset ($sdi)) $interbreadcrumb[]= array(
($sdiall ? '&sdisub='. UZYX : '')),
'name'=> get_lang('Continue') . ' ' . $sdi .
($sdisub ? ' (' . $sdisub . ')' : ($sdiall ? ' ('. UZYX. ')' : '')));
<link rel="stylesheet" type="text/css" href="md_styles.css">
<script type="text/javascript" src="md_script.js"></script>
// OPERATIONS ----------------------------------------------------------------->
if (isset ($smo)) echo '<h3>', $smo, '</h3>', "\n"; // selected manifest op
echo get_lang('MffOk'); $hdrInfo = $originalHdrInfo;
$filespec = $_FILES['import_file']['tmp_name'];
$htt_file = $baseWorkDir . '/'. $workWith . '/' . HTF;
@unlink($fhtf = $baseWorkDir . $workWith . '/' . HTF);
define('TREETOP', 'organizations/organization');
define('IDENTIF', 'identifier');
define('ITEMID', '@'. IDENTIF);
define('SUBIT', SUBITEM. '/'. ITEMID);
define('RESOURCE', 'resources/resource');
define('ISITEM', '@identifierref');
define('THUMB', FILE. '[1]/'. WEBF);
$resForItem = $xht_doc->xmd_select_elements_where(RESOURCE,
return (count($resForItem) == 0) ? - 1 : $resForItem[0];
$contextElem, $treeElem, $parentElem)
global $_user, $xht_doc, $mdStore, $mdObj, $sdisub;
// $contextElem -> @identifier, metadata/lom
// $treeElem -> title, items
$itemId = $xht_doc->xmd_value(ITEMID, $contextElem);
if ($sdisub && $level == 1 && $sdisub != $itemId) return;
// <item level=... number=... identifier=...>:
// <parent identifier=... /> <previous ... /> <next ... />
// <child identifier=... /> <child identifier=... /> ...
// <file href=... /> <file href=... /> ...
// <metadata>...</metadata>
$mddoc = new xmddoc('<item/>'); // version, name ?
$mddoc->xmd_set_attribute(0, 'level', $level, FALSE);
$mddoc->xmd_set_attribute(0, 'number', $counter, FALSE);
$mddoc->xmd_set_attribute(0, IDENTIF, $itemId, FALSE);
$mddoc->xmd_set_attribute(0, 'created', date('Y/m/d H:i:s'), FALSE);
$mddoc->xmd_set_attribute(0, 'by', $_user['user_id'], FALSE);
$mddoc->xmd_add_text_element(TITLE,
$xht_doc->xmd_value(TITLE, $treeElem));
if (($ppnId = $xht_doc->xmd_value(ITEMID, $parentElem))) $mddoc->
xmd_add_element('parent', 0, array(IDENTIF => $ppnId));
if (($ppnId = $xht_doc->xmd_value('-'. SUBIT, $treeElem))) $mddoc->
xmd_add_element('previous', 0, array(IDENTIF => $ppnId));
if (($ppnId = $xht_doc->xmd_value('+'. SUBIT, $treeElem))) $mddoc->
xmd_add_element('next', 0, array(IDENTIF => $ppnId));
// change stuff below to xmd_copy_foreign_child ?
$resElem = $mddoc->xmd_add_element('resource', 0,
array(HREF => $xht_doc->xmd_value(WEBF, $srcElem)));
foreach ($xht_doc->xmd_select_elements(FILE, $srcElem) as $fileElem)
$mddoc->xmd_add_element(FILE, $resElem,
array(HREF => $xht_doc->xmd_value(WEBF, $fileElem)));
$mddoc->xmd_copy_foreign_child($xht_doc,
$xht_doc->xmd_select_single_element('metadata', $contextElem));
foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem)
$mddoc->xmd_add_element('child', 0,
$mdt = $mddoc->xmd_xml();
$xhtDoc = $mdObj->mdo_define_htt();
$xhtDoc->xht_xmldoc = $mddoc; // $xhtDoc->xht_param['xxx'] = 'yyy';
$mdStore->mds_put($eid = EID_TYPE . '.' . $mfdocId . '.' . $itemId,
$mdStore->mds_put($eid, $ixt =
$xhtDoc->xht_fill_template('INDEXABLETEXT'), 'indexabletext');
if ($level == 0) // store a copy as 'Scorm.nnn'
$mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $mdt, 'mdxmltext', '?');
$mdStore->mds_put(EID_TYPE . '.' . $mfdocId, $ixt, 'indexabletext');
foreach ($xht_doc->xmd_select_elements(SUBITEM, $treeElem) as $subElem)
$subElem, $subElem, $contextElem);
// note: replacing this recursion by queue+loop makes it slower!
// 'if {}' and 'else {}' are string literals spanning several lines
// This PHP file has been generated by metadata/importmanifest.php
if (isset($_GET["th"]) && ($th = str_replace("..", "",
get_magic_quotes_gpc() ? stripslashes($_GET["th"]) : $_GET["th"])))
if (strtolower(substr($th, -4)) != ".jpg") exit; // other ext?
$thf = $_SERVER["PHP_SELF"];
if(!is_file($thf = $_SERVER["DOCUMENT_ROOT"] .
substr($thf, 0, strrpos($thf, "/")) . "/" . $th)) exit;
header("Content-disposition: filename=".basename($th));
header("Content-Type: image/jpeg");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+10)." GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time()+10)." GMT");
$fp = fopen($thf, "rb"); fpassthru($fp); fclose($fp);
str_replace('<scid>', $scid, // 2 * replace in $drs-line below
$drs = "<SYS_PATH-placeholder>"; $scormid = "<scid>";
require($drs. "main/metadata/playscormmdset.inc.php");
foreach ($sdiall as $sdisub)
echo '? ', $sdisub, ': ', $errmsg, '<br>';
$xht_doc->xmd_select_single_element(TREETOP), - 1);
else // just once, slurpmanifest() has already been done
$xht_doc->xmd_select_single_element(TREETOP), - 1);
$playIt = $baseWorkDir . '/'. $workWith . '/index.php';
$fileHandler = @fopen($playIt, 'w');
elseif ($smo == get_lang('Remove') && $sdisub)
$screm = EID_TYPE . '.' . $sdi . '.' . $sdisub;
$mdStore->mds_delete_offspring($screm, '\_'); // SQL LIKE underscore
elseif ($smo == get_lang('Remove')) // remove all, regardless of $sdiall
$mdStore->mds_delete($screm = EID_TYPE . '.' . $sdi);
$mdStore->mds_delete_offspring($screm);
'<b>' . get_lang('AllRemovedFor') . ' ' . $screm . '</b><br>';
ereg('^http://([^/]+)/(.+)/index\.php$', $mdObj->mdo_url, $regs))
$result = $mdStore->mds_get_many('eid,mdxmltext,indexabletext',
($sdisub ? "." . $sdisub . "\_%'" : ".%'") .
($sdiall ? "" : " AND NOT INSTR(eid,'_')")); // SQL LIKE underscore
// URL: index.php[?sid=xxx[&thumb=yyy]] (file[1]/@href: pptslnnn_t.jpg)
$th = ''; $indtxt = $row['indexabletext'];
if (($fh = strpos($rx = $row['mdxmltext'], 'file href="')) !== FALSE)
if (($cq = strpos($rx, '"', $fh += 11)) !== FALSE)
if (ereg('^pptsl[0-9]+_t\.jpg$', $thwf = substr($rx, $fh, $cq - $fh)))
if ($th == '' && ($sclvl = strpos($indtxt, 'scorm-level-')) !== FALSE)
$th = '&thumb=scorm-level-' . $indtxt{$sclvl + 12} . '.jpg';
$idt[($dotpos = strpos($ri = $row['eid'], '.', TPLEN)) !== FALSE ?
require ($phpDigIncCn); // switch to PhpDig DB
$regs[2] . '/', $sdisub ? 'index.php?sid=' . $sdisub . '_' : '')))
foreach ($idt as $url => $text)
// possible enhancement: UPDATE spider record for still existing pages
if(isset ($db)) mysql_select_db($_configuration['main_database'], $db); // back to Dokeos
echo 'Problem! PhpDig connect.php has gone or else URL "' .
'" is not like "http://xxxx/yyy.../zzz/index.php"';
// STATISTICS ----------------------------------------------------------------->
echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
$result = $mdStore->mds_get_many('eid', "eid LIKE '" . EID_TYPE . ".%'");
if (($dotpos = strpos($eid_id, '.')))
$eid_id = substr($eid_id, 0, $dotpos);
$mdtmain[$eid_id] = $mdStore->mds_get($eid);
$perId[$eid_id] = ($pi = $perId[$eid_id]) ? $pi + 1 : 1;
($perId[$sdi] ? $perId[$sdi] : '0'), ' ',
($mdtmain[$sdi] ? '- <span class="lbs" onClick="' .
"makeWindow('index.php?eid=" . EID_TYPE . '.' . $sdi . "', '', '')\">" .
get_lang('MainMD') . '</span>' : ''), "\n";
foreach ($perId as $id => $number)
if (!($pth = $mdo->mdo_path))
$pth = $mdtmain[$id]; // fetch something simple without parsing
if ($ttopen = strpos($pth, '<title>'))
if ($ttclose = strpos($pth, '</title>', $ttopen))
(substr($pth, $ttopen+ 7, $ttclose- $ttopen- 7));
else $pth = ' ' . substr($pth, $ttopen+ 7, 30);
else $pth = ' ' . substr($pth, 0, 30);
echo '<br><br><table>', "\n"; ksort($pathId); $wwl = strlen($workWith);
foreach ($pathId as $pth => $id) if ($wwl == 0 ||
($wwl < strlen($pth) && substr($pth, 0, $wwl) == $workWith))
'</td><td align="right">(SD-id ', $id,
'):</td><td align="right">', $perId[$id], '</td></tr>', "\n";
if (!$sdisub && ($dh = opendir($baseWorkDir . $workWith)))
while (FALSE !== ($file = readdir($dh)))
$result = $mdStore->mds_get_many('eid', "eid LIKE '" .
EID_TYPE . "." . $sdi . "." . $ns . "\_%'");
echo $ns, $nns ? '_ ' . $nns : '', '; ';
if (file_exists($baseWorkDir . $workWith . '/index.php'))
echo "<span class=\"lbs\" onClick=\"makeWindow('" .
$mdObj->mdo_url . "', '', '')\">" . get_lang('Play'), '</span>', "\n";
echo '<br>', $workWith, '/', HTF, ': ',
// SELECT & FOOTER ------------------------------------------------------------>
if ($mfContents || $xht_doc->error)
echo '<h3>', get_lang('UploadMff'), "</h3>\n\n",
($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='. UZYX : '')) .
'" enctype="multipart/form-data" method="post">', "\n",
'<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
'<input type="file" name="import_file" size="30">', "\n",
'<input type="submit" name="smo" value="', get_lang('UploadMff'),
(' + ' . get_lang('RemoveHtt')) : '', "</h3>\n\n",
($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='. UZYX : '')) .
'" enctype="multipart/form-data" method="post">', "\n",
'<input type="hidden" name="MAX_FILE_SIZE" value="32768">', "\n",
'<input type="file" name="import_file" size="30">', "\n",
'<input type="submit" name="smo" value="', get_lang('UploadHtt'), '">';
'<input type="submit" name="smo" value="', get_lang('RemoveHtt'), '">';
echo '<h3>', $nameTools, $hdrInfo, '</h3>', "\n";
if ($mfContents || $perId[$sdi]) // buttons for manifest operations
($sdisub ? '&sdisub=' . urlencode($sdisub) : ($sdiall ? '&sdisub='. UZYX : '')) .
'" method="post">', "\n";
'<input type="submit" name="smo" value="', get_lang('Import'), '">', "\n";
'<input type="submit" name="smo" value="', get_lang('Remove'), '">', "\n";
if ($mfContents && $perId[$sdi] && file_exists($phpDigIncCn)) echo
'<input type="submit" name="smo" value="', get_lang('Index'), '">', "\n";
echo '(', get_lang('NonePossible'), '...)';
echo '<tr><td align="right" class="alternativeBgDark">', "\n",
get_lang($label), ' :', "\n", $specifics, "\n",
'<input type="submit" value="', get_lang('Ok'), '" />', "\n",
'</form></td></tr>', "\n";
echo '<h3>', get_lang('OrElse'), '</h3>', "\n<table>\n";
$specifics = '<select name="workWith">' . "\n" .
'<option value="" style="color:#999999">' . get_lang('Root') . "</option>\n";
foreach ($dirList as $pathValue)
foreach ($someDirs as $pathValue => $mfExists) if ($mfExists)
while (($i = strrpos($pathValue, '/')))
$pathValue = substr($pathValue, 0, $i);
$someDirs[$pathValue] = TRUE;
foreach ($someDirs as $pathValue => $mfExists) if ($mfExists)
$pathValue = substr($pathValue, $bwdL);
$specifics .= '<option value="' . $pathValue . '"' .
($pathValue == $workWith ? ' selected' : '') . '>' .
basename($pathValue) . '</option>' . "\n";
'<input type="text" size="5" name="sdi" value="' .
'(<input type="text" size="4" name="sdisub" value="' .
|