answer_admin.inc.php 54 KB

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