hotspot_admin.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * This script allows to manage answers. It is included from the script admin.php
  18. * @package dokeos.exercise
  19. * @author Toon Keppens
  20. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  21. */
  22. require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
  23. // ALLOWED_TO_INCLUDE is defined in admin.php
  24. if(!defined('ALLOWED_TO_INCLUDE')) {
  25. exit();
  26. }
  27. $modifyAnswers = $_GET['hotspotadmin'];
  28. if(!is_object($objQuestion)) {
  29. $objQuestion = Question :: read($modifyAnswers);
  30. }
  31. $questionName=$objQuestion->selectTitle();
  32. $answerType=$objQuestion->selectType();
  33. $pictureName=$objQuestion->selectPicture();
  34. $debug = 0; // debug variable to get where we are
  35. $okPicture=empty($pictureName)?false:true;
  36. // if we come from the warning box "this question is used in serveral exercises"
  37. if($modifyIn)
  38. {
  39. if($debug>0){echo '$modifyIn was set'."<br />\n";}
  40. // if the user has chosed to modify the question only in the current exercise
  41. if($modifyIn == 'thisExercise')
  42. {
  43. // duplicates the question
  44. $questionId=$objQuestion->duplicate();
  45. // deletes the old question
  46. $objQuestion->delete($exerciseId);
  47. // removes the old question ID from the question list of the Exercise object
  48. $objExercise->removeFromList($modifyAnswers);
  49. // adds the new question ID into the question list of the Exercise object
  50. $objExercise->addToList($questionId);
  51. // construction of the duplicated Question
  52. $objQuestion = Question :: read($questionId);
  53. // adds the exercise ID into the exercise list of the Question object
  54. $objQuestion->addToList($exerciseId);
  55. // copies answers from $modifyAnswers to $questionId
  56. $objAnswer->duplicate($questionId);
  57. // construction of the duplicated Answers
  58. $objAnswer=new Answer($questionId);
  59. }
  60. $color=unserialize($color);
  61. $reponse=unserialize($reponse);
  62. $comment=unserialize($comment);
  63. $weighting=unserialize($weighting);
  64. $hotspot_coordinates=unserialize($hotspot_coordinates);
  65. $hotspot_type=unserialize($hotspot_type);
  66. unset($buttonBack);
  67. }
  68. // the answer form has been submitted
  69. if($submitAnswers || $buttonBack)
  70. {
  71. if($debug>0){echo '$submitAnswers or $buttonBack was set'."<br />\n";}
  72. $questionWeighting=$nbrGoodAnswers=0;
  73. for($i=1;$i <= $nbrAnswers;$i++)
  74. {
  75. if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  76. $reponse[$i]=trim($reponse[$i]);
  77. $comment[$i]=trim($comment[$i]);
  78. $weighting[$i]=$weighting[$i]; // it can be float
  79. // checks if field is empty
  80. if(empty($reponse[$i]) && $reponse[$i] != '0') {
  81. $msgErr=get_lang('HotspotGiveAnswers');
  82. // clears answers already recorded into the Answer object
  83. $objAnswer->cancel();
  84. break;
  85. }
  86. if($weighting[$i] <= 0) {
  87. $msgErr=get_lang('HotspotWeightingError');
  88. // clears answers already recorded into the Answer object
  89. $objAnswer->cancel();
  90. break;
  91. }
  92. if($hotspot_coordinates[$i] == '0;0|0|0' || empty($hotspot_coordinates[$i])) {
  93. $msgErr=get_lang('HotspotNotDrawn');
  94. // clears answers already recorded into the Answer object
  95. $objAnswer->cancel();
  96. break;
  97. }
  98. } // end for()
  99. if(empty($msgErr)) {
  100. for($i=1;$i <= $nbrAnswers;$i++) {
  101. if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  102. $reponse[$i]=trim($reponse[$i]);
  103. $comment[$i]=addslashes(trim($comment[$i]));
  104. $weighting[$i]=($weighting[$i]); //it can be float
  105. if($weighting[$i]) {
  106. $questionWeighting+=$weighting[$i];
  107. }
  108. // creates answer
  109. $objAnswer->createAnswer($reponse[$i], '',$comment[$i],$weighting[$i],$i,$hotspot_coordinates[$i],$hotspot_type[$i]);
  110. } // end for()
  111. // saves the answers into the data base
  112. $objAnswer->save();
  113. // sets the total weighting of the question
  114. $objQuestion->updateWeighting($questionWeighting);
  115. $objQuestion->save($exerciseId);
  116. $editQuestion=$questionId;
  117. unset($modifyAnswers);
  118. echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  119. }
  120. if($debug>0){echo '$modifyIn was set - end'."<br />\n";}
  121. }
  122. if($modifyAnswers)
  123. {
  124. if($debug>0){echo str_repeat('&nbsp;',0).'$modifyAnswers is set'."<br />\n";}
  125. // construction of the Answer object
  126. $objAnswer=new Answer($objQuestion -> id);
  127. api_session_register('objAnswer');
  128. if($debug>0){echo str_repeat('&nbsp;',2).'$answerType is HOT_SPOT'."<br />\n";}
  129. $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
  130. if(!$nbrAnswers)
  131. {
  132. $nbrAnswers=$objAnswer->selectNbrAnswers();
  133. $reponse=Array();
  134. $comment=Array();
  135. $weighting=Array();
  136. $hotspot_coordinates=Array();
  137. $hotspot_type=array();
  138. for($i=1;$i <= $nbrAnswers;$i++)
  139. {
  140. $reponse[$i]=$objAnswer->selectAnswer($i);
  141. $comment[$i]=$objAnswer->selectComment($i);
  142. $weighting[$i]=$objAnswer->selectWeighting($i);
  143. $hotspot_coordinates[$i]=$objAnswer->selectHotspotCoordinates($i);
  144. $hotspot_type[$i]=$objAnswer->selectHotspotType($i);
  145. }
  146. }
  147. $_SESSION['tmp_answers'] = array();
  148. $_SESSION['tmp_answers']['answer'] = $reponse;
  149. $_SESSION['tmp_answers']['comment'] = $comment;
  150. $_SESSION['tmp_answers']['weighting'] = $weighting;
  151. $_SESSION['tmp_answers']['hotspot_coordinates'] = $hotspot_coordinates;
  152. $_SESSION['tmp_answers']['hotspot_type'] = $hotspot_type;
  153. if($lessAnswers)
  154. {
  155. // At least 1 answer
  156. if ($nbrAnswers > 1) {
  157. $nbrAnswers--;
  158. // Remove the last answer
  159. $tmp = array_pop($_SESSION['tmp_answers']['answer']);
  160. $tmp = array_pop($_SESSION['tmp_answers']['comment']);
  161. $tmp = array_pop($_SESSION['tmp_answers']['weighting']);
  162. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_coordinates']);
  163. $tmp = array_pop($_SESSION['tmp_answers']['hotspot_type']);
  164. }
  165. else
  166. {
  167. $msgErr=get_lang('MinHotspot');
  168. }
  169. }
  170. if($moreAnswers)
  171. {
  172. if ($nbrAnswers < 12)
  173. {
  174. $nbrAnswers++;
  175. // Add a new answer
  176. $_SESSION['tmp_answers']['answer'][]='';
  177. $_SESSION['tmp_answers']['comment'][]='';
  178. $_SESSION['tmp_answers']['weighting'][]='1';
  179. $_SESSION['tmp_answers']['hotspot_coordinates'][]='0;0|0|0';
  180. $_SESSION['tmp_answers']['hotspot_type'][]='square';
  181. }
  182. else
  183. {
  184. $msgErr=get_lang('MaxHotspot');
  185. }
  186. }
  187. if($debug>0){echo str_repeat('&nbsp;',2).'$usedInSeveralExercises is untrue'."<br />\n";}
  188. if($debug>0){echo str_repeat('&nbsp;',4).'$answerType is HOT_SPOT'."<br />\n";}
  189. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  190. "#4271B5",
  191. "#FE8E16",
  192. "#3B3B3B",
  193. "#BCD631",
  194. "#D63173",
  195. "#D7D7D7",
  196. "#90AFDD",
  197. "#AF8640",
  198. "#4F9242",
  199. "#F4EB24",
  200. "#ED2024",
  201. "#45C7F0",
  202. "#F7BDE2");
  203. ?>
  204. <h3>
  205. <?php echo $langQuestion.": ".$questionName.' <img src="../img/info3.gif" title="'.strip_tags(get_lang('HotspotChoose')).'" alt="'.strip_tags(get_lang('HotspotChoose')).'" />'; ?>
  206. </h3>
  207. <?php
  208. if(!empty($msgErr))
  209. {
  210. Display::display_normal_message($msgErr); //main API
  211. }
  212. ?>
  213. <form method="post" action="<?php echo api_get_self(); ?>?hotspotadmin=<?php echo $modifyAnswers; ?>" name="frm_exercise">
  214. <table border="0" cellpadding="0" cellspacing="2" width="100%">
  215. <tr>
  216. <td colspan="2" valign="bottom">
  217. <button type="submit" class="minus" name="lessAnswers" value="<?php echo get_lang('LessHotspots'); ?>" ><?php echo get_lang('LessHotspots'); ?></button>
  218. <button type="submit" class="plus" name="moreAnswers" value="<?php echo get_lang('MoreHotspots'); ?>" /><?php echo get_lang('MoreHotspots'); ?></button>
  219. <button type="submit" class="cancel" name="cancelAnswers" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;" ><?php echo get_lang('Cancel'); ?></button>
  220. <button type="submit" class="save" name="submitAnswers" value="<?php echo get_lang('Ok'); ?>" /><?php echo get_lang('SaveQuestion'); ?></button>
  221. </td>
  222. </tr>
  223. <tr>
  224. <td valign="top" style="border:1px solid #4271b5;border-top:none;border-bottom:none;border-right:none;" >
  225. <input type="hidden" name="formSent" value="1" />
  226. <input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
  227. <table class="data_table">
  228. <!--
  229. <tr>
  230. <td colspan="5"><?php echo get_lang('AnswerHotspot'); ?> :</td>
  231. </tr>
  232. -->
  233. <tr>
  234. <th width="5">&nbsp;<?php /* echo get_lang('Hotspot'); */ ?></th>
  235. <th ><?php echo get_lang('HotspotDescription'); ?>*</th>
  236. <th ><?php echo get_lang('Comment'); ?></th>
  237. <th><?php echo get_lang('QuestionWeighting'); ?>*</th>
  238. </tr>
  239. <?php
  240. for($i=1;$i <= $nbrAnswers;$i++) {
  241. ?>
  242. <tr>
  243. <td valign="top"><div style="height: 15px; width: 15px; background-color: <?php echo $hotspot_colors[$i]; ?>"> </div></td>
  244. <td valign="top" align="left"><input type="text" name="reponse[<?php echo $i; ?>]" value="<?php echo htmlentities($reponse[$i]); ?>" size="45" /></td>
  245. <td align="left"><textarea wrap="virtual" rows="1" cols="25" name="comment[<?php echo $i; ?>]" style="width: 100%"><?php echo stripslashes(htmlentities($comment[$i])); ?></textarea></td>
  246. <td valign="top"><input type="text" name="weighting[<?php echo $i; ?>]" size="5" value="<?php echo (isset($weighting[$i]) ? float_format($weighting[$i],1) : 10); ?>" />
  247. <input type="hidden" name="hotspot_coordinates[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_coordinates[$i]) ? '0;0|0|0' : $hotspot_coordinates[$i]); ?>" />
  248. <input type="hidden" name="hotspot_type[<?php echo $i; ?>]" value="<?php echo (empty($hotspot_type[$i]) ? 'square' : $hotspot_type[$i]); ?>" /></td>
  249. </tr>
  250. <?php
  251. }
  252. ?>
  253. </table>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td colspan="2" valign="top" style="border:1px solid #4271b5;border-top:none">
  258. <script type="text/javascript">
  259. <!--
  260. // Version check based upon the values entered above in "Globals"
  261. var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  262. // Check to see if the version meets the requirements for playback
  263. if (hasReqestedVersion) { // if we've detected an acceptable version
  264. var oeTags = '<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" width="720" height="650">'
  265. + '<param name="movie" value="../plugin/hotspot/hotspot_admin.swf?modifyAnswers=<?php echo $modifyAnswers ?>" />'
  266. + '<param name="test" value="OOoowww fo shooww" />'
  267. + '</object>';
  268. document.write(oeTags); // embed the Flash Content SWF when all tests are passed
  269. } else { // flash is too old or we can't detect the plugin
  270. var alternateContent = 'Error<br \/>'
  271. + 'This content requires the Macromedia Flash Player.<br \/>'
  272. + '<a href=http://www.macromedia.com/go/getflash/>Get Flash<\/a>';
  273. document.write(alternateContent); // insert non-flash content
  274. }
  275. // -->
  276. </script>
  277. </td>
  278. </tr>
  279. </table>
  280. </form>
  281. <?php
  282. if($debug>0){echo str_repeat('&nbsp;',0).'$modifyAnswers was set - end'."<br />\n";}
  283. }
  284. ?>