hotspot_admin.inc.php 50 KB

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