index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This tool show global Statistics on general platform events.
  5. *
  6. * @package chamilo.Statistics
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../../inc/global.inc.php';
  10. api_protect_admin_script();
  11. $interbreadcrumb[] = ['url' => '../index.php', 'name' => get_lang('Administration')];
  12. $report = isset($_REQUEST['report']) ? $_REQUEST['report'] : '';
  13. $sessionDuration = isset($_GET['session_duration']) ? (int) $_GET['session_duration'] : '';
  14. if (
  15. in_array(
  16. $report,
  17. ['recentlogins', 'tools', 'courses', 'coursebylanguage', 'users']
  18. )
  19. ) {
  20. $htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
  21. // Prepare variables for the JS charts
  22. $url = $reportName = $reportType = $reportOptions = '';
  23. switch ($report) {
  24. case 'recentlogins':
  25. $url = api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=recent_logins&session_duration='.$sessionDuration;
  26. $reportName = '';
  27. $reportType = 'line';
  28. $reportOptions = '';
  29. $htmlHeadXtra[] = Statistics::getJSChartTemplate($url, $reportType, $reportOptions);
  30. break;
  31. case 'tools':
  32. $url = api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=tools_usage';
  33. $reportName = 'PlatformToolAccess';
  34. $reportType = 'pie';
  35. $reportOptions = '
  36. legend: {
  37. position: "left"
  38. },
  39. title: {
  40. text: "'.get_lang($reportName).'",
  41. display: true
  42. },
  43. cutoutPercentage: 25
  44. ';
  45. $htmlHeadXtra[] = Statistics::getJSChartTemplate($url, $reportType, $reportOptions);
  46. break;
  47. case 'courses':
  48. $url = api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=courses';
  49. $reportName = 'CountCours';
  50. $reportType = 'pie';
  51. $reportOptions = '
  52. legend: {
  53. position: "left"
  54. },
  55. title: {
  56. text: "'.get_lang($reportName).'",
  57. display: true
  58. },
  59. cutoutPercentage: 25
  60. ';
  61. $htmlHeadXtra[] = Statistics::getJSChartTemplate($url, $reportType, $reportOptions);
  62. break;
  63. case 'coursebylanguage':
  64. $url = api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?a=courses_by_language';
  65. $reportName = 'CountCourseByLanguage';
  66. $reportType = 'pie';
  67. $reportOptions = '
  68. legend: {
  69. position: "left"
  70. },
  71. title: {
  72. text: "'.get_lang($reportName).'",
  73. display: true
  74. },
  75. cutoutPercentage: 25
  76. ';
  77. $htmlHeadXtra[] = Statistics::getJSChartTemplate($url, $reportType, $reportOptions);
  78. break;
  79. case 'users':
  80. $invisible = isset($_GET['count_invisible_courses']) ? intval($_GET['count_invisible_courses']) : null;
  81. $urlBase = api_get_path(WEB_CODE_PATH).'inc/ajax/statistics.ajax.php?';
  82. $url1 = $urlBase.'a=users&count_invisible='.$invisible;
  83. $url2 = $urlBase.'a=users_teachers&count_invisible='.$invisible;
  84. $url3 = $urlBase.'a=users_students&count_invisible='.$invisible;
  85. $reportName1 = get_lang('Number of users');
  86. $reportName2 = get_lang('Trainers');
  87. $reportName3 = get_lang('Learners');
  88. $reportType = 'pie';
  89. $reportOptions = '
  90. legend: {
  91. position: "left"
  92. },
  93. title: {
  94. text: "%s",
  95. display: true
  96. },
  97. cutoutPercentage: 25
  98. ';
  99. $reportOptions1 = sprintf($reportOptions, $reportName1);
  100. $reportOptions2 = sprintf($reportOptions, $reportName2);
  101. $reportOptions3 = sprintf($reportOptions, $reportName3);
  102. $htmlHeadXtra[] = Statistics::getJSChartTemplate(
  103. $url1,
  104. $reportType,
  105. $reportOptions1,
  106. 'canvas1'
  107. );
  108. $htmlHeadXtra[] = Statistics::getJSChartTemplate(
  109. $url2,
  110. $reportType,
  111. $reportOptions2,
  112. 'canvas2'
  113. );
  114. $htmlHeadXtra[] = Statistics::getJSChartTemplate(
  115. $url3,
  116. $reportType,
  117. $reportOptions3,
  118. 'canvas3'
  119. );
  120. break;
  121. }
  122. }
  123. if ($report == 'user_session') {
  124. $htmlHeadXtra[] = api_get_jqgrid_js();
  125. }
  126. if (isset($_GET['export'])) {
  127. ob_start();
  128. }
  129. $tool_name = get_lang('Statistics');
  130. Display::display_header($tool_name);
  131. echo Display::page_header($tool_name);
  132. $strCourse = get_lang('Courses');
  133. $strUsers = get_lang('Users');
  134. $strSystem = get_lang('System');
  135. $strSocial = get_lang('Social');
  136. $strSession = get_lang('Session');
  137. // courses ...
  138. $tools[$strCourse]['report=courses'] = get_lang('Courses');
  139. $tools[$strCourse]['report=tools'] = get_lang('Tools access');
  140. $tools[$strCourse]['report=courselastvisit'] = get_lang('Latest access');
  141. $tools[$strCourse]['report=coursebylanguage'] = get_lang('CourseseByLanguage');
  142. // users ...
  143. $tools[$strUsers]['report=users'] = get_lang('Number of users');
  144. $tools[$strUsers]['report=recentlogins'] = get_lang('Logins');
  145. $tools[$strUsers]['report=logins&amp;type=month'] = get_lang('Logins').' ('.get_lang('Month').')';
  146. $tools[$strUsers]['report=logins&amp;type=day'] = get_lang('Logins').' ('.get_lang('Day').')';
  147. $tools[$strUsers]['report=logins&amp;type=hour'] = get_lang('Logins').' ('.get_lang('Hour').')';
  148. $tools[$strUsers]['report=pictures'] = get_lang('Number of users').' ('.get_lang('Picture').')';
  149. $tools[$strUsers]['report=logins_by_date'] = get_lang('Logins by date');
  150. $tools[$strUsers]['report=no_login_users'] = get_lang('Not logged in for some time');
  151. $tools[$strUsers]['report=zombies'] = get_lang('Zombies');
  152. // system ...
  153. $tools[$strSystem]['report=activities'] = get_lang('Important activities');
  154. if (api_is_global_platform_admin() && api_is_multiple_url_enabled()) {
  155. $tools[$strSystem]['report=user_session'] = get_lang('Portal user session stats');
  156. }
  157. // social ...
  158. $tools[$strSocial]['report=messagesent'] = get_lang('Number of messages sent');
  159. $tools[$strSocial]['report=messagereceived'] = get_lang('Number of messages received');
  160. $tools[$strSocial]['report=friends'] = get_lang('Contacts count');
  161. echo '<table><tr>';
  162. foreach ($tools as $section => $items) {
  163. echo '<td style="vertical-align:top;">';
  164. echo '<h3>'.$section.'</h3>';
  165. echo '<ul>';
  166. foreach ($items as $key => $value) {
  167. echo '<li><a href="index.php?'.$key.'">'.$value.'</a></li>';
  168. }
  169. echo '</ul>';
  170. echo '</td>';
  171. }
  172. echo '</tr></table>';
  173. $course_categories = Statistics::getCourseCategories();
  174. //@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
  175. echo '<br/><br/>';
  176. switch ($report) {
  177. case 'user_session':
  178. $form = new FormValidator('user_session', 'get');
  179. $form->addDateRangePicker('range', get_lang('DateRange'), true);
  180. $form->addHidden('report', 'user_session');
  181. $form->addButtonSearch(get_lang('Search'));
  182. $date = new DateTime($now);
  183. $startDate = $date->format('Y-m-d').' 00:00:00';
  184. $endDate = $date->format('Y-m-d').' 23:59:59';
  185. $start = $startDate;
  186. $end = $endDate;
  187. if ($form->validate()) {
  188. $values = $form->getSubmitValues();
  189. $start = $values['range_start'];
  190. $end = $values['range_end'];
  191. }
  192. echo $form->returnForm();
  193. $url = api_get_path(WEB_AJAX_PATH).'statistics.ajax.php?a=get_user_session&start='.$start.'&end='.$end;
  194. $columns = [
  195. 'URL',
  196. get_lang('Session'),
  197. get_lang('Course'),
  198. get_lang('Number of users'),
  199. ];
  200. $columnModel = [
  201. [
  202. 'name' => 'url',
  203. 'index' => 'url',
  204. 'width' => '120',
  205. 'align' => 'left',
  206. ],
  207. [
  208. 'name' => 'session',
  209. 'index' => 'session',
  210. 'width' => '180',
  211. 'align' => 'left',
  212. 'sortable' => 'false',
  213. ],
  214. [
  215. 'name' => 'course',
  216. 'index' => 'course',
  217. 'width' => '100',
  218. 'align' => 'left',
  219. 'sortable' => 'false',
  220. ],
  221. [
  222. 'name' => 'count',
  223. 'index' => 'count',
  224. 'width' => '50',
  225. 'align' => 'left',
  226. 'sortable' => 'false',
  227. ],
  228. ];
  229. $extraParams['autowidth'] = 'true'; //use the width of the parent
  230. $extraParams['height'] = 'auto'; //use the width of the parent
  231. $actionLinks = '';
  232. ?>
  233. <script>
  234. $(function() {
  235. <?php
  236. echo Display::grid_js(
  237. 'user_session_grid',
  238. $url,
  239. $columns,
  240. $columnModel,
  241. $extraParams,
  242. [],
  243. $actionLinks,
  244. true
  245. );
  246. ?>
  247. jQuery("#user_session_grid").jqGrid("navGrid","#user_session_grid_pager",{
  248. view:false,
  249. edit:false,
  250. add:false,
  251. del:false,
  252. search:false,
  253. excel:true
  254. });
  255. jQuery("#user_session_grid").jqGrid("navButtonAdd","#user_session_grid_pager", {
  256. caption:"",
  257. onClickButton : function () {
  258. jQuery("#user_session_grid").jqGrid("excelExport",{"url":"<?php echo $url; ?>&export_format=xls"});
  259. }
  260. });
  261. });
  262. </script>
  263. <?php
  264. echo Display::grid_html('user_session_grid');
  265. break;
  266. case 'courses':
  267. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  268. // total amount of courses
  269. foreach ($course_categories as $code => $name) {
  270. $courses[$name] = Statistics::countCourses($code);
  271. }
  272. // courses for each course category
  273. Statistics::printStats(get_lang('Courses'), $courses);
  274. break;
  275. case 'tools':
  276. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  277. Statistics::printToolStats();
  278. break;
  279. case 'coursebylanguage':
  280. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  281. $result = Statistics::printCourseByLanguageStats();
  282. Statistics::printStats(get_lang('CourseseByLanguage'), $result, true);
  283. break;
  284. case 'courselastvisit':
  285. Statistics::printCourseLastVisit();
  286. break;
  287. case 'users':
  288. echo '<div class="row">';
  289. echo '<div class="col-md-4"><canvas id="canvas1" style="margin-bottom: 20px"></canvas></div>';
  290. echo '<div class="col-md-4"><canvas id="canvas2" style="margin-bottom: 20px"></canvas></div>';
  291. echo '<div class="col-md-4"><canvas id="canvas3" style="margin-bottom: 20px"></canvas></div>';
  292. echo '</div>';
  293. // total amount of users
  294. $teachers = $students = [];
  295. $countInvisible = isset($_GET['count_invisible_courses']) ? intval($_GET['count_invisible_courses']) : null;
  296. Statistics::printStats(
  297. get_lang('Number of users'),
  298. [
  299. get_lang('Trainers') => Statistics::countUsers(COURSEMANAGER, null, $countInvisible),
  300. get_lang('Learners') => Statistics::countUsers(STUDENT, null, $countInvisible),
  301. ]
  302. );
  303. foreach ($course_categories as $code => $name) {
  304. $name = str_replace(get_lang('Department'), "", $name);
  305. $teachers[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
  306. $students[$name] = Statistics::countUsers(STUDENT, $code, $countInvisible);
  307. }
  308. // docents for each course category
  309. Statistics::printStats(get_lang('Trainers'), $teachers);
  310. // students for each course category
  311. Statistics::printStats(get_lang('Learners'), $students);
  312. break;
  313. case 'recentlogins':
  314. echo '<h2>'.sprintf(get_lang('Last %s days'), '15').'</h2>';
  315. $form = new FormValidator('session_time', 'get', api_get_self().'?report=recentlogins&session_duration='.$sessionDuration);
  316. $sessionTimeList = ['', 5 => 5, 15 => 15, 30 => 30, 60 => 60];
  317. $form->addSelect('session_duration', [get_lang('Session min duration'), get_lang('Minutes')], $sessionTimeList);
  318. $form->addButtonSend(get_lang('Filter'));
  319. $form->addHidden('report', 'recentlogins');
  320. $form->display();
  321. echo '<canvas class="col-md-12" id="canvas" height="200px" style="margin-bottom: 20px"></canvas>';
  322. Statistics::printRecentLoginStats(false, $sessionDuration);
  323. Statistics::printRecentLoginStats(true, $sessionDuration);
  324. break;
  325. case 'logins':
  326. Statistics::printLoginStats($_GET['type']);
  327. break;
  328. case 'pictures':
  329. Statistics::printUserPicturesStats();
  330. break;
  331. case 'no_login_users':
  332. Statistics::printUsersNotLoggedInStats();
  333. break;
  334. case 'zombies':
  335. ZombieReport::create(['report' => 'zombies'])->display();
  336. break;
  337. case 'activities':
  338. Statistics::printActivitiesStats();
  339. break;
  340. case 'messagesent':
  341. $messages_sent = Statistics::getMessages('sent');
  342. Statistics::printStats(get_lang('Number of messages sent'), $messages_sent);
  343. break;
  344. case 'messagereceived':
  345. $messages_received = Statistics::getMessages('received');
  346. Statistics::printStats(get_lang('Number of messages received'), $messages_received);
  347. break;
  348. case 'friends':
  349. // total amount of friends
  350. $friends = Statistics::getFriends();
  351. Statistics::printStats(get_lang('Contacts count'), $friends);
  352. break;
  353. case 'logins_by_date':
  354. Statistics::printLoginsByDate();
  355. break;
  356. }
  357. Display::display_footer();
  358. if (isset($_GET['export'])) {
  359. ob_end_clean();
  360. }