question.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 21734 2009-07-02 17:12:41Z cvargas1 $
  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. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  31. $htmlHeadXtra[] = '<script type="text/javascript">
  32. $(document).ready( function() {
  33. //Allow dokeos install in IE
  34. $("button").click(function() {
  35. $("#is_executable").attr("value",$(this).attr("name"));
  36. });
  37. } ); </script>';
  38. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  39. if (!api_is_allowed_to_edit(false,true)) {
  40. Display :: display_header();
  41. Display :: display_error_message(get_lang('NotAllowed'), false);
  42. Display :: display_footer();
  43. exit;
  44. }
  45. //Is valid request
  46. $is_valid_request=$_REQUEST['is_executable'];
  47. if ($request_index<>$is_valid_request) {
  48. if ($request_index=='save_question') {
  49. unset($_POST[$request_index]);
  50. } elseif ($request_index=='add_answer') {
  51. unset($_POST[$request_index]);
  52. } elseif($request_index=='remove_answer') {
  53. unset($_POST[$request_index]);
  54. }
  55. }
  56. // Database table definitions
  57. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  58. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  59. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  60. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  61. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  62. // getting the survey information
  63. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  64. if (empty($survey_data)) {
  65. Display :: display_header(get_lang('Survey'));
  66. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  67. Display :: display_footer();
  68. exit;
  69. }
  70. $urlname = api_substr(api_html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40);
  71. if (api_strlen(strip_tags($survey_data['title'])) > 40) {
  72. $urlname .= '...';
  73. }
  74. if($survey_data['survey_type']==1) {
  75. $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
  76. $rs = api_sql_query($sql,__FILE__,__LINE__);
  77. if(Database::num_rows($rs)===0) {
  78. header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');
  79. exit;
  80. }
  81. }
  82. // breadcrumbs
  83. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  84. $interbreadcrumb[] = array ("url" => 'survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname));
  85. // Tool name
  86. if ($_GET['action'] == 'add') {
  87. $tool_name = get_lang('AddQuestion');
  88. }
  89. if ($_GET['action'] == 'edit') {
  90. $tool_name = get_lang('EditQuestion');
  91. }
  92. // the possible question types
  93. $possible_types = array('personality','yesno', 'multiplechoice', 'multipleresponse', 'open', 'dropdown', 'comment', 'pagebreak', 'percentage', 'score');
  94. // actions
  95. $actions = '<div class="actions">';
  96. $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>';
  97. $actions .= '</div>';
  98. // checking if it is a valid type
  99. if (!in_array($_GET['type'], $possible_types))
  100. {
  101. Display :: display_header($tool_name,'Survey');
  102. echo $actions;
  103. Display :: display_error_message(get_lang('TypeDoesNotExist'), false);
  104. Display :: display_footer();
  105. }
  106. // displaying the form for adding or editing the question
  107. if (empty($_POST['save_question']) && in_array($_GET['type'],$possible_types)) {
  108. if (!isset($_POST['save_question'])) {
  109. // Displaying the header
  110. Display::display_header($tool_name,'Survey');
  111. echo $actions;
  112. $error_message='';
  113. // Displys message if exists
  114. if (isset($_SESSION['temp_sys_message'])) {
  115. $error_message=$_SESSION['temp_sys_message'];
  116. unset($_SESSION['temp_sys_message']);
  117. if ($error_message=='PleaseEnterAQuestion' || $error_message=='PleasFillAllAnswer'|| $error_message=='PleaseChooseACondition'|| $error_message=='ChooseDifferentCategories') {
  118. Display::display_error_message(get_lang($error_message), true);
  119. }
  120. }
  121. }
  122. $form = new $_GET['type'];
  123. // The defaults values for the form
  124. $form_content['answers'] = array('', '');
  125. if ($_GET['type'] == 'yesno') {
  126. $form_content['answers'][0]=get_lang('Yes');
  127. $form_content['answers'][1]=get_lang('No');
  128. }
  129. if ($_GET['type'] == 'personality') {
  130. $form_content['answers'][0]=get_lang('1');
  131. $form_content['answers'][1]=get_lang('2');
  132. $form_content['answers'][2]=get_lang('3');
  133. $form_content['answers'][3]=get_lang('4');
  134. $form_content['answers'][4]=get_lang('5');
  135. $form_content['values'][0]=0;
  136. $form_content['values'][1]=0;
  137. $form_content['values'][2]=1;
  138. $form_content['values'][3]=2;
  139. $form_content['values'][4]=3;
  140. }
  141. // We are editing a question
  142. if (isset($_GET['question_id']) AND !empty($_GET['question_id'])) {
  143. $form_content = survey_manager::get_question($_GET['question_id']);
  144. }
  145. // an action has been performed (for instance adding a possible answer, moving an answer, ...)
  146. if ($_POST) {
  147. $form_content = $_POST;
  148. $form_content = $form->handle_action($form_content);
  149. }
  150. if ($error_message!='') {
  151. $form_content['question']=$_SESSION['temp_user_message'];
  152. $form_content['answers']=$_SESSION['temp_answers'];
  153. $form_content['values']=$_SESSION['temp_values'];
  154. $form_content['horizontalvertical'] = $_SESSION['temp_horizontalvertical'];
  155. unset($_SESSION['temp_user_message']);
  156. unset($_SESSION['temp_answers']);
  157. unset($_SESSION['temp_values']);
  158. unset($_SESSION['temp_horizontalvertical']);
  159. }
  160. $form->create_form($form_content);
  161. $form->render_form();
  162. } else {
  163. $form_content = $_POST;
  164. $form = new question();
  165. $form->handle_action($form_content);
  166. }
  167. // Footer
  168. Display :: display_footer();
  169. ?>