hotspot_admin.inc.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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->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) . '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($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 = isset($_POST['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 (isset($try[$i]) && $try[$i] == 'on') {
  160. $try_str = 1;
  161. } else {
  162. $try_str = 0;
  163. }
  164. if (empty($lp[$i])) {
  165. $lp_str = 0;
  166. } else {
  167. $lp_str = $lp[$i];
  168. }
  169. 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 = Security::remove_XSS($_POST['select_question_noerror']);
  202. $lp_noerror = Security::remove_XSS($_POST['lp_noerror']);
  203. $try_noerror = isset($_POST['try_noerror']) ? Security::remove_XSS($_POST['try_noerror']) : null;
  204. $url_noerror = Security::remove_XSS($_POST['url_noerror']);
  205. $comment_noerror = Security::remove_XSS($_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 = isset($_POST['try']) ? $_POST['try'] : [];
  284. for ($i = 1; $i <= $nbrAnswers; $i++) {
  285. if (isset($try[$i]) && $try[$i] == 'on') {
  286. $try[$i] = 1;
  287. } else {
  288. $try[$i] = 0;
  289. }
  290. }
  291. if (isset($_POST['try_noerror']) && $_POST['try_noerror'] == 'on') {
  292. $try_noerror = 1;
  293. } else {
  294. $try_noerror = 0;
  295. }
  296. }
  297. if (!$nbrAnswers) {
  298. $nbrAnswers = $objAnswer->selectNbrAnswers();
  299. if ($answerType == HOT_SPOT_DELINEATION) {
  300. // the magic happens here ...
  301. // we do this to not count the if no error section
  302. if ($nbrAnswers >= 2) {
  303. $nbrAnswers--;
  304. }
  305. }
  306. $reponse = array();
  307. $comment = array();
  308. $weighting = array();
  309. $hotspot_coordinates = array();
  310. $hotspot_type = array();
  311. $destination_items = array();
  312. $destination = array();
  313. for ($i = 1; $i <= $nbrAnswers; $i++) {
  314. $reponse[$i] = $objAnswer->selectAnswer($i);
  315. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  316. $comment[$i] = $objAnswer->selectComment($i);
  317. }
  318. $weighting[$i] = $objAnswer->selectWeighting($i);
  319. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($i);
  320. $hotspot_type[$i] = $objAnswer->selectHotspotType($i);
  321. if ($answerType == HOT_SPOT_DELINEATION) {
  322. $destination[$i] = $objAnswer->selectDestination($i);
  323. if (empty($destination[$i])) {
  324. $destination[$i] = ';;;@@@@@@@@';
  325. }
  326. $destination_items = explode('@@', $destination[$i]);
  327. $threadhold_total = $destination_items[0];
  328. $threadhold_items = explode(';', $threadhold_total);
  329. $threadhold1[$i] = $threadhold_items[0];
  330. $threadhold2[$i] = $threadhold_items[1];
  331. $threadhold3[$i] = $threadhold_items[2];
  332. $try[$i] = $destination_items[1];
  333. $lp[$i] = $destination_items[2];
  334. $select_question[$i] = $destination_items[3];
  335. $url[$i] = $destination_items[4];
  336. }
  337. }
  338. }
  339. if ($answerType == HOT_SPOT_DELINEATION) {
  340. //added the noerror answer
  341. $reponse_noerror = 'noerror';
  342. $comment_noerror = $objAnswer->selectComment($nbrAnswers + 1);
  343. $destination_noerror_list = $objAnswer->selectDestination($nbrAnswers + 1);
  344. if (empty($destination_noerror_list)) {
  345. $destination_noerror_list = '@@@@@@@@';
  346. }
  347. $destination_items = explode('@@', $destination_noerror_list);
  348. $try_noerror = $destination_items[1];
  349. $lp_noerror = $destination_items[2];
  350. $selectQuestionNoError = $destination_items[3];
  351. $url_noerror = $destination_items[4];
  352. }
  353. $_SESSION['tmp_answers'] = array();
  354. $_SESSION['tmp_answers']['answer'] = $reponse;
  355. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  356. $_SESSION['tmp_answers']['comment'] = $comment;
  357. }
  358. $_SESSION['tmp_answers']['weighting'] = $weighting;
  359. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  360. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  361. if ($answerType == HOT_SPOT_DELINEATION) {
  362. $_SESSION['tmp_answers']['destination'] = isset($destination) ? $destination : null;
  363. }
  364. $lessAnswers = isset($_POST['lessAnswers']) ? true : false;
  365. if ($lessAnswers) {
  366. if ($answerType == HOT_SPOT_DELINEATION) {
  367. $lest_answer = 1;
  368. // At least 1 answer
  369. if ($nbrAnswers > $lest_answer) {
  370. $nbrAnswers--;
  371. // Remove the last answer
  372. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  373. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  374. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  375. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  376. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  377. if (is_array($_SESSION['tmp_answers']['destination'])) {
  378. $tmp = array_pop($_SESSION['tmp_answers']['destination']);
  379. }
  380. } else {
  381. $msgErr = get_lang('MinHotspot');
  382. }
  383. } else {
  384. // At least 1 answer
  385. if ($nbrAnswers > 1) {
  386. $nbrAnswers--;
  387. // Remove the last answer
  388. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  389. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  390. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  391. }
  392. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  393. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  394. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  395. } else {
  396. $msgErr = get_lang('MinHotspot');
  397. }
  398. }
  399. }
  400. $moreAnswers = isset($_POST['moreAnswers']) ? true : false;
  401. if ($moreAnswers) {
  402. if ($nbrAnswers < 12) {
  403. $nbrAnswers++;
  404. // Add a new answer
  405. $_SESSION['tmp_answers']['answer'][] = '';
  406. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  407. $_SESSION['tmp_answers']['comment'][] = '';
  408. }
  409. $_SESSION['tmp_answers']['weighting'][] = '1';
  410. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  411. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  412. $_SESSION['tmp_answers']['destination'][] = '';
  413. } else {
  414. $msgErr = get_lang('MaxHotspot');
  415. }
  416. }
  417. $moreOARAnswers = isset($_POST['moreOARAnswers']) ? true : false;
  418. if ($moreOARAnswers) {
  419. if ($nbrAnswers < 12) {
  420. // Add a new answer
  421. $nbrAnswers++;
  422. $_SESSION['tmp_answers']['answer'][] = '';
  423. $_SESSION['tmp_answers']['comment'][] = '';
  424. $_SESSION['tmp_answers']['weighting'][] = '1';
  425. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  426. $_SESSION['tmp_answers']['hotspot_type'][] = 'oar';
  427. $_SESSION['tmp_answers']['destination'][] = '';
  428. } else {
  429. $msgErr = get_lang('MaxHotspot');
  430. }
  431. }
  432. if ($debug > 0) {
  433. echo str_repeat('&nbsp;', 2) . '$usedInSeveralExercises is untrue' . "<br />\n";
  434. }
  435. if ($debug > 0) {
  436. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  437. }
  438. if ($answerType == HOT_SPOT_DELINEATION) {
  439. $hotspot_colors = array(
  440. "",
  441. "#4271B5",
  442. "#FE8E16",
  443. "#45C7F0",
  444. "#BCD631",
  445. "#D63173",
  446. "#D7D7D7",
  447. "#90AFDD",
  448. "#AF8640",
  449. "#4F9242",
  450. "#F4EB24",
  451. "#ED2024",
  452. "#3B3B3B"
  453. );
  454. } else {
  455. $hotspot_colors = array(
  456. "", // $i starts from 1 on next loop (ugly fix)
  457. "#4271B5",
  458. "#FE8E16",
  459. "#45C7F0",
  460. "#BCD631",
  461. "#D63173",
  462. "#D7D7D7",
  463. "#90AFDD",
  464. "#AF8640",
  465. "#4F9242",
  466. "#F4EB24",
  467. "#ED2024",
  468. "#3B3B3B",
  469. "#F7BDE2"
  470. );
  471. }
  472. Display::tag(
  473. 'h3',
  474. get_lang('Question') . ": " . $questionName . Display::return_icon('info3.gif', strip_tags(get_lang('HotspotChoose')))
  475. );
  476. if (!empty($msgErr)) {
  477. Display::display_normal_message($msgErr); //main API
  478. }
  479. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercise/admin.php?' . api_get_cidreq() . '&hotspotadmin=' . $modifyAnswers . '&exerciseId=' . $exerciseId . '&' . api_get_cidreq();
  480. ?>
  481. <form method="post" action="<?php echo $hotspot_admin_url; ?>" class="form-horizontal" id="frm_exercise" name="frm_exercise">
  482. <div class="form-group">
  483. <div class="col-sm-12">
  484. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  485. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  486. <em class="fa fa-trash"></em> <?php echo get_lang('LessOAR'); ?>
  487. </button>
  488. <button type="submit" class="btn btn-primary" name="moreOARAnswers" value="moreOARAnswers">
  489. <em class="fa fa-plus"></em> <?php echo get_lang('MoreOAR'); ?>
  490. </button>
  491. <?php } else { ?>
  492. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  493. <em class="fa fa-trash"></em> <?php echo get_lang('LessHotspots'); ?>
  494. </button>
  495. <button type="submit" class="btn btn-primary" name="moreAnswers" value="moreAnswers">
  496. <em class="fa fa-plus"></em> <?php echo get_lang('MoreHotspots'); ?>
  497. </button>
  498. <?php } ?>
  499. <button type="submit" class="btn btn-primary" name="submitAnswers" value="submitAnswers">
  500. <em class="fa fa-save"></em> <?php echo get_lang('AddQuestionToExercise'); ?>
  501. </button>
  502. </div>
  503. </div>
  504. <input type="hidden" name="formSent" value="1" />
  505. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  506. <div class="table-responsive">
  507. <table class="table table-striped table-hover">
  508. <thead>
  509. <tr>
  510. <th width="5">&nbsp;</th>
  511. <th> <?php echo get_lang('HotspotDescription'); ?> *</th>
  512. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  513. <th><?php echo get_lang('Comment'); ?></th>
  514. <?php
  515. if ($answerType == HOT_SPOT_DELINEATION) {
  516. echo '<th >' . get_lang('Scenario') . '</th>';
  517. }
  518. } else { ?>
  519. <th colspan="2">
  520. <?php echo get_lang('Comment'); ?>
  521. </th>
  522. <?php } ?>
  523. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  524. </tr>
  525. </thead>
  526. <tbody>
  527. <?php
  528. $list = new LearnpathList(api_get_user_id());
  529. // Loading list of LPs
  530. $flat_list = $list->get_flat_list();
  531. for ($i = 1; $i <= $nbrAnswers; $i++) {
  532. // is an delineation
  533. if ($answerType == HOT_SPOT_DELINEATION) {
  534. $option_lp = '';
  535. // setting the LP
  536. $isSelected = false;
  537. foreach ($flat_list as $id => $details) {
  538. $selected = '';
  539. if ($id == $lp[$i]) {
  540. $isSelected = true;
  541. $selected = 'selected="selected"';
  542. }
  543. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  544. }
  545. if ($isSelected) {
  546. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  547. } else {
  548. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  549. }
  550. // Feedback SELECT
  551. $question_list = $objExercise->selectQuestionList();
  552. $option_feed = '';
  553. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  554. foreach ($question_list as $key => $questionid) {
  555. $selected = '';
  556. $question = Question::read($questionid);
  557. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  558. if (isset($select_question[$i]) && $questionid == $select_question[$i]) {
  559. $selected = 'selected="selected"';
  560. }
  561. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  562. }
  563. if (isset($select_question[$i]) && $select_question[$i] == -1) {
  564. $option_feed .= '<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  565. } else {
  566. $option_feed .= '<option value="-1">' . get_lang('ExitTest') . '</option>';
  567. }
  568. //-------- IF it is a delineation
  569. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  570. $option1 = $option2 = $option3 = '';
  571. for ($k = 1; $k <= 100; $k++) {
  572. $selected1 = $selected2 = $selected3 = '';
  573. if ($k == $threadhold1[$i])
  574. $selected1 = 'selected="selected"';
  575. if ($k == $threadhold2[$i])
  576. $selected2 = 'selected="selected"';
  577. if ($k == $threadhold3[$i])
  578. $selected3 = 'selected="selected"';
  579. $option1.='<option ' . $selected1 . ' >' . $k . ' % </option>';
  580. $option2.='<option ' . $selected2 . ' >' . $k . ' % </option>';
  581. $option3.='<option ' . $selected3 . '>' . $k . ' %</option>';
  582. }
  583. ?>
  584. <tr>
  585. <td>
  586. <span class="fa fa-square fa-2x" aria-hidden="true" style="color: <?php echo $hotspot_colors[$i]; ?>;"></span>
  587. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  588. </td>
  589. <td>
  590. <p><strong><?php echo get_lang('Delineation'); ?></strong></p>
  591. <p>
  592. <?php echo get_lang('MinOverlap'); ?>
  593. <select class="form-control" name="threadhold1[<?php echo $i; ?>]">
  594. <?php echo $option1; ?>
  595. </select>
  596. </p>
  597. <p>
  598. <?php echo get_lang('MaxExcess'); ?>
  599. <select class="form-control" name="threadhold2[<?php echo $i; ?>]" >
  600. <?php echo $option2; ?>
  601. </select>
  602. </p>
  603. <p>
  604. <?php echo get_lang('MaxMissing'); ?>
  605. <select class="form-control" name="threadhold3[<?php echo $i; ?>]" >
  606. <?php echo $option3; ?>
  607. </select>
  608. </p>
  609. </td>
  610. <td align="left">
  611. <p>
  612. <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>
  613. <span id="comment-<?php echo $i ?>-help" class="help-block"><?php echo get_lang('LearnerIsInformed'); ?></span>
  614. </p>
  615. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  616. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  617. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  618. ?>" />
  619. </td>
  620. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  621. <td>
  622. <div class="checkbox">
  623. <p>
  624. <label>
  625. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  626. <?php echo get_lang('TryAgain'); ?>
  627. </label>
  628. </p>
  629. </div>
  630. <p>
  631. <?php echo get_lang('SeeTheory'); ?>
  632. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  633. <?php echo $option_lp; ?>
  634. </select>
  635. </p>
  636. <p>
  637. <?php echo get_lang('Other'); ?>
  638. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  639. </p>
  640. <p>
  641. <?php echo get_lang('SelectQuestion'); ?>
  642. <select class="form-control" name="select_question[<?php echo $i; ?>]" >
  643. <?php echo $option_feed; ?>
  644. </select>
  645. </p>
  646. </td>
  647. <?php } else { ?>
  648. <td> &nbsp;</td>
  649. <?php
  650. }
  651. } elseif (false) {
  652. ?>
  653. <tr>
  654. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  655. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  656. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  657. <th></th>
  658. </tr>
  659. <tr>
  660. <td colspan="2">
  661. <?php echo get_lang('LearnerHasNoMistake'); ?>
  662. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  663. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  664. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  665. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  666. </td>
  667. <td align="left">
  668. <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>
  669. </td>
  670. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  671. <td>
  672. <table>
  673. <tr>
  674. <td>
  675. <div class="checkbox">
  676. <p>
  677. <label>
  678. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  679. <?php echo get_lang('TryAgain'); ?>
  680. </label>
  681. </p>
  682. </div>
  683. <p>
  684. <?php echo get_lang('SeeTheory'); ?>
  685. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  686. <?php echo $option_lp; ?>
  687. </select>
  688. </p>
  689. <p>
  690. <?php echo get_lang('Other'); ?> <br />
  691. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  692. </p>
  693. <p>
  694. <?php echo get_lang('SelectQuestion'); ?> <br />
  695. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  696. <?php echo $option_feed; ?>
  697. </select>
  698. </p>
  699. </td>
  700. </tr>
  701. </table>
  702. </td>
  703. <?php } else { ?>
  704. <td>&nbsp;</td>
  705. <?php } ?>
  706. </tr>
  707. <?php
  708. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  709. // if it's an OAR
  710. if ($i == 2) {
  711. ?>
  712. <tr>
  713. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  714. <th ><?php echo get_lang('OAR'); ?>*</th>
  715. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  716. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  717. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  718. <?php } else { ?>
  719. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  720. <?php } ?>
  721. <th>&nbsp;</th>
  722. </tr>
  723. <?php } ?>
  724. <tr>
  725. <td>
  726. <span class="fa fa-square fa-2x" aria-hidden="true" style="color: <?php echo $hotspot_colors[$i]; ?>"></span>
  727. </td>
  728. <td>
  729. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo isset($reponse[$i]) ? Security::remove_XSS($reponse[$i]) : ''; ?>" />
  730. </td>
  731. <td colspan="2" align="left">
  732. <textarea class="form-control" wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo isset($comment[$i]) ? Security::remove_XSS($comment[$i]) : ''; ?></textarea>
  733. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  734. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  735. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  736. ?>" />
  737. </td>
  738. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  739. <td>
  740. <div class="checkbox">
  741. <p>
  742. <label>
  743. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if (isset($try[$i]) && $try[$i] == 1) echo'checked'; ?> />
  744. <?php echo get_lang('TryAgain'); ?>
  745. </label>
  746. </p>
  747. </div>
  748. <p>
  749. <?php echo get_lang('SeeTheory'); ?>
  750. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  751. <?php echo $option_lp; ?>
  752. </select>
  753. </p>
  754. <p>
  755. <?php echo get_lang('Other'); ?>
  756. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo isset($url[$i]) ? $url[$i] : ''; ?>">
  757. </p>
  758. <p>
  759. <?php echo get_lang('SelectQuestion'); ?>
  760. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  761. <?php echo $option_feed; ?>
  762. </select>
  763. </p>
  764. </td>
  765. <?php } else { ?>
  766. <td>&nbsp;</td>
  767. <?php
  768. }
  769. }
  770. //end if is delineation
  771. } else {
  772. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  773. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null;
  774. ?>
  775. <tr>
  776. <td>
  777. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>" aria-hidden="true"></span>
  778. </td>
  779. <td>
  780. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($responseValue); ?>" />
  781. </td>
  782. <?php
  783. $form = new FormValidator('form_' . $i);
  784. $config = array(
  785. 'ToolbarSet' => 'TestProposedAnswer',
  786. 'cols-size' => [0, 12, 0]
  787. );
  788. $form->addHtmlEditor('comment[' . $i . ']', null, false, false, $config);
  789. $renderer = $form->defaultRenderer();
  790. $form_template = '{content}';
  791. $renderer->setFormTemplate($form_template);
  792. $element_template = '
  793. {label}
  794. {element}';
  795. $renderer->setElementTemplate($element_template);
  796. $form->setDefaults(array('comment[' . $i . ']' => $commentValue));
  797. $return = $form->return_form();
  798. ?>
  799. <td colspan="2" align="left" ><?php echo $return; ?></td>
  800. <?php } ?>
  801. <td>
  802. <?php
  803. if ($answerType == HOT_SPOT_DELINEATION) {
  804. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  805. ?>
  806. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="form-cotrol" value="0" />
  807. <?php } else { ?>
  808. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  809. <?php
  810. }
  811. }
  812. if ($answerType == HOT_SPOT) {
  813. ?>
  814. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  815. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  816. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  817. <?php } ?>
  818. </td>
  819. </tr>
  820. <?php
  821. }
  822. $list = new LearnpathList(api_get_user_id());
  823. $flat_list = $list->get_flat_list();
  824. $option_lp = '';
  825. $isSelected = false;
  826. foreach ($flat_list as $id => $details) {
  827. $selected = '';
  828. if (isset($lp_noerror) && $id == $lp_noerror) {
  829. $selected = 'selected="selected"';
  830. $isSelected = true;
  831. }
  832. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  833. }
  834. if ($isSelected) {
  835. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  836. } else {
  837. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  838. }
  839. // Feedback SELECT
  840. $question_list = $objExercise->selectQuestionList();
  841. $option_feed = '';
  842. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  843. $details = isset($details) ? $details : null;
  844. $id = isset($id) ? $id : 0;
  845. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  846. foreach ($question_list as $key => $questionid) {
  847. $selected = '';
  848. $question = Question::read($questionid);
  849. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  850. if ($questionid == $selectQuestionNoError) {
  851. $selected = 'selected="selected"';
  852. }
  853. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  854. }
  855. if ($selectQuestionNoError == -1) {
  856. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  857. } else {
  858. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  859. }
  860. if ($answerType == HOT_SPOT_DELINEATION) {
  861. ?>
  862. <tr>
  863. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  864. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  865. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  866. <th><?php echo get_lang('Scenario'); ?></th>
  867. <?php } else { ?>
  868. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  869. <?php } ?>
  870. <th>&nbsp;</th>
  871. </tr>
  872. <tr>
  873. <td colspan="2">
  874. <?php echo get_lang('LearnerHasNoMistake'); ?>
  875. </td>
  876. <td colspan="2" align="left">
  877. <textarea class="form-control" wrap="virtual" rows="3" cols="25" name="comment_noerror"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  878. </td>
  879. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  880. <td>
  881. <div class="checkbox">
  882. <p>
  883. <label>
  884. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  885. <?php echo get_lang('TryAgain'); ?>
  886. </label>
  887. </p>
  888. </div>
  889. <p>
  890. <?php echo get_lang('SeeTheory'); ?> <br />
  891. <select class="form-control" name="lp_noerror" >
  892. <?php echo $option_lp; ?>
  893. </select>
  894. </p>
  895. <p>
  896. <?php echo get_lang('Other'); ?> <br />
  897. <input class="form-control" name="url_noerror" value="<?php echo $url_noerror; ?>">
  898. </p>
  899. <p>
  900. <?php echo get_lang('SelectQuestion'); ?> <br />
  901. <select class="form-control" name="select_question_noerror">
  902. <?php echo $option_feed; ?>
  903. </select>
  904. </p>
  905. </td>
  906. <td>&nbsp;</td>
  907. <?php } else { ?>
  908. <td colspan="2">&nbsp;</td>
  909. <?php } ?>
  910. </tr>
  911. <?php } ?>
  912. </tbody>
  913. </table>
  914. </div>
  915. <div class="row">
  916. <div class="col-xs-12">
  917. <?php
  918. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  919. $height = 450;
  920. $relPath = api_get_path(WEB_CODE_PATH);
  921. ?>
  922. <div id="hotspot-container" class="center-block">
  923. </div>
  924. </div>
  925. </div>
  926. </form>
  927. <script>
  928. $(document).on('ready', function () {
  929. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  930. new DelineationQuestion({
  931. questionId: <?php echo $modifyAnswers ?>,
  932. selector: '#hotspot-container',
  933. for: 'admin',
  934. relPath: '<?php echo $relPath ?>'
  935. });
  936. <?php } else { ?>
  937. new HotspotQuestion({
  938. questionId: <?php echo $modifyAnswers ?>,
  939. selector: '#hotspot-container',
  940. for: 'admin',
  941. relPath: '<?php echo $relPath ?>'
  942. });
  943. <?php } ?>
  944. });
  945. </script>
  946. <?php
  947. if ($debug > 0) {
  948. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  949. }
  950. }