hotspot_admin.inc.php 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. /**
  10. * Init
  11. */
  12. use \ChamiloSession as Session;
  13. $modifyAnswers = intval($_GET['hotspotadmin']);
  14. if (!is_object($objQuestion)) {
  15. $objQuestion = Question :: read($modifyAnswers);
  16. }
  17. $questionName = $objQuestion->selectTitle();
  18. $answerType = $objQuestion->selectType();
  19. $pictureName = $objQuestion->selectPicture();
  20. $debug = 0; // debug variable to get where we are
  21. $okPicture = empty($pictureName) ? false : true;
  22. // if we come from the warning box "this question is used in serveral exercises"
  23. if ($modifyIn) {
  24. if ($debug > 0) {
  25. echo '$modifyIn was set' . "<br />\n";
  26. }
  27. // if the user has chosed to modify the question only in the current exercise
  28. if ($modifyIn == 'thisExercise') {
  29. // duplicates the question
  30. $questionId = $objQuestion->duplicate();
  31. // deletes the old question
  32. $objQuestion->delete($exerciseId);
  33. // removes the old question ID from the question list of the Exercise object
  34. $objExercise->removeFromList($modifyAnswers);
  35. // adds the new question ID into the question list of the Exercise object
  36. $objExercise->addToList($questionId);
  37. // construction of the duplicated Question
  38. $objQuestion = Question :: read($questionId);
  39. // adds the exercise ID into the exercise list of the Question object
  40. $objQuestion->addToList($exerciseId);
  41. // copies answers from $modifyAnswers to $questionId
  42. $objAnswer->duplicate($questionId);
  43. // construction of the duplicated Answers
  44. $objAnswer = new Answer($questionId);
  45. }
  46. $color = unserialize($color);
  47. $reponse = unserialize($reponse);
  48. $comment = unserialize($comment);
  49. $weighting = unserialize($weighting);
  50. $hotspot_coordinates = unserialize($hotspot_coordinates);
  51. $hotspot_type = unserialize($hotspot_type);
  52. $destination = unserialize($destination);
  53. unset($buttonBack);
  54. }
  55. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&exerciseId=' . $exerciseId;
  56. // the answer form has been submitted
  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($reponse[$i], '', $comment[$i], $weighting[$i], $i, $hotspot_coordinates[$i], $hotspot_type[$i]);
  103. } // end for()
  104. // saves the answers into the data base
  105. $objAnswer->save();
  106. // sets the total weighting of the question
  107. $objQuestion->updateWeighting($questionWeighting);
  108. $objQuestion->save($exerciseId);
  109. $editQuestion = $questionId;
  110. unset($modifyAnswers);
  111. echo '<script type="text/javascript">window.location.href="' . $hotspot_admin_url . '&message=ItemUpdated"</script>';
  112. }
  113. if ($debug > 0) {
  114. echo '$modifyIn was set - end' . "<br />\n";
  115. }
  116. } else {
  117. if ($debug > 0) {
  118. echo '$submitAnswers or $buttonBack was set' . "<br />\n";
  119. }
  120. $questionWeighting = $nbrGoodAnswers = 0;
  121. $select_question = $_POST['select_question'];
  122. $try = $_POST['try'];
  123. $url = $_POST['url'];
  124. $destination = array();
  125. $threadhold1 = $_POST['threadhold1'];
  126. $threadhold2 = $_POST['threadhold2'];
  127. $threadhold3 = $_POST['threadhold3'];
  128. for ($i = 1; $i <= $nbrAnswers; $i++) {
  129. if ($debug > 0) {
  130. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  131. }
  132. $reponse[$i] = trim($reponse[$i]);
  133. $comment[$i] = trim($comment[$i]);
  134. $weighting[$i] = $weighting[$i];
  135. if (empty($threadhold1[$i]))
  136. $threadhold1_str = 0;
  137. else
  138. $threadhold1_str = intval($threadhold1[$i]);
  139. if (empty($threadhold2[$i]))
  140. $threadhold2_str = 0;
  141. else
  142. $threadhold2_str = intval($threadhold2[$i]);
  143. if (empty($threadhold3[$i]))
  144. $threadhold3_str = 0;
  145. else
  146. $threadhold3_str = intval($threadhold3[$i]);
  147. $threadhold_total = $threadhold1_str . ';' . $threadhold2_str . ';' . $threadhold3_str;
  148. //echo '<pre>';print_r($_POST);echo '</pre>';
  149. if ($try[$i] == 'on') {
  150. $try_str = 1;
  151. } else {
  152. $try_str = 0;
  153. }
  154. if (empty($lp[$i])) {
  155. $lp_str = 0;
  156. } else {
  157. $lp_str = $lp[$i];
  158. }
  159. if ($url[$i] == '') {
  160. $url_str = '';
  161. } else {
  162. $url_str = $url[$i];
  163. }
  164. if ($select_question[$i] == '') {
  165. $question_str = 0;
  166. } else {
  167. $question_str = $select_question[$i];
  168. }
  169. $destination[$i] = $threadhold_total . '@@' . $try_str . '@@' . $lp_str . '@@' . $question_str . '@@' . $url_str;
  170. // the last answer is the IF NO ERROR section witch has not have the reponse, weight and coordinates values
  171. //if ($i!=$nbrAnswers && !($answerType==HOT_SPOT_DELINEATION))
  172. // {
  173. // checks if field is empty
  174. if (empty($reponse[$i]) && $reponse[$i] != '0') {
  175. $msgErr = get_lang('HotspotGiveAnswers');
  176. // clears answers already recorded into the Answer object
  177. $objAnswer->cancel();
  178. break;
  179. }
  180. if ($weighting[$i] <= 0 && $_SESSION['tmp_answers']['hotspot_type'][$i] != 'oar') {
  181. $msgErr = get_lang('HotspotWeightingError');
  182. // clears answers already recorded into the Answer object
  183. $objAnswer->cancel();
  184. break;
  185. }
  186. if ($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  187. $msgErr = get_lang('HotspotNotDrawn');
  188. // clears answers already recorded into the Answer object
  189. $objAnswer->cancel();
  190. break;
  191. }
  192. } // end for()
  193. //now the noerror section
  194. $select_question_noerror = $_POST['select_question_noerror'];
  195. $lp_noerror = $_POST['lp_noerror'];
  196. $try_noerror = $_POST['try_noerror'];
  197. $url_noerror = $_POST['url_noerror'];
  198. $comment_noerror = $_POST['comment_noerror'];
  199. $threadhold_total = '0;0;0';
  200. if ($try_noerror == 'on') {
  201. $try_str = 1;
  202. } else {
  203. $try_str = 0;
  204. }
  205. if (empty($lp_noerror)) {
  206. $lp_str = 0;
  207. } else {
  208. $lp_str = $lp_noerror;
  209. }
  210. if ($url_noerror == '') {
  211. $url_str = '';
  212. } else {
  213. $url_str = $url_noerror;
  214. }
  215. if ($select_question_noerror == '') {
  216. $question_str = 0;
  217. } else {
  218. $question_str = $select_question_noerror;
  219. }
  220. $destination_noerror = $threadhold_total . '@@' . $try_str . '@@' . $lp_str . '@@' . $question_str . '@@' . $url_str;
  221. if (empty($msgErr)) {
  222. for ($i = 1; $i <= $nbrAnswers; $i++) {
  223. if ($debug > 0) {
  224. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  225. }
  226. $reponse[$i] = trim($reponse[$i]);
  227. $comment[$i] = trim($comment[$i]);
  228. $weighting[$i] = ($weighting[$i]); //it can be float
  229. if ($weighting[$i]) {
  230. $questionWeighting+=$weighting[$i];
  231. }
  232. // creates answer
  233. $objAnswer->createAnswer($reponse[$i], '', $comment[$i], $weighting[$i], $i, $hotspot_coordinates[$i], $hotspot_type[$i], $destination[$i]);
  234. } // end for()
  235. // saves the answers into the data base
  236. $objAnswer->createAnswer('noerror', '', $comment_noerror, '0', $nbrAnswers + 1, null, 'noerror', $destination_noerror);
  237. $objAnswer->save();
  238. // sets the total weighting of the question
  239. $objQuestion->updateWeighting($questionWeighting);
  240. $objQuestion->save($exerciseId);
  241. $editQuestion = $questionId;
  242. unset($modifyAnswers);
  243. echo '<script type="text/javascript">window.location.href="' . $hotspot_admin_url . '&message=ItemUpdated"</script>';
  244. }
  245. }
  246. }
  247. if ($modifyAnswers) {
  248. if ($debug > 0) {
  249. echo str_repeat('&nbsp;', 0) . '$modifyAnswers is set' . "<br />\n";
  250. }
  251. // construction of the Answer object
  252. $objAnswer = new Answer($objQuestion->id);
  253. Session::write('objAnswer', $objAnswer);
  254. if ($debug > 0) {
  255. echo str_repeat('&nbsp;', 2) . '$answerType is HOT_SPOT' . "<br />\n";
  256. }
  257. if ($answerType == HOT_SPOT_DELINEATION) {
  258. $try = $_POST['try'];
  259. for ($i = 1; $i <= $nbrAnswers; $i++) {
  260. if ($try[$i] == 'on') {
  261. $try[$i] = 1;
  262. } else {
  263. $try[$i] = 0;
  264. }
  265. }
  266. if ($_POST['try_noerror'] == 'on') {
  267. $try_noerror = 1;
  268. } else {
  269. $try_noerror = 0;
  270. }
  271. }
  272. if (!$nbrAnswers) {
  273. $nbrAnswers = $objAnswer->selectNbrAnswers();
  274. if ($answerType == HOT_SPOT_DELINEATION) {
  275. // the magic happens here ...
  276. // we do this to not count the if no error section
  277. if ($nbrAnswers >= 2)
  278. $nbrAnswers--;
  279. }
  280. $reponse = array();
  281. $comment = array();
  282. $weighting = array();
  283. $hotspot_coordinates = array();
  284. $hotspot_type = array();
  285. $destination_items = array();
  286. $destination = array();
  287. for ($i = 1; $i <= $nbrAnswers; $i++) {
  288. $reponse[$i] = $objAnswer->selectAnswer($i);
  289. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  290. $comment[$i] = $objAnswer->selectComment($i);
  291. }
  292. $weighting[$i] = $objAnswer->selectWeighting($i);
  293. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($i);
  294. $hotspot_type[$i] = $objAnswer->selectHotspotType($i);
  295. if ($answerType == HOT_SPOT_DELINEATION) {
  296. $destination[$i] = $objAnswer->selectDestination($i);
  297. $destination_items = explode('@@', $destination[$i]);
  298. $threadhold_total = $destination_items[0];
  299. $threadhold_items = explode(';', $threadhold_total);
  300. $threadhold1[$i] = $threadhold_items[0];
  301. $threadhold2[$i] = $threadhold_items[1];
  302. $threadhold3[$i] = $threadhold_items[2];
  303. $try[$i] = $destination_items[1];
  304. $lp[$i] = $destination_items[2];
  305. $select_question[$i] = $destination_items[3];
  306. $url[$i] = $destination_items[4];
  307. }
  308. }
  309. }
  310. if ($answerType == HOT_SPOT_DELINEATION) {
  311. //added the noerror answer
  312. $reponse_noerror = 'noerror';
  313. $comment_noerror = $objAnswer->selectComment($nbrAnswers + 1);
  314. $destination_noerror_list = $objAnswer->selectDestination($nbrAnswers + 1);
  315. $destination_items = explode('@@', $destination_noerror_list);
  316. $try_noerror = $destination_items[1];
  317. $lp_noerror = $destination_items[2];
  318. $select_question_noerror = $destination_items[3];
  319. $url_noerror = $destination_items[4];
  320. }
  321. $_SESSION['tmp_answers'] = array();
  322. $_SESSION['tmp_answers']['answer'] = $reponse;
  323. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  324. $_SESSION['tmp_answers']['comment'] = $comment;
  325. }
  326. $_SESSION['tmp_answers']['weighting'] = $weighting;
  327. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  328. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  329. if ($answerType == HOT_SPOT_DELINEATION) {
  330. $_SESSION['tmp_answers']['destination'] = $destination;
  331. }
  332. if ($lessAnswers) {
  333. if ($answerType == HOT_SPOT_DELINEATION) {
  334. $lest_answer = 1;
  335. // At least 1 answer
  336. if ($nbrAnswers > $lest_answer) {
  337. $nbrAnswers--;
  338. // Remove the last answer
  339. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  340. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  341. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  342. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  343. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  344. if (is_array($_SESSION['tmp_answers']['destination'])) {
  345. $tmp = array_pop($_SESSION['tmp_answers']['destination']);
  346. }
  347. } else {
  348. $msgErr = get_lang('MinHotspot');
  349. }
  350. } else {
  351. // At least 1 answer
  352. if ($nbrAnswers > 1) {
  353. $nbrAnswers--;
  354. // Remove the last answer
  355. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  356. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  357. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  358. }
  359. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  360. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  361. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  362. } else {
  363. $msgErr = get_lang('MinHotspot');
  364. }
  365. }
  366. }
  367. if ($moreAnswers) {
  368. if ($nbrAnswers < 12) {
  369. $nbrAnswers++;
  370. // Add a new answer
  371. $_SESSION['tmp_answers']['answer'][] = '';
  372. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  373. $_SESSION['tmp_answers']['comment'][] = '';
  374. }
  375. $_SESSION['tmp_answers']['weighting'][] = '1';
  376. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  377. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  378. $_SESSION['tmp_answers']['destination'][] = '';
  379. } else {
  380. $msgErr = get_lang('MaxHotspot');
  381. }
  382. }
  383. if ($moreOARAnswers) {
  384. if ($nbrAnswers < 12) {
  385. // Add a new answer
  386. $nbrAnswers++;
  387. $_SESSION['tmp_answers']['answer'][] = '';
  388. $_SESSION['tmp_answers']['comment'][] = '';
  389. $_SESSION['tmp_answers']['weighting'][] = '1';
  390. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  391. $_SESSION['tmp_answers']['hotspot_type'][] = 'oar';
  392. $_SESSION['tmp_answers']['destination'][] = '';
  393. } else {
  394. $msgErr = get_lang('MaxHotspot');
  395. }
  396. }
  397. if ($debug > 0) {
  398. echo str_repeat('&nbsp;', 2) . '$usedInSeveralExercises is untrue' . "<br />\n";
  399. }
  400. if ($debug > 0) {
  401. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  402. }
  403. if ($answerType == HOT_SPOT_DELINEATION) {
  404. $hotspot_colors = array("", "#4271B5", "#FE8E16", "#45C7F0", "#BCD631", "#D63173", "#D7D7D7", "#90AFDD", "#AF8640", "#4F9242", "#F4EB24", "#ED2024", "#3B3B3B");
  405. } else {
  406. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  407. "#4271B5",
  408. "#FE8E16",
  409. "#45C7F0",
  410. "#BCD631",
  411. "#D63173",
  412. "#D7D7D7",
  413. "#90AFDD",
  414. "#AF8640",
  415. "#4F9242",
  416. "#F4EB24",
  417. "#ED2024",
  418. "#3B3B3B",
  419. "#F7BDE2");
  420. }
  421. Display::tag('h3', get_lang('Question') . ": " . $questionName . ' <img src="../img/info3.gif" title="' . strip_tags(get_lang('HotspotChoose')) . '" alt="' . strip_tags(get_lang('HotspotChoose')) . '" />');
  422. if (!empty($msgErr)) {
  423. Display::display_normal_message($msgErr); //main API
  424. }
  425. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&hotspotadmin=' . $modifyAnswers . '&exerciseId=' . $exerciseId;
  426. ?>
  427. <form method="post" action="<?php echo $hotspot_admin_url; ?>" id="frm_exercise" name="frm_exercise">
  428. <table border="0" cellpadding="0" cellspacing="2" width="100%">
  429. <tr>
  430. <td colspan="2" valign="bottom">
  431. <?php
  432. $navigator_info = api_get_navigator();
  433. //ie6 fix
  434. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  435. ?>
  436. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  437. <input type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessOAR'); ?>" >
  438. <input type="submit" class="btn plus" name="moreOARAnswers" value="<?php echo get_lang('MoreOAR'); ?>" />
  439. <?php } else { ?>
  440. <input type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" >
  441. <input type="submit" class="btn plus" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" />
  442. <?php } ?>
  443. <input type="submit" class="btn save" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" />
  444. <?php
  445. } else {
  446. if ($answerType == HOT_SPOT_DELINEATION) {
  447. ?>
  448. <button type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessOAR'); ?>" ><?php echo get_lang('LessOAR'); ?></button>
  449. <button type="submit" class="btn plus" name="moreOARAnswers" value="<?php echo get_lang('MoreOAR'); ?>" /><?php echo get_lang('MoreOAR'); ?></button>
  450. <?php } else { ?>
  451. <button type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" ><?php echo get_lang('LessHotspots'); ?></button>
  452. <button type="submit" class="btn plus" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" /><?php echo get_lang('MoreHotspots'); ?></button>
  453. <?php } ?>
  454. <button type="submit" class="btn save" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" /><?php echo get_lang('AddQuestionToExercise'); ?></button>
  455. <?php
  456. }
  457. ?>
  458. </td>
  459. </tr>
  460. <tr>
  461. <td valign="top">
  462. <input type="hidden" name="formSent" value="1" />
  463. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  464. <table class="data_table">
  465. <!--
  466. <tr>
  467. <td colspan="5"><?php echo get_lang('AnswerHotspot'); ?> :</td>
  468. </tr>
  469. -->
  470. <tr>
  471. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  472. <th><?php echo get_lang('HotspotDescription'); ?> *</th>
  473. <?php if ($answerType == HOT_SPOT_DELINEATION) echo '<th >' . get_lang('Thresholds') . '</th>'; ?>
  474. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  475. <th><?php echo get_lang('Comment'); ?></th>
  476. <?php if ($answerType == HOT_SPOT_DELINEATION) echo '<th >' . get_lang('Scenario') . '</th>'; ?>
  477. <?php } else { ?>
  478. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  479. <?php } ?>
  480. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  481. </tr>
  482. <?php
  483. require_once '../newscorm/learnpathList.class.php';
  484. $list = new LearnpathList(api_get_user_id());
  485. $flat_list = $list->get_flat_list(); //loading list of LPs
  486. for ($i = 1; $i <= $nbrAnswers; $i++) {
  487. // is an delineation
  488. if ($answerType == HOT_SPOT_DELINEATION) {
  489. $select_lp_id = array();
  490. $option_lp = '';
  491. // setting the LP
  492. $is_selected = false;
  493. foreach ($flat_list as $id => $details) {
  494. $select_lp_id[$id] = $details['lp_name'];
  495. $selected = '';
  496. if ($id == $lp[$i]) {
  497. $is_selected = true;
  498. $selected = 'selected="selected"';
  499. }
  500. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  501. }
  502. if ($is_selected) {
  503. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  504. } else {
  505. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  506. }
  507. //Feedback SELECT
  508. $question_list = $objExercise->selectQuestionList();
  509. $option_feed = '';
  510. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  511. foreach ($question_list as $key => $questionid) {
  512. $selected = '';
  513. $question = Question::read($questionid);
  514. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  515. $select_lp_id[$id] = $details['lp_name'];
  516. if ($questionid == $select_question[$i]) {
  517. $selected = 'selected="selected"';
  518. }
  519. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  520. }
  521. if ($select_question[$i] == -1)
  522. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  523. else
  524. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  525. //-------- IF it is a delineation
  526. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  527. for ($k = 1; $k <= 100; $k++) {
  528. $selected1 = $selected2 = $selected3 = '';
  529. if ($k == $threadhold1[$i])
  530. $selected1 = 'selected="selected"';
  531. if ($k == $threadhold2[$i])
  532. $selected2 = 'selected="selected"';
  533. if ($k == $threadhold3[$i])
  534. $selected3 = 'selected="selected"';
  535. $option1.='<option ' . $selected1 . ' >' . $k . '</option>';
  536. $option2.='<option ' . $selected2 . ' >' . $k . '</option>';
  537. $option3.='<option ' . $selected3 . '>' . $k . '</option>';
  538. }
  539. ?>
  540. <tr>
  541. <td valign="top">
  542. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  543. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  544. </td>
  545. <td valign="top" align="left">
  546. <b><?php echo get_lang('Delineation'); ?></b><br /><br />
  547. <?php echo get_lang('MinOverlap'); ?><br/><br/>
  548. <?php echo get_lang('MaxExcess'); ?><br/><br/>
  549. <?php echo get_lang('MaxMissing'); ?><br/><br/>
  550. </td>
  551. <td>
  552. <br/><br/>
  553. <select name="threadhold1[<?php echo $i; ?>]" >
  554. <?php echo $option1; ?>
  555. </select>%
  556. <br/><br/>
  557. <select name="threadhold2[<?php echo $i; ?>]" >
  558. <?php echo $option2; ?>
  559. </select>%
  560. <br/><br/>
  561. <select name="threadhold3[<?php echo $i; ?>]" >
  562. <?php echo $option3; ?>
  563. </select>%
  564. <br/>
  565. </td>
  566. <td align="left">
  567. <br />
  568. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%">
  569. <?php echo Security::remove_XSS($comment[$i]); ?>
  570. </textarea>
  571. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  572. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  573. <br/>
  574. <?php echo get_lang('LearnerIsInformed'); ?>
  575. </td>
  576. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  577. <td>
  578. <table>
  579. <tr>
  580. <td>
  581. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  582. <?php echo get_lang('TryAgain'); ?>
  583. <br /><br />
  584. <?php echo get_lang('SeeTheory'); ?> <br />
  585. <select name="lp[<?php echo $i; ?>]" >
  586. <?php echo $option_lp; ?>
  587. </select>
  588. <br /><br />
  589. <?php echo get_lang('Other'); ?> <br />
  590. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  591. <br /> <br />
  592. <?php echo get_lang('SelectQuestion'); ?> <br />
  593. <select name="select_question[<?php echo $i; ?>]" >
  594. <?php echo $option_feed; ?>
  595. </select>
  596. </td>
  597. </tr>
  598. </table>
  599. </td>
  600. <?php } else { ?>
  601. <td> &nbsp;</td>
  602. <?php
  603. }
  604. }
  605. //elseif ($_SESSION['tmp_answers']['hotspot_type'][$i]=='noerror' || $_SESSION['tmp_answers']['answer'][$i]=='noerror')
  606. elseif (false) {
  607. ?>
  608. <tr>
  609. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  610. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  611. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  612. <th></th>
  613. </tr>
  614. <tr>
  615. <td colspan="2" valign="top" align="left">
  616. <?php echo get_lang('LearnerHasNoMistake'); ?>
  617. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  618. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  619. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  620. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  621. </td>
  622. <td colspan="2" align="left">
  623. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  624. </td>
  625. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  626. <td>
  627. <table>
  628. <tr>
  629. <td>
  630. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  631. <?php echo get_lang('TryAgain'); ?>
  632. <br /><br />
  633. <?php echo get_lang('SeeTheory'); ?> <br />
  634. <select name="lp[<?php echo $i; ?>]" >
  635. <?php echo $option_lp; ?>
  636. </select>
  637. <br /><br />
  638. <?php echo get_lang('Other'); ?> <br />
  639. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  640. <br /> <br />
  641. <?php echo get_lang('SelectQuestion'); ?> <br />
  642. <select name="select_question[<?php echo $i; ?>]">
  643. <?php echo $option_feed; ?>
  644. </select>
  645. </td>
  646. </tr>
  647. </table>
  648. </td>
  649. <?php } else { ?>
  650. <td>&nbsp;</td>
  651. <?php } ?>
  652. </tr>
  653. <?php
  654. }
  655. // if it's an OAR
  656. elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  657. if ($i == 2) {
  658. ?>
  659. <tr>
  660. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  661. <th ><?php echo get_lang('OAR'); ?>*</th>
  662. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  663. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  664. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  665. <?php } else { ?>
  666. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  667. <?php } ?>
  668. <th>&nbsp;</th>
  669. </tr>
  670. <?php
  671. }
  672. ?>
  673. <tr>
  674. <td valign="top">
  675. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  676. </td>
  677. <td valign="top" align="left">
  678. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="20" />
  679. </td>
  680. <td colspan="2" align="left">
  681. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  682. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  683. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  684. </td>
  685. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  686. <td>
  687. <table>
  688. <tr>
  689. <td>
  690. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  691. <?php echo get_lang('TryAgain'); ?>
  692. <br /><br />
  693. <?php echo get_lang('SeeTheory'); ?> <br />
  694. <select name="lp[<?php echo $i; ?>]" >
  695. <?php echo $option_lp; ?>
  696. </select>
  697. <br /><br />
  698. <?php echo get_lang('Other'); ?> <br />
  699. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  700. <br /><br />
  701. <?php echo get_lang('SelectQuestion'); ?> <br />
  702. <select name="select_question[<?php echo $i; ?>]">
  703. <?php echo $option_feed; ?>
  704. </select>
  705. </td>
  706. </tr>
  707. </table>
  708. </td>
  709. <?php } else { ?>
  710. <td>&nbsp;</td>
  711. <?php } ?>
  712. <?php
  713. }
  714. } else { //end if is delineation
  715. ?>
  716. <td valign="top">
  717. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  718. </td>
  719. <td valign="top" align="left">
  720. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="45" />
  721. </td>
  722. <?php
  723. $oFCKeditor = new FCKeditor("comment[$i]");
  724. $content = $comment[$i];
  725. $oFCKeditor->ToolbarSet = 'TestProposedAnswer';
  726. $oFCKeditor->Config['ToolbarStartExpanded'] = 'false';
  727. $oFCKeditor->Width = '100%';
  728. $oFCKeditor->Height = '100';
  729. $oFCKeditor->Value = $content;
  730. $return = $oFCKeditor->CreateHtml();
  731. /* <td align="left"><textarea wrap="virtual" rows="1" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo api_htmlentities($comment[$i], ENT_QUOTES, api_get_system_encoding()); ?></textarea></td> */
  732. ?>
  733. <td>&nbsp;</td>
  734. <td align="left" ><?php echo $return; ?></td>
  735. <?php
  736. }
  737. ?>
  738. <td valign="top">
  739. <?php
  740. //if ($answerType==HOT_SPOT_DELINEATION && $i!=2)
  741. if ($answerType == HOT_SPOT_DELINEATION) {
  742. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  743. ?>
  744. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
  745. <?php } else { ?>
  746. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  747. <?php
  748. }
  749. }
  750. if ($answerType == HOT_SPOT) {
  751. ?>
  752. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  753. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  754. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  755. <?php
  756. }
  757. ?>
  758. </td>
  759. </tr>
  760. <?php
  761. }
  762. require_once '../newscorm/learnpathList.class.php';
  763. $list = new LearnpathList(api_get_user_id());
  764. $flat_list = $list->get_flat_list();
  765. $select_lp_id = array();
  766. $option_lp = '';
  767. //$option_lp.='<option value="0">'.get_lang('SelectTargetLP').'</option>';
  768. foreach ($flat_list as $id => $details) {
  769. $selected = '';
  770. $select_lp_id[$id] = $details['lp_name'];
  771. if ($id == $lp_noerror) {
  772. $selected = 'selected="selected"';
  773. $is_selected = true;
  774. }
  775. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  776. }
  777. if ($is_selected) {
  778. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  779. } else {
  780. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  781. }
  782. //Feedback SELECT
  783. $question_list = $objExercise->selectQuestionList();
  784. $option_feed = '';
  785. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  786. foreach ($question_list as $key => $questionid) {
  787. $selected = '';
  788. $question = Question::read($questionid);
  789. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  790. $select_lp_id[$id] = $details['lp_name'];
  791. if ($questionid == $select_question_noerror) {
  792. $selected = 'selected="selected"';
  793. }
  794. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  795. }
  796. if ($select_question_noerror == -1)
  797. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  798. else
  799. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  800. if ($answerType == HOT_SPOT_DELINEATION) {
  801. ?>
  802. <tr>
  803. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  804. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  805. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  806. <th><?php echo get_lang('Scenario'); ?></th>
  807. <?php } else { ?>
  808. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  809. <?php } ?>
  810. <th>&nbsp;</th>
  811. </tr>
  812. <tr>
  813. <td colspan="2" valign="top" align="left">
  814. <?php echo get_lang('LearnerHasNoMistake'); ?>
  815. </td>
  816. <td colspan="2" align="left">
  817. <textarea wrap="virtual" rows="3" cols="25" name="comment_noerror" style="width: 100%"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  818. </td>
  819. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  820. <td>
  821. <table>
  822. <tr>
  823. <td>
  824. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  825. <?php echo get_lang('TryAgain'); ?>
  826. <br /><br />
  827. <?php echo get_lang('SeeTheory'); ?> <br />
  828. <select name="lp_noerror" >
  829. <?php echo $option_lp; ?>
  830. </select>
  831. <br /><br />
  832. <?php echo get_lang('Other'); ?> <br />
  833. <input name="url_noerror" value="<?php echo $url_noerror; ?>">
  834. <br /><br />
  835. <?php echo get_lang('SelectQuestion'); ?> <br />
  836. <select name="select_question_noerror">
  837. <?php echo $option_feed; ?>
  838. </select>
  839. </td>
  840. </tr>
  841. </table>
  842. </td>
  843. <td>&nbsp;</td>
  844. <?php } else { ?>
  845. <td colspan="2">&nbsp;</td>
  846. <?php } ?>
  847. </tr>
  848. <?php
  849. }
  850. ?>
  851. </table>
  852. </td>
  853. </tr>
  854. <tr>
  855. <td colspan="2" valign="top" style="border-top:none">
  856. <script>
  857. <!--
  858. // Version check based upon the values entered above in "Globals"
  859. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  860. <?php
  861. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  862. $height = 450;
  863. ?>
  864. // Check to see if the version meets the requirements for playback
  865. if (hasReqestedVersion) { // if we've detected an acceptable version
  866. var oeTags = '<object type="application/x-shockwave-flash" data="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="600" height="<?php echo $height ?>">'
  867. + '<param name="movie" value="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  868. + '<param name="test" value="OOoowww fo shooww" />'
  869. + '</object>';
  870. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  871. } else { // flash is too old or we can't detect the plugin
  872. var alternateContent = 'Error<br \/>'
  873. + 'This content requires the Macromedia Flash Player.<br \/>'
  874. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  875. document.write(alternateContent); // insert non-flash content
  876. }
  877. // -->
  878. </script>
  879. </td>
  880. </tr>
  881. </table>
  882. </form>
  883. <?php
  884. if ($debug > 0) {
  885. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  886. }
  887. }