events.lib.inc.php 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * EVENTS LIBRARY
  5. *
  6. * This is the events library for Chamilo.
  7. * Include/require it in your code to use its functionality.
  8. * Functions of this library are used to record informations when some kind
  9. * of event occur. Each event has his own types of informations then each event
  10. * use its own function.
  11. *
  12. * @package chamilo.library
  13. */
  14. /* INIT SECTION */
  15. $TABLETRACK_LOGIN = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  16. $TABLETRACK_OPEN = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_OPEN);
  17. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  18. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  19. $TABLETRACK_UPLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_UPLOADS);
  20. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  21. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  22. //$TABLETRACK_SUBSCRIPTIONS = $_configuration['statistics_database'].".track_e_subscriptions"; // this table is never use
  23. $TABLETRACK_LASTACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); //for "what's new" notification
  24. $TABLETRACK_DEFAULT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
  25. /* FUNCTIONS */
  26. /**
  27. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  28. * @desc Record information for open event (when homepage is opened)
  29. */
  30. function event_open() {
  31. global $_configuration;
  32. global $TABLETRACK_OPEN;
  33. // @getHostByAddr($_SERVER['REMOTE_ADDR']) : will provide host and country information
  34. // $_SERVER['HTTP_USER_AGENT'] : will provide browser and os information
  35. // $_SERVER['HTTP_REFERER'] : provide information about refering url
  36. if(isset($_SERVER['HTT_REFERER']))
  37. {
  38. $referer = Database::escape_string($_SERVER['HTTP_REFERER']);
  39. } else {
  40. $referer = '';
  41. }
  42. // record informations only if user comes from another site
  43. //if(!eregi($_configuration['root_web'],$referer))
  44. $pos = strpos($referer, $_configuration['root_web']);
  45. if ($pos === false && $referer != '') {
  46. $remhost = @ getHostByAddr($_SERVER['REMOTE_ADDR']);
  47. if ($remhost == $_SERVER['REMOTE_ADDR'])
  48. $remhost = "Unknown"; // don't change this
  49. $reallyNow = api_get_utc_datetime();
  50. $sql = "INSERT INTO ".$TABLETRACK_OPEN."
  51. (open_remote_host,
  52. open_agent,
  53. open_referer,
  54. open_date)
  55. VALUES
  56. ('".$remhost."',
  57. '".Database::escape_string($_SERVER['HTTP_USER_AGENT'])."', '".Database::escape_string($referer)."', '$reallyNow')";
  58. $res = Database::query($sql);
  59. }
  60. return 1;
  61. }
  62. /**
  63. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  64. * @desc Record information for login event
  65. * (when an user identifies himself with username & password)
  66. */
  67. function event_login() {
  68. global $_user;
  69. global $TABLETRACK_LOGIN;
  70. $reallyNow = api_get_utc_datetime();
  71. $sql = "INSERT INTO ".$TABLETRACK_LOGIN." (login_user_id, login_ip, login_date, logout_date)
  72. VALUES ('".$_user['user_id']."',
  73. '".Database::escape_string($_SERVER['REMOTE_ADDR'])."',
  74. '".$reallyNow."',
  75. '".$reallyNow."'
  76. )";
  77. $res = Database::query($sql);
  78. }
  79. /**
  80. * @param tool name of the tool (name in mainDb.accueil table)
  81. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  82. * @desc Record information for access event for courses
  83. */
  84. function event_access_course() {
  85. global $_user;
  86. global $_cid;
  87. global $TABLETRACK_ACCESS;
  88. global $TABLETRACK_LASTACCESS; //for "what's new" notification
  89. $id_session = api_get_session_id();
  90. $reallyNow = api_get_utc_datetime();
  91. if ($_user['user_id']) {
  92. $user_id = "'".$_user['user_id']."'";
  93. } else {
  94. $user_id = "0"; // no one
  95. }
  96. $sql = "INSERT INTO ".$TABLETRACK_ACCESS." (access_user_id, access_cours_code, access_date, access_session_id) VALUES
  97. (".$user_id.", '".$_cid."', '".$reallyNow."','".$id_session."')";
  98. $res = Database::query($sql);
  99. // added for "what's new" notification
  100. $sql = "UPDATE $TABLETRACK_LASTACCESS SET access_date = '$reallyNow'
  101. WHERE access_user_id = $user_id AND access_cours_code = '$_cid' AND access_tool IS NULL AND access_session_id=".$id_session;
  102. $res = Database::query($sql);
  103. if (Database::affected_rows() == 0) {
  104. $sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id, access_cours_code, access_date, access_session_id)
  105. VALUES (".$user_id.", '".$_cid."', '$reallyNow', '".$id_session."')";
  106. $res = Database::query($sql);
  107. }
  108. // end "what's new" notification
  109. return 1;
  110. }
  111. /**
  112. * @param tool name of the tool (name in mainDb.accueil table)
  113. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  114. * @desc Record information for access event for tools
  115. *
  116. * $tool can take this values :
  117. * Links, Calendar, Document, Announcements,
  118. * Group, Video, Works, Users, Exercices, Course Desc
  119. * ...
  120. * Values can be added if new modules are created (15char max)
  121. * I encourage to use $nameTool as $tool when calling this function
  122. *
  123. * Functionality for "what's new" notification is added by Toon Van Hoecke
  124. */
  125. function event_access_tool($tool, $id_session=0) {
  126. global $_configuration;
  127. global $_user;
  128. global $_cid;
  129. global $TABLETRACK_ACCESS;
  130. global $_course;
  131. global $TABLETRACK_LASTACCESS; //for "what's new" notification
  132. $id_session = api_get_session_id();
  133. $tool = Database::escape_string($tool);
  134. $reallyNow = api_get_utc_datetime();
  135. $user_id = $_user['user_id'] ? "'".$_user['user_id']."'" : "0"; // no one
  136. // record information
  137. // only if user comes from the course $_cid
  138. //if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
  139. //$pos = strpos($_SERVER['HTTP_REFERER'],$_configuration['root_web'].$_cid);
  140. $pos = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_COURSE_PATH).$_course['path'])) : false;
  141. // added for "what's new" notification
  142. $pos2 = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower($_configuration['root_web']."index")) : false;
  143. // end "what's new" notification
  144. if ($pos !== false || $pos2 !== false) {
  145. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  146. (access_user_id,
  147. access_cours_code,
  148. access_tool,
  149. access_date,
  150. access_session_id
  151. )
  152. VALUES
  153. (".$user_id.",".// Don't add ' ' around value, it's already done.
  154. "'".$_cid."' ,
  155. '".$tool."',
  156. '".$reallyNow."',
  157. '".$id_session."')";
  158. $res = Database::query($sql);
  159. }
  160. // "what's new" notification
  161. $sql = "UPDATE $TABLETRACK_LASTACCESS
  162. SET access_date = '$reallyNow'
  163. WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool = '".$tool."' AND access_session_id=".$id_session;
  164. $res = Database::query($sql);
  165. if (Database::affected_rows() == 0) {
  166. $sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id,access_cours_code,access_tool, access_date, access_session_id)
  167. VALUES (".$user_id.", '".$_cid."' , '$tool', '$reallyNow', $id_session)";
  168. $res = Database::query($sql);
  169. }
  170. return 1;
  171. }
  172. /**
  173. * @param doc_id id of document (id in mainDb.document table)
  174. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  175. * @desc Record information for download event
  176. * (when an user click to d/l a document)
  177. * it will be used in a redirection page
  178. * bug fixed: Roan Embrechts
  179. * Roan:
  180. * The user id is put in single quotes,
  181. * (why? perhaps to prevent sql insertion hacks?)
  182. * and later again.
  183. * Doing this twice causes an error, I remove one of them.
  184. */
  185. function event_download($doc_url) {
  186. $tbl_stats_downloads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  187. $doc_url = Database::escape_string($doc_url);
  188. $reallyNow = api_get_utc_datetime();
  189. $user_id = "'".api_get_user_id()."'";
  190. $_cid = api_get_course_id();
  191. $sql = "INSERT INTO $tbl_stats_downloads (
  192. down_user_id,
  193. down_cours_id,
  194. down_doc_path,
  195. down_date,
  196. down_session_id
  197. )
  198. VALUES (
  199. ".$user_id.",
  200. '".$_cid."',
  201. '".$doc_url."',
  202. '".$reallyNow."',
  203. '".api_get_session_id()."'
  204. )";
  205. $res = Database::query($sql);
  206. return 1;
  207. }
  208. /**
  209. * @param doc_id id of document (id in mainDb.document table)
  210. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  211. * @desc Record information for upload event
  212. * used in the works tool to record informations when
  213. * an user upload 1 work
  214. */
  215. function event_upload($doc_id) {
  216. global $_user;
  217. global $_cid;
  218. global $TABLETRACK_UPLOADS;
  219. $reallyNow = api_get_utc_datetime();
  220. if (isset($_user['user_id']) && $_user['user_id']!='') {
  221. $user_id = "'".$_user['user_id']."'";
  222. } else {
  223. $user_id = "0"; // anonymous
  224. }
  225. $sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
  226. ( upload_user_id,
  227. upload_cours_id,
  228. upload_work_id,
  229. upload_date,
  230. upload_session_id
  231. )
  232. VALUES (
  233. ".$user_id.",
  234. '".$_cid."',
  235. '".$doc_id."',
  236. '".$reallyNow."',
  237. '".api_get_session_id()."'
  238. )";
  239. $res = Database::query($sql);
  240. return 1;
  241. }
  242. /**
  243. * @param link_id (id in coursDb liens table)
  244. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  245. * @desc Record information for link event (when an user click on an added link)
  246. * it will be used in a redirection page
  247. */
  248. function event_link($link_id) {
  249. global $_user, $TABLETRACK_LINKS;
  250. $reallyNow = api_get_utc_datetime();
  251. if (isset($_user['user_id']) && $_user['user_id']!='') {
  252. $user_id = "'".Database::escape_string($_user['user_id'])."'";
  253. } else {
  254. // anonymous
  255. $user_id = "0";
  256. }
  257. $sql = "INSERT INTO ".$TABLETRACK_LINKS."
  258. ( links_user_id,
  259. links_cours_id,
  260. links_link_id,
  261. links_date,
  262. links_session_id
  263. ) VALUES (
  264. ".$user_id.",
  265. '".api_get_course_id()."',
  266. '".Database::escape_string($link_id)."',
  267. '".$reallyNow."',
  268. '".api_get_session_id()."'
  269. )";
  270. $res = Database::query($sql);
  271. return 1;
  272. }
  273. /**
  274. * Update the TRACK_E_EXERCICES exercises
  275. *
  276. * @param int exeid id of the attempt
  277. * @param int exo_id exercise id
  278. * @param mixed result score
  279. * @param int weighting ( higher score )
  280. * @param int duration ( duration of the attempt, in seconds )
  281. * @param int session_id
  282. * @param int learnpath_id (id of the learnpath)
  283. * @param int learnpath_item_id (id of the learnpath_item)
  284. *
  285. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  286. * @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
  287. * @desc Record result of user when an exercice was done
  288. */
  289. function update_event_exercice($exeid, $exo_id, $score, $weighting,$session_id,$learnpath_id=0, $learnpath_item_id=0, $learnpath_item_view_id = 0, $duration , $question_list) {
  290. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  291. if ($exeid!='') {
  292. // Validation in case of fraud with actived control time
  293. if (!exercise_time_control_is_valid($exo_id)) {
  294. $score = 0;
  295. }
  296. $now = time();
  297. //Validation in case of wrong start_date
  298. if (isset($_SESSION['exercice_start_date'])) {
  299. $start_date = $_SESSION['exercice_start_date'];
  300. $diff = abs($start_date - $now);
  301. if ($diff > 14400) { // 14400 = 4h*60*60 more than 4h of diff
  302. $start_date = $now - 1800; // Now - 30min
  303. }
  304. }
  305. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  306. array_map('intval', $question_list);
  307. $sql = "UPDATE $TABLETRACK_EXERCICES SET
  308. exe_exo_id = '".Database::escape_string($exo_id)."',
  309. exe_result = '".Database::escape_string($score)."',
  310. exe_weighting = '".Database::escape_string($weighting)."',
  311. session_id = '".Database::escape_string($session_id)."',
  312. orig_lp_id = '".Database::escape_string($learnpath_id)."',
  313. orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
  314. orig_lp_item_view_id = '".Database::escape_string($learnpath_item_view_id)."',
  315. exe_duration = '".Database::escape_string($duration)."',
  316. exe_date = '".api_get_utc_datetime()."',
  317. status = '',
  318. start_date = '".api_get_utc_datetime($start_date)."',
  319. data_tracking = '".implode(',', $question_list)."'
  320. WHERE exe_id = '".Database::escape_string($exeid)."'";
  321. $res = @Database::query($sql);
  322. //Deleting control time session track
  323. exercise_time_control_delete($exo_id);
  324. return $res;
  325. } else {
  326. return false;
  327. }
  328. }
  329. /**
  330. * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table.
  331. * After that in exercise_result.php we call the update_event_exercice() to update the exercise
  332. * @return $id the last id registered, or false on error
  333. * @author Julio Montoya <gugli100@gmail.com>
  334. * @desc Record result of user when an exercice was done
  335. */
  336. function create_event_exercice($exo_id) {
  337. if (empty($exo_id) or (intval($exo_id)!=$exo_id)) { return false; }
  338. //error_log('create_event_exercice');
  339. $tbl_track_exe = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  340. $tbl_exe = Database::get_course_table(TABLE_QUIZ_TEST);
  341. $now = api_get_utc_datetime();
  342. $uid = api_get_user_id();
  343. // First, check the exercise exists
  344. $sql_exe_id="SELECT exercises.id FROM $tbl_exe as exercises WHERE exercises.id=$exo_id";
  345. $res_exe_id=Database::query($sql_exe_id);
  346. if ($res_exe_id === false) { return false; } //sql error
  347. if (Database::num_rows($res_exe_id)<1) { return false;} //exe not found
  348. $row_exe_id=Database::fetch_row($res_exe_id);
  349. $exercise_id = intval($row_exe_id[0]);
  350. // Second, check if the record exists in the database (looking for incomplete records)
  351. $sql = "SELECT exe_id FROM $tbl_track_exe ";
  352. $condition = " WHERE exe_exo_id = $exo_id AND " .
  353. "exe_user_id = $uid AND " .
  354. "exe_cours_id = '".api_get_course_id()."' AND " .
  355. "status = 'incomplete' AND ".
  356. "session_id = ".api_get_session_id();
  357. $res = Database::query($sql.$condition);
  358. if ($res === false) {return false;}
  359. if (Database::num_rows($res) > 0) {
  360. $row = Database::fetch_array($res);
  361. return $row['exe_id'];
  362. }
  363. // No record was found, so create one
  364. // get expire time to insert into the tracking record
  365. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  366. $current_expired_time_key = get_time_control_key($exercise_id);
  367. if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
  368. $expired_date = $_SESSION['expired_time'][$current_expired_time_key];
  369. } else {
  370. $expired_date = '0000-00-00 00:00:00';
  371. }
  372. $sql = "INSERT INTO $tbl_track_exe ( exe_user_id, exe_cours_id, expired_time_control, exe_exo_id, session_id)
  373. VALUES ( $uid, '".api_get_course_id()."' ,'$expired_date','$exo_id','".api_get_session_id()."')";
  374. $res = Database::query($sql);
  375. $id= Database::insert_id();
  376. return $id;
  377. }
  378. /**
  379. * Record an event for this attempt at answering an exercise
  380. * @param float Score achieved
  381. * @param string Answer given
  382. * @param integer Question ID
  383. * @param integer Exercise ID
  384. * @param integer Position
  385. * @return boolean Result of the insert query
  386. */
  387. function exercise_attempt($score, $answer, $quesId, $exeId, $j, $exercise_id = 0) {
  388. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  389. $score = Database::escape_string($score);
  390. $answer = Database::escape_string($answer);
  391. $quesId = Database::escape_string($quesId);
  392. $exeId = Database::escape_string($exeId);
  393. $j = Database::escape_string($j);
  394. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  395. //Validation in case of fraud with actived control time
  396. if (!exercise_time_control_is_valid($exercise_id)) {
  397. $score = 0;
  398. $answer = 0;
  399. $j = 0;
  400. }
  401. $reallyNow = api_get_utc_datetime();
  402. $user_id = api_get_user_id();
  403. if (!empty($user_id)) {
  404. $user_id = "'".$user_id."'";
  405. } else {
  406. // anonymous
  407. $user_id = api_get_anonymous_id();
  408. }
  409. $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, course_code, session_id, position, tms )
  410. VALUES (
  411. ".$exeId.",
  412. ".$user_id.",
  413. '".$quesId."',
  414. '".$answer."',
  415. '".$score."',
  416. '".api_get_course_id()."',
  417. '".api_get_session_id()."',
  418. '".$j."',
  419. '".$reallyNow."'
  420. )";
  421. //error_log($sql);
  422. if (!empty($quesId) && !empty($exeId) && !empty($user_id)) {
  423. $res = Database::query($sql);
  424. if (defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  425. $recording_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  426. $recording_changes = "INSERT INTO $recording_table (exe_id, question_id, marks, insert_date, author, session_id) VALUES ('$exeId','$quesId','$score','".api_get_utc_datetime()."','', '".api_get_session_id()."') ";
  427. Database::query($recording_changes);
  428. }
  429. return $res;
  430. } else {
  431. return false;
  432. }
  433. }
  434. /**
  435. * Record an hotspot spot for this attempt at answering an hotspot question
  436. * @param int Exercise ID
  437. * @param int Question ID
  438. * @param int Answer ID
  439. * @param int Whether this answer is correct (1) or not (0)
  440. * @param string Coordinates of this point (e.g. 123;324)
  441. * @return boolean Result of the insert query
  442. * @uses Course code and user_id from global scope $_cid and $_user
  443. */
  444. function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords, $exerciseId = 0) {
  445. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  446. //Validation in case of fraud with actived control time
  447. if (!exercise_time_control_is_valid($exerciseId)) {
  448. $correct = 0;
  449. }
  450. $tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  451. $sql = "INSERT INTO $tbl_track_e_hotspot (hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
  452. " VALUES ('" . api_get_user_id() . "'," .
  453. " '" . api_get_course_id() . "', " .
  454. " '" . Database :: escape_string($exe_id) . "', " .
  455. " '" . Database :: escape_string($question_id) . "'," .
  456. " '" . Database :: escape_string($answer_id) . "'," .
  457. " '" . Database :: escape_string($correct) . "'," .
  458. " '" . Database :: escape_string($coords) . "')";
  459. return $result = Database::query($sql);
  460. }
  461. /**
  462. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  463. * @desc Record information for common (or admin) events (in the track_e_default table)
  464. * @param string Type of event
  465. * @param string Type of value
  466. * @param string Value
  467. * @param string Timestamp (defaults to null)
  468. * @param integer User ID (defaults to null)
  469. * @param string Course code (defaults to null)
  470. */
  471. function event_system($event_type, $event_value_type, $event_value, $datetime = null, $user_id=null, $course_code=null) {
  472. global $_user;
  473. global $TABLETRACK_DEFAULT;
  474. $event_type = Database::escape_string($event_type);
  475. $event_value_type = Database::escape_string($event_value_type);
  476. $event_value = Database::escape_string($event_value);
  477. $datetime = Database::escape_string($datetime);
  478. $user_id = Database::escape_string($user_id);
  479. $course_code = Database::escape_string($course_code);
  480. if(!isset($datetime)) {
  481. $datetime = api_get_utc_datetime();
  482. }
  483. if(!isset($user_id)) {
  484. $user_id = 0;
  485. }
  486. if(!isset($course_code)) {
  487. $course_code = '';
  488. }
  489. $sql = "INSERT INTO $TABLETRACK_DEFAULT
  490. (default_user_id,
  491. default_cours_code,
  492. default_date,
  493. default_event_type,
  494. default_value_type,
  495. default_value
  496. )
  497. VALUES
  498. ('$user_id.',
  499. '$course_code',
  500. '$datetime',
  501. '$event_type',
  502. '$event_value_type',
  503. '$event_value')";
  504. $res = Database::query($sql);
  505. return true;
  506. }
  507. /**
  508. * Gets the last attempt of an exercise based in the exe_id
  509. */
  510. function get_last_attempt_date_of_exercise($exe_id) {
  511. $exe_id = intval($exe_id);
  512. $track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  513. $track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  514. $sql_track_attempt = 'SELECT max(tms) as last_attempt_date FROM '.$track_attempts.' WHERE exe_id='.$exe_id;
  515. $rs_last_attempt = Database::query($sql_track_attempt);
  516. $row_last_attempt = Database::fetch_array($rs_last_attempt);
  517. $last_attempt_date = $row_last_attempt['last_attempt_date'];//Get the date of last attempt
  518. return $last_attempt_date;
  519. }
  520. /**
  521. * Gets how many attempts exists by user, exercise, learning path
  522. * @param int user id
  523. * @param int exercise id
  524. * @param int lp id
  525. * @param int lp item id
  526. * @param int lp item view id
  527. */
  528. function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id,$lp_item_view_id) {
  529. $stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  530. $user_id = intval($user_id);
  531. $exerciseId = intval($exerciseId);
  532. $lp_id = intval($lp_id);
  533. $lp_item_id = intval($lp_item_id);
  534. $lp_item_view_id= intval($lp_item_view_id);
  535. $sql = "SELECT count(*) as count FROM $stat_table WHERE exe_exo_id = '$exerciseId'
  536. AND exe_user_id = '$user_id' AND status != 'incomplete'
  537. AND orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id AND orig_lp_item_view_id = $lp_item_view_id AND exe_cours_id = '".api_get_course_id()."' AND session_id = '" . api_get_session_id() . "'";
  538. $query = Database::query($sql);
  539. if (Database::num_rows($query) > 0 ) {
  540. $attempt = Database :: fetch_array($query,'ASSOC');
  541. return $attempt['count'];
  542. } else {
  543. return 0;
  544. }
  545. }
  546. function delete_student_lp_events($user_id, $lp_id, $course, $session_id) {
  547. $lp_view_table = Database::get_course_table(TABLE_LP_VIEW, $course['dbName']);
  548. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW, $course['dbName']);
  549. $track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  550. $track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  551. $recording_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  552. $user_id = intval($user_id);
  553. $lp_id = intval($lp_id);
  554. $session_id = intval($session_id);
  555. //make sure we have the exact lp_view_id
  556. $sqlview = "SELECT id FROM $lp_view_table WHERE user_id = $user_id AND lp_id = $lp_id AND session_id = $session_id ";
  557. $resultview = Database::query($sqlview);
  558. $view = Database::fetch_array($resultview, 'ASSOC');
  559. $lp_view_id = $view['id'];
  560. $sql_delete = "DELETE FROM $lp_item_view_table WHERE lp_view_id = $view_id ";
  561. $result = Database::query($sql_delete);
  562. $sql_delete = "DELETE FROM $lp_view_table WHERE user_id = $user_id AND lp_id= $lp_id AND session_id= $session_id ";
  563. $result = Database::query($sql_delete);
  564. $select_all_attempts = "SELECT exe_id FROM $track_e_exercises WHERE exe_user_id = $user_id AND session_id= $session_id AND exe_cours_id = '{$course['code']}' AND orig_lp_id = $lp_id";
  565. $result = Database::query($select_all_attempts);
  566. $exe_list = array();
  567. while ($row = Database::fetch_array($result, 'ASSOC')) {
  568. $exe_list[] = $row['exe_id'];
  569. }
  570. if (!empty($exe_list) && is_array($exe_list) && count($exe_list) > 0) {
  571. $sql_delete = "DELETE FROM $track_e_exercises WHERE exe_id IN (".implode(',',$exe_list).")";
  572. $result = Database::query($sql_delete);
  573. $sql_delete = "DELETE FROM $track_attempts WHERE exe_id IN (".implode(',',$exe_list).")";
  574. $result = Database::query($sql_delete);
  575. $sql_delete = "DELETE FROM $recording_table WHERE exe_id IN (".implode(',',$exe_list).")";
  576. $result = Database::query($sql_delete);
  577. }
  578. }
  579. /**
  580. * Delete all exercise attempts (included in LP or not)
  581. *
  582. * @param int user id
  583. * @param int exercise id
  584. * @param string course code
  585. * @param int session id
  586. */
  587. function delete_all_incomplete_attempts($user_id, $exercise_id, $course_code, $session_id = 0) {
  588. $track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  589. $track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  590. $user_id = intval($user_id);
  591. $exercise_id = intval($exercise_id);
  592. $course_code = Database::escape_string($course_code);
  593. $session_id = intval($session_id);
  594. if (!empty($user_id) && !empty($exercise_id) && !empty($course_code)) {
  595. $sql = "DELETE FROM $track_e_exercises WHERE exe_user_id = $user_id AND exe_exo_id = $exercise_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND status = 'incomplete' ";
  596. $result = Database::query($sql);
  597. }
  598. }
  599. /**
  600. * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
  601. * @param int exercise id
  602. * @param string course code
  603. * @param int session id
  604. * @return array with the results
  605. *
  606. */
  607. function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) {
  608. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  609. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  610. $course_code = Database::escape_string($course_code);
  611. $exercise_id = intval($exercise_id);
  612. $session_id = intval($session_id);
  613. $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
  614. $res = Database::query($sql);
  615. $list = array();
  616. while($row = Database::fetch_array($res,'ASSOC')) {
  617. $list[$row['exe_id']] = $row;
  618. $sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}";
  619. $res_question = Database::query($sql);
  620. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  621. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  622. }
  623. }
  624. return $list;
  625. }
  626. /**
  627. * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
  628. * @param string course code
  629. * @param int session id
  630. * @return array with the results
  631. *
  632. */
  633. function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_count = true) {
  634. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  635. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  636. $course_code = Database::escape_string($course_code);
  637. $session_id = intval($session_id);
  638. $select = '*';
  639. if ($get_count) {
  640. $select = 'count(*) as count';
  641. }
  642. $sql = "SELECT $select FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_id";
  643. $res = Database::query($sql);
  644. if ($get_count) {
  645. $row = Database::fetch_array($res,'ASSOC');
  646. return $row['count'];
  647. } else {
  648. $list = array();
  649. while($row = Database::fetch_array($res,'ASSOC')) {
  650. $list[$row['exe_id']] = $row;
  651. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  652. $res_question = Database::query($sql);
  653. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  654. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  655. }
  656. }
  657. return $list;
  658. }
  659. }
  660. /**
  661. * Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session
  662. * @param int exercise id
  663. * @param string course code
  664. * @param int session id
  665. * @return array with the results
  666. *
  667. */
  668. function get_all_exercise_results_by_user($user_id, $course_code, $session_id = 0) {
  669. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  670. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  671. $course_code = Database::escape_string($course_code);
  672. $exercise_id = intval($exercise_id);
  673. $session_id = intval($session_id);
  674. $user_id = intval($user_id);
  675. $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_user_id = $user_id AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER by exe_id";
  676. $res = Database::query($sql);
  677. $list = array();
  678. while($row = Database::fetch_array($res,'ASSOC')) {
  679. $list[$row['exe_id']] = $row;
  680. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  681. $res_question = Database::query($sql);
  682. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  683. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  684. }
  685. }
  686. //echo '<pre>'; print_r($list);
  687. return $list;
  688. }
  689. /**
  690. * Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session
  691. * @param int exercise id
  692. * @param string course code
  693. * @param int session id
  694. * @return array with the results
  695. *
  696. */
  697. function get_exercise_results_by_attempt($exe_id) {
  698. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  699. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  700. $table_track_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  701. $exe_id = intval($exe_id);
  702. $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_id = $exe_id";
  703. $res = Database::query($sql);
  704. $list = array();
  705. if (Database::num_rows($res)) {
  706. $row = Database::fetch_array($res,'ASSOC');
  707. //Checking if this attempt was revised by a teacher
  708. $sql_revised = 'SELECT exe_id FROM ' . $table_track_attempt_recording . ' WHERE author != "" AND exe_id = '.$exe_id.' LIMIT 1';
  709. $res_revised = Database::query($sql_revised);
  710. $row['attempt_revised'] = 0;
  711. if (Database::num_rows($res_revised) > 0) {
  712. $row['attempt_revised'] = 1;
  713. }
  714. $list[$exe_id] = $row;
  715. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = $exe_id";
  716. $res_question = Database::query($sql);
  717. while ($row_q = Database::fetch_array($res_question,'ASSOC')) {
  718. $list[$exe_id]['question_list'][$row_q['question_id']] = $row_q;
  719. }
  720. }
  721. //echo '<pre>'; print_r($list);
  722. return $list;
  723. }
  724. /**
  725. * Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session
  726. * @param int exercise id
  727. * @param string course code
  728. * @param int session id
  729. * @return array with the results
  730. *
  731. */
  732. function get_exercise_results_by_user($user_id, $exercise_id, $course_code, $session_id = 0, $lp_id = 0, $lp_item_id = 0) {
  733. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  734. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  735. $table_track_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  736. $course_code = Database::escape_string($course_code);
  737. $exercise_id = intval($exercise_id);
  738. $session_id = intval($session_id);
  739. $user_id = intval($user_id);
  740. $lp_id = intval($lp_id);
  741. $lp_item_id = intval($lp_item_id);
  742. $sql = "SELECT * FROM $table_track_exercises
  743. WHERE status = '' AND exe_user_id = $user_id AND exe_cours_id = '$course_code' AND exe_exo_id = $exercise_id AND session_id = $session_id AND orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id ORDER by exe_id";
  744. $res = Database::query($sql);
  745. $list = array();
  746. while($row = Database::fetch_array($res,'ASSOC')) {
  747. //Checking if this attempt was revised by a teacher
  748. $sql_revised = 'SELECT exe_id FROM ' . $table_track_attempt_recording . ' WHERE author != "" AND exe_id = '.$row['exe_id'].' LIMIT 1';
  749. $res_revised = Database::query($sql_revised);
  750. $row['attempt_revised'] = 0;
  751. if (Database::num_rows($res_revised) > 0) {
  752. $row['attempt_revised'] = 1;
  753. }
  754. $list[$row['exe_id']] = $row;
  755. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  756. $res_question = Database::query($sql);
  757. while ($row_q = Database::fetch_array($res_question,'ASSOC')) {
  758. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  759. }
  760. }
  761. //echo '<pre>'; print_r($list);
  762. return $list;
  763. }
  764. /**
  765. * Count exercise attempts (NO Exercises in LPs ) from a given exercise id, course, session
  766. * @param int exercise id
  767. * @param string course code
  768. * @param int session id
  769. * @return array with the results
  770. *
  771. */
  772. function count_exercise_attempts_by_user($user_id, $exercise_id, $course_code, $session_id = 0) {
  773. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  774. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  775. $course_code = Database::escape_string($course_code);
  776. $exercise_id = intval($exercise_id);
  777. $session_id = intval($session_id);
  778. $user_id = intval($user_id);
  779. $sql = "SELECT count(*) as count FROM $TABLETRACK_EXERCICES
  780. WHERE status = '' AND exe_user_id = '$user_id' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
  781. $res = Database::query($sql);
  782. $result = 0;
  783. if (Database::num_rows($res) > 0 ) {
  784. $row = Database::fetch_array($res,'ASSOC');
  785. $result = $row['count'];
  786. }
  787. return $result;
  788. }
  789. /**
  790. * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
  791. * @param int exercise id
  792. * @param string course code
  793. * @param int session id
  794. * @return array with the results
  795. *
  796. */
  797. function get_best_exercise_results_by_user($exercise_id, $course_code, $session_id = 0) {
  798. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  799. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  800. $course_code = Database::escape_string($course_code);
  801. $exercise_id = intval($exercise_id);
  802. $session_id = intval($session_id);
  803. $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
  804. $res = Database::query($sql);
  805. $list = array();
  806. while($row = Database::fetch_array($res,'ASSOC')) {
  807. $list[$row['exe_id']] = $row;
  808. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  809. $res_question = Database::query($sql);
  810. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  811. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  812. }
  813. }
  814. /*
  815. echo count($list);
  816. echo '<br>';
  817. echo '<pre>'; print_r($list);*/
  818. //Getting the best results of every student
  819. $best_score_return = array();
  820. foreach($list as $student_result) {
  821. $user_id = $student_result['exe_user_id'];
  822. $current_best_score[$user_id] = $student_result['exe_result'];
  823. //echo $current_best_score[$user_id].' - '.$best_score_return[$user_id]['exe_result'].'<br />';
  824. if ($current_best_score[$user_id] > $best_score_return[$user_id]['exe_result']) {
  825. $best_score_return[$user_id] = $student_result;
  826. }
  827. }
  828. /*
  829. echo count($best_score_return);
  830. echo '<pre>'; print_r($best_score_return);*/
  831. return $best_score_return;
  832. }
  833. /**
  834. * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
  835. * @param int exercise id
  836. * @param string course code
  837. * @param int session id
  838. * @return array with the results
  839. *
  840. */
  841. function get_count_exercises_attempted_by_course($course_code, $session_id = 0) {
  842. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  843. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  844. $course_code = Database::escape_string($course_code);
  845. $session_id = intval($session_id);
  846. $sql = "SELECT DISTINCT exe_exo_id, exe_user_id FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
  847. $res = Database::query($sql);
  848. $count = 0;
  849. if (Database::num_rows($res) > 0) {
  850. $count = Database::num_rows($res);
  851. }
  852. return $count;
  853. }
  854. /**
  855. * Gets all exercise events from a Learning Path within a Course nd Session
  856. * @param int exercise id
  857. * @param string course_code
  858. * @param int session id
  859. * @return array
  860. */
  861. function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id = 0) {
  862. $table_track_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  863. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  864. $course_code = Database::escape_string($course_code);
  865. $exercise_id = intval($exercise_id);
  866. $session_id = intval($session_id);
  867. $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id !=0 AND orig_lp_item_id != 0";
  868. $res = Database::query($sql);
  869. $list = array();
  870. while($row = Database::fetch_array($res,'ASSOC')) {
  871. $list[$row['exe_id']] = $row;
  872. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  873. $res_question = Database::query($sql);
  874. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  875. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  876. }
  877. }
  878. return $list;
  879. }
  880. /*
  881. function get_all_exercise_event_from_lp($exercise_id, $course_db, $session_id ) {
  882. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_db);
  883. $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course_db);
  884. $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_db);
  885. $exercise_id = intval($exercise_id);
  886. $session_id = intval($session_id);
  887. $sql = "SELECT title, user_id, score , iv.max_score, status, session_id
  888. FROM $lp_item_table as i INNER JOIN $lp_item_view_table iv ON (i.id = iv.lp_item_id ) INNER JOIN $lp_view_table v ON iv.lp_view_id = v.id
  889. WHERE path = $exercise_id AND status ='completed' AND session_id = $session_id";
  890. $res = Database::query($sql);
  891. $list = array();
  892. while($row = Database::fetch_array($res,'ASSOC')) {
  893. $list[$row['exe_id']]['question_list'][$row['question_id']] = $row;
  894. }
  895. //echo '<pre>'; print_r($list);
  896. return $list;
  897. }*/
  898. function get_all_exercises_from_lp($lp_id, $course_db) {
  899. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_db);
  900. $lp_id = intval($lp_id);
  901. $sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$lp_id."' ORDER BY parent_item_id, display_order";
  902. $res = Database::query($sql);
  903. $my_exercise_list = array();
  904. while($row = Database::fetch_array($res,'ASSOC')) {
  905. if ($row['item_type'] == 'quiz') {
  906. $my_exercise_list[] = $row;
  907. }
  908. }
  909. return $my_exercise_list;
  910. }
  911. /**
  912. * This function gets the comments of an exercise
  913. *
  914. * @param int $id
  915. * @param int $question_id
  916. * @return str the comment
  917. */
  918. function get_comments($id,$question_id) {
  919. $table_track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  920. $sql = "SELECT teacher_comment FROM ".$table_track_attempt." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
  921. $sqlres = Database::query($sql);
  922. $comm = Database::result($sqlres,0,"teacher_comment");
  923. return $comm;
  924. }