question.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 18472 2009-02-12 18:00:38Z juliomontoya $
  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. /** @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(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40);
  47. if (strlen(strip_tags($survey_data['title'])) > 40) {
  48. $urlname .= '...';
  49. }
  50. if($survey_data['survey_type']==1) {
  51. $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
  52. $rs = api_sql_query($sql,__FILE__,__LINE__);
  53. if(Database::num_rows($rs)===0) {
  54. header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
  55. exit;
  56. }
  57. }
  58. // breadcrumbs
  59. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  60. $interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.$_GET['survey_id'], 'name' => $urlname);
  61. // Tool name
  62. if ($_GET['action'] == 'add') {
  63. $tool_name = get_lang('AddQuestion');
  64. }
  65. if ($_GET['action'] == 'edit') {
  66. $tool_name = get_lang('EditQuestion');
  67. }
  68. // the possible question types
  69. $possible_types = array('personality','yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score');
  70. // checking if it is a valid type
  71. if (!in_array($_GET['type'], $possible_types))
  72. {
  73. Display :: display_header($tool_name,'Survey');
  74. Display :: display_error_message(get_lang('TypeDoesNotExist'), false);
  75. Display :: display_footer();
  76. }
  77. // displaying the form for adding or editing the question
  78. if (empty($_POST['save_question']) && in_array($_GET['type'],$possible_types)) {
  79. if (!isset($_POST['save_question'])) {
  80. // Displaying the header
  81. Display::display_header($tool_name,'Survey');
  82. $error_message='';
  83. // Displys message if exists
  84. if (isset($_SESSION['temp_sys_message'])) {
  85. $error_message=$_SESSION['temp_sys_message'];
  86. unset($_SESSION['temp_sys_message']);
  87. if ($error_message=='PleaseEnterAQuestion' || $error_message=='PleasFillAllAnswer'|| $error_message=='PleaseChooseACondition'|| $error_message=='ChooseDifferentCategories') {
  88. Display::display_error_message(get_lang($error_message), true);
  89. }
  90. }
  91. echo '<img src="../img/'.survey_manager::icon_question($_GET['type']).'" alt="'.get_lang(ucfirst($_GET['type'])).'" title="'.get_lang(ucfirst($_GET['type'])).'" /><br />';
  92. echo get_lang(ucfirst($_GET['type']));
  93. }
  94. $form = new $_GET['type'];
  95. // The defaults values for the form
  96. $form_content['horizontalvertical'] = 'vertical2';
  97. $form_content['answers'] = array('', '');
  98. if ($_GET['type'] == 'yesno') {
  99. $form_content['answers'][0]=get_lang('Yes');
  100. $form_content['answers'][1]=get_lang('No');
  101. }
  102. if ($_GET['type'] == 'personality') {
  103. $form_content['answers'][0]=get_lang('1');
  104. $form_content['answers'][1]=get_lang('2');
  105. $form_content['answers'][2]=get_lang('3');
  106. $form_content['answers'][3]=get_lang('4');
  107. $form_content['answers'][4]=get_lang('5');
  108. $form_content['values'][0]=0;
  109. $form_content['values'][1]=0;
  110. $form_content['values'][2]=1;
  111. $form_content['values'][3]=2;
  112. $form_content['values'][4]=3;
  113. }
  114. // We are editing a question
  115. if (isset($_GET['question_id']) AND !empty($_GET['question_id'])) {
  116. $form_content = survey_manager::get_question($_GET['question_id']);
  117. }
  118. // an action has been performed (for instance adding a possible answer, moving an answer, ...)
  119. if ($_POST) {
  120. $form_content = $_POST;
  121. $form_content = $form->handle_action($form_content);
  122. }
  123. if ($error_message!='') {
  124. $form_content['question']=$_SESSION['temp_user_message'];
  125. $form_content['answers']=$_SESSION['temp_answers'];
  126. $form_content['values']=$_SESSION['temp_values'];
  127. unset($_SESSION['temp_user_message']);
  128. unset($_SESSION['temp_answers']);
  129. unset($_SESSION['temp_values']);
  130. }
  131. $form->create_form($form_content);
  132. $form->render_form();
  133. } else {
  134. $form_content = $_POST;
  135. $form = new question();
  136. $form->handle_action($form_content);
  137. }
  138. // Footer
  139. Display :: display_footer();
  140. ?>