report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. exit;
  4. use ChamiloSession as Session;
  5. /**
  6. * @package chamilo.plugin.ticket
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. if (!api_is_allowed_to_edit()) {
  12. api_not_allowed();
  13. }
  14. $this_section = 'Reports';
  15. Session::erase('this_section');
  16. $htmlHeadXtra[] = '<script>
  17. $(function() {
  18. $( "#keyword_start_date_start" ).datepicker({ dateFormat: '."'yy-mm-dd'".' });
  19. $( "#keyword_start_date_end" ).datepicker({ dateFormat: '."'yy-mm-dd'".' });
  20. });
  21. function validate() {
  22. if( $("#keyword_start_date_start").val() != "" && $("#keyword_start_date_end").val() != ""){
  23. datestart = $("#keyword_start_date_start").val();
  24. dateend = $("#keyword_start_date_end").val();
  25. dif = $.datepicker.parseDate("dd/mm/yy", datestart) - $.datepicker.parseDate("dd/mm/yy", dateend);
  26. if(dif > 0){
  27. alert("La fecha final no puede ser mayor a la fecha inicial");
  28. return false;
  29. }
  30. }
  31. }
  32. function load_course_list (div_course,my_user_id) {
  33. $.ajax({
  34. contentType: "application/x-www-form-urlencoded",
  35. type: "GET",
  36. url: "course_user_list.php",
  37. data: "user_id="+my_user_id,
  38. success: function(datos) {
  39. $("div#user_request").html(datos);
  40. $("#btnsubmit").attr("disabled", false);
  41. }
  42. });
  43. }
  44. </script>
  45. <style>
  46. div.row div.label2 {
  47. float:left;
  48. width:10%;
  49. }
  50. div.row div.formw2 {
  51. width:90%;
  52. float:left
  53. }
  54. div.ticket-form {
  55. width: 70%;
  56. float: center;
  57. margin-left: 15%;
  58. }
  59. </style>';
  60. $types = TicketManager::get_all_tickets_categories();
  61. $tools = [];
  62. $tools['todas'] = ['id' => '', 'name' => get_lang('All')];
  63. $tools['announcement'] = ['id' => 'announcement', 'name' => get_lang('Announcement')];
  64. // $tools[]= array('id'=>'assignment','name'=>get_lang('Assignment'));
  65. $tools['calendar_event'] = ['id' => 'calendar_event', 'name' => get_lang('ToolCalendarEvent')];
  66. $tools['chat'] = ['id' => 'chat', 'name' => get_lang('Chat')];
  67. $tools['course_description'] = ['id' => 'course_description', 'name' => get_lang('CourseDescription')];
  68. $tools['document'] = ['id' => 'document', 'name' => get_lang('Document')];
  69. $tools['dropbox'] = ['id' => 'dropbox', 'name' => get_lang('Dropbox')];
  70. $tools['group'] = ['id' => 'group', 'name' => get_lang('Group')];
  71. $tools['learnpath'] = ['id' => 'learnpath', 'name' => get_lang('Learnpath')];
  72. $tools['link'] = ['id' => 'link', 'name' => get_lang('Link')];
  73. $tools['quiz'] = ['id' => 'quiz', 'name' => get_lang('Quiz')];
  74. $tools['student_publication'] = ['id' => 'student_publication', 'name' => get_lang('ToolStudentPublication')];
  75. $tools['user'] = ['id' => 'user', 'name' => get_lang('User')];
  76. $tools['forum'] = ['id' => 'forum', 'name' => get_lang('Forum')];
  77. /**
  78. * This function is to show the ticket form.
  79. *
  80. * @global array $tools
  81. */
  82. function show_form()
  83. {
  84. global $tools;
  85. echo '<div class="ticket-form">';
  86. echo '<form enctype="multipart/form-data" action="'.api_get_self().'" method="post" name="send_ticket" id="send_ticket"
  87. onsubmit="return validate()" style="width:100%">';
  88. $select_course = '<div id="user_request" >
  89. </div>';
  90. echo $select_course;
  91. //select status
  92. $select_tool = '<div class="row" >
  93. <div class="label2" >'.get_lang('Tool').':</div>
  94. <div class="formw2">';
  95. $select_tool .= '<select style="width: 95%; " name = "tool" id="tool" >';
  96. foreach ($tools as $tool) {
  97. $select_tool .= "<option value = '".$tool['id']."' selected >".$tool['name']."</option>";
  98. }
  99. $select_tool .= "</select>";
  100. $select_tool .= '</div></div>';
  101. echo $select_tool;
  102. echo '<div class="row">
  103. <div class="label2">'.get_lang('From').':</div>
  104. <div class="formw2"><input id="keyword_start_date_start" name="keyword_start_date_start" type="text"></div>
  105. </div>
  106. <div class="row">
  107. <div class="label2"> '.get_lang('To').'</div>
  108. <div class="formw2"><input id="keyword_start_date_end" name="keyword_start_date_end" type="text"></div>
  109. </div>';
  110. echo '</div>';
  111. echo '<div class="row">
  112. <div class="label2">
  113. </div>
  114. <div class="formw2">
  115. <button class="save" name="report" type="submit" id="btnsubmit" disabled="disabled">'.get_lang('CompleteReport').'</button>
  116. </div>
  117. </div>';
  118. }
  119. /**
  120. * Get the total number of users on the platform.
  121. *
  122. * @see SortableTable#get_total_number_of_items()
  123. */
  124. function get_number_of_users()
  125. {
  126. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  127. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  128. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  129. $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  130. $sql .= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  131. }
  132. if (isset($_GET['keyword'])) {
  133. $keyword = Database::escape_string(trim($_GET['keyword']));
  134. $sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
  135. u.lastname LIKE '%$keyword%' OR
  136. concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
  137. concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
  138. u.username LIKE '%$keyword%' OR
  139. u.email LIKE '%$keyword %' OR
  140. u.official_code LIKE '%$keyword%') ";
  141. }
  142. $res = Database::query($sql);
  143. $obj = Database::fetch_object($res);
  144. return $obj->total_number_of_items;
  145. }
  146. /**
  147. * Get the users to display on the current page (fill the sortable-table).
  148. *
  149. * @param int offset of first user to recover
  150. * @param int Number of users to get
  151. * @param int Column to sort on
  152. * @param string Order (ASC,DESC)
  153. *
  154. * @return array
  155. *
  156. * @see SortableTable#get_table_data($from)
  157. */
  158. function get_user_data($from, $number_of_items, $column, $direction)
  159. {
  160. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  161. if (api_is_western_name_order()) {
  162. $col34 = "u.firstname AS col3,
  163. u.lastname AS col4,";
  164. } else {
  165. $col34 = "u.lastname AS col3,
  166. u.firstname AS col4,";
  167. }
  168. $sql = "SELECT
  169. u.user_id AS col0,
  170. u.official_code AS col2,
  171. $col34
  172. u.username AS col5,
  173. u.email AS col6,
  174. u.status AS col7,
  175. u.active AS col8,
  176. u.user_id AS col9,
  177. u.expiration_date AS exp
  178. FROM $user_table u ";
  179. if (isset($_GET['keyword'])) {
  180. $keyword = Database::escape_string(trim($_GET['keyword']));
  181. $sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
  182. u.lastname LIKE '%$keyword%' OR
  183. concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
  184. concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
  185. u.username LIKE '%$keyword%' OR
  186. u.official_code LIKE '%$keyword%'
  187. OR u.email LIKE '%$keyword%' )";
  188. }
  189. if (!in_array($direction, ['ASC', 'DESC'])) {
  190. $direction = 'ASC';
  191. }
  192. $column = intval($column);
  193. $from = intval($from);
  194. $number_of_items = intval($number_of_items);
  195. $sql .= " ORDER BY col$column $direction ";
  196. $sql .= " LIMIT $from, $number_of_items";
  197. $res = Database::query($sql);
  198. $users = [];
  199. $webPath = api_get_path(WEB_PATH);
  200. while ($user = Database::fetch_row($res)) {
  201. $userPicture = UserManager::getUserPicture($user[0]);
  202. $photo = '<img src="'.$userPicture.'" alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" />';
  203. $user_id = $user[0];
  204. $button = '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')">
  205. <img onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" src="'.$webPath.'img/view_more_stats.gif" title="'.get_lang('Courses').'" alt="'.get_lang('Courses').'"/>
  206. </a>&nbsp;&nbsp;';
  207. $users[] = [
  208. $photo,
  209. $user[1],
  210. $user[2],
  211. $user[3],
  212. $user[4],
  213. $user[5],
  214. $button,
  215. ];
  216. }
  217. return $users;
  218. }
  219. Display::display_header('Reports');
  220. echo '<div class="actions">
  221. <form action="'.api_get_self().'" method="get" name="search_simple" id="search_simple">
  222. <input name="user_id_request" id="user_id_request" type="hidden" value="">
  223. <span><label for="keyword">B&uacute;squeda del usuario: </label><input size="25" name="keyword" type="text" id="keyword"></span>
  224. <span><button class="search" name="submit" type="submit">Buscar</button></span>
  225. <div class="clear">&nbsp;</div>
  226. </form></div>';
  227. if (isset($_GET['keyword'])) {
  228. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() || api_sort_by_first_name()) ? 3 : 2);
  229. $table->set_header(0, '', false, 'width="18px"');
  230. $table->set_header(0, get_lang('Photo'), false);
  231. $table->set_header(1, get_lang('OfficialCode'));
  232. if (api_is_western_name_order()) {
  233. $table->set_header(2, get_lang('FirstName'));
  234. $table->set_header(3, get_lang('LastName'));
  235. } else {
  236. $table->set_header(2, get_lang('LastName'));
  237. $table->set_header(3, get_lang('FirstName'));
  238. }
  239. $table->set_header(4, get_lang('LoginName'));
  240. $table->set_header(5, get_lang('Email'));
  241. $table->set_header(6, get_lang('Action'));
  242. $table->display();
  243. }
  244. if (isset($_POST['report'])) {
  245. $course_info = api_get_course_info_by_id($course_id);
  246. $course_id = Database::escape_string($_POST['course_id']);
  247. $tool = Database::escape_string($_POST['tool']);
  248. $user_id = intval($_POST['user_id_request']);
  249. $sql = "SELECT
  250. u.username , CONCAT(u.lastname, ' ', u.firstname) AS fullname,
  251. DATE_SUB(access.access_date,INTERVAL 5 HOUR) AS access_date,
  252. c.title AS course, access_tool AS tool
  253. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS)." access
  254. LEFT JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u ON access.access_user_id = u.user_id
  255. LEFT JOIN ".Database::get_main_table(TABLE_MAIN_COURSE)." c ON access.c_id = c.id
  256. WHERE access.c_id = ".$course_info['real_id']." AND u.user_id = $user_id ";
  257. if ($tool != '') {
  258. $sql .= "AND access.access_tool = '$tool' ";
  259. }
  260. $start_date = Database::escape_string($_POST['keyword_start_date_start']);
  261. $end_date = Database::escape_string($_POST['keyword_start_date_end']);
  262. if ($start_date != '' || $end_date != '') {
  263. $sql .= " HAVING ";
  264. if ($start_date != '') {
  265. $sql .= " access_date >= '$start_date' ";
  266. }
  267. if ($end_date != '') {
  268. $sql = ($start_date == '') ? $sql : ($sql." AND ");
  269. $sql .= " access_date <= '$end_date' ";
  270. }
  271. }
  272. $result = Database::query($sql);
  273. $table_result = new SortableTable();
  274. $table_result->set_header(0, get_lang('User'), false);
  275. $table_result->set_header(1, get_lang('FullUserName'), false);
  276. $table_result->set_header(2, get_lang('Date'), false);
  277. $table_result->set_header(3, get_lang('Course'), false);
  278. $table_result->set_header(4, get_lang('Tool'), false);
  279. while ($row = Database::fetch_assoc($result)) {
  280. $row = [
  281. $row['username'],
  282. $row['fullname'],
  283. $row['access_date'],
  284. $row['course'],
  285. get_lang($tools[$row['tool']]['name']),
  286. ];
  287. $table_result->addRow($row);
  288. }
  289. $table_result->display();
  290. } else {
  291. show_form();
  292. }
  293. Display::display_footer();