hotspot_admin.inc.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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('Please give an answer');
  75. // clears answers already recorded into the Answer object
  76. $objAnswer->cancel();
  77. break;
  78. }
  79. if ($weighting[$i] <= 0) {
  80. $msgErr = get_lang('You must give a positive score for each hotspots');
  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('You haven\'t drawn all your hotspots yet');
  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 = isset($_POST['select_question']) ? $_POST['select_question'] : null;
  133. $try = isset($_POST['try']) ? $_POST['try'] : [];
  134. $url = isset($_POST['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. $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 = (int) $threadhold1[$i];
  147. }
  148. if (empty($threadhold2[$i])) {
  149. $threadhold2_str = 0;
  150. } else {
  151. $threadhold2_str = (int) $threadhold2[$i];
  152. }
  153. if (empty($threadhold3[$i])) {
  154. $threadhold3_str = 0;
  155. } else {
  156. $threadhold3_str = (int) $threadhold3[$i];
  157. }
  158. $threadhold_total = $threadhold1_str.';'.$threadhold2_str.';'.$threadhold3_str;
  159. if (isset($try[$i]) && $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. $url_str = '';
  170. if (isset($url[$i]) && !empty($url[$i])) {
  171. $url_str = $url[$i];
  172. }
  173. if ($select_question[$i] == '') {
  174. $question_str = 0;
  175. } else {
  176. $question_str = $select_question[$i];
  177. }
  178. $destination[$i] = $threadhold_total.'@@'.$try_str.'@@'.$lp_str.'@@'.$question_str.'@@'.$url_str;
  179. // checks if field is empty
  180. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  181. $msgErr = get_lang('Please give an answer');
  182. // clears answers already recorded into the Answer object
  183. $objAnswer->cancel();
  184. break;
  185. }
  186. if ($weighting[$i] <= 0 && $_SESSION['tmp_answers']['hotspot_type'][$i] != 'oar') {
  187. $msgErr = get_lang('You must give a positive score for each hotspots');
  188. // clears answers already recorded into the Answer object
  189. $objAnswer->cancel();
  190. break;
  191. }
  192. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  193. $msgErr = get_lang('You haven\'t drawn all your hotspots yet');
  194. // clears answers already recorded into the Answer object
  195. $objAnswer->cancel();
  196. break;
  197. }
  198. }
  199. // now the noerror section
  200. $selectQuestionNoError = isset($_POST['select_question_noerror']) ? Security::remove_XSS($_POST['select_question_noerror']) : null;
  201. $lp_noerror = isset($_POST['lp_noerror']) ? Security::remove_XSS($_POST['lp_noerror']) : '';
  202. $try_noerror = isset($_POST['try_noerror']) ? Security::remove_XSS($_POST['try_noerror']) : null;
  203. $url_noerror = isset($_POST['url_noerror']) ? Security::remove_XSS($_POST['url_noerror']) : null;
  204. $comment_noerror = isset($_POST['comment_noerror']) ? Security::remove_XSS($_POST['comment_noerror']) : null;
  205. $threadhold_total = '0;0;0';
  206. if ($try_noerror == 'on') {
  207. $try_str = 1;
  208. } else {
  209. $try_str = 0;
  210. }
  211. if (empty($lp_noerror)) {
  212. $lp_str = 0;
  213. } else {
  214. $lp_str = $lp_noerror;
  215. }
  216. if ($url_noerror == '') {
  217. $url_str = '';
  218. } else {
  219. $url_str = $url_noerror;
  220. }
  221. if ($selectQuestionNoError == '') {
  222. $question_str = 0;
  223. } else {
  224. $question_str = $selectQuestionNoError;
  225. }
  226. $destination_noerror = $threadhold_total.'@@'.$try_str.'@@'.$lp_str.'@@'.$question_str.'@@'.$url_str;
  227. if (empty($msgErr)) {
  228. for ($i = 1; $i <= $nbrAnswers; $i++) {
  229. if ($debug > 0) {
  230. echo str_repeat('&nbsp;', 4).'$answerType is HOT_SPOT'."<br />\n";
  231. }
  232. $reponse[$i] = trim($reponse[$i]);
  233. $comment[$i] = trim($comment[$i]);
  234. $weighting[$i] = ($weighting[$i]); //it can be float
  235. if ($weighting[$i]) {
  236. $questionWeighting += $weighting[$i];
  237. }
  238. // creates answer
  239. $objAnswer->createAnswer(
  240. $reponse[$i],
  241. '',
  242. $comment[$i],
  243. $weighting[$i],
  244. $i,
  245. $hotspot_coordinates[$i],
  246. $hotspot_type[$i],
  247. $destination[$i]
  248. );
  249. } // end for()
  250. // saves the answers into the data base
  251. $objAnswer->createAnswer(
  252. 'noerror',
  253. '',
  254. $comment_noerror,
  255. '0',
  256. $nbrAnswers + 1,
  257. null,
  258. 'noerror',
  259. $destination_noerror
  260. );
  261. $objAnswer->save();
  262. // sets the total weighting of the question
  263. $objQuestion->updateWeighting($questionWeighting);
  264. $objQuestion->save($objExercise);
  265. $editQuestion = $questionId;
  266. unset($modifyAnswers);
  267. echo '<script type="text/javascript">window.location.href="'.$hotspot_admin_url
  268. .'&message=ItemUpdated"</script>';
  269. }
  270. }
  271. }
  272. if (isset($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 = isset($_POST['try']) ? $_POST['try'] : [];
  284. for ($i = 1; $i <= $nbrAnswers; $i++) {
  285. if (isset($try[$i]) && $try[$i] == 'on') {
  286. $try[$i] = 1;
  287. } else {
  288. $try[$i] = 0;
  289. }
  290. }
  291. if (isset($_POST['try_noerror']) && $_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. }
  306. $reponse = [];
  307. $comment = [];
  308. $weighting = [];
  309. $hotspot_coordinates = [];
  310. $hotspot_type = [];
  311. $destination_items = [];
  312. $destination = [];
  313. for ($i = 1; $i <= $nbrAnswers; $i++) {
  314. $reponse[$i] = $objAnswer->selectAnswer($i);
  315. if ($objExercise->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  316. $comment[$i] = $objAnswer->selectComment($i);
  317. }
  318. $weighting[$i] = $objAnswer->selectWeighting($i);
  319. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($i);
  320. $hotspot_type[$i] = $objAnswer->selectHotspotType($i);
  321. if ($answerType == HOT_SPOT_DELINEATION) {
  322. $destination[$i] = $objAnswer->selectDestination($i);
  323. if (empty($destination[$i])) {
  324. $destination[$i] = ';;;@@@@@@@@';
  325. }
  326. $destination_items = explode('@@', $destination[$i]);
  327. $threadhold_total = $destination_items[0];
  328. $threadhold_items = explode(';', $threadhold_total);
  329. $threadhold1[$i] = $threadhold_items[0];
  330. $threadhold2[$i] = $threadhold_items[1];
  331. $threadhold3[$i] = $threadhold_items[2];
  332. $try[$i] = $destination_items[1];
  333. $lp[$i] = $destination_items[2];
  334. $select_question[$i] = $destination_items[3];
  335. $url[$i] = $destination_items[4];
  336. }
  337. }
  338. }
  339. if ($answerType == HOT_SPOT_DELINEATION) {
  340. //added the noerror answer
  341. $comment_noerror = $objAnswer->selectComment($nbrAnswers + 1);
  342. $destination_noerror_list = $objAnswer->selectDestination($nbrAnswers + 1);
  343. if (empty($destination_noerror_list)) {
  344. $destination_noerror_list = '@@@@@@@@';
  345. }
  346. $destination_items = explode('@@', $destination_noerror_list);
  347. $try_noerror = $destination_items[1];
  348. $lp_noerror = $destination_items[2];
  349. $selectQuestionNoError = $destination_items[3];
  350. $url_noerror = $destination_items[4];
  351. }
  352. $_SESSION['tmp_answers'] = [];
  353. $_SESSION['tmp_answers']['answer'] = $reponse;
  354. if ($objExercise->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  355. $_SESSION['tmp_answers']['comment'] = $comment;
  356. }
  357. $_SESSION['tmp_answers']['weighting'] = $weighting;
  358. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  359. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  360. if ($answerType == HOT_SPOT_DELINEATION) {
  361. $_SESSION['tmp_answers']['destination'] = isset($destination) ? $destination : null;
  362. }
  363. $lessAnswers = isset($_POST['lessAnswers']) ? true : false;
  364. if ($lessAnswers) {
  365. if ($answerType == HOT_SPOT_DELINEATION) {
  366. $lest_answer = 1;
  367. // At least 1 answer
  368. if ($nbrAnswers > $lest_answer) {
  369. $nbrAnswers--;
  370. // Remove the last answer
  371. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  372. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  373. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  374. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  375. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  376. if (is_array($_SESSION['tmp_answers']['destination'])) {
  377. $tmp = array_pop($_SESSION['tmp_answers']['destination']);
  378. }
  379. } else {
  380. $msgErr = get_lang('You have to create one (1) hotspot at least.');
  381. }
  382. } else {
  383. // At least 1 answer
  384. if ($nbrAnswers > 1) {
  385. $nbrAnswers--;
  386. // Remove the last answer
  387. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  388. if ($objExercise->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  389. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  390. }
  391. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  392. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  393. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  394. } else {
  395. $msgErr = get_lang('You have to create one (1) hotspot at least.');
  396. }
  397. }
  398. }
  399. $moreAnswers = isset($_POST['moreAnswers']) ? true : false;
  400. if ($moreAnswers) {
  401. if ($nbrAnswers < 12) {
  402. $nbrAnswers++;
  403. // Add a new answer
  404. $_SESSION['tmp_answers']['answer'][] = '';
  405. if ($objExercise->getFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  406. $_SESSION['tmp_answers']['comment'][] = '';
  407. }
  408. $_SESSION['tmp_answers']['weighting'][] = '1';
  409. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  410. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  411. $_SESSION['tmp_answers']['destination'][] = '';
  412. } else {
  413. $msgErr = get_lang('The maximum hotspots you can create is twelve (12).');
  414. }
  415. }
  416. $moreOARAnswers = isset($_POST['moreOARAnswers']) ? true : false;
  417. if ($moreOARAnswers) {
  418. if ($nbrAnswers < 12) {
  419. // Add a new answer
  420. $nbrAnswers++;
  421. $_SESSION['tmp_answers']['answer'][] = '';
  422. $_SESSION['tmp_answers']['comment'][] = '';
  423. $_SESSION['tmp_answers']['weighting'][] = '1';
  424. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  425. $_SESSION['tmp_answers']['hotspot_type'][] = 'oar';
  426. $_SESSION['tmp_answers']['destination'][] = '';
  427. } else {
  428. $msgErr = get_lang('The maximum hotspots you can create is twelve (12).');
  429. }
  430. }
  431. if ($debug > 0) {
  432. echo str_repeat('&nbsp;', 2).'$usedInSeveralExercises is untrue'."<br />\n";
  433. }
  434. if ($debug > 0) {
  435. echo str_repeat('&nbsp;', 4).'$answerType is HOT_SPOT'."<br />\n";
  436. }
  437. if ($answerType == HOT_SPOT_DELINEATION) {
  438. $hotspot_colors = [
  439. "",
  440. "#4271B5",
  441. "#FE8E16",
  442. "#45C7F0",
  443. "#BCD631",
  444. "#D63173",
  445. "#D7D7D7",
  446. "#90AFDD",
  447. "#AF8640",
  448. "#4F9242",
  449. "#F4EB24",
  450. "#ED2024",
  451. "#3B3B3B",
  452. ];
  453. } else {
  454. $hotspot_colors = [
  455. "", // $i starts from 1 on next loop (ugly fix)
  456. "#4271B5",
  457. "#FE8E16",
  458. "#45C7F0",
  459. "#BCD631",
  460. "#D63173",
  461. "#D7D7D7",
  462. "#90AFDD",
  463. "#AF8640",
  464. "#4F9242",
  465. "#F4EB24",
  466. "#ED2024",
  467. "#3B3B3B",
  468. "#F7BDE2",
  469. ];
  470. }
  471. Display::tag(
  472. 'h3',
  473. get_lang('Question').": ".$questionName.Display::return_icon('info3.gif', strip_tags(get_lang('To create a hotspot: select a shape next to the colour, and draw the hotspot. To move a hotspot, select the colour, click another spot in the image, and draw the hotspot. To add a hotspot: click the Add hotspot button. To close a polygon shape: right click and select Close polygon.')))
  474. );
  475. if (!empty($msgErr)) {
  476. echo Display::return_message($msgErr, 'normal'); //main API
  477. }
  478. $hotspot_admin_url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&'
  479. .http_build_query(['hotspotadmin' => $modifyAnswers, 'exerciseId' => $exerciseId]); ?>
  480. <form method="post" action="<?php echo $hotspot_admin_url; ?>" class="form-horizontal" id="frm_exercise"
  481. name="frm_exercise">
  482. <div class="form-group">
  483. <div class="col-sm-12">
  484. <?php if ($answerType == HOT_SPOT_DELINEATION) {
  485. ?>
  486. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  487. <em class="fa fa-trash"></em> <?php echo get_lang('Less areas at risk'); ?>
  488. </button>
  489. <button type="submit" class="btn btn-primary" name="moreArea to avoidAnswers" value="moreArea to avoidAnswers">
  490. <em class="fa fa-plus"></em> <?php echo get_lang('More areas at risk'); ?>
  491. </button>
  492. <?php
  493. } else {
  494. ?>
  495. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  496. <em class="fa fa-trash"></em> <?php echo get_lang('Remove hotspot'); ?>
  497. </button>
  498. <button type="submit" class="btn btn-primary" name="moreAnswers" value="moreAnswers">
  499. <em class="fa fa-plus"></em> <?php echo get_lang('Add hotspot'); ?>
  500. </button>
  501. <?php
  502. } ?>
  503. <button type="submit" class="btn btn-primary" name="submitAnswers" value="submitAnswers">
  504. <em class="fa fa-save"></em> <?php echo get_lang('Add this question to the test'); ?>
  505. </button>
  506. </div>
  507. </div>
  508. <input type="hidden" name="formSent" value="1"/>
  509. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>"/>
  510. <div class="table-responsive">
  511. <table class="table table-striped table-hover">
  512. <thead>
  513. <tr>
  514. <th width="5">&nbsp;</th>
  515. <th><?php echo get_lang('Now click on : (...)'); ?> *</th>
  516. <?php
  517. if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  518. echo '<th>'.get_lang('Comment').'</th>';
  519. if ($answerType == HOT_SPOT_DELINEATION) {
  520. echo '<th >'.get_lang('Scenario').'</th>';
  521. }
  522. } else {
  523. echo '<th colspan="2">'.get_lang('Comment').'</th>';
  524. } ?>
  525. <th><?php echo get_lang('Score'); ?> *</th>
  526. </tr>
  527. </thead>
  528. <tbody>
  529. <?php
  530. $list = new LearnpathList(api_get_user_id());
  531. // Loading list of LPs
  532. $flat_list = $list->get_flat_list();
  533. for ($i = 1; $i <= $nbrAnswers; $i++) {
  534. // is an delineation
  535. if ($answerType == HOT_SPOT_DELINEATION) {
  536. $option_lp = '';
  537. // setting the LP
  538. $isSelected = false;
  539. foreach ($flat_list as $id => $details) {
  540. $selected = '';
  541. if (isset($lp[$i]) && $id == $lp[$i]) {
  542. $isSelected = true;
  543. $selected = 'selected="selected"';
  544. }
  545. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  546. }
  547. if ($isSelected) {
  548. $option_lp = '<option value="0">'.get_lang('Select target course').'</option>'.$option_lp;
  549. } else {
  550. $option_lp = '<option value="0" selected="selected" >'.get_lang('Select target course')
  551. .'</option>'.$option_lp;
  552. }
  553. // Feedback SELECT
  554. $question_list = $objExercise->selectQuestionList();
  555. $option_feed = '';
  556. $option_feed .= '<option value="0">'.get_lang('Select target question').'</option>';
  557. foreach ($question_list as $key => $questionid) {
  558. $selected = '';
  559. $question = Question::read($questionid);
  560. $questionTitle = strip_tags($question->selectTitle());
  561. $val = "Q$key: $questionTitle";
  562. if (isset($select_question[$i]) && $questionid == $select_question[$i]) {
  563. $selected = 'selected="selected"';
  564. }
  565. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  566. }
  567. if (isset($select_question[$i]) && $select_question[$i] == -1) {
  568. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('Exit test').'</option>';
  569. } else {
  570. $option_feed .= '<option value="-1">'.get_lang('Exit test').'</option>';
  571. }
  572. //-------- IF it is a delineation
  573. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  574. $option1 = $option2 = $option3 = '';
  575. for ($k = 1; $k <= 100; $k++) {
  576. $selected1 = $selected2 = $selected3 = '';
  577. if ($k == $threadhold1[$i]) {
  578. $selected1 = 'selected="selected"';
  579. }
  580. if ($k == $threadhold2[$i]) {
  581. $selected2 = 'selected="selected"';
  582. }
  583. if ($k == $threadhold3[$i]) {
  584. $selected3 = 'selected="selected"';
  585. }
  586. $option1 .= '<option '.$selected1.' >'.$k.' % </option>';
  587. $option2 .= '<option '.$selected2.' >'.$k.' % </option>';
  588. $option3 .= '<option '.$selected3.'>'.$k.' %</option>';
  589. } ?>
  590. <tr>
  591. <td>
  592. <span class="fa fa-square fa-2x" aria-hidden="true"
  593. style="color: <?php echo $hotspot_colors[$i]; ?>;"></span>
  594. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation"/>
  595. </td>
  596. <td>
  597. <p><strong><?php echo get_lang('Delineation'); ?></strong></p>
  598. <p>
  599. <?php echo get_lang('Minimum overlap'); ?>
  600. <select class="form-control" name="threadhold1[<?php echo $i; ?>]">
  601. <?php echo $option1; ?>
  602. </select>
  603. </p>
  604. <p>
  605. <?php echo get_lang('Maximum excess'); ?>
  606. <select class="form-control" name="threadhold2[<?php echo $i; ?>]">
  607. <?php echo $option2; ?>
  608. </select>
  609. </p>
  610. <p>
  611. <?php echo get_lang('Maximum missing'); ?>
  612. <select class="form-control" name="threadhold3[<?php echo $i; ?>]">
  613. <?php echo $option3; ?>
  614. </select>
  615. </p>
  616. </td>
  617. <td align="left">
  618. <p>
  619. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  620. name="comment[<?php echo $i; ?>]"
  621. aria-describedBy="comment-<?php echo $i; ?>-help"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  622. <span id="comment-<?php echo $i; ?>-help"
  623. class="help-block"><?php echo get_lang('This message, as well as the results table, will appear to the learner if he fails this step'); ?></span>
  624. </p>
  625. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation"/>
  626. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  627. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  628. </td>
  629. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  630. ?>
  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) {
  637. echo 'checked';
  638. } ?> />
  639. <?php echo get_lang('Try again'); ?>
  640. </label>
  641. </p>
  642. </div>
  643. <p>
  644. <?php echo get_lang('Theory link'); ?>
  645. <select class="form-control" name="lp[<?php echo $i; ?>]">
  646. <?php echo $option_lp; ?>
  647. </select>
  648. </p>
  649. <p>
  650. <?php echo get_lang('Other'); ?>
  651. <input class="form-control" name="url[<?php echo $i; ?>]"
  652. value="<?php echo $url[$i]; ?>">
  653. </p>
  654. <p>
  655. <?php echo get_lang('Select question'); ?>
  656. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  657. <?php echo $option_feed; ?>
  658. </select>
  659. </p>
  660. </td>
  661. <?php
  662. } else {
  663. ?>
  664. <td> &nbsp;</td>
  665. <?php
  666. }
  667. } elseif (false) {
  668. ?>
  669. <tr>
  670. <th colspan="2"><?php echo get_lang('If no error'); ?></th>
  671. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  672. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  673. <th></th>
  674. </tr>
  675. <tr>
  676. <td colspan="2">
  677. <?php echo get_lang('The learner made no mistake'); ?>
  678. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror"/>
  679. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0"/>
  680. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror"/>
  681. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0"/>
  682. </td>
  683. <td align="left">
  684. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  685. name="comment[<?php echo $i; ?>]"
  686. style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  687. </td>
  688. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  689. ?>
  690. <td>
  691. <table>
  692. <tr>
  693. <td>
  694. <div class="checkbox">
  695. <p>
  696. <label>
  697. <input type="checkbox" class="checkbox"
  698. name="<?php echo 'try['
  699. .$i; ?>]" <?php if ($try[$i] == 1) {
  700. echo 'checked';
  701. } ?> />
  702. <?php echo get_lang('Try again'); ?>
  703. </label>
  704. </p>
  705. </div>
  706. <p>
  707. <?php echo get_lang('Theory link'); ?>
  708. <select class="form-control" name="lp[<?php echo $i; ?>]">
  709. <?php echo $option_lp; ?>
  710. </select>
  711. </p>
  712. <p>
  713. <?php echo get_lang('Other'); ?> <br/>
  714. <input class="form-control" name="url[<?php echo $i; ?>]"
  715. value="<?php echo $url[$i]; ?>">
  716. </p>
  717. <p>
  718. <?php echo get_lang('Select question'); ?> <br/>
  719. <select class="form-control"
  720. name="select_question[<?php echo $i; ?>]">
  721. <?php echo $option_feed; ?>
  722. </select>
  723. </p>
  724. </td>
  725. </tr>
  726. </table>
  727. </td>
  728. <?php
  729. } else {
  730. ?>
  731. <td>&nbsp;</td>
  732. <?php
  733. } ?>
  734. </tr>
  735. <?php
  736. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  737. // if it's an Area to avoid
  738. if ($i == 2) {
  739. ?>
  740. <tr>
  741. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  742. <th><?php echo get_lang('Area to avoid'); ?>*</th>
  743. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  744. ?>
  745. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  746. <th><?php if ($answerType == HOT_SPOT_DELINEATION) {
  747. echo get_lang('Scenario');
  748. } ?></th>
  749. <?php
  750. } else {
  751. ?>
  752. <th colspan="3"><?php echo get_lang('Comment'); ?></th>
  753. <?php
  754. } ?>
  755. <th>&nbsp;</th>
  756. </tr>
  757. <?php
  758. } ?>
  759. <tr>
  760. <td>
  761. <span class="fa fa-square fa-2x" aria-hidden="true"
  762. style="color: <?php echo $hotspot_colors[$i]; ?>"></span>
  763. </td>
  764. <td>
  765. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  766. value="<?php echo isset($reponse[$i]) ? Security::remove_XSS($reponse[$i]) : ''; ?>"/>
  767. </td>
  768. <td colspan="2" align="left">
  769. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  770. name="comment[<?php echo $i; ?>]"
  771. style="width: 100%"><?php echo isset($comment[$i]) ? Security::remove_XSS($comment[$i]) : ''; ?></textarea>
  772. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar"/>
  773. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  774. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  775. </td>
  776. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  777. ?>
  778. <td>
  779. <div class="checkbox">
  780. <p>
  781. <label>
  782. <input type="checkbox" class="checkbox"
  783. name="<?php echo 'try['.$i; ?>]" <?php if (isset($try[$i]) && $try[$i] == 1) {
  784. echo 'checked';
  785. } ?> />
  786. <?php echo get_lang('Try again'); ?>
  787. </label>
  788. </p>
  789. </div>
  790. <p>
  791. <?php echo get_lang('Theory link'); ?>
  792. <select class="form-control" name="lp[<?php echo $i; ?>]">
  793. <?php echo $option_lp; ?>
  794. </select>
  795. </p>
  796. <p>
  797. <?php echo get_lang('Other'); ?>
  798. <input class="form-control" name="url[<?php echo $i; ?>]"
  799. value="<?php echo isset($url[$i]) ? $url[$i] : ''; ?>">
  800. </p>
  801. <p>
  802. <?php echo get_lang('Select question'); ?>
  803. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  804. <?php echo $option_feed; ?>
  805. </select>
  806. </p>
  807. </td>
  808. <?php
  809. } else {
  810. ?>
  811. <td>&nbsp;</td>
  812. <?php
  813. }
  814. }
  815. //end if is delineation
  816. } else {
  817. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  818. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null; ?>
  819. <tr>
  820. <td>
  821. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>"
  822. aria-hidden="true"></span>
  823. </td>
  824. <td>
  825. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  826. value="<?php echo Security::remove_XSS($responseValue); ?>"/>
  827. </td>
  828. <?php
  829. $form = new FormValidator('form_'.$i);
  830. $config = [
  831. 'ToolbarSet' => 'TestProposedAnswer',
  832. 'cols-size' => [0, 12, 0],
  833. ];
  834. $form->addHtmlEditor('comment['.$i.']', null, false, false, $config);
  835. $renderer = $form->defaultRenderer();
  836. $form_template = '{content}';
  837. $renderer->setFormTemplate($form_template);
  838. $element_template = '{label} {element}';
  839. $renderer->setElementTemplate($element_template);
  840. $form->setDefaults(['comment['.$i.']' => $commentValue]);
  841. $return = $form->returnForm(); ?>
  842. <td colspan="2" align="left"><?php echo $return; ?></td>
  843. <?php
  844. } ?>
  845. <td>
  846. <?php
  847. if ($answerType == HOT_SPOT_DELINEATION) {
  848. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  849. ?>
  850. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="form-cotrol" value="0"/>
  851. <?php
  852. } else {
  853. ?>
  854. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  855. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  856. <?php
  857. }
  858. }
  859. if ($answerType == HOT_SPOT) {
  860. ?>
  861. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  862. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  863. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]"
  864. value="<?php echo empty($hotspot_coordinates[$i])
  865. ? '0;0|0|0'
  866. : $hotspot_coordinates[$i]; ?>"/>
  867. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]"
  868. value="<?php echo empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]; ?>"/>
  869. <?php
  870. } ?>
  871. </td>
  872. </tr>
  873. <?php
  874. }
  875. $list = new LearnpathList(api_get_user_id());
  876. $flat_list = $list->get_flat_list();
  877. $option_lp = '';
  878. $isSelected = false;
  879. foreach ($flat_list as $id => $details) {
  880. $selected = '';
  881. if (isset($lp_noerror) && $id == $lp_noerror) {
  882. $selected = 'selected="selected"';
  883. $isSelected = true;
  884. }
  885. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  886. }
  887. if ($isSelected) {
  888. $option_lp = '<option value="0">'.get_lang('Select target course').'</option>'.$option_lp;
  889. } else {
  890. $option_lp = '<option value="0" selected="selected" >'.get_lang('Select target course').'</option>'
  891. .$option_lp;
  892. }
  893. // Feedback SELECT
  894. $question_list = $objExercise->selectQuestionList();
  895. $option_feed = '';
  896. $option_feed .= '<option value="0">'.get_lang('Select target question').'</option>';
  897. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  898. foreach ($question_list as $key => $questionid) {
  899. $selected = '';
  900. $question = Question::read($questionid);
  901. $questionTitle = $question->selectTitle();
  902. $val = "Q$key: $questionTitle";
  903. if ($questionid == $selectQuestionNoError) {
  904. $selected = 'selected="selected"';
  905. }
  906. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  907. }
  908. if ($selectQuestionNoError == -1) {
  909. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('Exit test').'</option>';
  910. } else {
  911. $option_feed .= '<option value="-1">'.get_lang('Exit test').'</option>';
  912. }
  913. if ($answerType == HOT_SPOT_DELINEATION) {
  914. ?>
  915. <tr>
  916. <th colspan="2"><?php echo get_lang('If no error'); ?></th>
  917. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  918. ?>
  919. <th colspan="2"><?php echo get_lang('Feedback'); ?></th>
  920. <th><?php echo get_lang('Scenario'); ?></th>
  921. <?php
  922. } else {
  923. ?>
  924. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  925. <?php
  926. } ?>
  927. <th>&nbsp;</th>
  928. </tr>
  929. <tr>
  930. <td colspan="2">
  931. <?php echo get_lang('The learner made no mistake'); ?>
  932. </td>
  933. <td colspan="2" align="left">
  934. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  935. name="comment_noerror"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  936. </td>
  937. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  938. ?>
  939. <td>
  940. <div class="checkbox">
  941. <p>
  942. <label>
  943. <input type="checkbox" class="checkbox"
  944. name="try_noerror" <?php if ($try_noerror == 1) {
  945. echo 'checked';
  946. } ?> />
  947. <?php echo get_lang('Try again'); ?>
  948. </label>
  949. </p>
  950. </div>
  951. <p>
  952. <?php echo get_lang('Theory link'); ?> <br/>
  953. <select class="form-control" name="lp_noerror">
  954. <?php echo $option_lp; ?>
  955. </select>
  956. </p>
  957. <p>
  958. <?php echo get_lang('Other'); ?> <br/>
  959. <input class="form-control" name="url_noerror" value="<?php echo $url_noerror; ?>">
  960. </p>
  961. <p>
  962. <?php echo get_lang('Select question'); ?> <br/>
  963. <select class="form-control" name="select_question_noerror">
  964. <?php echo $option_feed; ?>
  965. </select>
  966. </p>
  967. </td>
  968. <td>&nbsp;</td>
  969. <?php
  970. } else {
  971. ?>
  972. <td colspan="2">&nbsp;</td>
  973. <?php
  974. } ?>
  975. </tr>
  976. <?php
  977. } ?>
  978. </tbody>
  979. </table>
  980. </div>
  981. <div class="row">
  982. <div class="col-xs-12">
  983. <?php
  984. $relPath = api_get_path(WEB_CODE_PATH); ?>
  985. <div id="hotspot-container" class="center-block"></div>
  986. </div>
  987. </div>
  988. </form>
  989. <script>
  990. $(function () {
  991. <?php if ($answerType == HOT_SPOT_DELINEATION) {
  992. ?>
  993. new DelineationQuestion({
  994. questionId: <?php echo $modifyAnswers; ?>,
  995. selector: '#hotspot-container',
  996. for: 'admin',
  997. relPath: '<?php echo $relPath; ?>'
  998. });
  999. <?php
  1000. } else {
  1001. ?>
  1002. new HotspotQuestion({
  1003. questionId: <?php echo $modifyAnswers; ?>,
  1004. selector: '#hotspot-container',
  1005. for: 'admin',
  1006. relPath: '<?php echo $relPath; ?>'
  1007. });
  1008. <?php
  1009. } ?>
  1010. });
  1011. </script>
  1012. <?php
  1013. if ($debug > 0) {
  1014. echo str_repeat('&nbsp;', 0).'$modifyAnswers was set - end'."<br />\n";
  1015. }
  1016. }