report.php 12 KB

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