hotspot_admin.inc.php 37 KB

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