hotspot_admin.inc.php 51 KB

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