events.lib.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. $current_time = time();
  378. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  379. $expired_date = $_SESSION['expired_time'];
  380. $expired_time = strtotime($expired_date);
  381. }
  382. //Validation in case of fraud
  383. $total_time_allowed = $expired_time + 30;
  384. if ($total_time_allowed < $current_time) {
  385. $score = 0;
  386. }
  387. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  388. $reallyNow = time();
  389. $sql = "UPDATE $TABLETRACK_EXERCICES SET
  390. exe_exo_id = '".Database::escape_string($exo_id)."',
  391. exe_result = '".Database::escape_string($score)."',
  392. exe_weighting = '".Database::escape_string($weighting)."',
  393. session_id = '".Database::escape_string($session_id)."',
  394. orig_lp_id = '".Database::escape_string($learnpath_id)."',
  395. orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
  396. exe_duration = '".Database::escape_string($duration)."',
  397. exe_date= FROM_UNIXTIME(".$reallyNow."),status = '', data_tracking='',start_date =FROM_UNIXTIME(".Database::escape_string($_SESSION['exercice_start_date']).")
  398. WHERE exe_id = '".Database::escape_string($exeid)."'";
  399. $res = @Database::query($sql,__FILE__,__LINE__);
  400. unset($_SESSION['expired_time']);
  401. return $res;
  402. } else
  403. return false;
  404. }
  405. /**
  406. * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table.
  407. * After that in exercise_result.php we call the update_event_exercice() to update the exercise
  408. * @return $id the last id registered
  409. * @author Julio Montoya <gugli100@gmail.com>
  410. * @desc Record result of user when an exercice was done
  411. */
  412. function create_event_exercice($exo_id)
  413. {
  414. global $_user, $_cid, $_configuration;
  415. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  416. $reallyNow = time();
  417. if (isset($_user['user_id']) && $_user['user_id']!='') {
  418. $user_id = "'".$_user['user_id']."'";
  419. } else {
  420. // anonymous
  421. $user_id = "0";
  422. }
  423. if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  424. $condition = ' WHERE ' .
  425. 'exe_exo_id = '."'".Database::escape_string($exo_id)."'".' AND ' .
  426. 'exe_user_id = '."'".api_get_user_id()."'".' AND ' .
  427. 'exe_cours_id = '."'".$_cid."'".' AND ' .
  428. 'status = '."'incomplete'".' AND '.
  429. 'session_id = '."'".api_get_session_id()."'";
  430. $sql = Database::query('SELECT exe_id FROM '.$TABLETRACK_EXERCICES.$condition,__FILE__,__LINE__);
  431. $row = Database::fetch_array($sql);
  432. return $row['exe_id'];
  433. }
  434. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  435. $expired_date = $_SESSION['expired_time'];
  436. } else {
  437. $expired_date = '0000-00-00 00:00:00';
  438. }
  439. $sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id,expired_time_control,exe_exo_id)
  440. VALUES ( ".$user_id.", '".$_cid."' ,'".$expired_date."','".$exo_id."')";
  441. $res = @Database::query($sql,__FILE__,__LINE__);
  442. $id= Database::insert_id();
  443. return $id;
  444. }
  445. /**
  446. * Record an event for this attempt at answering an exercise
  447. * @param float Score achieved
  448. * @param string Answer given
  449. * @param integer Question ID
  450. * @param integer Exercise ID
  451. * @param integer Position
  452. * @return boolean Result of the insert query
  453. */
  454. function exercise_attempt($score,$answer,$quesId,$exeId,$j)
  455. {
  456. $score = Database::escape_string($score);
  457. $answer = Database::escape_string($answer);
  458. $quesId = Database::escape_string($quesId);
  459. $exeId = Database::escape_string($exeId);
  460. $j = Database::escape_string($j);
  461. global $_configuration, $_user, $_cid;
  462. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  463. $current_time = time();
  464. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  465. $expired_date = $_SESSION['expired_time'];
  466. $expired_time = strtotime($expired_date);
  467. }
  468. //Validation in case of fraud
  469. $total_time_allowed = $expired_time + 30;
  470. if ($total_time_allowed < $current_time) {
  471. $score = 0;
  472. $answer = 0;
  473. $j = 0;
  474. }
  475. // if tracking is disabled record nothing
  476. if (!$_configuration['tracking_enabled'])
  477. {
  478. return 0;
  479. }
  480. $reallyNow = time();
  481. if (isset($_user['user_id']) && $_user['user_id']!='')
  482. {
  483. $user_id = "'".$_user['user_id']."'";
  484. }
  485. else // anonymous
  486. {
  487. $user_id = api_get_anonymous_id();
  488. }
  489. $_SESSION['current_exercice_attempt'][$user_id] = $exeId;
  490. $sql = "INSERT INTO $TBL_TRACK_ATTEMPT
  491. (
  492. exe_id,
  493. user_id,
  494. question_id,
  495. answer,
  496. marks,
  497. course_code,
  498. position,
  499. tms
  500. )
  501. VALUES
  502. (
  503. ".$exeId.",
  504. ".$user_id.",
  505. '".$quesId."',
  506. '".addslashes($answer)."',
  507. '".$score."',
  508. '".$_cid."',
  509. '".$j."',
  510. FROM_UNIXTIME(".$reallyNow.")
  511. )";
  512. if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  513. $TBL_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  514. $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
  515. '(exe_id,
  516. question_id,
  517. marks,
  518. insert_date,
  519. author)
  520. VALUES
  521. ('."'$exeId','".$quesId."','$score','".date('Y-m-d H:i:s')."',''".')';
  522. Database::query($recording_changes,__FILE__,__LINE__);
  523. }
  524. if (!empty($quesId) && !empty($exeId) && !empty($user_id)) {
  525. $res = Database::query($sql,__FILE__,__LINE__);
  526. return $res;
  527. } else {
  528. return false;
  529. }
  530. }
  531. /**
  532. * Record an hotspot spot for this attempt at answering an hotspot question
  533. * @param int Exercise ID
  534. * @param int Question ID
  535. * @param int Answer ID
  536. * @param int Whether this answer is correct (1) or not (0)
  537. * @param string Coordinates of this point (e.g. 123;324)
  538. * @return boolean Result of the insert query
  539. * @uses Course code and user_id from global scope $_cid and $_user
  540. */
  541. function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords)
  542. {
  543. global $_configuration, $_user, $_cid;
  544. // if tracking is disabled record nothing
  545. if (!$_configuration['tracking_enabled'])
  546. {
  547. return 0;
  548. }
  549. $current_time = time();
  550. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  551. $expired_date = $_SESSION['expired_time'];
  552. $expired_time = strtotime($expired_date);
  553. }
  554. //Validation in case of fraud
  555. $total_time_allowed = $expired_time + 30;
  556. if ($total_time_allowed < $current_time) {
  557. $correct = 0;
  558. }
  559. $tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  560. $sql = "INSERT INTO $tbl_track_e_hotspot " .
  561. "(hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
  562. " VALUES ('" . Database :: escape_string($_user['user_id']) . "'," .
  563. " '" . Database :: escape_string($_cid) . "', " .
  564. " '" . Database :: escape_string($exe_id) . "', " .
  565. " '" . Database :: escape_string($question_id) . "'," .
  566. " '" . Database :: escape_string($answer_id) . "'," .
  567. " '" . Database :: escape_string($correct) . "'," .
  568. " '" . Database :: escape_string($coords) . "')";
  569. return $result = Database::query($sql, __FILE__, __LINE__);
  570. }
  571. /**
  572. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  573. * @desc Record information for common (or admin) events (in the track_e_default table)
  574. * @param string Type of event
  575. * @param string Type of value
  576. * @param string Value
  577. * @param string Timestamp (defaults to null)
  578. * @param integer User ID (defaults to null)
  579. * @param string Course code (defaults to null)
  580. */
  581. function event_system($event_type, $event_value_type, $event_value, $timestamp = null, $user_id=null, $course_code=null)
  582. {
  583. global $_configuration;
  584. global $_user;
  585. global $TABLETRACK_DEFAULT;
  586. $event_type = Database::escape_string($event_type);
  587. $event_value_type = Database::escape_string($event_value_type);
  588. $event_value = Database::escape_string($event_value);
  589. $timestamp = Database::escape_string($timestamp);
  590. $user_id = Database::escape_string($user_id);
  591. $course_code = Database::escape_string($course_code);
  592. // if tracking is disabled record nothing
  593. if (!$_configuration['tracking_enabled'])
  594. {
  595. return 0;
  596. }
  597. if(!isset($timestamp))
  598. {
  599. $timestamp = time();
  600. }
  601. if(!isset($user_id))
  602. {
  603. $user_id = 0;
  604. }
  605. if(!isset($course_code))
  606. {
  607. $course_code = '';
  608. }
  609. $sql = "INSERT INTO $TABLETRACK_DEFAULT
  610. (default_user_id,
  611. default_cours_code,
  612. default_date,
  613. default_event_type,
  614. default_value_type,
  615. default_value
  616. )
  617. VALUES
  618. ('$user_id.',
  619. '$course_code',
  620. FROM_UNIXTIME($timestamp),
  621. '$event_type',
  622. '$event_value_type',
  623. '$event_value')";
  624. $res = Database::query($sql,__FILE__,__LINE__);
  625. return true;
  626. }
  627. ?>