index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This tool show global Statistics on general platform events
  5. * @package chamilo.Statistics
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../../inc/global.inc.php';
  9. api_protect_admin_script();
  10. $interbreadcrumb[] = array('url' => '../index.php', 'name' => get_lang('PlatformAdmin'));
  11. $report = isset($_REQUEST['report']) ? $_REQUEST['report'] : '';
  12. if ($report) {
  13. $htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
  14. $htmlHeadXtra[] = '
  15. <script>
  16. $(document).ready(function() {
  17. $.ajax({
  18. url: "'. api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=recentlogins",
  19. type: "POST",
  20. success: function(data) {
  21. Chart.defaults.global.responsive = true;
  22. var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(data);
  23. }
  24. });
  25. });
  26. </script>';
  27. }
  28. $tool_name = get_lang('Statistics');
  29. Display::display_header($tool_name);
  30. echo Display::page_header($tool_name);
  31. $strCourse = get_lang('Courses');
  32. $strUsers = get_lang('Users');
  33. $strSystem = get_lang('System');
  34. $strSocial = get_lang('Social');
  35. $strSession = get_lang('Session');
  36. // courses ...
  37. $tools[$strCourse]['report=courses'] = get_lang('CountCours');
  38. $tools[$strCourse]['report=tools'] = get_lang('PlatformToolAccess');
  39. $tools[$strCourse]['report=courselastvisit'] = get_lang('LastAccess');
  40. $tools[$strCourse]['report=coursebylanguage'] = get_lang('CountCourseByLanguage');
  41. // users ...
  42. $tools[$strUsers]['report=users'] = get_lang('CountUsers');
  43. $tools[$strUsers]['report=recentlogins'] = get_lang('Logins');
  44. $tools[$strUsers]['report=logins&amp;type=month'] = get_lang('Logins').' ('.get_lang('PeriodMonth').')';
  45. $tools[$strUsers]['report=logins&amp;type=day'] = get_lang('Logins').' ('.get_lang('PeriodDay').')';
  46. $tools[$strUsers]['report=logins&amp;type=hour'] = get_lang('Logins').' ('.get_lang('PeriodHour').')';
  47. $tools[$strUsers]['report=pictures'] = get_lang('CountUsers').' ('.get_lang('UserPicture').')';
  48. $tools[$strUsers]['report=no_login_users'] = get_lang('StatsUsersDidNotLoginInLastPeriods');
  49. $tools[$strUsers]['report=zombies'] = get_lang('Zombies');
  50. // system ...
  51. $tools[$strSystem]['report=activities'] = get_lang('ImportantActivities');
  52. // social ...
  53. $tools[$strSocial]['report=messagesent'] = get_lang('MessagesSent');
  54. $tools[$strSocial]['report=messagereceived'] = get_lang('MessagesReceived');
  55. $tools[$strSocial]['report=friends'] = get_lang('CountFriends');
  56. echo '<table><tr>';
  57. foreach ($tools as $section => $items) {
  58. echo '<td style="vertical-align:top;">';
  59. echo '<h3>'.$section.'</h3>';
  60. echo '<ul>';
  61. foreach ($items as $key => $value) {
  62. echo '<li><a href="index.php?'.$key.'">'.$value.'</a></li>';
  63. }
  64. echo '</ul>';
  65. echo '</td>';
  66. }
  67. echo '</tr></table>';
  68. $course_categories = Statistics::getCourseCategories();
  69. echo '<br/><br/>'; //@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
  70. switch ($report) {
  71. case 'courses':
  72. // total amount of courses
  73. foreach ($course_categories as $code => $name) {
  74. $courses[$name] = Statistics::countCourses($code);
  75. }
  76. // courses for each course category
  77. Statistics::printStats(get_lang('CountCours'), $courses);
  78. break;
  79. case 'tools':
  80. Statistics::printToolStats();
  81. break;
  82. case 'coursebylanguage':
  83. Statistics::printCourseByLanguageStats();
  84. break;
  85. case 'courselastvisit':
  86. Statistics::printCourseLastVisit();
  87. break;
  88. case 'users':
  89. // total amount of users
  90. $teachers = $students = array();
  91. $countInvisible = isset($_GET['count_invisible_courses']) ? intval($_GET['count_invisible_courses']) : null;
  92. Statistics::printStats(
  93. get_lang('NumberOfUsers'),
  94. array(
  95. get_lang('Teachers') => Statistics::countUsers(COURSEMANAGER, null, $countInvisible),
  96. get_lang('Students') => Statistics::countUsers(STUDENT, null, $countInvisible)
  97. )
  98. );
  99. foreach ($course_categories as $code => $name) {
  100. $name = str_replace(get_lang('Department'), "", $name);
  101. $teachers[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
  102. $students[$name] = Statistics::countUsers(STUDENT, $code, $countInvisible);
  103. }
  104. // docents for each course category
  105. Statistics::printStats(get_lang('Teachers'), $teachers);
  106. // students for each course category
  107. Statistics::printStats(get_lang('Students'), $students);
  108. break;
  109. case 'recentlogins':
  110. echo '<h2>'.sprintf(get_lang('LastXDays'), '15').'</h2>';
  111. echo '<canvas class="col-md-12" id="canvas" height="100px" style="margin-bottom: 20px"></canvas>';
  112. Statistics::printRecentLoginStats();
  113. Statistics::printRecentLoginStats(true);
  114. break;
  115. case 'logins':
  116. Statistics::printLoginStats($_GET['type']);
  117. break;
  118. case 'pictures':
  119. Statistics::printUserPicturesStats();
  120. break;
  121. case 'no_login_users':
  122. Statistics::printUsersNotLoggedInStats();
  123. break;
  124. case 'zombies':
  125. ZombieReport::create(array('report' => 'zombies'))->display();
  126. break;
  127. case 'activities':
  128. Statistics::printActivitiesStats();
  129. break;
  130. case 'messagesent':
  131. $messages_sent = Statistics::getMessages('sent');
  132. Statistics::printStats(get_lang('MessagesSent'), $messages_sent);
  133. break;
  134. case 'messagereceived':
  135. $messages_received = Statistics::getMessages('received');
  136. Statistics::printStats(get_lang('MessagesReceived'), $messages_received);
  137. break;
  138. case 'friends':
  139. // total amount of friends
  140. $friends = Statistics::getFriends();
  141. Statistics::printStats(get_lang('CountFriends'), $friends);
  142. break;
  143. }
  144. Display::display_footer();