preview.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
  21. *
  22. * @todo use quickforms for the forms
  23. */
  24. // name of the language file that needs to be included
  25. $language_file = 'survey';
  26. // including the global dokeos file
  27. require ('../inc/global.inc.php');
  28. // including additional libraries
  29. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  30. require_once('survey.lib.php');
  31. // Database table definitions
  32. $table_survey = Database :: get_course_table(TABLE_SURVEY);
  33. $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
  34. $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  35. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  36. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  37. // breadcrumbs
  38. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  39. // Header
  40. Display :: display_header(get_lang('SurveyPreview'));
  41. // debug
  42. /*
  43. echo '<pre>';
  44. print_r($_POST);
  45. echo '</pre>';
  46. */
  47. // only a course admin is allowed to preview a survey: you are NOT a course admin => error message
  48. if (!api_is_allowed_to_edit())
  49. {
  50. Display :: display_error_message(get_lang('NotAllowedHere'));
  51. }
  52. // only a course admin is allowed to preview a survey: you are a course admin
  53. else
  54. {
  55. if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id']))
  56. {
  57. Display :: display_error_message(get_lang('InvallidSurvey'));
  58. }
  59. // survey information
  60. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  61. echo '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
  62. echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
  63. // displaying the survey introduction
  64. if (!isset($_GET['show']))
  65. {
  66. echo '<div id="survey_content">'.$survey_data['survey_introduction'].'</div>';
  67. $limit = 0;
  68. }
  69. // displaying the survey thanks message
  70. if ($_POST['finish_survey'])
  71. {
  72. echo '<div id="survey_content"><strong>'.get_lang('SurveyFinished').'</strong>'.$survey_data['survey_thanks'].'</div>';
  73. Display :: display_footer();
  74. exit;
  75. }
  76. if (isset($_GET['show']))
  77. {
  78. // Getting all the questions for this page
  79. $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type,
  80. survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  81. FROM $table_survey_question survey_question
  82. LEFT JOIN $table_survey_question_option survey_question_option
  83. ON survey_question.question_id = survey_question_option.question_id
  84. WHERE survey_question.survey_id = '".mysql_real_escape_string($_GET['survey_id'])."'
  85. ORDER BY survey_question.sort ASC";
  86. if ($_GET['show'])
  87. {
  88. $sql .= ' LIMIT '.($_GET['show']+1).',1000';
  89. }
  90. $result = api_sql_query($sql, __FILE__, __LINE__);
  91. $question_counter_max = mysql_num_rows($result);
  92. $counter = 0;
  93. while ($row = mysql_fetch_assoc($result))
  94. {
  95. // if the type is not a pagebreak we store it in the $questions array
  96. if($row['type'] <> 'pagebreak')
  97. {
  98. $questions[$row['sort']]['question_id'] = $row['question_id'];
  99. $questions[$row['sort']]['survey_id'] = $row['survey_id'];
  100. $questions[$row['sort']]['survey_question'] = $row['survey_question'];
  101. $questions[$row['sort']]['display'] = $row['display'];
  102. $questions[$row['sort']]['type'] = $row['type'];
  103. $questions[$row['sort']]['options'][$row['option_sort']] = $row['option_text'];
  104. }
  105. // if the type is a pagebreak we are finished loading the questions for this page
  106. else
  107. {
  108. $limit = $counter;
  109. break;
  110. }
  111. $counter++;
  112. }
  113. }
  114. // Displaying the form with the questions
  115. echo '<form id="question" name="question" method="post" action="'.$_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id'].'&show='.$limit.'">';
  116. foreach ($questions as $key=>$question)
  117. {
  118. $display = new $question['type'];
  119. $display->render_question($question);
  120. }
  121. if (($limit AND $limit <> $question_counter_max) OR !$_GET['show'])
  122. {
  123. //echo '<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id'].'&amp;show='.$limit.'">NEXT</a>';
  124. echo '<input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
  125. }
  126. if (!$limit AND $_GET['show'])
  127. {
  128. echo '<input type="submit" name="finish_survey" value="'.get_lang('FinishSurvey').' >> " />';
  129. }
  130. echo '</form>';
  131. /*
  132. echo '<pre>';
  133. print_r($questions);
  134. echo '</pre>';
  135. */
  136. }
  137. // Footer
  138. Display :: display_footer();
  139. ?>