Пример #1
0
 /**
  * Process config change of survey
  *
  * @return array errors
  */
 protected function process_config_change()
 {
     if (!check_form_key($this->form_key_name)) {
         return array($this->user->lang('FORM_INVALID'));
     }
     $new_settings = array('caption' => '', 'show_order' => 0, 'reverse_order' => 0, 'allow_change_answer' => 0, 'allow_multiple_answer' => 0, 'visibility' => 0, 'stop_time' => '', 'default_hide' => 0);
     if ($this->survey->is_moderator()) {
         $new_settings['topic_poster_right'] = 0;
     }
     foreach ($new_settings as $setting => $default) {
         $new_settings[$setting] = $this->request->variable('survey_setting_' . $setting, $default, true);
     }
     if ($new_settings['caption'] == '') {
         return array($this->user->lang('SURVEY_INVALID_CAPTION'));
     }
     if (!in_array($new_settings['show_order'], survey::$SHOW_ORDER_TYPES)) {
         return array($this->user->lang('SURVEY_INVALID_SHOW_ORDER_TYPE'));
     }
     $new_settings['reverse_order'] = $new_settings['reverse_order'] ? 1 : 0;
     $new_settings['allow_change_answer'] = $new_settings['allow_change_answer'] ? 1 : 0;
     $new_settings['allow_multiple_answer'] = $new_settings['allow_multiple_answer'] ? 1 : 0;
     $new_settings['default_hide'] = $new_settings['default_hide'] ? 1 : 0;
     if (!in_array($new_settings['visibility'], survey::$VISIBILITY_TYPES)) {
         return array($this->user->lang('SURVEY_INVALID_VISIBILITY_TYPE'));
     }
     if ($new_settings['stop_time'] != '') {
         $orig_input = $new_settings['stop_time'];
         $new_settings['stop_time'] = $this->user->get_timestamp_from_format('Y-m-d H:i', $new_settings['stop_time']);
         if ($new_settings['stop_time'] === false || $new_settings['stop_time'] + 60 < $this->survey->fixed_time() && $new_settings['stop_time'] != $this->survey->settings['stop_time']) {
             return array($this->user->lang('SURVEY_INVALID_STOPDATE', $orig_input));
         }
     } else {
         $new_settings['stop_time'] = null;
     }
     if ($this->survey->is_moderator()) {
         if (!in_array($new_settings['topic_poster_right'], survey::$TOPIC_POSTER_RIGHT_TYPES)) {
             return array($this->user->lang('SURVEY_INVALID_TOPIC_POSTER_RIGHT_TYPE'));
         }
     }
     $this->survey->change_config($new_settings);
     return array();
 }