hotspot_admin.inc.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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. ?>
  491. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  492. <em class="fa fa-trash"></em> <?php echo get_lang('LessOAR'); ?>
  493. </button>
  494. <button type="submit" class="btn btn-primary" name="moreOARAnswers" value="moreOARAnswers">
  495. <em class="fa fa-plus"></em> <?php echo get_lang('MoreOAR'); ?>
  496. </button>
  497. <?php
  498. } else {
  499. ?>
  500. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  501. <em class="fa fa-trash"></em> <?php echo get_lang('LessHotspots'); ?>
  502. </button>
  503. <button type="submit" class="btn btn-primary" name="moreAnswers" value="moreAnswers">
  504. <em class="fa fa-plus"></em> <?php echo get_lang('MoreHotspots'); ?>
  505. </button>
  506. <?php
  507. } ?>
  508. <button type="submit" class="btn btn-primary" name="submitAnswers" value="submitAnswers">
  509. <em class="fa fa-save"></em> <?php echo get_lang('AddQuestionToExercise'); ?>
  510. </button>
  511. </div>
  512. </div>
  513. <input type="hidden" name="formSent" value="1"/>
  514. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>"/>
  515. <div class="table-responsive">
  516. <table class="table table-striped table-hover">
  517. <thead>
  518. <tr>
  519. <th width="5">&nbsp;</th>
  520. <th><?php echo get_lang('HotspotDescription'); ?> *</th>
  521. <?php
  522. if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  523. echo '<th>'.get_lang('Comment').'</th>';
  524. if ($answerType == HOT_SPOT_DELINEATION) {
  525. echo '<th >'.get_lang('Scenario').'</th>';
  526. }
  527. } else {
  528. echo '<th colspan="2">'.get_lang('Comment').'</th>';
  529. } ?>
  530. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  531. </tr>
  532. </thead>
  533. <tbody>
  534. <?php
  535. $list = new LearnpathList(api_get_user_id());
  536. // Loading list of LPs
  537. $flat_list = $list->get_flat_list();
  538. for ($i = 1; $i <= $nbrAnswers; $i++) {
  539. // is an delineation
  540. if ($answerType == HOT_SPOT_DELINEATION) {
  541. $option_lp = '';
  542. // setting the LP
  543. $isSelected = false;
  544. foreach ($flat_list as $id => $details) {
  545. $selected = '';
  546. if (isset($lp[$i]) && $id == $lp[$i]) {
  547. $isSelected = true;
  548. $selected = 'selected="selected"';
  549. }
  550. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  551. }
  552. if ($isSelected) {
  553. $option_lp = '<option value="0">'.get_lang('SelectTargetLP').'</option>'.$option_lp;
  554. } else {
  555. $option_lp = '<option value="0" selected="selected" >'.get_lang('SelectTargetLP')
  556. .'</option>'.$option_lp;
  557. }
  558. // Feedback SELECT
  559. $question_list = $objExercise->selectQuestionList();
  560. $option_feed = '';
  561. $option_feed .= '<option value="0">'.get_lang('SelectTargetQuestion').'</option>';
  562. foreach ($question_list as $key => $questionid) {
  563. $selected = '';
  564. $question = Question::read($questionid);
  565. $questionTitle = strip_tags($question->selectTitle());
  566. $val = "Q$key: $questionTitle";
  567. if (isset($select_question[$i]) && $questionid == $select_question[$i]) {
  568. $selected = 'selected="selected"';
  569. }
  570. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  571. }
  572. if (isset($select_question[$i]) && $select_question[$i] == -1) {
  573. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('ExitTest').'</option>';
  574. } else {
  575. $option_feed .= '<option value="-1">'.get_lang('ExitTest').'</option>';
  576. }
  577. //-------- IF it is a delineation
  578. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  579. $option1 = $option2 = $option3 = '';
  580. for ($k = 1; $k <= 100; $k++) {
  581. $selected1 = $selected2 = $selected3 = '';
  582. if ($k == $threadhold1[$i]) {
  583. $selected1 = 'selected="selected"';
  584. }
  585. if ($k == $threadhold2[$i]) {
  586. $selected2 = 'selected="selected"';
  587. }
  588. if ($k == $threadhold3[$i]) {
  589. $selected3 = 'selected="selected"';
  590. }
  591. $option1 .= '<option '.$selected1.' >'.$k.' % </option>';
  592. $option2 .= '<option '.$selected2.' >'.$k.' % </option>';
  593. $option3 .= '<option '.$selected3.'>'.$k.' %</option>';
  594. } ?>
  595. <tr>
  596. <td>
  597. <span class="fa fa-square fa-2x" aria-hidden="true"
  598. style="color: <?php echo $hotspot_colors[$i]; ?>;"></span>
  599. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation"/>
  600. </td>
  601. <td>
  602. <p><strong><?php echo get_lang('Delineation'); ?></strong></p>
  603. <p>
  604. <?php echo get_lang('MinOverlap'); ?>
  605. <select class="form-control" name="threadhold1[<?php echo $i; ?>]">
  606. <?php echo $option1; ?>
  607. </select>
  608. </p>
  609. <p>
  610. <?php echo get_lang('MaxExcess'); ?>
  611. <select class="form-control" name="threadhold2[<?php echo $i; ?>]">
  612. <?php echo $option2; ?>
  613. </select>
  614. </p>
  615. <p>
  616. <?php echo get_lang('MaxMissing'); ?>
  617. <select class="form-control" name="threadhold3[<?php echo $i; ?>]">
  618. <?php echo $option3; ?>
  619. </select>
  620. </p>
  621. </td>
  622. <td align="left">
  623. <p>
  624. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  625. name="comment[<?php echo $i; ?>]"
  626. aria-describedBy="comment-<?php echo $i; ?>-help"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  627. <span id="comment-<?php echo $i; ?>-help"
  628. class="help-block"><?php echo get_lang('LearnerIsInformed'); ?></span>
  629. </p>
  630. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation"/>
  631. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  632. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  633. </td>
  634. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  635. ?>
  636. <td>
  637. <div class="checkbox">
  638. <p>
  639. <label>
  640. <input type="checkbox" class="checkbox" name="<?php echo 'try['.$i; ?>]"
  641. <?php if ($try[$i] == 1) {
  642. echo 'checked';
  643. } ?> />
  644. <?php echo get_lang('TryAgain'); ?>
  645. </label>
  646. </p>
  647. </div>
  648. <p>
  649. <?php echo get_lang('SeeTheory'); ?>
  650. <select class="form-control" name="lp[<?php echo $i; ?>]">
  651. <?php echo $option_lp; ?>
  652. </select>
  653. </p>
  654. <p>
  655. <?php echo get_lang('Other'); ?>
  656. <input class="form-control" name="url[<?php echo $i; ?>]"
  657. value="<?php echo $url[$i]; ?>">
  658. </p>
  659. <p>
  660. <?php echo get_lang('SelectQuestion'); ?>
  661. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  662. <?php echo $option_feed; ?>
  663. </select>
  664. </p>
  665. </td>
  666. <?php
  667. } else {
  668. ?>
  669. <td> &nbsp;</td>
  670. <?php
  671. }
  672. } elseif (false) {
  673. ?>
  674. <tr>
  675. <th colspan="2"><?php echo get_lang('IfNoError'); ?></th>
  676. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  677. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  678. <th></th>
  679. </tr>
  680. <tr>
  681. <td colspan="2">
  682. <?php echo get_lang('LearnerHasNoMistake'); ?>
  683. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror"/>
  684. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0"/>
  685. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror"/>
  686. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0"/>
  687. </td>
  688. <td align="left">
  689. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  690. name="comment[<?php echo $i; ?>]"
  691. style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  692. </td>
  693. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  694. ?>
  695. <td>
  696. <table>
  697. <tr>
  698. <td>
  699. <div class="checkbox">
  700. <p>
  701. <label>
  702. <input type="checkbox" class="checkbox"
  703. name="<?php echo 'try['
  704. .$i; ?>]" <?php if ($try[$i] == 1) {
  705. echo 'checked';
  706. } ?> />
  707. <?php echo get_lang('TryAgain'); ?>
  708. </label>
  709. </p>
  710. </div>
  711. <p>
  712. <?php echo get_lang('SeeTheory'); ?>
  713. <select class="form-control" name="lp[<?php echo $i; ?>]">
  714. <?php echo $option_lp; ?>
  715. </select>
  716. </p>
  717. <p>
  718. <?php echo get_lang('Other'); ?> <br/>
  719. <input class="form-control" name="url[<?php echo $i; ?>]"
  720. value="<?php echo $url[$i]; ?>">
  721. </p>
  722. <p>
  723. <?php echo get_lang('SelectQuestion'); ?> <br/>
  724. <select class="form-control"
  725. name="select_question[<?php echo $i; ?>]">
  726. <?php echo $option_feed; ?>
  727. </select>
  728. </p>
  729. </td>
  730. </tr>
  731. </table>
  732. </td>
  733. <?php
  734. } else {
  735. ?>
  736. <td>&nbsp;</td>
  737. <?php
  738. } ?>
  739. </tr>
  740. <?php
  741. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  742. // if it's an OAR
  743. if ($i == 2) {
  744. ?>
  745. <tr>
  746. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  747. <th><?php echo get_lang('OAR'); ?>*</th>
  748. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  749. ?>
  750. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  751. <th><?php if ($answerType == HOT_SPOT_DELINEATION) {
  752. echo get_lang('Scenario');
  753. } ?></th>
  754. <?php
  755. } else {
  756. ?>
  757. <th colspan="3"><?php echo get_lang('Comment'); ?></th>
  758. <?php
  759. } ?>
  760. <th>&nbsp;</th>
  761. </tr>
  762. <?php
  763. } ?>
  764. <tr>
  765. <td>
  766. <span class="fa fa-square fa-2x" aria-hidden="true"
  767. style="color: <?php echo $hotspot_colors[$i]; ?>"></span>
  768. </td>
  769. <td>
  770. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  771. value="<?php echo isset($reponse[$i]) ? Security::remove_XSS($reponse[$i]) : ''; ?>"/>
  772. </td>
  773. <td colspan="2" align="left">
  774. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  775. name="comment[<?php echo $i; ?>]"
  776. style="width: 100%"><?php echo isset($comment[$i]) ? Security::remove_XSS($comment[$i]) : ''; ?></textarea>
  777. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar"/>
  778. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  779. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  780. </td>
  781. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  782. ?>
  783. <td>
  784. <div class="checkbox">
  785. <p>
  786. <label>
  787. <input type="checkbox" class="checkbox"
  788. name="<?php echo 'try['.$i; ?>]" <?php if (isset($try[$i]) && $try[$i] == 1) {
  789. echo 'checked';
  790. } ?> />
  791. <?php echo get_lang('TryAgain'); ?>
  792. </label>
  793. </p>
  794. </div>
  795. <p>
  796. <?php echo get_lang('SeeTheory'); ?>
  797. <select class="form-control" name="lp[<?php echo $i; ?>]">
  798. <?php echo $option_lp; ?>
  799. </select>
  800. </p>
  801. <p>
  802. <?php echo get_lang('Other'); ?>
  803. <input class="form-control" name="url[<?php echo $i; ?>]"
  804. value="<?php echo isset($url[$i]) ? $url[$i] : ''; ?>">
  805. </p>
  806. <p>
  807. <?php echo get_lang('SelectQuestion'); ?>
  808. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  809. <?php echo $option_feed; ?>
  810. </select>
  811. </p>
  812. </td>
  813. <?php
  814. } else {
  815. ?>
  816. <td>&nbsp;</td>
  817. <?php
  818. }
  819. }
  820. //end if is delineation
  821. } else {
  822. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  823. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null; ?>
  824. <tr>
  825. <td>
  826. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>"
  827. aria-hidden="true"></span>
  828. </td>
  829. <td>
  830. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  831. value="<?php echo Security::remove_XSS($responseValue); ?>"/>
  832. </td>
  833. <?php
  834. $form = new FormValidator('form_'.$i);
  835. $config = [
  836. 'ToolbarSet' => 'TestProposedAnswer',
  837. 'cols-size' => [0, 12, 0],
  838. ];
  839. $form->addHtmlEditor('comment['.$i.']', null, false, false, $config);
  840. $renderer = $form->defaultRenderer();
  841. $form_template = '{content}';
  842. $renderer->setFormTemplate($form_template);
  843. $element_template = '{label} {element}';
  844. $renderer->setElementTemplate($element_template);
  845. $form->setDefaults(['comment['.$i.']' => $commentValue]);
  846. $return = $form->returnForm(); ?>
  847. <td colspan="2" align="left"><?php echo $return; ?></td>
  848. <?php
  849. } ?>
  850. <td>
  851. <?php
  852. if ($answerType == HOT_SPOT_DELINEATION) {
  853. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  854. ?>
  855. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="form-cotrol" value="0"/>
  856. <?php
  857. } else {
  858. ?>
  859. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  860. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  861. <?php
  862. }
  863. }
  864. if ($answerType == HOT_SPOT) {
  865. ?>
  866. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  867. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  868. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]"
  869. value="<?php echo empty($hotspot_coordinates[$i])
  870. ? '0;0|0|0'
  871. : $hotspot_coordinates[$i]; ?>"/>
  872. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]"
  873. value="<?php echo empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]; ?>"/>
  874. <?php
  875. } ?>
  876. </td>
  877. </tr>
  878. <?php
  879. }
  880. $list = new LearnpathList(api_get_user_id());
  881. $flat_list = $list->get_flat_list();
  882. $option_lp = '';
  883. $isSelected = false;
  884. foreach ($flat_list as $id => $details) {
  885. $selected = '';
  886. if (isset($lp_noerror) && $id == $lp_noerror) {
  887. $selected = 'selected="selected"';
  888. $isSelected = true;
  889. }
  890. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  891. }
  892. if ($isSelected) {
  893. $option_lp = '<option value="0">'.get_lang('SelectTargetLP').'</option>'.$option_lp;
  894. } else {
  895. $option_lp = '<option value="0" selected="selected" >'.get_lang('SelectTargetLP').'</option>'
  896. .$option_lp;
  897. }
  898. // Feedback SELECT
  899. $question_list = $objExercise->selectQuestionList();
  900. $option_feed = '';
  901. $option_feed .= '<option value="0">'.get_lang('SelectTargetQuestion').'</option>';
  902. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  903. foreach ($question_list as $key => $questionid) {
  904. $selected = '';
  905. $question = Question::read($questionid);
  906. $questionTitle = $question->selectTitle();
  907. $val = "Q$key: $questionTitle";
  908. if ($questionid == $selectQuestionNoError) {
  909. $selected = 'selected="selected"';
  910. }
  911. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  912. }
  913. if ($selectQuestionNoError == -1) {
  914. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('ExitTest').'</option>';
  915. } else {
  916. $option_feed .= '<option value="-1">'.get_lang('ExitTest').'</option>';
  917. }
  918. if ($answerType == HOT_SPOT_DELINEATION) {
  919. ?>
  920. <tr>
  921. <th colspan="2"><?php echo get_lang('IfNoError'); ?></th>
  922. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  923. ?>
  924. <th colspan="2"><?php echo get_lang('Feedback'); ?></th>
  925. <th><?php echo get_lang('Scenario'); ?></th>
  926. <?php
  927. } else {
  928. ?>
  929. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  930. <?php
  931. } ?>
  932. <th>&nbsp;</th>
  933. </tr>
  934. <tr>
  935. <td colspan="2">
  936. <?php echo get_lang('LearnerHasNoMistake'); ?>
  937. </td>
  938. <td colspan="2" align="left">
  939. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  940. name="comment_noerror"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  941. </td>
  942. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  943. ?>
  944. <td>
  945. <div class="checkbox">
  946. <p>
  947. <label>
  948. <input type="checkbox" class="checkbox"
  949. name="try_noerror" <?php if ($try_noerror == 1) {
  950. echo 'checked';
  951. } ?> />
  952. <?php echo get_lang('TryAgain'); ?>
  953. </label>
  954. </p>
  955. </div>
  956. <p>
  957. <?php echo get_lang('SeeTheory'); ?> <br/>
  958. <select class="form-control" name="lp_noerror">
  959. <?php echo $option_lp; ?>
  960. </select>
  961. </p>
  962. <p>
  963. <?php echo get_lang('Other'); ?> <br/>
  964. <input class="form-control" name="url_noerror" value="<?php echo $url_noerror; ?>">
  965. </p>
  966. <p>
  967. <?php echo get_lang('SelectQuestion'); ?> <br/>
  968. <select class="form-control" name="select_question_noerror">
  969. <?php echo $option_feed; ?>
  970. </select>
  971. </p>
  972. </td>
  973. <td>&nbsp;</td>
  974. <?php
  975. } else {
  976. ?>
  977. <td colspan="2">&nbsp;</td>
  978. <?php
  979. } ?>
  980. </tr>
  981. <?php
  982. } ?>
  983. </tbody>
  984. </table>
  985. </div>
  986. <div class="row">
  987. <div class="col-xs-12">
  988. <?php
  989. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  990. $height = 450;
  991. $relPath = api_get_path(WEB_CODE_PATH); ?>
  992. <div id="hotspot-container" class="center-block"></div>
  993. </div>
  994. </div>
  995. </form>
  996. <script>
  997. $(function () {
  998. <?php if ($answerType == HOT_SPOT_DELINEATION) {
  999. ?>
  1000. new DelineationQuestion({
  1001. questionId: <?php echo $modifyAnswers; ?>,
  1002. selector: '#hotspot-container',
  1003. for: 'admin',
  1004. relPath: '<?php echo $relPath; ?>'
  1005. });
  1006. <?php
  1007. } else {
  1008. ?>
  1009. new HotspotQuestion({
  1010. questionId: <?php echo $modifyAnswers; ?>,
  1011. selector: '#hotspot-container',
  1012. for: 'admin',
  1013. relPath: '<?php echo $relPath; ?>'
  1014. });
  1015. <?php
  1016. } ?>
  1017. });
  1018. </script>
  1019. <?php
  1020. if ($debug > 0) {
  1021. echo str_repeat('&nbsp;', 0).'$modifyAnswers was set - end'."<br />\n";
  1022. }
  1023. }