hotspot_admin.inc.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  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" 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 ($answerType == HOT_SPOT_DELINEATION) {
  504. echo '<th >' . get_lang('Thresholds') . '</th>';
  505. }
  506. if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  507. ?>
  508. <th><?php echo get_lang('Comment'); ?></th>
  509. <?php
  510. if ($answerType == HOT_SPOT_DELINEATION) {
  511. echo '<th >' . get_lang('Scenario') . '</th>';
  512. }
  513. ?>
  514. <?php
  515. } else {
  516. ?>
  517. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  518. <?php } ?>
  519. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  520. </tr>
  521. </thead>
  522. <tbody>
  523. <?php
  524. $list = new LearnpathList(api_get_user_id());
  525. // Loading list of LPs
  526. $flat_list = $list->get_flat_list();
  527. for ($i = 1; $i <= $nbrAnswers; $i++) {
  528. // is an delineation
  529. if ($answerType == HOT_SPOT_DELINEATION) {
  530. $select_lp_id = array();
  531. $option_lp = '';
  532. // setting the LP
  533. $isSelected = false;
  534. foreach ($flat_list as $id => $details) {
  535. $select_lp_id[$id] = $details['lp_name'];
  536. $selected = '';
  537. if ($id == $lp[$i]) {
  538. $isSelected = true;
  539. $selected = 'selected="selected"';
  540. }
  541. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  542. }
  543. if ($isSelected) {
  544. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  545. } else {
  546. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  547. }
  548. // Feedback SELECT
  549. $question_list = $objExercise->selectQuestionList();
  550. $option_feed = '';
  551. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  552. foreach ($question_list as $key => $questionid) {
  553. $selected = '';
  554. $question = Question::read($questionid);
  555. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  556. $select_lp_id[$id] = $details['lp_name'];
  557. if ($questionid == $select_question[$i]) {
  558. $selected = 'selected="selected"';
  559. }
  560. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  561. }
  562. if ($select_question[$i] == -1) {
  563. $option_feed .= '<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  564. } else {
  565. $option_feed .= '<option value="-1">' . get_lang('ExitTest') . '</option>';
  566. }
  567. //-------- IF it is a delineation
  568. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  569. for ($k = 1; $k <= 100; $k++) {
  570. $selected1 = $selected2 = $selected3 = '';
  571. if ($k == $threadhold1[$i])
  572. $selected1 = 'selected="selected"';
  573. if ($k == $threadhold2[$i])
  574. $selected2 = 'selected="selected"';
  575. if ($k == $threadhold3[$i])
  576. $selected3 = 'selected="selected"';
  577. $option1.='<option ' . $selected1 . ' >' . $k . '</option>';
  578. $option2.='<option ' . $selected2 . ' >' . $k . '</option>';
  579. $option3.='<option ' . $selected3 . '>' . $k . '</option>';
  580. }
  581. ?>
  582. <tr>
  583. <td>
  584. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  585. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  586. </td>
  587. <td>
  588. <b><?php echo get_lang('Delineation'); ?></b><br /><br />
  589. <?php echo get_lang('MinOverlap'); ?><br/><br/>
  590. <?php echo get_lang('MaxExcess'); ?><br/><br/>
  591. <?php echo get_lang('MaxMissing'); ?><br/><br/>
  592. </td>
  593. <td>
  594. <br/><br/>
  595. <select name="threadhold1[<?php echo $i; ?>]" >
  596. <?php echo $option1; ?>
  597. </select>%
  598. <br/><br/>
  599. <select name="threadhold2[<?php echo $i; ?>]" >
  600. <?php echo $option2; ?>
  601. </select>%
  602. <br/><br/>
  603. <select name="threadhold3[<?php echo $i; ?>]" >
  604. <?php echo $option3; ?>
  605. </select>%
  606. <br/>
  607. </td>
  608. <td align="left">
  609. <br />
  610. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%">
  611. <?php echo Security::remove_XSS($comment[$i]); ?>
  612. </textarea>
  613. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  614. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  615. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  616. ?>" />
  617. <br/>
  618. <?php echo get_lang('LearnerIsInformed'); ?>
  619. </td>
  620. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  621. <td>
  622. <table>
  623. <tr>
  624. <td>
  625. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  626. <?php echo get_lang('TryAgain'); ?><br /><br />
  627. <?php echo get_lang('SeeTheory'); ?><br />
  628. <select name="lp[<?php echo $i; ?>]" >
  629. <?php echo $option_lp; ?>
  630. </select>
  631. <br /><br />
  632. <?php echo get_lang('Other'); ?> <br />
  633. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  634. <br /> <br />
  635. <?php echo get_lang('SelectQuestion'); ?> <br />
  636. <select name="select_question[<?php echo $i; ?>]" >
  637. <?php echo $option_feed; ?>
  638. </select>
  639. </td>
  640. </tr>
  641. </table>
  642. </td>
  643. <?php } else { ?>
  644. <td> &nbsp;</td>
  645. <?php
  646. }
  647. } elseif (false) {
  648. ?>
  649. <tr>
  650. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  651. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  652. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  653. <th></th>
  654. </tr>
  655. <tr>
  656. <td colspan="2">
  657. <?php echo get_lang('LearnerHasNoMistake'); ?>
  658. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  659. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  660. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  661. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  662. </td>
  663. <td colspan="2" align="left">
  664. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  665. </td>
  666. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  667. <td>
  668. <table>
  669. <tr>
  670. <td>
  671. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  672. <?php echo get_lang('TryAgain'); ?>
  673. <br /><br />
  674. <?php echo get_lang('SeeTheory'); ?>
  675. <br />
  676. <select name="lp[<?php echo $i; ?>]" >
  677. <?php echo $option_lp; ?>
  678. </select>
  679. <br /><br />
  680. <?php echo get_lang('Other'); ?> <br />
  681. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  682. <br /> <br />
  683. <?php echo get_lang('SelectQuestion'); ?> <br />
  684. <select name="select_question[<?php echo $i; ?>]">
  685. <?php echo $option_feed; ?>
  686. </select>
  687. </td>
  688. </tr>
  689. </table>
  690. </td>
  691. <?php } else { ?>
  692. <td>&nbsp;</td>
  693. <?php } ?>
  694. </tr>
  695. <?php
  696. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  697. // if it's an OAR
  698. if ($i == 2) {
  699. ?>
  700. <tr>
  701. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  702. <th ><?php echo get_lang('OAR'); ?>*</th>
  703. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  704. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  705. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  706. <?php } else { ?>
  707. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  708. <?php } ?>
  709. <th>&nbsp;</th>
  710. </tr>
  711. <?php } ?>
  712. <tr>
  713. <td>
  714. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  715. </td>
  716. <td>
  717. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" />
  718. </td>
  719. <td colspan="2" align="left">
  720. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  721. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  722. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  723. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  724. ?>" />
  725. </td>
  726. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  727. <td>
  728. <table>
  729. <tr>
  730. <td>
  731. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  732. <?php echo get_lang('TryAgain'); ?>
  733. <br /><br />
  734. <?php echo get_lang('SeeTheory'); ?> <br />
  735. <select name="lp[<?php echo $i; ?>]" >
  736. <?php echo $option_lp; ?>
  737. </select>
  738. <br /><br />
  739. <?php echo get_lang('Other'); ?> <br />
  740. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  741. <br /><br />
  742. <?php echo get_lang('SelectQuestion'); ?> <br />
  743. <select name="select_question[<?php echo $i; ?>]">
  744. <?php echo $option_feed; ?>
  745. </select>
  746. </td>
  747. </tr>
  748. </table>
  749. </td>
  750. <?php } else { ?>
  751. <td>&nbsp;</td>
  752. <?php
  753. }
  754. }
  755. //end if is delineation
  756. } else {
  757. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  758. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null;
  759. ?>
  760. <tr>
  761. <td>
  762. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>" aria-hidden="true"></span>
  763. </td>
  764. <td>
  765. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($responseValue); ?>" />
  766. </td>
  767. <?php
  768. $form = new FormValidator('form_' . $i);
  769. $config = array(
  770. 'ToolbarSet' => 'TestProposedAnswer',
  771. 'cols-size' => [0, 12, 0]
  772. );
  773. $form->addHtmlEditor('comment[' . $i . ']', null, false, false, $config);
  774. $renderer = $form->defaultRenderer();
  775. $form_template = '{content}';
  776. $renderer->setFormTemplate($form_template);
  777. $element_template = '
  778. {label}
  779. {element}';
  780. $renderer->setElementTemplate($element_template);
  781. $form->setDefaults(array('comment[' . $i . ']' => $commentValue));
  782. $return = $form->return_form();
  783. ?>
  784. <td colspan="2" align="left" ><?php echo $return; ?></td>
  785. <?php } ?>
  786. <td>
  787. <?php
  788. if ($answerType == HOT_SPOT_DELINEATION) {
  789. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  790. ?>
  791. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
  792. <?php } else { ?>
  793. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  794. <?php
  795. }
  796. }
  797. if ($answerType == HOT_SPOT) {
  798. ?>
  799. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  800. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  801. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  802. <?php } ?>
  803. </td>
  804. </tr>
  805. <?php
  806. }
  807. $list = new LearnpathList(api_get_user_id());
  808. $flat_list = $list->get_flat_list();
  809. $select_lp_id = array();
  810. $option_lp = '';
  811. $isSelected = false;
  812. foreach ($flat_list as $id => $details) {
  813. $selected = '';
  814. $select_lp_id[$id] = $details['lp_name'];
  815. if (isset($lp_noerror) && $id == $lp_noerror) {
  816. $selected = 'selected="selected"';
  817. $isSelected = true;
  818. }
  819. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  820. }
  821. if ($isSelected) {
  822. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  823. } else {
  824. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  825. }
  826. // Feedback SELECT
  827. $question_list = $objExercise->selectQuestionList();
  828. $option_feed = '';
  829. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  830. $details = isset($details) ? $details : null;
  831. $id = isset($id) ? $id : 0;
  832. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  833. foreach ($question_list as $key => $questionid) {
  834. $selected = '';
  835. $question = Question::read($questionid);
  836. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  837. $select_lp_id[$id] = $details['lp_name'];
  838. if ($questionid == $selectQuestionNoError) {
  839. $selected = 'selected="selected"';
  840. }
  841. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  842. }
  843. if ($selectQuestionNoError == -1) {
  844. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  845. } else {
  846. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  847. }
  848. if ($answerType == HOT_SPOT_DELINEATION) {
  849. ?>
  850. <tr>
  851. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  852. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  853. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  854. <th><?php echo get_lang('Scenario'); ?></th>
  855. <?php } else { ?>
  856. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  857. <?php } ?>
  858. <th>&nbsp;</th>
  859. </tr>
  860. <tr>
  861. <td colspan="2">
  862. <?php echo get_lang('LearnerHasNoMistake'); ?>
  863. </td>
  864. <td colspan="2" align="left">
  865. <textarea wrap="virtual" rows="3" cols="25" name="comment_noerror" style="width: 100%"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  866. </td>
  867. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  868. <td>
  869. <table>
  870. <tr>
  871. <td>
  872. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  873. <?php echo get_lang('TryAgain'); ?>
  874. <br /><br />
  875. <?php echo get_lang('SeeTheory'); ?> <br />
  876. <select name="lp_noerror" >
  877. <?php echo $option_lp; ?>
  878. </select>
  879. <br /><br />
  880. <?php echo get_lang('Other'); ?> <br />
  881. <input name="url_noerror" value="<?php echo $url_noerror; ?>">
  882. <br /><br />
  883. <?php echo get_lang('SelectQuestion'); ?> <br />
  884. <select name="select_question_noerror">
  885. <?php echo $option_feed; ?>
  886. </select>
  887. </td>
  888. </tr>
  889. </table>
  890. </td>
  891. <td>&nbsp;</td>
  892. <?php } else { ?>
  893. <td colspan="2">&nbsp;</td>
  894. <?php } ?>
  895. </tr>
  896. <?php } ?>
  897. </tbody>
  898. </table>
  899. </div>
  900. <div class="row">
  901. <div class="col-xs-12">
  902. <?php
  903. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  904. $height = 450;
  905. ?>
  906. <div id="hotspot-container" class="center-block">
  907. </div>
  908. </div>
  909. </div>
  910. </form>
  911. <script>
  912. $(document).on('ready', function () {
  913. HotspotQuestion.init({
  914. questionId: <?php echo $modifyAnswers ?>,
  915. selector: '#hotspot-container',
  916. for: 'admin'
  917. });
  918. });
  919. </script>
  920. <?php
  921. if ($debug > 0) {
  922. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  923. }
  924. }