statement_admin.inc.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php // $Id: statement_admin.inc.php 9665 2006-10-24 10:43:48Z elixir_inter $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * STATEMENT ADMINISTRATION
  22. * This script allows to manage the statements of questions.
  23. * It is included from the script admin.php
  24. *
  25. * @author Olivier Brouckaert
  26. * @package dokeos.exercise
  27. ==============================================================================
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  35. // ALLOWED_TO_INCLUDE is defined in admin.php
  36. if(!defined('ALLOWED_TO_INCLUDE'))
  37. {
  38. exit();
  39. }
  40. //debug var. Set to 0 if you don't want any debug display
  41. $debug = 0;
  42. // the question form has been submitted
  43. // this question form is the one below.
  44. // In case the form has been submitted, at the end of the process part of this script, we "skip" the form
  45. // display and pass to answer_admin.inc.php which displays a form for the answer itself
  46. if($submitQuestion)
  47. {
  48. if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion is true'."<br />\n";}
  49. $questionName=trim(stripslashes($_POST['questionName']));
  50. $questionDescription=trim(stripslashes($_POST['questionDescription']));
  51. $_FILES['imageUpload']['name']=strtolower($_FILES['imageUpload']['name']);
  52. // no name given
  53. if(empty($questionName))
  54. {
  55. $msgErr=get_lang('GiveQuestion');
  56. }
  57. // checks if the question is used in several exercises
  58. elseif($exerciseId && !$modifyIn && $objQuestion->selectNbrExercises() > 1)
  59. {
  60. if($debug>0){echo str_repeat('&nbsp;',4).'$exerciseId is set and $modifyIn is unset and this question is in more than one exercise'."<br />\n";}
  61. $usedInSeveralExercises=1;
  62. // if a picture has been set
  63. if($_FILES['imageUpload']['size'])
  64. {
  65. // saves the picture into a temporary file
  66. $objQuestion->setTmpPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']);
  67. }
  68. }
  69. else
  70. {
  71. if($debug>0){echo str_repeat('&nbsp;',4).'You have chosen to modify/add a question locally'."<br />\n";}
  72. // if the user has chosed to modify the question only in the current exercise
  73. if($modifyIn == 'thisExercise')
  74. {
  75. // duplicates the question
  76. $questionId=$objQuestion->duplicate();
  77. // deletes the old question
  78. $objQuestion->delete($exerciseId);
  79. // removes the old question ID from the question list of the Exercise object
  80. $objExercise->removeFromList($modifyQuestion);
  81. $nbrQuestions--;
  82. // construction of the duplicated Question
  83. $objQuestion=new Question();
  84. $objQuestion->read($questionId);
  85. // adds the exercise ID into the exercise list of the Question object
  86. $objQuestion->addToList($exerciseId);
  87. // construction of the Answer object
  88. $objAnswerTmp=new Answer($modifyQuestion);
  89. // copies answers from $modifyQuestion to $questionId
  90. $objAnswerTmp->duplicate($questionId);
  91. // destruction of the Answer object
  92. unset($objAnswerTmp);
  93. }
  94. $objQuestion->updateTitle($questionName);
  95. $objQuestion->updateDescription($questionDescription);
  96. $objQuestion->updateType($_REQUEST['answerType']);
  97. $objQuestion->save($exerciseId);
  98. // if a picture has been set or checkbox "delete" has been checked
  99. if($_FILES['imageUpload']['size'] || $deletePicture)
  100. {
  101. // we remove the picture
  102. $objQuestion->removePicture();
  103. // if we add a new picture
  104. if($_FILES['imageUpload']['size'])
  105. {
  106. // image is already saved in a temporary file
  107. if($modifyIn)
  108. {
  109. $objQuestion->getTmpPicture();
  110. }
  111. // saves the picture coming from POST FILE
  112. else
  113. {
  114. $objQuestion->uploadPicture($_FILES['imageUpload']['tmp_name'],$_FILES['imageUpload']['name']);
  115. }
  116. }
  117. $objQuestion->save($exerciseId);
  118. }
  119. $questionId=$objQuestion->selectId();
  120. if($exerciseId)
  121. {
  122. // adds the question ID into the question list of the Exercise object
  123. if($objExercise->addToList($questionId))
  124. {
  125. $objExercise->save();
  126. $nbrQuestions++;
  127. }
  128. }
  129. if($newQuestion)
  130. {
  131. // goes to answer administration
  132. // -> answer_admin.inc.php
  133. $modifyAnswers=$questionId;
  134. }
  135. else
  136. {
  137. // goes to exercise viewing
  138. $editQuestion=$questionId;
  139. }
  140. // avoids displaying the following form in case we're editing the answer
  141. unset($newQuestion,$modifyQuestion);
  142. }
  143. if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion is true - end'."<br />\n";}
  144. }
  145. else
  146. {
  147. if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion was unset'."<br />\n";}
  148. // if we don't come here after having cancelled the warning message "used in serveral exercises"
  149. if(!$buttonBack)
  150. {
  151. if($debug>0){echo str_repeat('&nbsp;',4).'$buttonBack was unset'."<br />\n";}
  152. $questionName=$objQuestion->selectTitle();
  153. $questionDescription=$objQuestion->selectDescription();
  154. $answerType= isset($_REQUEST['answerType']) ? $_REQUEST['answerType'] : $objQuestion->selectType();
  155. $pictureName=$objQuestion->selectPicture();
  156. }
  157. $okPicture=empty($pictureName)?false:true;
  158. if($debug>0){echo str_repeat('&nbsp;',2).'$submitQuestion was unset - end'."<br />\n";}
  159. }
  160. if(($newQuestion || $modifyQuestion) && !$usedInSeveralExercises)
  161. {
  162. if($debug>0){echo str_repeat('&nbsp;',2).'$newQuestion or modifyQuestion was set but the question only exists in this exercise'."<br />\n";}
  163. ?>
  164. <h3>
  165. <?php echo $questionName; ?>
  166. </h3>
  167. <?php
  168. if($okPicture)
  169. {
  170. ?>
  171. <img src="../document/download.php?doc_url=%2Fimages%2F<?php echo $pictureName; ?>" border="0">
  172. <?php
  173. }
  174. if(!empty($msgErr))
  175. {
  176. Display::display_normal_message($msgErr); //main API
  177. }
  178. //api_disp_html_area('questionDescription',$questionDescription,'250px');
  179. $defaultType = isset($_REQUEST['answerType']) ? $_REQUEST['answerType'] : $answerType;
  180. $user = array("questionDescription"=>$questionDescription,
  181. "questionName"=>$questionName,
  182. "answerType"=>$defaultType);
  183. $fck_attribute['Width'] = '600';
  184. $fck_attribute['Height'] = '300';
  185. $fck_attribute['ToolbarSet'] = 'Question';
  186. $form = new FormValidator('introduction_text','post',$_SERVER['PHP_SELF']."?modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion);
  187. //$renderer =&$form->defaultRenderer();
  188. //$renderer->setElementTemplate('<div align ="left">{element}</div>');
  189. //$attrs = array("align"=>"right");
  190. //$buttons[] = &$form->createElement('static','label1',get_lang('Question'));
  191. //$buttons[] = &$form->createElement('text','questionName');
  192. //$form->addGroup($buttons, null, null, '&nbsp;');
  193. //$form->addelement('static','label1',get_lang('Question'));
  194. $form->addelement('text','questionName',get_lang('Question'));
  195. $form->addelement('hidden','myid',$_REQUEST['myid']);
  196. //$form->add_html_editor('questionDescription',get_lang('QuestionDescription'),false);
  197. $form->addElement('html_editor','questionDescription',get_lang('QuestionDescription'),false);
  198. if($okPicture)
  199. {
  200. $form->addelement('checkbox','deletePicture',get_lang('DeletePicture'));
  201. }
  202. if($modifyQuestion) {
  203. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('langUniqueSelect'),1);
  204. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('langMultipleSelect'),2);
  205. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('langMatching'),4);
  206. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('langFillBlanks'),3);
  207. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('freeAnswer'),5);
  208. $obj_group_type[] = &HTML_QuickForm::createElement('radio', NULL, NULL, get_lang('Hotspot'),6);
  209. $form->addGroup($obj_group_type, 'answerType', get_lang('AnswerType').':','<br />');
  210. }
  211. else {
  212. $form->addElement('hidden','answerType',$_REQUEST['answerType']);
  213. }
  214. if($answerType == HOT_SPOT)
  215. $form->addElement('file','imageUpload');
  216. $form->addElement('submit','submitQuestion',get_lang('Ok'));
  217. $form->setDefaults($user);
  218. $form->display();
  219. ?>
  220. <!--
  221. <td valign="top"><?php echo get_lang('AnswerType'); ?> :</td>
  222. <td><input class="checkbox" type="radio" name="answerType" value="1" <?php if($answerType <= 1) echo 'checked="checked"'; ?>> <?php echo get_lang('langUniqueSelect'); ?><br />
  223. <input class="checkbox" type="radio" name="answerType" value="2" <?php if($answerType == 2) echo 'checked="checked"'; ?>> <?php echo get_lang('langMultipleSelect'); ?><br />
  224. <input class="checkbox" type="radio" name="answerType" value="4" <?php if($answerType == 4) echo 'checked="checked"'; ?>> <?php echo get_lang('langMatching'); ?><br />
  225. <input class="checkbox" type="radio" name="answerType" value="3" <?php if($answerType == 3) echo 'checked="checked"'; ?>> <?php echo get_lang('langFillBlanks'); ?><br />
  226. <input class="checkbox" type="radio" name="answerType" value="5" <?php if($answerType == 5) echo 'checked="checked"'; ?>> <?php echo get_lang('freeAnswer'); ?>
  227. <input class="checkbox" type="radio" name="answerType" value="6" <?php if($answerType == 6) echo 'checked="checked"'; ?>> <?php echo get_lang('langHotspot'); ?>
  228. </td>
  229. </tr>
  230. <tr>
  231. <td>&nbsp;</td>
  232. <td>
  233. <input type="hidden" name="myid" value="<?php echo $_REQUEST['myid'];?>">
  234. <input type="submit" name="submitQuestion" value="<?php echo get_lang('Ok'); ?>">
  235. <!-- &nbsp;&nbsp;<input type="submit" name="cancelQuestion" value="<?php echo get_lang('Cancel'); ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;">
  236. <!-- </td>
  237. </tr>
  238. </table>
  239. </form>-->
  240. <?php
  241. }
  242. ?>