hotspot_admin.inc.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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 . ' <img src="../img/info3.gif" title="' . strip_tags(get_lang('HotspotChoose')) . '" alt="' . strip_tags(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. require_once '../newscorm/learnpathList.class.php';
  488. $list = new LearnpathList(api_get_user_id());
  489. $flat_list = $list->get_flat_list(); //loading list of LPs
  490. for ($i = 1; $i <= $nbrAnswers; $i++) {
  491. // is an delineation
  492. if ($answerType == HOT_SPOT_DELINEATION) {
  493. $select_lp_id = array();
  494. $option_lp = '';
  495. // setting the LP
  496. $is_selected = false;
  497. foreach ($flat_list as $id => $details) {
  498. $select_lp_id[$id] = $details['lp_name'];
  499. $selected = '';
  500. if ($id == $lp[$i]) {
  501. $is_selected = true;
  502. $selected = 'selected="selected"';
  503. }
  504. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  505. }
  506. if ($is_selected) {
  507. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  508. } else {
  509. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  510. }
  511. //Feedback SELECT
  512. $question_list = $objExercise->selectQuestionList();
  513. $option_feed = '';
  514. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  515. foreach ($question_list as $key => $questionid) {
  516. $selected = '';
  517. $question = Question::read($questionid);
  518. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  519. $select_lp_id[$id] = $details['lp_name'];
  520. if ($questionid == $select_question[$i]) {
  521. $selected = 'selected="selected"';
  522. }
  523. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  524. }
  525. if ($select_question[$i] == -1)
  526. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  527. else
  528. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  529. //-------- IF it is a delineation
  530. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'delineation') {
  531. for ($k = 1; $k <= 100; $k++) {
  532. $selected1 = $selected2 = $selected3 = '';
  533. if ($k == $threadhold1[$i])
  534. $selected1 = 'selected="selected"';
  535. if ($k == $threadhold2[$i])
  536. $selected2 = 'selected="selected"';
  537. if ($k == $threadhold3[$i])
  538. $selected3 = 'selected="selected"';
  539. $option1.='<option ' . $selected1 . ' >' . $k . '</option>';
  540. $option2.='<option ' . $selected2 . ' >' . $k . '</option>';
  541. $option3.='<option ' . $selected3 . '>' . $k . '</option>';
  542. }
  543. ?>
  544. <tr>
  545. <td valign="top">
  546. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  547. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="delineation" />
  548. </td>
  549. <td valign="top" align="left">
  550. <b><?php echo get_lang('Delineation'); ?></b><br /><br />
  551. <?php echo get_lang('MinOverlap'); ?><br/><br/>
  552. <?php echo get_lang('MaxExcess'); ?><br/><br/>
  553. <?php echo get_lang('MaxMissing'); ?><br/><br/>
  554. </td>
  555. <td>
  556. <br/><br/>
  557. <select name="threadhold1[<?php echo $i; ?>]" >
  558. <?php echo $option1; ?>
  559. </select>%
  560. <br/><br/>
  561. <select name="threadhold2[<?php echo $i; ?>]" >
  562. <?php echo $option2; ?>
  563. </select>%
  564. <br/><br/>
  565. <select name="threadhold3[<?php echo $i; ?>]" >
  566. <?php echo $option3; ?>
  567. </select>%
  568. <br/>
  569. </td>
  570. <td align="left">
  571. <br />
  572. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%">
  573. <?php echo Security::remove_XSS($comment[$i]); ?>
  574. </textarea>
  575. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="delineation" />
  576. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  577. <br/>
  578. <?php echo get_lang('LearnerIsInformed'); ?>
  579. </td>
  580. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  581. <td>
  582. <table>
  583. <tr>
  584. <td>
  585. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  586. <?php echo get_lang('TryAgain'); ?>
  587. <br /><br />
  588. <?php echo get_lang('SeeTheory'); ?> <br />
  589. <select name="lp[<?php echo $i; ?>]" >
  590. <?php echo $option_lp; ?>
  591. </select>
  592. <br /><br />
  593. <?php echo get_lang('Other'); ?> <br />
  594. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  595. <br /> <br />
  596. <?php echo get_lang('SelectQuestion'); ?> <br />
  597. <select name="select_question[<?php echo $i; ?>]" >
  598. <?php echo $option_feed; ?>
  599. </select>
  600. </td>
  601. </tr>
  602. </table>
  603. </td>
  604. <?php } else { ?>
  605. <td> &nbsp;</td>
  606. <?php
  607. }
  608. }
  609. //elseif ($_SESSION['tmp_answers']['hotspot_type'][$i]=='noerror' || $_SESSION['tmp_answers']['answer'][$i]=='noerror')
  610. elseif (false) {
  611. ?>
  612. <tr>
  613. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  614. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  615. <!-- th colspan="1" ><?php echo get_lang('Scenario'); ?></th -->
  616. <th></th>
  617. </tr>
  618. <tr>
  619. <td colspan="2" valign="top" align="left">
  620. <?php echo get_lang('LearnerHasNoMistake'); ?>
  621. <input type="hidden" name="reponse[<?php echo $i; ?>]" value="noerror" />
  622. <input type="hidden" name="weighting[<?php echo $i; ?>]" value="0" />
  623. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="noerror" />
  624. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="0;0|0|0" />
  625. </td>
  626. <td colspan="2" align="left">
  627. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  628. </td>
  629. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  630. <td>
  631. <table>
  632. <tr>
  633. <td>
  634. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  635. <?php echo get_lang('TryAgain'); ?>
  636. <br /><br />
  637. <?php echo get_lang('SeeTheory'); ?> <br />
  638. <select name="lp[<?php echo $i; ?>]" >
  639. <?php echo $option_lp; ?>
  640. </select>
  641. <br /><br />
  642. <?php echo get_lang('Other'); ?> <br />
  643. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  644. <br /> <br />
  645. <?php echo get_lang('SelectQuestion'); ?> <br />
  646. <select name="select_question[<?php echo $i; ?>]">
  647. <?php echo $option_feed; ?>
  648. </select>
  649. </td>
  650. </tr>
  651. </table>
  652. </td>
  653. <?php } else { ?>
  654. <td>&nbsp;</td>
  655. <?php } ?>
  656. </tr>
  657. <?php
  658. }
  659. // if it's an OAR
  660. elseif ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  661. if ($i == 2) {
  662. ?>
  663. <tr>
  664. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  665. <th ><?php echo get_lang('OAR'); ?>*</th>
  666. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  667. <th colspan="2" ><?php echo get_lang('Comment'); ?></th>
  668. <th ><?php if ($answerType == HOT_SPOT_DELINEATION) echo get_lang('Scenario'); ?></th>
  669. <?php } else { ?>
  670. <th colspan="3" ><?php echo get_lang('Comment'); ?></th>
  671. <?php } ?>
  672. <th>&nbsp;</th>
  673. </tr>
  674. <?php
  675. }
  676. ?>
  677. <tr>
  678. <td valign="top">
  679. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  680. </td>
  681. <td valign="top" align="left">
  682. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="20" />
  683. </td>
  684. <td colspan="2" align="left">
  685. <textarea wrap="virtual" rows="3" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo Security::remove_XSS($comment[$i]); ?></textarea>
  686. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="oar" />
  687. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  688. </td>
  689. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  690. <td>
  691. <table>
  692. <tr>
  693. <td>
  694. <input type="checkbox" class="checkbox" name="<?php echo 'try[' . $i; ?>]" <?php if ($try[$i] == 1) echo'checked'; ?> />
  695. <?php echo get_lang('TryAgain'); ?>
  696. <br /><br />
  697. <?php echo get_lang('SeeTheory'); ?> <br />
  698. <select name="lp[<?php echo $i; ?>]" >
  699. <?php echo $option_lp; ?>
  700. </select>
  701. <br /><br />
  702. <?php echo get_lang('Other'); ?> <br />
  703. <input name="url[<?php echo $i; ?>]" value="<?php echo $url[$i]; ?>">
  704. <br /><br />
  705. <?php echo get_lang('SelectQuestion'); ?> <br />
  706. <select name="select_question[<?php echo $i; ?>]">
  707. <?php echo $option_feed; ?>
  708. </select>
  709. </td>
  710. </tr>
  711. </table>
  712. </td>
  713. <?php } else { ?>
  714. <td>&nbsp;</td>
  715. <?php } ?>
  716. <?php
  717. }
  718. } else { //end if is delineation
  719. ?>
  720. <td valign="top">
  721. <div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div>
  722. </td>
  723. <td valign="top" align="left">
  724. <input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo Security::remove_XSS($reponse[$i]); ?>" size="45" />
  725. </td>
  726. <?php
  727. $oFCKeditor = new FCKeditor("comment[$i]");
  728. $content = $comment[$i];
  729. $oFCKeditor->ToolbarSet = 'TestProposedAnswer';
  730. $oFCKeditor->Config['ToolbarStartExpanded'] = 'false';
  731. $oFCKeditor->Width = '100%';
  732. $oFCKeditor->Height = '100';
  733. $oFCKeditor->Value = $content;
  734. $return = $oFCKeditor->CreateHtml();
  735. /* <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> */
  736. ?>
  737. <td>&nbsp;</td>
  738. <td align="left" ><?php echo $return; ?></td>
  739. <?php
  740. }
  741. ?>
  742. <td valign="top">
  743. <?php
  744. //if ($answerType==HOT_SPOT_DELINEATION && $i!=2)
  745. if ($answerType == HOT_SPOT_DELINEATION) {
  746. if ($_SESSION['tmp_answers']['hotspot_type'][$i] == 'oar') {
  747. ?>
  748. <input type="hidden" name="weighting[<?php echo $i; ?>]" class="span3" value="0" />
  749. <?php } else { ?>
  750. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  751. <?php
  752. }
  753. }
  754. if ($answerType == HOT_SPOT) {
  755. ?>
  756. <input type="text" name="weighting[<?php echo $i; ?>]" class="span3" value="<?php echo (isset($weighting[$i]) ? $weighting[$i] : 10); ?>" />
  757. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  758. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" />
  759. <?php
  760. }
  761. ?>
  762. </td>
  763. </tr>
  764. <?php
  765. }
  766. require_once '../newscorm/learnpathList.class.php';
  767. $list = new LearnpathList(api_get_user_id());
  768. $flat_list = $list->get_flat_list();
  769. $select_lp_id = array();
  770. $option_lp = '';
  771. //$option_lp.='<option value="0">'.get_lang('SelectTargetLP').'</option>';
  772. foreach ($flat_list as $id => $details) {
  773. $selected = '';
  774. $select_lp_id[$id] = $details['lp_name'];
  775. if ($id == $lp_noerror) {
  776. $selected = 'selected="selected"';
  777. $is_selected = true;
  778. }
  779. $option_lp.='<option value="' . $id . '" ' . $selected . '>' . $details['lp_name'] . '</option>';
  780. }
  781. if ($is_selected) {
  782. $option_lp = '<option value="0">' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  783. } else {
  784. $option_lp = '<option value="0" selected="selected" >' . get_lang('SelectTargetLP') . '</option>' . $option_lp;
  785. }
  786. //Feedback SELECT
  787. $question_list = $objExercise->selectQuestionList();
  788. $option_feed = '';
  789. $option_feed.='<option value="0">' . get_lang('SelectTargetQuestion') . '</option>';
  790. foreach ($question_list as $key => $questionid) {
  791. $selected = '';
  792. $question = Question::read($questionid);
  793. $val = 'Q' . $key . ' :' . Text::substrwords($question->selectTitle(), ICON_SIZE_SMALL);
  794. $select_lp_id[$id] = $details['lp_name'];
  795. if ($questionid == $select_question_noerror) {
  796. $selected = 'selected="selected"';
  797. }
  798. $option_feed.='<option value="' . $questionid . '" ' . $selected . ' >' . $val . '</option>';
  799. }
  800. if ($select_question_noerror == -1)
  801. $option_feed.='<option value="-1" selected="selected" >' . get_lang('ExitTest') . '</option>';
  802. else
  803. $option_feed.='<option value="-1">' . get_lang('ExitTest') . '</option>';
  804. if ($answerType == HOT_SPOT_DELINEATION) {
  805. ?>
  806. <tr>
  807. <th colspan="2" ><?php echo get_lang('IfNoError'); ?></th>
  808. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  809. <th colspan="2" ><?php echo get_lang('Feedback'); ?></th>
  810. <th><?php echo get_lang('Scenario'); ?></th>
  811. <?php } else { ?>
  812. <th colspan="3" ><?php echo get_lang('Feedback'); ?></th>
  813. <?php } ?>
  814. <th>&nbsp;</th>
  815. </tr>
  816. <tr>
  817. <td colspan="2" valign="top" align="left">
  818. <?php echo get_lang('LearnerHasNoMistake'); ?>
  819. </td>
  820. <td colspan="2" align="left">
  821. <textarea wrap="virtual" rows="3" cols="25" name="comment_noerror" style="width: 100%"><?php echo Security::remove_XSS($comment_noerror); ?></textarea>
  822. </td>
  823. <?php if ($objExercise->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT) { ?>
  824. <td>
  825. <table>
  826. <tr>
  827. <td>
  828. <input type="checkbox" class="checkbox" name="try_noerror" <?php if ($try_noerror == 1) echo'checked'; ?> />
  829. <?php echo get_lang('TryAgain'); ?>
  830. <br /><br />
  831. <?php echo get_lang('SeeTheory'); ?> <br />
  832. <select name="lp_noerror" >
  833. <?php echo $option_lp; ?>
  834. </select>
  835. <br /><br />
  836. <?php echo get_lang('Other'); ?> <br />
  837. <input name="url_noerror" value="<?php echo $url_noerror; ?>">
  838. <br /><br />
  839. <?php echo get_lang('SelectQuestion'); ?> <br />
  840. <select name="select_question_noerror">
  841. <?php echo $option_feed; ?>
  842. </select>
  843. </td>
  844. </tr>
  845. </table>
  846. </td>
  847. <td>&nbsp;</td>
  848. <?php } else { ?>
  849. <td colspan="2">&nbsp;</td>
  850. <?php } ?>
  851. </tr>
  852. <?php
  853. }
  854. ?>
  855. </table>
  856. </td>
  857. </tr>
  858. <tr>
  859. <td colspan="2" valign="top" style="border-top:none">
  860. <script>
  861. <!--
  862. // Version check based upon the values entered above in "Globals"
  863. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  864. <?php
  865. $swf_loaded = $answerType == HOT_SPOT_DELINEATION ? 'hotspot_delineation_admin' : 'hotspot_admin';
  866. $height = 450;
  867. ?>
  868. // Check to see if the version meets the requirements for playback
  869. if (hasReqestedVersion) { // if we've detected an acceptable version
  870. 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 ?>">'
  871. + '<param name="movie" value="../plugin/hotspot/<?php echo $swf_loaded ?>.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  872. + '<param name="test" value="OOoowww fo shooww" />'
  873. + '</object>';
  874. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  875. } else { // flash is too old or we can't detect the plugin
  876. var alternateContent = 'Error<br \/>'
  877. + 'This content requires the Macromedia Flash Player.<br \/>'
  878. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  879. document.write(alternateContent); // insert non-flash content
  880. }
  881. // -->
  882. </script>
  883. </td>
  884. </tr>
  885. </table>
  886. </form>
  887. <?php
  888. if ($debug > 0) {
  889. echo str_repeat('&nbsp;', 0) . '$modifyAnswers was set - end' . "<br />\n";
  890. }
  891. }