userlogCSV.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // TODO: Is this file deprecated?
  4. /**
  5. * @package chamilo.tracking
  6. * @todo clean code - structure is unclear and difficult to modify
  7. */
  8. /**
  9. * Code
  10. */
  11. /* INIT SECTION */
  12. $uInfo = $_REQUEST['uInfo'];
  13. $view = $_REQUEST['view'];
  14. // name of the language file that needs to be included
  15. $language_file = 'tracking';
  16. require_once '../inc/global.inc.php';
  17. // Roles and rights system
  18. $user_id = api_get_user_id();
  19. $course_id = api_get_course_id();
  20. /*
  21. $role_id = RolesRights::get_local_user_role_id($user_id, $course_id);
  22. $location_id = RolesRights::get_course_tool_location_id($course_id, TOOL_TRACKING);
  23. $is_allowed = RolesRights::is_allowed_which_rights($role_id, $location_id);
  24. //block users without view right
  25. RolesRights::protect_location($role_id, $location_id);
  26. */
  27. //YW Hack security to quick fix RolesRights bug
  28. $is_allowed = true;
  29. /* Libraries */
  30. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  31. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  32. require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php';
  33. /* Header */
  34. /*
  35. $interbreadcrumb[]= array ("url"=>"../group/group.php", "name"=> get_lang('BredCrumpGroups'));
  36. $interbreadcrumb[]= array ("url"=>"../group/group_space.php?gidReq=$_gid", "name"=> get_lang('BredCrumpGroupSpace'));
  37. */
  38. if($uInfo)
  39. {
  40. $interbreadcrumb[]= array ("url"=>"../user/userInfo.php?uInfo=$uInfo", "name"=> get_lang('BredCrumpUsers'));
  41. }
  42. $nameTools = get_lang('ToolName');
  43. /* Constants and variables */
  44. $is_allowedToTrack = $is_courseAdmin;
  45. $is_course_member = CourseManager::is_user_subscribed_in_real_or_linked_course($user_id, $course_id);
  46. // Database Table Definitions
  47. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  48. $TABLEUSER = Database::get_main_table(TABLE_MAIN_USER);
  49. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  50. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  51. $TABLECOURSE_GROUPSUSER = Database::get_course_table(TABLE_GROUP_USER);
  52. if(api_get_setting('use_session_mode') == "true") {
  53. $sql = "SELECT 1
  54. FROM $tbl_session_course_user AS session_course_user
  55. INNER JOIN $tbl_session AS session
  56. ON session_course_user.id_session = session.id
  57. AND ((date_start<=NOW()
  58. AND date_end>=NOW())
  59. OR (date_start='0000-00-00' AND date_end='0000-00-00'))
  60. WHERE id_session='".$_SESSION['id_session']."' AND course_code='$_cid'";
  61. //echo $sql;
  62. $result=Database::query($sql);
  63. if(!Database::num_rows($result)){
  64. $disabled = true;
  65. }
  66. }
  67. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  68. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  69. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  70. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  71. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  72. // The variables for the days and the months
  73. $DaysShort = api_get_week_days_short();
  74. $DaysLong = api_get_week_days_long();
  75. $MonthsLong = api_get_months_long();
  76. $MonthsShort = api_get_months_short();
  77. //$is_allowedToTrack = $is_groupTutor; // allowed to track only user of one group
  78. //$is_allowedToTrackEverybodyInCourse = $is_allowed[EDIT_RIGHT]; // allowed to track all students in course
  79. //YW hack security to fix RolesRights bug
  80. $is_allowedToTrack = true; // allowed to track only user of one group
  81. $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track all students in course
  82. /* MAIN SECTION */
  83. $title[0]='';
  84. $title[1]='';
  85. $line='';
  86. $title_line='';
  87. // check if uid is tutor of this group
  88. if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse))
  89. {
  90. if(!$uInfo && !isset($uInfo) )
  91. {
  92. /*
  93. * Display list of user of this group
  94. */
  95. if( $is_allowedToTrackEverybodyInCourse )
  96. {
  97. // if user can track everybody : list user of course
  98. if(api_get_setting('use_session_mode')) {
  99. $sql = "SELECT count(user_id)
  100. FROM $TABLECOURSUSER
  101. WHERE course_code = '$_cid' AND relation_type<>".COURSE_RELATION_TYPE_RRHH."";
  102. }
  103. else {
  104. $sql = "SELECT count(id_user)
  105. FROM $tbl_session_course_user
  106. WHERE course_code = '$_cid'";
  107. }
  108. }
  109. else
  110. {
  111. // if user can only track one group : list users of this group
  112. $sql = "SELECT count(user)
  113. FROM $TABLECOURSE_GROUPSUSER
  114. WHERE group_id = '$_gid'";
  115. }
  116. $userGroupNb = getOneResult($sql);
  117. $step = 25; // number of student per page
  118. if ($userGroupNb > $step)
  119. {
  120. if(!isset($offset))
  121. {
  122. $offset=0;
  123. }
  124. $next = $offset + $step;
  125. $previous = $offset - $step;
  126. $navLink = "";
  127. if ($previous >= 0)
  128. {
  129. }
  130. if ($next < $userGroupNb)
  131. {
  132. }
  133. }
  134. else
  135. {
  136. $offset = 0;
  137. }
  138. echo $navLink;
  139. if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.'); //sanity check of integer vars
  140. if( $is_allowedToTrackEverybodyInCourse )
  141. {
  142. // list of users in this course
  143. $sql = "SELECT u.user_id, u.firstname,u.lastname
  144. FROM $TABLECOURSUSER cu , $TABLEUSER u
  145. WHERE cu.user_id = u.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH."
  146. AND cu.course_code = '$_cid'
  147. LIMIT $offset,$step";
  148. }
  149. else
  150. {
  151. // list of users of this group
  152. $sql = "SELECT u.user_id, u.firstname,u.lastname
  153. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  154. WHERE gu.user_id = u.user_id
  155. AND gu.group_id = '$_gid'
  156. LIMIT $offset,$step";
  157. }
  158. $list_users = getManyResults3Col($sql);
  159. for($i = 0 ; $i < sizeof($list_users) ; $i++)
  160. {
  161. }
  162. }
  163. else // if uInfo is set
  164. {
  165. /*
  166. * Informations about student uInfo
  167. */
  168. // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
  169. // another course, or group
  170. if( $is_allowedToTrackEverybodyInCourse )
  171. {
  172. // check if user is in this course
  173. $tracking_is_accepted = $is_course_member;
  174. $tracked_user_info = Database::get_user_info_from_id($uInfo);
  175. $title[0]=$tracked_user_info[1].'_'.$tracked_user_info[2];
  176. }
  177. else
  178. {
  179. // check if user is in the group of this tutor
  180. $sql = "SELECT u.firstname,u.lastname, u.email
  181. FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
  182. WHERE gu.user_id = u.user_id
  183. AND gu.group_id = '$_gid'
  184. AND u.user_id = '$uInfo'";
  185. $query = Database::query($sql);
  186. $tracked_user_info = @Database::fetch_assoc($query);
  187. if(is_array($tracked_user_info)) $tracking_is_accepted = true;
  188. $title[0] = $tracked_user_info['firstname'].'_'.$tracked_user_info['lastname'];
  189. }
  190. if ($tracking_is_accepted)
  191. {
  192. $tracked_user_info['email'] == '' ? $mail_link = get_lang('NoEmail') : $mail_link = Display::encrypted_mailto_link($tracked_user_info['email']);
  193. if(!isset($view))
  194. {
  195. $view ='0000000';
  196. }
  197. //Logins
  198. list($title_line1, $line1) = TrackingUserLogCSV::display_login_tracking_info($view, $uInfo, $_cid);
  199. //Exercise results
  200. list($title_line2, $line2) = TrackingUserLogCSV::display_exercise_tracking_info($view, $uInfo, $_cid);
  201. //Student publications uploaded
  202. list($title_line3, $line3) = TrackingUserLogCSV::display_student_publications_tracking_info($view, $uInfo, $_cid);
  203. //Links usage
  204. list($title_line4, $line4) = TrackingUserLogCSV::display_links_tracking_info($view, $uInfo, $_cid);
  205. //Documents downloaded
  206. list($title_line5, $line5) = TrackingUserLogCSV::display_document_tracking_info($view, $uInfo, $_cid);
  207. $title_line = $title_line1.$title_line2.$title_line3.$title_line4.$title_line5;
  208. $line= $line1.$line2.$line3.$line4.$line5;
  209. }
  210. else
  211. {
  212. echo get_lang('ErrorUserNotInGroup');
  213. }
  214. /*
  215. * Scorm contents and Learning Path
  216. */
  217. //TODO: scorm tools is in work and the logs will change in few days...
  218. /*if(substr($view,5,1) == '1')
  219. {
  220. $new_view = substr_replace($view,'0',5,1);
  221. $title[1]=get_lang('ScormContentColumn');
  222. $line ='';
  223. $sql = "SELECT id, name FROM $tbl_learnpath_main";
  224. $result=Database::query($sql);
  225. $ar=Database::fetch_array($result);
  226. if (is_array($ar))
  227. {
  228. while ($ar['id'] != '') {
  229. $lp_title = stripslashes($ar['name']);
  230. echo "<tr><td>";
  231. echo "<a href='".api_get_self()."?view=".$view."&scormcontopen=".$ar['id']."&uInfo=$uInfo' class='specialLink'>$lp_title</a>";
  232. echo "</td></tr>";
  233. if ($ar['id']==$scormcontopen) { //have to list the students here
  234. $contentId=$ar['id'];
  235. $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " .
  236. "FROM $tbl_learnpath_item i " .
  237. "INNER JOIN $tbl_learnpath_item_view iv ON i.id=iv.lp_item_id " .
  238. "INNER JOIN $tbl_learnpath_view v ON iv.lp_view_id=v.id " .
  239. "WHERE (v.user_id=$uInfo and v.lp_id=$contentId) ORDER BY v.id, i.id";
  240. $result3=Database::query($sql3);
  241. $ar3=Database::fetch_array($result3);
  242. if (is_array($ar3)) {
  243. $title_line=get_lang('ScormTitleColumn').";".get_lang('ScormStatusColumn').";".get_lang('ScormScoreColumn').";".get_lang('ScormTimeColumn')."\n";
  244. while ($ar3['status'] != '') {
  245. require_once('../newscorm/learnpathItem.class.php');
  246. $time = learnpathItem::get_scorm_time('php',$ar3['total_time']);
  247. $line .= $title.';'.$ar3['status'].';'.$ar3['score'].';'.$time."\n";
  248. $ar3=Database::fetch_array($result3);
  249. }
  250. } else {
  251. $line .= get_lang('ScormNeverOpened');
  252. }
  253. }
  254. $ar=Database::fetch_array($result);
  255. }
  256. }
  257. else
  258. {
  259. $noscorm=true;
  260. }
  261. if ($noscorm) {
  262. $line=get_lang('NoResult');
  263. }
  264. }
  265. else
  266. {
  267. $new_view = substr_replace($view,'1',5,1);
  268. }*/
  269. }
  270. /*
  271. * Export to a CSV file
  272. * force the browser to save the file instead of opening it
  273. */
  274. $len = strlen($title_line.$line);
  275. header('Content-type: application/octet-stream');
  276. //header('Content-Type: application/force-download');
  277. header('Content-length: '.$len);
  278. $filename = html_entity_decode(str_replace(":","",str_replace(" ","_", $title[0].'_'.$title[1].'.csv')));
  279. $filename = replace_dangerous_char($filename);
  280. if(preg_match("/MSIE 5.5/",$_SERVER['HTTP_USER_AGENT']))
  281. {
  282. header('Content-Disposition: filename= '.$filename);
  283. }
  284. else
  285. {
  286. header('Content-Disposition: attachment; filename= '.$filename);
  287. }
  288. if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
  289. {
  290. header('Pragma: ');
  291. header('Cache-Control: ');
  292. header('Cache-Control: public'); // IE cannot download from sessions without a cache
  293. }
  294. header('Content-Description: '.$filename);
  295. header('Content-transfer-encoding: binary');
  296. echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
  297. echo api_html_entity_decode($line, ENT_QUOTES, $charset);
  298. exit;
  299. }
  300. // not allowed
  301. else
  302. {
  303. api_not_allowed();
  304. }