access_details.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /* MAIN */
  28. $user_id = intval($_REQUEST['student']);
  29. $session_id = intval($_GET['id_session']);
  30. $type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : '';
  31. $course_code = isset($_REQUEST['course']) ? Security::remove_XSS($_REQUEST['course']) : '';
  32. $courseInfo = api_get_course_info($course_code);
  33. $courseId = (!empty($courseInfo['real_id']) ? $courseInfo['real_id'] : null);
  34. $quote_simple = "'";
  35. $form = new FormValidator(
  36. 'myform',
  37. 'get',
  38. api_get_self(),
  39. null,
  40. ['id' => 'myform']
  41. );
  42. $form->addElement('text', 'from', get_lang('From'), ['id' => 'date_from']);
  43. $form->addElement('text', 'to', get_lang('Until'), ['id' => 'date_to']);
  44. $form->addElement(
  45. 'select',
  46. 'type',
  47. get_lang('Type'),
  48. ['day' => get_lang('Day'), 'month' => get_lang('Month')],
  49. ['id' => 'type']
  50. );
  51. $form->addElement('hidden', 'student', $user_id);
  52. $form->addElement('hidden', 'course', $course_code);
  53. $form->addRule('from', get_lang('ThisFieldIsRequired'), 'required');
  54. $form->addRule('to', get_lang('ThisFieldIsRequired'), 'required');
  55. $group = [
  56. $form->createElement(
  57. 'label',
  58. null,
  59. Display::url(
  60. get_lang('Search'),
  61. 'javascript://',
  62. ['onclick' => 'loadGraph();', 'class' => 'btn btn-default']
  63. )
  64. ),
  65. ];
  66. $form->addGroup($group);
  67. $from = null;
  68. $to = null;
  69. $course = $course_code;
  70. if ($form->validate()) {
  71. $values = $form->getSubmitValues();
  72. $from = $values['from'];
  73. $to = $values['to'];
  74. $type = $values['type'];
  75. $course = $values['course'];
  76. }
  77. $url = api_get_path(WEB_AJAX_PATH).'myspace.ajax.php?a=access_detail_by_date&course='.$course.'&student='.$user_id.'&session_id='.$session_id;
  78. $htmlHeadXtra[] = '<script src="slider.js" type="text/javascript"></script>';
  79. $htmlHeadXtra[] = '<link rel="stylesheet" href="slider.css" />';
  80. $htmlHeadXtra[] = "<script>
  81. function loadGraph() {
  82. var startDate = $('#date_from').val();
  83. var endDate = $('#date_to').val();
  84. var type = $('#type option:selected').val();
  85. $.ajax({
  86. url: '".$url."&startDate='+startDate+'&endDate='+endDate+'&type='+type,
  87. dataType: 'json',
  88. success: function(db) {
  89. if (!db.is_empty) {
  90. // Display confirmation message to the user
  91. $('#messages').html(db.result).stop().css('opacity', 1).fadeIn(30);
  92. $('#cev_cont_stats').html(db.stats);
  93. $('#graph' ).html(db.graph_result);
  94. } else {
  95. $('#messages').text('".get_lang('NoDataAvailable')."');
  96. $('#messages').addClass('warning-message');
  97. $('#cev_cont_stats').html('');
  98. $('#graph').empty();
  99. }
  100. }
  101. });
  102. }
  103. $(function() {
  104. var dates = $('#date_from, #date_to').datepicker({
  105. dateFormat: ".$quote_simple."yy-mm-dd".$quote_simple.",
  106. changeMonth: true,
  107. changeYear: true
  108. });
  109. });
  110. </script>";
  111. $htmlHeadXtra[] = '<script>
  112. $(function() {
  113. $("#cev_button").hide();
  114. $("#container-9").tabs({remote: true});
  115. });
  116. </script>';
  117. //Changes END
  118. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')];
  119. Display :: display_header('');
  120. $userInfo = api_get_user_info($user_id);
  121. $result_to_print = '';
  122. $sql_result = MySpace::get_connections_to_course($user_id, $courseInfo);
  123. $result_to_print = convert_to_string($sql_result);
  124. echo Display::page_header(get_lang('DetailsStudentInCourse'));
  125. echo Display::page_subheader(
  126. get_lang('User').': '.$userInfo['complete_name'].' - '.get_lang('Course').': '.$courseInfo['title'].' ('.$course_code.')'
  127. );
  128. $form->setDefaults(['from' => $from, 'to' => $to]);
  129. $form->display();
  130. ?>
  131. <br />
  132. <br />
  133. <div class="text-center" id="graph"></div>
  134. <br />
  135. <br />
  136. <div class="row">
  137. <div id="cev_results" class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6">
  138. <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
  139. <?php echo get_lang('Statistics'); ?>
  140. </div><br />
  141. <div id="cev_cont_stats">
  142. <?php
  143. if ($result_to_print != '') {
  144. $rst = get_stats($user_id, $courseInfo, $session_id);
  145. $foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
  146. $foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
  147. $foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
  148. echo $foo_stats;
  149. } else {
  150. echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
  151. }
  152. ?>
  153. </div>
  154. <br />
  155. </div>
  156. <div class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6 col-md-6">
  157. <div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
  158. <?php echo get_lang('Details'); ?>
  159. </div><br />
  160. <div id="messages"></div>
  161. </div>
  162. </div>
  163. <?php
  164. Display:: display_footer();