events.lib.inc.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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 = api_sql_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 = api_sql_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. {
  136. $user_id = "'".$_user['user_id']."'";
  137. }
  138. else // anonymous
  139. {
  140. $user_id = "NULL";
  141. }
  142. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  143. (access_user_id,
  144. access_cours_code,
  145. access_date)
  146. VALUES
  147. (".$user_id.",
  148. '".$_cid."',
  149. FROM_UNIXTIME(".$reallyNow."))";
  150. $res = api_sql_query($sql,__FILE__,__LINE__);
  151. // added for "what's new" notification
  152. $sql = " UPDATE $TABLETRACK_LASTACCESS
  153. SET access_date = FROM_UNIXTIME($reallyNow)
  154. WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool IS NULL AND access_session_id=".$id_session;
  155. $res = api_sql_query($sql,__FILE__,__LINE__);
  156. if (Database::affected_rows() == 0)
  157. {
  158. $sql = " INSERT INTO $TABLETRACK_LASTACCESS
  159. (access_user_id,access_cours_code,access_date, access_session_id)
  160. VALUES
  161. (".$user_id.", '".$_cid."', FROM_UNIXTIME($reallyNow), ".$id_session.")";
  162. $res = api_sql_query($sql,__FILE__,__LINE__);
  163. }
  164. // end "what's new" notification
  165. return 1;
  166. }
  167. /**
  168. * @param tool name of the tool (name in mainDb.accueil table)
  169. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  170. * @desc Record information for access event for tools
  171. *
  172. * $tool can take this values :
  173. * Links, Calendar, Document, Announcements,
  174. * Group, Video, Works, Users, Exercices, Course Desc
  175. * ...
  176. * Values can be added if new modules are created (15char max)
  177. * I encourage to use $nameTool as $tool when calling this function
  178. *
  179. * Functionality for "what's new" notification is added by Toon Van Hoecke
  180. */
  181. function event_access_tool($tool, $id_session=0)
  182. {
  183. global $_configuration;
  184. // if tracking is disabled record nothing
  185. // if( ! $_configuration['tracking_enabled'] ) return 0; //commented because "what's new" notification must always occur
  186. global $_user;
  187. global $_cid;
  188. global $TABLETRACK_ACCESS;
  189. global $_configuration;
  190. global $_course;
  191. global $TABLETRACK_LASTACCESS; //for "what's new" notification
  192. if(api_get_setting('use_session_mode')=='true' && isset($_SESSION['id_session']))
  193. {
  194. $id_session = intval($_SESSION['id_session']);
  195. }
  196. else
  197. {
  198. $id_session = 0;
  199. }
  200. $reallyNow = time();
  201. $user_id = $_user['user_id'] ? "'".$_user['user_id']."'" : "NULL"; // "NULL" is anonymous
  202. // record information
  203. // only if user comes from the course $_cid
  204. //if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
  205. //$pos = strpos($_SERVER['HTTP_REFERER'],$_configuration['root_web'].$_cid);
  206. $pos = strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_COURSE_PATH).$_course['path']));
  207. // added for "what's new" notification
  208. $pos2 = strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower($_configuration['root_web']."index"));
  209. // end "what's new" notification
  210. if ($_configuration['tracking_enabled'] && ($pos !== false || $pos2 !== false))
  211. {
  212. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  213. (access_user_id,
  214. access_cours_code,
  215. access_tool,
  216. access_date)
  217. VALUES
  218. (".$user_id.",".// Don't add ' ' around value, it's already done.
  219. "'".$_cid."' ,
  220. '".htmlspecialchars($tool, ENT_QUOTES)."',
  221. FROM_UNIXTIME(".$reallyNow."))";
  222. $res = api_sql_query($sql,__FILE__,__LINE__);
  223. }
  224. // "what's new" notification
  225. $sql = " UPDATE $TABLETRACK_LASTACCESS
  226. SET access_date = FROM_UNIXTIME($reallyNow)
  227. WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool = '".htmlspecialchars($tool, ENT_QUOTES)."' AND access_session_id=".$id_session;
  228. $res = api_sql_query($sql,__FILE__,__LINE__);
  229. if (Database::affected_rows() == 0)
  230. {
  231. $sql = "INSERT INTO $TABLETRACK_LASTACCESS
  232. (access_user_id,access_cours_code,access_tool, access_date, access_session_id)
  233. VALUES
  234. (".$user_id.", '".$_cid."' , '".htmlspecialchars($tool, ENT_QUOTES)."', FROM_UNIXTIME($reallyNow), $id_session)";
  235. $res = api_sql_query($sql,__FILE__,__LINE__);
  236. }
  237. return 1;
  238. }
  239. /**
  240. * @param doc_id id of document (id in mainDb.document table)
  241. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  242. * @desc Record information for download event
  243. * (when an user click to d/l a document)
  244. * it will be used in a redirection page
  245. * bug fixed: Roan Embrechts
  246. * Roan:
  247. * The user id is put in single quotes,
  248. * (why? perhaps to prevent sql insertion hacks?)
  249. * and later again.
  250. * Doing this twice causes an error, I remove one of them.
  251. */
  252. function event_download($doc_url)
  253. {
  254. global $_configuration;
  255. global $_user;
  256. global $_cid;
  257. global $TABLETRACK_DOWNLOADS;
  258. // if tracking is disabled record nothing
  259. if (!$_configuration['tracking_enabled'])
  260. {
  261. return 0;
  262. }
  263. $reallyNow = time();
  264. if ($_user['user_id'])
  265. {
  266. $user_id = "'".$_user['user_id']."'";
  267. }
  268. else // anonymous
  269. {
  270. $user_id = "NULL";
  271. }
  272. $sql = "INSERT INTO ".$TABLETRACK_DOWNLOADS."
  273. (
  274. down_user_id,
  275. down_cours_id,
  276. down_doc_path,
  277. down_date
  278. )
  279. VALUES
  280. (
  281. ".$user_id.",
  282. '".$_cid."',
  283. '".htmlspecialchars($doc_url, ENT_QUOTES)."',
  284. FROM_UNIXTIME(".$reallyNow.")
  285. )";
  286. $res = api_sql_query($sql,__FILE__,__LINE__);
  287. return 1;
  288. }
  289. /**
  290. * @param doc_id id of document (id in mainDb.document table)
  291. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  292. * @desc Record information for upload event
  293. * used in the works tool to record informations when
  294. * an user upload 1 work
  295. */
  296. function event_upload($doc_id)
  297. {
  298. global $_configuration;
  299. global $_user;
  300. global $_cid;
  301. global $TABLETRACK_UPLOADS;
  302. // if tracking is disabled record nothing
  303. if (!$_configuration['tracking_enabled'])
  304. {
  305. return 0;
  306. }
  307. $reallyNow = time();
  308. if ($_user['user_id'])
  309. {
  310. $user_id = "'".$_user['user_id']."'";
  311. }
  312. else // anonymous
  313. {
  314. $user_id = "NULL";
  315. }
  316. $sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
  317. (
  318. upload_user_id,
  319. upload_cours_id,
  320. upload_work_id,
  321. upload_date
  322. )
  323. VALUES
  324. (
  325. ".$user_id.",
  326. '".$_cid."',
  327. '".$doc_id."',
  328. FROM_UNIXTIME(".$reallyNow.")
  329. )";
  330. $res = api_sql_query($sql,__FILE__,__LINE__);
  331. return 1;
  332. }
  333. /**
  334. * @param link_id (id in coursDb liens table)
  335. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  336. * @desc Record information for link event (when an user click on an added link)
  337. * it will be used in a redirection page
  338. */
  339. function event_link($link_id)
  340. {
  341. global $_configuration;
  342. global $_user;
  343. global $_cid;
  344. global $TABLETRACK_LINKS;
  345. // if tracking is disabled record nothing
  346. if (!$_configuration['tracking_enabled']) {
  347. return 0;
  348. }
  349. $reallyNow = time();
  350. if ($_user['user_id']) {
  351. $user_id = "'".Database::escape_string($_user['user_id'])."'";
  352. } else {
  353. // anonymous
  354. $user_id = "NULL";
  355. }
  356. $sql = "INSERT INTO ".$TABLETRACK_LINKS."
  357. ( links_user_id,
  358. links_cours_id,
  359. links_link_id,
  360. links_date
  361. )
  362. VALUES
  363. (
  364. ".$user_id.",
  365. '".$_cid."',
  366. '".Database::escape_string($link_id)."',
  367. FROM_UNIXTIME(".$reallyNow.")
  368. )";
  369. $res = api_sql_query($sql,__FILE__,__LINE__);
  370. return 1;
  371. }
  372. /**
  373. * @param exeid ( id of the exercise)
  374. * @param exo_id ( id in courseDb exercices table )
  375. * @param result ( score @ exercice )
  376. * @param weighting ( higher score )
  377. * @param duration ( duration of the attempt, in seconds )
  378. * @param session_id
  379. * @param learnpath_id (id of the learnpath)
  380. * @param learnpath_item_id (id of the learnpath_item)
  381. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  382. * @author Julio Montoya Armas <gugli100@gmail.com>
  383. * @desc Record result of user when an exercice was done
  384. */
  385. function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0, $duration)
  386. {
  387. if ($exeid!='') {
  388. $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  389. $reallyNow = time();
  390. $sql = "UPDATE $TABLETRACK_EXERCICES SET
  391. exe_exo_id = '".Database::escape_string($exo_id)."',
  392. exe_result = '".Database::escape_string($score)."',
  393. exe_weighting = '".Database::escape_string($weighting)."',
  394. session_id = '".Database::escape_string($session_id)."',
  395. orig_lp_id = '".Database::escape_string($learnpath_id)."',
  396. orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
  397. exe_duration = '".Database::escape_string($duration)."',
  398. exe_date= FROM_UNIXTIME(".$reallyNow."),status = '', data_tracking='',start_date =FROM_UNIXTIME(".Database::escape_string($_SESSION['exercice_start_date']).")
  399. WHERE exe_id = '".Database::escape_string($exeid)."'";
  400. $res = @api_sql_query($sql,__FILE__,__LINE__);
  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 ($_user['user_id']) {
  418. $user_id = "'".$_user['user_id']."'";
  419. } else {
  420. // anonymous
  421. $user_id = "NULL";
  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 = api_sql_query('SELECT exe_id FROM '.$TABLETRACK_EXERCICES.$condition,__FILE__,__LINE__);
  431. $row = Database::fetch_array($sql);
  432. return $row['exe_id'];
  433. }
  434. $sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id )
  435. VALUES ( ".$user_id.", '".$_cid."' )";
  436. $res = @api_sql_query($sql,__FILE__,__LINE__);
  437. $id= Database::get_last_insert_id();
  438. return $id;
  439. }
  440. /**
  441. * Record an event for this attempt at answering an exercise
  442. * @param float Score achieved
  443. * @param string Answer given
  444. * @param integer Question ID
  445. * @param integer Exercise ID
  446. * @param integer Position
  447. * @return boolean Result of the insert query
  448. */
  449. function exercise_attempt($score,$answer,$quesId,$exeId,$j)
  450. {
  451. $score = Database::escape_string($score);
  452. $answer = Database::escape_string($answer);
  453. $quesId = Database::escape_string($quesId);
  454. $exeId = Database::escape_string($exeId);
  455. $j = Database::escape_string($j);
  456. global $_configuration, $_user, $_cid;
  457. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  458. // if tracking is disabled record nothing
  459. if (!$_configuration['tracking_enabled'])
  460. {
  461. return 0;
  462. }
  463. $reallyNow = time();
  464. if ($_user['user_id'])
  465. {
  466. $user_id = "'".$_user['user_id']."'";
  467. }
  468. else // anonymous
  469. {
  470. $user_id = api_get_anonymous_id();
  471. }
  472. $sql = "INSERT INTO $TBL_TRACK_ATTEMPT
  473. (
  474. exe_id,
  475. user_id,
  476. question_id,
  477. answer,
  478. marks,
  479. course_code,
  480. position,
  481. tms
  482. )
  483. VALUES
  484. (
  485. ".$exeId.",
  486. ".$user_id.",
  487. '".$quesId."',
  488. '".addslashes($answer)."',
  489. '".$score."',
  490. '".$_cid."',
  491. '".$j."',
  492. FROM_UNIXTIME(".$reallyNow.")
  493. )";
  494. if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
  495. $TBL_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  496. $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
  497. '(exe_id,
  498. question_id,
  499. marks,
  500. insert_date,
  501. author)
  502. VALUES
  503. ('."'$exeId','".$quesId."','$score','".date('Y-m-d H:i:s')."',''".')';
  504. api_sql_query($recording_changes,__FILE__,__LINE__);
  505. }
  506. if (isset($quesId) && isset($exeId) && isset($user_id)) {
  507. $res = api_sql_query($sql,__FILE__,__LINE__);
  508. return $res;
  509. } else {
  510. return false;
  511. }
  512. }
  513. /**
  514. * Record an hotspot spot for this attempt at answering an hotspot question
  515. * @param int Exercise ID
  516. * @param int Question ID
  517. * @param int Answer ID
  518. * @param int Whether this answer is correct (1) or not (0)
  519. * @param string Coordinates of this point (e.g. 123;324)
  520. * @return boolean Result of the insert query
  521. * @uses Course code and user_id from global scope $_cid and $_user
  522. */
  523. function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords)
  524. {
  525. global $_configuration, $_user, $_cid;
  526. // if tracking is disabled record nothing
  527. if (!$_configuration['tracking_enabled'])
  528. {
  529. return 0;
  530. }
  531. $tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  532. $sql = "INSERT INTO $tbl_track_e_hotspot " .
  533. "(hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
  534. " VALUES ('" . Database :: escape_string($_user['user_id']) . "'," .
  535. " '" . Database :: escape_string($_cid) . "', " .
  536. " '" . Database :: escape_string($exe_id) . "', " .
  537. " '" . Database :: escape_string($question_id) . "'," .
  538. " '" . Database :: escape_string($answer_id) . "'," .
  539. " '" . Database :: escape_string($correct) . "'," .
  540. " '" . Database :: escape_string($coords) . "')";
  541. return $result = api_sql_query($sql, __FILE__, __LINE__);
  542. }
  543. /**
  544. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  545. * @desc Record information for common (or admin) events (in the track_e_default table)
  546. * @param string Type of event
  547. * @param string Type of value
  548. * @param string Value
  549. * @param string Timestamp (defaults to null)
  550. * @param integer User ID (defaults to null)
  551. * @param string Course code (defaults to null)
  552. */
  553. function event_system($event_type, $event_value_type, $event_value, $timestamp = null, $user_id=null, $course_code=null)
  554. {
  555. global $_configuration;
  556. global $_user;
  557. global $TABLETRACK_DEFAULT;
  558. $event_type = Database::escape_string($event_type);
  559. $event_value_type = Database::escape_string($event_value_type);
  560. $event_value = Database::escape_string($event_value);
  561. $timestamp = Database::escape_string($timestamp);
  562. $user_id = Database::escape_string($user_id);
  563. $course_code = Database::escape_string($course_code);
  564. // if tracking is disabled record nothing
  565. if (!$_configuration['tracking_enabled'])
  566. {
  567. return 0;
  568. }
  569. if(!isset($timestamp))
  570. {
  571. $timestamp = time();
  572. }
  573. if(!isset($user_id))
  574. {
  575. $user_id = 0;
  576. }
  577. if(!isset($course_code))
  578. {
  579. $course_code = '';
  580. }
  581. $sql = "INSERT INTO $TABLETRACK_DEFAULT
  582. (default_user_id,
  583. default_cours_code,
  584. default_date,
  585. default_event_type,
  586. default_value_type,
  587. default_value
  588. )
  589. VALUES
  590. ('$user_id.',
  591. '$course_code',
  592. FROM_UNIXTIME($timestamp),
  593. '$event_type',
  594. '$event_value_type',
  595. '$event_value')";
  596. $res = api_sql_query($sql,__FILE__,__LINE__);
  597. return true;
  598. }
  599. ?>