preview.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. // getting the survey information
  38. $survey_data = survey_manager::get_survey($_GET['survey_id']);
  39. $urlname = substr(strip_tags($survey_data['title']), 0, 40);
  40. if (strlen(strip_tags($survey_data['title'])) > 40)
  41. {
  42. $urlname .= '...';
  43. }
  44. // breadcrumbs
  45. $interbreadcrumb[] = array ("url" => 'survey_list.php', 'name' => get_lang('SurveyList'));
  46. $interbreadcrumb[] = array ("url" => "survey.php?survey_id=".$_GET['survey_id'], "name" => $urlname);
  47. // Header
  48. Display :: display_header(get_lang('SurveyPreview'));
  49. // only a course admin is allowed to preview a survey: you are NOT a course admin => error message
  50. if (!api_is_allowed_to_edit())
  51. {
  52. Display :: display_error_message(get_lang('NotAllowedHere'), false);
  53. }
  54. // only a course admin is allowed to preview a survey: you are a course admin
  55. else
  56. {
  57. if (!isset($_GET['survey_id']) OR !is_numeric($_GET['survey_id']))
  58. {
  59. Display :: display_error_message(get_lang('InvallidSurvey'), false);
  60. }
  61. // survey information
  62. echo '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
  63. echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
  64. // displaying the survey introduction
  65. if (!isset($_GET['show']))
  66. {
  67. echo '<div id="survey_content" class="survey_content">'.$survey_data['survey_introduction'].'</div>';
  68. $limit = 0;
  69. }
  70. // displaying the survey thanks message
  71. if ($_POST['finish_survey'])
  72. {
  73. echo '<div id="survey_content" class="survey_content"><strong>'.get_lang('SurveyFinished').'</strong>'.$survey_data['survey_thanks'].'</div>';
  74. Display :: display_footer();
  75. exit;
  76. }
  77. if (isset($_GET['show']))
  78. {
  79. // Getting all the questions for this page
  80. $sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value,
  81. survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  82. FROM $table_survey_question survey_question
  83. LEFT JOIN $table_survey_question_option survey_question_option
  84. ON survey_question.question_id = survey_question_option.question_id
  85. WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  86. ORDER BY survey_question.sort ASC";
  87. if ($_GET['show'])
  88. {
  89. $sql .= ' LIMIT '.($_GET['show']+1).',1000';
  90. }
  91. $result = api_sql_query($sql, __FILE__, __LINE__);
  92. $question_counter_max = mysql_num_rows($result);
  93. $counter = 0;
  94. $limit=0;
  95. while ($row = mysql_fetch_assoc($result))
  96. {
  97. // if the type is not a pagebreak we store it in the $questions array
  98. if($row['type'] <> 'pagebreak')
  99. {
  100. $questions[$row['sort']]['question_id'] = $row['question_id'];
  101. $questions[$row['sort']]['survey_id'] = $row['survey_id'];
  102. $questions[$row['sort']]['survey_question'] = $row['survey_question'];
  103. $questions[$row['sort']]['display'] = $row['display'];
  104. $questions[$row['sort']]['type'] = $row['type'];
  105. $questions[$row['sort']]['options'][$row['option_sort']] = $row['option_text'];
  106. $questions[$row['sort']]['maximum_score'] = $row['max_value'];
  107. }
  108. // if the type is a pagebreak we are finished loading the questions for this page
  109. else
  110. {
  111. $limit = $counter;
  112. break;
  113. }
  114. $counter++;
  115. }
  116. }
  117. // Displaying the form with the questions
  118. echo '<form id="question" name="question" method="post" action="'.$_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id'].'&show='.$limit.'">';
  119. foreach ($questions as $key=>$question)
  120. {
  121. $display = new $question['type'];
  122. $display->render_question($question);
  123. }
  124. if (($limit AND $limit <> $question_counter_max) OR !$_GET['show'])
  125. {
  126. //echo '<a href="'.$_SERVER['PHP_SELF'].'?survey_id='.$_GET['survey_id'].'&amp;show='.$limit.'">NEXT</a>';
  127. echo '<br /><input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
  128. }
  129. if ($limit==0 AND $_GET['show'])
  130. {
  131. echo '<input type="submit" name="finish_survey" value="'.get_lang('FinishSurvey').' >> " />';
  132. }
  133. echo '</form>';
  134. }
  135. // Footer
  136. Display :: display_footer();
  137. ?>