index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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('PlatformAdmin')];
  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('NumberOfUsers');
  86. $reportName2 = get_lang('Teachers');
  87. $reportName3 = get_lang('Students');
  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. $tool_name = get_lang('Statistics');
  127. Display::display_header($tool_name);
  128. echo Display::page_header($tool_name);
  129. $strCourse = get_lang('Courses');
  130. $strUsers = get_lang('Users');
  131. $strSystem = get_lang('System');
  132. $strSocial = get_lang('Social');
  133. $strSession = get_lang('Session');
  134. // courses ...
  135. $tools[$strCourse]['report=courses'] = get_lang('CountCours');
  136. $tools[$strCourse]['report=tools'] = get_lang('PlatformToolAccess');
  137. $tools[$strCourse]['report=courselastvisit'] = get_lang('LastAccess');
  138. $tools[$strCourse]['report=coursebylanguage'] = get_lang('CountCourseByLanguage');
  139. // users ...
  140. $tools[$strUsers]['report=users'] = get_lang('CountUsers');
  141. $tools[$strUsers]['report=recentlogins'] = get_lang('Logins');
  142. $tools[$strUsers]['report=logins&amp;type=month'] = get_lang('Logins').' ('.get_lang('PeriodMonth').')';
  143. $tools[$strUsers]['report=logins&amp;type=day'] = get_lang('Logins').' ('.get_lang('PeriodDay').')';
  144. $tools[$strUsers]['report=logins&amp;type=hour'] = get_lang('Logins').' ('.get_lang('PeriodHour').')';
  145. $tools[$strUsers]['report=pictures'] = get_lang('CountUsers').' ('.get_lang('UserPicture').')';
  146. $tools[$strUsers]['report=no_login_users'] = get_lang('StatsUsersDidNotLoginInLastPeriods');
  147. $tools[$strUsers]['report=zombies'] = get_lang('Zombies');
  148. // system ...
  149. $tools[$strSystem]['report=activities'] = get_lang('ImportantActivities');
  150. if (api_is_global_platform_admin() && api_is_multiple_url_enabled()) {
  151. $tools[$strSystem]['report=user_session'] = get_lang('PortalUserSessionStats');
  152. }
  153. // social ...
  154. $tools[$strSocial]['report=messagesent'] = get_lang('MessagesSent');
  155. $tools[$strSocial]['report=messagereceived'] = get_lang('MessagesReceived');
  156. $tools[$strSocial]['report=friends'] = get_lang('CountFriends');
  157. echo '<table><tr>';
  158. foreach ($tools as $section => $items) {
  159. echo '<td style="vertical-align:top;">';
  160. echo '<h3>'.$section.'</h3>';
  161. echo '<ul>';
  162. foreach ($items as $key => $value) {
  163. echo '<li><a href="index.php?'.$key.'">'.$value.'</a></li>';
  164. }
  165. echo '</ul>';
  166. echo '</td>';
  167. }
  168. echo '</tr></table>';
  169. $course_categories = Statistics::getCourseCategories();
  170. //@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
  171. echo '<br/><br/>';
  172. switch ($report) {
  173. case 'user_session':
  174. $form = new FormValidator('user_session', 'get');
  175. $form->addDateRangePicker('range', get_lang('DateRange'), true);
  176. $form->addHidden('report', 'user_session');
  177. $form->addButtonSearch(get_lang('Search'));
  178. $date = new DateTime($now);
  179. $startDate = $date->format('Y-m-d').' 00:00:00';
  180. $endDate = $date->format('Y-m-d').' 23:59:59';
  181. $start = $startDate;
  182. $end = $endDate;
  183. if ($form->validate()) {
  184. $values = $form->getSubmitValues();
  185. $start = $values['range_start'];
  186. $end = $values['range_end'];
  187. }
  188. echo $form->returnForm();
  189. $url = api_get_path(WEB_AJAX_PATH).'statistics.ajax.php?a=get_user_session&start='.$start.'&end='.$end;
  190. $columns = [
  191. 'URL',
  192. get_lang('Session'),
  193. get_lang('Course'),
  194. get_lang('CountUsers'),
  195. ];
  196. $columnModel = [
  197. [
  198. 'name' => 'url',
  199. 'index' => 'url',
  200. 'width' => '120',
  201. 'align' => 'left',
  202. ],
  203. [
  204. 'name' => 'session',
  205. 'index' => 'session',
  206. 'width' => '180',
  207. 'align' => 'left',
  208. 'sortable' => 'false',
  209. ],
  210. [
  211. 'name' => 'course',
  212. 'index' => 'course',
  213. 'width' => '100',
  214. 'align' => 'left',
  215. 'sortable' => 'false',
  216. ],
  217. [
  218. 'name' => 'count',
  219. 'index' => 'count',
  220. 'width' => '50',
  221. 'align' => 'left',
  222. 'sortable' => 'false',
  223. ],
  224. ];
  225. $extraParams['autowidth'] = 'true'; //use the width of the parent
  226. $extraParams['height'] = 'auto'; //use the width of the parent
  227. $actionLinks = '';
  228. ?>
  229. <script>
  230. $(function() {
  231. <?php
  232. echo Display::grid_js(
  233. 'user_session_grid',
  234. $url,
  235. $columns,
  236. $columnModel,
  237. $extraParams,
  238. [],
  239. $actionLinks,
  240. true
  241. );
  242. ?>
  243. jQuery("#user_session_grid").jqGrid("navGrid","#user_session_grid_pager",{
  244. view:false,
  245. edit:false,
  246. add:false,
  247. del:false,
  248. search:false,
  249. excel:true
  250. });
  251. jQuery("#user_session_grid").jqGrid("navButtonAdd","#user_session_grid_pager", {
  252. caption:"",
  253. onClickButton : function () {
  254. jQuery("#user_session_grid").jqGrid("excelExport",{"url":"<?php echo $url; ?>&export_format=xls"});
  255. }
  256. });
  257. });
  258. </script>
  259. <?php
  260. echo Display::grid_html('user_session_grid');
  261. break;
  262. case 'courses':
  263. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  264. // total amount of courses
  265. foreach ($course_categories as $code => $name) {
  266. $courses[$name] = Statistics::countCourses($code);
  267. }
  268. // courses for each course category
  269. Statistics::printStats(get_lang('CountCours'), $courses);
  270. break;
  271. case 'tools':
  272. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  273. Statistics::printToolStats();
  274. break;
  275. case 'coursebylanguage':
  276. echo '<canvas class="col-md-12" id="canvas" height="300px" style="margin-bottom: 20px"></canvas>';
  277. $result = Statistics::printCourseByLanguageStats();
  278. Statistics::printStats(get_lang('CountCourseByLanguage'), $result, true);
  279. break;
  280. case 'courselastvisit':
  281. Statistics::printCourseLastVisit();
  282. break;
  283. case 'users':
  284. echo '<div class="row">';
  285. echo '<div class="col-md-4"><canvas id="canvas1" style="margin-bottom: 20px"></canvas></div>';
  286. echo '<div class="col-md-4"><canvas id="canvas2" style="margin-bottom: 20px"></canvas></div>';
  287. echo '<div class="col-md-4"><canvas id="canvas3" style="margin-bottom: 20px"></canvas></div>';
  288. echo '</div>';
  289. // total amount of users
  290. $teachers = $students = [];
  291. $countInvisible = isset($_GET['count_invisible_courses']) ? intval($_GET['count_invisible_courses']) : null;
  292. Statistics::printStats(
  293. get_lang('NumberOfUsers'),
  294. [
  295. get_lang('Teachers') => Statistics::countUsers(COURSEMANAGER, null, $countInvisible),
  296. get_lang('Students') => Statistics::countUsers(STUDENT, null, $countInvisible),
  297. ]
  298. );
  299. foreach ($course_categories as $code => $name) {
  300. $name = str_replace(get_lang('Department'), "", $name);
  301. $teachers[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
  302. $students[$name] = Statistics::countUsers(STUDENT, $code, $countInvisible);
  303. }
  304. // docents for each course category
  305. Statistics::printStats(get_lang('Teachers'), $teachers);
  306. // students for each course category
  307. Statistics::printStats(get_lang('Students'), $students);
  308. break;
  309. case 'recentlogins':
  310. echo '<h2>'.sprintf(get_lang('LastXDays'), '15').'</h2>';
  311. $form = new FormValidator('session_time', 'get', api_get_self().'?report=recentlogins&session_duration='.$sessionDuration);
  312. $sessionTimeList = ['', 5 => 5, 15 => 15, 30 => 30, 60 => 60];
  313. $form->addSelect('session_duration', [get_lang('SessionMinDuration'), get_lang('Minutes')], $sessionTimeList);
  314. $form->addButtonSend(get_lang('Filter'));
  315. $form->addHidden('report', 'recentlogins');
  316. $form->display();
  317. echo '<canvas class="col-md-12" id="canvas" height="200px" style="margin-bottom: 20px"></canvas>';
  318. Statistics::printRecentLoginStats(false, $sessionDuration);
  319. Statistics::printRecentLoginStats(true, $sessionDuration);
  320. break;
  321. case 'logins':
  322. Statistics::printLoginStats($_GET['type']);
  323. break;
  324. case 'pictures':
  325. Statistics::printUserPicturesStats();
  326. break;
  327. case 'no_login_users':
  328. Statistics::printUsersNotLoggedInStats();
  329. break;
  330. case 'zombies':
  331. ZombieReport::create(['report' => 'zombies'])->display();
  332. break;
  333. case 'activities':
  334. Statistics::printActivitiesStats();
  335. break;
  336. case 'messagesent':
  337. $messages_sent = Statistics::getMessages('sent');
  338. Statistics::printStats(get_lang('MessagesSent'), $messages_sent);
  339. break;
  340. case 'messagereceived':
  341. $messages_received = Statistics::getMessages('received');
  342. Statistics::printStats(get_lang('MessagesReceived'), $messages_received);
  343. break;
  344. case 'friends':
  345. // total amount of friends
  346. $friends = Statistics::getFriends();
  347. Statistics::printStats(get_lang('CountFriends'), $friends);
  348. break;
  349. }
  350. Display::display_footer();