exercise.class.php 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise class: This class allows to instantiate an object of type Exercise
  5. * @package chamilo.exercise
  6. * @author Olivier Brouckaert
  7. * @author Julio Montoya Cleaning exercises
  8. * @version $Id: exercise.class.php 22046 2009-07-14 01:45:19Z ivantcholakov $
  9. */
  10. define('ALL_ON_ONE_PAGE',1);
  11. define('ONE_PER_PAGE',2);
  12. //0=>Feedback , 1=>DirectFeedback, 2=>NoFeedback
  13. define('EXERCISE_FEEDBACK_TYPE_END',0);
  14. define('EXERCISE_FEEDBACK_TYPE_DIRECT',1);
  15. define('EXERCISE_FEEDBACK_TYPE_EXAM',2);
  16. require_once dirname(__FILE__).'/../inc/lib/exercise_show_functions.lib.php';
  17. if(!class_exists('Exercise')):
  18. class Exercise {
  19. public $id;
  20. public $exercise;
  21. public $description;
  22. public $sound;
  23. public $type; //ALL_ON_ONE_PAGE or ONE_PER_PAGE
  24. public $random;
  25. public $random_answers;
  26. public $active;
  27. public $timeLimit;
  28. public $attempts;
  29. public $feedbacktype;
  30. public $end_time;
  31. public $start_time;
  32. public $questionList; // array with the list of this exercise's questions
  33. public $results_disabled;
  34. public $expired_time;
  35. public $course;
  36. public $propagate_neg;
  37. /**
  38. * Constructor of the class
  39. *
  40. * @author - Olivier Brouckaert
  41. */
  42. function Exercise($course_id = null) {
  43. $this->id = 0;
  44. $this->exercise = '';
  45. $this->description = '';
  46. $this->sound = '';
  47. $this->type = ALL_ON_ONE_PAGE;
  48. $this->random = 0;
  49. $this->random_answers = 0;
  50. $this->active = 1;
  51. $this->questionList = array();
  52. $this->timeLimit = 0;
  53. $this->end_time = '0000-00-00 00:00:00';
  54. $this->start_time = '0000-00-00 00:00:00';
  55. $this->results_disabled = 1;
  56. $this->expired_time = '0000-00-00 00:00:00';
  57. $this->propagate_neg = 0;
  58. if (!empty($course_id)) {
  59. $this->course_id = intval($course_id);
  60. $course_info = api_get_course_info_by_id($this->course_id);
  61. } else {
  62. $course_info = api_get_course_info();
  63. }
  64. $this->course = $course_info;
  65. }
  66. /**
  67. * reads exercise informations from the data base
  68. *
  69. * @author - Olivier Brouckaert
  70. * @param - integer $id - exercise ID
  71. * @return - boolean - true if exercise exists, otherwise false
  72. */
  73. function read($id) {
  74. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION,$this->course['db_name']);
  75. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST,$this->course['db_name']);
  76. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION,$this->course['db_name']);
  77. #$TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  78. $sql="SELECT * FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
  79. $result=Database::query($sql);
  80. // if the exercise has been found
  81. if ($object=Database::fetch_object($result)) {
  82. $this->id = $id;
  83. $this->exercise = $object->title;
  84. $this->description = $object->description;
  85. $this->sound = $object->sound;
  86. $this->type = $object->type;
  87. $this->random = $object->random;
  88. $this->random_answers = $object->random_answers;
  89. $this->active = $object->active;
  90. $this->results_disabled = $object->results_disabled;
  91. $this->attempts = $object->max_attempt;
  92. $this->feedbacktype = $object->feedback_type;
  93. $this->propagate_neg = $object->propagate_neg;
  94. if ($object->end_time != '0000-00-00 00:00:00') {
  95. $this->end_time = api_get_local_time($object->end_time);
  96. }
  97. if ($object->start_time != '0000-00-00 00:00:00') {
  98. $this->start_time = api_get_local_time($object->start_time);
  99. }
  100. $this->expired_time = $object->expired_time; //control time
  101. $sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION, $TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
  102. $result=Database::query($sql);
  103. // fills the array with the question ID for this exercise
  104. // the key of the array is the question position
  105. while ($new_object = Database::fetch_object($result)) {
  106. $this->questionList[$new_object->question_order]= $new_object->question_id;
  107. }
  108. //overload questions list with recorded questions list
  109. //load questions only for exercises of type 'one question per page'
  110. //this is needed only is there is no questions
  111. //
  112. // @todo not sure were in the code this is used somebody mess with the exercise tool
  113. global $_configuration, $questionList;
  114. if ($this->type == ONE_PER_PAGE && $_configuration['live_exercise_tracking'] && $_SERVER['REQUEST_METHOD'] != 'POST' && defined('QUESTION_LIST_ALREADY_LOGGED')) {
  115. //if(empty($_SESSION['questionList']))
  116. $this->questionList = $questionList;
  117. }
  118. return true;
  119. }
  120. // exercise not found
  121. return false;
  122. }
  123. /**
  124. * returns the exercise ID
  125. *
  126. * @author - Olivier Brouckaert
  127. * @return - integer - exercise ID
  128. */
  129. function selectId() {
  130. return $this->id;
  131. }
  132. /**
  133. * returns the exercise title
  134. *
  135. * @author - Olivier Brouckaert
  136. * @return - string - exercise title
  137. */
  138. function selectTitle() {
  139. return $this->exercise;
  140. }
  141. /**
  142. * returns the number of attempts setted
  143. *
  144. * @return - numeric - exercise attempts
  145. */
  146. function selectAttempts() {
  147. return $this->attempts;
  148. }
  149. /** returns the number of FeedbackType *
  150. * 0=>Feedback , 1=>DirectFeedback, 2=>NoFeedback
  151. * @return - numeric - exercise attempts
  152. */
  153. function selectFeedbackType() {
  154. return $this->feedbacktype;
  155. }
  156. /**
  157. * returns the time limit
  158. */
  159. function selectTimeLimit() {
  160. return $this->timeLimit;
  161. }
  162. /**
  163. * returns the exercise description
  164. *
  165. * @author - Olivier Brouckaert
  166. * @return - string - exercise description
  167. */
  168. function selectDescription() {
  169. return $this->description;
  170. }
  171. /**
  172. * returns the exercise sound file
  173. *
  174. * @author - Olivier Brouckaert
  175. * @return - string - exercise description
  176. */
  177. function selectSound() {
  178. return $this->sound;
  179. }
  180. /**
  181. * returns the exercise type
  182. *
  183. * @author - Olivier Brouckaert
  184. * @return - integer - exercise type
  185. */
  186. function selectType() {
  187. return $this->type;
  188. }
  189. /**
  190. * tells if questions are selected randomly, and if so returns the draws
  191. *
  192. * @author - Carlos Vargas
  193. * @return - integer - results disabled exercise
  194. */
  195. function selectResultsDisabled() {
  196. return $this->results_disabled;
  197. }
  198. /**
  199. * tells if questions are selected randomly, and if so returns the draws
  200. *
  201. * @author - Olivier Brouckaert
  202. * @return - integer - 0 if not random, otherwise the draws
  203. */
  204. function isRandom() {
  205. if($this->random > 0){
  206. return true;
  207. } else {
  208. return false;
  209. }
  210. }
  211. /**
  212. * returns random answers status.
  213. *
  214. * @author - Juan Carlos Ra�a
  215. */
  216. function selectRandomAnswers() {
  217. $this->random_answers;
  218. return $this->random_answers;
  219. }
  220. /**
  221. * Same as isRandom() but has a name applied to values different than 0 or 1
  222. */
  223. function getShuffle() {
  224. return $this->random;
  225. }
  226. /**
  227. * returns the exercise status (1 = enabled ; 0 = disabled)
  228. *
  229. * @author - Olivier Brouckaert
  230. * @return - boolean - true if enabled, otherwise false
  231. */
  232. function selectStatus() {
  233. return $this->active;
  234. }
  235. /**
  236. * returns the array with the question ID list
  237. *
  238. * @author - Olivier Brouckaert
  239. * @return - array - question ID list
  240. */
  241. function selectQuestionList() {
  242. return $this->questionList;
  243. }
  244. /**
  245. * returns the number of questions in this exercise
  246. *
  247. * @author - Olivier Brouckaert
  248. * @return - integer - number of questions
  249. */
  250. function selectNbrQuestions() {
  251. return sizeof($this->questionList);
  252. }
  253. function selectPropagateNeg() {
  254. return $this->propagate_neg;
  255. }
  256. /**
  257. * Selects questions randomly in the question list
  258. *
  259. * @author - Olivier Brouckaert
  260. * @return - array - if the exercise is not set to take questions randomly, returns the question list
  261. * without randomizing, otherwise, returns the list with questions selected randomly
  262. */
  263. function selectRandomList() {
  264. $nbQuestions = $this->selectNbrQuestions();
  265. $temp_list = $this->questionList;
  266. //Not a random exercise, or if there are not at least 2 questions
  267. if($this->random == 0 || $nbQuestions < 2) {
  268. return $this->questionList;
  269. }
  270. if ($nbQuestions != 0) {
  271. shuffle($temp_list);
  272. $my_random_list = array_combine(range(1,$nbQuestions),$temp_list);
  273. $my_question_list = array();
  274. $i = 0;
  275. foreach ($my_random_list as $item) {
  276. if ($i < $this->random) {
  277. $my_question_list[$i] = $item;
  278. } else {
  279. break;
  280. }
  281. $i++;
  282. }
  283. return $my_question_list;
  284. }
  285. }
  286. /**
  287. * returns 'true' if the question ID is in the question list
  288. *
  289. * @author - Olivier Brouckaert
  290. * @param - integer $questionId - question ID
  291. * @return - boolean - true if in the list, otherwise false
  292. */
  293. function isInList($questionId) {
  294. if (is_array($this->questionList))
  295. return in_array($questionId,$this->questionList);
  296. else
  297. return false;
  298. }
  299. /**
  300. * changes the exercise title
  301. *
  302. * @author - Olivier Brouckaert
  303. * @param - string $title - exercise title
  304. */
  305. function updateTitle($title) {
  306. $this->exercise=$title;
  307. }
  308. /**
  309. * changes the exercise max attempts
  310. *
  311. * @param - numeric $attempts - exercise max attempts
  312. */
  313. function updateAttempts($attempts) {
  314. $this->attempts=$attempts;
  315. }
  316. /**
  317. * changes the exercise feedback type
  318. *
  319. * @param - numeric $attempts - exercise max attempts
  320. */
  321. function updateFeedbackType($feedback_type) {
  322. $this->feedbacktype=$feedback_type;
  323. }
  324. /**
  325. * changes the exercise description
  326. *
  327. * @author - Olivier Brouckaert
  328. * @param - string $description - exercise description
  329. */
  330. function updateDescription($description) {
  331. $this->description=$description;
  332. }
  333. /**
  334. * changes the exercise expired_time
  335. *
  336. * @author - Isaac flores
  337. * @param - int The expired time of the quiz
  338. */
  339. function updateExpiredTime($expired_time) {
  340. $this->expired_time = $expired_time;
  341. }
  342. function updatePropagateNegative($value) {
  343. $this->propagate_neg = $value;
  344. }
  345. /**
  346. * changes the exercise sound file
  347. *
  348. * @author - Olivier Brouckaert
  349. * @param - string $sound - exercise sound file
  350. * @param - string $delete - ask to delete the file
  351. */
  352. function updateSound($sound,$delete) {
  353. global $audioPath, $documentPath;
  354. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT, $this->course['db_name']);
  355. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY,$this->course['db_name']);
  356. if ($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video'))) {
  357. $this->sound=$sound['name'];
  358. if (@move_uploaded_file($sound['tmp_name'],$audioPath.'/'.$this->sound)) {
  359. $query="SELECT 1 FROM $TBL_DOCUMENT WHERE path='".str_replace($documentPath,'',$audioPath).'/'.$this->sound."'";
  360. $result=Database::query($query);
  361. if(!Database::num_rows($result)) {
  362. /*$query="INSERT INTO $TBL_DOCUMENT(path,filetype) VALUES "
  363. ." ('".str_replace($documentPath,'',$audioPath).'/'.$this->sound."','file')";
  364. Database::query($query);*/
  365. $id = add_document($this->course,str_replace($documentPath,'',$audioPath).'/'.$this->sound,'file',$sound['size'],$sound['name']);
  366. //$id = Database::insert_id();
  367. //$time = time();
  368. //$time = date("Y-m-d H:i:s", $time);
  369. // insert into the item_property table, using default visibility of "visible"
  370. /*$query = "INSERT INTO $TBL_ITEM_PROPERTY "
  371. ."(tool, ref, insert_user_id,to_group_id, insert_date, lastedit_date, lastedit_type) "
  372. ." VALUES "
  373. ."('".TOOL_DOCUMENT."', $id, $_user['user_id'], 0, '$time', '$time', 'DocumentAdded' )";
  374. Database::query($query);*/
  375. api_item_property_update($this->course, TOOL_DOCUMENT, $id, 'DocumentAdded',api_get_user_id());
  376. item_property_update_on_folder($this->course,str_replace($documentPath,'',$audioPath),api_get_user_id());
  377. }
  378. }
  379. } elseif($delete && is_file($audioPath.'/'.$this->sound)) {
  380. $this->sound='';
  381. }
  382. }
  383. /**
  384. * changes the exercise type
  385. *
  386. * @author - Olivier Brouckaert
  387. * @param - integer $type - exercise type
  388. */
  389. function updateType($type) {
  390. $this->type=$type;
  391. }
  392. /**
  393. * sets to 0 if questions are not selected randomly
  394. * if questions are selected randomly, sets the draws
  395. *
  396. * @author - Olivier Brouckaert
  397. * @param - integer $random - 0 if not random, otherwise the draws
  398. */
  399. function setRandom($random) {
  400. $this->random=$random;
  401. }
  402. /**
  403. * sets to 0 if answers are not selected randomly
  404. * if answers are selected randomly
  405. * @author - Juan Carlos Ra�a
  406. * @param - integer $random_answers - random answers
  407. */
  408. function updateRandomAnswers($random_answers) {
  409. $this->$random_answers = $random_answers;
  410. }
  411. /**
  412. * enables the exercise
  413. *
  414. * @author - Olivier Brouckaert
  415. */
  416. function enable() {
  417. $this->active=1;
  418. }
  419. /**
  420. * disables the exercise
  421. *
  422. * @author - Olivier Brouckaert
  423. */
  424. function disable() {
  425. $this->active=0;
  426. }
  427. function disable_results() {
  428. $this->results_disabled = true;
  429. }
  430. function enable_results()
  431. {
  432. $this->results_disabled = false;
  433. }
  434. function updateResultsDisabled($results_disabled) {
  435. $this->results_disabled = intval($results_disabled);
  436. }
  437. /**
  438. * updates the exercise in the data base
  439. *
  440. * @author - Olivier Brouckaert
  441. */
  442. function save($type_e='') {
  443. global $_course;
  444. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  445. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  446. $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  447. $id = $this->id;
  448. $exercise = $this->exercise;
  449. $description = $this->description;
  450. $sound = $this->sound;
  451. $type = $this->type;
  452. $attempts = $this->attempts;
  453. $feedbacktype = $this->feedbacktype;
  454. $random = $this->random;
  455. $random_answers = $this->random_answers;
  456. $active = $this->active;
  457. $propagate_neg = $this->propagate_neg;
  458. $session_id = api_get_session_id();
  459. if ($feedbacktype==1){
  460. $results_disabled = 1;
  461. } else {
  462. $results_disabled = intval($this->results_disabled);
  463. }
  464. $expired_time = intval($this->expired_time);
  465. $start_time = Database::escape_string(api_get_utc_datetime($this->start_time));
  466. $end_time = Database::escape_string(api_get_utc_datetime($this->end_time));
  467. // Exercise already exists
  468. if($id) {
  469. $sql="UPDATE $TBL_EXERCICES SET
  470. title='".Database::escape_string($exercise)."',
  471. description='".Database::escape_string($description)."'";
  472. if ($type_e != 'simple') {
  473. $sql .= ", sound='".Database::escape_string($sound)."',
  474. type='".Database::escape_string($type)."',
  475. random='".Database::escape_string($random)."',
  476. random_answers='".Database::escape_string($random_answers)."',
  477. active='".Database::escape_string($active)."',
  478. feedback_type='".Database::escape_string($feedbacktype)."',
  479. start_time='$start_time',end_time='$end_time',
  480. max_attempt='".Database::escape_string($attempts)."',
  481. expired_time='".Database::escape_string($expired_time)."',
  482. propagate_neg='".Database::escape_string($propagate_neg)."',
  483. results_disabled='".Database::escape_string($results_disabled)."'";
  484. }
  485. $sql .= " WHERE id='".Database::escape_string($id)."'";
  486. Database::query($sql);
  487. // update into the item_property table
  488. api_item_property_update($_course, TOOL_QUIZ, $id,'QuizUpdated',api_get_user_id());
  489. if (api_get_setting('search_enabled')=='true') {
  490. $this -> search_engine_edit();
  491. }
  492. } else {// creates a new exercise
  493. //add condition by anonymous user
  494. /*if (!api_is_anonymous()) {
  495. //is course manager
  496. $cond1=Database::escape_string($exercise);
  497. $cond2=Database::escape_string($description);
  498. } else {
  499. //is anonymous user
  500. $cond1=Database::escape_string(Security::remove_XSS($exercise));
  501. $cond2=Database::escape_string(Security::remove_XSS(api_html_entity_decode($description),COURSEMANAGERLOWSECURITY));
  502. }*/
  503. $sql="INSERT INTO $TBL_EXERCICES (start_time, end_time, title, description, sound, type, random, random_answers,active, results_disabled, max_attempt, feedback_type, expired_time, session_id)
  504. VALUES(
  505. '$start_time','$end_time',
  506. '".Database::escape_string($exercise)."',
  507. '".Database::escape_string($description)."',
  508. '".Database::escape_string($sound)."',
  509. '".Database::escape_string($type)."',
  510. '".Database::escape_string($random)."',
  511. '".Database::escape_string($random_answers)."',
  512. '".Database::escape_string($active)."',
  513. '".Database::escape_string($results_disabled)."',
  514. '".Database::escape_string($attempts)."',
  515. '".Database::escape_string($feedbacktype)."',
  516. '".Database::escape_string($expired_time)."',
  517. '".Database::escape_string($session_id)."'
  518. )";
  519. Database::query($sql);
  520. $this->id=Database::insert_id();
  521. // insert into the item_property table
  522. api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizAdded',api_get_user_id());
  523. if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
  524. $this -> search_engine_save();
  525. }
  526. }
  527. // updates the question position
  528. $this->update_question_positions();
  529. }
  530. function update_question_positions() {
  531. // updates the question position
  532. $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  533. foreach($this->questionList as $position=>$questionId) {
  534. //$sql="UPDATE $TBL_QUESTIONS SET position='".Database::escape_string($position)."' WHERE id='".Database::escape_string($questionId)."'";
  535. $sql="UPDATE $TBL_QUIZ_QUESTION SET question_order='".Database::escape_string($position)."' " .
  536. "WHERE question_id='".Database::escape_string($questionId)."' and exercice_id=".Database::escape_string($this->id)."";
  537. Database::query($sql);
  538. }
  539. }
  540. /**
  541. * moves a question up in the list
  542. *
  543. * @author - Olivier Brouckaert
  544. * @author - Julio Montoya (rewrote the code)
  545. * @param - integer $id - question ID to move up
  546. */
  547. function moveUp($id) {
  548. // there is a bug with some version of PHP with the key and prev functions
  549. // the script commented was tested in dev.dokeos.com with no success
  550. // Instead of using prev and next this was change with arrays.
  551. /*
  552. foreach($this->questionList as $position=>$questionId)
  553. {
  554. // if question ID found
  555. if($questionId == $id)
  556. {
  557. // position of question in the array
  558. echo $pos1=$position; //1
  559. echo "<br>";
  560. prev($this->questionList);
  561. prev($this->questionList);
  562. // position of previous question in the array
  563. $pos2=key($this->questionList);
  564. //if the cursor of the array hit the end
  565. // then we must reset the array to get the previous key
  566. if($pos2===null)
  567. {
  568. end($this->questionList);
  569. prev($this->questionList);
  570. $pos2=key($this->questionList);
  571. }
  572. // error, can't move question
  573. if(!$pos2)
  574. {
  575. //echo 'cant move!';
  576. $pos2=key($this->questionList);
  577. reset($this->questionList);
  578. }
  579. $id2=$this->questionList[$pos2];
  580. // exits foreach()
  581. break;
  582. }
  583. $i++;
  584. }
  585. */
  586. $question_list =array();
  587. foreach($this->questionList as $position=>$questionId)
  588. {
  589. $question_list[]= $questionId;
  590. }
  591. $len=count($question_list);
  592. $orderlist=array_keys($this->questionList);
  593. for($i=0;$i<$len;$i++)
  594. {
  595. $questionId = $question_list[$i];
  596. if($questionId == $id)
  597. {
  598. // position of question in the array
  599. $pos1=$orderlist[$i];
  600. $pos2=$orderlist[$i-1];
  601. if($pos2===null)
  602. {
  603. $pos2 = $orderlist[$len-1];
  604. }
  605. // error, can't move question
  606. if(!$pos2)
  607. {
  608. $pos2=$orderlist[0];
  609. $i=0;
  610. }
  611. break;
  612. }
  613. }
  614. // permutes questions in the array
  615. $temp=$this->questionList[$pos2];
  616. $this->questionList[$pos2]=$this->questionList[$pos1];
  617. $this->questionList[$pos1]=$temp;
  618. }
  619. /**
  620. * moves a question down in the list
  621. *
  622. * @author - Olivier Brouckaert
  623. * @param - integer $id - question ID to move down
  624. */
  625. function moveDown($id) {
  626. // there is a bug with some version of PHP with the key and prev functions
  627. // the script commented was tested in dev.dokeos.com with no success
  628. // Instead of using prev and next this was change with arrays.
  629. /*
  630. foreach($this->questionList as $position=>$questionId)
  631. {
  632. // if question ID found
  633. if($questionId == $id)
  634. {
  635. // position of question in the array
  636. $pos1=$position;
  637. //next($this->questionList);
  638. // position of next question in the array
  639. $pos2=key($this->questionList);
  640. // error, can't move question
  641. if(!$pos2)
  642. {
  643. //echo 'cant move!';
  644. return;
  645. }
  646. $id2=$this->questionList[$pos2];
  647. // exits foreach()
  648. break;
  649. }
  650. }
  651. */
  652. $question_list =array();
  653. foreach($this->questionList as $position=>$questionId) {
  654. $question_list[]= $questionId;
  655. }
  656. $len=count($question_list);
  657. $orderlist=array_keys($this->questionList);
  658. for($i=0;$i<$len;$i++) {
  659. $questionId = $question_list[$i];
  660. if($questionId == $id) {
  661. $pos1=$orderlist[$i+1];
  662. $pos2 =$orderlist[$i];
  663. if(!$pos2) {
  664. //echo 'cant move!';
  665. }
  666. break;
  667. }
  668. }
  669. // permutes questions in the array
  670. $temp=$this->questionList[$pos2];
  671. $this->questionList[$pos2]=$this->questionList[$pos1];
  672. $this->questionList[$pos1]=$temp;
  673. }
  674. /**
  675. * adds a question into the question list
  676. *
  677. * @author - Olivier Brouckaert
  678. * @param - integer $questionId - question ID
  679. * @return - boolean - true if the question has been added, otherwise false
  680. */
  681. function addToList($questionId) {
  682. // checks if the question ID is not in the list
  683. if(!$this->isInList($questionId)) {
  684. // selects the max position
  685. if(!$this->selectNbrQuestions()) {
  686. $pos=1;
  687. } else {
  688. if (is_array($this->questionList))
  689. $pos=max(array_keys($this->questionList))+1;
  690. }
  691. $this->questionList[$pos]=$questionId;
  692. return true;
  693. }
  694. return false;
  695. }
  696. /**
  697. * removes a question from the question list
  698. *
  699. * @author - Olivier Brouckaert
  700. * @param - integer $questionId - question ID
  701. * @return - boolean - true if the question has been removed, otherwise false
  702. */
  703. function removeFromList($questionId) {
  704. // searches the position of the question ID in the list
  705. $pos=array_search($questionId,$this->questionList);
  706. // question not found
  707. if($pos === false) {
  708. return false;
  709. } else {
  710. // deletes the position from the array containing the wanted question ID
  711. unset($this->questionList[$pos]);
  712. return true;
  713. }
  714. }
  715. /**
  716. * deletes the exercise from the database
  717. * Notice : leaves the question in the data base
  718. *
  719. * @author - Olivier Brouckaert
  720. */
  721. function delete() {
  722. global $_course;
  723. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  724. $sql="UPDATE $TBL_EXERCICES SET active='-1' WHERE id='".Database::escape_string($this->id)."'";
  725. Database::query($sql);
  726. api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizDeleted',api_get_user_id());
  727. if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian') ) {
  728. $this -> search_engine_delete();
  729. }
  730. }
  731. /**
  732. * Creates the form to create / edit an exercise
  733. * @param FormValidator $form the formvalidator instance (by reference)
  734. */
  735. function createForm ($form, $type='full') {
  736. global $id;
  737. if(empty($type)){
  738. $type='full';
  739. }
  740. // form title
  741. if (!empty($_GET['exerciseId'])) {
  742. $form_title = get_lang('ModifyExercise');
  743. } else {
  744. $form_title = get_lang('NewEx');
  745. }
  746. $form->addElement('header', '', $form_title);
  747. // title
  748. $form -> addElement('text', 'exerciseTitle', get_lang('ExerciseName'),'class="input_titles" id="exercise_title"');
  749. //$form->applyFilter('exerciseTitle','html_filter');
  750. $form -> addElement('html','<div class="row">
  751. <div class="label"></div>
  752. <div class="formw" style="height:50px">
  753. <a href="javascript://" onclick=" return show_media()"> <span id="media_icon"> <img style="vertical-align: middle;" src="../img/looknfeel.png" alt="" />&nbsp;'.get_lang('ExerciseDescription').'</span></a>
  754. </div>
  755. </div>');
  756. $editor_config = array('ToolbarSet' => 'TestQuestionDescription', 'Width' => '100%', 'Height' => '150');
  757. if(is_array($type)){
  758. $editor_config = array_merge($editor_config, $type);
  759. }
  760. $form -> addElement ('html','<div class="HideFCKEditor" id="HiddenFCKexerciseDescription" >');
  761. $form -> add_html_editor('exerciseDescription', get_lang('langExerciseDescription'), false, false, $editor_config);
  762. $form -> addElement ('html','</div>');
  763. $form -> addElement('html','<div class="row">
  764. <div class="label">&nbsp;</div>
  765. <div class="formw">
  766. <a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top;" ><img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AdvancedParameters').'</div></span></a>
  767. </div>
  768. </div>');
  769. // Random questions
  770. $form -> addElement('html','<div id="options" style="display:none">');
  771. if($type=='full') {
  772. // feedback type
  773. $radios_feedback = array();
  774. $radios_feedback[] = FormValidator :: createElement ('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'),'0',array('id' =>'exerciseType_1','onclick' => 'check_feedback()'));
  775. $radios_feedback[] = FormValidator :: createElement ('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'),'2',array('id' =>'exerciseType_2'));
  776. $form -> addGroup($radios_feedback, null, get_lang('FeedbackType'));
  777. $feedback_option[0]=get_lang('ExerciseAtTheEndOfTheTest');
  778. $feedback_option[1]=get_lang('DirectFeedback');
  779. $feedback_option[2]=get_lang('NoFeedback');
  780. //Can't modify a DirectFeedback question
  781. if ($this->selectFeedbackType() != 1 ) {
  782. // $form -> addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"');
  783. // test type
  784. $radios = array();
  785. $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('QuestionsPerPageOne'),'2','onclick = "check_per_page_one() " ');
  786. $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('QuestionsPerPageAll'),'1',array('onclick' => 'check_per_page_all()', 'id'=>'OptionPageAll'));
  787. $form -> addGroup($radios, null, get_lang('QuestionsPerPage'));
  788. } else {
  789. // if is Directfeedback but has not questions we can allow to modify the question type
  790. if ($this->selectNbrQuestions()== 0) {
  791. $form -> addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"');
  792. // test type
  793. $radios = array();
  794. $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SimpleExercise'),'1');
  795. $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2');
  796. $form -> addGroup($radios, null, get_lang('ExerciseType'));
  797. } else {
  798. //we force the options to the DirectFeedback exercisetype
  799. $form -> addElement('hidden', 'exerciseFeedbackType','1');
  800. $form -> addElement('hidden', 'exerciseType','2');
  801. }
  802. }
  803. $radios_results_disabled = array();
  804. $radios_results_disabled[] = FormValidator :: createElement ('radio', 'results_disabled', null, get_lang('Yes'), '0', array('id'=>'result_disabled_0'));
  805. $radios_results_disabled[] = FormValidator :: createElement ('radio', 'results_disabled', null, get_lang('No'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()'));
  806. $radios_results_disabled[] = FormValidator :: createElement ('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()'));
  807. $form -> addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'));
  808. $random = array();
  809. $option=array();
  810. $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ;
  811. $option = range(0,$max);
  812. $option[0]=get_lang('No');
  813. $random[] = FormValidator :: createElement ('select', 'randomQuestions',null,$option);
  814. $random[] = FormValidator :: createElement ('static', 'help','help','<span style="font-style: italic;">'.get_lang('RandomQuestionsHelp').'</span>');
  815. //$random[] = FormValidator :: createElement ('text', 'randomQuestions', null,null,'0');
  816. $form -> addGroup($random,null,get_lang('RandomQuestions'),'<br />');
  817. //random answers
  818. $radios_random_answers = array();
  819. $radios_random_answers[] = FormValidator :: createElement ('radio', 'randomAnswers', null, get_lang('Yes'),'1');
  820. $radios_random_answers[] = FormValidator :: createElement ('radio', 'randomAnswers', null, get_lang('No'),'0');
  821. $form -> addGroup($radios_random_answers, null, get_lang('RandomAnswers'));
  822. //Attempts
  823. $attempt_option=range(0,10);
  824. $attempt_option[0]=get_lang('Infinite');
  825. $form -> addElement('select', 'exerciseAttempts',get_lang('ExerciseAttempts'),$attempt_option);
  826. $form -> addElement('checkbox', 'enabletimelimit',get_lang('EnableTimeLimits'),null,'onclick = " return timelimit() "');
  827. $var= Exercise::selectTimeLimit();
  828. if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
  829. $form -> addElement('html','<div id="options2" style="display:block;">');
  830. else
  831. $form -> addElement('html','<div id="options2" style="display:none;">');
  832. //$form -> addElement('date', 'start_time', get_lang('ExeStartTime'), array('language'=>'es','format' => 'dMYHi'));
  833. //$form -> addElement('date', 'end_time', get_lang('ExeEndTime'), array('language'=>'es','format' => 'dMYHi'));
  834. $form->addElement('datepicker', 'start_time', get_lang('ExeStartTime'), array('form_name'=>'exercise_admin'), 5);
  835. $form->addElement('datepicker', 'end_time', get_lang('ExeEndTime'), array('form_name'=>'exercise_admin'), 5);
  836. //$form -> addElement('select', 'enabletimercontroltotalminutes',get_lang('ExerciseTimerControlMinutes'),$time_minutes_option);
  837. $form -> addElement('html','</div>');
  838. $check_option=$this -> selectType();
  839. if ($check_option==1 && isset($_GET['exerciseId'])) {
  840. $diplay = 'none';
  841. } else {
  842. $diplay = 'block';
  843. }
  844. $form -> addElement('checkbox', 'propagate_neg',get_lang('PropagateNegativeResults'),null);
  845. $form -> addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">');
  846. //Timer control
  847. $time_hours_option = range(0,12);
  848. $time_minutes_option = range(0,59);
  849. $form -> addElement('checkbox', 'enabletimercontrol',get_lang('EnableTimerControl'),null,array('onclick' =>'option_time_expired()','id'=>'enabletimercontrol','onload'=>'check_load_time()'));
  850. $expired_date = (int)$this->selectExpiredTime();
  851. if(($expired_date!='0')) {
  852. $form -> addElement('html','<div id="timercontrol" style="display:block;">');
  853. } else {
  854. $form -> addElement('html','<div id="timercontrol" style="display:none;">');
  855. }
  856. $form -> addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTotalDurationInMinutes'),array('style' => 'width : 35px','id' => 'enabletimercontroltotalminutes'));
  857. $form -> addElement('html','</div>');
  858. //$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));
  859. $form -> addElement('html','</div>'); //End advanced setting
  860. $form -> addElement('html','</div>');
  861. $defaults = array();
  862. if (api_get_setting('search_enabled') === 'true') {
  863. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  864. $form -> addElement ('checkbox', 'index_document','', get_lang('SearchFeatureDoIndexDocument'));
  865. $form -> addElement ('html','<br /><div class="row">');
  866. $form -> addElement ('html', '<div class="label">'. get_lang('SearchFeatureDocumentLanguage') .'</div>');
  867. $form -> addElement ('html', '<div class="formw">'. api_get_languages_combo() .'</div>');
  868. $form -> addElement ('html','</div><div class="sub-form">');
  869. $specific_fields = get_specific_field_list();
  870. foreach ($specific_fields as $specific_field) {
  871. $form -> addElement ('text', $specific_field['code'], $specific_field['name']);
  872. $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\''. TOOL_QUIZ .'\'');
  873. $values = get_specific_field_values_list($filter, array('value'));
  874. if ( !empty($values) ) {
  875. $arr_str_values = array();
  876. foreach ($values as $value) {
  877. $arr_str_values[] = $value['value'];
  878. }
  879. $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
  880. }
  881. }
  882. $form -> addElement ('html','</div>');
  883. }
  884. }
  885. // submit
  886. isset($_GET['exerciseId'])?$text=get_lang('ModifyExercise'):$text=get_lang('ProcedToQuestions');
  887. $form -> addElement('html', '<br /><br />');
  888. $form -> addElement('style_submit_button', 'submitExercise', $text, 'class="save"');
  889. $form -> addRule ('exerciseTitle', get_lang('GiveExerciseName'), 'required');
  890. if($type=='full') {
  891. // rules
  892. $form -> addRule ('exerciseAttempts', get_lang('Numeric'), 'numeric');
  893. $form -> addRule ('start_time', get_lang('InvalidDate'), 'date');
  894. $form -> addRule ('end_time', get_lang('InvalidDate'), 'date');
  895. $form -> addRule(array ('start_time', 'end_time'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
  896. }
  897. // defaults
  898. if($type=='full') {
  899. if($this -> id > 0) {
  900. if ($this -> random > $this->selectNbrQuestions()) {
  901. $defaults['randomQuestions'] = $this->selectNbrQuestions();
  902. } else {
  903. $defaults['randomQuestions'] = $this -> random;
  904. }
  905. $defaults['randomAnswers'] = $this ->selectRandomAnswers();
  906. $defaults['exerciseType'] = $this -> selectType();
  907. $defaults['exerciseTitle'] = $this -> selectTitle();
  908. $defaults['exerciseDescription'] = $this -> selectDescription();
  909. $defaults['exerciseAttempts'] = $this->selectAttempts();
  910. $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
  911. $defaults['results_disabled'] = $this->selectResultsDisabled();
  912. $defaults['propagate_neg'] = $this->selectPropagateNeg();
  913. if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
  914. $defaults['enabletimelimit'] = 1;
  915. $defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00')? $this -> start_time : date('Y-m-d 12:00:00');
  916. $defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00')?$this -> end_time : date('Y-m-d 12:00:00',time()+84600);
  917. //Get expired time
  918. if($this -> expired_time != '0') {
  919. $defaults['enabletimercontrol'] = 1;
  920. $defaults['enabletimercontroltotalminutes'] = $this -> expired_time;
  921. } else {
  922. $defaults['enabletimercontroltotalminutes'] = 0;
  923. }
  924. } else {
  925. $defaults['exerciseType'] = 2;
  926. $defaults['exerciseAttempts'] = 0;
  927. $defaults['randomQuestions'] = 0;
  928. $defaults['randomAnswers'] = 0;
  929. $defaults['exerciseDescription'] = '';
  930. $defaults['exerciseFeedbackType'] = 0;
  931. $defaults['results_disabled'] = 0;
  932. $defaults['start_time'] = date('Y-m-d 12:00:00');
  933. $defaults['end_time'] = date('Y-m-d 12:00:00',time()+84600);
  934. }
  935. } else {
  936. $defaults['exerciseTitle'] = $this -> selectTitle();
  937. $defaults['exerciseDescription'] = $this -> selectDescription();
  938. }
  939. if (api_get_setting('search_enabled') === 'true') {
  940. $defaults['index_document'] = 'checked="checked"';
  941. }
  942. $form -> setDefaults($defaults);
  943. }
  944. /**
  945. * function which process the creation of exercises
  946. * @param FormValidator $form the formvalidator instance
  947. */
  948. function processCreation($form, $type='') {
  949. $this -> updateTitle($form -> getSubmitValue('exerciseTitle'));
  950. $this -> updateDescription($form -> getSubmitValue('exerciseDescription'));
  951. $this -> updateAttempts($form -> getSubmitValue('exerciseAttempts'));
  952. $this -> updateFeedbackType($form -> getSubmitValue('exerciseFeedbackType'));
  953. $this -> updateType($form -> getSubmitValue('exerciseType'));
  954. $this -> setRandom($form -> getSubmitValue('randomQuestions'));
  955. $this -> updateRandomAnswers($form -> getSubmitValue('randomAnswers'));
  956. $this -> updateResultsDisabled($form -> getSubmitValue('results_disabled'));
  957. $this -> updateExpiredTime($form -> getSubmitValue('enabletimercontroltotalminutes'));
  958. $this -> updatePropagateNegative($form -> getSubmitValue('propagate_neg'));
  959. if($form -> getSubmitValue('enabletimelimit')==1) {
  960. $start_time = $form -> getSubmitValue('start_time');
  961. $this->start_time = $start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00';
  962. $end_time = $form -> getSubmitValue('end_time');
  963. $this->end_time = $end_time['Y'].'-'.$end_time['F'].'-'.$end_time['d'].' '.$end_time['H'].':'.$end_time['i'].':00';
  964. } else {
  965. $this->start_time = '0000-00-00 00:00:00';
  966. $this->end_time = '0000-00-00 00:00:00';
  967. }
  968. if($form -> getSubmitValue('enabletimercontrol') == 1) {
  969. $expired_total_time = $form -> getSubmitValue('enabletimercontroltotalminutes');
  970. if ($this->expired_time == 0) {
  971. $this->expired_time = $expired_total_time;
  972. }
  973. } else {
  974. $this->expired_time = 0;
  975. }
  976. if($form -> getSubmitValue('randomAnswers') == 1) {
  977. $this->random_answers=1;
  978. } else {
  979. $this->random_answers=0;
  980. }
  981. $this -> save($type);
  982. }
  983. function search_engine_save() {
  984. if ($_POST['index_document'] != 1) {
  985. return;
  986. }
  987. $course_id = api_get_course_id();
  988. require_once(api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  989. require_once(api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  990. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  991. $specific_fields = get_specific_field_list();
  992. $ic_slide = new IndexableChunk();
  993. $all_specific_terms = '';
  994. foreach ($specific_fields as $specific_field) {
  995. if (isset($_REQUEST[$specific_field['code']])) {
  996. $sterms = trim($_REQUEST[$specific_field['code']]);
  997. if (!empty($sterms)) {
  998. $all_specific_terms .= ' '. $sterms;
  999. $sterms = explode(',', $sterms);
  1000. foreach ($sterms as $sterm) {
  1001. $ic_slide->addTerm(trim($sterm), $specific_field['code']);
  1002. add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm);
  1003. }
  1004. }
  1005. }
  1006. }
  1007. // build the chunk to index
  1008. $ic_slide->addValue("title", $this->exercise);
  1009. $ic_slide->addCourseId($course_id);
  1010. $ic_slide->addToolId(TOOL_QUIZ);
  1011. $xapian_data = array(
  1012. SE_COURSE_ID => $course_id,
  1013. SE_TOOL_ID => TOOL_QUIZ,
  1014. SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id),
  1015. SE_USER => (int)api_get_user_id(),
  1016. );
  1017. $ic_slide->xapian_data = serialize($xapian_data);
  1018. $exercise_description = $all_specific_terms .' '. $this->description;
  1019. $ic_slide->addValue("content", $exercise_description);
  1020. $di = new DokeosIndexer();
  1021. isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english';
  1022. $di->connectDb(NULL, NULL, $lang);
  1023. $di->addChunk($ic_slide);
  1024. //index and return search engine document id
  1025. $did = $di->index();
  1026. if ($did) {
  1027. // save it to db
  1028. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  1029. $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
  1030. VALUES (NULL , \'%s\', \'%s\', %s, %s)';
  1031. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did);
  1032. Database::query($sql);
  1033. }
  1034. }
  1035. function search_engine_edit() {
  1036. // update search enchine and its values table if enabled
  1037. if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
  1038. $course_id = api_get_course_id();
  1039. // actually, it consists on delete terms from db, insert new ones, create a new search engine document, and remove the old one
  1040. // get search_did
  1041. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  1042. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
  1043. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
  1044. $res = Database::query($sql);
  1045. if (Database::num_rows($res) > 0) {
  1046. require_once(api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
  1047. require_once(api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
  1048. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  1049. $se_ref = Database::fetch_array($res);
  1050. $specific_fields = get_specific_field_list();
  1051. $ic_slide = new IndexableChunk();
  1052. $all_specific_terms = '';
  1053. foreach ($specific_fields as $specific_field) {
  1054. delete_all_specific_field_value($course_id, $specific_field['id'], TOOL_QUIZ, $this->id);
  1055. if (isset($_REQUEST[$specific_field['code']])) {
  1056. $sterms = trim($_REQUEST[$specific_field['code']]);
  1057. $all_specific_terms .= ' '. $sterms;
  1058. $sterms = explode(',', $sterms);
  1059. foreach ($sterms as $sterm) {
  1060. $ic_slide->addTerm(trim($sterm), $specific_field['code']);
  1061. add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm);
  1062. }
  1063. }
  1064. }
  1065. // build the chunk to index
  1066. $ic_slide->addValue("title", $this->exercise);
  1067. $ic_slide->addCourseId($course_id);
  1068. $ic_slide->addToolId(TOOL_QUIZ);
  1069. $xapian_data = array(
  1070. SE_COURSE_ID => $course_id,
  1071. SE_TOOL_ID => TOOL_QUIZ,
  1072. SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id),
  1073. SE_USER => (int)api_get_user_id(),
  1074. );
  1075. $ic_slide->xapian_data = serialize($xapian_data);
  1076. $exercise_description = $all_specific_terms .' '. $this->description;
  1077. $ic_slide->addValue("content", $exercise_description);
  1078. $di = new DokeosIndexer();
  1079. isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english';
  1080. $di->connectDb(NULL, NULL, $lang);
  1081. $di->remove_document((int)$se_ref['search_did']);
  1082. $di->addChunk($ic_slide);
  1083. //index and return search engine document id
  1084. $did = $di->index();
  1085. if ($did) {
  1086. // save it to db
  1087. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=\'%s\'';
  1088. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
  1089. Database::query($sql);
  1090. $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
  1091. VALUES (NULL , \'%s\', \'%s\', %s, %s)';
  1092. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did);
  1093. Database::query($sql);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. function search_engine_delete() {
  1099. // remove from search engine if enabled
  1100. if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian') ) {
  1101. $course_id = api_get_course_id();
  1102. $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
  1103. $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
  1104. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
  1105. $res = Database::query($sql);
  1106. if (Database::num_rows($res) > 0) {
  1107. $row = Database::fetch_array($res);
  1108. require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
  1109. $di = new DokeosIndexer();
  1110. $di->remove_document((int)$row['search_did']);
  1111. unset($di);
  1112. $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
  1113. foreach ( $this->questionList as $question_i) {
  1114. $sql = 'SELECT type FROM %s WHERE id=%s';
  1115. $sql = sprintf($sql, $tbl_quiz_question, $question_i);
  1116. $qres = Database::query($sql);
  1117. if (Database::num_rows($qres) > 0) {
  1118. $qrow = Database::fetch_array($qres);
  1119. $objQuestion = Question::getInstance($qrow['type']);
  1120. $objQuestion = Question::read((int)$question_i);
  1121. $objQuestion->search_engine_edit($this->id, FALSE, TRUE);
  1122. unset($objQuestion);
  1123. }
  1124. }
  1125. }
  1126. $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
  1127. $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
  1128. Database::query($sql);
  1129. // remove terms from db
  1130. require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php');
  1131. delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id);
  1132. }
  1133. }
  1134. function selectExpiredTime() {
  1135. return $this->expired_time;
  1136. }
  1137. /**
  1138. * Cleans the student's results only for the Exercise tool (Not from the LP)
  1139. * The LP results are NOT deleted
  1140. * Works with exercises in sessions
  1141. * @return int quantity of user's exercises deleted
  1142. */
  1143. function clean_results() {
  1144. $table_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1145. $table_track_e_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1146. $sql_select = "SELECT exe_id FROM $table_track_e_exercises
  1147. WHERE exe_cours_id = '".api_get_course_id()."' AND exe_exo_id = ".$this->id." AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = ".api_get_session_id()."";
  1148. $result = Database::query($sql_select);
  1149. $exe_list = Database::store_result($result);
  1150. //deleting TRACK_E_ATTEMPT table
  1151. $i = 0;
  1152. if (is_array($exe_list) && count($exe_list) > 0) {
  1153. foreach($exe_list as $item) {
  1154. $sql = "DELETE FROM $table_track_e_attempt WHERE exe_id = '".$item['exe_id']."'";
  1155. Database::query($sql);
  1156. $i++;
  1157. }
  1158. }
  1159. //delete TRACK_E_EXERCICES table
  1160. $sql = "DELETE FROM $table_track_e_exercises
  1161. WHERE exe_cours_id = '".api_get_course_id()."' AND exe_exo_id = ".$this->id." AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id = ".api_get_session_id()."";
  1162. Database::query($sql);
  1163. return $i;
  1164. }
  1165. /**
  1166. * Copies an exercise (duplicate all questions and answers)
  1167. */
  1168. public function copy_exercise() {
  1169. $exercise_obj= new Exercise();
  1170. $exercise_obj = $this;
  1171. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  1172. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  1173. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  1174. // force the creation of a new exercise
  1175. $exercise_obj->updateTitle($exercise_obj->selectTitle().' - '.get_lang('Copy'));
  1176. //Hides the new exercise
  1177. $exercise_obj->updateStatus(false);
  1178. $exercise_obj->updateId(0);
  1179. $exercise_obj->save();
  1180. $new_exercise_id = $exercise_obj->selectId();
  1181. $question_list = $exercise_obj->selectQuestionList();
  1182. //Question creation
  1183. foreach ($question_list as $old_question_id) {
  1184. $old_question_obj = Question::read($old_question_id);
  1185. $new_id = $old_question_obj->duplicate();
  1186. $new_question_obj = Question::read($new_id);
  1187. $new_question_obj->addToList($new_exercise_id);
  1188. // This should be moved to the duplicate function
  1189. $new_answer_obj = new Answer($old_question_id);
  1190. $new_answer_obj->read();
  1191. $new_answer_obj->duplicate($new_id);
  1192. }
  1193. }
  1194. /**
  1195. * Changes the exercise id
  1196. *
  1197. * @param - in $id - exercise id
  1198. */
  1199. private function updateId($id) {
  1200. $this->id = $id;
  1201. }
  1202. /**
  1203. * Changes the exercise status
  1204. *
  1205. * @param - string $status - exercise status
  1206. */
  1207. function updateStatus($status) {
  1208. $this->active = $status;
  1209. }
  1210. public function get_stat_track_exercise_info($lp_id = 0, $lp_item_id = 0, $lp_item_view_id = 0, $status = 'incomplete') {
  1211. $track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1212. if (empty($lp_id)) {
  1213. $lp_id = 0;
  1214. }
  1215. if (empty($lp_item_id)) {
  1216. $lp_item_id = 0;
  1217. }
  1218. if (empty($lp_item_view_id)) {
  1219. $lp_item_view_id = 0;
  1220. }
  1221. $condition = ' WHERE exe_exo_id = ' . "'" . $this->id . "'" .' AND
  1222. exe_user_id = ' . "'" . api_get_user_id() . "'" . ' AND
  1223. exe_cours_id = ' . "'" . api_get_course_id() . "'" . ' AND
  1224. status = ' . "'" . Database::escape_string($status). "'" . ' AND
  1225. orig_lp_id = ' . "'" . $lp_id . "'" . ' AND
  1226. orig_lp_item_id = ' . "'" . $lp_item_id . "'" . ' AND
  1227. orig_lp_item_view_id = ' . "'" . $lp_item_view_id . "'" . ' AND
  1228. session_id = ' . "'" . api_get_session_id() . "' LIMIT 1"; //Adding limit 1 just in case
  1229. $sql_track = 'SELECT * FROM '.$track_exercises.$condition;
  1230. $result = Database::query($sql_track);
  1231. $new_array = array();
  1232. if (Database::num_rows($result) > 0 ) {
  1233. $new_array = Database::fetch_array($result, 'ASSOC');
  1234. }
  1235. return $new_array;
  1236. }
  1237. public function save_stat_track_exercise_info($clock_expired_time = 0, $safe_lp_id = 0, $safe_lp_item_id = 0, $safe_lp_item_view_id = 0, $questionList = array()) {
  1238. $track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  1239. if (empty($safe_lp_id)) {
  1240. $safe_lp_id = 0;
  1241. }
  1242. if (empty($safe_lp_item_id)) {
  1243. $safe_lp_item_id = 0;
  1244. }
  1245. if (empty($clock_expired_time)) {
  1246. $clock_expired_time = 0;
  1247. }
  1248. if ($this->expired_time != 0) {
  1249. $sql_fields = "expired_time_control, ";
  1250. $sql_fields_values = "'"."$clock_expired_time"."',";
  1251. } else {
  1252. $sql_fields = "";
  1253. $sql_fields_values = "";
  1254. }
  1255. if ($this->type == ONE_PER_PAGE) {
  1256. $sql = "INSERT INTO $track_exercises($sql_fields exe_exo_id,exe_user_id,exe_cours_id,status,session_id,data_tracking,start_date,orig_lp_id,orig_lp_item_id)
  1257. VALUES($sql_fields_values '".$this->id."','" . api_get_user_id() . "','" . api_get_course_id() . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "','" . api_get_utc_datetime() . "',$safe_lp_id,$safe_lp_item_id)";
  1258. } else {
  1259. $sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date,orig_lp_id,orig_lp_item_id)
  1260. VALUES($sql_fields_values '".$this->id."','" . api_get_user_id() . "','" . api_get_course_id() . "','incomplete','" . api_get_session_id() . "','" . api_get_utc_datetime() . "',$safe_lp_id,$safe_lp_item_id)";
  1261. }
  1262. Database::query($sql);
  1263. }
  1264. public function show_button($nbrQuestions, $questionNum) {
  1265. $html = '';
  1266. $html = '<div style="margin-top:-10px;">';
  1267. $confirmation_alert = $this->type == 1? " onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\" ":"";
  1268. $submit_btn = '<button class="next" type="submit" name="submit" name="submit_save" id="submit_save" '.$confirmation_alert.' >';
  1269. $hotspot_get = $_POST['hotspot'];
  1270. if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) {
  1271. $submit_btn = '';
  1272. $html .='<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js" type="text/javascript"></script>';
  1273. $html .='<style type="text/css" media="all">@import "' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css";</style>';
  1274. } else {
  1275. if (api_is_allowed_to_session_edit() ) {
  1276. if ($this->type == ALL_ON_ONE_PAGE || $nbrQuestions == $questionNum) {
  1277. $submit_btn .= get_lang('ValidateAnswer');
  1278. $name_btn = get_lang('ValidateAnswer');
  1279. } else {
  1280. $submit_btn .= get_lang('NextQuestion');
  1281. $name_btn = get_lang('NextQuestion');
  1282. }
  1283. $submit_btn .= '</button>';
  1284. if ($this->expired_time != 0) {
  1285. $html .= $submit_btn ='<button class="next" type="submit" id="submit_save" value="'.$name_btn.'" name="submit_save"/>'.$name_btn.'</button>';
  1286. } else {
  1287. $html .= $submit_btn;
  1288. }
  1289. }
  1290. }
  1291. $html .= '</div>'; //margin top -10
  1292. return $html;
  1293. }
  1294. /**
  1295. * So the time control will work
  1296. */
  1297. public function show_time_control_js($time_left) {
  1298. $time_left = intval($time_left);
  1299. return "<script type=\"text/javascript\">
  1300. $(document).ready(function(){
  1301. function get_expired_date_string(expired_time) {
  1302. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
  1303. var day, month, year, hours, minutes, seconds, date_string;
  1304. var obj_date = new Date(expired_time);
  1305. day = obj_date.getDate();
  1306. if (day < 10) day = '0' + day;
  1307. month = obj_date.getMonth();
  1308. year = obj_date.getFullYear();
  1309. hours = obj_date.getHours();
  1310. if (hours < 10) hours = '0' + hours;
  1311. minutes = obj_date.getMinutes();
  1312. if (minutes < 10) minutes = '0' + minutes;
  1313. seconds = obj_date.getSeconds();
  1314. if (seconds < 10) seconds = '0' + seconds;
  1315. date_string = months[month] +' ' + day + ', ' + year + ' ' + hours + ':' + minutes + ':' + seconds;
  1316. return date_string;
  1317. }
  1318. function onExpiredTimeExercise() {
  1319. $('#wrapper-clock').hide(); $('#exercise_form').hide();
  1320. $('#expired-message-id').show();
  1321. $('#exercise_form').submit();
  1322. }
  1323. var current_time = new Date().getTime();
  1324. var time_left = parseInt(".$time_left.");
  1325. var expired_time = current_time + (time_left*1000);
  1326. var expired_date = get_expired_date_string(expired_time);
  1327. $('#text-content').epiclock({
  1328. mode: EC_COUNTDOWN,
  1329. format: 'x{ : } i{ : } s{}',
  1330. target: expired_date,
  1331. onTimer: function(){ onExpiredTimeExercise(); }
  1332. }).clocks(EC_RUN);
  1333. $('#submit_save').click(function () {});
  1334. });
  1335. </script>";
  1336. }
  1337. /**
  1338. * Lp javascript for hotspots
  1339. */
  1340. public function show_lp_javascript() {
  1341. return "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  1342. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  1343. <script language=\"JavaScript\" type=\"text/javascript\">
  1344. <!--
  1345. // -----------------------------------------------------------------------------
  1346. // Globals
  1347. // Major version of Flash required
  1348. var requiredMajorVersion = 7;
  1349. // Minor version of Flash required
  1350. var requiredMinorVersion = 0;
  1351. // Minor version of Flash required
  1352. var requiredRevision = 0;
  1353. // the version of javascript supported
  1354. var jsVersion = 1.0;
  1355. // -----------------------------------------------------------------------------
  1356. // -->
  1357. </script>
  1358. <script language=\"VBScript\" type=\"text/vbscript\">
  1359. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  1360. Function VBGetSwfVer(i)
  1361. on error resume next
  1362. Dim swControl, swVersion
  1363. swVersion = 0
  1364. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  1365. if (IsObject(swControl)) then
  1366. swVersion = swControl.GetVariable(\"\$version\")
  1367. end if
  1368. VBGetSwfVer = swVersion
  1369. End Function
  1370. // -->
  1371. </script>
  1372. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  1373. <!-- // Detect Client Browser type
  1374. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  1375. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  1376. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  1377. jsVersion = 1.1;
  1378. // JavaScript helper required to detect Flash Player PlugIn version information
  1379. function JSGetSwfVer(i){
  1380. // NS/Opera version >= 3 check for Flash plugin in plugin array
  1381. if (navigator.plugins != null && navigator.plugins.length > 0) {
  1382. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  1383. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  1384. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  1385. descArray = flashDescription.split(\" \");
  1386. tempArrayMajor = descArray[2].split(\".\");
  1387. versionMajor = tempArrayMajor[0];
  1388. versionMinor = tempArrayMajor[1];
  1389. if ( descArray[3] != \"\" ) {
  1390. tempArrayMinor = descArray[3].split(\"r\");
  1391. } else {
  1392. tempArrayMinor = descArray[4].split(\"r\");
  1393. }
  1394. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  1395. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  1396. } else {
  1397. flashVer = -1;
  1398. }
  1399. }
  1400. // MSN/WebTV 2.6 supports Flash 4
  1401. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  1402. // WebTV 2.5 supports Flash 3
  1403. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  1404. // older WebTV supports Flash 2
  1405. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  1406. // Can't detect in all other cases
  1407. else {
  1408. flashVer = -1;
  1409. }
  1410. return flashVer;
  1411. }
  1412. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  1413. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  1414. {
  1415. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  1416. // loop backwards through the versions until we find the newest version
  1417. for (i=25;i>0;i--) {
  1418. if (isIE && isWin && !isOpera) {
  1419. versionStr = VBGetSwfVer(i);
  1420. } else {
  1421. versionStr = JSGetSwfVer(i);
  1422. }
  1423. if (versionStr == -1 ) {
  1424. return false;
  1425. } else if (versionStr != 0) {
  1426. if(isIE && isWin && !isOpera) {
  1427. tempArray = versionStr.split(\" \");
  1428. tempString = tempArray[1];
  1429. versionArray = tempString .split(\",\");
  1430. } else {
  1431. versionArray = versionStr.split(\".\");
  1432. }
  1433. versionMajor = versionArray[0];
  1434. versionMinor = versionArray[1];
  1435. versionRevision = versionArray[2];
  1436. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  1437. versionNum = parseFloat(versionString);
  1438. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  1439. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  1440. return true;
  1441. } else {
  1442. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  1443. }
  1444. }
  1445. }
  1446. }
  1447. // -->
  1448. </script>";
  1449. }
  1450. /**
  1451. * This function was originally found in the exercise_show.php
  1452. * @param int exe id
  1453. * @param int question id
  1454. * @param int the choice the user selected
  1455. * @param array the hotspot coordinates $hotspot[$question_id] = coordinates
  1456. * @param string function is called from 'exercise_show' or 'exercise_result'
  1457. * @param bool save results in the DB or just show the reponse
  1458. * @param bool gets information from DB or from the current selection
  1459. * @param bool show results or not
  1460. * @todo reduce parameters of this function
  1461. * @return string html code
  1462. */
  1463. function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0) {
  1464. global $_configuration, $feedback_type;
  1465. $html = '';
  1466. $questionId = intval($questionId);
  1467. $exeId = intval($exeId);
  1468. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  1469. $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
  1470. // Creates a temporary Question object
  1471. $objQuestionTmp = Question :: read($questionId);
  1472. $questionName = $objQuestionTmp->selectTitle();
  1473. $questionDescription = $objQuestionTmp->selectDescription();
  1474. $questionWeighting = $objQuestionTmp->selectWeighting();
  1475. $answerType = $objQuestionTmp->selectType();
  1476. $quesId = $objQuestionTmp->selectId();
  1477. $extra = $objQuestionTmp->extra;
  1478. //Extra information of the question
  1479. if (!empty($extra)){
  1480. $extra = explode(':', $extra);
  1481. $true_score = $extra[0];
  1482. $false_score = $extra[1];
  1483. $doubt_score = $extra[2];
  1484. }
  1485. $totalWeighting = 0;
  1486. $totalScore = 0;
  1487. // Destruction of the Question object
  1488. unset ($objQuestionTmp);
  1489. // Construction of the Answer object
  1490. $objAnswerTmp = new Answer($questionId);
  1491. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  1492. $questionScore = 0;
  1493. if ($answerType == FREE_ANSWER) {
  1494. $nbrAnswers = 1;
  1495. }
  1496. $user_answer = '';
  1497. // Get answer list for matching
  1498. $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.$questionId.'" ';
  1499. $res_answer = Database::query($sql_answer);
  1500. $answer_matching =array();
  1501. while ($real_answer = Database::fetch_array($res_answer)) {
  1502. $answer_matching[$real_answer['id']]= $real_answer['answer'];
  1503. }
  1504. $real_answers = array();
  1505. $quiz_question_options = Question::readQuestionOption($questionId);
  1506. for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
  1507. $answer = $objAnswerTmp->selectAnswer($answerId);
  1508. $answerComment = $objAnswerTmp->selectComment($answerId);
  1509. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  1510. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  1511. $numAnswer = $objAnswerTmp->selectAutoId($answerId);
  1512. switch ($answerType) {
  1513. // for unique answer
  1514. case UNIQUE_ANSWER :
  1515. case UNIQUE_ANSWER_NO_OPTION :
  1516. if ($from_database) {
  1517. $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
  1518. $resultans = Database::query($queryans);
  1519. $choice = Database::result($resultans,0,"answer");
  1520. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1521. $studentChoice=($choice == $numAnswer)?1:0;
  1522. if ($studentChoice) {
  1523. $questionScore+=$answerWeighting;
  1524. $totalScore+=$answerWeighting;
  1525. }
  1526. } else {
  1527. $studentChoice=($choice == $numAnswer)?1:0;
  1528. if ($studentChoice) {
  1529. $questionScore+=$answerWeighting;
  1530. $totalScore+=$answerWeighting;
  1531. }
  1532. }
  1533. break;
  1534. // for multiple answers
  1535. case MULTIPLE_ANSWER_TRUE_FALSE :
  1536. if ($from_database) {
  1537. $choice=array();
  1538. $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
  1539. $resultans = Database::query($queryans);
  1540. while ($row = Database::fetch_array($resultans)) {
  1541. $ind = $row['answer'];
  1542. $result = explode(':',$ind);
  1543. $my_answer_id = $result[0];
  1544. $option = $result[1];
  1545. $choice[$my_answer_id] = $option;
  1546. }
  1547. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1548. $studentChoice =$choice[$numAnswer];
  1549. } else {
  1550. $studentChoice =$choice[$numAnswer];
  1551. }
  1552. if ($studentChoice == $answerCorrect ) {
  1553. $questionScore +=$true_score;
  1554. } else {
  1555. if ($quiz_question_options[$studentChoice]['name'] != 'DoubtScore') {
  1556. $questionScore += $false_score;
  1557. } else {
  1558. $questionScore += $doubt_score;
  1559. }
  1560. }
  1561. $totalScore +=$true_score;
  1562. break;
  1563. case MULTIPLE_ANSWER :
  1564. if ($from_database) {
  1565. $choice=array();
  1566. $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
  1567. $resultans = Database::query($queryans);
  1568. while ($row = Database::fetch_array($resultans)) {
  1569. $ind = $row['answer'];
  1570. $choice[$ind] = 1;
  1571. }
  1572. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1573. $studentChoice=$choice[$numAnswer];
  1574. if ($studentChoice) {
  1575. $questionScore +=$answerWeighting;
  1576. $totalScore +=$answerWeighting;
  1577. }
  1578. } else {
  1579. $studentChoice=$choice[$numAnswer];
  1580. if ($studentChoice) {
  1581. $questionScore +=$answerWeighting;
  1582. $totalScore +=$answerWeighting;
  1583. }
  1584. }
  1585. break;
  1586. case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
  1587. if ($from_database) {
  1588. $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
  1589. $resultans = Database::query($queryans);
  1590. while ($row = Database::fetch_array($resultans)) {
  1591. $ind = $row['answer'];
  1592. $result = explode(':',$ind);
  1593. $my_answer_id = $result[0];
  1594. $option = $result[1];
  1595. $choice[$my_answer_id] = $option;
  1596. }
  1597. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1598. $studentChoice=$choice[$numAnswer];
  1599. if ($answerCorrect == 1) {
  1600. if ($studentChoice == 1) { //true value see MultipleAnswerCombinationTrueFalse class
  1601. $real_answers[$answerId] = true;
  1602. } elseif ($studentChoice == 2) { //false value
  1603. $real_answers[$answerId] = false;
  1604. } else {
  1605. $real_answers[$answerId] = false;
  1606. }
  1607. } else {
  1608. if ($studentChoice == 1) { //true value
  1609. $real_answers[$answerId] = false;
  1610. } elseif ($studentChoice == 2) { //false value see MultipleAnswerCombinationTrueFalse class
  1611. $real_answers[$answerId] = true;
  1612. } else {
  1613. $real_answers[$answerId] = true;
  1614. }
  1615. }
  1616. } else {
  1617. $studentChoice=$choice[$numAnswer];
  1618. if ($answerCorrect == 1) {
  1619. if ($studentChoice == 1) { //true value see MultipleAnswerCombinationTrueFalse class
  1620. $real_answers[$answerId] = true;
  1621. } elseif ($studentChoice == 2) { //false value
  1622. $real_answers[$answerId] = false;
  1623. } else {
  1624. $real_answers[$answerId] = false;
  1625. }
  1626. } else {
  1627. if ($studentChoice == 1) { //true value
  1628. $real_answers[$answerId] = false;
  1629. } elseif ($studentChoice == 2) { //false value see MultipleAnswerCombinationTrueFalse class
  1630. $real_answers[$answerId] = true;
  1631. } else {
  1632. $real_answers[$answerId] = true;
  1633. }
  1634. }
  1635. $final_answer = true;
  1636. foreach($real_answers as $my_answer) {
  1637. if (!$my_answer) {
  1638. $final_answer = false;
  1639. }
  1640. }
  1641. }
  1642. break;
  1643. case MULTIPLE_ANSWER_COMBINATION:
  1644. if ($from_database) {
  1645. $queryans = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".$exeId."' and question_id= '".$questionId."'";
  1646. $resultans = Database::query($queryans);
  1647. while ($row = Database::fetch_array($resultans)) {
  1648. $ind = $row['answer'];
  1649. $choice[$ind] = 1;
  1650. }
  1651. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1652. $studentChoice=$choice[$numAnswer];
  1653. if ($answerCorrect == 1) {
  1654. if ($studentChoice) {
  1655. $real_answers[$answerId] = true;
  1656. } else {
  1657. $real_answers[$answerId] = false;
  1658. }
  1659. } else {
  1660. if ($studentChoice) {
  1661. $real_answers[$answerId] = false;
  1662. } else {
  1663. $real_answers[$answerId] = true;
  1664. }
  1665. }
  1666. } else {
  1667. $studentChoice=$choice[$numAnswer];
  1668. if ($answerCorrect == 1) {
  1669. if ($studentChoice) {
  1670. $real_answers[$answerId] = true;
  1671. } else {
  1672. $real_answers[$answerId] = false;
  1673. }
  1674. } else {
  1675. if ($studentChoice) {
  1676. $real_answers[$answerId] = false;
  1677. } else {
  1678. $real_answers[$answerId] = true;
  1679. }
  1680. }
  1681. $final_answer = true;
  1682. foreach($real_answers as $my_answer) {
  1683. if (!$my_answer) {
  1684. $final_answer = false;
  1685. }
  1686. }
  1687. }
  1688. break;
  1689. // for fill in the blanks
  1690. case FILL_IN_BLANKS :
  1691. // the question is encoded like this
  1692. // [A] B [C] D [E] F::10,10,10@1
  1693. // number 1 before the "@" means that is a switchable fill in blank question
  1694. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  1695. // means that is a normal fill blank question
  1696. // first we explode the "::"
  1697. $pre_array = explode('::', $answer);
  1698. // is switchable fill blank or not
  1699. $last = count($pre_array) - 1;
  1700. $is_set_switchable = explode('@', $pre_array[$last]);
  1701. $switchable_answer_set = false;
  1702. if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
  1703. $switchable_answer_set = true;
  1704. }
  1705. $answer = '';
  1706. for ($k = 0; $k < $last; $k++) {
  1707. $answer .= $pre_array[$k];
  1708. }
  1709. // splits weightings that are joined with a comma
  1710. $answerWeighting = explode(',', $is_set_switchable[0]);
  1711. // we save the answer because it will be modified
  1712. //$temp = $answer;
  1713. $temp = text_filter($answer);
  1714. /* // Deprecated code
  1715. // TeX parsing
  1716. // 1. find everything between the [tex] and [/tex] tags
  1717. $startlocations = api_strpos($temp, '[tex]');
  1718. $endlocations = api_strpos($temp, '[/tex]');
  1719. if ($startlocations !== false && $endlocations !== false) {
  1720. $texstring = api_substr($temp, $startlocations, $endlocations - $startlocations +6);
  1721. // 2. replace this by {texcode}
  1722. $temp = str_replace($texstring, '{texcode}', $temp);
  1723. }
  1724. */
  1725. $answer = '';
  1726. $j = 0;
  1727. //initialise answer tags
  1728. $user_tags = array ();
  1729. $correct_tags = array ();
  1730. $real_text = array ();
  1731. // the loop will stop at the end of the text
  1732. while (1) {
  1733. // quits the loop if there are no more blanks (detect '[')
  1734. if (($pos = api_strpos($temp, '[')) === false) {
  1735. // adds the end of the text
  1736. $answer = $temp;
  1737. /* // Deprecated code
  1738. // TeX parsing - replacement of texcode tags
  1739. $texstring = api_parse_tex($texstring);
  1740. $answer = str_replace("{texcode}", $texstring, $answer);
  1741. */
  1742. $real_text[] = $answer;
  1743. break; //no more "blanks", quit the loop
  1744. }
  1745. // adds the piece of text that is before the blank
  1746. //and ends with '[' into a general storage array
  1747. $real_text[] = api_substr($temp, 0, $pos +1);
  1748. $answer .= api_substr($temp, 0, $pos +1);
  1749. //take the string remaining (after the last "[" we found)
  1750. $temp = api_substr($temp, $pos +1);
  1751. // quit the loop if there are no more blanks, and update $pos to the position of next ']'
  1752. if (($pos = api_strpos($temp, ']')) === false) {
  1753. // adds the end of the text
  1754. $answer .= $temp;
  1755. break;
  1756. }
  1757. if ($from_database) {
  1758. $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($exeId)."' AND question_id= '".Database::escape_string($questionId)."'";
  1759. $resfill = Database::query($queryfill);
  1760. $str = Database::result($resfill,0,'answer');
  1761. preg_match_all('#\[([^[]*)\]#', $str, $arr);
  1762. $str = str_replace('\r\n', '', $str);
  1763. $choice = $arr[1];
  1764. $tmp=strrpos($choice[$j],' / ');
  1765. $choice[$j]=api_substr($choice[$j],0,$tmp);
  1766. $choice[$j]=trim($choice[$j]);
  1767. //Needed to let characters ' and " to work as part of an answer
  1768. $choice[$j] = stripslashes($choice[$j]);
  1769. } else {
  1770. $choice[$j] = trim($choice[$j]);
  1771. }
  1772. $user_tags[] = api_strtolower($choice[$j]);
  1773. //put the contents of the [] answer tag into correct_tags[]
  1774. $correct_tags[] = api_strtolower(api_substr($temp, 0, $pos));
  1775. $j++;
  1776. $temp = api_substr($temp, $pos +1);
  1777. //$answer .= ']';
  1778. }
  1779. $answer = '';
  1780. $real_correct_tags = $correct_tags;
  1781. $chosen_list = array ();
  1782. for ($i = 0; $i < count($real_correct_tags); $i++) {
  1783. if ($i == 0) {
  1784. $answer .= $real_text[0];
  1785. }
  1786. if (!$switchable_answer_set) {
  1787. //needed to parse ' and " characters
  1788. $user_tags[$i] = stripslashes($user_tags[$i]);
  1789. if ($correct_tags[$i] == $user_tags[$i]) {
  1790. // gives the related weighting to the student
  1791. $questionScore += $answerWeighting[$i];
  1792. // increments total score
  1793. $totalScore += $answerWeighting[$i];
  1794. // adds the word in green at the end of the string
  1795. $answer .= $correct_tags[$i];
  1796. }
  1797. // else if the word entered by the student IS NOT the same as the one defined by the professor
  1798. elseif (!empty ($user_tags[$i])) {
  1799. // adds the word in red at the end of the string, and strikes it
  1800. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  1801. } else {
  1802. // adds a tabulation if no word has been typed by the student
  1803. $answer .= '&nbsp;&nbsp;&nbsp;';
  1804. }
  1805. } else {
  1806. // switchable fill in the blanks
  1807. if (in_array($user_tags[$i], $correct_tags)) {
  1808. $chosen_list[] = $user_tags[$i];
  1809. $correct_tags = array_diff($correct_tags, $chosen_list);
  1810. // gives the related weighting to the student
  1811. $questionScore += $answerWeighting[$i];
  1812. // increments total score
  1813. $totalScore += $answerWeighting[$i];
  1814. // adds the word in green at the end of the string
  1815. $answer .= $user_tags[$i];
  1816. }
  1817. elseif (!empty ($user_tags[$i])) {
  1818. // else if the word entered by the student IS NOT the same as the one defined by the professor
  1819. // adds the word in red at the end of the string, and strikes it
  1820. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  1821. } else {
  1822. // adds a tabulation if no word has been typed by the student
  1823. $answer .= '&nbsp;&nbsp;&nbsp;';
  1824. }
  1825. }
  1826. // adds the correct word, followed by ] to close the blank
  1827. $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
  1828. if (isset ($real_text[$i +1])) {
  1829. $answer .= $real_text[$i +1];
  1830. }
  1831. }
  1832. break;
  1833. // for free answer
  1834. case FREE_ANSWER :
  1835. if ($from_database) {
  1836. $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
  1837. $resq = Database::query($query);
  1838. $choice = Database::result($resq,0,'answer');
  1839. $choice = str_replace('\r\n', '', $choice);
  1840. $choice = stripslashes($choice);
  1841. $questionScore = Database::result($resq,0,"marks");
  1842. if ($questionScore==-1) {
  1843. $totalScore+=0;
  1844. } else {
  1845. $totalScore+=$questionScore;
  1846. }
  1847. $arrques[] = $questionName;
  1848. $arrans[] = $choice;
  1849. } else {
  1850. $studentChoice = $choice;
  1851. if ($studentChoice) {
  1852. //Fixing negative puntation see #2193
  1853. $questionScore = 0;
  1854. $totalScore += 0;
  1855. }
  1856. }
  1857. break;
  1858. // for matching
  1859. case MATCHING :
  1860. if ($from_database) {
  1861. $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.$questionId.'" AND correct=0';
  1862. $res_answer = Database::query($sql_answer);
  1863. // getting the real answer
  1864. $real_list =array();
  1865. while ($real_answer = Database::fetch_array($res_answer)) {
  1866. $real_list[$real_answer['id']]= $real_answer['answer'];
  1867. }
  1868. $sql_select_answer = 'SELECT id, answer, correct, id_auto FROM '.$table_ans.'
  1869. WHERE question_id="'.$questionId.'" AND correct <> 0 ORDER BY id_auto';
  1870. $res_answers = Database::query($sql_select_answer);
  1871. $questionScore = 0;
  1872. while ($a_answers = Database::fetch_array($res_answers)) {
  1873. $i_answer_id = $a_answers['id']; //3
  1874. $s_answer_label = $a_answers['answer']; // your daddy - your mother
  1875. $i_answer_correct_answer = $a_answers['correct']; //1 - 2
  1876. $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4
  1877. $sql_user_answer = "SELECT answer FROM $TBL_TRACK_ATTEMPT
  1878. WHERE exe_id = '$exeId' AND question_id = '$questionId' AND position='$i_answer_id_auto'";
  1879. $res_user_answer = Database::query($sql_user_answer);
  1880. if (Database::num_rows($res_user_answer)>0 ) {
  1881. $s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking
  1882. } else {
  1883. $s_user_answer = 0;
  1884. }
  1885. $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
  1886. $user_answer = '';
  1887. if (!empty($s_user_answer)) {
  1888. if ($s_user_answer == $i_answer_correct_answer) {
  1889. $questionScore += $i_answerWeighting;
  1890. $totalScore += $i_answerWeighting;
  1891. $user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
  1892. } else {
  1893. $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
  1894. }
  1895. }
  1896. if ($show_result) {
  1897. echo '<tr>';
  1898. echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
  1899. echo '</tr>';
  1900. }
  1901. }
  1902. break(2); //break the switch and the "for" condition
  1903. } else {
  1904. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  1905. if ($answerCorrect) {
  1906. if ($answerCorrect == $choice[$numAnswer]) {
  1907. $questionScore += $answerWeighting;
  1908. $totalScore += $answerWeighting;
  1909. $user_answer = '<span>'.$answer_matching[$choice[$numAnswer]].'</span>';
  1910. } else {
  1911. $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$answer_matching[$choice[$numAnswer]].'</span>';
  1912. }
  1913. $matching[$numAnswer] = $choice[$numAnswer];
  1914. }
  1915. break;
  1916. }
  1917. // for hotspot with no order
  1918. case HOT_SPOT :
  1919. if ($from_database) {
  1920. if ($show_result) {
  1921. $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  1922. $query = "SELECT hotspot_correct FROM ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".$exeId."' and hotspot_question_id= '".$questionId."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
  1923. $resq=Database::query($query);
  1924. $studentChoice = Database::result($resq,0,"hotspot_correct");
  1925. }
  1926. } else {
  1927. $studentChoice = $choice[$answerId];
  1928. if ($studentChoice) {
  1929. $questionScore += $answerWeighting;
  1930. $totalScore += $answerWeighting;
  1931. }
  1932. }
  1933. break;
  1934. // @todo never added to chamilo
  1935. //for hotspot with fixed order
  1936. case HOT_SPOT_ORDER :
  1937. $studentChoice = $choice['order'][$answerId];
  1938. if ($studentChoice == $answerId) {
  1939. $questionScore += $answerWeighting;
  1940. $totalScore += $answerWeighting;
  1941. $studentChoice = true;
  1942. } else {
  1943. $studentChoice = false;
  1944. }
  1945. break;
  1946. } // end switch Answertype
  1947. global $origin;
  1948. if ($show_result) {
  1949. if ($from == 'exercise_result') {
  1950. //display answers (if not matching type, or if the answer is correct)
  1951. if ($answerType != MATCHING || $answerCorrect) {
  1952. if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION))) {
  1953. if ($origin!='learnpath') {
  1954. ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
  1955. }
  1956. } elseif($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  1957. if ($origin!='learnpath') {
  1958. ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,$questionId,0);
  1959. }
  1960. } elseif($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
  1961. if ($origin!='learnpath') {
  1962. ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0);
  1963. }
  1964. } elseif($answerType == FILL_IN_BLANKS) {
  1965. if ($origin!='learnpath') {
  1966. ExerciseShowFunctions::display_fill_in_blanks_answer($answer,0,0);
  1967. }
  1968. } elseif($answerType == FREE_ANSWER) {
  1969. // to store the details of open questions in an array to be used in mail
  1970. $arrques[] = $questionName;
  1971. $arrans[] = $choice;
  1972. if($origin != 'learnpath') {
  1973. ExerciseShowFunctions::display_free_answer($choice,0,0);
  1974. }
  1975. } elseif($answerType == HOT_SPOT) {
  1976. if ($origin != 'learnpath') {
  1977. ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  1978. }
  1979. } elseif($answerType == HOT_SPOT_ORDER) {
  1980. ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  1981. } elseif($answerType==MATCHING) {
  1982. if ($origin != 'learnpath') {
  1983. echo '<tr>';
  1984. echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter($user_answer).' / <b><span style="color: #008000;">'.text_filter($answer_matching[$answerCorrect]).'</span></b></td>';
  1985. echo '</tr>';
  1986. }
  1987. }
  1988. }
  1989. } else {
  1990. switch($answerType) {
  1991. case UNIQUE_ANSWER :
  1992. case UNIQUE_ANSWER_NO_OPTION:
  1993. case MULTIPLE_ANSWER :
  1994. case MULTIPLE_ANSWER_COMBINATION :
  1995. if ($answerId==1) {
  1996. ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
  1997. } else {
  1998. ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
  1999. }
  2000. break;
  2001. case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
  2002. if ($answerId==1) {
  2003. ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
  2004. } else {
  2005. ExerciseShowFunctions::display_multiple_answer_combination_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
  2006. }
  2007. break;
  2008. case MULTIPLE_ANSWER_TRUE_FALSE :
  2009. if ($answerId==1) {
  2010. ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId);
  2011. } else {
  2012. ExerciseShowFunctions::display_multiple_answer_true_false($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"");
  2013. }
  2014. break;
  2015. case FILL_IN_BLANKS:
  2016. echo '<tr><td>';
  2017. ExerciseShowFunctions::display_fill_in_blanks_answer($answer,$exeId,$questionId);
  2018. echo '</td></tr>';
  2019. break;
  2020. case FREE_ANSWER:
  2021. echo '<tr>
  2022. <td valign="top">'.ExerciseShowFunctions::display_free_answer($choice, $exeId, $questionId).'</td>
  2023. </tr>
  2024. </table>';
  2025. break;
  2026. case HOT_SPOT:
  2027. ExerciseShowFunctions::display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
  2028. break;
  2029. case HOT_SPOT_ORDER:
  2030. ExerciseShowFunctions::display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
  2031. break;
  2032. case MATCHING:
  2033. if ($origin != 'learnpath') {
  2034. echo '<tr>';
  2035. echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter($user_answer).' / <b><span style="color: #008000;">'.text_filter($answer_matching[$answerCorrect]).'</span></b></td>';
  2036. echo '</tr>';
  2037. }
  2038. break;
  2039. }
  2040. }
  2041. }
  2042. } // end for that loops over all answers of the current question
  2043. // destruction of Answer
  2044. if (!$saved_results && $answerType == HOT_SPOT) {
  2045. $queryfree = "SELECT marks FROM ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($exeId)."' and question_id= '".Database::escape_string($questionId)."'";
  2046. $resfree = Database::query($queryfree);
  2047. $questionScore = Database::result($resfree,0,"marks");
  2048. }
  2049. $final_answer = true;
  2050. foreach($real_answers as $my_answer) {
  2051. if (!$my_answer) {
  2052. $final_answer = false;
  2053. }
  2054. }
  2055. //we add the total score after dealing with the answers
  2056. if ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
  2057. if ($final_answer) {
  2058. //getting only the first score where we save the weight of all the question
  2059. $answerWeighting = $objAnswerTmp->selectWeighting(1);
  2060. $questionScore += $answerWeighting;
  2061. $totalScore += $answerWeighting;
  2062. }
  2063. }
  2064. if ($from == 'exercise_result') {
  2065. // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
  2066. // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
  2067. if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  2068. // We made an extra table for the answers
  2069. if ($show_result) {
  2070. if ($origin != 'learnpath') {
  2071. echo '</table></td></tr>';
  2072. echo '<tr>
  2073. <td colspan="2">';
  2074. echo '<i>'.get_lang('HotSpot').'</i><br /><br />';
  2075. echo '<object type="application/x-shockwave-flash" data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id=&from_db=0" width="552" height="352">';
  2076. echo '<param name="movie" value="'.api_get_path(WEB_PLUGIN_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id=&from_db=0" />
  2077. </object>
  2078. </td>
  2079. </tr>';
  2080. }
  2081. }
  2082. }
  2083. if ($origin != 'learnpath') {
  2084. if ($show_result) {
  2085. echo '</table>';
  2086. if ($this->type == ALL_ON_ONE_PAGE) {
  2087. echo '<div id="question_score">';
  2088. if ($propagate_neg == 0 && $questionScore < 0) {
  2089. $questionScore = 0;
  2090. }
  2091. echo get_lang('Score').": ".show_score($questionScore, $questionWeighting, false, false);
  2092. echo '</div>';
  2093. }
  2094. echo '<br />';
  2095. }
  2096. }
  2097. }
  2098. unset ($objAnswerTmp);
  2099. $i++;
  2100. $totalWeighting += $questionWeighting;
  2101. // Store results directly in the database
  2102. // For all in one page exercises, the results will be
  2103. // stored by exercise_results.php (using the session)
  2104. if ($saved_results) {
  2105. if (empty ($choice)) {
  2106. $choice = 0;
  2107. }
  2108. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
  2109. if ($choice != 0) {
  2110. $reply = array_keys($choice);
  2111. for ($i = 0; $i < sizeof($reply); $i++) {
  2112. $ans = $reply[$i];
  2113. exercise_attempt($questionScore, $ans.':'.$choice[$ans], $quesId, $exeId, $i, $this->id);
  2114. }
  2115. } else {
  2116. exercise_attempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
  2117. }
  2118. } elseif ($answerType == MULTIPLE_ANSWER) {
  2119. if ($choice != 0) {
  2120. $reply = array_keys($choice);
  2121. for ($i = 0; $i < sizeof($reply); $i++) {
  2122. $ans = $reply[$i];
  2123. exercise_attempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
  2124. }
  2125. } else {
  2126. exercise_attempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
  2127. }
  2128. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
  2129. if ($choice != 0) {
  2130. $reply = array_keys($choice);
  2131. for ($i = 0; $i < sizeof($reply); $i++) {
  2132. $ans = $reply[$i];
  2133. exercise_attempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
  2134. }
  2135. } else {
  2136. exercise_attempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
  2137. }
  2138. } elseif ($answerType == MATCHING) {
  2139. foreach ($matching as $j => $val) {
  2140. exercise_attempt($questionScore, $val, $quesId, $exeId, $j, $this->id);
  2141. }
  2142. } elseif ($answerType == FREE_ANSWER) {
  2143. $answer = $choice;
  2144. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
  2145. } elseif ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
  2146. $answer = $choice;
  2147. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
  2148. } elseif ($answerType == HOT_SPOT) {
  2149. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
  2150. if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) {
  2151. foreach($exerciseResultCoordinates[$questionId] as $idx => $val) {
  2152. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val,$this->id);
  2153. }
  2154. }
  2155. } else {
  2156. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0,$this->id);
  2157. }
  2158. }
  2159. if ($saved_results) {
  2160. $stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  2161. $sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . floatval($totalScore) . ',exe_weighting = exe_weighting + ' . floatval($totalWeighting) . ' WHERE exe_id = ' . $exeId;
  2162. Database::query($sql_update);
  2163. }
  2164. if ($propagate_neg == 0 && $questionScore < 0) {
  2165. $questionScore = 0;
  2166. }
  2167. $return_array = array('score'=>$questionScore, 'weight'=>$questionWeighting);
  2168. return $return_array;
  2169. } //End function
  2170. function send_notification($arrques, $arrans) {
  2171. // Email configuration settings
  2172. $coursecode = api_get_course_id();
  2173. $course_info = api_get_course_info(api_get_course_id());
  2174. $to = '';
  2175. $teachers = array();
  2176. if (api_get_session_id()) {
  2177. $teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
  2178. } else {
  2179. $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
  2180. }
  2181. $num = count($teachers);
  2182. if($num>1) {
  2183. $to = array();
  2184. foreach($teachers as $teacher) {
  2185. $to[] = $teacher['email'];
  2186. }
  2187. } elseif ($num>0){
  2188. foreach($teachers as $teacher) {
  2189. $to = $teacher['email'];
  2190. }
  2191. } else {
  2192. //this is a problem (it means that there is no admin for this course)
  2193. }
  2194. global $courseName, $exerciseTitle, $url_email;
  2195. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  2196. $user_info = UserManager::get_user_info_by_id(api_get_user_id());
  2197. if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
  2198. return '';
  2199. }
  2200. $mycharset = api_get_system_encoding();
  2201. $msg = '<html><head>
  2202. <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
  2203. <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type"></head>';
  2204. if(count($arrques)>0) {
  2205. $msg .= '<body>
  2206. <p>'.get_lang('OpenQuestionsAttempted').' :
  2207. </p>
  2208. <p>'.get_lang('AttemptDetails').' : <br />
  2209. </p>
  2210. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  2211. <tr>
  2212. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  2213. <td width="469" valign="top"><h2>#course#</h2></td>
  2214. </tr>
  2215. <tr>
  2216. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  2217. <td width="469" valign="top" class="outerframe">#exercise#</td>
  2218. </tr>
  2219. <tr>
  2220. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  2221. <td valign="top" >#firstName# #lastName#</td>
  2222. </tr>
  2223. <tr>
  2224. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  2225. <td valign="top"> #mail#</td>
  2226. </tr></table>
  2227. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  2228. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  2229. for($i=0;$i<sizeof($arrques);$i++) {
  2230. $msg.='
  2231. <tr>
  2232. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  2233. <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
  2234. </tr>
  2235. <tr>
  2236. <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  2237. <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
  2238. </tr>';
  2239. $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
  2240. $msg= str_replace("#firstName#",$user_info['firstname'],$msg1);
  2241. $msg1= str_replace("#lastName#",$user_info['lastname'],$msg);
  2242. $msg= str_replace("#mail#",$user_info['email'],$msg1);
  2243. $msg1= str_replace("#questionName#",$arrques[$i],$msg);
  2244. $msg= str_replace("#answer#",$arrans[$i],$msg1);
  2245. $msg1= str_replace("#i#",$i,$msg);
  2246. $msg= str_replace("#course#",$courseName,$msg1);
  2247. }
  2248. $msg.='</table><br>
  2249. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  2250. <a href="#url#">#url#</a></span></body></html>';
  2251. $msg1= str_replace("#url#",$url_email,$msg);
  2252. $mail_content = $msg1;
  2253. $subject = get_lang('OpenQuestionsAttempted');
  2254. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  2255. $email_admin = api_get_setting('emailAdministrator');
  2256. $result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
  2257. } else {
  2258. $msg .= '<body>
  2259. <p>'.get_lang('ExerciseAttempted').' <br />
  2260. </p>
  2261. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  2262. <tr>
  2263. <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  2264. <td width="469" valign="top"><h2>#course#</h2></td>
  2265. </tr>
  2266. <tr>
  2267. <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  2268. <td width="469" valign="top" class="outerframe">#exercise#</td>
  2269. </tr>
  2270. <tr>
  2271. <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  2272. '.(api_is_western_name_order() ? '<td valign="top" >#firstName# #lastName#</td>' : '<td valign="top" >#lastName# #firstName#</td>').'
  2273. </tr>
  2274. <tr>
  2275. <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  2276. <td valign="top"> #mail#</td>
  2277. </tr></table>';
  2278. $msg= str_replace("#exercise#",$exerciseTitle,$msg);
  2279. $msg= str_replace("#firstName#",$user_info['firstname'],$msg);
  2280. $msg= str_replace("#lastName#",$user_info['lastname'],$msg);
  2281. $msg= str_replace("#mail#",$user_info['email'],$msg);
  2282. $msg= str_replace("#course#",$courseName,$msg);
  2283. $msg.='<br />
  2284. <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  2285. <a href="#url#">#url#</a></span></body></html>';
  2286. $msg= str_replace("#url#",$url_email,$msg);
  2287. $mail_content = $msg;
  2288. $sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
  2289. $email_admin = api_get_setting('emailAdministrator');
  2290. $subject = get_lang('ExerciseAttempted');
  2291. $result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
  2292. }
  2293. }
  2294. function show_exercise_result_header($user_data, $date = null) {
  2295. $description = '';
  2296. if (!empty($this->description)) {
  2297. $description = '<tr>
  2298. <td style="font-weight:bold" width="10%">
  2299. &nbsp;'.get_lang("Description").' :
  2300. </td>
  2301. <td width="90%">
  2302. '.$this->description.'
  2303. </td>
  2304. </tr>';
  2305. }
  2306. $date_data = '';
  2307. if (!empty($date)) {
  2308. $date_data = '<tr>
  2309. <td style="font-weight:bold" width="10%">
  2310. &nbsp;'.get_lang("Date").' :
  2311. </td>
  2312. <td width="90%">
  2313. '.$date.'
  2314. </td>
  2315. </tr>';
  2316. }
  2317. $html = '<table width="100%">
  2318. <tr>
  2319. <td colspan="2">
  2320. <h2>'.Display::return_icon('quiz_big.png', get_lang('Result')).' '.$this->exercise.' : '.get_lang('Result').'</h2>
  2321. </td>
  2322. </tr>
  2323. <tr>
  2324. <td style="font-weight:bold" width="90px">&nbsp;'.get_lang('User').' : </td>
  2325. <td>
  2326. '.$user_data.'
  2327. </td>
  2328. </tr>
  2329. '.$date_data.'
  2330. '.$description.'
  2331. </table>
  2332. <br />';
  2333. return $html;
  2334. }
  2335. /**
  2336. * Create a quiz from quiz data
  2337. * @param string Title
  2338. * @param int Time before it expires (in minutes)
  2339. * @param int Type of exercise
  2340. * @param int Whether it's randomly picked questions (1) or not (0)
  2341. * @param int Whether the exercise is visible to the user (1) or not (0)
  2342. * @param int Whether the results are show to the user (0) or not (1)
  2343. * @param int Maximum number of attempts (0 if no limit)
  2344. * @param int Feedback type
  2345. * @return int New exercise ID
  2346. */
  2347. function create_quiz ($title, $expired_time = 0, $type = 2, $random = 0, $active = 1, $results_disabled = 0, $max_attempt = 0, $feedback = 3) {
  2348. $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  2349. $expired_time = filter_var($expired_time,FILTER_SANITIZE_NUMBER_INT);
  2350. $type = filter_var($type,FILTER_SANITIZE_NUMBER_INT);
  2351. $random = filter_var($random,FILTER_SANITIZE_NUMBER_INT);
  2352. $active = filter_var($active,FILTER_SANITIZE_NUMBER_INT);
  2353. $results_disabled = filter_var($results_disabled,FILTER_SANITIZE_NUMBER_INT);
  2354. $max_attempt = filter_var($max_attempt,FILTER_SANITIZE_NUMBER_INT);
  2355. $feedback = filter_var($feedback,FILTER_SANITIZE_NUMBER_INT);
  2356. $sid = api_get_session_id();
  2357. // Save a new quiz
  2358. $sql = "INSERT INTO $tbl_quiz (title,type,random,active,results_disabled, ".
  2359. "max_attempt,start_time,end_time,feedback_type,expired_time, session_id) ".
  2360. " VALUES('".Database::escape_string($title)."',$type,$random,$active, ".
  2361. "$results_disabled,$max_attempt,'','',$feedback,$expired_time,$sid)";
  2362. $rs = Database::query($sql);
  2363. $quiz_id = Database::get_last_insert_id();
  2364. return $quiz_id;
  2365. }
  2366. }
  2367. endif;
  2368. ?>