userlogCSV.php 12 KB

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