dokeos-metadata
[ class tree: dokeos-metadata ] [ index: dokeos-metadata ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php /*                                      <!-- Dokeos metadata/index.php -->
  2.                                                              <!-- 2005/05/19 -->
  3.  
  4. <!-- Copyright (C) 2005 rene.haentjens@UGent.be -  see metadata/md_funcs.php -->
  5.     
  6. */
  7.  
  8. /**
  9. ============================================================================== 
  10. *    Dokeos Metadata: view/edit metadata of a Dokeos course object
  11. *
  12. *   URL parameters:
  13. *   - eid=  entry-id = object-id = type.identifier, e.g. 'Document.12';
  14. *   - lfn=  filename of a language file, default= 'md_' + type, e.g. 'md_doc';
  15. *   - htt=  HTML template file (same dir as script), default= same as lfn;
  16. *   - dbg=  debuginfo start number, e.g. 10000
  17. *
  18. *    @package dokeos.metadata
  19. ============================================================================== 
  20. */
  21.  
  22.  
  23. // PRELIMS -------------------------------------------------------------------->
  24.  
  25. require("md_funcs.php");
  26.  
  27. getpar('EID''Entry IDentifier');           // e.g. 'Document.12' or 'Scorm.xx'
  28. if (!($dotpos strpos(EID'.'))) give_up('No . in ' EID);
  29.  
  30. define('EID_TYPE'substr(EID0$dotpos))// e.g. 'Document' or 'Scorm'
  31. require('md_' strtolower(EID_TYPE'.php');
  32.  
  33. define('EID_ID'substr(EID$dotpos 1));  // e.g. '12'
  34.  
  35. getpar('LFN''LanguageFileName''md_' strtolower(EID_TYPE));
  36. getpar('HTT''HTML Template Text filename'LFN);
  37.  
  38. getpar('DBG''Debug number''0');
  39.  
  40. $urlp =                                              '?eid=' urlencode(EID);
  41. if (LFN != 'md_' strtolower(EID_TYPE))    $urlp .= '&lfn=' urlencode(LFN);
  42. if (HTT != LFN)                             $urlp .= '&htt=' urlencode(HTT);
  43. if (DBG)                                    $urlp .= '&dbg=' urlencode(DBG);
  44.  
  45. // name of the language file that needs to be included 
  46. $language_file LFN
  47. require("../inc/global.inc.php");
  48. $this_section=SECTION_COURSES;
  49.  
  50. $nameTools get_lang('Tool');
  51.  
  52. ($nameTools && get_lang('Sorry'))
  53.     or give_up('Language file ' LFN " doesn't define 'Tool' and 'Sorry'");
  54.  
  55. $_course api_get_course_info()isset($_courseor give_up(get_lang('Sorry'));
  56.  
  57. require(api_get_path(LIBRARY_PATH'xmd.lib.php');
  58. require(api_get_path(LIBRARY_PATH'xht.lib.php');
  59.  
  60. $mdObj new mdobject($_courseEID_ID);  // see 'md_' . EID_TYPE . '.php'
  61.  
  62.  
  63. // Construct assoclist $langLangs from language table ------------------------->
  64.  
  65. $result api_sql_query("SELECT isocode FROM " 
  66.     " WHERE available='1' ORDER BY isocode ASC"__FILE____LINE__);
  67.  
  68. $sep ":"$langLangs $sep "xx" $sep "xx"
  69.  
  70. while ($row mysql_fetch_array($result))
  71.     if (($isocode $row['isocode']))
  72.         $langLangs .= ",, " $isocode $sep $isocode;
  73.  
  74.  
  75. // XML and DB STUFF ----------------------------------------------------------->
  76.  
  77. $is_allowed_to_edit = isset($_user['user_id']&& $is_courseMember && is_allowed_to_edit();
  78.  
  79. $mdStore new mdstore($is_allowed_to_edit);
  80.  
  81. if (($mdt_rec $mdStore->mds_get(EID)) === FALSE)  // no record, default XML
  82.      $mdt $mdObj->mdo_generate_default_xml_metadata();
  83. else $mdt $mdt_rec;
  84.     
  85. $xhtxmldoc new xmddoc(explode("\n"$mdt));
  86.  
  87. $httfile ($xhtxmldoc->error'md_editxml.htt' HTT '.htt';
  88.  
  89. if (!$xhtxmldoc->error && $mdt_rec !== FALSE && 
  90.         method_exists($mdObj'mdo_override'))
  91.     $mdt $mdObj->mdo_override($xhtxmldoc);
  92.  
  93. $xhtDoc define_htt($httfile$urlp$_course['path']);
  94.  
  95. define('HSH'md5($mdt LFN $nameTools get_lang('Sorry'$httfile 
  96.     implode('{}'$xhtDoc->htt_array)));  // cached HTML depends on LFN+HTT
  97.  
  98. $xhtDoc->xht_param['traceinfo'$xhtxmldoc->error;
  99. $xhtDoc->xht_param['dbrecord'$mdt_rec !== FALSE 'TRUE' '';
  100.  
  101. $xhtDoc->xht_xmldoc $xhtxmldoc;
  102.  
  103. if ($is_allowed_to_edit$xhtDoc->xht_param['isallowedtoedit''TRUE';
  104.  
  105. if ($is_allowed_to_edit && isset($_POST['mda']))  // MD updates to Doc and DB
  106. {
  107.     $mdt $mdStore->mds_update_xml_and_mdt($mdObj$xhtDoc->xht_xmldoc
  108.         get_magic_quotes_gpc(stripslashes($_POST['mda']$_POST['mda']
  109.         EID$xhtDoc->xht_param['traceinfo']$mdt_rec !== FALSE);
  110.     
  111.     if ($mdt_rec !== FALSE)
  112.     {
  113.          if (strpos($xhtDoc->xht_param['traceinfo']'DELETE'!== FALSE)
  114.             $xhtDoc->xht_param['dbrecord''';
  115.     }
  116.     else if (strpos($xhtDoc->xht_param['traceinfo']'INSERT'!== FALSE)
  117.             $xhtDoc->xht_param['dbrecord''TRUE';
  118.     
  119.     if (method_exists($mdObj'mdo_storeback'))
  120.         $mdObj->mdo_storeback($xhtDoc->xht_xmldoc);
  121.         
  122.     $mdt_rec FALSE;  // cached HTML obsolete, must re-apply templates
  123. }
  124. elseif ($is_allowed_to_edit && $_POST['mdt'])  // md_editxml.htt
  125. {
  126.     $mdStore->mds_put(EID
  127.         get_magic_quotes_gpc(stripslashes($_POST['mdt']$_POST['mdt']
  128.         'mdxmltext''?');
  129.     $mdStore->mds_put(EIDHSH'md5');
  130.     
  131.     $xhtDoc->xht_param['dbrecord''TRUE';
  132.     
  133.     $mdt ''$xhtDoc->xht_param['traceinfo'get_lang('PressAgain');
  134.     
  135.     $mdt_rec FALSE;  // cached HTML obsolete, must re-apply templates
  136. }
  137.  
  138. $xhtDoc->xht_param['mdt'$mdt;
  139.  
  140. define('CACHE_IS_VALID'isset($mdt_rec&& $mdt_rec !== FALSE && 
  141.     HSH && HSH == $mdStore->mds_get(EID'md5'));
  142.  
  143.     
  144. function md_part($part$newtext)  // callback from template (HTML cache in DB)
  145. {
  146.     global $mdStore;
  147.     
  148.     if ($newtext === FALSE)
  149.     {
  150.         if (!CACHE_IS_VALIDreturn FALSE;
  151.         return '<!-- ' $part ' -->' $mdStore->mds_get(EID$part);
  152.     }
  153.     else
  154.     {
  155.         $mdStore->mds_put(EIDHSH'md5');
  156.         $mdStore->mds_put(EID$newtext$part);
  157.         
  158.         return $newtext;
  159.     }
  160. }
  161.  
  162. function md_part1($newtext)         return md_part('htmlcache1',    $newtext)}
  163. function md_part2($newtext)         return md_part('htmlcache2',    $newtext)}
  164. function md_indexabletext($newtextreturn md_part('indexabletext'$newtext)}
  165.  
  166.  
  167. // GENERATE OUTPUT ------------------------------------------------------------>
  168.  
  169. foreach (explode("\n"$xhtDoc->htt_array['HTTP']as $httpXtra)
  170.     if ($httpXtra$httpHeadXtra[$httpXtra;
  171.  
  172. $xhtDoc->xht_get_lang 'get_lang';
  173.  
  174. function resource_for($e{return $e;}  // dummy, '=/' not used here
  175. $xhtDoc->xht_resource 'resource_for';
  176.  
  177. $htmlHeadXtra[$xhtDoc->xht_fill_template('HEAD');
  178.  
  179. $mdObj->mdo_add_breadcrump_nav();  // see 'md_' . EID_TYPE . '.php'
  180. $noPHP_SELF TRUE;  // in breadcrumps
  181.  
  182. Display::display_header($nameTools)echo "\n";
  183.  
  184. $xhtDoc->xht_dbgn DBG;  // for template debug info, set to e.g. 10000
  185. if (($ti $xhtDoc->xht_param['traceinfo'])) $xhtDoc->xht_param['traceinfo'
  186.     '<h5>Trace information</h5>' htmlspecialchars($ti);
  187.  
  188. echo $xhtDoc->xht_fill_template('METADATA')"\n";
  189.  
  190. if ($xhtDoc->xht_dbgnecho $xhtDoc->xht_dbgo;
  191.  
  192. ?>

Documentation generated on Thu, 12 Jun 2008 13:50:32 -0500 by phpDocumentor 1.4.1