report.php 12 KB

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