events.lib.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <?php // $Id: events.lib.inc.php 22205 2009-07-17 21:11:52Z cfasanando $
  2. /* See license terms in /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * EVENTS LIBRARY
  6. *
  7. * This is the events library for Dokeos.
  8. * Include/require it in your code to use its functionality.
  9. * Functions of this library are used to record informations when some kind
  10. * of event occur. Each event has his own types of informations then each event
  11. * use its own function.
  12. *
  13. * @package dokeos.library
  14. * @todo convert queries to use Database API
  15. ==============================================================================
  16. */
  17. /*
  18. ==============================================================================
  19. INIT SECTION
  20. ==============================================================================
  21. */
  22. // REGROUP TABLE NAMES FOR MAINTENANCE PURPOSE
  23. $TABLETRACK_LOGIN = $_configuration['statistics_database'].".track_e_login";
  24. $TABLETRACK_OPEN = $_configuration['statistics_database'].".track_e_open";
  25. $TABLETRACK_ACCESS = $_configuration['statistics_database'].".track_e_access";
  26. $TABLETRACK_DOWNLOADS = $_configuration['statistics_database'].".track_e_downloads";
  27. $TABLETRACK_UPLOADS = $_configuration['statistics_database'].".track_e_uploads";
  28. $TABLETRACK_LINKS = $_configuration['statistics_database'].".track_e_links";
  29. $TABLETRACK_EXERCICES = $_configuration['statistics_database'].".track_e_exercices";
  30. $TABLETRACK_SUBSCRIPTIONS = $_configuration['statistics_database'].".track_e_subscriptions";
  31. $TABLETRACK_LASTACCESS = $_configuration['statistics_database'].".track_e_lastaccess"; //for "what's new" notification
  32. $TABLETRACK_DEFAULT = $_configuration['statistics_database'].".track_e_default";
  33. /*
  34. ==============================================================================
  35. FUNCTIONS
  36. ==============================================================================
  37. */
  38. /**
  39. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  40. * @desc Record information for open event (when homepage is opened)
  41. */
  42. function event_open()
  43. {
  44. global $_configuration;
  45. global $TABLETRACK_OPEN;
  46. // if tracking is disabled record nothing
  47. if (!$_configuration['tracking_enabled'])
  48. {
  49. return 0;
  50. }
  51. // @getHostByAddr($_SERVER['REMOTE_ADDR']) : will provide host and country information
  52. // $_SERVER['HTTP_USER_AGENT'] : will provide browser and os information
  53. // $_SERVER['HTTP_REFERER'] : provide information about refering url
  54. if(isset($_SERVER['HTT_REFERER']))
  55. {
  56. $referer = Database::escape_string($_SERVER['HTTP_REFERER']);
  57. }
  58. else
  59. {
  60. $referer = '';
  61. }
  62. // record informations only if user comes from another site
  63. //if(!eregi($_configuration['root_web'],$referer))
  64. $pos = strpos($referer, $_configuration['root_web']);
  65. if ($pos === false && $referer != '')
  66. {
  67. $remhost = @ getHostByAddr($_SERVER['REMOTE_ADDR']);
  68. if ($remhost == $_SERVER['REMOTE_ADDR'])
  69. $remhost = "Unknown"; // don't change this
  70. $reallyNow = time();
  71. $sql = "INSERT INTO ".$TABLETRACK_OPEN."
  72. (open_remote_host,
  73. open_agent,
  74. open_referer,
  75. open_date)
  76. VALUES
  77. ('".$remhost."',
  78. '".Database::escape_string($_SERVER['HTTP_USER_AGENT'])."', '".Database::escape_string($referer)."', FROM_UNIXTIME($reallyNow) )";
  79. $res = Database::query($sql,__FILE__,__LINE__);
  80. }
  81. return 1;
  82. }
  83. /**
  84. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  85. * @desc Record information for login event
  86. * (when an user identifies himself with username & password)
  87. */
  88. function event_login()
  89. {
  90. global $_configuration;
  91. global $_user;
  92. global $TABLETRACK_LOGIN;
  93. // if tracking is disabled record nothing
  94. if (!$_configuration['tracking_enabled']) {
  95. return 0;
  96. }
  97. $reallyNow = time();
  98. $sql = "INSERT INTO ".$TABLETRACK_LOGIN."
  99. (login_user_id,
  100. login_ip,
  101. login_date)
  102. VALUES
  103. ('".$_user['user_id']."',
  104. '".Database::escape_string($_SERVER['REMOTE_ADDR'])."',
  105. FROM_UNIXTIME(".$reallyNow."))";
  106. $res = Database::query($sql,__FILE__,__LINE__);
  107. }
  108. /**
  109. * @param tool name of the tool (name in mainDb.accueil table)
  110. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  111. * @desc Record information for access event for courses
  112. */
  113. function event_access_course()
  114. {
  115. global $_configuration;
  116. global $_user;
  117. global $_cid;
  118. global $TABLETRACK_ACCESS;
  119. global $TABLETRACK_LASTACCESS; //for "what's new" notification
  120. // if tracking is disabled record nothing
  121. if (!$_configuration['tracking_enabled'])
  122. {
  123. return 0;
  124. }
  125. if(api_get_setting('use_session_mode')=='true' && isset($_SESSION['id_session']))
  126. {
  127. $id_session = intval($_SESSION['id_session']);
  128. }
  129. else
  130. {
  131. $id_session = 0;
  132. }
  133. $reallyNow = time();
  134. if ($_user['user_id']) {
  135. $user_id = "'".$_user['user_id']."'";
  136. } else {
  137. $user_id = "0"; // no one
  138. }
  139. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  140. (access_user_id,
  141. access_cours_code,
  142. access_date)
  143. VALUES
  144. (".$user_id.",
  145. '".$_cid."',
  146. FROM_UNIXTIME(".$reallyNow."))";
  147. $res = Database::query($sql,__FILE__,__LINE__);
  148. // added for "what's new" notification
  149. $sql = " UPDATE $TABLETRACK_LASTACCESS
  150. SET access_date = FROM_UNIXTIME($reallyNow)
  151. WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool IS NULL AND access_session_id=".$id_session;
  152. $res = Database::query($sql,__FILE__,__LINE__);
  153. if (Database::affected_rows() == 0)
  154. {
  155. $sql = " INSERT INTO $TABLETRACK_LASTACCESS
  156. (access_user_id,access_cours_code,access_date, access_session_id)
  157. VALUES
  158. (".$user_id.", '".$_cid."', FROM_UNIXTIME($reallyNow), ".$id_session.")";
  159. $res = Database::query($sql,__FILE__,__LINE__);
  160. }
  161. // end "what's new" notification
  162. return 1;
  163. }
  164. /**
  165. * @param tool name of the tool (name in mainDb.accueil table)
  166. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  167. * @desc Record information for access event for tools
  168. *
  169. * $tool can take this values :
  170. * Links, Calendar, Document, Announcements,
  171. * Group, Video, Works, Users, Exercices, Course Desc
  172. * ...
  173. * Values can be added if new modules are created (15char max)
  174. * I encourage to use $nameTool as $tool when calling this function
  175. *
  176. * Functionality for "what's new" notification is added by Toon Van Hoecke
  177. */
  178. function event_access_tool($tool, $id_session=0)
  179. {
  180. global $_configuration;
  181. // if tracking is disabled record nothing
  182. // if( ! $_configuration['tracking_enabled'] ) return 0; //commented because "what's new" notification must always occur
  183. global $_user;
  184. global $_cid;
  185. global $TABLETRACK_ACCESS;
  186. global $_configuration;
  187. global $_course;
  188. global $TABLETRACK_LASTACCESS; //for "what's new" notification
  189. if(api_get_setting('use_session_mode')=='true' && isset($_SESSION['id_session']))
  190. {
  191. $id_session = intval($_SESSION['id_session']);
  192. }
  193. else
  194. {
  195. $id_session = 0;
  196. }
  197. $reallyNow = time();
  198. $user_id = $_user['user_id'] ? "'".$_user['user_id']."'" : "0"; // no one
  199. // record information
  200. // only if user comes from the course $_cid
  201. //if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
  202. //$pos = strpos($_SERVER['HTTP_REFERER'],$_configuration['root_web'].$_cid);
  203. $pos = strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_COURSE_PATH).$_course['path']));
  204. // added for "what's new" notification
  205. $pos2 = strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower($_configuration['root_web']."index"));
  206. // end "what's new" notification
  207. if ($_configuration['tracking_enabled'] && ($pos !== false || $pos2 !== false))
  208. {
  209. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  210. (access_user_id,
  211. access_cours_code,
  212. access_tool,
  213. access_date)
  214. VALUES
  215. (".$user_id.",".// Don't add ' ' around value, it's already done.
  216. "'".$_cid."' ,
  217. '".htmlspecialchars($tool, ENT_QUOTES)."',
  218. FROM_UNIXTIME(".$reallyNow."))";
  219. $res = Database::query($sql,__FILE__,__LINE__);
  220. }
  221. // "what's new" notification
  222. $sql = " UPDATE $TABLETRACK_LASTACCESS
  223. SET access_date = FROM_UNIXTIME($reallyNow)
  224. WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool = '".htmlspecialchars($tool, ENT_QUOTES)."' AND access_session_id=".$id_session;
  225. $res = Database::query($sql,__FILE__,__LINE__);
  226. if (Database::affected_rows() == 0)
  227. {
  228. $sql = "INSERT INTO $TABLETRACK_LASTACCESS
  229. (access_user_id,access_cours_code,access_tool, access_date, access_session_id)
  230. VALUES
  231. (".$user_id.", '".$_cid."' , '".htmlspecialchars($tool, ENT_QUOTES)."', FROM_UNIXTIME($reallyNow), $id_session)";
  232. $res = Database::query($sql,__FILE__,__LINE__);
  233. }
  234. return 1;
  235. }
  236. /**
  237. * @param doc_id id of document (id in mainDb.document table)
  238. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  239. * @desc Record information for download event
  240. * (when an user click to d/l a document)
  241. * it will be used in a redirection page
  242. * bug fixed: Roan Embrechts
  243. * Roan:
  244. * The user id is put in single quotes,
  245. * (why? perhaps to prevent sql insertion hacks?)
  246. * and later again.
  247. * Doing this twice causes an error, I remove one of them.
  248. */
  249. function event_download($doc_url)
  250. {
  251. global $_configuration;
  252. global $_user;
  253. global $_cid;
  254. global $TABLETRACK_DOWNLOADS;
  255. // if tracking is disabled record nothing
  256. if (!$_configuration['tracking_enabled'])
  257. {
  258. return 0;
  259. }
  260. $reallyNow = time();
  261. if ($_user['user_id'])
  262. {
  263. $user_id = "'".$_user['user_id']."'";
  264. } else {
  265. $user_id = "0";
  266. }
  267. $sql = "INSERT INTO ".$TABLETRACK_DOWNLOADS."
  268. (
  269. down_user_id,
  270. down_cours_id,
  271. down_doc_path,
  272. down_date
  273. )
  274. VALUES
  275. (
  276. ".$user_id.",
  277. '".$_cid."',
  278. '".htmlspecialchars($doc_url, ENT_QUOTES)."',
  279. FROM_UNIXTIME(".$reallyNow.")
  280. )";
  281. $res = Database::query($sql,__FILE__,__LINE__);
  282. return 1;
  283. }
  284. /**
  285. * @param doc_id id of document (id in mainDb.document table)
  286. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  287. * @desc Record information for upload event
  288. * used in the works tool to record informations when
  289. * an user upload 1 work
  290. */
  291. function event_upload($doc_id)
  292. {
  293. global $_configuration;
  294. global $_user;
  295. global $_cid;
  296. global $TABLETRACK_UPLOADS;
  297. // if tracking is disabled record nothing
  298. if (!$_configuration['tracking_enabled']) {
  299. return 0;
  300. }
  301. $reallyNow = time();
  302. if (isset($_user['user_id']) && $_user['user_id']!='') {
  303. $user_id = "'".$_user['user_id']."'";
  304. } else {
  305. $user_id = "0"; // anonymous
  306. }
  307. $sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
  308. ( upload_user_id,
  309. upload_cours_id,
  310. upload_work_id,
  311. upload_date
  312. )
  313. VALUES (
  314. ".$user_id.",
  315. '".$_cid."',
  316. '".$doc_id."',
  317. FROM_UNIXTIME(".$reallyNow.")
  318. )";
  319. $res = Database::query($sql,__FILE__,__LINE__);
  320. return 1;
  321. }
  322. /**
  323. * @param link_id (id in coursDb liens table)
  324. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  325. * @desc Record information for link event (when an user click on an added link)
  326. * it will be used in a redirection page
  327. */
  328. function event_link($link_id)
  329. {
  330. global $_configuration;
  331. global $_user;
  332. global $_cid;
  333. global $TABLETRACK_LINKS;
  334. // if tracking is disabled record nothing
  335. if (!$_configuration['tracking_enabled']) {
  336. return 0;
  337. }
  338. $reallyNow = time();
  339. if (isset($_user['user_id']) && $_user['user_id']!='') {
  340. $user_id = "'".Database::escape_string($_user['user_id'])."'";
  341. } else {
  342. // anonymous
  343. $user_id = "0";
  344. }
  345. $sql = "INSERT INTO ".$TABLETRACK_LINKS."
  346. ( links_user_id,
  347. links_cours_id,
  348. links_link_id,
  349. links_date
  350. )
  351. VALUES
  352. (
  353. ".$user_id.",
  354. '".$_cid."',
  355. '".Database::escape_string($link_id)."',
  356. FROM_UNIXTIME(".$reallyNow.")
  357. )";
  358. $res = Database::query($sql,__FILE__,__LINE__);
  359. return 1;
  360. }
  361. /**
  362. * @param exeid ( id of the exercise)
  363. * @param exo_id ( id in courseDb exercices table )
  364. * @param result ( score @ exercice )
  365. * @param weighting ( higher score )
  366. * @param duration ( duration of the attempt, in seconds )
  367. * @param session_id
  368. * @param learnpath_id (id of the learnpath)
  369. * @param learnpath_item_id (id of the learnpath_item)
  370. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  371. * @author Julio Montoya Armas <gugli100@gmail.com>
  372. * @desc Record result of user when an exercice was done
  373. */
  374. function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0, $duration)
  375. {
  376. if ($exeid!='') {
  377. // Validation in case of fraud with actived control time
  378. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  379. $current_time = time();
  380. $expired_date = $_SESSION['expired_time'];
  381. $expired_time = strtotime($expired_date);
  382. $total_time_allowed = $expired_time + 30;
  383. if ($total_time_allowed < $current_time) {
  384. $score = 0;
  385. }
  386. }
  387. $now = time();
  388. //Validation in case of wrong start_date
  389. if (isset($_SESSION['exercice_start_date'])) {
  390. $start_date = $_SESSION['exercice_start_date'];
  391. $diff = abs($start_date - $now);
  392. if ($diff > 14400) { // 14400 = 4h*60*60 more than 4h of diff
  393. $start_date = $now - 1800; // Now - 30min
  394. }
  395. }
  396. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  397. $sql = "UPDATE $TABLETRACK_EXERCICES SET
  398. exe_exo_id = '".Database::escape_string($exo_id)."',
  399. exe_result = '".Database::escape_string($score)."',
  400. exe_weighting = '".Database::escape_string($weighting)."',
  401. session_id = '".Database::escape_string($session_id)."',
  402. orig_lp_id = '".Database::escape_string($learnpath_id)."',
  403. orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
  404. exe_duration = '".Database::escape_string($duration)."',
  405. exe_date= FROM_UNIXTIME(".$now."),status = '', data_tracking='', start_date = FROM_UNIXTIME(".Database::escape_string($start_date).")
  406. WHERE exe_id = '".Database::escape_string($exeid)."'";
  407. $res = @Database::query($sql,__FILE__,__LINE__);
  408. unset($_SESSION['expired_time']);
  409. return $res;
  410. } else
  411. return false;
  412. }
  413. /**
  414. * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table.
  415. * After that in exercise_result.php we call the update_event_exercice() to update the exercise
  416. * @return $id the last id registered
  417. * @author Julio Montoya <gugli100@gmail.com>
  418. * @desc Record result of user when an exercice was done
  419. */
  420. function create_event_exercice($exo_id)
  421. {
  422. global $_user, $_cid, $_configuration;
  423. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  424. $reallyNow = time();
  425. if (isset($_user['user_id']) && $_user['user_id']!='') {
  426. $user_id = "'".$_user['user_id']."'";
  427. } else {
  428. // anonymous
  429. $user_id = "0";
  430. }
  431. if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  432. $condition = ' WHERE ' .
  433. 'exe_exo_id = '."'".Database::escape_string($exo_id)."'".' AND ' .
  434. 'exe_user_id = '."'".api_get_user_id()."'".' AND ' .
  435. 'exe_cours_id = '."'".$_cid."'".' AND ' .
  436. 'status = '."'incomplete'".' AND '.
  437. 'session_id = '."'".api_get_session_id()."'";
  438. $sql = Database::query('SELECT exe_id FROM '.$TABLETRACK_EXERCICES.$condition,__FILE__,__LINE__);
  439. $row = Database::fetch_array($sql);
  440. return $row['exe_id'];
  441. }
  442. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  443. $expired_date = $_SESSION['expired_time'];
  444. } else {
  445. $expired_date = '0000-00-00 00:00:00';
  446. }
  447. $sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id,expired_time_control,exe_exo_id)
  448. VALUES ( ".$user_id.", '".$_cid."' ,'".$expired_date."','".$exo_id."')";
  449. $res = @Database::query($sql,__FILE__,__LINE__);
  450. $id= Database::insert_id();
  451. return $id;
  452. }
  453. /**
  454. * Record an event for this attempt at answering an exercise
  455. * @param float Score achieved
  456. * @param string Answer given
  457. * @param integer Question ID
  458. * @param integer Exercise ID
  459. * @param integer Position
  460. * @return boolean Result of the insert query
  461. */
  462. function exercise_attempt($score,$answer,$quesId,$exeId,$j)
  463. {
  464. $score = Database::escape_string($score);
  465. $answer = Database::escape_string($answer);
  466. $quesId = Database::escape_string($quesId);
  467. $exeId = Database::escape_string($exeId);
  468. $j = Database::escape_string($j);
  469. global $_configuration, $_user, $_cid;
  470. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  471. //Validation in case of fraud with actived control time
  472. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  473. $current_time = time();
  474. $expired_date = $_SESSION['expired_time'];
  475. $expired_time = strtotime($expired_date);
  476. $total_time_allowed = $expired_time + 30;
  477. if ($total_time_allowed < $current_time) {
  478. $score = 0;
  479. $answer = 0;
  480. $j = 0;
  481. }
  482. }
  483. // if tracking is disabled record nothing
  484. if (!$_configuration['tracking_enabled'])
  485. {
  486. return 0;
  487. }
  488. $reallyNow = time();
  489. if (isset($_user['user_id']) && $_user['user_id']!='')
  490. {
  491. $user_id = "'".$_user['user_id']."'";
  492. }
  493. else // anonymous
  494. {
  495. $user_id = api_get_anonymous_id();
  496. }
  497. $_SESSION['current_exercice_attempt'][$user_id] = $exeId;
  498. $sql = "INSERT INTO $TBL_TRACK_ATTEMPT
  499. (
  500. exe_id,
  501. user_id,
  502. question_id,
  503. answer,
  504. marks,
  505. course_code,
  506. position,
  507. tms
  508. )
  509. VALUES
  510. (
  511. ".$exeId.",
  512. ".$user_id.",
  513. '".$quesId."',
  514. '".addslashes($answer)."',
  515. '".$score."',
  516. '".$_cid."',
  517. '".$j."',
  518. FROM_UNIXTIME(".$reallyNow.")
  519. )";
  520. if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  521. $TBL_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  522. $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
  523. '(exe_id,
  524. question_id,
  525. marks,
  526. insert_date,
  527. author)
  528. VALUES
  529. ('."'$exeId','".$quesId."','$score','".date('Y-m-d H:i:s')."',''".')';
  530. Database::query($recording_changes,__FILE__,__LINE__);
  531. }
  532. if (!empty($quesId) && !empty($exeId) && !empty($user_id)) {
  533. $res = Database::query($sql,__FILE__,__LINE__);
  534. return $res;
  535. } else {
  536. return false;
  537. }
  538. }
  539. /**
  540. * Record an hotspot spot for this attempt at answering an hotspot question
  541. * @param int Exercise ID
  542. * @param int Question ID
  543. * @param int Answer ID
  544. * @param int Whether this answer is correct (1) or not (0)
  545. * @param string Coordinates of this point (e.g. 123;324)
  546. * @return boolean Result of the insert query
  547. * @uses Course code and user_id from global scope $_cid and $_user
  548. */
  549. function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords)
  550. {
  551. global $_configuration, $_user, $_cid;
  552. // if tracking is disabled record nothing
  553. if (!$_configuration['tracking_enabled'])
  554. {
  555. return 0;
  556. }
  557. //Validation in case of fraud with actived control time
  558. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  559. $current_time = time();
  560. $expired_date = $_SESSION['expired_time'];
  561. $expired_time = strtotime($expired_date);
  562. $total_time_allowed = $expired_time + 30;
  563. if ($total_time_allowed < $current_time) {
  564. $correct = 0;
  565. }
  566. }
  567. $tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  568. $sql = "INSERT INTO $tbl_track_e_hotspot " .
  569. "(hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
  570. " VALUES ('" . Database :: escape_string($_user['user_id']) . "'," .
  571. " '" . Database :: escape_string($_cid) . "', " .
  572. " '" . Database :: escape_string($exe_id) . "', " .
  573. " '" . Database :: escape_string($question_id) . "'," .
  574. " '" . Database :: escape_string($answer_id) . "'," .
  575. " '" . Database :: escape_string($correct) . "'," .
  576. " '" . Database :: escape_string($coords) . "')";
  577. return $result = Database::query($sql, __FILE__, __LINE__);
  578. }
  579. /**
  580. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  581. * @desc Record information for common (or admin) events (in the track_e_default table)
  582. * @param string Type of event
  583. * @param string Type of value
  584. * @param string Value
  585. * @param string Timestamp (defaults to null)
  586. * @param integer User ID (defaults to null)
  587. * @param string Course code (defaults to null)
  588. */
  589. function event_system($event_type, $event_value_type, $event_value, $timestamp = null, $user_id=null, $course_code=null)
  590. {
  591. global $_configuration;
  592. global $_user;
  593. global $TABLETRACK_DEFAULT;
  594. $event_type = Database::escape_string($event_type);
  595. $event_value_type = Database::escape_string($event_value_type);
  596. $event_value = Database::escape_string($event_value);
  597. $timestamp = Database::escape_string($timestamp);
  598. $user_id = Database::escape_string($user_id);
  599. $course_code = Database::escape_string($course_code);
  600. // if tracking is disabled record nothing
  601. if (!$_configuration['tracking_enabled'])
  602. {
  603. return 0;
  604. }
  605. if(!isset($timestamp))
  606. {
  607. $timestamp = time();
  608. }
  609. if(!isset($user_id))
  610. {
  611. $user_id = 0;
  612. }
  613. if(!isset($course_code))
  614. {
  615. $course_code = '';
  616. }
  617. $sql = "INSERT INTO $TABLETRACK_DEFAULT
  618. (default_user_id,
  619. default_cours_code,
  620. default_date,
  621. default_event_type,
  622. default_value_type,
  623. default_value
  624. )
  625. VALUES
  626. ('$user_id.',
  627. '$course_code',
  628. FROM_UNIXTIME($timestamp),
  629. '$event_type',
  630. '$event_value_type',
  631. '$event_value')";
  632. $res = Database::query($sql,__FILE__,__LINE__);
  633. return true;
  634. }
  635. ?>