events.lib.inc.php 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. <?php
  2. /* See license terms in /license.txt */
  3. /**
  4. * EVENTS LIBRARY
  5. *
  6. * This is the events library for Chamilo.
  7. * Include/require it in your code to use its functionality.
  8. * Functions of this library are used to record informations when some kind
  9. * of event occur. Each event has his own types of informations then each event
  10. * use its own function.
  11. *
  12. * @package chamilo.library
  13. */
  14. /**
  15. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  16. * @desc Record information for open event (when homepage is opened)
  17. */
  18. function event_open()
  19. {
  20. global $_configuration;
  21. $TABLETRACK_OPEN = Database::get_main_table(TABLE_STATISTIC_TRACK_E_OPEN);
  22. // @getHostByAddr($_SERVER['REMOTE_ADDR']) : will provide host and country information
  23. // $_SERVER['HTTP_USER_AGENT'] : will provide browser and os information
  24. // $_SERVER['HTTP_REFERER'] : provide information about refering url
  25. if (isset($_SERVER['HTTP_REFERER'])) {
  26. $referer = Database::escape_string($_SERVER['HTTP_REFERER']);
  27. } else {
  28. $referer = '';
  29. }
  30. // record informations only if user comes from another site
  31. //if(!eregi($_configuration['root_web'],$referer))
  32. $pos = strpos($referer, $_configuration['root_web']);
  33. if ($pos === false && $referer != '') {
  34. $ip = api_get_real_ip();
  35. $remhost = @ getHostByAddr($ip);
  36. if ($remhost == $ip)
  37. $remhost = "Unknown"; // don't change this
  38. $reallyNow = api_get_utc_datetime();
  39. $sql = "INSERT INTO ".$TABLETRACK_OPEN."
  40. (open_remote_host,
  41. open_agent,
  42. open_referer,
  43. open_date)
  44. VALUES
  45. ('".$remhost."',
  46. '".Database::escape_string($_SERVER['HTTP_USER_AGENT'])."', '".Database::escape_string($referer)."', '$reallyNow')";
  47. $res = Database::query($sql);
  48. }
  49. return 1;
  50. }
  51. /**
  52. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  53. * @desc Record information for login event
  54. * (when an user identifies himself with username & password)
  55. */
  56. function event_login()
  57. {
  58. $TABLETRACK_LOGIN = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  59. $_user = api_get_user_info();
  60. $reallyNow = api_get_utc_datetime();
  61. $sql = "INSERT INTO ".$TABLETRACK_LOGIN." (login_user_id, login_ip, login_date, logout_date) VALUES
  62. ('".api_get_user_id()."',
  63. '".Database::escape_string(api_get_real_ip())."',
  64. '".$reallyNow."',
  65. '".$reallyNow."'
  66. )";
  67. Database::query($sql);
  68. // auto subscribe
  69. $user_status = $_user['status'] == SESSIONADMIN ? 'sessionadmin' :
  70. $_user['status'] == COURSEMANAGER ? 'teacher' :
  71. $_user['status'] == DRH ? 'DRH' : 'student';
  72. $autoSubscribe = api_get_setting($user_status.'_autosubscribe');
  73. if ($autoSubscribe) {
  74. $autoSubscribe = explode('|', $autoSubscribe);
  75. foreach ($autoSubscribe as $code) {
  76. if (CourseManager::course_exists($code)) {
  77. CourseManager::subscribe_user($_user['user_id'], $code);
  78. }
  79. }
  80. }
  81. }
  82. /**
  83. * @param tool name of the tool (name in mainDb.accueil table)
  84. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  85. * @desc Record information for access event for courses
  86. */
  87. function event_access_course()
  88. {
  89. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  90. $TABLETRACK_LASTACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); //for "what's new" notification
  91. $id_session = api_get_session_id();
  92. $now = api_get_utc_datetime();
  93. $courseId = api_get_course_int_id();
  94. $user_id = api_get_user_id();
  95. if ($user_id) {
  96. $user_id = "'".$user_id."'";
  97. } else {
  98. $user_id = "0"; // no one
  99. }
  100. $sql = "INSERT INTO ".$TABLETRACK_ACCESS." (access_user_id, c_id, access_date, access_session_id) VALUES
  101. (".$user_id.", '".$courseId."', '".$now."','".$id_session."')";
  102. Database::query($sql);
  103. // added for "what's new" notification
  104. $sql = "UPDATE $TABLETRACK_LASTACCESS SET access_date = '$now'
  105. WHERE access_user_id = $user_id AND c_id = '$courseId' AND access_tool IS NULL AND access_session_id=".$id_session;
  106. Database::query($sql);
  107. if (Database::affected_rows() == 0) {
  108. $sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id, c_id, access_date, access_session_id)
  109. VALUES (".$user_id.", '".$courseId."', '$now', '".$id_session."')";
  110. Database::query($sql);
  111. }
  112. // end "what's new" notification
  113. return 1;
  114. }
  115. /**
  116. * @param tool name of the tool (name in mainDb.accueil table)
  117. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  118. * @desc Record information for access event for tools
  119. *
  120. * $tool can take this values :
  121. * Links, Calendar, Document, Announcements,
  122. * Group, Video, Works, Users, Exercices, Course Desc
  123. * ...
  124. * Values can be added if new modules are created (15char max)
  125. * I encourage to use $nameTool as $tool when calling this function
  126. *
  127. * Functionality for "what's new" notification is added by Toon Van Hoecke
  128. */
  129. function event_access_tool($tool, $id_session = 0)
  130. {
  131. global $_configuration;
  132. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  133. $TABLETRACK_LASTACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); //for "what's new" notification
  134. $_course = api_get_course_info();
  135. $courseId = api_get_course_int_id();
  136. $id_session = api_get_session_id();
  137. $tool = Database::escape_string($tool);
  138. $reallyNow = api_get_utc_datetime();
  139. $user_id = api_get_user_id();
  140. // record information
  141. // only if user comes from the course $_cid
  142. //if( eregi($_configuration['root_web'].$_cid,$_SERVER['HTTP_REFERER'] ) )
  143. //$pos = strpos($_SERVER['HTTP_REFERER'],$_configuration['root_web'].$_cid);
  144. $pos = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower(api_get_path(WEB_COURSE_PATH).$_course['path'])) : false;
  145. // added for "what's new" notification
  146. $pos2 = isset($_SERVER['HTTP_REFERER']) ? strpos(strtolower($_SERVER['HTTP_REFERER']), strtolower($_configuration['root_web']."index")) : false;
  147. // end "what's new" notification
  148. if ($pos !== false || $pos2 !== false) {
  149. $sql = "INSERT INTO ".$TABLETRACK_ACCESS."
  150. (access_user_id,
  151. c_id,
  152. access_tool,
  153. access_date,
  154. access_session_id
  155. )
  156. VALUES
  157. (".$user_id.",".// Don't add ' ' around value, it's already done.
  158. "'".$courseId."' ,
  159. '".$tool."',
  160. '".$reallyNow."',
  161. '".$id_session."')";
  162. Database::query($sql);
  163. }
  164. // "what's new" notification
  165. $sql = "UPDATE $TABLETRACK_LASTACCESS
  166. SET access_date = '$reallyNow'
  167. WHERE access_user_id = ".$user_id." AND c_id = '".$courseId."' AND access_tool = '".$tool."' AND access_session_id=".$id_session;
  168. Database::query($sql);
  169. if (Database::affected_rows() == 0) {
  170. $sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id, c_id, access_tool, access_date, access_session_id)
  171. VALUES (".$user_id.", '".$courseId."' , '$tool', '$reallyNow', $id_session)";
  172. Database::query($sql);
  173. }
  174. return 1;
  175. }
  176. /**
  177. * @param doc_id id of document (id in mainDb.document table)
  178. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  179. * @desc Record information for download event
  180. * (when an user click to d/l a document)
  181. * it will be used in a redirection page
  182. * bug fixed: Roan Embrechts
  183. * Roan:
  184. * The user id is put in single quotes,
  185. * (why? perhaps to prevent sql insertion hacks?)
  186. * and later again.
  187. * Doing this twice causes an error, I remove one of them.
  188. */
  189. function event_download($doc_url)
  190. {
  191. $tbl_stats_downloads = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  192. $doc_url = Database::escape_string($doc_url);
  193. $reallyNow = api_get_utc_datetime();
  194. $user_id = "'".api_get_user_id()."'";
  195. $_cid = api_get_course_int_id();
  196. $sql = "INSERT INTO $tbl_stats_downloads (
  197. down_user_id,
  198. c_id,
  199. down_doc_path,
  200. down_date,
  201. down_session_id
  202. )
  203. VALUES (
  204. ".$user_id.",
  205. '".$_cid."',
  206. '".$doc_url."',
  207. '".$reallyNow."',
  208. '".api_get_session_id()."'
  209. )";
  210. Database::query($sql);
  211. return 1;
  212. }
  213. /**
  214. * @param doc_id id of document (id in mainDb.document table)
  215. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  216. * @desc Record information for upload event
  217. * used in the works tool to record informations when
  218. * an user upload 1 work
  219. */
  220. function event_upload($doc_id)
  221. {
  222. $TABLETRACK_UPLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_UPLOADS);
  223. $courseCode = api_get_course_id();
  224. $reallyNow = api_get_utc_datetime();
  225. $user_id = api_get_user_id();
  226. $sql = "INSERT INTO ".$TABLETRACK_UPLOADS."
  227. ( upload_user_id,
  228. upload_cours_id,
  229. upload_work_id,
  230. upload_date,
  231. upload_session_id
  232. )
  233. VALUES (
  234. ".$user_id.",
  235. '".$courseCode."',
  236. '".$doc_id."',
  237. '".$reallyNow."',
  238. '".api_get_session_id()."'
  239. )";
  240. Database::query($sql);
  241. return 1;
  242. }
  243. /**
  244. * @param link_id (id in coursDb liens table)
  245. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  246. * @desc Record information for link event (when an user click on an added link)
  247. * it will be used in a redirection page
  248. */
  249. function event_link($link_id)
  250. {
  251. $TABLETRACK_LINKS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LINKS);
  252. $reallyNow = api_get_utc_datetime();
  253. $user_id = api_get_user_id();
  254. $sql = "INSERT INTO ".$TABLETRACK_LINKS."
  255. ( links_user_id,
  256. c_id,
  257. links_link_id,
  258. links_date,
  259. links_session_id
  260. ) VALUES (
  261. ".$user_id.",
  262. '".api_get_course_int_id()."',
  263. '".Database::escape_string($link_id)."',
  264. '".$reallyNow."',
  265. '".api_get_session_id()."'
  266. )";
  267. Database::query($sql);
  268. return 1;
  269. }
  270. /**
  271. * Update the TRACK_E_EXERCICES exercises
  272. *
  273. * @param int id of the attempt
  274. * @param int exercise id
  275. * @param mixed score obtained
  276. * @param int highest score for this exercise (and combination of questions)
  277. * @param int duration ( duration of the attempt in seconds )
  278. * @param int session_id
  279. * @param int learnpath_id (id of the learnpath)
  280. * @param int learnpath_item_id (id of the learnpath_item)
  281. *
  282. * @author Sebastien Piraux <piraux_seb@hotmail.com>
  283. * @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
  284. * @desc Record result of user when an exercice was done
  285. */
  286. function update_event_exercise($exeid, $exo_id, $score, $weight, $session_id, $learnpath_id = 0, $learnpath_item_id = 0, $learnpath_item_view_id = 0, $duration = 0, $status = '', $remind_list = array() , $end_date = null) {
  287. global $debug;
  288. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  289. if ($debug) {
  290. error_log('Called to update_event_exercise');
  291. error_log('duration:'.$duration);
  292. }
  293. if (!empty($exeid)) {
  294. // Validation in case of fraud with actived control time
  295. if (!ExerciseLib::exercise_time_control_is_valid($exo_id, $learnpath_id, $learnpath_item_id)) {
  296. $score = 0;
  297. }
  298. if (!isset($status) || empty($status)) {
  299. $status = '';
  300. } else {
  301. $status = Database::escape_string($status);
  302. }
  303. if (!empty($remind_list)) {
  304. $remind_list = array_map('intval', $remind_list);
  305. $remind_list = array_filter($remind_list);
  306. $remind_list = implode(",", $remind_list);
  307. } else {
  308. $remind_list = '';
  309. }
  310. if (empty($end_date)) {
  311. $end_date = api_get_utc_datetime();
  312. }
  313. $sql = "UPDATE $TABLETRACK_EXERCICES SET
  314. exe_exo_id = '".Database::escape_string($exo_id)."',
  315. exe_result = '".Database::escape_string($score)."',
  316. exe_weighting = '".Database::escape_string($weight)."',
  317. session_id = '".Database::escape_string($session_id)."',
  318. orig_lp_id = '".Database::escape_string($learnpath_id)."',
  319. orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
  320. orig_lp_item_view_id = '".Database::escape_string($learnpath_item_view_id)."',
  321. exe_duration = '".Database::escape_string($duration)."',
  322. exe_date = '".$end_date."',
  323. status = '".$status."',
  324. questions_to_check = '".$remind_list."'
  325. WHERE exe_id = '".Database::escape_string($exeid)."'";
  326. $res = Database::query($sql);
  327. if ($debug) {
  328. error_log('update_event_exercise called');
  329. error_log("$sql");
  330. }
  331. //Deleting control time session track
  332. //ExerciseLib::exercise_time_control_delete($exo_id);
  333. return $res;
  334. } else {
  335. return false;
  336. }
  337. }
  338. /**
  339. * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table.
  340. * After that in exercise_result.php we call the update_event_exercise() to update the exercise
  341. * @return int $id the last id registered, or false on error
  342. * @author Julio Montoya <gugli100@gmail.com>
  343. * @desc Record result of user when an exercice was done
  344. * @deprecated this function seems to be deprecated
  345. */
  346. function createEventExercise($exo_id)
  347. {
  348. if (empty($exo_id) or (intval($exo_id) != $exo_id)) {
  349. return false;
  350. }
  351. $tbl_track_exe = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  352. $tbl_exe = Database::get_course_table(TABLE_QUIZ_TEST);
  353. $uid = api_get_user_id();
  354. $course_id = api_get_course_int_id();
  355. // First, check the exercise exists
  356. $sql_exe_id = "SELECT exercises.id FROM $tbl_exe as exercises WHERE c_id = $course_id AND exercises.id=$exo_id";
  357. $res_exe_id = Database::query($sql_exe_id);
  358. if ($res_exe_id === false) {
  359. return false;
  360. } //sql error
  361. if (Database::num_rows($res_exe_id) < 1) {
  362. return false;
  363. } //exe not found
  364. $row_exe_id = Database::fetch_row($res_exe_id);
  365. $exercise_id = intval($row_exe_id[0]);
  366. // Second, check if the record exists in the database (looking for incomplete records)
  367. $sql = "SELECT exe_id FROM $tbl_track_exe
  368. WHERE exe_exo_id = $exo_id AND
  369. exe_user_id = $uid AND c_id = '".$course_id."' AND ".
  370. "status = 'incomplete' AND ".
  371. "session_id = ".api_get_session_id();
  372. $res = Database::query($sql);
  373. if ($res === false) {
  374. return false;
  375. }
  376. if (Database::num_rows($res) > 0) {
  377. $row = Database::fetch_array($res);
  378. return $row['exe_id'];
  379. }
  380. // No record was found, so create one
  381. // get expire time to insert into the tracking record
  382. $current_expired_time_key = ExerciseLib::get_time_control_key($exercise_id);
  383. if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
  384. $expired_date = $_SESSION['expired_time'][$current_expired_time_key];
  385. } else {
  386. $expired_date = '0000-00-00 00:00:00';
  387. }
  388. $sql = "INSERT INTO $tbl_track_exe (exe_user_id, c_id, expired_time_control, exe_exo_id, session_id)
  389. VALUES ($uid, '".$course_id."' ,'$expired_date','$exo_id','".api_get_session_id()."')";
  390. Database::query($sql);
  391. $id = Database::insert_id();
  392. return $id;
  393. }
  394. /**
  395. * Record an event for this attempt at answering an exercise
  396. * @param float Score achieved
  397. * @param string Answer given
  398. * @param integer Question ID
  399. * @param integer Exercise ID
  400. * @param integer Position
  401. * @return boolean Result of the insert query
  402. */
  403. function saveExerciseAttempt($score, $answer, $question_id, $exe_id, $position, $exercise_id = 0, $nano = null)
  404. {
  405. global $debug, $learnpath_id, $learnpath_item_id;
  406. $score = Database::escape_string($score);
  407. $answer = Database::escape_string($answer);
  408. $question_id = Database::escape_string($question_id);
  409. $exe_id = Database::escape_string($exe_id);
  410. $position = Database::escape_string($position);
  411. $now = api_get_utc_datetime();
  412. $user_id = api_get_user_id();
  413. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  414. if ($debug) {
  415. error_log("----- entering saveExerciseAttempt() function ------");
  416. error_log("answer: $answer");
  417. error_log("score: $score");
  418. error_log("question_id : $question_id");
  419. error_log("position: $position");
  420. }
  421. //Validation in case of fraud with active control time
  422. if (!ExerciseLib::exercise_time_control_is_valid($exercise_id, $learnpath_id, $learnpath_item_id)) {
  423. if ($debug) {
  424. error_log("exercise_time_control_is_valid is false");
  425. }
  426. $score = 0;
  427. $answer = 0;
  428. }
  429. if (!empty($user_id)) {
  430. $user_id = "'".$user_id."'";
  431. } else {
  432. // anonymous
  433. $user_id = api_get_anonymous_id();
  434. }
  435. $file = '';
  436. if (isset($nano)) {
  437. $file = Database::escape_string(basename($nano->load_filename_if_exists(false)));
  438. }
  439. $courseId = api_get_course_int_id();
  440. $session_id = api_get_session_id();
  441. if (!empty($question_id) && !empty($exe_id) && !empty($user_id)) {
  442. //Check if attempt exists
  443. $sql = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT
  444. WHERE c_id = $courseId AND
  445. session_id = $session_id AND
  446. exe_id = $exe_id AND
  447. user_id = $user_id AND
  448. question_id = $question_id AND
  449. position = $position";
  450. $result = Database::query($sql);
  451. if (Database::num_rows($result)) {
  452. if ($debug)
  453. error_log("Attempt already exist: exe_id: $exe_id - user_id:$user_id - question_id:$question_id");
  454. //The attempt already exist do not update use update_event_exercise() instead
  455. return false;
  456. }
  457. $sql = "INSERT INTO $TBL_TRACK_ATTEMPT (exe_id, user_id, question_id, answer, marks, c_id, session_id, position, tms, filename)
  458. VALUES (
  459. ".$exe_id.",
  460. ".$user_id.",
  461. '".$question_id."',
  462. '".$answer."',
  463. '".$score."',
  464. '".$courseId."',
  465. '".$session_id."',
  466. '".$position."',
  467. '".$now."',
  468. '".$file."'
  469. )";
  470. if ($debug) {
  471. error_log("Saving question attempt: ");
  472. error_log($sql);
  473. }
  474. $res = Database::query($sql);
  475. if (defined('ENABLED_LIVE_EXERCISE_TRACKING')) {
  476. $recording_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  477. if ($debug) {
  478. error_log("Saving e attempt recording ");
  479. }
  480. $recording_changes = "INSERT INTO $recording_table (exe_id, question_id, marks, insert_date, author, session_id) VALUES ('$exe_id','$question_id','$score','".api_get_utc_datetime()."','', '".api_get_session_id()."') ";
  481. Database::query($recording_changes);
  482. }
  483. return $res;
  484. } else {
  485. return false;
  486. }
  487. }
  488. /**
  489. * Record an hotspot spot for this attempt at answering an hotspot question
  490. * @param int Exercise ID
  491. * @param int Question ID
  492. * @param int Answer ID
  493. * @param int Whether this answer is correct (1) or not (0)
  494. * @param string Coordinates of this point (e.g. 123;324)
  495. * @return boolean Result of the insert query
  496. * @uses Course code and user_id from global scope $_cid and $_user
  497. */
  498. function saveExerciseAttemptHotspot($exe_id, $question_id, $answer_id, $correct, $coords, $exerciseId = 0)
  499. {
  500. global $safe_lp_id, $safe_lp_item_id;
  501. //Validation in case of fraud with actived control time
  502. if (!ExerciseLib::exercise_time_control_is_valid($exerciseId, $safe_lp_id, $safe_lp_item_id)) {
  503. $correct = 0;
  504. }
  505. $tbl_track_e_hotspot = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  506. $sql = "INSERT INTO $tbl_track_e_hotspot (hotspot_user_id, c_id, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
  507. " VALUES ('".api_get_user_id()."',".
  508. " '".api_get_course_int_id()."', ".
  509. " '".Database :: escape_string($exe_id)."', ".
  510. " '".Database :: escape_string($question_id)."',".
  511. " '".Database :: escape_string($answer_id)."',".
  512. " '".Database :: escape_string($correct)."',".
  513. " '".Database :: escape_string($coords)."')";
  514. return $result = Database::query($sql);
  515. }
  516. /**
  517. * Records information for common (or admin) events (in the track_e_default table)
  518. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  519. * @param string Type of event
  520. * @param string Type of value
  521. * @param string Value
  522. * @param string Timestamp (defaults to null)
  523. * @param integer User ID (defaults to null)
  524. * @param string Course code (defaults to null)
  525. * @assert ('','','') === false
  526. */
  527. function event_system($event_type, $event_value_type, $event_value, $datetime = null, $user_id = null, $course_code = null)
  528. {
  529. $TABLETRACK_DEFAULT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
  530. if (empty($event_type)) {
  531. return false;
  532. }
  533. $event_type = Database::escape_string($event_type);
  534. $event_value_type = Database::escape_string($event_value_type);
  535. //Clean the user_info
  536. if ($event_value_type == LOG_USER_OBJECT) {
  537. if (is_array($event_value)) {
  538. unset($event_value['complete_name']);
  539. unset($event_value['complete_name_with_username']);
  540. unset($event_value['firstName']);
  541. unset($event_value['lastName']);
  542. unset($event_value['avatar_small']);
  543. unset($event_value['avatar_sys_path']);
  544. unset($event_value['avatar']);
  545. unset($event_value['mail']);
  546. unset($event_value['password']);
  547. unset($event_value['lastLogin']);
  548. unset($event_value['picture_uri']);
  549. $event_value = serialize($event_value);
  550. }
  551. }
  552. $event_value = Database::escape_string($event_value);
  553. $course_info = api_get_course_info($course_code);
  554. if (!empty($course_info)) {
  555. $course_id = $course_info['real_id'];
  556. $course_code = $course_info['code'];
  557. $course_code = Database::escape_string($course_code);
  558. } else {
  559. $course_id = null;
  560. $course_code = null;
  561. }
  562. if (!isset($datetime)) {
  563. $datetime = api_get_utc_datetime();
  564. }
  565. $datetime = Database::escape_string($datetime);
  566. if (!isset($user_id)) {
  567. $user_id = api_get_user_id();
  568. }
  569. $user_id = intval($user_id);
  570. $sql = "INSERT INTO $TABLETRACK_DEFAULT
  571. (default_user_id,
  572. default_cours_code,
  573. c_id,
  574. default_date,
  575. default_event_type,
  576. default_value_type,
  577. default_value
  578. )
  579. VALUES('$user_id.',
  580. '$course_code',
  581. '$course_id',
  582. '$datetime',
  583. '$event_type',
  584. '$event_value_type',
  585. '$event_value')";
  586. Database::query($sql);
  587. return true;
  588. }
  589. /**
  590. * Get every email stored in the database
  591. *
  592. * @param int $etId
  593. * @return type
  594. * @assert () !== false
  595. */
  596. function get_all_event_types()
  597. {
  598. global $event_config;
  599. $sql = 'SELECT etm.id, event_type_name, activated, language_id, message, subject, dokeos_folder
  600. FROM '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).' etm
  601. INNER JOIN '.Database::get_main_table(TABLE_MAIN_LANGUAGE).' l
  602. ON etm.language_id = l.id';
  603. $events_types = Database::store_result(Database::query($sql), 'ASSOC');
  604. $to_return = array();
  605. foreach ($events_types as $et) {
  606. $et['nameLangVar'] = $event_config[$et["event_type_name"]]["name_lang_var"];
  607. $et['descLangVar'] = $event_config[$et["event_type_name"]]["desc_lang_var"];
  608. $to_return[] = $et;
  609. }
  610. return $to_return;
  611. }
  612. /**
  613. * Get users linked to an event
  614. *
  615. * @param int $etId
  616. * @return type
  617. */
  618. function get_users_subscribed_to_event($event_name)
  619. {
  620. $event_name = Database::escape_string($event_name);
  621. $sql = 'SELECT u.* FROM '.Database::get_main_table(TABLE_MAIN_USER).' u,'
  622. .Database::get_main_table(TABLE_MAIN_EVENT_TYPE).' e,'
  623. .Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' ue
  624. WHERE ue.user_id = u.user_id
  625. AND e.name = "'.$event_name.'"
  626. AND e.id = ue.event_type_id';
  627. $return = Database::store_result(Database::query($sql), 'ASSOC');
  628. return json_encode($return);
  629. }
  630. /**
  631. * Get the users related to one event
  632. *
  633. * @param string $event_name
  634. */
  635. function get_event_users($event_name)
  636. {
  637. $event_name = Database::escape_string($event_name);
  638. $sql = 'SELECT user.user_id, user.firstname, user.lastname FROM '.Database::get_main_table(TABLE_MAIN_USER).' user JOIN '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' relUser
  639. ON relUser.user_id = user.user_id
  640. WHERE user.status <> '.ANONYMOUS.' AND relUser.event_type_name = "'.$event_name.'"';
  641. //For tests
  642. //$sql = 'SELECT user.user_id, user.firstname, user.lastname FROM '.Database::get_main_table(TABLE_MAIN_USER);
  643. $user_list = Database::store_result(Database::query($sql), 'ASSOC');
  644. return json_encode($user_list);
  645. }
  646. function get_events_by_user_and_type($user_id, $event_type)
  647. {
  648. $TABLETRACK_DEFAULT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
  649. $user_id = intval($user_id);
  650. $event_type = Database::escape_string($event_type);
  651. $sql = "SELECT * FROM $TABLETRACK_DEFAULT
  652. WHERE default_value_type = 'user_id' AND
  653. default_value = $user_id AND
  654. default_event_type = '$event_type'
  655. ORDER BY default_date ";
  656. $result = Database::query($sql);
  657. if ($result) {
  658. return Database::store_result($result, 'ASSOC');
  659. }
  660. return false;
  661. }
  662. function get_latest_event_by_user_and_type($user_id, $event_type)
  663. {
  664. $result = get_events_by_user_and_type($user_id, $event_type);
  665. if ($result && !empty($result)) {
  666. return $result[0];
  667. }
  668. }
  669. /**
  670. * Save the new message for one event and for one language
  671. *
  672. * @param string $eventName
  673. * @param array $users
  674. * @param string $message
  675. * @param string $subject
  676. * @param string $eventMessageLanguage
  677. * @param int $activated
  678. */
  679. function save_event_type_message($event_name, $users, $message, $subject, $event_message_language, $activated)
  680. {
  681. $event_name = Database::escape_string($event_name);
  682. $activated = intval($activated);
  683. $event_message_language = Database::escape_string($event_message_language);
  684. // Deletes then re-adds the users linked to the event
  685. $sql = 'DELETE FROM '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' WHERE event_type_name = "'.$event_name.'" ';
  686. Database::query($sql);
  687. foreach ($users as $user) {
  688. $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' (user_id,event_type_name) VALUES('.intval($user).',"'.$event_name.'")';
  689. Database::query($sql);
  690. }
  691. $language_id = api_get_language_id($event_message_language);
  692. // check if this template in this language already exists or not
  693. $sql = 'SELECT COUNT(id) as total FROM '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).'
  694. WHERE event_type_name = "'.$event_name.'" AND language_id = '.$language_id;
  695. $sql = Database::store_result(Database::query($sql), 'ASSOC');
  696. // if already exists, we update
  697. if ($sql[0]["total"] > 0) {
  698. $sql = 'UPDATE '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).'
  699. SET message = "'.Database::escape_string($message).'",
  700. subject = "'.Database::escape_string($subject).'",
  701. activated = '.$activated.'
  702. WHERE event_type_name = "'.$event_name.'" AND language_id = (SELECT id FROM '.Database::get_main_table(TABLE_MAIN_LANGUAGE).'
  703. WHERE dokeos_folder = "'.$event_message_language.'")';
  704. Database::query($sql);
  705. } else { // else we create a new record
  706. // gets the language_-_id
  707. $lang_id = '(SELECT id FROM '.Database::get_main_table(TABLE_MAIN_LANGUAGE).'
  708. WHERE dokeos_folder = "'.$event_message_language.'")';
  709. $lang_id = Database::store_result(Database::query($lang_id), 'ASSOC');
  710. if (!empty($lang_id[0]["id"])) {
  711. $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).' (event_type_name, language_id, message, subject, activated)
  712. VALUES("'.$event_name.'", '.$lang_id[0]["id"].', "'.Database::escape_string($message).'", "'.Database::escape_string($subject).'", '.$activated.')';
  713. Database::query($sql);
  714. }
  715. }
  716. // set activated at every save
  717. $sql = 'UPDATE '.Database::get_main_table(TABLE_EVENT_EMAIL_TEMPLATE).'
  718. SET activated = '.$activated.'
  719. WHERE event_type_name = "'.$event_name.'"';
  720. Database::query($sql);
  721. }
  722. function eventType_mod($etId, $users, $message, $subject)
  723. {
  724. $etId = intval($etId);
  725. $sql = 'DELETE FROM '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' WHERE event_type_id = '.$etId.' ';
  726. Database::query($sql);
  727. foreach ($users as $user) {
  728. $sql = 'INSERT INTO '.Database::get_main_table(TABLE_EVENT_TYPE_REL_USER).' (user_id,event_type_id)
  729. VALUES('.intval($user).','.$etId.') ';
  730. Database::query($sql);
  731. }
  732. $sql = 'UPDATE '.Database::get_main_table(TABLE_MAIN_EVENT_TYPE_MESSAGE).'
  733. SET message = "'.Database::escape_string($message).'",
  734. subject = "'.Database::escape_string($subject).'"
  735. WHERE event_type_id = '.$etId.'';
  736. Database::query($sql);
  737. }
  738. /**
  739. * Gets the last attempt of an exercise based in the exe_id
  740. * @param int $exe_id
  741. * @return mixed
  742. */
  743. function getLastAttemptDateOfExercise($exe_id)
  744. {
  745. $exe_id = intval($exe_id);
  746. $track_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  747. $sql_track_attempt = 'SELECT max(tms) as last_attempt_date FROM '.$track_attempts.' WHERE exe_id='.$exe_id;
  748. $rs_last_attempt = Database::query($sql_track_attempt);
  749. $row_last_attempt = Database::fetch_array($rs_last_attempt);
  750. $last_attempt_date = $row_last_attempt['last_attempt_date']; //Get the date of last attempt
  751. return $last_attempt_date;
  752. }
  753. /**
  754. * Gets the last attempt of an exercise based in the exe_id
  755. * @param int $exe_id
  756. * @return mixed
  757. */
  758. function getLatestQuestionIdFromAttempt($exe_id)
  759. {
  760. $exe_id = intval($exe_id);
  761. $track_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  762. $sql = 'SELECT question_id FROM '.$track_attempts.' WHERE exe_id='.$exe_id.' ORDER BY tms DESC LIMIT 1';
  763. $result = Database::query($sql);
  764. if (Database::num_rows($result)) {
  765. $row = Database::fetch_array($result);
  766. return $row['question_id'];
  767. } else {
  768. return false;
  769. }
  770. }
  771. /**
  772. * Gets how many attempts exists by user, exercise, learning path
  773. * @param int user id
  774. * @param int exercise id
  775. * @param int lp id
  776. * @param int lp item id
  777. * @param int lp item view id
  778. */
  779. function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id, $lp_item_view_id)
  780. {
  781. $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  782. $user_id = intval($user_id);
  783. $exerciseId = intval($exerciseId);
  784. $lp_id = intval($lp_id);
  785. $lp_item_id = intval($lp_item_id);
  786. $lp_item_view_id = intval($lp_item_view_id);
  787. $sql = "SELECT count(*) as count FROM $stat_table WHERE
  788. exe_exo_id = $exerciseId AND
  789. exe_user_id = $user_id AND
  790. status != 'incomplete' AND
  791. orig_lp_id = $lp_id AND
  792. orig_lp_item_id = $lp_item_id AND
  793. orig_lp_item_view_id = $lp_item_view_id AND
  794. c_id = '".api_get_course_int_id()."' AND
  795. session_id = '".api_get_session_id()."'";
  796. $query = Database::query($sql);
  797. if (Database::num_rows($query) > 0) {
  798. $attempt = Database :: fetch_array($query, 'ASSOC');
  799. return $attempt['count'];
  800. } else {
  801. return 0;
  802. }
  803. }
  804. function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_id)
  805. {
  806. $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  807. $user_id = intval($user_id);
  808. $exerciseId = intval($exerciseId);
  809. $lp_id = intval($lp_id);
  810. $lp_item_id = intval($lp_item_id);
  811. //$lp_item_view_id = intval($lp_item_view_id);
  812. $sql = "SELECT count(*) as count FROM $stat_table WHERE
  813. exe_exo_id = $exerciseId AND
  814. exe_user_id = $user_id AND
  815. status != 'incomplete' AND
  816. orig_lp_id = $lp_id AND
  817. orig_lp_item_id = $lp_item_id AND
  818. c_id = '".api_get_course_int_id()."' AND
  819. session_id = '".api_get_session_id()."'";
  820. $query = Database::query($sql);
  821. if (Database::num_rows($query) > 0) {
  822. $attempt = Database :: fetch_array($query, 'ASSOC');
  823. return $attempt['count'];
  824. } else {
  825. return 0;
  826. }
  827. }
  828. /**
  829. * @param int $user_id
  830. * @param int $lp_id
  831. * @param array $course
  832. * @param int $session_id
  833. */
  834. function delete_student_lp_events($user_id, $lp_id, $course, $session_id)
  835. {
  836. $lp_view_table = Database::get_course_table(TABLE_LP_VIEW);
  837. $lp_item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  838. $course_id = $course['real_id'];
  839. if (empty($course_id)) {
  840. $course_id = api_get_course_int_id();
  841. }
  842. $track_e_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  843. $track_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  844. $recording_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  845. $user_id = intval($user_id);
  846. $lp_id = intval($lp_id);
  847. $session_id = intval($session_id);
  848. //Make sure we have the exact lp_view_id
  849. $sql = "SELECT id FROM $lp_view_table WHERE c_id = $course_id AND user_id = $user_id AND lp_id = $lp_id AND session_id = $session_id ";
  850. $result = Database::query($sql);
  851. if (Database::num_rows($result)) {
  852. $view = Database::fetch_array($result, 'ASSOC');
  853. $lp_view_id = $view['id'];
  854. $sql = "DELETE FROM $lp_item_view_table WHERE c_id = $course_id AND lp_view_id = $lp_view_id ";
  855. Database::query($sql);
  856. }
  857. $sql = "DELETE FROM $lp_view_table WHERE c_id = $course_id AND user_id = $user_id AND lp_id= $lp_id AND session_id = $session_id ";
  858. Database::query($sql);
  859. $sql = "SELECT exe_id FROM $track_e_exercises
  860. WHERE exe_user_id = $user_id AND
  861. session_id = $session_id AND
  862. c_id = $course_id AND
  863. orig_lp_id = $lp_id";
  864. $result = Database::query($sql);
  865. $exe_list = array();
  866. while ($row = Database::fetch_array($result, 'ASSOC')) {
  867. $exe_list[] = $row['exe_id'];
  868. }
  869. if (!empty($exe_list) && is_array($exe_list) && count($exe_list) > 0) {
  870. $sql_delete = "DELETE FROM $track_e_exercises WHERE exe_id IN (".implode(',', $exe_list).")";
  871. Database::query($sql_delete);
  872. $sql_delete = "DELETE FROM $track_attempts WHERE exe_id IN (".implode(',', $exe_list).")";
  873. Database::query($sql_delete);
  874. $sql_delete = "DELETE FROM $recording_table WHERE exe_id IN (".implode(',', $exe_list).")";
  875. Database::query($sql_delete);
  876. }
  877. }
  878. /**
  879. * Delete all exercise attempts (included in LP or not)
  880. *
  881. * @param int user id
  882. * @param int exercise id
  883. * @param string course code
  884. * @param int session id
  885. */
  886. function delete_all_incomplete_attempts($user_id, $exercise_id, $course_id, $session_id = 0)
  887. {
  888. $track_e_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  889. $user_id = intval($user_id);
  890. $exercise_id = intval($exercise_id);
  891. $course_id = intval($course_id);
  892. $session_id = intval($session_id);
  893. if (!empty($user_id) && !empty($exercise_id) && !empty($course_code)) {
  894. $sql = "DELETE FROM $track_e_exercises
  895. WHERE exe_user_id = $user_id AND
  896. exe_exo_id = $exercise_id AND
  897. c_id = '$course_id' AND
  898. session_id = $session_id AND
  899. status = 'incomplete' ";
  900. Database::query($sql);
  901. }
  902. }
  903. /**
  904. * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
  905. * @param int exercise id
  906. * @param string course code
  907. * @param int session id
  908. * @return array with the results
  909. *
  910. */
  911. function get_all_exercise_results($exercise_id, $courseId, $session_id = 0, $load_question_list = true, $user_id = null)
  912. {
  913. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  914. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  915. $courseId = intval($courseId);
  916. $exercise_id = intval($exercise_id);
  917. $session_id = intval($session_id);
  918. $user_condition = null;
  919. if (!empty($user_id)) {
  920. $user_id = intval($user_id);
  921. $user_condition = "AND exe_user_id = $user_id ";
  922. }
  923. $sql = "SELECT * FROM $TABLETRACK_EXERCICES
  924. WHERE status = '' AND
  925. c_id = '$courseId' AND
  926. exe_exo_id = '$exercise_id' AND
  927. session_id = $session_id AND
  928. orig_lp_id =0 AND
  929. orig_lp_item_id = 0
  930. $user_condition
  931. ORDER BY exe_id";
  932. $res = Database::query($sql);
  933. $list = array();
  934. while ($row = Database::fetch_array($res, 'ASSOC')) {
  935. $list[$row['exe_id']] = $row;
  936. if ($load_question_list) {
  937. $sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}";
  938. $res_question = Database::query($sql);
  939. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  940. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  941. }
  942. }
  943. }
  944. return $list;
  945. }
  946. /**
  947. * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
  948. * @param string course code
  949. * @param int session id
  950. * @return array with the results
  951. *
  952. */
  953. function get_all_exercise_results_by_course($courseId, $session_id = 0, $get_count = true)
  954. {
  955. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  956. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  957. $courseId = intval($courseId);
  958. $session_id = intval($session_id);
  959. $select = '*';
  960. if ($get_count) {
  961. $select = 'count(*) as count';
  962. }
  963. $sql = "SELECT $select FROM $table_track_exercises
  964. WHERE status = '' AND
  965. c_id = '$courseId' AND
  966. session_id = $session_id AND
  967. orig_lp_id = 0 AND
  968. orig_lp_item_id = 0
  969. ORDER BY exe_id";
  970. $res = Database::query($sql);
  971. if ($get_count) {
  972. $row = Database::fetch_array($res, 'ASSOC');
  973. return $row['count'];
  974. } else {
  975. $list = array();
  976. while ($row = Database::fetch_array($res, 'ASSOC')) {
  977. $list[$row['exe_id']] = $row;
  978. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  979. $res_question = Database::query($sql);
  980. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  981. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  982. }
  983. }
  984. return $list;
  985. }
  986. }
  987. /**
  988. * Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session
  989. * @param int exercise id
  990. * @param string course code
  991. * @param int session id
  992. * @return array with the results
  993. *
  994. */
  995. function get_all_exercise_results_by_user($user_id, $courseId, $session_id = 0)
  996. {
  997. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  998. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  999. $courseId = intval($courseId);
  1000. $session_id = intval($session_id);
  1001. $user_id = intval($user_id);
  1002. $sql = "SELECT * FROM $table_track_exercises
  1003. WHERE status = '' AND
  1004. exe_user_id = $user_id AND
  1005. c_id = '$courseId' AND
  1006. session_id = $session_id AND
  1007. orig_lp_id = 0 AND
  1008. orig_lp_item_id = 0
  1009. ORDER by exe_id";
  1010. $res = Database::query($sql);
  1011. $list = array();
  1012. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1013. $list[$row['exe_id']] = $row;
  1014. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  1015. $res_question = Database::query($sql);
  1016. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1017. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  1018. }
  1019. }
  1020. //echo '<pre>'; print_r($list);
  1021. return $list;
  1022. }
  1023. /**
  1024. * Gets exercise results (NO Exercises in LPs) from a given exercise id, course, session
  1025. * @param int exercise id
  1026. * @param string course code
  1027. * @param int session id
  1028. * @return array with the results
  1029. *
  1030. */
  1031. function get_exercise_results_by_attempt($exe_id)
  1032. {
  1033. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1034. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1035. $table_track_attempt_recording = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  1036. $exe_id = intval($exe_id);
  1037. $sql = "SELECT * FROM $table_track_exercises WHERE status = '' AND exe_id = $exe_id";
  1038. $res = Database::query($sql);
  1039. $list = array();
  1040. if (Database::num_rows($res)) {
  1041. $row = Database::fetch_array($res, 'ASSOC');
  1042. //Checking if this attempt was revised by a teacher
  1043. $sql_revised = 'SELECT exe_id FROM '.$table_track_attempt_recording.' WHERE author != "" AND exe_id = '.$exe_id.' LIMIT 1';
  1044. $res_revised = Database::query($sql_revised);
  1045. $row['attempt_revised'] = 0;
  1046. if (Database::num_rows($res_revised) > 0) {
  1047. $row['attempt_revised'] = 1;
  1048. }
  1049. $list[$exe_id] = $row;
  1050. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = $exe_id ORDER BY tms ASC";
  1051. $res_question = Database::query($sql);
  1052. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1053. $list[$exe_id]['question_list'][$row_q['question_id']] = $row_q;
  1054. }
  1055. }
  1056. return $list;
  1057. }
  1058. /**
  1059. * Gets exercise results (NO Exercises in LPs) from a given user, exercise id, course, session, lp_id, lp_item_id
  1060. * @param int user id
  1061. * @param int exercise id
  1062. * @param string course code
  1063. * @param int session id
  1064. * @param int lp id
  1065. * @param int lp item id
  1066. * @param string order asc or desc
  1067. * @return array with the results
  1068. *
  1069. */
  1070. function getExerciseResultsByUser($user_id, $exercise_id, $courseId, $session_id = 0, $lp_id = 0, $lp_item_id = 0, $order = null)
  1071. {
  1072. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1073. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1074. $table_track_attempt_recording = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  1075. $courseId = intval($courseId);
  1076. $exercise_id = intval($exercise_id);
  1077. $session_id = intval($session_id);
  1078. $user_id = intval($user_id);
  1079. $lp_id = intval($lp_id);
  1080. $lp_item_id = intval($lp_item_id);
  1081. if (!in_array(strtolower($order), array('asc', 'desc'))) {
  1082. $order = 'asc';
  1083. }
  1084. $sql = "SELECT * FROM $table_track_exercises
  1085. WHERE status = '' AND
  1086. exe_user_id = $user_id AND
  1087. c_id = $courseId AND
  1088. exe_exo_id = $exercise_id AND
  1089. session_id = $session_id AND
  1090. orig_lp_id = $lp_id AND
  1091. orig_lp_item_id = $lp_item_id
  1092. ORDER by exe_id $order ";
  1093. $res = Database::query($sql);
  1094. $list = array();
  1095. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1096. //Checking if this attempt was revised by a teacher
  1097. $sql_revised = 'SELECT exe_id FROM '.$table_track_attempt_recording.' WHERE author != "" AND exe_id = '.$row['exe_id'].' LIMIT 1';
  1098. $res_revised = Database::query($sql_revised);
  1099. $row['attempt_revised'] = 0;
  1100. if (Database::num_rows($res_revised) > 0) {
  1101. $row['attempt_revised'] = 1;
  1102. }
  1103. $list[$row['exe_id']] = $row;
  1104. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  1105. $res_question = Database::query($sql);
  1106. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1107. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  1108. }
  1109. }
  1110. return $list;
  1111. }
  1112. /**
  1113. * Count exercise attempts (NO Exercises in LPs ) from a given exercise id, course, session
  1114. * @param int exercise id
  1115. * @param int course id
  1116. * @param int session id
  1117. * @return array with the results
  1118. *
  1119. */
  1120. function count_exercise_attempts_by_user($user_id, $exercise_id, $courseId, $session_id = 0)
  1121. {
  1122. $TABLETRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1123. $courseId = intval($courseId);
  1124. $exercise_id = intval($exercise_id);
  1125. $session_id = intval($session_id);
  1126. $user_id = intval($user_id);
  1127. $sql = "SELECT count(*) as count FROM $TABLETRACK_EXERCICES
  1128. WHERE status = '' AND
  1129. exe_user_id = '$user_id' AND
  1130. c_id = '$courseId' AND
  1131. exe_exo_id = '$exercise_id' AND
  1132. session_id = $session_id AND
  1133. orig_lp_id =0 AND
  1134. orig_lp_item_id = 0
  1135. ORDER BY exe_id";
  1136. $res = Database::query($sql);
  1137. $result = 0;
  1138. if (Database::num_rows($res) > 0) {
  1139. $row = Database::fetch_array($res, 'ASSOC');
  1140. $result = $row['count'];
  1141. }
  1142. return $result;
  1143. }
  1144. /**
  1145. * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
  1146. * @param int exercise id
  1147. * @param int course id
  1148. * @param int session id
  1149. * @return array with the results
  1150. * @todo rename this function
  1151. *
  1152. */
  1153. function get_best_exercise_results_by_user($exercise_id, $courseId, $session_id = 0)
  1154. {
  1155. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1156. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1157. $courseId = intval($courseId);
  1158. $exercise_id = intval($exercise_id);
  1159. $session_id = intval($session_id);
  1160. $sql = "SELECT * FROM $table_track_exercises
  1161. WHERE status = '' AND
  1162. c_id = $courseId AND
  1163. exe_exo_id = '$exercise_id' AND
  1164. session_id = $session_id AND
  1165. orig_lp_id = 0 AND
  1166. orig_lp_item_id = 0
  1167. ORDER BY exe_id";
  1168. $res = Database::query($sql);
  1169. $list = array();
  1170. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1171. $list[$row['exe_id']] = $row;
  1172. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  1173. $res_question = Database::query($sql);
  1174. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1175. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  1176. }
  1177. }
  1178. //Getting the best results of every student
  1179. $best_score_return = array();
  1180. foreach ($list as $student_result) {
  1181. $user_id = $student_result['exe_user_id'];
  1182. $current_best_score[$user_id] = $student_result['exe_result'];
  1183. if (isset($current_best_score[$user_id]) && isset($best_score_return[$user_id]) && $current_best_score[$user_id] > $best_score_return[$user_id]['exe_result']) {
  1184. $best_score_return[$user_id] = $student_result;
  1185. }
  1186. }
  1187. return $best_score_return;
  1188. }
  1189. /**
  1190. * @param int $user_id
  1191. * @param int $exercise_id
  1192. * @param int $courseId
  1193. * @param int $session_id
  1194. * @return array
  1195. */
  1196. function get_best_attempt_exercise_results_per_user($user_id, $exercise_id, $courseId, $session_id = 0)
  1197. {
  1198. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1199. $courseId = intval($courseId);
  1200. $exercise_id = intval($exercise_id);
  1201. $session_id = intval($session_id);
  1202. $user_id = intval($user_id);
  1203. $sql = "SELECT * FROM $table_track_exercises
  1204. WHERE status = '' AND
  1205. c_id = '$courseId' AND
  1206. exe_exo_id = '$exercise_id' AND
  1207. session_id = $session_id AND
  1208. exe_user_id = $user_id AND
  1209. orig_lp_id =0 AND
  1210. orig_lp_item_id = 0
  1211. ORDER BY exe_id";
  1212. $res = Database::query($sql);
  1213. $list = array();
  1214. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1215. $list[$row['exe_id']] = $row; /*
  1216. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  1217. $res_question = Database::query($sql);
  1218. while($row_q = Database::fetch_array($res_question,'ASSOC')) {
  1219. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  1220. } */
  1221. }
  1222. //Getting the best results of every student
  1223. $best_score_return = array();
  1224. $best_score_return['exe_result'] = 0;
  1225. foreach ($list as $result) {
  1226. $current_best_score = $result;
  1227. if ($current_best_score['exe_result'] > $best_score_return['exe_result']) {
  1228. $best_score_return = $result;
  1229. }
  1230. }
  1231. if (!isset($best_score_return['exe_weighting'])) {
  1232. $best_score_return = array();
  1233. }
  1234. return $best_score_return;
  1235. }
  1236. /**
  1237. * @param int $exercise_id
  1238. * @param int $courseId
  1239. * @param int $session_id
  1240. * @return mixed
  1241. */
  1242. function count_exercise_result_not_validated($exercise_id, $courseId, $session_id = 0)
  1243. {
  1244. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1245. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  1246. $courseId = intval($courseId);
  1247. $session_id = intval($session_id);
  1248. $exercise_id = intval($exercise_id);
  1249. $sql = "SELECT count(e.exe_id) as count
  1250. FROM $table_track_exercises e LEFT JOIN $table_track_attempt a ON e.exe_id = a.exe_id
  1251. WHERE exe_exo_id = $exercise_id AND
  1252. c_id = '$courseId' AND
  1253. e.session_id = $session_id AND
  1254. orig_lp_id = 0 AND
  1255. marks IS NULL AND
  1256. status = '' AND
  1257. orig_lp_item_id = 0 ORDER BY e.exe_id";
  1258. $res = Database::query($sql);
  1259. $row = Database::fetch_array($res, 'ASSOC');
  1260. return $row['count'];
  1261. }
  1262. /**
  1263. * Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
  1264. * @param int exercise id
  1265. * @param int course id
  1266. * @param int session id
  1267. * @return array with the results
  1268. *
  1269. */
  1270. function get_count_exercises_attempted_by_course($courseId, $session_id = 0)
  1271. {
  1272. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1273. $courseId = intval($courseId);
  1274. $session_id = intval($session_id);
  1275. $sql = "SELECT DISTINCT exe_exo_id, exe_user_id
  1276. FROM $table_track_exercises
  1277. WHERE status = '' AND
  1278. c_id = '$courseId' AND
  1279. session_id = $session_id AND
  1280. orig_lp_id =0 AND
  1281. orig_lp_item_id = 0
  1282. ORDER BY exe_id";
  1283. $res = Database::query($sql);
  1284. $count = 0;
  1285. if (Database::num_rows($res) > 0) {
  1286. $count = Database::num_rows($res);
  1287. }
  1288. return $count;
  1289. }
  1290. /**
  1291. * Gets all exercise events from a Learning Path within a Course nd Session
  1292. * @param int exercise id
  1293. * @param string course_code
  1294. * @param int session id
  1295. * @return array
  1296. */
  1297. function get_all_exercise_event_from_lp($exercise_id, $courseId, $session_id = 0)
  1298. {
  1299. $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1300. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1301. $courseId = intval($courseId);
  1302. $exercise_id = intval($exercise_id);
  1303. $session_id = intval($session_id);
  1304. $sql = "SELECT * FROM $table_track_exercises
  1305. WHERE status = '' AND
  1306. c_id = $courseId AND
  1307. exe_exo_id = '$exercise_id' AND
  1308. session_id = $session_id AND
  1309. orig_lp_id !=0 AND
  1310. orig_lp_item_id != 0";
  1311. $res = Database::query($sql);
  1312. $list = array();
  1313. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1314. $list[$row['exe_id']] = $row;
  1315. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = {$row['exe_id']}";
  1316. $res_question = Database::query($sql);
  1317. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1318. $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
  1319. }
  1320. }
  1321. return $list;
  1322. }
  1323. function get_all_exercises_from_lp($lp_id, $course_id)
  1324. {
  1325. $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM);
  1326. $course_id = intval($course_id);
  1327. $lp_id = intval($lp_id);
  1328. $sql = "SELECT * FROM $lp_item_table WHERE c_id = $course_id AND lp_id = '".$lp_id."' ORDER BY parent_item_id, display_order";
  1329. $res = Database::query($sql);
  1330. $my_exercise_list = array();
  1331. while ($row = Database::fetch_array($res, 'ASSOC')) {
  1332. if ($row['item_type'] == 'quiz') {
  1333. $my_exercise_list[] = $row;
  1334. }
  1335. }
  1336. return $my_exercise_list;
  1337. }
  1338. /**
  1339. * This function gets the comments of an exercise
  1340. *
  1341. * @param int $id
  1342. * @param int $question_id
  1343. * @return string the comment
  1344. */
  1345. function get_comments($exe_id, $question_id)
  1346. {
  1347. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1348. $sql = "SELECT teacher_comment FROM ".$table_track_attempt."
  1349. WHERE exe_id='".Database::escape_string($exe_id)."' AND question_id = '".Database::escape_string($question_id)."'
  1350. ORDER by question_id";
  1351. $sqlres = Database::query($sql);
  1352. $comm = Database::result($sqlres, 0, "teacher_comment");
  1353. return $comm;
  1354. }
  1355. /**
  1356. * @param int $exe_id
  1357. * @return array
  1358. */
  1359. function getAllExerciseEventByExeId($exe_id)
  1360. {
  1361. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1362. $exe_id = intval($exe_id);
  1363. $list = array();
  1364. $sql = "SELECT * FROM $table_track_attempt WHERE exe_id = $exe_id ORDER BY position";
  1365. $res_question = Database::query($sql);
  1366. if (Database::num_rows($res_question)) {
  1367. while ($row_q = Database::fetch_array($res_question, 'ASSOC')) {
  1368. $list[$row_q['question_id']][] = $row_q;
  1369. }
  1370. }
  1371. return $list;
  1372. }
  1373. /**
  1374. *
  1375. * @param int $exe_id
  1376. * @param int $user_id
  1377. * @param int $courseId
  1378. * @param int $session_id
  1379. * @param int $question_id
  1380. */
  1381. function delete_attempt($exe_id, $user_id, $courseId, $session_id, $question_id)
  1382. {
  1383. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1384. $exe_id = intval($exe_id);
  1385. $user_id = intval($user_id);
  1386. $courseId = intval($courseId);
  1387. $session_id = intval($session_id);
  1388. $question_id = intval($question_id);
  1389. $sql = "DELETE FROM $table_track_attempt
  1390. WHERE exe_id = $exe_id AND
  1391. user_id = $user_id AND
  1392. c_id = $courseId AND
  1393. session_id = $session_id AND
  1394. question_id = $question_id ";
  1395. Database::query($sql);
  1396. }
  1397. /**
  1398. * @param $exe_id
  1399. * @param $user_id
  1400. * @param int $courseId
  1401. * @param $question_id
  1402. */
  1403. function delete_attempt_hotspot($exe_id, $user_id, $courseId, $question_id)
  1404. {
  1405. $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  1406. $exe_id = intval($exe_id);
  1407. $user_id = intval($user_id);
  1408. $courseId = intval($courseId);
  1409. $question_id = intval($question_id);
  1410. $sql = "DELETE FROM $table_track_attempt
  1411. WHERE hotspot_exe_id = $exe_id AND
  1412. hotspot_user_id = $user_id AND
  1413. c_id = $courseId AND
  1414. hotspot_question_id = $question_id ";
  1415. Database::query($sql);
  1416. }
  1417. function getAnsweredQuestionsFromAttempt($exe_id, $objExercise)
  1418. {
  1419. $attempt_list = getAllExerciseEventByExeId($exe_id);
  1420. $exercise_result = array();
  1421. if (!empty($attempt_list)) {
  1422. foreach ($attempt_list as $question_id => $options) {
  1423. foreach ($options as $item) {
  1424. $question_obj = Question::read($item['question_id']);
  1425. switch ($question_obj->type) {
  1426. case FILL_IN_BLANKS:
  1427. $item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']);
  1428. break;
  1429. case HOT_SPOT:
  1430. //var_dump($item['answer']);
  1431. break;
  1432. }
  1433. if ($item['answer'] != '0' && !empty($item['answer'])) {
  1434. $exercise_result[] = $question_id;
  1435. break;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. return $exercise_result;
  1441. }
  1442. /**
  1443. * User logs in for the first time to a course
  1444. * @param $course_code
  1445. * @param $user_id
  1446. * @param $session_id
  1447. */
  1448. function event_course_login($courseId, $user_id, $session_id)
  1449. {
  1450. $course_tracking_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  1451. $time = api_get_datetime();
  1452. $courseId = Database::escape_string($courseId);
  1453. $user_id = Database::escape_string($user_id);
  1454. $session_id = Database::escape_string($session_id);
  1455. $sql = "INSERT INTO $course_tracking_table(c_id, user_id, login_course_date, logout_course_date, counter, session_id)
  1456. VALUES('".$courseId."', '".$user_id."', '$time', '$time', '1', '".$session_id."')";
  1457. Database::query($sql);
  1458. //Course catalog stats modifications see #4191
  1459. CourseManager::update_course_ranking(null, null, null, null, true, false);
  1460. }
  1461. /**
  1462. * For the sake of genericity, this function is a switch.
  1463. * It's called by EventsDispatcher and fires the good function
  1464. * with the good require_once.
  1465. *
  1466. * @param string $event_name
  1467. * @param array $params
  1468. */
  1469. function event_send_mail($event_name, $params)
  1470. {
  1471. EventsMail::send_mail($event_name, $params);
  1472. }
  1473. /**
  1474. * Internal function checking if the mail was already sent from that user to that user
  1475. * @param string $event_name
  1476. * @param int $user_from
  1477. * @param int $user_to
  1478. * @return boolean
  1479. */
  1480. function check_if_mail_already_sent($event_name, $user_from, $user_to = null)
  1481. {
  1482. if ($user_to == null) {
  1483. $sql = 'SELECT COUNT(*) as total FROM '.Database::get_main_table(TABLE_EVENT_SENT).'
  1484. WHERE user_from = '.$user_from.' AND event_type_name = "'.$event_name.'"';
  1485. } else {
  1486. $sql = 'SELECT COUNT(*) as total FROM '.Database::get_main_table(TABLE_EVENT_SENT).'
  1487. WHERE user_from = '.$user_from.' AND user_to = '.$user_to.' AND event_type_name = "'.$event_name.'"';
  1488. }
  1489. $result = Database::store_result(Database::query($sql), 'ASSOC');
  1490. return $result[0]["total"];
  1491. }
  1492. /**
  1493. *
  1494. * Filter EventEmailTemplate Filters see the main/inc/conf/events.conf.dist.php
  1495. *
  1496. */
  1497. /**
  1498. * Basic template event message filter (to be used by other filters as default)
  1499. * @param array $values (passing by reference)
  1500. * @return boolean True if everything is OK, false otherwise
  1501. */
  1502. function _event_send_mail_filter_func(&$values)
  1503. {
  1504. return true;
  1505. }
  1506. /**
  1507. * user_registration - send_mail filter
  1508. * @param array $values (passing by reference)
  1509. * @return boolean True if everything is OK, false otherwise
  1510. */
  1511. function user_registration_event_send_mail_filter_func(&$values)
  1512. {
  1513. $res = _event_send_mail_filter_func($values);
  1514. // proper logic for this filter
  1515. return $res;
  1516. }
  1517. /**
  1518. * portal_homepage_edited - send_mail filter
  1519. * @param array $values (passing by reference)
  1520. * @return boolean True if everything is OK, false otherwise
  1521. */
  1522. function portal_homepage_edited_event_send_mail_filter_func(&$values)
  1523. {
  1524. $res = _event_send_mail_filter_func($values);
  1525. // proper logic for this filter
  1526. return $res;
  1527. }