hotspot_admin.inc.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. *
  8. * @package chamilo.exercise
  9. *
  10. * @author Toon Keppens
  11. */
  12. $modifyAnswers = (int) $_GET['hotspotadmin'];
  13. if (!is_object($objQuestion)) {
  14. $objQuestion = Question::read($modifyAnswers);
  15. }
  16. $questionName = $objQuestion->selectTitle();
  17. $answerType = $objQuestion->selectType();
  18. $pictureName = $objQuestion->getPictureFilename();
  19. $debug = 0; // debug variable to get where we are
  20. $okPicture = empty($pictureName) ? false : true;
  21. // if we come from the warning box "this question is used in several exercises"
  22. if ($modifyIn) {
  23. if ($debug > 0) {
  24. echo '$modifyIn was set'."<br />\n";
  25. }
  26. // if the user has chosen to modify the question only in the current exercise
  27. if ($modifyIn === 'thisExercise') {
  28. // duplicates the question
  29. $questionId = $objQuestion->duplicate();
  30. // deletes the old question
  31. $objQuestion->delete($exerciseId);
  32. // removes the old question ID from the question list of the Exercise object
  33. $objExercise->removeFromList($modifyAnswers);
  34. // adds the new question ID into the question list of the Exercise object
  35. $objExercise->addToList($questionId);
  36. // construction of the duplicated Question
  37. $objQuestion = Question::read($questionId);
  38. // adds the exercise ID into the exercise list of the Question object
  39. $objQuestion->addToList($exerciseId);
  40. // copies answers from $modifyAnswers to $questionId
  41. $objAnswer->duplicate($objQuestion);
  42. // construction of the duplicated Answers
  43. $objAnswer = new Answer($questionId);
  44. }
  45. $color = UnserializeApi::unserialize('not_allowed_classes', $color);
  46. $reponse = UnserializeApi::unserialize('not_allowed_classes', $reponse);
  47. $comment = UnserializeApi::unserialize('not_allowed_classes', $comment);
  48. $weighting = UnserializeApi::unserialize('not_allowed_classes', $weighting);
  49. $hotspot_coordinates = UnserializeApi::unserialize('not_allowed_classes', $hotspot_coordinates);
  50. $hotspot_type = UnserializeApi::unserialize('not_allowed_classes', $hotspot_type);
  51. $destination = UnserializeApi::unserialize('not_allowed_classes', $destination);
  52. unset($buttonBack);
  53. }
  54. $hotspot_admin_url = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$exerciseId;
  55. // the answer form has been submitted
  56. $submitAnswers = isset($_POST['submitAnswers']) ? true : false;
  57. $buttonBack = isset($_POST['buttonBack']) ? true : false;
  58. $nbrAnswers = isset($_POST['nbrAnswers']) ? (int) $_POST['nbrAnswers'] : 0;
  59. if ($submitAnswers || $buttonBack) {
  60. if ($answerType == HOT_SPOT) {
  61. if ($debug > 0) {
  62. echo '$submitAnswers or $buttonBack was set'."<br />\n";
  63. }
  64. $questionWeighting = $nbrGoodAnswers = 0;
  65. for ($i = 1; $i <= $nbrAnswers; $i++) {
  66. if ($debug > 0) {
  67. echo str_repeat('&nbsp;', 4).'$answerType is HOT_SPOT'."<br />\n";
  68. }
  69. $reponse[$i] = trim($reponse[$i]);
  70. $comment[$i] = trim($comment[$i]);
  71. $weighting[$i] = $weighting[$i]; // it can be float
  72. // checks if field is empty
  73. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  74. $msgErr = get_lang('HotspotGiveAnswers');
  75. // clears answers already recorded into the Answer object
  76. $objAnswer->cancel();
  77. break;
  78. }
  79. if ($weighting[$i] <= 0) {
  80. $msgErr = get_lang('HotspotWeightingError');
  81. // clears answers already recorded into the Answer object
  82. $objAnswer->cancel();
  83. break;
  84. }
  85. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  86. $msgErr = get_lang('HotspotNotDrawn');
  87. // clears answers already recorded into the Answer object
  88. $objAnswer->cancel();
  89. break;
  90. }
  91. } // end for()
  92. if (empty($msgErr)) {
  93. for ($i = 1; $i <= $nbrAnswers; $i++) {
  94. if ($debug > 0) {
  95. echo str_repeat('&nbsp;', 4).'$answerType is HOT_SPOT'."<br />\n";
  96. }
  97. $reponse[$i] = trim($reponse[$i]);
  98. $comment[$i] = trim($comment[$i]);
  99. $weighting[$i] = ($weighting[$i]); //it can be float
  100. if ($weighting[$i]) {
  101. $questionWeighting += $weighting[$i];
  102. }
  103. // creates answer
  104. $objAnswer->createAnswer(
  105. $reponse[$i],
  106. '',
  107. $comment[$i],
  108. $weighting[$i],
  109. $i,
  110. $hotspot_coordinates[$i],
  111. $hotspot_type[$i]
  112. );
  113. } // end for()
  114. // saves the answers into the data base
  115. $objAnswer->save();
  116. // sets the total weighting of the question
  117. $objQuestion->updateWeighting($questionWeighting);
  118. $objQuestion->save($objExercise);
  119. $editQuestion = $questionId;
  120. unset($modifyAnswers);
  121. echo '<script type="text/javascript">window.location.href="'.$hotspot_admin_url
  122. .'&message=ItemUpdated"</script>';
  123. }
  124. if ($debug > 0) {
  125. echo '$modifyIn was set - end'."<br />\n";
  126. }
  127. } else {
  128. if ($debug > 0) {
  129. echo '$submitAnswers or $buttonBack was set'."<br />\n";
  130. }
  131. $questionWeighting = $nbrGoodAnswers = 0;
  132. $select_question = isset($_POST['select_question']) ? $_POST['select_question'] : null;
  133. $try = isset($_POST['try']) ? $_POST['try'] : [];
  134. $url = isset($_POST['url']) ? $_POST['url'] : '';
  135. $destination = [];
  136. $threadhold1 = $_POST['threadhold1'];
  137. $threadhold2 = $_POST['threadhold2'];
  138. $threadhold3 = $_POST['threadhold3'];
  139. for ($i = 1; $i <= $nbrAnswers; $i++) {
  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 = (int) $threadhold1[$i];
  147. }
  148. if (empty($threadhold2[$i])) {
  149. $threadhold2_str = 0;
  150. } else {
  151. $threadhold2_str = (int) $threadhold2[$i];
  152. }
  153. if (empty($threadhold3[$i])) {
  154. $threadhold3_str = 0;
  155. } else {
  156. $threadhold3_str = (int) $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. $url_str = '';
  170. if (isset($url[$i]) && !empty($url[$i])) {
  171. $url_str = $url[$i];
  172. }
  173. if ($select_question[$i] == '') {
  174. $question_str = 0;
  175. } else {
  176. $question_str = $select_question[$i];
  177. }
  178. $destination[$i] = $threadhold_total.'@@'.$try_str.'@@'.$lp_str.'@@'.$question_str.'@@'.$url_str;
  179. // checks if field is empty
  180. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  181. $msgErr = get_lang('HotspotGiveAnswers');
  182. // clears answers already recorded into the Answer object
  183. $objAnswer->cancel();
  184. break;
  185. }
  186. if ($weighting[$i] <= 0 && $_SESSION['tmp_answers']['hotspot_type'][$i] != 'oar') {
  187. $msgErr = get_lang('HotspotWeightingError');
  188. // clears answers already recorded into the Answer object
  189. $objAnswer->cancel();
  190. break;
  191. }
  192. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  193. $msgErr = get_lang('HotspotNotDrawn');
  194. // clears answers already recorded into the Answer object
  195. $objAnswer->cancel();
  196. break;
  197. }
  198. }
  199. // now the noerror section
  200. $selectQuestionNoError = isset($_POST['select_question_noerror']) ? Security::remove_XSS($_POST['select_question_noerror']) : null;
  201. $lp_noerror = isset($_POST['lp_noerror']) ? Security::remove_XSS($_POST['lp_noerror']) : '';
  202. $try_noerror = isset($_POST['try_noerror']) ? Security::remove_XSS($_POST['try_noerror']) : null;
  203. $url_noerror = isset($_POST['url_noerror']) ? Security::remove_XSS($_POST['url_noerror']) : null;
  204. $comment_noerror = isset($_POST['comment_noerror']) ? Security::remove_XSS($_POST['comment_noerror']) : null;
  205. $threadhold_total = '0;0;0';
  206. if ($try_noerror == 'on') {
  207. $try_str = 1;
  208. } else {
  209. $try_str = 0;
  210. }
  211. if (empty($lp_noerror)) {
  212. $lp_str = 0;
  213. } else {
  214. $lp_str = $lp_noerror;
  215. }
  216. if ($url_noerror == '') {
  217. $url_str = '';
  218. } else {
  219. $url_str = $url_noerror;
  220. }
  221. if ($selectQuestionNoError == '') {
  222. $question_str = 0;
  223. } else {
  224. $question_str = $selectQuestionNoError;
  225. }
  226. $destination_noerror = $threadhold_total.'@@'.$try_str.'@@'.$lp_str.'@@'.$question_str.'@@'.$url_str;
  227. if (empty($msgErr)) {
  228. for ($i = 1; $i <= $nbrAnswers; $i++) {
  229. if ($debug > 0) {
  230. echo str_repeat('&nbsp;', 4).'$answerType is HOT_SPOT'."<br />\n";
  231. }
  232. $reponse[$i] = trim($reponse[$i]);
  233. $comment[$i] = trim($comment[$i]);
  234. $weighting[$i] = ($weighting[$i]); //it can be float
  235. if ($weighting[$i]) {
  236. $questionWeighting += $weighting[$i];
  237. }
  238. // creates answer
  239. $objAnswer->createAnswer(
  240. $reponse[$i],
  241. '',
  242. $comment[$i],
  243. $weighting[$i],
  244. $i,
  245. $hotspot_coordinates[$i],
  246. $hotspot_type[$i],
  247. $destination[$i]
  248. );
  249. } // end for()
  250. // saves the answers into the data base
  251. $objAnswer->createAnswer(
  252. 'noerror',
  253. '',
  254. $comment_noerror,
  255. '0',
  256. $nbrAnswers + 1,
  257. null,
  258. 'noerror',
  259. $destination_noerror
  260. );
  261. $objAnswer->save();
  262. // sets the total weighting of the question
  263. $objQuestion->updateWeighting($questionWeighting);
  264. $objQuestion->save($objExercise);
  265. $editQuestion = $questionId;
  266. unset($modifyAnswers);
  267. echo '<script type="text/javascript">window.location.href="'.$hotspot_admin_url
  268. .'&message=ItemUpdated"</script>';
  269. }
  270. }
  271. }
  272. if (isset($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 = [];
  307. $comment = [];
  308. $weighting = [];
  309. $hotspot_coordinates = [];
  310. $hotspot_type = [];
  311. $destination_items = [];
  312. $destination = [];
  313. for ($i = 1; $i <= $nbrAnswers; $i++) {
  314. $reponse[$i] = $objAnswer->selectAnswer($i);
  315. if ($objExercise->getFeedbackType() != 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'] = [];
  354. $_SESSION['tmp_answers']['answer'] = $reponse;
  355. if ($objExercise->getFeedbackType() != 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->getFeedbackType() != 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->getFeedbackType() != 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 = [
  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 = [
  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().'&'
  480. .http_build_query(['hotspotadmin' => $modifyAnswers, 'exerciseId' => $exerciseId]); ?>
  481. <form method="post" action="<?php echo $hotspot_admin_url; ?>" class="form-horizontal" id="frm_exercise"
  482. name="frm_exercise">
  483. <div class="form-group">
  484. <div class="col-sm-12">
  485. <?php if ($answerType == HOT_SPOT_DELINEATION) {
  486. ?>
  487. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  488. <em class="fa fa-trash"></em> <?php echo get_lang('LessOAR'); ?>
  489. </button>
  490. <button type="submit" class="btn btn-primary" name="moreOARAnswers" value="moreOARAnswers">
  491. <em class="fa fa-plus"></em> <?php echo get_lang('MoreOAR'); ?>
  492. </button>
  493. <?php
  494. } else {
  495. ?>
  496. <button type="submit" class="btn btn-danger" name="lessAnswers" value="lessAnswers">
  497. <em class="fa fa-trash"></em> <?php echo get_lang('LessHotspots'); ?>
  498. </button>
  499. <button type="submit" class="btn btn-primary" name="moreAnswers" value="moreAnswers">
  500. <em class="fa fa-plus"></em> <?php echo get_lang('MoreHotspots'); ?>
  501. </button>
  502. <?php
  503. } ?>
  504. <button type="submit" class="btn btn-primary" name="submitAnswers" value="submitAnswers">
  505. <em class="fa fa-save"></em> <?php echo get_lang('AddQuestionToExercise'); ?>
  506. </button>
  507. </div>
  508. </div>
  509. <input type="hidden" name="formSent" value="1"/>
  510. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>"/>
  511. <div class="table-responsive">
  512. <table class="table table-striped table-hover">
  513. <thead>
  514. <tr>
  515. <th width="5">&nbsp;</th>
  516. <th><?php echo get_lang('HotspotDescription'); ?> *</th>
  517. <?php
  518. if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  519. echo '<th>'.get_lang('Comment').'</th>';
  520. if ($answerType == HOT_SPOT_DELINEATION) {
  521. echo '<th >'.get_lang('Scenario').'</th>';
  522. }
  523. } else {
  524. echo '<th colspan="2">'.get_lang('Comment').'</th>';
  525. } ?>
  526. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  527. </tr>
  528. </thead>
  529. <tbody>
  530. <?php
  531. $list = new LearnpathList(api_get_user_id());
  532. // Loading list of LPs
  533. $flat_list = $list->get_flat_list();
  534. for ($i = 1; $i <= $nbrAnswers; $i++) {
  535. // is an delineation
  536. if ($answerType == HOT_SPOT_DELINEATION) {
  537. $option_lp = '';
  538. // setting the LP
  539. $isSelected = false;
  540. foreach ($flat_list as $id => $details) {
  541. $selected = '';
  542. if (isset($lp[$i]) && $id == $lp[$i]) {
  543. $isSelected = true;
  544. $selected = 'selected="selected"';
  545. }
  546. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  547. }
  548. if ($isSelected) {
  549. $option_lp = '<option value="0">'.get_lang('SelectTargetLP').'</option>'.$option_lp;
  550. } else {
  551. $option_lp = '<option value="0" selected="selected" >'.get_lang('SelectTargetLP')
  552. .'</option>'.$option_lp;
  553. }
  554. // Feedback SELECT
  555. $question_list = $objExercise->selectQuestionList();
  556. $option_feed = '';
  557. $option_feed .= '<option value="0">'.get_lang('SelectTargetQuestion').'</option>';
  558. foreach ($question_list as $key => $questionid) {
  559. $selected = '';
  560. $question = Question::read($questionid);
  561. $questionTitle = strip_tags($question->selectTitle());
  562. $val = "Q$key: $questionTitle";
  563. if (isset($select_question[$i]) && $questionid == $select_question[$i]) {
  564. $selected = 'selected="selected"';
  565. }
  566. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  567. }
  568. if (isset($select_question[$i]) && $select_question[$i] == -1) {
  569. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('ExitTest').'</option>';
  570. } else {
  571. $option_feed .= '<option value="-1">'.get_lang('ExitTest').'</option>';
  572. }
  573. //-------- IF it is a delineation
  574. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  575. $option1 = $option2 = $option3 = '';
  576. for ($k = 1; $k <= 100; $k++) {
  577. $selected1 = $selected2 = $selected3 = '';
  578. if ($k == $threadhold1[$i]) {
  579. $selected1 = 'selected="selected"';
  580. }
  581. if ($k == $threadhold2[$i]) {
  582. $selected2 = 'selected="selected"';
  583. }
  584. if ($k == $threadhold3[$i]) {
  585. $selected3 = 'selected="selected"';
  586. }
  587. $option1 .= '<option '.$selected1.' >'.$k.' % </option>';
  588. $option2 .= '<option '.$selected2.' >'.$k.' % </option>';
  589. $option3 .= '<option '.$selected3.'>'.$k.' %</option>';
  590. } ?>
  591. <tr>
  592. <td>
  593. <span class="fa fa-square fa-2x" aria-hidden="true"
  594. style="color: <?php echo $hotspot_colors[$i]; ?>;"></span>
  595. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation"/>
  596. </td>
  597. <td>
  598. <p><strong><?php echo get_lang('Delineation'); ?></strong></p>
  599. <p>
  600. <?php echo get_lang('MinOverlap'); ?>
  601. <select class="form-control" name="threadhold1[<?php echo $i; ?>]">
  602. <?php echo $option1; ?>
  603. </select>
  604. </p>
  605. <p>
  606. <?php echo get_lang('MaxExcess'); ?>
  607. <select class="form-control" name="threadhold2[<?php echo $i; ?>]">
  608. <?php echo $option2; ?>
  609. </select>
  610. </p>
  611. <p>
  612. <?php echo get_lang('MaxMissing'); ?>
  613. <select class="form-control" name="threadhold3[<?php echo $i; ?>]">
  614. <?php echo $option3; ?>
  615. </select>
  616. </p>
  617. </td>
  618. <td align="left">
  619. <p>
  620. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  621. name="comment[<?php echo $i; ?>]"
  622. aria-describedBy="comment-<?php echo $i; ?>-help"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  623. <span id="comment-<?php echo $i; ?>-help"
  624. class="help-block"><?php echo get_lang('LearnerIsInformed'); ?></span>
  625. </p>
  626. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation"/>
  627. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  628. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  629. </td>
  630. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  631. ?>
  632. <td>
  633. <div class="checkbox">
  634. <p>
  635. <label>
  636. <input type="checkbox" class="checkbox" name="<?php echo 'try['.$i; ?>]"
  637. <?php if ($try[$i] == 1) {
  638. echo 'checked';
  639. } ?> />
  640. <?php echo get_lang('TryAgain'); ?>
  641. </label>
  642. </p>
  643. </div>
  644. <p>
  645. <?php echo get_lang('SeeTheory'); ?>
  646. <select class="form-control" name="lp[<?php echo $i; ?>]">
  647. <?php echo $option_lp; ?>
  648. </select>
  649. </p>
  650. <p>
  651. <?php echo get_lang('Other'); ?>
  652. <input class="form-control" name="url[<?php echo $i; ?>]"
  653. value="<?php echo $url[$i]; ?>">
  654. </p>
  655. <p>
  656. <?php echo get_lang('SelectQuestion'); ?>
  657. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  658. <?php echo $option_feed; ?>
  659. </select>
  660. </p>
  661. </td>
  662. <?php
  663. } else {
  664. ?>
  665. <td> &nbsp;</td>
  666. <?php
  667. }
  668. } elseif (false) {
  669. ?>
  670. <tr>
  671. <th colspan="2"><?php echo get_lang('IfNoError'); ?></th>
  672. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  673. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  674. <th></th>
  675. </tr>
  676. <tr>
  677. <td colspan="2">
  678. <?php echo get_lang('LearnerHasNoMistake'); ?>
  679. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror"/>
  680. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0"/>
  681. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror"/>
  682. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0"/>
  683. </td>
  684. <td align="left">
  685. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  686. name="comment[<?php echo $i; ?>]"
  687. style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  688. </td>
  689. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  690. ?>
  691. <td>
  692. <table>
  693. <tr>
  694. <td>
  695. <div class="checkbox">
  696. <p>
  697. <label>
  698. <input type="checkbox" class="checkbox"
  699. name="<?php echo 'try['
  700. .$i; ?>]" <?php if ($try[$i] == 1) {
  701. echo 'checked';
  702. } ?> />
  703. <?php echo get_lang('TryAgain'); ?>
  704. </label>
  705. </p>
  706. </div>
  707. <p>
  708. <?php echo get_lang('SeeTheory'); ?>
  709. <select class="form-control" name="lp[<?php echo $i; ?>]">
  710. <?php echo $option_lp; ?>
  711. </select>
  712. </p>
  713. <p>
  714. <?php echo get_lang('Other'); ?> <br/>
  715. <input class="form-control" name="url[<?php echo $i; ?>]"
  716. value="<?php echo $url[$i]; ?>">
  717. </p>
  718. <p>
  719. <?php echo get_lang('SelectQuestion'); ?> <br/>
  720. <select class="form-control"
  721. name="select_question[<?php echo $i; ?>]">
  722. <?php echo $option_feed; ?>
  723. </select>
  724. </p>
  725. </td>
  726. </tr>
  727. </table>
  728. </td>
  729. <?php
  730. } else {
  731. ?>
  732. <td>&nbsp;</td>
  733. <?php
  734. } ?>
  735. </tr>
  736. <?php
  737. } elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  738. // if it's an OAR
  739. if ($i == 2) {
  740. ?>
  741. <tr>
  742. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  743. <th><?php echo get_lang('OAR'); ?>*</th>
  744. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  745. ?>
  746. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  747. <th><?php if ($answerType == HOT_SPOT_DELINEATION) {
  748. echo get_lang('Scenario');
  749. } ?></th>
  750. <?php
  751. } else {
  752. ?>
  753. <th colspan="3"><?php echo get_lang('Comment'); ?></th>
  754. <?php
  755. } ?>
  756. <th>&nbsp;</th>
  757. </tr>
  758. <?php
  759. } ?>
  760. <tr>
  761. <td>
  762. <span class="fa fa-square fa-2x" aria-hidden="true"
  763. style="color: <?php echo $hotspot_colors[$i]; ?>"></span>
  764. </td>
  765. <td>
  766. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  767. value="<?php echo isset($reponse[$i]) ? Security::remove_XSS($reponse[$i]) : ''; ?>"/>
  768. </td>
  769. <td colspan="2" align="left">
  770. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  771. name="comment[<?php echo $i; ?>]"
  772. style="width: 100%"><?php echo isset($comment[$i]) ? Security::remove_XSS($comment[$i]) : ''; ?></textarea>
  773. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar"/>
  774. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php
  775. echo empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]; ?>"/>
  776. </td>
  777. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  778. ?>
  779. <td>
  780. <div class="checkbox">
  781. <p>
  782. <label>
  783. <input type="checkbox" class="checkbox"
  784. name="<?php echo 'try['.$i; ?>]" <?php if (isset($try[$i]) && $try[$i] == 1) {
  785. echo 'checked';
  786. } ?> />
  787. <?php echo get_lang('TryAgain'); ?>
  788. </label>
  789. </p>
  790. </div>
  791. <p>
  792. <?php echo get_lang('SeeTheory'); ?>
  793. <select class="form-control" name="lp[<?php echo $i; ?>]">
  794. <?php echo $option_lp; ?>
  795. </select>
  796. </p>
  797. <p>
  798. <?php echo get_lang('Other'); ?>
  799. <input class="form-control" name="url[<?php echo $i; ?>]"
  800. value="<?php echo isset($url[$i]) ? $url[$i] : ''; ?>">
  801. </p>
  802. <p>
  803. <?php echo get_lang('SelectQuestion'); ?>
  804. <select class="form-control" name="select_question[<?php echo $i; ?>]">
  805. <?php echo $option_feed; ?>
  806. </select>
  807. </p>
  808. </td>
  809. <?php
  810. } else {
  811. ?>
  812. <td>&nbsp;</td>
  813. <?php
  814. }
  815. }
  816. //end if is delineation
  817. } else {
  818. $commentValue = isset($comment[$i]) ? $comment[$i] : null;
  819. $responseValue = isset($reponse[$i]) ? $reponse[$i] : null; ?>
  820. <tr>
  821. <td>
  822. <span class="fa fa-square fa-2x" style="color: <?php echo $hotspot_colors[$i]; ?>"
  823. aria-hidden="true"></span>
  824. </td>
  825. <td>
  826. <input class="form-control" type="text" name="reponse[<?php echo $i; ?>]"
  827. value="<?php echo Security::remove_XSS($responseValue); ?>"/>
  828. </td>
  829. <?php
  830. $form = new FormValidator('form_'.$i);
  831. $config = [
  832. 'ToolbarSet' => 'TestProposedAnswer',
  833. 'cols-size' => [0, 12, 0],
  834. ];
  835. $form->addHtmlEditor('comment['.$i.']', null, false, false, $config);
  836. $renderer = $form->defaultRenderer();
  837. $form_template = '{content}';
  838. $renderer->setFormTemplate($form_template);
  839. $element_template = '{label} {element}';
  840. $renderer->setElementTemplate($element_template);
  841. $form->setDefaults(['comment['.$i.']' => $commentValue]);
  842. $return = $form->returnForm(); ?>
  843. <td colspan="2" align="left"><?php echo $return; ?></td>
  844. <?php
  845. } ?>
  846. <td>
  847. <?php
  848. if ($answerType == HOT_SPOT_DELINEATION) {
  849. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  850. ?>
  851. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="form-cotrol" value="0"/>
  852. <?php
  853. } else {
  854. ?>
  855. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  856. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  857. <?php
  858. }
  859. }
  860. if ($answerType == HOT_SPOT) {
  861. ?>
  862. <input class="form-control" type="text" name="weighting[<?php echo $i; ?>]"
  863. value="<?php echo isset($weighting[$i]) ? $weighting[$i] : 10; ?>"/>
  864. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]"
  865. value="<?php echo empty($hotspot_coordinates[$i])
  866. ? '0;0|0|0'
  867. : $hotspot_coordinates[$i]; ?>"/>
  868. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]"
  869. value="<?php echo empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]; ?>"/>
  870. <?php
  871. } ?>
  872. </td>
  873. </tr>
  874. <?php
  875. }
  876. $list = new LearnpathList(api_get_user_id());
  877. $flat_list = $list->get_flat_list();
  878. $option_lp = '';
  879. $isSelected = false;
  880. foreach ($flat_list as $id => $details) {
  881. $selected = '';
  882. if (isset($lp_noerror) && $id == $lp_noerror) {
  883. $selected = 'selected="selected"';
  884. $isSelected = true;
  885. }
  886. $option_lp .= '<option value="'.$id.'" '.$selected.'>'.$details['lp_name'].'</option>';
  887. }
  888. if ($isSelected) {
  889. $option_lp = '<option value="0">'.get_lang('SelectTargetLP').'</option>'.$option_lp;
  890. } else {
  891. $option_lp = '<option value="0" selected="selected" >'.get_lang('SelectTargetLP').'</option>'
  892. .$option_lp;
  893. }
  894. // Feedback SELECT
  895. $question_list = $objExercise->selectQuestionList();
  896. $option_feed = '';
  897. $option_feed .= '<option value="0">'.get_lang('SelectTargetQuestion').'</option>';
  898. $selectQuestionNoError = isset($selectQuestionNoError) ? $selectQuestionNoError : null;
  899. foreach ($question_list as $key => $questionid) {
  900. $selected = '';
  901. $question = Question::read($questionid);
  902. $questionTitle = $question->selectTitle();
  903. $val = "Q$key: $questionTitle";
  904. if ($questionid == $selectQuestionNoError) {
  905. $selected = 'selected="selected"';
  906. }
  907. $option_feed .= '<option value="'.$questionid.'" '.$selected.' >'.$val.'</option>';
  908. }
  909. if ($selectQuestionNoError == -1) {
  910. $option_feed .= '<option value="-1" selected="selected" >'.get_lang('ExitTest').'</option>';
  911. } else {
  912. $option_feed .= '<option value="-1">'.get_lang('ExitTest').'</option>';
  913. }
  914. if ($answerType == HOT_SPOT_DELINEATION) {
  915. ?>
  916. <tr>
  917. <th colspan="2"><?php echo get_lang('IfNoError'); ?></th>
  918. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  919. ?>
  920. <th colspan="2"><?php echo get_lang('Feedback'); ?></th>
  921. <th><?php echo get_lang('Scenario'); ?></th>
  922. <?php
  923. } else {
  924. ?>
  925. <th colspan="3"><?php echo get_lang('Feedback'); ?></th>
  926. <?php
  927. } ?>
  928. <th>&nbsp;</th>
  929. </tr>
  930. <tr>
  931. <td colspan="2">
  932. <?php echo get_lang('LearnerHasNoMistake'); ?>
  933. </td>
  934. <td colspan="2" align="left">
  935. <textarea class="form-control" wrap="virtual" rows="3" cols="25"
  936. name="comment_noerror"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  937. </td>
  938. <?php if ($objExercise->getFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  939. ?>
  940. <td>
  941. <div class="checkbox">
  942. <p>
  943. <label>
  944. <input type="checkbox" class="checkbox"
  945. name="try_noerror" <?php if ($try_noerror == 1) {
  946. echo 'checked';
  947. } ?> />
  948. <?php echo get_lang('TryAgain'); ?>
  949. </label>
  950. </p>
  951. </div>
  952. <p>
  953. <?php echo get_lang('SeeTheory'); ?> <br/>
  954. <select class="form-control" name="lp_noerror">
  955. <?php echo $option_lp; ?>
  956. </select>
  957. </p>
  958. <p>
  959. <?php echo get_lang('Other'); ?> <br/>
  960. <input class="form-control" name="url_noerror" value="<?php echo $url_noerror; ?>">
  961. </p>
  962. <p>
  963. <?php echo get_lang('SelectQuestion'); ?> <br/>
  964. <select class="form-control" name="select_question_noerror">
  965. <?php echo $option_feed; ?>
  966. </select>
  967. </p>
  968. </td>
  969. <td>&nbsp;</td>
  970. <?php
  971. } else {
  972. ?>
  973. <td colspan="2">&nbsp;</td>
  974. <?php
  975. } ?>
  976. </tr>
  977. <?php
  978. } ?>
  979. </tbody>
  980. </table>
  981. </div>
  982. <div class="row">
  983. <div class="col-xs-12">
  984. <?php
  985. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  986. $height = 450;
  987. $relPath = api_get_path(WEB_CODE_PATH); ?>
  988. <div id="hotspot-container" class="center-block"></div>
  989. </div>
  990. </div>
  991. </form>
  992. <script>
  993. $(function () {
  994. <?php if ($answerType == HOT_SPOT_DELINEATION) {
  995. ?>
  996. new DelineationQuestion({
  997. questionId: <?php echo $modifyAnswers; ?>,
  998. selector: '#hotspot-container',
  999. for: 'admin',
  1000. relPath: '<?php echo $relPath; ?>'
  1001. });
  1002. <?php
  1003. } else {
  1004. ?>
  1005. new HotspotQuestion({
  1006. questionId: <?php echo $modifyAnswers; ?>,
  1007. selector: '#hotspot-container',
  1008. for: 'admin',
  1009. relPath: '<?php echo $relPath; ?>'
  1010. });
  1011. <?php
  1012. } ?>
  1013. });
  1014. </script>
  1015. <?php
  1016. if ($debug > 0) {
  1017. echo str_repeat('&nbsp;', 0).'$modifyAnswers was set - end'."<br />\n";
  1018. }
  1019. }