events.lib.inc.php 18 KB

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