hotspot_admin.inc.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script allows to manage answers. It is included from the
  5. * script admin.php
  6. * @package chamilo.exercise
  7. * @author Toon Keppens
  8. */
  9. use \ChamiloSession as Session;
  10. $modifyAnswers = intval($_GET['hotspotadmin']);
  11. if (!is_object($objQuestion)) {
  12. $objQuestion = Question :: read($modifyAnswers);
  13. }
  14. $questionName = $objQuestion->selectTitle();
  15. $answerType = $objQuestion->selectType();
  16. $pictureName = $objQuestion->selectPicture();
  17. $debug = 0; // debug variable to get where we are
  18. $okPicture = empty($pictureName) ? false : true;
  19. // if we come from the warning box "this question is used in several exercises"
  20. if ($modifyIn) {
  21. if ($debug > 0) {
  22. echo '$modifyIn was set' . "<br />\n";
  23. }
  24. // if the user has chosen to modify the question only in the current exercise
  25. if ($modifyIn == 'thisExercise') {
  26. // duplicates the question
  27. $questionId = $objQuestion->duplicate();
  28. // deletes the old question
  29. $objQuestion->delete($exerciseId);
  30. // removes the old question ID from the question list of the Exercise object
  31. $objExercise->removeFromList($modifyAnswers);
  32. // adds the new question ID into the question list of the Exercise object
  33. $objExercise->addToList($questionId);
  34. // construction of the duplicated Question
  35. $objQuestion = Question :: read($questionId);
  36. // adds the exercise ID into the exercise list of the Question object
  37. $objQuestion->addToList($exerciseId);
  38. // copies answers from $modifyAnswers to $questionId
  39. $objAnswer->duplicate($questionId);
  40. // construction of the duplicated Answers
  41. $objAnswer = new Answer($questionId);
  42. }
  43. $color = unserialize($color);
  44. $reponse = unserialize($reponse);
  45. $comment = unserialize($comment);
  46. $weighting = unserialize($weighting);
  47. $hotspot_coordinates = unserialize($hotspot_coordinates);
  48. $hotspot_type = unserialize($hotspot_type);
  49. $destination = unserialize($destination);
  50. unset($buttonBack);
  51. }
  52. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&exerciseId=' . $exerciseId;
  53. // the answer form has been submitted
  54. $submitAnswers = isset($_POST['submitAnswers']) ? true : false;
  55. $buttonBack = isset($_POST['buttonBack']) ? true : false;
  56. $nbrAnswers = isset($_POST['nbrAnswers']) ? intval($_POST['nbrAnswers']) : 0;
  57. if ($submitAnswers || $buttonBack) {
  58. if ($answerType == HOT_SPOT) {
  59. if ($debug > 0) {
  60. echo '$submitAnswers or $buttonBack was set' . "<br />\n";
  61. }
  62. $questionWeighting = $nbrGoodAnswers = 0;
  63. for ($i = 1; $i <= $nbrAnswers; $i++) {
  64. if ($debug > 0) {
  65. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  66. }
  67. $reponse[$i] = trim($reponse[$i]);
  68. $comment[$i] = trim($comment[$i]);
  69. $weighting[$i] = $weighting[$i]; // it can be float
  70. // checks if field is empty
  71. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  72. $msgErr = get_lang('HotspotGiveAnswers');
  73. // clears answers already recorded into the Answer object
  74. $objAnswer->cancel();
  75. break;
  76. }
  77. if ($weighting[$i] <= 0) {
  78. $msgErr = get_lang('HotspotWeightingError');
  79. // clears answers already recorded into the Answer object
  80. $objAnswer->cancel();
  81. break;
  82. }
  83. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  84. $msgErr = get_lang('HotspotNotDrawn');
  85. // clears answers already recorded into the Answer object
  86. $objAnswer->cancel();
  87. break;
  88. }
  89. } // end for()
  90. if (empty($msgErr)) {
  91. for ($i = 1; $i <= $nbrAnswers; $i++) {
  92. if ($debug > 0) {
  93. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  94. }
  95. $reponse[$i] = trim($reponse[$i]);
  96. $comment[$i] = trim($comment[$i]);
  97. $weighting[$i] = ($weighting[$i]); //it can be float
  98. if ($weighting[$i]) {
  99. $questionWeighting+=$weighting[$i];
  100. }
  101. // creates answer
  102. $objAnswer->createAnswer(
  103. $reponse[$i],
  104. '',
  105. $comment[$i],
  106. $weighting[$i],
  107. $i,
  108. $hotspot_coordinates[$i],
  109. $hotspot_type[$i]
  110. );
  111. } // end for()
  112. // saves the answers into the data base
  113. $objAnswer->save();
  114. // sets the total weighting of the question
  115. $objQuestion->updateWeighting($questionWeighting);
  116. $objQuestion->save($exerciseId);
  117. $editQuestion = $questionId;
  118. unset($modifyAnswers);
  119. echo '<script type="text/javascript">window.location.href="' . $hotspot_admin_url . '&message=ItemUpdated"</script>';
  120. }
  121. if ($debug > 0) {
  122. echo '$modifyIn was set - end' . "<br />\n";
  123. }
  124. } else {
  125. if ($debug > 0) {
  126. echo '$submitAnswers or $buttonBack was set' . "<br />\n";
  127. }
  128. $questionWeighting = $nbrGoodAnswers = 0;
  129. $select_question = $_POST['select_question'];
  130. $try = $_POST['try'];
  131. $url = $_POST['url'];
  132. $destination = array();
  133. $threadhold1 = $_POST['threadhold1'];
  134. $threadhold2 = $_POST['threadhold2'];
  135. $threadhold3 = $_POST['threadhold3'];
  136. for ($i = 1; $i <= $nbrAnswers; $i++) {
  137. if ($debug > 0) {
  138. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  139. }
  140. $reponse[$i] = trim($reponse[$i]);
  141. $comment[$i] = trim($comment[$i]);
  142. $weighting[$i] = $weighting[$i];
  143. if (empty($threadhold1[$i])) {
  144. $threadhold1_str = 0;
  145. } else {
  146. $threadhold1_str = intval($threadhold1[$i]);
  147. }
  148. if (empty($threadhold2[$i])) {
  149. $threadhold2_str = 0;
  150. } else {
  151. $threadhold2_str = intval($threadhold2[$i]);
  152. }
  153. if (empty($threadhold3[$i])) {
  154. $threadhold3_str = 0;
  155. } else {
  156. $threadhold3_str = intval($threadhold3[$i]);
  157. }
  158. $threadhold_total = $threadhold1_str . ';' . $threadhold2_str . ';' . $threadhold3_str;
  159. if ($try[$i] == 'on') {
  160. $try_str = 1;
  161. } else {
  162. $try_str = 0;
  163. }
  164. if (empty($lp[$i])) {
  165. $lp_str = 0;
  166. } else {
  167. $lp_str = $lp[$i];
  168. }
  169. if ($url[$i] == '') {
  170. $url_str = '';
  171. } else {
  172. $url_str = $url[$i];
  173. }
  174. if ($select_question[$i] == '') {
  175. $question_str = 0;
  176. } else {
  177. $question_str = $select_question[$i];
  178. }
  179. $destination[$i] = $threadhold_total . '@@' . $try_str . '@@' . $lp_str . '@@' . $question_str . '@@' . $url_str;
  180. // checks if field is empty
  181. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  182. $msgErr = get_lang('HotspotGiveAnswers');
  183. // clears answers already recorded into the Answer object
  184. $objAnswer->cancel();
  185. break;
  186. }
  187. if ($weighting[$i] <= 0 && $_SESSION['tmp_answers']['hotspot_type'][$i] != 'oar') {
  188. $msgErr = get_lang('HotspotWeightingError');
  189. // clears answers already recorded into the Answer object
  190. $objAnswer->cancel();
  191. break;
  192. }
  193. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  194. $msgErr = get_lang('HotspotNotDrawn');
  195. // clears answers already recorded into the Answer object
  196. $objAnswer->cancel();
  197. break;
  198. }
  199. } // end for()
  200. //now the noerror section
  201. $selectQuestionNoError = $_POST['select_question_noerror'];
  202. $lp_noerror = $_POST['lp_noerror'];
  203. $try_noerror = $_POST['try_noerror'];
  204. $url_noerror = $_POST['url_noerror'];
  205. $comment_noerror = $_POST['comment_noerror'];
  206. $threadhold_total = '0;0;0';
  207. if ($try_noerror == 'on') {
  208. $try_str = 1;
  209. } else {
  210. $try_str = 0;
  211. }
  212. if (empty($lp_noerror)) {
  213. $lp_str = 0;
  214. } else {
  215. $lp_str = $lp_noerror;
  216. }
  217. if ($url_noerror == '') {
  218. $url_str = '';
  219. } else {
  220. $url_str = $url_noerror;
  221. }
  222. if ($selectQuestionNoError == '') {
  223. $question_str = 0;
  224. } else {
  225. $question_str = $selectQuestionNoError;
  226. }
  227. $destination_noerror = $threadhold_total . '@@' . $try_str . '@@' . $lp_str . '@@' . $question_str . '@@' . $url_str;
  228. if (empty($msgErr)) {
  229. for ($i = 1; $i <= $nbrAnswers; $i++) {
  230. if ($debug > 0) {
  231. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  232. }
  233. $reponse[$i] = trim($reponse[$i]);
  234. $comment[$i] = trim($comment[$i]);
  235. $weighting[$i] = ($weighting[$i]); //it can be float
  236. if ($weighting[$i]) {
  237. $questionWeighting+=$weighting[$i];
  238. }
  239. // creates answer
  240. $objAnswer->createAnswer(
  241. $reponse[$i],
  242. '',
  243. $comment[$i],
  244. $weighting[$i],
  245. $i,
  246. $hotspot_coordinates[$i],
  247. $hotspot_type[$i],
  248. $destination[$i]
  249. );
  250. } // end for()
  251. // saves the answers into the data base
  252. $objAnswer->createAnswer(
  253. 'noerror',
  254. '',
  255. $comment_noerror,
  256. '0',
  257. $nbrAnswers + 1,
  258. null,
  259. 'noerror',
  260. $destination_noerror
  261. );
  262. $objAnswer->save();
  263. // sets the total weighting of the question
  264. $objQuestion->updateWeighting($questionWeighting);
  265. $objQuestion->save($exerciseId);
  266. $editQuestion = $questionId;
  267. unset($modifyAnswers);
  268. echo '<script type="text/javascript">window.location.href="' . $hotspot_admin_url . '&message=ItemUpdated"</script>';
  269. }
  270. }
  271. }
  272. if ($modifyAnswers) {
  273. if ($debug > 0) {
  274. echo str_repeat('&nbsp;', 0) . '$modifyAnswers is set' . "<br />\n";
  275. }
  276. // construction of the Answer object
  277. $objAnswer = new Answer($objQuestion->id);
  278. Session::write('objAnswer', $objAnswer);
  279. if ($debug > 0) {
  280. echo str_repeat('&nbsp;', 2) . '$answerType is HOT_SPOT' . "<br />\n";
  281. }
  282. if ($answerType == HOT_SPOT_DELINEATION) {
  283. $try = $_POST['try'];
  284. for ($i = 1; $i <= $nbrAnswers; $i++) {
  285. if ($try[$i] == 'on') {
  286. $try[$i] = 1;
  287. } else {
  288. $try[$i] = 0;
  289. }
  290. }
  291. if ($_POST['try_noerror'] == 'on') {
  292. $try_noerror = 1;
  293. } else {
  294. $try_noerror = 0;
  295. }
  296. }
  297. if (!$nbrAnswers) {
  298. $nbrAnswers = $objAnswer->selectNbrAnswers();
  299. if ($answerType == HOT_SPOT_DELINEATION) {
  300. // the magic happens here ...
  301. // we do this to not count the if no error section
  302. if ($nbrAnswers >= 2)
  303. $nbrAnswers--;
  304. }
  305. $reponse = array();
  306. $comment = array();
  307. $weighting = array();
  308. $hotspot_coordinates = array();
  309. $hotspot_type = array();
  310. $destination_items = array();
  311. $destination = array();
  312. for ($i = 1; $i <= $nbrAnswers; $i++) {
  313. $reponse[$i] = $objAnswer->selectAnswer($i);
  314. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  315. $comment[$i] = $objAnswer->selectComment($i);
  316. }
  317. $weighting[$i] = $objAnswer->selectWeighting($i);
  318. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($i);
  319. $hotspot_type[$i] = $objAnswer->selectHotspotType($i);
  320. if ($answerType == HOT_SPOT_DELINEATION) {
  321. $destination[$i] = $objAnswer->selectDestination($i);
  322. $destination_items = explode('@@', $destination[$i]);
  323. $threadhold_total = $destination_items[0];
  324. $threadhold_items = explode(';', $threadhold_total);
  325. $threadhold1[$i] = $threadhold_items[0];
  326. $threadhold2[$i] = $threadhold_items[1];
  327. $threadhold3[$i] = $threadhold_items[2];
  328. $try[$i] = $destination_items[1];
  329. $lp[$i] = $destination_items[2];
  330. $select_question[$i] = $destination_items[3];
  331. $url[$i] = $destination_items[4];
  332. }
  333. }
  334. }
  335. if ($answerType == HOT_SPOT_DELINEATION) {
  336. //added the noerror answer
  337. $reponse_noerror = 'noerror';
  338. $comment_noerror = $objAnswer->selectComment($nbrAnswers + 1);
  339. $destination_noerror_list = $objAnswer->selectDestination($nbrAnswers + 1);
  340. $destination_items = explode('@@', $destination_noerror_list);
  341. $try_noerror = $destination_items[1];
  342. $lp_noerror = $destination_items[2];
  343. $selectQuestionNoError = $destination_items[3];
  344. $url_noerror = $destination_items[4];
  345. }
  346. $_SESSION['tmp_answers'] = array();
  347. $_SESSION['tmp_answers']['answer'] = $reponse;
  348. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  349. $_SESSION['tmp_answers']['comment'] = $comment;
  350. }
  351. $_SESSION['tmp_answers']['weighting'] = $weighting;
  352. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  353. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  354. if ($answerType == HOT_SPOT_DELINEATION) {
  355. $_SESSION['tmp_answers']['destination'] = $destination;
  356. }
  357. $lessAnswers = isset($_POST['lessAnswers']) ? true : false;
  358. if ($lessAnswers) {
  359. if ($answerType == HOT_SPOT_DELINEATION) {
  360. $lest_answer = 1;
  361. // At least 1 answer
  362. if ($nbrAnswers > $lest_answer) {
  363. $nbrAnswers--;
  364. // Remove the last answer
  365. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  366. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  367. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  368. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  369. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  370. if (is_array($_SESSION['tmp_answers']['destination'])) {
  371. $tmp = array_pop($_SESSION['tmp_answers']['destination']);
  372. }
  373. } else {
  374. $msgErr = get_lang('MinHotspot');
  375. }
  376. } else {
  377. // At least 1 answer
  378. if ($nbrAnswers > 1) {
  379. $nbrAnswers--;
  380. // Remove the last answer
  381. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  382. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  383. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  384. }
  385. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  386. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  387. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  388. } else {
  389. $msgErr = get_lang('MinHotspot');
  390. }
  391. }
  392. }
  393. $moreAnswers = isset($_POST['moreAnswers']) ? true : false;
  394. if ($moreAnswers) {
  395. if ($nbrAnswers < 12) {
  396. $nbrAnswers++;
  397. // Add a new answer
  398. $_SESSION['tmp_answers']['answer'][] = '';
  399. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  400. $_SESSION['tmp_answers']['comment'][] = '';
  401. }
  402. $_SESSION['tmp_answers']['weighting'][] = '1';
  403. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  404. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  405. $_SESSION['tmp_answers']['destination'][] = '';
  406. } else {
  407. $msgErr = get_lang('MaxHotspot');
  408. }
  409. }
  410. $moreOARAnswers = isset($_POST['moreOARAnswers']) ? true : false;
  411. if ($moreOARAnswers) {
  412. if ($nbrAnswers < 12) {
  413. // Add a new answer
  414. $nbrAnswers++;
  415. $_SESSION['tmp_answers']['answer'][] = '';
  416. $_SESSION['tmp_answers']['comment'][] = '';
  417. $_SESSION['tmp_answers']['weighting'][] = '1';
  418. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  419. $_SESSION['tmp_answers']['hotspot_type'][] = 'oar';
  420. $_SESSION['tmp_answers']['destination'][] = '';
  421. } else {
  422. $msgErr = get_lang('MaxHotspot');
  423. }
  424. }
  425. if ($debug > 0) {
  426. echo str_repeat('&nbsp;', 2) . '$usedInSeveralExercises is untrue' . "<br />\n";
  427. }
  428. if ($debug > 0) {
  429. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  430. }
  431. if ($answerType == HOT_SPOT_DELINEATION) {
  432. $hotspot_colors = array(
  433. "",
  434. "#4271B5",
  435. "#FE8E16",
  436. "#45C7F0",
  437. "#BCD631",
  438. "#D63173",
  439. "#D7D7D7",
  440. "#90AFDD",
  441. "#AF8640",
  442. "#4F9242",
  443. "#F4EB24",
  444. "#ED2024",
  445. "#3B3B3B"
  446. );
  447. } else {
  448. $hotspot_colors = array(
  449. "", // $i starts from 1 on next loop (ugly fix)
  450. "#4271B5",
  451. "#FE8E16",
  452. "#45C7F0",
  453. "#BCD631",
  454. "#D63173",
  455. "#D7D7D7",
  456. "#90AFDD",
  457. "#AF8640",
  458. "#4F9242",
  459. "#F4EB24",
  460. "#ED2024",
  461. "#3B3B3B",
  462. "#F7BDE2"
  463. );
  464. }
  465. Display::tag('h3', get_lang('Question') . ": " . $questionName . ' <img src="../img/info3.gif" title="' . strip_tags(get_lang('HotspotChoose')) . '" alt="' . strip_tags(get_lang('HotspotChoose')) . '" />');
  466. if (!empty($msgErr)) {
  467. Display::display_normal_message($msgErr); //main API
  468. }
  469. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&hotspotadmin=' . $modifyAnswers . '&exerciseId=' . $exerciseId . '&' . api_get_cidreq();
  470. ?>
  471. <form method="post" action="<?php echo $hotspot_admin_url; ?>" class="form-horizontal" id="frm_exercise" name="frm_exercise">
  472. <div class="form-group">
  473. <div class="col-sm-12">
  474. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  475. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  476. <i class="fa fa-trash"></i> <?php echo get_lang('LessOAR'); ?>
  477. </button>
  478. <button type="submit" name="moreOARAnswers" value="moreOARAnswers">
  479. <i class="fa fa-plus"></i> <?php echo get_lang('MoreOAR'); ?>
  480. </button>
  481. <?php } else { ?>
  482. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  483. <i class="fa fa-trash"></i> <?php echo get_lang('LessHotspots'); ?>
  484. </button>
  485. <button type="submit" class="btn btn-primary" name="moreAnswers" value="moreAnswers">
  486. <i class="fa fa-plus"></i> <?php echo get_lang('MoreHotspots'); ?>
  487. </button>
  488. <?php } ?>
  489. <button type="submit" class="btn btn-primary" name="submitAnswers" value="submitAnswers">
  490. <i class="fa fa-save"></i> <?php echo get_lang('AddQuestionToExercise'); ?>
  491. </button>
  492. </div>
  493. </div>
  494. <table border="0" cellpadding="0" cellspacing="2" width="100%">
  495. <tr>
  496. <td>
  497. <input type="hidden" name="formSent" value="1" />
  498. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  499. <table class="table table-striped table-hover">
  500. <tr>
  501. <th width="5">&nbsp;</th>
  502. <th> <?php echo get_lang('HotspotDescription'); ?> *</th>
  503. <?php
  504. if ($answerType == HOT_SPOT_DELINEATION) {
  505. echo '<th >' . get_lang('Thresholds') . '</th>';
  506. }
  507. if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  508. ?>
  509. <th><?php echo get_lang('Comment'); ?></th>
  510. <?php
  511. if ($answerType == HOT_SPOT_DELINEATION) {
  512. echo '<th >' . get_lang('Scenario') . '</th>';
  513. }
  514. ?>
  515. <?php
  516. } else {
  517. ?>
  518. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  519. <?php } ?>
  520. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  521. </tr>
  522. <?php
  523. $list = new LearnpathList(api_get_user_id());
  524. // Loading list of LPs
  525. $flat_list = $list->get_flat_list();
  526. for ($i = 1; $i <= $nbrAnswers; $i++) {
  527. // is an delineation
  528. if ($answerType == HOT_SPOT_DELINEATION) {
  529. $select_lp_id = array();
  530. $option_lp = '';
  531. // setting the LP
  532. $isSelected = false;
  533. foreach ($flat_list as $id => $details) {
  534. $select_lp_id[$id] = $details['lp_name'];
  535. $selected = '';
  536. if ($id == $lp[$i]) {
  537. $isSelected = true;
  538. $selected = 'selected="selected"';
  539. }
  540. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  541. }
  542. if ($isSelected) {
  543. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  544. } else {
  545. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  546. }
  547. // Feedback SELECT
  548. $question_list = $objExercise->selectQuestionList();
  549. $option_feed = '';
  550. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  551. foreach ($question_list as $key => $questionid) {
  552. $selected = '';
  553. $question = Question::read($questionid);
  554. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  555. $select_lp_id[$id] = $details['lp_name'];
  556. if ($questionid == $select_question[$i]) {
  557. $selected = 'selected="selected"';
  558. }
  559. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  560. }
  561. if ($select_question[$i] == -1) {
  562. $option_feed .= '<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  563. } else {
  564. $option_feed .= '<option value="-1">' . get_lang('ExitTest') . '</option>';
  565. }
  566. //-------- IF it is a delineation
  567. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  568. for ($k = 1; $k <= 100; $k++) {
  569. $selected1 = $selected2 = $selected3 = '';
  570. if ($k == $threadhold1[$i])
  571. $selected1 = 'selected="selected"';
  572. if ($k == $threadhold2[$i])
  573. $selected2 = 'selected="selected"';
  574. if ($k == $threadhold3[$i])
  575. $selected3 = 'selected="selected"';
  576. $option1.='<option ' . $selected1 . ' >' . $k . '</option>';
  577. $option2.='<option ' . $selected2 . ' >' . $k . '</option>';
  578. $option3.='<option ' . $selected3 . '>' . $k . '</option>';
  579. }
  580. ?>
  581. <tr>
  582. <td>
  583. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  584. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  585. </td>
  586. <td>
  587. <b><?php echo get_lang('Delineation'); ?></b><br /><br />
  588. <?php echo get_lang('MinOverlap'); ?><br/><br/>
  589. <?php echo get_lang('MaxExcess'); ?><br/><br/>
  590. <?php echo get_lang('MaxMissing'); ?><br/><br/>
  591. </td>
  592. <td>
  593. <br/><br/>
  594. <select name="threadhold1[<?php echo $i; ?>]" >
  595. <?php echo $option1; ?>
  596. </select>%
  597. <br/><br/>
  598. <select name="threadhold2[<?php echo $i; ?>]" >
  599. <?php echo $option2; ?>
  600. </select>%
  601. <br/><br/>
  602. <select name="threadhold3[<?php echo $i; ?>]" >
  603. <?php echo $option3; ?>
  604. </select>%
  605. <br/>
  606. </td>
  607. <td align="left">
  608. <br />
  609. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%">
  610. <?php echo Security::remove_XSS($comment[$i]); ?>
  611. </textarea>
  612. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  613. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  614. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  615. ?>" />
  616. <br/>
  617. <?php echo get_lang('LearnerIsInformed'); ?>
  618. </td>
  619. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  620. <td>
  621. <table>
  622. <tr>
  623. <td>
  624. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  625. <?php echo get_lang('TryAgain'); ?><br /><br />
  626. <?php echo get_lang('SeeTheory'); ?><br />
  627. <select name="lp[<?php echo $i; ?>]" >
  628. <?php echo $option_lp; ?>
  629. </select>
  630. <br /><br />
  631. <?php echo get_lang('Other'); ?> <br />
  632. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  633. <br /> <br />
  634. <?php echo get_lang('SelectQuestion'); ?> <br />
  635. <select name="select_question[<?php echo $i; ?>]" >
  636. <?php echo $option_feed; ?>
  637. </select>
  638. </td>
  639. </tr>
  640. </table>
  641. </td>
  642. <?php } else { ?>
  643. <td> &nbsp;</td>
  644. <?php
  645. }
  646. } elseif (false) {
  647. ?>
  648. <tr>
  649. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  650. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  651. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  652. <th></th>
  653. </tr>
  654. <tr>
  655. <td colspan="2">
  656. <?php echo get_lang('LearnerHasNoMistake'); ?>
  657. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  658. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  659. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  660. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  661. </td>
  662. <td colspan="2" align="left">
  663. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  664. </td>
  665. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  666. <td>
  667. <table>
  668. <tr>
  669. <td>
  670. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  671. <?php echo get_lang('TryAgain'); ?>
  672. <br /><br />
  673. <?php echo get_lang('SeeTheory'); ?>
  674. <br />
  675. <select name="lp[<?php echo $i; ?>]" >
  676. <?php echo $option_lp; ?>
  677. </select>
  678. <br /><br />
  679. <?php echo get_lang('Other'); ?> <br />
  680. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  681. <br /> <br />
  682. <?php echo get_lang('SelectQuestion'); ?> <br />
  683. <select name="select_question[<?php echo $i; ?>]">
  684. <?php echo $option_feed; ?>
  685. </select>
  686. </td>
  687. </tr>
  688. </table>
  689. </td>
  690. <?php } else { ?>
  691. <td>&nbsp;</td>
  692. <?php } ?>
  693. </tr>
  694. <?php
  695. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  696. // if it's an OAR
  697. if ($i == 2) {
  698. ?>
  699. <tr>
  700. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  701. <th ><?php echo get_lang('OAR'); ?>*</th>
  702. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  703. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  704. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  705. <?php } else { ?>
  706. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  707. <?php } ?>
  708. <th>&nbsp;</th>
  709. </tr>
  710. <?php } ?>
  711. <tr>
  712. <td>
  713. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  714. </td>
  715. <td>
  716. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="20" />
  717. </td>
  718. <td colspan="2" align="left">
  719. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  720. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  721. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  722. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  723. ?>" />
  724. </td>
  725. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  726. <td>
  727. <table>
  728. <tr>
  729. <td>
  730. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  731. <?php echo get_lang('TryAgain'); ?>
  732. <br /><br />
  733. <?php echo get_lang('SeeTheory'); ?> <br />
  734. <select name="lp[<?php echo $i; ?>]" >
  735. <?php echo $option_lp; ?>
  736. </select>
  737. <br /><br />
  738. <?php echo get_lang('Other'); ?> <br />
  739. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  740. <br /><br />
  741. <?php echo get_lang('SelectQuestion'); ?> <br />
  742. <select name="select_question[<?php echo $i; ?>]">
  743. <?php echo $option_feed; ?>
  744. </select>
  745. </td>
  746. </tr>
  747. </table>
  748. </td>
  749. <?php } else { ?>
  750. <td>&nbsp;</td>
  751. <?php
  752. }
  753. }
  754. //end if is delineation
  755. } else {
  756. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  757. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null;
  758. ?>
  759. <tr>
  760. <td>
  761. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  762. </td>
  763. <td>
  764. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($responseValue); ?>" size="45" />
  765. </td>
  766. <?php
  767. $form = new FormValidator('form_' . $i);
  768. $config = array(
  769. 'ToolbarSet' => 'TestProposedAnswer'
  770. );
  771. $form->addHtmlEditor('comment[' . $i . ']', null, false, false, $config);
  772. $renderer = $form->defaultRenderer();
  773. $form_template = '{content}';
  774. $renderer->setFormTemplate($form_template);
  775. $element_template = '
  776. {label}
  777. {element}';
  778. $renderer->setElementTemplate($element_template);
  779. $form->setDefaults(array('comment[' . $i . ']' => $commentValue));
  780. $return = $form->return_form();
  781. ?>
  782. <td>&nbsp;</td>
  783. <td align="left" ><?php echo $return; ?></td>
  784. <?php } ?>
  785. <td>
  786. <?php
  787. if ($answerType == HOT_SPOT_DELINEATION) {
  788. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  789. ?>
  790. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
  791. <?php } else { ?>
  792. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  793. <?php
  794. }
  795. }
  796. if ($answerType == HOT_SPOT) {
  797. ?>
  798. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  799. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  800. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  801. <?php } ?>
  802. </td>
  803. </tr>
  804. <?php
  805. }
  806. $list = new LearnpathList(api_get_user_id());
  807. $flat_list = $list->get_flat_list();
  808. $select_lp_id = array();
  809. $option_lp = '';
  810. $isSelected = false;
  811. foreach ($flat_list as $id => $details) {
  812. $selected = '';
  813. $select_lp_id[$id] = $details['lp_name'];
  814. if (isset($lp_noerror) && $id == $lp_noerror) {
  815. $selected = 'selected="selected"';
  816. $isSelected = true;
  817. }
  818. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  819. }
  820. if ($isSelected) {
  821. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  822. } else {
  823. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  824. }
  825. // Feedback SELECT
  826. $question_list = $objExercise->selectQuestionList();
  827. $option_feed = '';
  828. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  829. $details = isset($details) ? $details : null;
  830. $id = isset($id) ? $id : 0;
  831. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  832. foreach ($question_list as $key => $questionid) {
  833. $selected = '';
  834. $question = Question::read($questionid);
  835. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  836. $select_lp_id[$id] = $details['lp_name'];
  837. if ($questionid == $selectQuestionNoError) {
  838. $selected = 'selected="selected"';
  839. }
  840. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  841. }
  842. if ($selectQuestionNoError == -1) {
  843. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  844. } else {
  845. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  846. }
  847. if ($answerType == HOT_SPOT_DELINEATION) {
  848. ?>
  849. <tr>
  850. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  851. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  852. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  853. <th><?php echo get_lang('Scenario'); ?></th>
  854. <?php } else { ?>
  855. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  856. <?php } ?>
  857. <th>&nbsp;</th>
  858. </tr>
  859. <tr>
  860. <td colspan="2">
  861. <?php echo get_lang('LearnerHasNoMistake'); ?>
  862. </td>
  863. <td colspan="2" align="left">
  864. <textarea wrap="virtual" rows="3" cols="25" name="comment_noerror" style="width: 100%"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  865. </td>
  866. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  867. <td>
  868. <table>
  869. <tr>
  870. <td>
  871. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  872. <?php echo get_lang('TryAgain'); ?>
  873. <br /><br />
  874. <?php echo get_lang('SeeTheory'); ?> <br />
  875. <select name="lp_noerror" >
  876. <?php echo $option_lp; ?>
  877. </select>
  878. <br /><br />
  879. <?php echo get_lang('Other'); ?> <br />
  880. <input name="url_noerror" value="<?php echo $url_noerror; ?>">
  881. <br /><br />
  882. <?php echo get_lang('SelectQuestion'); ?> <br />
  883. <select name="select_question_noerror">
  884. <?php echo $option_feed; ?>
  885. </select>
  886. </td>
  887. </tr>
  888. </table>
  889. </td>
  890. <td>&nbsp;</td>
  891. <?php } else { ?>
  892. <td colspan="2">&nbsp;</td>
  893. <?php } ?>
  894. </tr>
  895. <?php } ?>
  896. </table>
  897. </td>
  898. </tr>
  899. <tr>
  900. <td>
  901. <script>
  902. <!--
  903. // Version check based upon the values entered above in "Globals"
  904. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  905. <?php
  906. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  907. $height = 450;
  908. ?>
  909. // Check to see if the version meets the requirements for playback
  910. if (hasReqestedVersion) { // if we've detected an acceptable version
  911. var oeTags = '<object type="application/x-shockwave-flash" data="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="600" height="<?php echo $height ?>">'
  912. + '<param name="movie" value="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  913. + '<param name="test" value="OOoowww fo shooww" />'
  914. + '</object>';
  915. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  916. } else { // flash is too old or we can't detect the plugin
  917. var alternateContent = 'Error<br \/>'
  918. + 'This content requires the Macromedia Flash Player.<br \/>'
  919. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  920. document.write(alternateContent); // insert non-flash content
  921. }
  922. // -->
  923. </script>
  924. </td>
  925. </tr>
  926. </table>
  927. </form>
  928. <?php
  929. if ($debug > 0) {
  930. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  931. }
  932. }