report.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.plugin.ticket
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. api_block_anonymous_users();
  8. if (!api_is_allowed_to_edit()) {
  9. api_not_allowed();
  10. }
  11. $this_section = 'Reports';
  12. unset($_SESSION['this_section']);
  13. $htmlHeadXtra[] = '<script>
  14. $(document).ready(function(){
  15. $( "#keyword_start_date_start" ).datepicker({ dateFormat: ' . "'yy-mm-dd'".' });
  16. $( "#keyword_start_date_end" ).datepicker({ dateFormat: ' . "'yy-mm-dd'".' });
  17. });
  18. function validate() {
  19. if( $("#keyword_start_date_start").val() != "" && $("#keyword_start_date_end").val() != ""){
  20. datestart = $("#keyword_start_date_start").val();
  21. dateend = $("#keyword_start_date_end").val();
  22. dif = $.datepicker.parseDate("dd/mm/yy", datestart) - $.datepicker.parseDate("dd/mm/yy", dateend);
  23. if(dif > 0){
  24. alert("La fecha final no puede ser mayor a la fecha inicial");
  25. return false;
  26. }
  27. }
  28. }
  29. function load_course_list (div_course,my_user_id) {
  30. $.ajax({
  31. contentType: "application/x-www-form-urlencoded",
  32. type: "GET",
  33. url: "course_user_list.php",
  34. data: "user_id="+my_user_id,
  35. success: function(datos) {
  36. $("div#user_request").html(datos);
  37. $("#btnsubmit").attr("disabled", false);
  38. }
  39. });
  40. }
  41. </script>
  42. <style>
  43. div.row div.label2 {
  44. float:left;
  45. width:10%;
  46. }
  47. div.row div.formw2 {
  48. width:90%;
  49. float:left
  50. }
  51. div.ticket-form {
  52. width: 70%;
  53. float: center;
  54. margin-left: 15%;
  55. }
  56. </style>';
  57. $types = TicketManager::get_all_tickets_categories();
  58. $tools = array();
  59. $tools['todas'] = array('id' => '', 'name' => get_lang('All'));
  60. $tools['announcement'] = array('id' => 'announcement', 'name' => get_lang('Announcement'));
  61. // $tools[]= array('id'=>'assignment','name'=>get_lang('Assignment'));
  62. $tools['calendar_event'] = array('id' => 'calendar_event', 'name' => get_lang('ToolCalendarEvent'));
  63. $tools['chat'] = array('id' => 'chat', 'name' => get_lang('Chat'));
  64. $tools['course_description'] = array('id' => 'course_description', 'name' => get_lang('CourseDescription'));
  65. $tools['document'] = array('id' => 'document', 'name' => get_lang('Document'));
  66. $tools['dropbox'] = array('id' => 'dropbox', 'name' => get_lang('Dropbox'));
  67. $tools['group'] = array('id' => 'group', 'name' => get_lang('Group'));
  68. $tools['learnpath'] = array('id' => 'learnpath', 'name' => get_lang('Learnpath'));
  69. $tools['link'] = array('id' => 'link', 'name' => get_lang('Link'));
  70. $tools['quiz'] = array('id' => 'quiz', 'name' => get_lang('Quiz'));
  71. $tools['student_publication'] = array('id' => 'student_publication', 'name' => get_lang('ToolStudentPublication'));
  72. $tools['user'] = array('id' => 'user', 'name' => get_lang('User'));
  73. $tools['forum'] = array('id' => 'forum', 'name' => get_lang('Forum'));
  74. /**
  75. * Returns the escaped string.
  76. * @param string $s
  77. * @return string
  78. */
  79. function js_str($s)
  80. {
  81. return '"'.addcslashes($s, "\0..\37\"\\").'"';
  82. }
  83. /**
  84. * This function is to show the ticket form
  85. * @global array $tools
  86. */
  87. function show_form()
  88. {
  89. global $tools;
  90. echo '<div class="ticket-form">';
  91. echo '<form enctype="multipart/form-data" action="'.api_get_self().'" method="post" name="send_ticket" id="send_ticket"
  92. onsubmit="return validate()" style="width:100%">';
  93. $select_course = '<div id="user_request" >
  94. </div>';
  95. echo $select_course;
  96. //select status
  97. $select_tool = '<div class="row" >
  98. <div class="label2" >' . get_lang('Tool').':</div>
  99. <div class="formw2">';
  100. $select_tool .= '<select style="width: 95%; " name = "tool" id="tool" >';
  101. foreach ($tools as $tool) {
  102. $select_tool .= "<option value = '".$tool['id']."' selected >".$tool['name']."</option>";
  103. }
  104. $select_tool .= "</select>";
  105. $select_tool .= '</div></div>';
  106. echo $select_tool;
  107. echo '<div class="row">
  108. <div class="label2">' . get_lang('From').':</div>
  109. <div class="formw2"><input id="keyword_start_date_start" name="keyword_start_date_start" type="text"></div>
  110. </div>
  111. <div class="row">
  112. <div class="label2"> ' . get_lang('To').'</div>
  113. <div class="formw2"><input id="keyword_start_date_end" name="keyword_start_date_end" type="text"></div>
  114. </div>';
  115. echo '</div>';
  116. echo '<div class="row">
  117. <div class="label2">
  118. </div>
  119. <div class="formw2">
  120. <button class="save" name="report" type="submit" id="btnsubmit" disabled="disabled">' . get_lang('CompleteReport').'</button>
  121. </div>
  122. </div>';
  123. }
  124. /**
  125. * Get the total number of users on the platform
  126. * @see SortableTable#get_total_number_of_items()
  127. */
  128. function get_number_of_users()
  129. {
  130. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  131. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  132. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  133. $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  134. $sql .= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  135. }
  136. if (isset($_GET['keyword'])) {
  137. $keyword = Database::escape_string(trim($_GET['keyword']));
  138. $sql .= " WHERE (u.firstname LIKE '%$keyword%' OR
  139. u.lastname LIKE '%$keyword%' OR
  140. concat(u.firstname,' ',u.lastname) LIKE '%$keyword%' OR
  141. concat(u.lastname,' ',u.firstname) LIKE '%$keyword%' OR
  142. u.username LIKE '%$keyword%' OR
  143. u.email LIKE '%$keyword %' OR
  144. u.official_code LIKE '%$keyword%') ";
  145. }
  146. $res = Database::query($sql);
  147. $obj = Database::fetch_object($res);
  148. return $obj->total_number_of_items;
  149. }
  150. /**
  151. * Get the users to display on the current page (fill the sortable-table)
  152. * @param int offset of first user to recover
  153. * @param int Number of users to get
  154. * @param int Column to sort on
  155. * @param string Order (ASC,DESC)
  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, array('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 = array();
  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[] = array(
  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. if ($end_date != '') {
  267. $sql = ($start_date == '') ? $sql : ($sql." AND ");
  268. $sql .= " access_date <= '$end_date' ";
  269. }
  270. }
  271. $result = Database::query($sql);
  272. $table_result = new SortableTable();
  273. $table_result->set_header(0, get_lang('User'), false);
  274. $table_result->set_header(1, get_lang('FullUserName'), false);
  275. $table_result->set_header(2, get_lang('Date'), false);
  276. $table_result->set_header(3, get_lang('Course'), false);
  277. $table_result->set_header(4, get_lang('Tool'), false);
  278. while ($row = Database::fetch_assoc($result)) {
  279. $row = array(
  280. $row['username'],
  281. $row['fullname'],
  282. $row['access_date'],
  283. $row['course'],
  284. get_lang($tools[$row['tool']]['name'])
  285. );
  286. $table_result->addRow($row);
  287. }
  288. $table_result->display();
  289. } else {
  290. show_form();
  291. }
  292. Display::display_footer();