access_details.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This is the tracking library for Chamilo.
  5. *
  6. * @package chamilo.reporting
  7. *
  8. * Calculates the time spent on the course
  9. *
  10. * @param int $user_id the user id
  11. * @param string $course_code the course code
  12. *
  13. * @author Julio Montoya <gugli100@gmail.com>
  14. * @author Jorge Frisancho Jibaja - select between dates
  15. */
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. api_block_anonymous_users();
  18. // Access restrictions.
  19. $is_allowedToTrack = api_is_platform_admin(true, true) ||
  20. api_is_teacher() || api_is_course_tutor();
  21. if (!$is_allowedToTrack) {
  22. api_not_allowed(true);
  23. exit;
  24. }
  25. // the section (for the tabs)
  26. $this_section = SECTION_TRACKING;
  27. $user_id = isset($_REQUEST['student']) ? (int) $_REQUEST['student'] : 0;
  28. $session_id = (int) $_GET['id_session'];
  29. $type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : '';
  30. $course_code = isset($_REQUEST['course']) ? Security::remove_XSS($_REQUEST['course']) : '';
  31. $courseInfo = api_get_course_info($course_code);
  32. if (empty($courseInfo)) {
  33. api_not_allowed(true);
  34. }
  35. $courseId = (!empty($courseInfo['real_id']) ? $courseInfo['real_id'] : null);
  36. $quote_simple = "'";
  37. $form = new FormValidator(
  38. 'myform',
  39. 'get',
  40. api_get_self(),
  41. null,
  42. ['id' => 'myform']
  43. );
  44. $form->addElement('text', 'from', get_lang('From'), ['id' => 'date_from']);
  45. $form->addElement('text', 'to', get_lang('Until'), ['id' => 'date_to']);
  46. $form->addElement(
  47. 'select',
  48. 'type',
  49. get_lang('Type'),
  50. ['day' => get_lang('Day'), 'month' => get_lang('Month')],
  51. ['id' => 'type']
  52. );
  53. $form->addElement('hidden', 'student', $user_id);
  54. $form->addElement('hidden', 'course', $course_code);
  55. $form->addRule('from', get_lang('Required field'), 'required');
  56. $form->addRule('to', get_lang('Required field'), 'required');
  57. $group = [
  58. $form->createElement(
  59. 'label',
  60. null,
  61. Display::url(
  62. get_lang('Search'),
  63. 'javascript://',
  64. ['onclick' => 'loadGraph();', 'class' => 'btn btn-default']
  65. )
  66. ),
  67. ];
  68. $form->addGroup($group);
  69. $from = null;
  70. $to = null;
  71. $course = $course_code;
  72. if ($form->validate()) {
  73. $values = $form->getSubmitValues();
  74. $from = $values['from'];
  75. $to = $values['to'];
  76. $type = $values['type'];
  77. $course = $values['course'];
  78. }
  79. $url = api_get_path(WEB_AJAX_PATH).'myspace.ajax.php?a=access_detail_by_date&course='.$course.'&student='.$user_id.'&session_id='.$session_id;
  80. $htmlHeadXtra[] = '<script src="slider.js" type="text/javascript"></script>';
  81. $htmlHeadXtra[] = '<link rel="stylesheet" href="slider.css" />';
  82. $htmlHeadXtra[] = "<script>
  83. function loadGraph() {
  84. var startDate = $('#date_from').val();
  85. var endDate = $('#date_to').val();
  86. var type = $('#type option:selected').val();
  87. $.ajax({
  88. url: '".$url."&startDate='+startDate+'&endDate='+endDate+'&type='+type,
  89. dataType: 'json',
  90. success: function(db) {
  91. if (!db.is_empty) {
  92. // Display confirmation message to the user
  93. $('#messages').html(db.result).stop().css('opacity', 1).fadeIn(30);
  94. $('#cev_cont_stats').html(db.stats);
  95. $('#graph' ).html(db.graph_result);
  96. } else {
  97. $('#messages').text('".get_lang('No data available')."');
  98. $('#messages').addClass('warning-message');
  99. $('#cev_cont_stats').html('');
  100. $('#graph').empty();
  101. }
  102. }
  103. });
  104. }
  105. $(function() {
  106. var dates = $('#date_from, #date_to').datepicker({
  107. dateFormat: ".$quote_simple."yy-mm-dd".$quote_simple.",
  108. changeMonth: true,
  109. changeYear: true
  110. });
  111. });
  112. </script>";
  113. $htmlHeadXtra[] = '<script>
  114. $(function() {
  115. $("#cev_button").hide();
  116. $("#container-9").tabs({remote: true});
  117. });
  118. </script>';
  119. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Access details')];
  120. Display::display_header('');
  121. $userInfo = api_get_user_info($user_id);
  122. $result_to_print = '';
  123. $sql_result = MySpace::get_connections_to_course($user_id, $courseInfo);
  124. $result_to_print = convert_to_string($sql_result);
  125. echo Display::page_header(get_lang('Learner details in course'));
  126. echo Display::page_subheader(
  127. get_lang('User').': '.$userInfo['complete_name'].' - '.get_lang('Course').': '.$courseInfo['title'].' ('.$course_code.')'
  128. );
  129. $form->setDefaults(['from' => $from, 'to' => $to]);
  130. $form->display();
  131. ?>
  132. <br />
  133. <br />
  134. <div class="text-center" id="graph"></div>
  135. <br />
  136. <br />
  137. <div class="row">
  138. <div id="cev_results" class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6">
  139. <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
  140. <?php echo get_lang('Statistics'); ?>
  141. </div><br />
  142. <div id="cev_cont_stats">
  143. <?php
  144. if ($result_to_print != '') {
  145. $rst = get_stats($user_id, $courseInfo, $session_id);
  146. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  147. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  148. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  149. echo $foo_stats;
  150. } else {
  151. echo Display::return_message(get_lang('No data available'), 'warning');
  152. }
  153. ?>
  154. </div>
  155. <br />
  156. </div>
  157. <div class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6 col-md-6">
  158. <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
  159. <?php echo get_lang('Details'); ?>
  160. </div><br />
  161. <div id="messages"></div>
  162. </div>
  163. </div>
  164. <?php
  165. Display::display_footer();