userlogCSV.php 12 KB

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