hotspot_admin.inc.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  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. }