hotspot_admin.inc.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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. $i = 1;
  289. foreach ($objAnswer->answer as $answer_id => $answer_item) {
  290. //$i = $answer_id;
  291. $reponse[$i] = $objAnswer->selectAnswer($answer_id);
  292. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  293. $comment[$i] = $objAnswer->selectComment($answer_id);
  294. }
  295. $weighting[$i] = $objAnswer->selectWeighting($answer_id);
  296. $hotspot_coordinates[$i] = $objAnswer->selectHotspotCoordinates($answer_id);
  297. $hotspot_type[$i] = $objAnswer->selectHotspotType($answer_id);
  298. if ($answerType == HOT_SPOT_DELINEATION) {
  299. $destination[$i] = $objAnswer->selectDestination($i);
  300. $destination_items = explode('@@', $destination[$i]);
  301. $threadhold_total = $destination_items[0];
  302. $threadhold_items = explode(';', $threadhold_total);
  303. $threadhold1[$i] = $threadhold_items[0];
  304. $threadhold2[$i] = $threadhold_items[1];
  305. $threadhold3[$i] = $threadhold_items[2];
  306. $try[$i] = $destination_items[1];
  307. $lp[$i] = $destination_items[2];
  308. $select_question[$i] = $destination_items[3];
  309. $url[$i] = $destination_items[4];
  310. }
  311. $i++;
  312. }
  313. }
  314. if ($answerType == HOT_SPOT_DELINEATION) {
  315. //added the noerror answer
  316. $reponse_noerror = 'noerror';
  317. $comment_noerror = $objAnswer->selectComment($nbrAnswers + 1);
  318. $destination_noerror_list = $objAnswer->selectDestination($nbrAnswers + 1);
  319. $destination_items = explode('@@', $destination_noerror_list);
  320. $try_noerror = $destination_items[1];
  321. $lp_noerror = $destination_items[2];
  322. $select_question_noerror = $destination_items[3];
  323. $url_noerror = $destination_items[4];
  324. }
  325. $_SESSION['tmp_answers'] = array();
  326. $_SESSION['tmp_answers']['answer'] = $reponse;
  327. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  328. $_SESSION['tmp_answers']['comment'] = $comment;
  329. }
  330. $_SESSION['tmp_answers']['weighting'] = $weighting;
  331. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  332. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  333. if ($answerType == HOT_SPOT_DELINEATION) {
  334. $_SESSION['tmp_answers']['destination'] = $destination;
  335. }
  336. if ($lessAnswers) {
  337. if ($answerType == HOT_SPOT_DELINEATION) {
  338. $lest_answer = 1;
  339. // At least 1 answer
  340. if ($nbrAnswers > $lest_answer) {
  341. $nbrAnswers--;
  342. // Remove the last answer
  343. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  344. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  345. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  346. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  347. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  348. if (is_array($_SESSION['tmp_answers']['destination'])) {
  349. $tmp = array_pop($_SESSION['tmp_answers']['destination']);
  350. }
  351. } else {
  352. $msgErr = get_lang('MinHotspot');
  353. }
  354. } else {
  355. // At least 1 answer
  356. if ($nbrAnswers > 1) {
  357. $nbrAnswers--;
  358. // Remove the last answer
  359. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  360. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  361. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  362. }
  363. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  364. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  365. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  366. } else {
  367. $msgErr = get_lang('MinHotspot');
  368. }
  369. }
  370. }
  371. if ($moreAnswers) {
  372. if ($nbrAnswers < 12) {
  373. $nbrAnswers++;
  374. // Add a new answer
  375. $_SESSION['tmp_answers']['answer'][] = '';
  376. if ($objExercise->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_EXAM) {
  377. $_SESSION['tmp_answers']['comment'][] = '';
  378. }
  379. $_SESSION['tmp_answers']['weighting'][] = '1';
  380. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  381. $_SESSION['tmp_answers']['hotspot_type'][] = 'square';
  382. $_SESSION['tmp_answers']['destination'][] = '';
  383. } else {
  384. $msgErr = get_lang('MaxHotspot');
  385. }
  386. }
  387. if ($moreOARAnswers) {
  388. if ($nbrAnswers < 12) {
  389. // Add a new answer
  390. $nbrAnswers++;
  391. $_SESSION['tmp_answers']['answer'][] = '';
  392. $_SESSION['tmp_answers']['comment'][] = '';
  393. $_SESSION['tmp_answers']['weighting'][] = '1';
  394. $_SESSION['tmp_answers']['hotspot_coordinates'][] = '0;0|0|0';
  395. $_SESSION['tmp_answers']['hotspot_type'][] = 'oar';
  396. $_SESSION['tmp_answers']['destination'][] = '';
  397. } else {
  398. $msgErr = get_lang('MaxHotspot');
  399. }
  400. }
  401. if ($debug > 0) {
  402. echo str_repeat('&nbsp;', 2) . '$usedInSeveralExercises is untrue' . "<br />\n";
  403. }
  404. if ($debug > 0) {
  405. echo str_repeat('&nbsp;', 4) . '$answerType is HOT_SPOT' . "<br />\n";
  406. }
  407. if ($answerType == HOT_SPOT_DELINEATION) {
  408. $hotspot_colors = array("", "#4271B5", "#FE8E16", "#45C7F0", "#BCD631", "#D63173", "#D7D7D7", "#90AFDD", "#AF8640", "#4F9242", "#F4EB24", "#ED2024", "#3B3B3B");
  409. } else {
  410. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  411. "#4271B5",
  412. "#FE8E16",
  413. "#45C7F0",
  414. "#BCD631",
  415. "#D63173",
  416. "#D7D7D7",
  417. "#90AFDD",
  418. "#AF8640",
  419. "#4F9242",
  420. "#F4EB24",
  421. "#ED2024",
  422. "#3B3B3B",
  423. "#F7BDE2");
  424. }
  425. Display::tag('h3', get_lang('Question') . ": " . $questionName.' '.Display::return_icon('info3.gif', get_lang('HotspotChoose')));
  426. if (!empty($msgErr)) {
  427. Display::display_normal_message($msgErr); //main API
  428. }
  429. $hotspot_admin_url = api_get_path(WEB_CODE_PATH) . 'exercice/admin.php?' . api_get_cidreq() . '&hotspotadmin=' . $modifyAnswers . '&exerciseId=' . $exerciseId;
  430. ?>
  431. <form method="post" action="<?php echo $hotspot_admin_url; ?>" id="frm_exercise" name="frm_exercise">
  432. <table border="0" cellpadding="0" cellspacing="2" width="100%">
  433. <tr>
  434. <td colspan="2" valign="bottom">
  435. <?php
  436. $navigator_info = api_get_navigator();
  437. //ie6 fix
  438. if ($navigator_info['name'] == 'Internet Explorer' && $navigator_info['version'] == '6') {
  439. ?>
  440. <?php if ($answerType == HOT_SPOT_DELINEATION) { ?>
  441. <input type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessOAR'); ?>" >
  442. <input type="submit" class="btn plus" name="moreOARAnswers" value="<?php echo get_lang('MoreOAR'); ?>" />
  443. <?php } else { ?>
  444. <input type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" >
  445. <input type="submit" class="btn plus" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" />
  446. <?php } ?>
  447. <input type="submit" class="btn save" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" />
  448. <?php
  449. } else {
  450. if ($answerType == HOT_SPOT_DELINEATION) {
  451. ?>
  452. <button type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessOAR'); ?>" ><?php echo get_lang('LessOAR'); ?></button>
  453. <button type="submit" class="btn plus" name="moreOARAnswers" value="<?php echo get_lang('MoreOAR'); ?>" /><?php echo get_lang('MoreOAR'); ?></button>
  454. <?php } else { ?>
  455. <button type="submit" class="btn minus" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" ><?php echo get_lang('LessHotspots'); ?></button>
  456. <button type="submit" class="btn plus" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" /><?php echo get_lang('MoreHotspots'); ?></button>
  457. <?php } ?>
  458. <button type="submit" class="btn save" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" /><?php echo get_lang('AddQuestionToExercise'); ?></button>
  459. <?php
  460. }
  461. ?>
  462. </td>
  463. </tr>
  464. <tr>
  465. <td valign="top">
  466. <input type="hidden" name="formSent" value="1" />
  467. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  468. <table class="data_table">
  469. <!--
  470. <tr>
  471. <td colspan="5"><?php echo get_lang('AnswerHotspot'); ?> :</td>
  472. </tr>
  473. -->
  474. <tr>
  475. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  476. <th><?php echo get_lang('HotspotDescription'); ?> *</th>
  477. <?php if ($answerType == HOT_SPOT_DELINEATION) echo '<th >' . get_lang('Thresholds') . '</th>'; ?>
  478. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  479. <th><?php echo get_lang('Comment'); ?></th>
  480. <?php if ($answerType == HOT_SPOT_DELINEATION) echo '<th >' . get_lang('Scenario') . '</th>'; ?>
  481. <?php } else { ?>
  482. <th colspan="2"><?php echo get_lang('Comment'); ?></th>
  483. <?php } ?>
  484. <th><?php echo get_lang('QuestionWeighting'); ?> *</th>
  485. </tr>
  486. <?php
  487. $list = new LearnpathList(api_get_user_id());
  488. $flat_list = $list->get_flat_list(); //loading list of LPs
  489. for ($i = 1; $i <= $nbrAnswers; $i++) {
  490. // is an delineation
  491. if ($answerType == HOT_SPOT_DELINEATION) {
  492. $select_lp_id = array();
  493. $option_lp = '';
  494. // setting the LP
  495. $is_selected = false;
  496. foreach ($flat_list as $id => $details) {
  497. $select_lp_id[$id] = $details['lp_name'];
  498. $selected = '';
  499. if ($id == $lp[$i]) {
  500. $is_selected = true;
  501. $selected = 'selected="selected"';
  502. }
  503. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  504. }
  505. if ($is_selected) {
  506. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  507. } else {
  508. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  509. }
  510. //Feedback SELECT
  511. $question_list = $objExercise->selectQuestionList();
  512. $option_feed = '';
  513. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  514. foreach ($question_list as $key => $questionid) {
  515. $selected = '';
  516. $question = Question::read($questionid);
  517. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  518. $select_lp_id[$id] = $details['lp_name'];
  519. if ($questionid == $select_question[$i]) {
  520. $selected = 'selected="selected"';
  521. }
  522. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  523. }
  524. if ($select_question[$i] == -1)
  525. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  526. else
  527. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  528. //-------- IF it is a delineation
  529. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  530. for ($k = 1; $k <= 100; $k++) {
  531. $selected1 = $selected2 = $selected3 = '';
  532. if ($k == $threadhold1[$i])
  533. $selected1 = 'selected="selected"';
  534. if ($k == $threadhold2[$i])
  535. $selected2 = 'selected="selected"';
  536. if ($k == $threadhold3[$i])
  537. $selected3 = 'selected="selected"';
  538. $option1.='<option ' . $selected1 . ' >' . $k . '</option>';
  539. $option2.='<option ' . $selected2 . ' >' . $k . '</option>';
  540. $option3.='<option ' . $selected3 . '>' . $k . '</option>';
  541. }
  542. ?>
  543. <tr>
  544. <td valign="top">
  545. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  546. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  547. </td>
  548. <td valign="top" align="left">
  549. <b><?php echo get_lang('Delineation'); ?></b><br /><br />
  550. <?php echo get_lang('MinOverlap'); ?><br/><br/>
  551. <?php echo get_lang('MaxExcess'); ?><br/><br/>
  552. <?php echo get_lang('MaxMissing'); ?><br/><br/>
  553. </td>
  554. <td>
  555. <br/><br/>
  556. <select name="threadhold1[<?php echo $i; ?>]" >
  557. <?php echo $option1; ?>
  558. </select>%
  559. <br/><br/>
  560. <select name="threadhold2[<?php echo $i; ?>]" >
  561. <?php echo $option2; ?>
  562. </select>%
  563. <br/><br/>
  564. <select name="threadhold3[<?php echo $i; ?>]" >
  565. <?php echo $option3; ?>
  566. </select>%
  567. <br/>
  568. </td>
  569. <td align="left">
  570. <br />
  571. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%">
  572. <?php echo Security::remove_XSS($comment[$i]); ?>
  573. </textarea>
  574. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  575. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  576. <br/>
  577. <?php echo get_lang('LearnerIsInformed'); ?>
  578. </td>
  579. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  580. <td>
  581. <table>
  582. <tr>
  583. <td>
  584. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  585. <?php echo get_lang('TryAgain'); ?>
  586. <br /><br />
  587. <?php echo get_lang('SeeTheory'); ?> <br />
  588. <select name="lp[<?php echo $i; ?>]" >
  589. <?php echo $option_lp; ?>
  590. </select>
  591. <br /><br />
  592. <?php echo get_lang('Other'); ?> <br />
  593. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  594. <br /> <br />
  595. <?php echo get_lang('SelectQuestion'); ?> <br />
  596. <select name="select_question[<?php echo $i; ?>]" >
  597. <?php echo $option_feed; ?>
  598. </select>
  599. </td>
  600. </tr>
  601. </table>
  602. </td>
  603. <?php } else { ?>
  604. <td> &nbsp;</td>
  605. <?php
  606. }
  607. }
  608. //elseif ($_SESSION['tmp_answers']['hotspot_type'][$i]=='noerror' || $_SESSION['tmp_answers']['answer'][$i]=='noerror')
  609. elseif (false) {
  610. ?>
  611. <tr>
  612. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  613. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  614. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  615. <th></th>
  616. </tr>
  617. <tr>
  618. <td colspan="2" valign="top" align="left">
  619. <?php echo get_lang('LearnerHasNoMistake'); ?>
  620. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  621. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  622. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  623. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  624. </td>
  625. <td colspan="2" align="left">
  626. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  627. </td>
  628. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  629. <td>
  630. <table>
  631. <tr>
  632. <td>
  633. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  634. <?php echo get_lang('TryAgain'); ?>
  635. <br /><br />
  636. <?php echo get_lang('SeeTheory'); ?> <br />
  637. <select name="lp[<?php echo $i; ?>]" >
  638. <?php echo $option_lp; ?>
  639. </select>
  640. <br /><br />
  641. <?php echo get_lang('Other'); ?> <br />
  642. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  643. <br /> <br />
  644. <?php echo get_lang('SelectQuestion'); ?> <br />
  645. <select name="select_question[<?php echo $i; ?>]">
  646. <?php echo $option_feed; ?>
  647. </select>
  648. </td>
  649. </tr>
  650. </table>
  651. </td>
  652. <?php } else { ?>
  653. <td>&nbsp;</td>
  654. <?php } ?>
  655. </tr>
  656. <?php
  657. }
  658. // if it's an OAR
  659. elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  660. if ($i == 2) {
  661. ?>
  662. <tr>
  663. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  664. <th ><?php echo get_lang('OAR'); ?>*</th>
  665. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  666. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  667. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  668. <?php } else { ?>
  669. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  670. <?php } ?>
  671. <th>&nbsp;</th>
  672. </tr>
  673. <?php
  674. }
  675. ?>
  676. <tr>
  677. <td valign="top">
  678. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  679. </td>
  680. <td valign="top" align="left">
  681. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="20" />
  682. </td>
  683. <td colspan="2" align="left">
  684. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  685. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  686. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  687. </td>
  688. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  689. <td>
  690. <table>
  691. <tr>
  692. <td>
  693. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  694. <?php echo get_lang('TryAgain'); ?>
  695. <br /><br />
  696. <?php echo get_lang('SeeTheory'); ?> <br />
  697. <select name="lp[<?php echo $i; ?>]" >
  698. <?php echo $option_lp; ?>
  699. </select>
  700. <br /><br />
  701. <?php echo get_lang('Other'); ?> <br />
  702. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  703. <br /><br />
  704. <?php echo get_lang('SelectQuestion'); ?> <br />
  705. <select name="select_question[<?php echo $i; ?>]">
  706. <?php echo $option_feed; ?>
  707. </select>
  708. </td>
  709. </tr>
  710. </table>
  711. </td>
  712. <?php } else { ?>
  713. <td>&nbsp;</td>
  714. <?php } ?>
  715. <?php
  716. }
  717. } else { //end if is delineation
  718. ?>
  719. <td valign="top">
  720. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  721. </td>
  722. <td valign="top" align="left">
  723. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="45" />
  724. </td>
  725. <textarea name="<?php echo "comment[$i]"; ?>"><?php echo $content; ?></textarea>
  726. <td>&nbsp;</td>
  727. <td align="left" ><?php echo $return; ?></td>
  728. <?php
  729. }
  730. ?>
  731. <td valign="top">
  732. <?php
  733. //if ($answerType==HOT_SPOT_DELINEATION && $i!=2)
  734. if ($answerType == HOT_SPOT_DELINEATION) {
  735. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  736. ?>
  737. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
  738. <?php } else { ?>
  739. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  740. <?php
  741. }
  742. }
  743. if ($answerType == HOT_SPOT) {
  744. ?>
  745. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  746. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  747. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  748. <?php
  749. }
  750. ?>
  751. </td>
  752. </tr>
  753. <?php
  754. }
  755. $list = new LearnpathList(api_get_user_id());
  756. $flat_list = $list->get_flat_list();
  757. $select_lp_id = array();
  758. $option_lp = '';
  759. //$option_lp.='<option value="0">'.get_lang('SelectTargetLP').'</option>';
  760. foreach ($flat_list as $id => $details) {
  761. $selected = '';
  762. $select_lp_id[$id] = $details['lp_name'];
  763. if ($id == $lp_noerror) {
  764. $selected = 'selected="selected"';
  765. $is_selected = true;
  766. }
  767. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  768. }
  769. if ($is_selected) {
  770. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  771. } else {
  772. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  773. }
  774. // Feedback SELECT
  775. $question_list = $objExercise->selectQuestionList();
  776. $option_feed = '';
  777. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  778. foreach ($question_list as $key => $questionid) {
  779. $selected = '';
  780. $question = Question::read($questionid);
  781. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  782. $select_lp_id[$id] = $details['lp_name'];
  783. if ($questionid == $select_question_noerror) {
  784. $selected = 'selected="selected"';
  785. }
  786. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  787. }
  788. if ($select_question_noerror == -1)
  789. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  790. else
  791. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  792. if ($answerType == HOT_SPOT_DELINEATION) {
  793. ?>
  794. <tr>
  795. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  796. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  797. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  798. <th><?php echo get_lang('Scenario'); ?></th>
  799. <?php } else { ?>
  800. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  801. <?php } ?>
  802. <th>&nbsp;</th>
  803. </tr>
  804. <tr>
  805. <td colspan="2" valign="top" align="left">
  806. <?php echo get_lang('LearnerHasNoMistake'); ?>
  807. </td>
  808. <td colspan="2" align="left">
  809. <textarea wrap="virtual" rows="3" cols="25" name="comment_noerror" style="width: 100%"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  810. </td>
  811. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  812. <td>
  813. <table>
  814. <tr>
  815. <td>
  816. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  817. <?php echo get_lang('TryAgain'); ?>
  818. <br /><br />
  819. <?php echo get_lang('SeeTheory'); ?> <br />
  820. <select name="lp_noerror" >
  821. <?php echo $option_lp; ?>
  822. </select>
  823. <br /><br />
  824. <?php echo get_lang('Other'); ?> <br />
  825. <input name="url_noerror" value="<?php echo $url_noerror; ?>">
  826. <br /><br />
  827. <?php echo get_lang('SelectQuestion'); ?> <br />
  828. <select name="select_question_noerror">
  829. <?php echo $option_feed; ?>
  830. </select>
  831. </td>
  832. </tr>
  833. </table>
  834. </td>
  835. <td>&nbsp;</td>
  836. <?php } else { ?>
  837. <td colspan="2">&nbsp;</td>
  838. <?php } ?>
  839. </tr>
  840. <?php
  841. }
  842. ?>
  843. </table>
  844. </td>
  845. </tr>
  846. <tr>
  847. <td colspan="2" valign="top" style="border-top:none">
  848. <script>
  849. <!--
  850. // Version check based upon the values entered above in "Globals"
  851. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  852. <?php
  853. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  854. $height = 450;
  855. ?>
  856. // Check to see if the version meets the requirements for playback
  857. if (hasReqestedVersion) { // if we've detected an acceptable version
  858. 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 ?>">'
  859. + '<param name="movie" value="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  860. + '<param name="test" value="OOoowww fo shooww" />'
  861. + '</object>';
  862. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  863. } else { // flash is too old or we can't detect the plugin
  864. var alternateContent = 'Error<br \/>'
  865. + 'This content requires the Macromedia Flash Player.<br \/>'
  866. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  867. document.write(alternateContent); // insert non-flash content
  868. }
  869. // -->
  870. </script>
  871. </td>
  872. </tr>
  873. </table>
  874. </form>
  875. <?php
  876. if ($debug > 0) {
  877. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  878. }
  879. }