question.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 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. * @package dokeos.survey
  19. * @author unknown, the initial survey that did not make it in 1.8 because of bad code
  20. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  21. * @version $Id: question.php 20424 2009-05-08 20:40:27Z herodoto $
  22. */
  23. // name of the language file that needs to be included
  24. $language_file = 'survey';
  25. // including the global dokeos file
  26. require ('../inc/global.inc.php');
  27. // including additional libraries
  28. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  29. require_once('survey.lib.php');
  30. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  31. if (!api_is_allowed_to_edit(false,true)) {
  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. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  39. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  40. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  41. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  42. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  43. // getting the survey information
  44. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  45. if (empty($survey_data)) {
  46. Display :: display_header(get_lang('Survey'));
  47. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  48. Display :: display_footer();
  49. exit;
  50. }
  51. $urlname = substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40);
  52. if (strlen(strip_tags($survey_data['title'])) > 40) {
  53. $urlname .= '...';
  54. }
  55. if($survey_data['survey_type']==1) {
  56. $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
  57. $rs = api_sql_query($sql,__FILE__,__LINE__);
  58. if(Database::num_rows($rs)===0) {
  59. header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
  60. exit;
  61. }
  62. }
  63. // breadcrumbs
  64. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  65. $interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
  66. // Tool name
  67. if ($_GET['action'] == 'add') {
  68. $tool_name = get_lang('AddQuestion');
  69. }
  70. if ($_GET['action'] == 'edit') {
  71. $tool_name = get_lang('EditQuestion');
  72. }
  73. // the possible question types
  74. $possible_types = array('personality','yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score');
  75. // actions
  76. $actions = '<div class="actions">';
  77. $actions .= '<a href="survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']).'">'.Display::return_icon('back.png',get_lang('BackToSurvey')).get_lang('BackToSurvey').'</a>';
  78. $actions .= '</div>';
  79. // checking if it is a valid type
  80. if (!in_array($_GET['type'], $possible_types))
  81. {
  82. Display :: display_header($tool_name,'Survey');
  83. echo $actions;
  84. Display :: display_error_message(get_lang('TypeDoesNotExist'), false);
  85. Display :: display_footer();
  86. }
  87. // displaying the form for adding or editing the question
  88. if (empty($_POST['save_question']) && in_array($_GET['type'],$possible_types)) {
  89. if (!isset($_POST['save_question'])) {
  90. // Displaying the header
  91. Display::display_header($tool_name,'Survey');
  92. echo $actions;
  93. $error_message='';
  94. // Displys message if exists
  95. if (isset($_SESSION['temp_sys_message'])) {
  96. $error_message=$_SESSION['temp_sys_message'];
  97. unset($_SESSION['temp_sys_message']);
  98. if ($error_message=='PleaseEnterAQuestion' || $error_message=='PleasFillAllAnswer'|| $error_message=='PleaseChooseACondition'|| $error_message=='ChooseDifferentCategories') {
  99. Display::display_error_message(get_lang($error_message), true);
  100. }
  101. }
  102. }
  103. $form = new $_GET['type'];
  104. // The defaults values for the form
  105. $form_content['answers'] = array('', '');
  106. if ($_GET['type'] == 'yesno') {
  107. $form_content['answers'][0]=get_lang('Yes');
  108. $form_content['answers'][1]=get_lang('No');
  109. }
  110. if ($_GET['type'] == 'personality') {
  111. $form_content['answers'][0]=get_lang('1');
  112. $form_content['answers'][1]=get_lang('2');
  113. $form_content['answers'][2]=get_lang('3');
  114. $form_content['answers'][3]=get_lang('4');
  115. $form_content['answers'][4]=get_lang('5');
  116. $form_content['values'][0]=0;
  117. $form_content['values'][1]=0;
  118. $form_content['values'][2]=1;
  119. $form_content['values'][3]=2;
  120. $form_content['values'][4]=3;
  121. }
  122. // We are editing a question
  123. if (isset($_GET['question_id']) AND !empty($_GET['question_id'])) {
  124. $form_content = survey_manager::get_question($_GET['question_id']);
  125. }
  126. // an action has been performed (for instance adding a possible answer, moving an answer, ...)
  127. if ($_POST) {
  128. $form_content = $_POST;
  129. $form_content = $form->handle_action($form_content);
  130. }
  131. if ($error_message!='') {
  132. $form_content['question']=$_SESSION['temp_user_message'];
  133. $form_content['answers']=$_SESSION['temp_answers'];
  134. $form_content['values']=$_SESSION['temp_values'];
  135. $form_content['horizontalvertical'] = $_SESSION['temp_horizontalvertical'];
  136. unset($_SESSION['temp_user_message']);
  137. unset($_SESSION['temp_answers']);
  138. unset($_SESSION['temp_values']);
  139. unset($_SESSION['temp_horizontalvertical']);
  140. }
  141. $form->create_form($form_content);
  142. $form->render_form();
  143. } else {
  144. $form_content = $_POST;
  145. $form = new question();
  146. $form->handle_action($form_content);
  147. }
  148. // Footer
  149. Display :: display_footer();
  150. ?>