importdocs.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php /* <!-- Dokeos metadata/importdocs.php -->
  2. <!-- 2005/09/20 -->
  3. <!-- Copyright (C) 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php -->
  4. */
  5. /**
  6. ==============================================================================
  7. * Dokeos Metadata: index all course documents with PhpDig
  8. *
  9. * @package dokeos.metadata
  10. ==============================================================================
  11. */
  12. // PRELIMS -------------------------------------------------------------------->
  13. $getpostvars = array('dmo'); require('md_funcs.php');
  14. define('EID_TYPE', 'Document'); define('AFTER_DOT', strlen(EID_TYPE) + 1);
  15. define('OF_EID_TYPE', "eid LIKE '" . EID_TYPE . ".%'");
  16. require('md_' . strtolower(EID_TYPE) . '.php');
  17. // name of the language file that needs to be included
  18. $language_file = 'md_' . strtolower(EID_TYPE);
  19. include('../inc/global.inc.php');
  20. $nameTools = get_lang('Tool');
  21. ($nameTools && get_lang('Sorry')) or give_up(
  22. 'Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");
  23. $_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));
  24. $is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && is_allowed_to_edit();
  25. if (!$is_allowed_to_edit) give_up(get_lang('Denied'));
  26. $mdObj = new mdobject($_course, 0);
  27. $mdStore = new mdstore($is_allowed_to_edit); // create table if needed
  28. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  29. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  30. require('md_phpdig.php');
  31. $mdObj->mdo_add_breadcrump_nav(); // see 'md_' . EID_TYPE . '.php'
  32. $htmlHeadXtra[] = '
  33. <link rel="stylesheet" type="text/css" href="md_styles.css">
  34. <script type="text/javascript" src="md_script.js"></script>
  35. ';
  36. Display::display_header($nameTools);
  37. if (isset($dmo)) // for future use
  38. {
  39. echo '<h3>', $dmo, '</h3>', "\n"; // document metadata op
  40. // if ($dmo == get_lang('Index')) $dmo = $dmo;
  41. }
  42. $result = $mdStore->mds_get_many('eid,indexabletext', OF_EID_TYPE);
  43. echo get_lang('Tool'), ': ', Database::num_rows($result), "<br><br>\n";
  44. $idt = array(); $cidpar = '?cidReq=' . $_course['sysCode'];
  45. while ($row = Database::fetch_array($result)) // load indexabletexts in memory
  46. {
  47. $mdObj = new mdobject($_course, substr($row['eid'], AFTER_DOT));
  48. $idt[$mdObj->mdo_url . $cidpar] = $row['indexabletext'];
  49. }
  50. if (count($idt) && file_exists($phpDigIncCn))
  51. {
  52. require($phpDigIncCn); // switch to PhpDig DB
  53. foreach ($idt as $url => $text)
  54. if (ereg('^http://([^/]+)/(.+)/([^/]+)\?cidReq=(.+)$', $url, $regs))
  55. {
  56. $path = $regs[2] .'/'; $file = $regs[3] . '?cidReq=' . $regs[4];
  57. if ($site_id = remove_engine_entries('http://' . $regs[1] .'/',
  58. $path, $file))
  59. {
  60. echo '<table>', "\n";
  61. index_words($site_id, $path, $file,
  62. get_first_words($text, $path, $file),
  63. get_keywords($text));
  64. echo '</table>', "\n";
  65. }
  66. }
  67. if(isset($db))
  68. {
  69. mysql_select_db($_configuration['main_database'], $db); // back to Dokeos
  70. }
  71. }
  72. else
  73. {
  74. echo 'No documents with metadata or no PhpDig in this course...<br />';
  75. }
  76. if (false && file_exists($phpDigIncCn)) // future: buttons for operations
  77. {
  78. echo '<form action="' .api_get_self(). '" method="post">', "\n",
  79. '<input type="submit" name="dmo" value="', get_lang('Import', 'noDLTT'), '">', "\n",
  80. '<input type="submit" name="dmo" value="', get_lang('Remove', 'noDLTT'), '">', "\n",
  81. '</form>', "\n";
  82. }
  83. Display::display_footer();
  84. ?>