hotspot_admin.inc.php 49 KB

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