dokeos-survey
[ class tree: dokeos-survey ] [ index: dokeos-survey ] [ all elements ]

Source for file preview.php

Documentation is available at preview.php

  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4.  
  5. For a full list of contributors, see documentation/credits.html
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11. See "documentation/licence.html" more details.
  12.  
  13. Contact:
  14. Dokeos
  15. Rue des Palais 44 Paleizenstraat
  16. B-1030 Brussels - Belgium
  17. Tel. +32 (2) 211 34 56
  18. */
  19.  
  20. /**
  21. *    @package dokeos.survey
  22. *     @author unknown, the initial survey that did not make it in 1.8 because of bad code
  23. *     @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
  24. *     @version $Id: survey_list.php 10680 2007-01-11 21:26:23Z pcool $
  25. *
  26. *     @todo use quickforms for the forms
  27. */
  28.  
  29. // name of the language file that needs to be included
  30. $language_file 'survey';
  31.  
  32. // including the global dokeos file
  33. require ('../inc/global.inc.php');
  34.  
  35. // including additional libraries
  36. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  37. require_once('survey.lib.php');
  38.  
  39. // Database table definitions
  40. $table_survey                     Database :: get_course_table(TABLE_SURVEY);
  41. $table_survey_question             Database :: get_course_table(TABLE_SURVEY_QUESTION);
  42. $table_survey_question_option     Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
  43. $table_course                     Database :: get_main_table(TABLE_MAIN_COURSE);
  44. $table_user                     Database :: get_main_table(TABLE_MAIN_USER);
  45.  
  46. // We exit here if ther is no valid $_GET parameter
  47. if (!isset($_GET['survey_id']OR !is_numeric($_GET['survey_id']))
  48. {
  49.     Display :: display_header();
  50.     Display :: display_error_message(get_lang('InvallidSurvey')false);
  51.     Display :: display_footer();
  52.     exit;
  53. }
  54.  
  55. // getting the survey information
  56. $survey_data survey_manager::get_survey($_GET['survey_id']);
  57. $urlname substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset)040);
  58. if (strlen(strip_tags($survey_data['title'])) 40)
  59. {
  60.     $urlname .= '...';
  61. }
  62.  
  63. // breadcrumbs
  64. $interbreadcrumb[array ("url" => 'survey_list.php''name' => get_lang('SurveyList'));
  65. $interbreadcrumb[array ("url" => "survey.php?survey_id=".$_GET['survey_id']"name" => $urlname);
  66.  
  67. // Header
  68. Display :: display_header(get_lang('SurveyPreview'));
  69.  
  70. // We exit here is the first or last question is a pagebreak (which causes errors)
  71. SurveyUtil::check_first_last_question($_GET['survey_id']false);
  72.  
  73. // only a course admin is allowed to preview a survey: you are NOT a course admin => error message
  74. {
  75.     Display :: display_error_message(get_lang('NotAllowed')false);
  76. }
  77. // only a course admin is allowed to preview a survey: you are a course admin
  78. else
  79. {
  80.     // survey information
  81.     echo '<div id="survey_title">'.$survey_data['survey_title'].'</div>';
  82.     echo '<div id="survey_subtitle">'.$survey_data['survey_subtitle'].'</div>';
  83.  
  84.     // displaying the survey introduction
  85.     if (!isset($_GET['show']))
  86.     {
  87.         echo '<div id="survey_content" class="survey_content">'.$survey_data['survey_introduction'].'</div>';
  88.         $limit 0;
  89.     }
  90.  
  91.     // displaying the survey thanks message
  92.     if ($_POST['finish_survey'])
  93.     {
  94.         echo '<div id="survey_content" class="survey_content"><strong>'.get_lang('SurveyFinished').' </strong>'.$survey_data['survey_thanks'].'</div>';
  95.         Display :: display_footer();
  96.         exit;
  97.     }
  98.  
  99.     if (isset($_GET['show']))
  100.     {
  101.         // Getting all the questions for this page and add them to a multidimensional array where the first index is the page.
  102.         // as long as there is no pagebreak fount we keep adding questions to the page
  103.         $questions_displayed array();
  104.         $counter 0;
  105.         $sql "SELECT * FROM $table_survey_question
  106.                 WHERE survey_id = '".Database::escape_string($_GET['survey_id'])."'
  107.                 ORDER BY sort ASC";
  108.         $result api_sql_query($sql__FILE____LINE__);
  109.  
  110.         while ($row Database::fetch_array($result))
  111.         {
  112.             if($row['type'== 'pagebreak')
  113.             {
  114.                 $counter++;
  115.             }
  116.             else
  117.             {
  118.                 $paged_questions[$counter][$row['question_id'];
  119.             }
  120.         }
  121.  
  122.         if (key_exists($_GET['show'],$paged_questions))
  123.         {
  124.             $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,
  125.                             survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
  126.                     FROM $table_survey_question survey_question
  127.                     LEFT JOIN $table_survey_question_option survey_question_option
  128.                     ON survey_question.question_id = survey_question_option.question_id
  129.                     WHERE survey_question.survey_id = '".Database::escape_string($_GET['survey_id'])."'
  130.                     AND survey_question.question_id IN (".Database::escape_string(implode(',',$paged_questions[$_GET['show']])).")
  131.                     ORDER BY survey_question.sort, survey_question_option.sort ASC";
  132.  
  133.             $result api_sql_query($sql__FILE____LINE__);
  134.             $question_counter_max Database::num_rows($result);
  135.             $counter 0;
  136.             $limit=0;
  137.             $questions array();
  138.             while ($row Database::fetch_array($result))
  139.             {
  140.                 // if the type is not a pagebreak we store it in the $questions array
  141.                 if($row['type'<> 'pagebreak')
  142.                 {
  143.                     $questions[$row['sort']]['question_id'$row['question_id'];
  144.                     $questions[$row['sort']]['survey_id'$row['survey_id'];
  145.                     $questions[$row['sort']]['survey_question'$row['survey_question'];
  146.                     $questions[$row['sort']]['display'$row['display'];
  147.                     $questions[$row['sort']]['type'$row['type'];
  148.                     $questions[$row['sort']]['options'][intval($row['option_sort'])$row['option_text'];
  149.                     $questions[$row['sort']]['maximum_score'$row['max_value'];
  150.                 }
  151.                 // if the type is a pagebreak we are finished loading the questions for this page
  152.                 else
  153.                 {
  154.                     break;
  155.                 }
  156.                 $counter++;
  157.             }
  158.         }
  159.     }
  160.     // selecting the maximum number of pages
  161.     $sql "SELECT * FROM $table_survey_question WHERE type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($_GET['survey_id'])."'";
  162.     $result api_sql_query($sql__FILE____LINE__);
  163.     $numberofpages Database::num_rows($result1;
  164.     // Displaying the form with the questions
  165.     if (isset($_GET['show']))
  166.     {
  167.         $show = (int)$_GET['show'1;
  168.     }
  169.     else
  170.     {
  171.         $show 0;
  172.     }
  173.     echo '<form id="question" name="question" method="post" action="'.api_get_self().'?survey_id='.Security::remove_XSS($_GET['survey_id']).'&show='.$show.'">';
  174.     if(is_array($questions&& count($questions)>0)
  175.     {
  176.         foreach ($questions as $key=>$question)
  177.         {
  178.             $display new $question['type'];
  179.             $display->render_question($question);
  180.         }
  181.     }
  182.     if (($show $numberofpagesOR !$_GET['show'])
  183.     {
  184.         //echo '<a href="'.api_get_self().'?survey_id='.$_GET['survey_id'].'&amp;show='.$limit.'">NEXT</a>';
  185.         echo '<br /><input type="submit" name="next_survey_page" value="'.get_lang('Next').' >> " />';
  186.     }
  187.     if ($show >= $numberofpages AND $_GET['show'])
  188.     {
  189.         echo '<input type="submit" name="finish_survey" value="'.get_lang('FinishSurvey').' >> " />';
  190.     }
  191.     echo '</form>';
  192. }
  193.  
  194. // Footer
  195. ?>

Documentation generated on Thu, 12 Jun 2008 09:26:27 -0500 by phpDocumentor 1.4.1