report.php 12 KB

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