, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code * @author Julio Montoya Armas , Chamilo: Personality Test modification and rewriting large parts of the code * @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $ * * @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter) */ // Language file that needs to be included $language_file = 'survey'; // Including the global initialization file require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; // Including additional libraries /** @todo check if these are all needed */ /** @todo check if the starting / is needed. api_get_path probably ends with an / */ //require_once api_get_path(LIBRARY_PATH).'survey.lib.php'; require_once 'survey.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; $htmlHeadXtra[] = ''; // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); $table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); /** @todo this has to be moved to a more appropriate place (after the display_header of the code) */ // If user is not teacher or if he's a coach trying to access an element out of his session if (!api_is_allowed_to_edit()) { if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id'])) ) { api_not_allowed(true); exit; } } // Getting the survey information $survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; $survey_data = survey_manager::get_survey($survey_id); // Additional information $course_id = api_get_course_id(); $session_id = api_get_session_id(); $gradebook_link_type = 8; $urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null; // Breadcrumbs if ($_GET['action'] == 'add') { $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), 'name' => get_lang('SurveyList') ); $tool_name = get_lang('CreateNewSurvey'); } if ($_GET['action'] == 'edit' && is_numeric($survey_id)) { $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php?'.api_get_cidreq(), 'name' => get_lang('SurveyList') ); $interbreadcrumb[] = array( 'url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id.'&'.api_get_cidreq(), 'name' => Security::remove_XSS($urlname) ); $tool_name = get_lang('EditSurvey'); } $gradebook_link_id = null; // Getting the default values if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) { $defaults = $survey_data; $defaults['survey_id'] = $survey_id; $defaults['anonymous'] = $survey_data['anonymous']; $link_info = is_resource_in_course_gradebook($course_id, $gradebook_link_type, $survey_id, $session_id); $gradebook_link_id = $link_info['id']; if ($link_info) { if ($sql_result_array = Database::fetch_array(Database::query('SELECT weight FROM '.$table_gradebook_link.' WHERE id='.$gradebook_link_id))) { $defaults['survey_qualify_gradebook'] = $gradebook_link_id; $defaults['survey_weight'] = number_format($sql_result_array['weight'], 2, '.', ''); } } } else { $defaults['survey_language'] = $_course['language']; $defaults['start_date'] = date('d-F-Y H:i'); $startdateandxdays = time() + 864000; // today + 10 days $defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays); //$defaults['survey_share']['survey_share'] = 0; //$form_share_value = 1; $defaults['anonymous'] = 0; } // Initialize the object $form = new FormValidator('survey', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&survey_id='.$survey_id); $form->addElement('header', '', $tool_name); // Setting the form elements if ($_GET['action'] == 'edit' && isset($survey_id) && is_numeric($survey_id)) { $form->addElement('hidden', 'survey_id'); } $survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20', 'maxlength' => '20', 'id' => 'surveycode_title')); if ($_GET['action'] == 'edit') { $survey_code->freeze(); $form->applyFilter('survey_code', 'api_strtoupper'); } $form->addElement('html_editor', 'survey_title', get_lang('SurveyTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '200')); $form->addElement('html_editor', 'survey_subtitle', get_lang('SurveySubTitle'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '100', 'ToolbarStartExpanded' => false)); /* //Language selection has been disabled. If you want to re-enable, please //disable the following line (hidden language field). $lang_array = api_get_languages(); foreach ($lang_array['name'] as $key => $value) { $languages[$lang_array['folder'][$key]] = $value; } $form->addElement('select', 'survey_language', get_lang('Language'), $languages); */ // Pass the language of the survey in the form $form->addElement('hidden', 'survey_language'); $form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name' => 'survey')); $form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name' => 'survey')); //$group = ''; //$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('Yes'), $form_share_value); /** TODO Maybe it is better to change this into false instead see line 95 in survey.lib.php */ //$group[] =& HTML_QuickForm::createElement('radio', 'survey_share', null, get_lang('No'), 0); //$form->addGroup($group, 'survey_share', get_lang('ShareSurvey'), ' '); $form->addElement('checkbox', 'anonymous', null, get_lang('Anonymous')); $form->addElement('html_editor', 'survey_introduction', get_lang('SurveyIntroduction'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false)); $form->addElement('html_editor', 'survey_thanks', get_lang('SurveyThanks'), null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '130', 'ToolbarStartExpanded' => false)); // Aditional Parameters $form->addElement( 'advanced_settings', '  '. Display::return_icon('div_show.gif', null, array('style' => 'vertical-align:middle')).' '.get_lang('AdvancedParameters').'' ); $form->addElement('html', '