statistics.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Chamilo metadata/statistics.php
  4. * 2005/02/02
  5. * @copyright 2005 rene.haentjens@UGent.be - see metadata/md_funcs.php
  6. * @package chamilo.metadata
  7. */
  8. /**
  9. * Chamilo Metadata: statistics about metadata
  10. */
  11. // PRELIMS -------------------------------------------------------------------->
  12. require('md_funcs.php');
  13. define('EID_TYPE', 'Mix');
  14. require('md_' . strtolower(EID_TYPE) . '.php');
  15. // name of the language file that needs to be included
  16. $language_file = 'md_mix';
  17. include('../inc/global.inc.php');
  18. $this_section=SECTION_COURSES;
  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. $mdStore = new mdstore(FALSE); // no create from statistics
  26. require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
  27. require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
  28. $htmldecode = array_flip(get_html_translation_table(HTML_SPECIALCHARS));
  29. // STATISTICS ----------------------------------------------------------------->
  30. $noPHP_SELF = TRUE; // in breadcrumps
  31. Display::display_header($nameTools);
  32. echo '<h3>', get_lang('Statistics'), '</h3>', "\n";
  33. $ckw = $_course['path'] . '/CourseKwds.js';
  34. define('KEYWORDS_CACHE', get_course_path() . $ckw);
  35. if (!file_exists(KEYWORDS_CACHE))
  36. {
  37. echo get_lang('NoKeywords');
  38. Display::display_footer();
  39. exit();
  40. }
  41. if (!($myFile = @fopen(KEYWORDS_CACHE, 'r')))
  42. {
  43. echo get_lang('KwCacheProblem');
  44. Display::display_footer();
  45. exit();
  46. }
  47. $kwds = array(); $kwcnt = array(); $kwrefs = array();
  48. while (($kwline = fgets($myFile)))
  49. {
  50. if (ereg('�>(.+)<�', $kwline, $regs) || ereg('">(.+)<�', $kwline, $regs))
  51. foreach (explode(',', $regs[1]) as $kw)
  52. if (!in_array($kw = strtr(trim($kw), $htmldecode), $kwds))
  53. $kwds []= $kw;
  54. }
  55. fclose($myFile);
  56. $result = $mdStore->mds_get_many('eid,mdxmltext', '1 = 1');
  57. echo get_lang('TotalMDEs'), Database::num_rows($result), "<br>\n";
  58. echo count($kwds), ' ', get_lang('CourseKwds'), '<br>', "\n";
  59. while ($row = Database::fetch_array($result))
  60. {
  61. $eid = $row['eid']; $curr = ''; $xmltext = $row['mdxmltext']; $offset = 0;
  62. if (substr($eid, 0, 6) == 'Scorm.')
  63. if (($dotpos = strpos($eid, '.', 6)) && $dotpos + 1 < strlen($eid))
  64. $curr = substr($eid, 0, $dotpos);
  65. while (($start = strpos($xmltext, '<keyword>', $offset)))
  66. if (($start = strpos($xmltext, '">', $start + 9)))
  67. {
  68. if (($stop = strpos($xmltext, '</', $start += 2)) && $stop > $start)
  69. {
  70. $kw = strtr(substr($xmltext, $start, $stop-$start), $htmldecode);
  71. if (!in_array($kw, $kwds))
  72. {
  73. if (!in_array($kw = '!' . $kw, $kwds)) $kwds []= $kw;
  74. $kwrefs[$kw] .= ' ' . ($curr ?
  75. (strpos($kwrefs[$kw], $curr) ?
  76. substr($eid, $dotpos+1) : $eid) : $eid);
  77. }
  78. $kwcnt[$kw] ++; // = $kwcnt[$kw] ? $kwcnt[$kw] + 1 : 1;
  79. $offset = $stop + 19;
  80. }
  81. else $offset = $start + 2;
  82. // <keyword><string language="en">lecture</string></keyword>
  83. }
  84. else $offset = $start + 9;
  85. // xmd would be nicer but this is faster...
  86. }
  87. echo count($kwds), ' ', get_lang('KwdsInMD'), '<br>'; sort($kwds);
  88. $total = 0; foreach ($kwcnt as $kw => $cnt) $total += $cnt;
  89. echo $total, ' ', get_lang('KwdRefs'), "\n";
  90. echo '<h4>', get_lang('NonCourseKwds'), '</h4>', "\n";
  91. foreach ($kwds as $kw)
  92. if ($kw{0} == '!')
  93. echo '<b>', htmlspecialchars(api_substr($kw, 1), ENT_QUOTES, $charset), '</b>: ', $kwcnt[$kw],
  94. ': <i>', htmlspecialchars($kwrefs[$kw], ENT_QUOTES, $charset), ";</i> \n";
  95. else break;
  96. echo '<h4>', get_lang('KwdsUse'), '</h4>', "\n";
  97. foreach ($kwds as $kw)
  98. if ($kw{0} != '!')
  99. if (!$kwcnt[$kw])
  100. echo '<b>', htmlspecialchars($kw, ENT_QUOTES, $charset), "</b>; \n";
  101. else echo htmlspecialchars($kw, ENT_QUOTES, $charset), ': ', $kwcnt[$kw], "; \n";
  102. Display::display_footer();
  103. ?>