hotspot_admin.inc.php 51 KB

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