importdocs.php 3.3 KB

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