hotspot_admin.inc.php 52 KB

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