hotspot_admin.inc.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use \ChamiloSession as Session;
  4. /**
  5. * This script allows to manage answers. It is included from the
  6. * script admin.php
  7. * @package chamilo.exercise
  8. * @author Toon Keppens
  9. */
  10. $modifyAnswers = intval($_GET['hotspotadmin']);
  11. if (!is_object($objQuestion)) {
  12. $objQuestion = Question :: read($modifyAnswers);
  13. }
  14. $questionName = $objQuestion->selectTitle();
  15. $answerType = $objQuestion->selectType();
  16. $pictureName = $objQuestion->getPictureFilename();
  17. $debug = 0; // debug variable to get where we are
  18. $okPicture = empty($pictureName) ? false : true;
  19. // if we come from the warning box "this question is used in several exercises"
  20. if ($modifyIn) {
  21. if ($debug > 0) {
  22. echo '$modifyIn was set' . "<br />\n";
  23. }
  24. // if the user has chosen to modify the question only in the current exercise
  25. if ($modifyIn == 'thisExercise') {
  26. // duplicates the question
  27. $questionId = $objQuestion->duplicate();
  28. // deletes the old question
  29. $objQuestion->delete($exerciseId);
  30. // removes the old question ID from the question list of the Exercise object
  31. $objExercise->removeFromList($modifyAnswers);
  32. // adds the new question ID into the question list of the Exercise object
  33. $objExercise->addToList($questionId);
  34. // construction of the duplicated Question
  35. $objQuestion = Question :: read($questionId);
  36. // adds the exercise ID into the exercise list of the Question object
  37. $objQuestion->addToList($exerciseId);
  38. // copies answers from $modifyAnswers to $questionId
  39. $objAnswer->duplicate($objQuestion);
  40. // construction of the duplicated Answers
  41. $objAnswer = new Answer($questionId);
  42. }
  43. $color = unserialize($color);
  44. $reponse = unserialize($reponse);
  45. $comment = unserialize($comment);
  46. $weighting = unserialize($weighting);
  47. $hotspot_coordinates = unserialize($hotspot_coordinates);
  48. $hotspot_type = unserialize($hotspot_type);
  49. $destination = unserialize($destination);
  50. unset($buttonBack);
  51. }
  52. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercise/admin.php?' . api_get_cidreq() . '&exerciseId=' . $exerciseId;
  53. // the answer form has been submitted
  54. $submitAnswers = isset($_POST['submitAnswers']) ? true : false;
  55. $buttonBack = isset($_POST['buttonBack']) ? true : false;
  56. $nbrAnswers = isset($_POST['nbrAnswers']) ? intval($_POST['nbrAnswers']) : 0;
  57. if ($submitAnswers || $buttonBack) {
  58. if ($answerType == HOT_SPOT) {
  59. if ($debug > 0) {
  60. echo '$submitAnswers or $buttonBack was set' . "<br />\n";
  61. }
  62. $questionWeighting = $nbrGoodAnswers = 0;
  63. for ($i = 1; $i <= $nbrAnswers; $i++) {
  64. if ($debug > 0) {
  65. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  66. }
  67. $reponse[$i] = trim($reponse[$i]);
  68. $comment[$i] = trim($comment[$i]);
  69. $weighting[$i] = $weighting[$i]; // it can be float
  70. // checks if field is empty
  71. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  72. $msgErr = get_lang('HotspotGiveAnswers');
  73. // clears answers already recorded into the Answer object
  74. $objAnswer->cancel();
  75. break;
  76. }
  77. if ($weighting[$i] <= 0) {
  78. $msgErr = get_lang('HotspotWeightingError');
  79. // clears answers already recorded into the Answer object
  80. $objAnswer->cancel();
  81. break;
  82. }
  83. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  84. $msgErr = get_lang('HotspotNotDrawn');
  85. // clears answers already recorded into the Answer object
  86. $objAnswer->cancel();
  87. break;
  88. }
  89. } // end for()
  90. if (empty($msgErr)) {
  91. for ($i = 1; $i <= $nbrAnswers; $i++) {
  92. if ($debug > 0) {
  93. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  94. }
  95. $reponse[$i] = trim($reponse[$i]);
  96. $comment[$i] = trim($comment[$i]);
  97. $weighting[$i] = ($weighting[$i]); //it can be float
  98. if ($weighting[$i]) {
  99. $questionWeighting+=$weighting[$i];
  100. }
  101. // creates answer
  102. $objAnswer->createAnswer(
  103. $reponse[$i],
  104. '',
  105. $comment[$i],
  106. $weighting[$i],
  107. $i,
  108. $hotspot_coordinates[$i],
  109. $hotspot_type[$i]
  110. );
  111. } // end for()
  112. // saves the answers into the data base
  113. $objAnswer->save();
  114. // sets the total weighting of the question
  115. $objQuestion->updateWeighting($questionWeighting);
  116. $objQuestion->save($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. echo Display::return_message($msgErr, 'normal'); //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. $select_lp_id = array();
  535. $option_lp = '';
  536. // setting the LP
  537. $isSelected = false;
  538. foreach ($flat_list as $id => $details) {
  539. $select_lp_id[$id] = $details['lp_name'];
  540. $selected = '';
  541. if (isset($lp[$i]) && $id == $lp[$i]) {
  542. $isSelected = true;
  543. $selected = 'selected="selected"';
  544. }
  545. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  546. }
  547. if ($isSelected) {
  548. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  549. } else {
  550. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  551. }
  552. // Feedback SELECT
  553. $question_list = $objExercise->selectQuestionList();
  554. $option_feed = '';
  555. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  556. foreach ($question_list as $key => $questionid) {
  557. $selected = '';
  558. $question = Question::read($questionid);
  559. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  560. if (isset($select_question[$i]) && $questionid == $select_question[$i]) {
  561. $selected = 'selected="selected"';
  562. }
  563. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  564. }
  565. if (isset($select_question[$i]) && $select_question[$i] == -1) {
  566. $option_feed .= '<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  567. } else {
  568. $option_feed .= '<option value="-1">' . get_lang('ExitTest') . '</option>';
  569. }
  570. //-------- IF it is a delineation
  571. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  572. $option1 = $option2 = $option3 = '';
  573. for ($k = 1; $k <= 100; $k++) {
  574. $selected1 = $selected2 = $selected3 = '';
  575. if ($k == $threadhold1[$i])
  576. $selected1 = 'selected="selected"';
  577. if ($k == $threadhold2[$i])
  578. $selected2 = 'selected="selected"';
  579. if ($k == $threadhold3[$i])
  580. $selected3 = 'selected="selected"';
  581. $option1.='<option ' . $selected1 . ' >' . $k . ' % </option>';
  582. $option2.='<option ' . $selected2 . ' >' . $k . ' % </option>';
  583. $option3.='<option ' . $selected3 . '>' . $k . ' %</option>';
  584. }
  585. ?>
  586. <tr>
  587. <td>
  588. <span class="fa fa-square fa-2x" aria-hidden="true" style="color: <?php echo $hotspot_colors[$i]; ?>;"></span>
  589. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  590. </td>
  591. <td>
  592. <p><strong><?php echo get_lang('Delineation'); ?></strong></p>
  593. <p>
  594. <?php echo get_lang('MinOverlap'); ?>
  595. <select class="form-control" name="threadhold1[<?php echo $i; ?>]">
  596. <?php echo $option1; ?>
  597. </select>
  598. </p>
  599. <p>
  600. <?php echo get_lang('MaxExcess'); ?>
  601. <select class="form-control" name="threadhold2[<?php echo $i; ?>]" >
  602. <?php echo $option2; ?>
  603. </select>
  604. </p>
  605. <p>
  606. <?php echo get_lang('MaxMissing'); ?>
  607. <select class="form-control" name="threadhold3[<?php echo $i; ?>]" >
  608. <?php echo $option3; ?>
  609. </select>
  610. </p>
  611. </td>
  612. <td align="left">
  613. <p>
  614. <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>
  615. <span id="comment-<?php echo $i ?>-help" class="help-block"><?php echo get_lang('LearnerIsInformed'); ?></span>
  616. </p>
  617. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  618. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  619. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  620. ?>" />
  621. </td>
  622. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  623. <td>
  624. <div class="checkbox">
  625. <p>
  626. <label>
  627. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  628. <?php echo get_lang('TryAgain'); ?>
  629. </label>
  630. </p>
  631. </div>
  632. <p>
  633. <?php echo get_lang('SeeTheory'); ?>
  634. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  635. <?php echo $option_lp; ?>
  636. </select>
  637. </p>
  638. <p>
  639. <?php echo get_lang('Other'); ?>
  640. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  641. </p>
  642. <p>
  643. <?php echo get_lang('SelectQuestion'); ?>
  644. <select class="form-control" name="select_question[<?php echo $i; ?>]" >
  645. <?php echo $option_feed; ?>
  646. </select>
  647. </p>
  648. </td>
  649. <?php } else { ?>
  650. <td> &nbsp;</td>
  651. <?php
  652. }
  653. } elseif (false) {
  654. ?>
  655. <tr>
  656. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  657. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  658. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  659. <th></th>
  660. </tr>
  661. <tr>
  662. <td colspan="2">
  663. <?php echo get_lang('LearnerHasNoMistake'); ?>
  664. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  665. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  666. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  667. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  668. </td>
  669. <td align="left">
  670. <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>
  671. </td>
  672. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  673. <td>
  674. <table>
  675. <tr>
  676. <td>
  677. <div class="checkbox">
  678. <p>
  679. <label>
  680. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  681. <?php echo get_lang('TryAgain'); ?>
  682. </label>
  683. </p>
  684. </div>
  685. <p>
  686. <?php echo get_lang('SeeTheory'); ?>
  687. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  688. <?php echo $option_lp; ?>
  689. </select>
  690. </p>
  691. <p>
  692. <?php echo get_lang('Other'); ?> <br />
  693. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  694. </p>
  695. <p>
  696. <?php echo get_lang('SelectQuestion'); ?> <br />
  697. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  698. <?php echo $option_feed; ?>
  699. </select>
  700. </p>
  701. </td>
  702. </tr>
  703. </table>
  704. </td>
  705. <?php } else { ?>
  706. <td>&nbsp;</td>
  707. <?php } ?>
  708. </tr>
  709. <?php
  710. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  711. // if it's an OAR
  712. if ($i == 2) {
  713. ?>
  714. <tr>
  715. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  716. <th ><?php echo get_lang('OAR'); ?>*</th>
  717. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  718. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  719. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  720. <?php } else { ?>
  721. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  722. <?php } ?>
  723. <th>&nbsp;</th>
  724. </tr>
  725. <?php } ?>
  726. <tr>
  727. <td>
  728. <span class="fa fa-square fa-2x" aria-hidden="true" style="color: <?php echo $hotspot_colors[$i]; ?>"></span>
  729. </td>
  730. <td>
  731. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo isset($reponse[$i]) ? Security::remove_XSS($reponse[$i]) : ''; ?>" />
  732. </td>
  733. <td colspan="2" align="left">
  734. <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>
  735. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  736. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  737. echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]);
  738. ?>" />
  739. </td>
  740. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  741. <td>
  742. <div class="checkbox">
  743. <p>
  744. <label>
  745. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if (isset($try[$i]) && $try[$i] == 1) echo'checked'; ?> />
  746. <?php echo get_lang('TryAgain'); ?>
  747. </label>
  748. </p>
  749. </div>
  750. <p>
  751. <?php echo get_lang('SeeTheory'); ?>
  752. <select class="form-control" name="lp[<?php echo $i; ?>]" >
  753. <?php echo $option_lp; ?>
  754. </select>
  755. </p>
  756. <p>
  757. <?php echo get_lang('Other'); ?>
  758. <input class="form-control" name="url[<?php echo $i; ?>]" value="<?php echo isset($url[$i]) ? $url[$i] : ''; ?>">
  759. </p>
  760. <p>
  761. <?php echo get_lang('SelectQuestion'); ?>
  762. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  763. <?php echo $option_feed; ?>
  764. </select>
  765. </p>
  766. </td>
  767. <?php } else { ?>
  768. <td>&nbsp;</td>
  769. <?php
  770. }
  771. }
  772. //end if is delineation
  773. } else {
  774. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  775. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null;
  776. ?>
  777. <tr>
  778. <td>
  779. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>" aria-hidden="true"></span>
  780. </td>
  781. <td>
  782. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($responseValue); ?>" />
  783. </td>
  784. <?php
  785. $form = new FormValidator('form_' . $i);
  786. $config = array(
  787. 'ToolbarSet' => 'TestProposedAnswer',
  788. 'cols-size' => [0, 12, 0]
  789. );
  790. $form->addHtmlEditor('comment[' . $i . ']', null, false, false, $config);
  791. $renderer = $form->defaultRenderer();
  792. $form_template = '{content}';
  793. $renderer->setFormTemplate($form_template);
  794. $element_template = '
  795. {label}
  796. {element}';
  797. $renderer->setElementTemplate($element_template);
  798. $form->setDefaults(array('comment[' . $i . ']' => $commentValue));
  799. $return = $form->return_form();
  800. ?>
  801. <td colspan="2" align="left" ><?php echo $return; ?></td>
  802. <?php } ?>
  803. <td>
  804. <?php
  805. if ($answerType == HOT_SPOT_DELINEATION) {
  806. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  807. ?>
  808. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="form-cotrol" value="0" />
  809. <?php } else { ?>
  810. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  811. <?php
  812. }
  813. }
  814. if ($answerType == HOT_SPOT) {
  815. ?>
  816. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  817. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  818. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  819. <?php } ?>
  820. </td>
  821. </tr>
  822. <?php
  823. }
  824. $list = new LearnpathList(api_get_user_id());
  825. $flat_list = $list->get_flat_list();
  826. $select_lp_id = array();
  827. $option_lp = '';
  828. $isSelected = false;
  829. foreach ($flat_list as $id => $details) {
  830. $selected = '';
  831. $select_lp_id[$id] = $details['lp_name'];
  832. if (isset($lp_noerror) && $id == $lp_noerror) {
  833. $selected = 'selected="selected"';
  834. $isSelected = true;
  835. }
  836. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  837. }
  838. if ($isSelected) {
  839. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  840. } else {
  841. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  842. }
  843. // Feedback SELECT
  844. $question_list = $objExercise->selectQuestionList();
  845. $option_feed = '';
  846. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  847. $details = isset($details) ? $details : null;
  848. $id = isset($id) ? $id : 0;
  849. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  850. foreach ($question_list as $key => $questionid) {
  851. $selected = '';
  852. $question = Question::read($questionid);
  853. $val = 'Q' . $key . ' :' . substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  854. $select_lp_id[$id] = $details['lp_name'];
  855. if ($questionid == $selectQuestionNoError) {
  856. $selected = 'selected="selected"';
  857. }
  858. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  859. }
  860. if ($selectQuestionNoError == -1) {
  861. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  862. } else {
  863. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  864. }
  865. if ($answerType == HOT_SPOT_DELINEATION) {
  866. ?>
  867. <tr>
  868. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  869. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  870. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  871. <th><?php echo get_lang('Scenario'); ?></th>
  872. <?php } else { ?>
  873. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  874. <?php } ?>
  875. <th>&nbsp;</th>
  876. </tr>
  877. <tr>
  878. <td colspan="2">
  879. <?php echo get_lang('LearnerHasNoMistake'); ?>
  880. </td>
  881. <td colspan="2" align="left">
  882. <textarea class="form-control" wrap="virtual" rows="3" cols="25" name="comment_noerror"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  883. </td>
  884. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  885. <td>
  886. <div class="checkbox">
  887. <p>
  888. <label>
  889. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  890. <?php echo get_lang('TryAgain'); ?>
  891. </label>
  892. </p>
  893. </div>
  894. <p>
  895. <?php echo get_lang('SeeTheory'); ?> <br />
  896. <select class="form-control" name="lp_noerror" >
  897. <?php echo $option_lp; ?>
  898. </select>
  899. </p>
  900. <p>
  901. <?php echo get_lang('Other'); ?> <br />
  902. <input class="form-control" name="url_noerror" value="<?php echo $url_noerror; ?>">
  903. </p>
  904. <p>
  905. <?php echo get_lang('SelectQuestion'); ?> <br />
  906. <select class="form-control" name="select_question_noerror">
  907. <?php echo $option_feed; ?>
  908. </select>
  909. </p>
  910. </td>
  911. <td>&nbsp;</td>
  912. <?php } else { ?>
  913. <td colspan="2">&nbsp;</td>
  914. <?php } ?>
  915. </tr>
  916. <?php } ?>
  917. </tbody>
  918. </table>
  919. </div>
  920. <div class="row">
  921. <div class="col-xs-12">
  922. <?php
  923. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  924. $height = 450;
  925. $relPath = api_get_path(WEB_CODE_PATH);
  926. ?>
  927. <div id="hotspot-container" class="center-block">
  928. </div>
  929. </div>
  930. </div>
  931. </form>
  932. <script>
  933. $(document).on('ready', function () {
  934. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  935. new DelineationQuestion({
  936. questionId: <?php echo $modifyAnswers ?>,
  937. selector: '#hotspot-container',
  938. for: 'admin',
  939. relPath: '<?php echo $relPath ?>'
  940. });
  941. <?php } else { ?>
  942. new HotspotQuestion({
  943. questionId: <?php echo $modifyAnswers ?>,
  944. selector: '#hotspot-container',
  945. for: 'admin',
  946. relPath: '<?php echo $relPath ?>'
  947. });
  948. <?php } ?>
  949. });
  950. </script>
  951. <?php
  952. if ($debug > 0) {
  953. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  954. }
  955. }