hotspot_admin.inc.php 12 KB

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