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

Source for file create_new_survey.php

Documentation is available at create_new_survey.php

  1. <?php
  2. /*
  3. ==============================================================================
  4.     Dokeos - elearning and course management software
  5.  
  6.     Copyright (c) 2004-2008 Dokeos SPRL
  7.  
  8.     For a full list of contributors, see "credits.txt".
  9.     The full license can be read in "license.txt".
  10.  
  11.     This program is free software; you can redistribute it and/or
  12.     modify it under the terms of the GNU General Public License
  13.     as published by the Free Software Foundation; either version 2
  14.     of the License, or (at your option) any later version.
  15.  
  16.     See the GNU General Public License for more details.
  17.  
  18.     Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  19.     Mail: info@dokeos.com
  20. ==============================================================================
  21. */
  22.  
  23. /**
  24. *    @package dokeos.survey
  25. *     @author unknown, the initial survey that did not make it in 1.8 because of bad code
  26. *     @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
  27. *     @version $Id: create_new_survey.php 15331 2008-05-20 15:48:35Z juliomontoya $
  28. *
  29. *     @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter)
  30. */
  31.  
  32. // name of the language file that needs to be included
  33. $language_file 'survey';
  34.  
  35. // including the global dokeos file
  36. require_once ('../inc/global.inc.php');
  37.  
  38. // including additional libraries
  39. /** @todo check if these are all needed */
  40. /** @todo check if the starting / is needed. api_get_path probably ends with an / */
  41. //require_once (api_get_path(LIBRARY_PATH)."/survey.lib.php");
  42. require_once('survey.lib.php');
  43. require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
  44. require_once (api_get_path(CONFIGURATION_PATH."/add_course.conf.php");
  45. require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
  46. require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
  47. require_once (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
  48. require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
  49. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  50.  
  51. // Database table definitions
  52. $table_survey                 Database :: get_course_table(TABLE_SURVEY);
  53. $table_user                 Database :: get_main_table(TABLE_MAIN_USER);
  54. $table_course                 Database :: get_main_table(TABLE_MAIN_COURSE);
  55. $table_course_survey_rel     Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY);
  56.  
  57. /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/
  58. {
  59.     Display :: display_header();
  60.     Display :: display_error_message(get_lang('NotAllowed')false);
  61.     Display :: display_footer();
  62.     exit;
  63. }
  64.  
  65. // getting the survey information
  66. $survey_data survey_manager::get_survey($_GET['survey_id']);
  67. $urlname =substr(html_entity_decode($survey_data['title'],ENT_QUOTES,$charset)040);
  68.  
  69. if (strlen(strip_tags($survey_data['title'])) 40)
  70. {
  71.     $urlname .= '...';
  72. }
  73.  
  74. // breadcrumbs
  75. if ($_GET['action'== 'add')
  76. {
  77.     $interbreadcrumb[array ("url" => "survey_list.php""name" => get_lang('SurveyList'));
  78.     $tool_name get_lang('CreateNewSurvey');
  79. }
  80. if ($_GET['action'== 'edit' AND is_numeric($_GET['survey_id']))
  81. {
  82.     $interbreadcrumb[array ("url" => "survey_list.php""name" => get_lang('SurveyList'));
  83.     $interbreadcrumb[array ("url" => "survey.php?survey_id=".$_GET['survey_id']"name" => $urlname);
  84.     $tool_name get_lang('EditSurvey');
  85. }
  86.  
  87. // getting the default values
  88. if ($_GET['action'== 'edit' AND isset($_GET['survey_id']AND is_numeric($_GET['survey_id']))
  89. {
  90.     $defaults $survey_data;
  91.     $defaults['survey_id'$_GET['survey_id'];
  92.     /*
  93.     $defaults['survey_share'] = array();
  94.     $defaults['survey_share']['survey_share'] = $survey_data['survey_share'];
  95.     
  96.     if (!is_numeric($survey_data['survey_share']) OR $survey_data['survey_share'] == 0)
  97.     {
  98.         $form_share_value = 'true';
  99.     }
  100.     else
  101.     {
  102.         $form_share_value = $defaults['survey_share']['survey_share'];
  103.     }
  104.     */
  105.     
  106.     $defaults['anonymous'$survey_data['anonymous'];
  107. }
  108. else
  109. {
  110.     $defaults['survey_language'$_course['language'];
  111.     $defaults['start_date'date('d-F-Y H:i');
  112.     $startdateandxdays time(864000// today + 10 days
  113.     $defaults['end_date'date('d-F-Y H:i'$startdateandxdays);
  114.     //$defaults['survey_share']['survey_share'] = 0;
  115.     //$form_share_value = 1;
  116.     $defaults['anonymous'0;
  117. }
  118.  
  119. // initiate the object
  120. $form new FormValidator('survey''post'api_get_self().'?action='.$_GET['action'].'&survey_id='.$_GET['survey_id']);
  121.  
  122. // settting the form elements
  123. if ($_GET['action'== 'edit' AND isset($_GET['survey_id']AND is_numeric($_GET['survey_id']))
  124. {
  125.     $form->addElement('hidden''survey_id');
  126. }
  127. $form->addElement('text''survey_code'get_lang('SurveyCode')array('size' => '40'));
  128. $fck_attribute['Width''100%';
  129. $fck_attribute['Height''100';
  130. $fck_attribute['ToolbarSet''Survey';
  131. $form->addElement('html_editor''survey_title'get_lang('SurveyTitle'));
  132. $form->addElement('html_editor''survey_subtitle'get_lang('SurveySubTitle'));
  133. $lang_array api_get_languages();
  134. foreach ($lang_array['name'as $key=>$value)
  135. {
  136.     $languages[$lang_array['folder'][$key]] $value;
  137. }
  138. $form->addElement('select''survey_language'get_lang('Language')$languages);
  139. $form->addElement('datepickerdate''start_date'get_lang('StartDate')array('form_name'=>'survey'));
  140. $form->addElement('datepickerdate''end_date'get_lang('EndDate')array('form_name'=>'survey'));
  141.  
  142. //$group='';
  143. //$group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('Yes'),$form_share_value);
  144. /** @todo maybe it is better to change this into false instead see line 95 in survey.lib.php */
  145. //$group[] =& HTML_QuickForm::createElement('radio', 'survey_share',null, get_lang('No'),0);
  146.  
  147. $fck_attribute['Height''200';
  148. //$form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), '&nbsp;');
  149. $form->addElement('checkbox''anonymous'get_lang('Anonymous'));
  150. $form->addElement('html_editor''survey_introduction'get_lang('SurveyIntroduction'));
  151. $form->addElement('html_editor''survey_thanks'get_lang('SurveyThanks'));
  152. $form->addElement('submit''submit_survey'get_lang('Ok'));
  153.  
  154. // setting the rules
  155. $form->addRule('survey_code''<div class="required">'.get_lang('ThisFieldIsRequired')'required');
  156. $form->addRule('survey_title''<div class="required">'.get_lang('ThisFieldIsRequired')'required');
  157. $form->addRule('start_date'get_lang('InvalidDate')'date');
  158. $form->addRule('end_date'get_lang('InvalidDate')'date');
  159. $form->addRule(array ('start_date''end_date')get_lang('StartDateShouldBeBeforeEndDate')'date_compare''lte');
  160.  
  161. // setting the default values
  162. $form->setDefaults($defaults);
  163.  
  164. // The validation or display
  165. if$form->validate() )
  166. {
  167.     // exporting the values
  168.     $values $form->exportValues();
  169.     // storing the survey
  170.     $return survey_manager::store_survey($values);
  171.     
  172.     /*// deleting the shared survey if the survey is getting unshared (this only happens when editing)    
  173.     if (is_numeric($survey_data['survey_share']) AND $values['survey_share']['survey_share'] == 0 AND $values['survey_id']<>'')
  174.     {
  175.         survey_manager::delete_survey($survey_data['survey_share'], true);
  176.     }
  177.     // storing the already existing questions and options of a survey that gets shared (this only happens when editing)
  178.     if ($survey_data['survey_share']== 0 AND $values['survey_share']['survey_share'] !== 0 AND $values['survey_id']<>'')
  179.     {
  180.         survey_manager::get_complete_survey_structure($return['id']);
  181.     }
  182.     */
  183.     if ($config['survey']['debug'])
  184.     {
  185.         // displaying a feedback message
  186.            Display::display_confirmation_message($return['message']false);
  187.     }
  188.     else
  189.     {
  190.            // redirecting to the survey page (whilst showing the return message
  191.            header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
  192.     }
  193. }
  194. else
  195. {
  196.     // Displaying the header
  197.     Display::display_header($tool_name);
  198.  
  199.     // Displaying the tool title
  200.     //api_display_tool_title($tool_name);
  201.  
  202.     // display the form
  203.     $form->display();
  204. }
  205.  
  206. // Footer
  207. ?>

Documentation generated on Thu, 12 Jun 2008 13:17:25 -0500 by phpDocumentor 1.4.1