question_admin.inc.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * Statement (?) administration
  19. * This script allows to manage the statements of questions.
  20. * It is included from the script admin.php
  21. * @package dokeos.exercise
  22. * @author Olivier Brouckaert
  23. * @version $Id: question_admin.inc.php 18002 2009-01-26 16:33:20Z juliomontoya $
  24. */
  25. /*
  26. ==============================================================================
  27. INIT SECTION
  28. ==============================================================================
  29. */
  30. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  31. include_once(api_get_path(LIBRARY_PATH).'image.lib.php');
  32. // ALLOWED_TO_INCLUDE is defined in admin.php
  33. if(!defined('ALLOWED_TO_INCLUDE'))
  34. {
  35. exit();
  36. }
  37. /*********************
  38. * INIT QUESTION
  39. *********************/
  40. if(isset($_GET['editQuestion']))
  41. {
  42. $objQuestion = Question::read ($_GET['editQuestion']);
  43. $action = api_get_self()."?modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  44. }
  45. else
  46. {
  47. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  48. $action = api_get_self()."?modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  49. }
  50. if(is_object($objQuestion))
  51. {
  52. /*********************
  53. * FORM STYLES
  54. *********************/
  55. // if you have a better way to improve the display, please inform me e.marguin@elixir-interactive.com
  56. $styles = '
  57. <style>
  58. div.row div.label{
  59. width: 10%;
  60. }
  61. div.row div.formw{
  62. width: 85%;
  63. }
  64. </style>
  65. ';
  66. echo $styles;
  67. /*********************
  68. * INIT FORM
  69. *********************/
  70. $form = new FormValidator('question_admin_form','post',$action);
  71. /*********************
  72. * FORM CREATION
  73. *********************/
  74. $objQuestion -> createForm ($form,array('Height'=>150));
  75. $objQuestion -> createAnswersForm ($form);
  76. $form->addElement('submit','submitQuestion',get_lang('Ok'));
  77. $renderer = $form->defaultRenderer();
  78. $renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','submitQuestion');
  79. /**********************
  80. * FORM VALIDATION
  81. **********************/
  82. if(isset($_POST['submitQuestion']) && $form->validate())
  83. {
  84. // question
  85. $objQuestion -> processCreation($form,$objExercise);
  86. // answers
  87. $objQuestion -> processAnswersCreation($form,$nb_answers);
  88. // TODO: maybe here is the better place to index this tool, including answers text
  89. // redirect
  90. if($objQuestion -> type != HOT_SPOT)
  91. echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  92. else
  93. echo '<script type="text/javascript">window.location.href="admin.php?hotspotadmin='.$objQuestion->id.'"</script>';
  94. }
  95. else
  96. {
  97. /******************
  98. * FORM DISPLAY
  99. ******************/
  100. echo '<h3>'.$questionName.'</h3>';
  101. if(!empty($pictureName)){
  102. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  103. }
  104. if(!empty($msgErr))
  105. {
  106. Display::display_normal_message($msgErr); //main API
  107. }
  108. // display the form
  109. $form->display();
  110. }
  111. }
  112. ?>