question.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * @package dokeos.survey
  18. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  19. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  20. * @version $Id: question.php 14784 2008-04-08 12:58:45Z pcool $
  21. */
  22. // name of the language file that needs to be included
  23. $language_file = 'survey';
  24. // including the global dokeos file
  25. require ('../inc/global.inc.php');
  26. // including additional libraries
  27. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  28. require_once('survey.lib.php');
  29. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  30. if (!api_is_allowed_to_edit())
  31. {
  32. Display :: display_header();
  33. Display :: display_error_message(get_lang('NotAllowed'), false);
  34. Display :: display_footer();
  35. exit;
  36. }
  37. // Database table definitions
  38. /** @todo use database constants for the survey tables */
  39. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  40. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  41. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  42. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  43. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  44. // getting the survey information
  45. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  46. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  47. if (strlen(strip_tags($survey_data['title'])) > 40)
  48. {
  49. $urlname .= '...';
  50. }
  51. // breadcrumbs
  52. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  53. $interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  54. // Tool name
  55. if ($_GET['action'] == 'add')
  56. {
  57. $tool_name = get_lang('AddQuestion');
  58. }
  59. if ($_GET['action'] == 'edit')
  60. {
  61. $tool_name = get_lang('EditQuestion');
  62. }
  63. // the possible question types
  64. $possible_types = array('yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score');
  65. // checking if it is a valid type
  66. if (!in_array($_GET['type'], $possible_types))
  67. {
  68. Display::display_header($tool_name);
  69. Display :: display_error_message(get_lang('TypeDoesNotExist'), false);
  70. Display :: display_footer();
  71. }
  72. // displaying the form for adding or editing the question
  73. if (empty($_POST['save_question']) && in_array($_GET['type'],$possible_types))
  74. {
  75. // Displaying the header
  76. Display::display_header($tool_name);
  77. $error_message='';
  78. // Displys message if exists
  79. if (isset($_SESSION['temp_sys_message']))
  80. {
  81. $error_message=$_SESSION['temp_sys_message'];
  82. unset($_SESSION['temp_sys_message']);
  83. if ($error_message=='PleaseEnterAQuestion' || $error_message=='PleasFillAllAnswer')
  84. {
  85. Display::display_error_message(get_lang($error_message), true);
  86. }
  87. }
  88. echo '<img src="../img/'.survey_manager::icon_question($_GET['type']).'" alt="'.get_lang(ucfirst($_GET['type'])).'" title="'.get_lang(ucfirst($_GET['type'])).'" /><br />';
  89. echo get_lang(ucfirst($_GET['type']));
  90. $form = new $_GET['type'];
  91. // The defaults values for the form
  92. $form_content['horizontalvertical'] = 'vertical';
  93. $form_content['answers'] = array('', '');
  94. if ($_GET['type'] == 'yesno')
  95. {
  96. $form_content['answers'][0]=get_lang('Yes');
  97. $form_content['answers'][1]=get_lang('No');
  98. }
  99. // We are editing a question
  100. if (isset($_GET['question_id']) AND !empty($_GET['question_id']))
  101. {
  102. $form_content = survey_manager::get_question($_GET['question_id']);
  103. }
  104. // an action has been performed (for instance adding a possible answer, moving an answer, ...)
  105. if ($_POST)
  106. {
  107. $form_content = $_POST;
  108. $form_content = $form->handle_action($form_content);
  109. }
  110. if ($error_message!='')
  111. {
  112. $form_content['question']=$_SESSION['temp_user_message'];
  113. $form_content['answers']=$_SESSION['temp_answers'];
  114. unset($_SESSION['temp_user_message']);
  115. unset($_SESSION['temp_answers']);
  116. }
  117. $form->create_form($form_content);
  118. $form->render_form();
  119. }
  120. else
  121. {
  122. $form_content = $_POST;
  123. $form = new question();
  124. $form->handle_action($form_content);
  125. }
  126. // Footer
  127. Display :: display_footer();
  128. ?>