report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. * Returns the escaped string.
  79. *
  80. * @param string $s
  81. *
  82. * @return string
  83. */
  84. function js_str($s)
  85. {
  86. return '"'.addcslashes($s, "\0..\37\"\\").'"';
  87. }
  88. /**
  89. * This function is to show the ticket form.
  90. *
  91. * @global array $tools
  92. */
  93. function show_form()
  94. {
  95. global $tools;
  96. echo '<div class="ticket-form">';
  97. echo '<form enctype="multipart/form-data" action="'.api_get_self().'" method="post" name="send_ticket" id="send_ticket"
  98. onsubmit="return validate()" style="width:100%">';
  99. $select_course = '<div id="user_request" >
  100. </div>';
  101. echo $select_course;
  102. //select status
  103. $select_tool = '<div class="row" >
  104. <div class="label2" >'.get_lang('Tool').':</div>
  105. <div class="formw2">';
  106. $select_tool .= '<select style="width: 95%; " name = "tool" id="tool" >';
  107. foreach ($tools as $tool) {
  108. $select_tool .= "<option value = '".$tool['id']."' selected >".$tool['name']."</option>";
  109. }
  110. $select_tool .= "</select>";
  111. $select_tool .= '</div></div>';
  112. echo $select_tool;
  113. echo '<div class="row">
  114. <div class="label2">'.get_lang('From').':</div>
  115. <div class="formw2"><input id="keyword_start_date_start" name="keyword_start_date_start" type="text"></div>
  116. </div>
  117. <div class="row">
  118. <div class="label2"> '.get_lang('To').'</div>
  119. <div class="formw2"><input id="keyword_start_date_end" name="keyword_start_date_end" type="text"></div>
  120. </div>';
  121. echo '</div>';
  122. echo '<div class="row">
  123. <div class="label2">
  124. </div>
  125. <div class="formw2">
  126. <button class="save" name="report" type="submit" id="btnsubmit" disabled="disabled">'.get_lang('CompleteReport').'</button>
  127. </div>
  128. </div>';
  129. }
  130. /**
  131. * Get the total number of users on the platform.
  132. *
  133. * @see SortableTable#get_total_number_of_items()
  134. */
  135. function get_number_of_users()
  136. {
  137. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  138. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  139. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  140. $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  141. $sql .= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  142. }
  143. if (isset($_GET['keyword'])) {
  144. $keyword = Database::escape_string(trim($_GET['keyword']));
  145. $sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
  146. u.lastname LIKE '%$keyword%' OR
  147. concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
  148. concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
  149. u.username LIKE '%$keyword%' OR
  150. u.email LIKE '%$keyword %' OR
  151. u.official_code LIKE '%$keyword%') ";
  152. }
  153. $res = Database::query($sql);
  154. $obj = Database::fetch_object($res);
  155. return $obj->total_number_of_items;
  156. }
  157. /**
  158. * Get the users to display on the current page (fill the sortable-table).
  159. *
  160. * @param int offset of first user to recover
  161. * @param int Number of users to get
  162. * @param int Column to sort on
  163. * @param string Order (ASC,DESC)
  164. *
  165. * @return array
  166. *
  167. * @see SortableTable#get_table_data($from)
  168. */
  169. function get_user_data($from, $number_of_items, $column, $direction)
  170. {
  171. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  172. if (api_is_western_name_order()) {
  173. $col34 = "u.firstname AS col3,
  174. u.lastname AS col4,";
  175. } else {
  176. $col34 = "u.lastname AS col3,
  177. u.firstname AS col4,";
  178. }
  179. $sql = "SELECT
  180. u.user_id AS col0,
  181. u.official_code AS col2,
  182. $col34
  183. u.username AS col5,
  184. u.email AS col6,
  185. u.status AS col7,
  186. u.active AS col8,
  187. u.user_id AS col9,
  188. u.expiration_date AS exp
  189. FROM $user_table u ";
  190. if (isset($_GET['keyword'])) {
  191. $keyword = Database::escape_string(trim($_GET['keyword']));
  192. $sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
  193. u.lastname LIKE '%$keyword%' OR
  194. concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
  195. concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
  196. u.username LIKE '%$keyword%' OR
  197. u.official_code LIKE '%$keyword%'
  198. OR u.email LIKE '%$keyword%' )";
  199. }
  200. if (!in_array($direction, ['ASC', 'DESC'])) {
  201. $direction = 'ASC';
  202. }
  203. $column = intval($column);
  204. $from = intval($from);
  205. $number_of_items = intval($number_of_items);
  206. $sql .= " ORDER BY col$column $direction ";
  207. $sql .= " LIMIT $from, $number_of_items";
  208. $res = Database::query($sql);
  209. $users = [];
  210. $webPath = api_get_path(WEB_PATH);
  211. while ($user = Database::fetch_row($res)) {
  212. $userPicture = UserManager::getUserPicture($user[0]);
  213. $photo = '<img src="'.$userPicture.'" alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" />';
  214. $user_id = $user[0];
  215. $button = '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')">
  216. <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').'"/>
  217. </a>&nbsp;&nbsp;';
  218. $users[] = [
  219. $photo,
  220. $user[1],
  221. $user[2],
  222. $user[3],
  223. $user[4],
  224. $user[5],
  225. $button,
  226. ];
  227. }
  228. return $users;
  229. }
  230. Display::display_header('Reports');
  231. echo '<div class="actions">
  232. <form action="'.api_get_self().'" method="get" name="search_simple" id="search_simple">
  233. <input name="user_id_request" id="user_id_request" type="hidden" value="">
  234. <span><label for="keyword">B&uacute;squeda del usuario: </label><input size="25" name="keyword" type="text" id="keyword"></span>
  235. <span><button class="search" name="submit" type="submit">Buscar</button></span>
  236. <div class="clear">&nbsp;</div>
  237. </form></div>';
  238. if (isset($_GET['keyword'])) {
  239. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() || api_sort_by_first_name()) ? 3 : 2);
  240. $table->set_header(0, '', false, 'width="18px"');
  241. $table->set_header(0, get_lang('Photo'), false);
  242. $table->set_header(1, get_lang('OfficialCode'));
  243. if (api_is_western_name_order()) {
  244. $table->set_header(2, get_lang('FirstName'));
  245. $table->set_header(3, get_lang('LastName'));
  246. } else {
  247. $table->set_header(2, get_lang('LastName'));
  248. $table->set_header(3, get_lang('FirstName'));
  249. }
  250. $table->set_header(4, get_lang('LoginName'));
  251. $table->set_header(5, get_lang('Email'));
  252. $table->set_header(6, get_lang('Action'));
  253. $table->display();
  254. }
  255. if (isset($_POST['report'])) {
  256. $course_info = api_get_course_info_by_id($course_id);
  257. $course_id = Database::escape_string($_POST['course_id']);
  258. $tool = Database::escape_string($_POST['tool']);
  259. $user_id = intval($_POST['user_id_request']);
  260. $sql = "SELECT
  261. u.username , CONCAT(u.lastname, ' ', u.firstname) AS fullname,
  262. DATE_SUB(access.access_date,INTERVAL 5 HOUR) AS access_date,
  263. c.title AS course, access_tool AS tool
  264. FROM ".Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS)." access
  265. LEFT JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u ON access.access_user_id = u.user_id
  266. LEFT JOIN ".Database::get_main_table(TABLE_MAIN_COURSE)." c ON access.c_id = c.id
  267. WHERE access.c_id = ".$course_info['real_id']." AND u.user_id = $user_id ";
  268. if ($tool != '') {
  269. $sql .= "AND access.access_tool = '$tool' ";
  270. }
  271. $start_date = Database::escape_string($_POST['keyword_start_date_start']);
  272. $end_date = Database::escape_string($_POST['keyword_start_date_end']);
  273. if ($start_date != '' || $end_date != '') {
  274. $sql .= " HAVING ";
  275. if ($start_date != '') {
  276. $sql .= " access_date >= '$start_date' ";
  277. }
  278. if ($end_date != '') {
  279. $sql = ($start_date == '') ? $sql : ($sql." AND ");
  280. $sql .= " access_date <= '$end_date' ";
  281. }
  282. }
  283. $result = Database::query($sql);
  284. $table_result = new SortableTable();
  285. $table_result->set_header(0, get_lang('User'), false);
  286. $table_result->set_header(1, get_lang('FullUserName'), false);
  287. $table_result->set_header(2, get_lang('Date'), false);
  288. $table_result->set_header(3, get_lang('Course'), false);
  289. $table_result->set_header(4, get_lang('Tool'), false);
  290. while ($row = Database::fetch_assoc($result)) {
  291. $row = [
  292. $row['username'],
  293. $row['fullname'],
  294. $row['access_date'],
  295. $row['course'],
  296. get_lang($tools[$row['tool']]['name']),
  297. ];
  298. $table_result->addRow($row);
  299. }
  300. $table_result->display();
  301. } else {
  302. show_form();
  303. }
  304. Display::display_footer();