hotspot_admin.inc.php 37 KB

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