123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- <?php
- $language_file = 'survey';
- require_once ('../inc/global.inc.php');
- $htmlHeadXtra[] = '<script type="text/javascript" language="javascript">
- function advanced_parameters() {
- if(document.getElementById(\'options\').style.display == \'none\') {
- document.getElementById(\'options\').style.display = \'block\';
- document.getElementById(\'plus_minus\').innerHTML=\' '.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'\';
- } else {
- document.getElementById(\'options\').style.display = \'none\';
- document.getElementById(\'plus_minus\').innerHTML=\' '.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'\';
- }
- }
- </script>';
- require_once('survey.lib.php');
- require_once (api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
- require_once (api_get_path(CONFIGURATION_PATH) ."/add_course.conf.php");
- require_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
- require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
- require_once (api_get_path(LIBRARY_PATH)."/groupmanager.lib.php");
- require_once (api_get_path(LIBRARY_PATH)."/usermanager.lib.php");
- require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
- $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_course_survey_rel = Database :: get_main_table(TABLE_MAIN_COURSE_SURVEY);
- if (!api_is_allowed_to_edit())
- {
- if(!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY,intval($_GET['survey_id']))))
- {
- Display :: display_header();
- Display :: display_error_message(get_lang('NotAllowed'), false);
- Display :: display_footer();
- exit;
- }
- }
- $survey_id = Security::remove_XSS($_GET['survey_id']);
- $survey_data = survey_manager::get_survey($survey_id);
- $urlname = strip_tags(api_substr(api_html_entity_decode($survey_data['title'],ENT_QUOTES,$charset), 0, 40));
- if (api_strlen(strip_tags($survey_data['title'])) > 40) {
- $urlname .= '...';
- }
- if ($_GET['action'] == 'add')
- {
- $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
- $tool_name = get_lang('CreateNewSurvey');
- }
- if ($_GET['action'] == 'edit' && is_numeric($survey_id))
- {
- $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
- $interbreadcrumb[] = array ("url" => "survey.php?survey_id=".$survey_id, "name" => strip_tags($urlname));
- $tool_name = get_lang('EditSurvey');
- }
- if ($_GET['action'] == 'edit' AND isset($survey_id) AND is_numeric($survey_id))
- {
- $defaults = $survey_data;
- $defaults['survey_id'] = $survey_id;
-
- $defaults['anonymous'] = $survey_data['anonymous'];
- }
- else
- {
- $defaults['survey_language'] = $_course['language'];
- $defaults['start_date'] = date('d-F-Y H:i');
- $startdateandxdays = time() + 864000;
- $defaults['end_date'] = date('d-F-Y H:i', $startdateandxdays);
-
-
- $defaults['anonymous'] = 0;
- }
- $form = new FormValidator('survey', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&survey_id='.$survey_id);
- $form->addElement('header', '', $tool_name);
- if ($_GET['action'] == 'edit' AND isset($survey_id) AND is_numeric($survey_id))
- {
- $form->addElement('hidden', 'survey_id');
- }
- $survey_code = $form->addElement('text', 'survey_code', get_lang('SurveyCode'), array('size' => '20','maxlength'=>'20'));
- 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));
- $form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name'=>'survey'));
- $form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name'=>'survey'));
- $form->addElement('checkbox', 'anonymous', 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));
- $surveytypes[0] = get_lang('Normal');
- $surveytypes[1] = get_lang('Conditional');
- if ($_GET['action'] == 'add')
- {
- $form->addElement('hidden','survey_type',0);
- $form -> addElement('html','<div id="options" style="display: none;">');
- require_once(api_get_path(LIBRARY_PATH).'surveymanager.lib.php');
- $survey_tree = new SurveyTree();
- $list_surveys = $survey_tree->createList($survey_tree->surveylist);
- $list_surveys[0]='';
- $form->addElement('select', 'parent_id', get_lang('ParentSurvey'), $list_surveys);
- $defaults['parent_id']=0;
- }
- if ($survey_data['survey_type']==1 || $_GET['action'] == 'add' )
- {
- $form->addElement('checkbox', 'one_question_per_page', get_lang('OneQuestionPerPage'));
- $form->addElement('checkbox', 'shuffle', get_lang('ActivateShuffle'));
- }
- if ((isset($_GET['action']) && $_GET['action'] == 'edit') && !empty($survey_id) )
- {
- if ($survey_data['anonymous']==0 ) {
-
- $form -> addElement('html','<div class="row">
- <div class="label">
- <a href="javascript: void(0);" onclick="javascript: advanced_parameters();" ><span id="plus_minus"> '.Display::return_icon('div_show.gif',null,array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedParameters').'</span></a>
- </div>
- <div class="formw">
-
- </div>
- </div>');
- $form -> addElement('html','<div id="options" style="display:none">');
- $form->addElement('checkbox', 'show_form_profile', get_lang('ShowFormProfile'),'','onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
- if ($survey_data['show_form_profile']== 1) {
- $form -> addElement('html','<div id="options_field" style="display:block">');
- } else {
- $form -> addElement('html','<div id="options_field" style="display:none">');
- }
- $field_list=SurveyUtil::make_field_list();
- if (is_array ($field_list))
- {
-
- foreach ($field_list as $key=> $field)
- {
- if ($field['visibility']==1)
- {
- $form->addElement('checkbox', 'profile_'.$key, ' ',' '.$field['name'] );
- $input_name_list.= 'profile_'.$key.',';
- }
- }
-
- $form->addElement('hidden', 'input_name_list', $input_name_list );
-
- if ($survey_data['form_fields'])
- {
- $form_fields=explode('@',$survey_data['form_fields']);
- foreach($form_fields as $field)
- {
- $field_value=explode(':',$field);
- if ($field_value[0]!='' && $field_value[1]!= '')
- {
- $defaults[$field_value[0]]=$field_value[1];
- }
- }
- }
- }
- $form->addElement('html', '</div></div>');
- }
- }
- $form -> addElement('html','</div><br />');
- if(isset($_GET['survey_id']) && $_GET['action']=='edit') {
- $class="save";
- $text=get_lang('ModifySurvey');
- } else {
- $class="add";
- $text=get_lang('CreateSurvey');
- }
- $form->addElement('style_submit_button', 'submit_survey', $text, 'class="'.$class.'"');
- if ($_GET['action'] == 'add')
- {
- $form->addRule('survey_code', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('survey_code', '', 'maxlength',20);
- }
- $form->addRule('survey_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('start_date', get_lang('InvalidDate'), 'date');
- $form->addRule('end_date', get_lang('InvalidDate'), 'date');
- $form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
- $form->setDefaults($defaults);
- if( $form->validate() )
- {
-
- $values = $form->exportValues();
-
- $return = survey_manager::store_survey($values);
-
- if($return['type'] == 'error')
- {
-
- Display::display_header($tool_name);
-
- Display::display_error_message(get_lang($return['message']), false);
-
- $form->display();
- }
- if ($config['survey']['debug'])
- {
-
- Display::display_confirmation_message($return['message'], false);
- } else {
-
- header('location:survey.php?survey_id='.$return['id'].'&message='.$return['message']);
- }
- } else {
-
- Display::display_header($tool_name);
-
-
-
- $form->display();
- }
- Display :: display_footer();
- ?>
|