answer_admin.inc.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // YW: 20110209: Script depredated?
  4. /**
  5. * This script allows to manage answers. It is included from the script admin.php
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert
  8. * @version $Id: answer_admin.inc.php 21361 2009-06-11 04:08:58Z ivantcholakov $
  9. */
  10. /**
  11. * Code
  12. */
  13. use \ChamiloSession as Session;
  14. // ALLOWED_TO_INCLUDE is defined in admin.php
  15. if (!defined('ALLOWED_TO_INCLUDE')) {
  16. exit();
  17. }
  18. if (!is_object($objQuestion)) {
  19. $objQuestion = Question :: read($_GET['modifyAnswers']);
  20. }
  21. $questionName = $objQuestion->selectTitle();
  22. $answerType = $objQuestion->selectType();
  23. $pictureName = $objQuestion->selectPicture();
  24. $debug = 0; // debug variable to get where we are
  25. $okPicture = empty($pictureName) ? false : true;
  26. // if we come from the warning box "this question is used in serveral exercises"
  27. if ($modifyIn) {
  28. if ($debug > 0) {
  29. echo '$modifyIn was set' . "<br />\n";
  30. }
  31. // if the user has chosed to modify the question only in the current exercise
  32. if ($modifyIn == 'thisExercise') {
  33. // duplicates the question
  34. $questionId = $objQuestion->duplicate();
  35. // deletes the old question
  36. $objQuestion->delete($exerciseId);
  37. // removes the old question ID from the question list of the Exercise object
  38. $objExercise->removeFromList($modifyAnswers);
  39. // adds the new question ID into the question list of the Exercise object
  40. $objExercise->addToList($questionId);
  41. // construction of the duplicated Question
  42. $objQuestion = Question::read($questionId);
  43. // adds the exercise ID into the exercise list of the Question object
  44. $objQuestion->addToList($exerciseId);
  45. // copies answers from $modifyAnswers to $questionId
  46. $objAnswer->duplicate($questionId);
  47. // construction of the duplicated Answers
  48. $objAnswer = new Answer($questionId);
  49. }
  50. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  51. $correct = unserialize($correct);
  52. $reponse = unserialize($reponse);
  53. $comment = unserialize($comment);
  54. $weighting = unserialize($weighting);
  55. } elseif ($answerType == MATCHING) {
  56. $option = unserialize($option);
  57. $match = unserialize($match);
  58. $sel = unserialize($sel);
  59. $weighting = unserialize($weighting);
  60. } elseif ($answerType == FREE_ANSWER) {
  61. $reponse = unserialize($reponse);
  62. $comment = unserialize($comment);
  63. $free_comment = $comment;
  64. $weighting = unserialize($weighting);
  65. } elseif ($answerType == ORAL_EXPRESSION) {
  66. $reponse = unserialize($reponse);
  67. $comment = unserialize($comment);
  68. $free_comment = $comment;
  69. $weighting = unserialize($weighting);
  70. } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION) {
  71. $color = unserialize($color);
  72. $reponse = unserialize($reponse);
  73. $comment = unserialize($comment);
  74. $weighting = unserialize($weighting);
  75. $hotspot_coordinates = unserialize($hotspot_coordinates);
  76. $hotspot_type = unserialize($hotspot_type);
  77. } else {
  78. //fill in blanks
  79. $reponse = unserialize($reponse);
  80. $comment = unserialize($comment);
  81. $blanks = unserialize($blanks);
  82. $weighting = unserialize($weighting);
  83. }
  84. unset($buttonBack);
  85. }
  86. // the answer form has been submitted
  87. if ($submitAnswers || $buttonBack) {
  88. if ($debug > 0) {
  89. echo '$submitAnswers or $buttonBack was set' . "<br />\n";
  90. }
  91. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  92. if ($debug > 0) {
  93. echo '&nbsp;&nbsp;$answerType is UNIQUE_ANSWER or MULTIPLE_ANSWER' . "<br />\n";
  94. }
  95. $questionWeighting = $nbrGoodAnswers = 0;
  96. for ($i = 1; $i <= $nbrAnswers; $i++) {
  97. $reponse[$i] = trim($reponse[$i]);
  98. $comment[$i] = trim($comment[$i]);
  99. $weighting[$i] = intval($weighting[$i]);
  100. if ($answerType == UNIQUE_ANSWER) {
  101. if ($debug > 0) {
  102. echo str_repeat('&nbsp;', 4) . '$answerType is UNIQUE_ANSWER' . "<br />\n";
  103. }
  104. $goodAnswer = ($correct == $i) ? 1 : 0;
  105. } else {
  106. $goodAnswer = $correct[$i];
  107. }
  108. if ($goodAnswer) {
  109. $nbrGoodAnswers++;
  110. // a good answer can't have a negative weighting
  111. $weighting[$i] = abs($weighting[$i]);
  112. // calculates the sum of answer weighting only if it is different from 0 and the answer is good
  113. if ($weighting[$i]) {
  114. $questionWeighting+=$weighting[$i];
  115. }
  116. } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  117. if ($debug > 0) {
  118. echo str_repeat('&nbsp;', 4) . '$answerType is MULTIPLE_ANSWER' . "<br />\n";
  119. }
  120. // a bad answer can't have a positive weighting
  121. $weighting[$i] = 0 - abs($weighting[$i]);
  122. }
  123. // checks if field is empty
  124. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  125. $msgErr = get_lang('GiveAnswers');
  126. // clears answers already recorded into the Answer object
  127. $objAnswer->cancel();
  128. break;
  129. } else {
  130. // adds the answer into the object
  131. $objAnswer->createAnswer($reponse[$i], $goodAnswer, $comment[$i], $weighting[$i], $i);
  132. //added
  133. //if($_REQUEST['myid']==1)
  134. $mainurl = "admin.php";
  135. // else
  136. // $mainurl="question_pool.php";
  137. ?>
  138. <script>
  139. window.location.href='<?php echo $mainurl; ?>';
  140. </script>
  141. <?php
  142. }
  143. } // end for()
  144. if (empty($msgErr)) {
  145. if (!$nbrGoodAnswers) {
  146. $msgErr = ($answerType == UNIQUE_ANSWER) ? get_lang('ChooseGoodAnswer') : get_lang('ChooseGoodAnswers');
  147. // clears answers already recorded into the Answer object
  148. $objAnswer->cancel();
  149. }
  150. // checks if the question is used in several exercises
  151. elseif ($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) {
  152. $usedInSeveralExercises = 1;
  153. } else {
  154. // saves the answers into the data base
  155. $objAnswer->save();
  156. // sets the total weighting of the question
  157. $objQuestion->updateWeighting($questionWeighting);
  158. $objQuestion->save($exerciseId);
  159. $editQuestion = $questionId;
  160. unset($modifyAnswers);
  161. }
  162. }
  163. } elseif ($answerType == FILL_IN_BLANKS) {
  164. if ($debug > 0) {
  165. echo str_repeat('&nbsp;', 2) . '$answerType is FILL_IN_BLANKS' . "<br />\n";
  166. }
  167. $reponse = trim($reponse);
  168. if (!$buttonBack) {
  169. if ($debug > 0) {
  170. echo str_repeat('&nbsp;', 4) . '$buttonBack is not set' . "<br />\n";
  171. }
  172. if ($setWeighting) {
  173. $blanks = unserialize($blanks);
  174. // checks if the question is used in several exercises
  175. if ($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) {
  176. $usedInSeveralExercises = 1;
  177. } else {
  178. // separates text and weightings by '::'
  179. $reponse.='::';
  180. $questionWeighting = 0;
  181. foreach ($weighting as $val) {
  182. // a blank can't have a negative weighting
  183. $val = abs($val);
  184. $questionWeighting+=$val;
  185. // adds blank weighting at the end of the text
  186. $reponse.=$val . ',';
  187. }
  188. $reponse = api_substr($reponse, 0, -1);
  189. $objAnswer->createAnswer($reponse, 0, '', 0, '');
  190. $objAnswer->save();
  191. //added
  192. //if($_REQUEST['myid']==1)
  193. $mainurl = "admin.php";
  194. // else
  195. // $mainurl="question_pool.php";
  196. ?>
  197. <script>
  198. window.location.href='<?php echo $mainurl; ?>';
  199. </script>
  200. <?php
  201. // sets the total weighting of the question
  202. $objQuestion->updateWeighting($questionWeighting);
  203. $objQuestion->save($exerciseId);
  204. $editQuestion = $questionId;
  205. unset($modifyAnswers);
  206. }
  207. }
  208. // if no text has been typed or the text contains no blank
  209. elseif (empty($reponse)) {
  210. $msgErr = get_lang('GiveText');
  211. } elseif (!api_ereg('\[.+\]', $reponse)) {
  212. $msgErr = get_lang('DefineBlanks');
  213. } else {
  214. // now we're going to give a weighting to each blank
  215. $setWeighting = 1;
  216. unset($submitAnswers);
  217. // removes character '::' possibly inserted by the user in the text
  218. $reponse = str_replace('::', '', $reponse);
  219. // we save the answer because it will be modified
  220. //$temp=$reponse;
  221. $temp = text_filter($reponse);
  222. /* // Deprecated code.
  223. // 1. find everything between the [tex] and [/tex] tags
  224. $startlocations=api_strpos($temp,'[tex]');
  225. $endlocations=api_strpos($temp,'[/tex]');
  226. if($startlocations !== false && $endlocations !== false)
  227. {
  228. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  229. // 2. replace this by {texcode}
  230. $temp=str_replace($texstring,"{texcode}",$temp);
  231. }
  232. */
  233. // blanks will be put into an array
  234. $blanks = array();
  235. $i = 1;
  236. // the loop will stop at the end of the text
  237. while (1) {
  238. // quits the loop if there are no more blanks
  239. if (($pos = api_strpos($temp, '[')) === false) {
  240. break;
  241. }
  242. // removes characters till '['
  243. $temp = api_substr($temp, $pos + 1);
  244. // quits the loop if there are no more blanks
  245. if (($pos = api_strpos($temp, ']')) === false) {
  246. break;
  247. }
  248. // stores the found blank into the array
  249. $blanks[$i++] = api_substr($temp, 0, $pos);
  250. // removes the character ']'
  251. $temp = api_substr($temp, $pos + 1);
  252. }
  253. }
  254. } else {
  255. unset($setWeighting);
  256. }
  257. } elseif ($answerType == FREE_ANSWER) {
  258. if ($debug > 0) {
  259. echo str_repeat('&nbsp;', 2) . '$answerType is FREE_ANSWER' . "<br />\n";
  260. }
  261. if (empty($free_comment)) {
  262. $free_comment = $_POST['comment'];
  263. }
  264. if (empty($weighting)) {
  265. $weighting = $_POST['weighting'];
  266. $weightingtemp = $_POST['weighting'];
  267. }
  268. if (!$buttonBack) {
  269. if ($debug > 0) {
  270. echo str_repeat('&nbsp;', 4) . '$buttonBack is not set' . "<br />\n";
  271. }
  272. if ($setWeighting) {
  273. if ($debug > 0) {
  274. echo str_repeat('&nbsp;', 6) . '$setWeighting is set' . "<br />\n";
  275. }
  276. // checks if the question is used in several exercises
  277. if ($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) {
  278. $usedInSeveralExercises = 1;
  279. } else {
  280. $objAnswer->createAnswer('', 0, $free_comment, $weighting, '');
  281. $objAnswer->save();
  282. // sets the total weighting of the question
  283. $objQuestion->updateWeighting($weighting);
  284. $objQuestion->save($exerciseId);
  285. $editQuestion = $questionId;
  286. unset($modifyAnswers); //added
  287. //if($_REQUEST['myid']==1)
  288. $mainurl = "admin.php";
  289. // else
  290. // $mainurl="question_pool.php";
  291. ?>
  292. <script>
  293. window.location.href='<?php echo $mainurl; ?>';
  294. </script>
  295. <?php
  296. }
  297. }
  298. // if no text has been typed or the text contains no blank
  299. elseif (empty($free_comment)) {
  300. if ($debug > 0) {
  301. echo str_repeat('&nbsp;', 6) . '$free_comment is empty' . "<br />\n";
  302. }
  303. $msgErr = get_lang('GiveText');
  304. }
  305. /* elseif(!ereg('\[.+\]',$reponse))
  306. {
  307. $msgErr=get_lang('DefineBlanks');
  308. } */ else {
  309. if ($debug > 0) {
  310. echo str_repeat('&nbsp;', 6) . '$setWeighting is not set and $free_comment is not empty' . "<br />\n";
  311. }
  312. // now we're going to give a weighting to each blank
  313. $setWeighting = 1;
  314. unset($submitAnswers);
  315. }
  316. } else {
  317. unset($setWeighting);
  318. }
  319. } elseif ($answerType == MATCHING) {
  320. if ($debug > 0) {
  321. echo str_repeat('&nbsp;', 2) . '$answerType is MATCHING' . "<br />\n";
  322. }
  323. for ($i = 1; $i <= $nbrOptions; $i++) {
  324. $option[$i] = trim($option[$i]);
  325. // checks if field is empty
  326. if (empty($option[$i]) && $option[$i] != '0') {
  327. $msgErr = get_lang('FillLists');
  328. // clears options already recorded into the Answer object
  329. $objAnswer->cancel();
  330. break;
  331. } else {
  332. // adds the option into the object
  333. $objAnswer->createAnswer($option[$i], 0, '', 0, $i);
  334. }
  335. }
  336. $questionWeighting = 0;
  337. if (empty($msgErr)) {
  338. for ($j = 1; $j <= $nbrMatches; $i++, $j++) {
  339. $match[$i] = trim($match[$i]);
  340. $weighting[$i] = abs(intval($weighting[$i]));
  341. $questionWeighting+=$weighting[$i];
  342. // checks if field is empty
  343. if (empty($match[$i]) && $match[$i] != '0') {
  344. $msgErr = get_lang('FillLists');
  345. // clears matches already recorded into the Answer object
  346. $objAnswer->cancel();
  347. break;
  348. }
  349. // check if correct number
  350. else {
  351. // adds the answer into the object
  352. $objAnswer->createAnswer($match[$i], $sel[$i], '', $weighting[$i], $i);
  353. //added
  354. //if($_REQUEST['myid']==1)
  355. $mainurl = "admin.php";
  356. //else
  357. //$mainurl="question_pool.php";
  358. ?>
  359. <script>
  360. window.location.href='<?php echo $mainurl; ?>';
  361. </script>
  362. <?php
  363. }
  364. }
  365. }
  366. if (empty($msgErr)) {
  367. // checks if the question is used in several exercises
  368. if ($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) {
  369. $usedInSeveralExercises = 1;
  370. } else {
  371. // all answers have been recorded, so we save them into the data base
  372. $objAnswer->save();
  373. // sets the total weighting of the question
  374. $objQuestion->updateWeighting($questionWeighting);
  375. $objQuestion->save($exerciseId);
  376. $editQuestion = $questionId;
  377. unset($modifyAnswers);
  378. }
  379. }
  380. } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  381. $questionWeighting = $nbrGoodAnswers = 0;
  382. for ($i = 1; $i <= $nbrAnswers; $i++) {
  383. if ($debug > 0) {
  384. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  385. }
  386. $reponse[$i] = trim($reponse[$i]);
  387. $comment[$i] = trim($comment[$i]);
  388. $weighting[$i] = intval($weighting[$i]);
  389. // checks if field is empty
  390. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  391. $msgErr = get_lang('HotspotGiveAnswers');
  392. // clears answers already recorded into the Answer object
  393. $objAnswer->cancel();
  394. break;
  395. }
  396. if ($weighting[$i] <= 0) {
  397. $msgErr = get_lang('HotspotWeightingError');
  398. // clears answers already recorded into the Answer object
  399. $objAnswer->cancel();
  400. break;
  401. }
  402. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  403. $msgErr = get_lang('HotspotNotDrawn');
  404. // clears answers already recorded into the Answer object
  405. $objAnswer->cancel();
  406. break;
  407. }
  408. } // end for()
  409. if (empty($msgErr)) {
  410. if ($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1) {
  411. $usedInSeveralExercises = 1;
  412. } else {
  413. for ($i = 1; $i <= $nbrAnswers; $i++) {
  414. if ($debug > 0) {
  415. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  416. }
  417. $reponse[$i] = trim($reponse[$i]);
  418. $comment[$i] = trim($comment[$i]);
  419. $weighting[$i] = intval($weighting[$i]);
  420. if ($weighting[$i]) {
  421. $questionWeighting+=$weighting[$i];
  422. }
  423. // creates answer
  424. $objAnswer->createAnswer($reponse[$i], '', $comment[$i], $weighting[$i], $i, $hotspot_coordinates[$i], $hotspot_type[$i]);
  425. } // end for()
  426. // saves the answers into the data base
  427. $objAnswer->save();
  428. // sets the total weighting of the question
  429. $objQuestion->updateWeighting($questionWeighting);
  430. $objQuestion->save($exerciseId);
  431. $editQuestion = $questionId;
  432. unset($modifyAnswers);
  433. }
  434. }
  435. }
  436. if ($debug > 0) {
  437. echo '$modifyIn was set - end' . "<br />\n";
  438. }
  439. }
  440. if ($modifyAnswers) {
  441. if ($debug > 0) {
  442. echo str_repeat('&nbsp;', 0) . '$modifyAnswers is set' . "<br />\n";
  443. }
  444. // construction of the Answer object
  445. $objAnswer = new Answer($questionId);
  446. Session::write('objAnswer', $objAnswer);
  447. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  448. if ($debug > 0) {
  449. echo str_repeat('&nbsp;', 2) . '$answerType is UNIQUE_ANSWER or MULTIPLE_ANSWER' . "<br />\n";
  450. }
  451. if (!$nbrAnswers) {
  452. $nbrAnswers = $objAnswer->selectNbrAnswers();
  453. $reponse = array();
  454. $comment = array();
  455. $weighting = array();
  456. // initializing + Modification de la ligne suivante
  457. if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  458. $correct = array();
  459. } else {
  460. $correct = 0;
  461. }
  462. for ($i = 1; $i <= $nbrAnswers; $i++) {
  463. $reponse[$i] = $objAnswer->selectAnswer($i);
  464. $comment[$i] = $objAnswer->selectComment($i);
  465. $weighting[$i] = $objAnswer->selectWeighting($i);
  466. if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  467. $correct[$i] = $objAnswer->isCorrect($i);
  468. } elseif ($objAnswer->isCorrect($i)) {
  469. $correct = $i;
  470. }
  471. }
  472. }
  473. if ($lessAnswers) {
  474. $nbrAnswers--;
  475. }
  476. if ($moreAnswers) {
  477. $nbrAnswers++;
  478. }
  479. // minimum 2 answers
  480. if ($nbrAnswers < 2) {
  481. $nbrAnswers = 2;
  482. }
  483. } elseif ($answerType == FILL_IN_BLANKS) {
  484. if ($debug > 0) {
  485. echo str_repeat('&nbsp;', 2) . '$answerType is FILL_IN_BLANKS' . "<br />\n";
  486. }
  487. if (!$submitAnswers && !$buttonBack) {
  488. if (!$setWeighting) {
  489. $reponse = $objAnswer->selectAnswer(1);
  490. list($reponse, $weighting) = explode('::', $reponse);
  491. $weighting = explode(',', $weighting);
  492. $temp = array();
  493. // keys of the array go from 1 to N and not from 0 to N-1
  494. for ($i = 0; $i < sizeof($weighting); $i++) {
  495. $temp[$i + 1] = $weighting[$i];
  496. }
  497. $weighting = $temp;
  498. } elseif (!$modifyIn) {
  499. $weighting = unserialize($weighting);
  500. }
  501. }
  502. } elseif ($answerType == FREE_ANSWER) {
  503. if ($debug > 0) {
  504. echo str_repeat('&nbsp;', 2) . '$answerType is FREE_ANSWER' . "<br />\n";
  505. }
  506. if (!$submitAnswers && !$buttonBack) {
  507. if ($debug > 0) {
  508. echo str_repeat('&nbsp;', 4) . '$submitAnswers && $buttonsBack are unset' . "<br />\n";
  509. }
  510. if (!$setWeighting) {
  511. if ($debug > 0) {
  512. echo str_repeat('&nbsp;', 6) . '$setWeighting is unset' . "<br />\n";
  513. }
  514. //YW: not quite sure about whether the comment has already been recovered,
  515. // but as we have passed into the submitAnswers loop, this should be in the
  516. // objAnswer object.
  517. $free_comment = $objAnswer->selectComment(1);
  518. $weighting = $objAnswer->selectWeighting(1); //added
  519. } elseif (!$modifyIn) {
  520. if ($debug > 0) {
  521. echo str_repeat('&nbsp;', 6) . '$setWeighting is set and $modifyIn is unset' . "<br />\n";
  522. }
  523. $weighting = unserialize($weighting);
  524. }
  525. }
  526. } elseif ($answerType == MATCHING) {
  527. if ($debug > 0) {
  528. echo str_repeat('&nbsp;', 2) . '$answerType is MATCHING' . "<br />\n";
  529. }
  530. if (!$nbrOptions || !$nbrMatches) {
  531. $option = array();
  532. $match = array();
  533. $sel = array();
  534. $nbrOptions = $nbrMatches = 0;
  535. // fills arrays with data from de data base
  536. for ($i = 1; $i <= $objAnswer->selectNbrAnswers(); $i++) {
  537. // it is a match
  538. if ($objAnswer->isCorrect($i)) {
  539. $match[$i] = $objAnswer->selectAnswer($i);
  540. $sel[$i] = $objAnswer->isCorrect($i);
  541. $weighting[$i] = $objAnswer->selectWeighting($i);
  542. $nbrMatches++;
  543. }
  544. // it is an option
  545. else {
  546. $option[$i] = $objAnswer->selectAnswer($i);
  547. $nbrOptions++;
  548. }
  549. }
  550. }
  551. if ($lessOptions) {
  552. // keeps the correct sequence of array keys when removing an option from the list
  553. for ($i = $nbrOptions + 1, $j = 1; $nbrOptions > 2 && $j <= $nbrMatches; $i++, $j++) {
  554. $match[$i - 1] = $match[$i];
  555. $sel[$i - 1] = $sel[$i];
  556. $weighting[$i - 1] = $weighting[$i];
  557. }
  558. unset($match[$i - 1]);
  559. unset($sel[$i - 1]);
  560. $nbrOptions--;
  561. }
  562. if ($moreOptions) {
  563. // keeps the correct sequence of array keys when adding an option into the list
  564. for ($i = $nbrMatches + $nbrOptions; $i > $nbrOptions; $i--) {
  565. $match[$i + 1] = $match[$i];
  566. $sel[$i + 1] = $sel[$i];
  567. $weighting[$i + 1] = $weighting[$i];
  568. }
  569. unset($match[$i + 1]);
  570. unset($sel[$i + 1]);
  571. $nbrOptions++;
  572. }
  573. if ($lessMatches) {
  574. $nbrMatches--;
  575. }
  576. if ($moreMatches) {
  577. $nbrMatches++;
  578. }
  579. // minimum 2 options
  580. if ($nbrOptions < 2) {
  581. $nbrOptions = 2;
  582. }
  583. // minimum 2 matches
  584. if ($nbrMatches < 2) {
  585. $nbrMatches = 2;
  586. }
  587. } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  588. if ($debug > 0) {
  589. echo str_repeat('&nbsp;', 2) . '$answerType is HOT_SPOT' . "<br />\n";
  590. }
  591. if (!$nbrAnswers) {
  592. $nbrAnswers = $objAnswer->selectNbrAnswers();
  593. $reponse = array();
  594. $comment = array();
  595. $weighting = array();
  596. $hotspot_coordinates = array();
  597. $hotspot_type = array();
  598. for ($i = 1; $i <= $nbrAnswers; $i++) {
  599. $reponse[$i] = $objAnswer->selectAnswer($i);
  600. $comment[$i] = $objAnswer->selectComment($i);
  601. $weighting[$i] = $objAnswer->selectWeighting($i);
  602. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($i);
  603. $hotspot_type[$i] = $objAnswer->selectHotspotType($i);
  604. }
  605. }
  606. $_SESSION['tmp_answers'] = array();
  607. $_SESSION['tmp_answers']['answer'] = $reponse;
  608. $_SESSION['tmp_answers']['comment'] = $comment;
  609. $_SESSION['tmp_answers']['weighting'] = $weighting;
  610. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  611. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  612. if ($lessAnswers) {
  613. // At least 1 answer
  614. if ($nbrAnswers > 1) {
  615. $nbrAnswers--;
  616. // Remove the last answer
  617. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  618. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  619. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  620. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  621. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  622. } else {
  623. $msgErr = get_lang('MinHotspot');
  624. }
  625. }
  626. if ($moreAnswers) {
  627. if ($nbrAnswers < 12) {
  628. $nbrAnswers++;
  629. // Add a new answer
  630. $_SESSION['tmp_answers']['answer'][] = '';
  631. $_SESSION['tmp_answers']['comment'][] = '';
  632. $_SESSION['tmp_answers']['weighting'][] = '1';
  633. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  634. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  635. } else {
  636. $msgErr = get_lang('MaxHotspot');
  637. }
  638. }
  639. }
  640. if (!$usedInSeveralExercises) {
  641. if ($debug > 0) {
  642. echo str_repeat('&nbsp;', 2) . '$usedInSeveralExercises is untrue' . "<br />\n";
  643. }
  644. if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == GLOBAL_MULTIPLE_ANSWER) {
  645. if ($debug > 0) {
  646. echo str_repeat('&nbsp;', 4) . '$answerType is UNIQUE_ANSWER or MULTIPLE_ANSWER' . "<br />\n";
  647. }
  648. ?>
  649. <h3>
  650. <?php echo $questionName; ?>
  651. </h3>
  652. <?php
  653. /* if ($exerciseId==0){
  654. ?>
  655. <form method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>">
  656. <?php }
  657. else
  658. {
  659. ?>
  660. <form method="post" action="<?php echo api_get_self(); ?>?exerciseId=<?php echo $exerciseId; ?>">
  661. <?php
  662. } */
  663. ?>
  664. <form method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>">
  665. <input type="hidden" name="formSent" value="1">
  666. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>">
  667. <input type="hidden" name="myid" value="<?php echo $_REQUEST['myid']; ?>">
  668. <table width="650" border="0" cellpadding="5">
  669. <?php
  670. if ($okPicture) {
  671. ?>
  672. <tr>
  673. <td colspan="5" align="center"><img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0"></td>
  674. </tr>
  675. <?php
  676. }
  677. if (!empty($msgErr)) {
  678. ?>
  679. <tr>
  680. <td colspan="5">
  681. <?php
  682. Display::display_normal_message($msgErr); //main API
  683. ?>
  684. </td>
  685. </tr>
  686. <?php
  687. }
  688. ?>
  689. <tr>
  690. <td colspan="5"><?php echo get_lang('Answers'); ?> :</td>
  691. </tr>
  692. <tr bgcolor="#E6E6E6">
  693. <td>N&#176;</td>
  694. <td><?php echo get_lang('True'); ?></td>
  695. <td><?php echo get_lang('Answer'); ?></td>
  696. <td><?php echo get_lang('Comment'); ?></td>
  697. <td><?php echo get_lang('QuestionWeighting'); ?></td>
  698. </tr>
  699. <?php
  700. for ($i = 1; $i <= $nbrAnswers; $i++) {
  701. ?>
  702. <tr>
  703. <td valign="top"><?php echo $i; ?></td>
  704. <?php
  705. if ($answerType == UNIQUE_ANSWER) {
  706. ?>
  707. <td valign="top"><input class="checkbox" type="radio" value="<?php echo $i; ?>" name="correct" <?php if ($correct == $i) echo 'checked="checked"'; ?>></td>
  708. <?php
  709. }
  710. else {
  711. ?>
  712. <td valign="top"><input class="checkbox" type="checkbox" value="1" name="correct[<?php echo $i; ?>]" <?php if ($correct[$i]) echo 'checked="checked"'; ?>></td>
  713. <?php
  714. }
  715. ?>
  716. <td align="left"><textarea wrap="virtual" rows="7" cols="25" name="reponse[<?php echo $i; ?>]"><?php echo api_htmlentities($reponse[$i], ENT_QUOTES, $charset); ?></textarea></td>
  717. <td align="left"><textarea wrap="virtual" rows="7" cols="25" name="comment[<?php echo $i; ?>]"><?php echo api_htmlentities($comment[$i], ENT_QUOTES, $charset); ?></textarea></td>
  718. <td valign="top"><input type="text" name="weighting[<?php echo $i; ?>]" size="5" value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 0; ?>"></td>
  719. </tr>
  720. <?php
  721. }
  722. ?>
  723. <tr>
  724. <td colspan="5">
  725. <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>">
  726. &nbsp;&nbsp;<input type="submit" name="lessAnswers" value="<?php echo get_lang('LessAnswers'); ?>">
  727. &nbsp;&nbsp;<input type="submit" name="moreAnswers" value="<?php echo get_lang('MoreAnswers'); ?>">
  728. <!-- &nbsp;&nbsp;<input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); ?>')) return false;"> //-->
  729. </td>
  730. </tr>
  731. </table>
  732. </form>
  733. <?php
  734. }
  735. elseif ($answerType == FILL_IN_BLANKS) {
  736. if ($debug > 0) {
  737. echo str_repeat('&nbsp;', 4) . '$answerType is FILL_IN_BLANKS' . "<br />\n";
  738. }
  739. ?>
  740. <h3>
  741. <?php echo $questionName; ?>
  742. </h3>
  743. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>">
  744. <input type="hidden" name="formSent" value="1">
  745. <input type="hidden" name="setWeighting" value="<?php echo $setWeighting; ?>">
  746. <input type="hidden" name="myid" value="<?php echo $_REQUEST['myid']; ?>">
  747. <?php
  748. if (!$setWeighting) {
  749. ?>
  750. <input type="hidden" name="weighting" value="<?php echo $submitAnswers ? api_htmlentities($weighting, ENT_QUOTES, $charset) : api_htmlentities(serialize($weighting), ENT_QUOTES, $charset); ?>">
  751. <table border="0" cellpadding="5" width="500">
  752. <?php
  753. if ($okPicture) {
  754. ?>
  755. <tr>
  756. <td align="center"><img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0"></td>
  757. </tr>
  758. <?php
  759. }
  760. if (!empty($msgErr)) {
  761. ?>
  762. <tr>
  763. <td colspan="2">
  764. <?php
  765. Display::display_normal_message($msgErr); //main API
  766. ?>
  767. </td>
  768. </tr>
  769. <?php
  770. }
  771. ?>
  772. <tr>
  773. <td><?php echo get_lang('TypeTextBelow') . ', ' . get_lang('And') . ' ' . get_lang('UseTagForBlank'); ?> :</td>
  774. </tr>
  775. <tr>
  776. <td><textarea wrap="virtual" name="reponse" cols="65" rows="6"><?php if (!$submitAnswers && empty($reponse)) echo get_lang('DefaultTextInBlanks'); else echo api_htmlentities($reponse, ENT_QUOTES, $charset); ?></textarea></td>
  777. </tr>
  778. <tr>
  779. <td colspan="5">
  780. <!-- <input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); ?>')) return false;">
  781. &nbsp;&nbsp; //--> <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>">
  782. </td>
  783. </tr>
  784. </table>
  785. <?php
  786. }
  787. else {
  788. ?>
  789. <input type="hidden" name="blanks" value="<?php echo api_htmlentities(serialize($blanks), ENT_QUOTES, $charset); ?>">
  790. <input type="hidden" name="reponse" value="<?php echo api_htmlentities($reponse, ENT_QUOTES, $charset); ?>">
  791. <table border="0" cellpadding="5" width="500">
  792. <?php
  793. if (!empty($msgErr)) {
  794. ?>
  795. <tr>
  796. <td colspan="2">
  797. <?php
  798. Display::display_normal_message($msgErr); //main API
  799. ?>
  800. </td>
  801. </tr>
  802. <?php
  803. }
  804. ?>
  805. <tr>
  806. <td colspan="2"><?php echo get_lang('WeightingForEachBlank'); ?> :</td>
  807. </tr>
  808. <tr>
  809. <td colspan="2">&nbsp;</td>
  810. </tr>
  811. <?php
  812. foreach ($blanks as $i => $blank) {
  813. ?>
  814. <tr>
  815. <td width="50%"><?php echo $blank; ?> :</td>
  816. <td width="50%"><input type="text" name="weighting[<?php echo $i; ?>]" size="5" value="<?php echo intval($weighting[$i]); ?>"></td>
  817. </tr>
  818. <?php
  819. }
  820. ?>
  821. <tr>
  822. <td colspan="2">&nbsp;</td>
  823. </tr>
  824. <tr>
  825. <td colspan="2">
  826. <input type="submit" name="buttonBack" value="&lt; <?php echo get_lang('Back'); ?>">
  827. &nbsp;&nbsp;<input type="submit" name="submitAnswers" value="<?php echo ' ' . get_lang('Ok') . ' '; ?>">
  828. <!-- &nbsp;&nbsp;<input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); ?>')) return false;"> //-->
  829. </td>
  830. </tr>
  831. </table>
  832. <?php
  833. }
  834. ?>
  835. </form>
  836. <?php
  837. } elseif ($answerType == FREE_ANSWER) { //edited by Priya Saini
  838. if ($debug > 0) {
  839. echo str_repeat('&nbsp;', 4) . '$answerType is FREE_ANSWER' . "<br />\n";
  840. }
  841. ?>
  842. <h3>
  843. <?php echo $questionName; ?></h3><?php
  844. $sql = "select description from " . $TBL_QUESTIONS . " WHERE id = '" . Database::escape_string($questionId) . "'";
  845. $res = Database::query($sql, _FILE_, _LINE_);
  846. ?>
  847. &nbsp; &nbsp; &nbsp;
  848. <?php
  849. echo $desc = Database::result($res, 0, 'description');
  850. ?>
  851. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>">
  852. <input type="hidden" name="formSent" value="1">
  853. <input type="hidden" name="setWeighting" value="1">
  854. <input type="hidden" name="myid" value="<?php echo $_REQUEST['myid']; ?>">
  855. <table border="0" cellpadding="5" width="500">
  856. <?php
  857. if ($okPicture) {
  858. echo "Ok picture";
  859. ?>
  860. <tr>
  861. <td align="center"><img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0"></td>
  862. </tr>
  863. <?php
  864. }
  865. if (!empty($msgErr)) {
  866. ?>
  867. <tr>
  868. <td colspan="2">
  869. <?php
  870. Display::display_normal_message($msgErr); //main API
  871. ?>
  872. </td>
  873. </tr>
  874. <?php
  875. }
  876. if (!$submitAnswers && empty($free_comment))
  877. echo '';
  878. else
  879. echo api_htmlentities($free_comment, ENT_QUOTES, $charset);
  880. ?>
  881. <tr><td width="22%"><?php echo get_lang('QuestionWeighting'); ?></td>
  882. <td width="78%"><input type="text" size="4" name="weighting" value="<?php if (!$submitAnswers && !isset($weighting)) echo '0'; else echo $weighting; ?>"></td>
  883. </tr>
  884. <tr>
  885. <td colspan="5">
  886. <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>">
  887. </td>
  888. </tr>
  889. </table>
  890. <?php
  891. }
  892. //end of FREE_ANSWER type*/
  893. elseif ($answerType == MATCHING) {
  894. ?>
  895. <h3>
  896. <?php echo $questionName; ?>
  897. </h3>
  898. <form method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>">
  899. <input type="hidden" name="formSent" value="1">
  900. <input type="hidden" name="nbrOptions" value="<?php echo $nbrOptions; ?>">
  901. <input type="hidden" name="nbrMatches" value="<?php echo $nbrMatches; ?>">
  902. <input type="hidden" name="myid" value="<?php echo $_REQUEST['myid']; ?>">
  903. <table border="0" cellpadding="5">
  904. <?php
  905. if ($okPicture) {
  906. ?>
  907. <tr>
  908. <td colspan="4" align="center"><img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0"></td>
  909. </tr>
  910. <?php
  911. }
  912. if (!empty($msgErr)) {
  913. ?>
  914. <tr>
  915. <td colspan="4">
  916. <?php
  917. Display::display_normal_message($msgErr); //main API
  918. ?>
  919. </td>
  920. </tr>
  921. <?php
  922. }
  923. $listeOptions = array();
  924. // creates an array with the option letters
  925. for ($i = 1, $j = 'A'; $i <= $nbrOptions; $i++, $j++) {
  926. $listeOptions[$i] = $j;
  927. }
  928. ?>
  929. <tr>
  930. <td colspan="3"><?php echo get_lang('MakeCorrespond'); ?> :</td>
  931. <td><?php echo get_lang('QuestionWeighting'); ?> :</td>
  932. </tr>
  933. <?php
  934. for ($j = 1; $j <= $nbrMatches; $i++, $j++) {
  935. ?>
  936. <tr>
  937. <td><?php echo $j; ?></td>
  938. <td><input type="text" name="match[<?php echo $i; ?>]" size="58" value="<?php if (!$formSent && !isset($match[$i])) echo ${"langDefaultMakeCorrespond$j"}; else echo api_htmlentities($match[$i], ENT_QUOTES, $charset); ?>"></td>
  939. <td align="center"><select name="sel[<?php echo $i; ?>]">
  940. <?php
  941. foreach ($listeOptions as $key => $val) {
  942. ?>
  943. <option value="<?php echo $key; ?>" <?php if ((!$submitAnswers && !isset($sel[$i]) && $j == 2 && $val == 'B') || $sel[$i] == $key) echo 'selected="selected"'; ?>><?php echo $val; ?></option>
  944. <?php
  945. } // end foreach()
  946. ?>
  947. </select></td>
  948. <td align="center"><input type="text" size="8" name="weighting[<?php echo $i; ?>]" value="<?php if (!$submitAnswers && !isset($weighting[$i])) echo '5'; else echo $weighting[$i]; ?>"></td>
  949. </tr>
  950. <?php
  951. } // end for()
  952. ?>
  953. <tr>
  954. <td colspan="4">
  955. <button type="submit" class="btn minus" name="lessMatches" value="<?php echo get_lang('LessElements'); ?>"><?php echo get_lang('LessElements'); ?></button>
  956. &nbsp;&nbsp;<button class="btn plus" type="submit" name="moreMatches" value="<?php echo get_lang('MoreElements'); ?>"><?php echo get_lang('MoreElements'); ?></button>
  957. </td>
  958. </tr>
  959. <tr>
  960. <td colspan="4"><?php echo get_lang('DefineOptions'); ?> :</td>
  961. </tr>
  962. <?php
  963. foreach ($listeOptions as $key => $val) {
  964. ?>
  965. <tr>
  966. <td><?php echo $val; ?></td>
  967. <td colspan="3"><input type="text" name="option[<?php echo $key; ?>]" size="80" value="<?php if (!$formSent && !isset($option[$key])) echo get_lang("DefaultMatchingOpt$val"); else echo api_htmlentities($option[$key], ENT_QUOTES, $charset); ?>"></td>
  968. </tr>
  969. <?php
  970. } // end foreach()
  971. ?>
  972. <tr>
  973. <td colspan="4">
  974. <button type="submit" class="minus" name="lessOptions" value="<?php echo get_lang('LessElements'); ?>"><?php echo get_lang('LessElements'); ?></button>
  975. &nbsp;&nbsp;<button type="submit" class="plus" name="moreOptions" value="<?php echo get_lang('MoreElements'); ?>"><?php echo get_lang('MoreElements'); ?></button>
  976. </td>
  977. </tr>
  978. <tr>
  979. <td colspan="4">&nbsp;</td>
  980. </tr>
  981. <tr>
  982. <td colspan="4">
  983. <!-- <input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); ?>')) return false;">
  984. &nbsp;&nbsp; //--> <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>">
  985. </td>
  986. </tr>
  987. </table>
  988. </form>
  989. <?php
  990. } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
  991. if ($debug > 0) {
  992. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  993. }
  994. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  995. "#4271B5",
  996. "#FE8E16",
  997. "#45C7F0",
  998. "#BCD631",
  999. "#D63173",
  1000. "#D7D7D7",
  1001. "#90AFDD",
  1002. "#AF8640",
  1003. "#4F9242",
  1004. "#F4EB24",
  1005. "#ED2024",
  1006. "#3B3B3B",
  1007. "#F7BDE2");
  1008. ?>
  1009. <h3>
  1010. <?php echo get_lang('Question') . ": " . $questionName; ?>
  1011. </h3>
  1012. <?php
  1013. if (!empty($msgErr)) {
  1014. Display::display_normal_message($msgErr); //main API
  1015. }
  1016. ?>
  1017. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  1018. <tr>
  1019. <td colspan="2" style="border:1px solid #4271b5; border-bottom:none;"><?php echo get_lang('HotspotChoose'); ?></td>
  1020. </tr>
  1021. <tr>
  1022. <td width="550" valign="top">
  1023. <script type="text/javascript">
  1024. <!--
  1025. // Version check based upon the values entered above in "Globals"
  1026. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  1027. // Check to see if the version meets the requirements for playback
  1028. if (hasReqestedVersion) { // if we've detected an acceptable version
  1029. var oeTags = '<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="550" height="377">'
  1030. + '<param name="movie" value="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  1031. + '<param name="test" value="OOoowww fo shooww" />'
  1032. + '</object>';
  1033. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  1034. } else { // flash is too old or we can't detect the plugin
  1035. var alternateContent = 'Error<br \/>'
  1036. + 'This content requires the Macromedia Flash Player.<br \/>'
  1037. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  1038. document.write(alternateContent); // insert non-flash content
  1039. }
  1040. // -->
  1041. </script>
  1042. </td>
  1043. <td valign="top">
  1044. <form method="post" id="frm_exercise" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>" name="frm_exercise">
  1045. <input type="hidden" name="formSent" value="1" />
  1046. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  1047. <table border="0" cellpadding="3" cellspacing="0" style="border: 1px solid #4271b5; border-left:none; width: 100%; ">
  1048. <!--
  1049. <tr>
  1050. <td colspan="5"><?php echo get_lang('AnswerHotspot'); ?> :</td>
  1051. </tr>
  1052. -->
  1053. <tr style="background-color: #E6E6E6; height: 37px">
  1054. <td style="width: 20px; border-bottom: 1px solid #4271b5">&nbsp;<?php /* echo get_lang('HotSpot'); */ ?></td>
  1055. <td style="width: 100px; border-bottom: 1px solid #4271b5"><?php echo get_lang('Description'); ?>*</td>
  1056. <td style="border-bottom: 1px solid #4271b5"><?php echo get_lang('Comment'); ?></td>
  1057. <td style="width: 60px; border-bottom: 1px solid #4271b5"><?php echo get_lang('QuestionWeighting'); ?>*</td>
  1058. </tr>
  1059. <?php
  1060. for ($i = 1; $i <= $nbrAnswers; $i++) {
  1061. ?>
  1062. <tr>
  1063. <td valign="top"><div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div></td>
  1064. <td valign="top" align="left"><input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo api_htmlentities($reponse[$i], ENT_QUOTES, $charset); ?>" size="12" /></td>
  1065. <td align="left"><textarea wrap="virtual" rows="3" cols="10" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo api_htmlentities($comment[$i], ENT_QUOTES, $charset); ?></textarea></td>
  1066. <td valign="top"><input type="text" name="weighting[<?php echo $i; ?>]" size="1" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 1); ?>" />
  1067. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  1068. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" /></td>
  1069. </tr>
  1070. <?php
  1071. }
  1072. ?>
  1073. <tr>
  1074. <td colspan="5">
  1075. <input type="submit" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" />
  1076. <input type="submit" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" />
  1077. <hr noshade="noshade" size="1" style="color: #4271b5" />
  1078. <input type="submit" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" />
  1079. <!--<input type="submit" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)); ?>')) return false;" />-->
  1080. </td>
  1081. </tr>
  1082. </table>
  1083. </form>
  1084. <table cellpadding="0" cellspacing="0">
  1085. <tr>
  1086. <td style="text-align:center; vertical-align:top; width:20px;">*</td>
  1087. <td style="width:auto;"><?php echo get_lang('HotspotRequired'); ?></td>
  1088. </tr>
  1089. </table>
  1090. </td>
  1091. </tr>
  1092. </table>
  1093. <?php
  1094. }
  1095. }
  1096. if ($debug > 0) {
  1097. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  1098. }
  1099. }