events.lib.inc.php 60 KB

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