/** * Displays survey data in posting.php * * @param unknown $event */ public function posting_display_template($event) { if (!$this->survey->can_create_survey($event['forum_id'])) { return; } // Check for first post if (isset($event['post_data']['topic_first_post_id']) && (!isset($event['post_data']['post_id']) || $event['post_data']['topic_first_post_id'] != $event['post_data']['post_id'])) { return; } $this->user->add_lang_ext('kilianr/survey', 'survey'); if (isset($event['topic_id']) && $event['topic_id']) { $this->survey->load_survey($event['topic_id']); } $this->template->assign_vars(array('S_SURVEY_ALLOWED' => true, 'S_TOPIC_HAS_SURVEY' => $this->survey->enabled, 'S_TOPIC_HAS_INACTIVE_SURVEY' => ($this->survey->entries || $this->survey->questions) && !$this->survey->enabled)); }
/** * Processes all actions * * @return array errors */ protected function process_submit() { if (!$this->request->is_set($this->action_name)) { return array(); } $action = $this->request->variable($this->action_name, ''); if (!$this->survey->enabled) { return array($this->user->lang('SURVEY_IS_DISABLED')); } $can_manage = $this->survey->can_manage($this->user->data['user_id']); if (!$can_manage && preg_match("/^(config_change|close|reopen|question_addition_or_modification|question_deletion|question_load_modify|delete|disable)\$/", $action)) { return array($this->user->lang('NO_AUTH_OPERATION')); } if ($this->survey->is_closed() && !$can_manage) { return array($this->user->lang('SURVEY_IS_CLOSED')); } if ($action == "config_change") { return $this->process_config_change(); } if ($action == "reopen") { if (!$this->survey->is_closed()) { return array($this->user->lang('SURVEY_IS_NOT_CLOSED')); } return $this->process_reopen(); } if ($action == "close") { if ($this->survey->is_closed()) { return array($this->user->lang('SURVEY_IS_CLOSED', $this->user->format_date($this->survey->settings['stop_time']))); } return $this->process_close(); } if ($action == "entry_deletion") { return $this->process_entry_deletion(); } if ($action == "entry_modification") { return $this->process_entry_modification(); } if ($action == "question_addition_or_modification") { return $this->process_question_addition_or_modification(); } if ($action == "question_deletion") { return $this->process_question_deletion(); } if ($action == "question_load_modify") { return $this->process_question_load_modify(); } if ($action == "disable") { return $this->process_disable(); } if ($action == "delete") { return $this->process_delete(); } return array(); }
public function main($id, $mode) { global $config, $user, $template, $request; $user->add_lang_ext('kilianr/survey', array('survey', 'info_acp_survey')); $this->tpl_name = 'acp_survey'; $this->page_title = $user->lang('ACP_SURVEY'); add_form_key('acp_survey'); if ($request->is_set_post('submit')) { if (!check_form_key('acp_survey')) { trigger_error('FORM_INVALID'); } $new_settings = array('show_order' => 0, 'reverse_order' => 0, 'allow_change_answer' => 0, 'allow_multiple_answer' => 0, 'visibility' => 0, 'default_hide' => 0, 'topic_poster_right' => 0); foreach ($new_settings as $setting => $default) { $new_settings[$setting] = $request->variable("kilianr_survey_default_{$setting}", $default); } if (!in_array($new_settings['show_order'], survey::$SHOW_ORDER_TYPES)) { trigger_error('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)) { trigger_error('SURVEY_INVALID_VISIBILITY_TYPE'); } if (!in_array($new_settings['topic_poster_right'], survey::$TOPIC_POSTER_RIGHT_TYPES)) { trigger_error('SURVEY_INVALID_TOPIC_POSTER_RIGHT_TYPE'); } foreach ($new_settings as $setting => $value) { $config->set("kilianr_survey_default_{$setting}", $value); } trigger_error($user->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); } foreach (array('show_order', 'visibility', 'topic_poster_right') as $block_setting) { survey::assign_block_vars_for_selection($block_setting, $template, $user, $config, 'kilianr_survey_default_'); } $template->assign_vars(array('U_ACTION' => $this->u_action, 'SURVEY_DEFAULT_REVERSE_ORDER' => $config['kilianr_survey_default_reverse_order'], 'SURVEY_DEFAULT_ALLOW_CHANGE_ANSWER' => $config['kilianr_survey_default_allow_change_answer'], 'SURVEY_DEFAULT_ALLOW_MULTIPLE_ANSWER' => $config['kilianr_survey_default_allow_multiple_answer'], 'SURVEY_DEFAULT_DEFAULT_HIDE' => $config['kilianr_survey_default_default_hide'])); }
/** * Delete all entries of the users in all existing surveys * * @param object $event The event object * @access public */ public function delete_user($event) { $this->survey->delete_user($event['mode'], $event['user_ids'], $event['retain_username']); }
public function convert_old_survey_data() { global $auth, $user; if (!isset($this->config['survey_version'])) { return; } if (!function_exists('user_get_id_name')) { include "{$this->phpbb_root_path}includes/functions_user.{$this->php_ext}"; } $user->add_lang_ext('kilianr/survey', 'survey'); $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . ' WHERE topic_survey = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $topic_id = $row['topic_id']; $sql = "SELECT * FROM {$this->table_prefix}survey WHERE topic_id = '{$topic_id}'"; $result2 = $this->db->sql_query($sql); $old_settings = $this->db->sql_fetchrow($result2); $this->db->sql_freeresult($result2); if ($old_settings) { $survey = new survey($this->db, $this->config, $user, $auth, $this->table_prefix . 'surveys', $this->table_prefix . 'surveys_questions', $this->table_prefix . 'surveys_q_choices', $this->table_prefix . 'surveys_entries', $this->table_prefix . 'surveys_answers'); $survey->enable($topic_id); $survey->initialize($topic_id); $survey->load_survey($topic_id); // Convert the settings $settings = array('caption' => $old_settings['survey_caption'] ? $old_settings['survey_caption'] : $user->lang('SURVEY'), 'show_order' => min(max((int) $old_settings['show_order'], 0), 2), 'reverse_order' => $old_settings['show_order'] == 3 ? 1 : 0, 'allow_change_answer' => $old_settings['allow_change_answers'] == 1 ? 1 : 0, 'allow_multiple_answer' => $old_settings['allow_change_answers'] == 2 ? 1 : 0, 'visibility' => $old_settings['hide_survey_results'] ? 3 : ($old_settings['hide_names_of_respondents'] ? 1 : 0), 'start_time' => $old_settings['survey_start'], 'stop_time' => $old_settings['survey_length'] == 0 ? null : $old_settings['survey_start'] + $old_settings['survey_length']); $survey->change_config($settings); // Convert the questions $questions_skip = array(); $questions_label = array_map('trim', explode('|', $old_settings['questions'])); $questions_type = explode('|', $old_settings['question_types']); $questions_choices = explode('|', htmlspecialchars_decode($old_settings['question_selections'])); $questions_sum_type = explode('|', $old_settings['question_sums']); $questions_sum_by = array_map('trim', explode('|', $old_settings['question_selected_text'])); $questions_cap = explode('|', $old_settings['question_response_caps']); $num_questions = min(sizeof($questions_label), sizeof($questions_type), sizeof($questions_choices), sizeof($questions_sum_type), sizeof($questions_sum_by), sizeof($questions_cap)); for ($i = 0; $i < $num_questions; $i++) { $questions_skip[$i] = false; if ($questions_label[$i] == '' || $survey->get_question_id_from_label($questions_label[$i], -1) != -1) { $questions_skip[$i] = true; continue; } $new_type = min(max((int) $questions_type[$i], 0), 5); $new_type = $new_type == 2 ? 0 : $new_type; $new_type = $new_type == 3 ? 4 : $new_type; $question = array('label' => $questions_label[$i], 'example_answer' => '', 'type' => $new_type, 'random_choice_order' => 0, 'sum_type' => min(max((int) $questions_sum_type[$i] == 4 ? 2 : (int) $questions_sum_type[$i], 0), 3), 'sum_by' => $questions_sum_type[$i] == 3 ? $questions_sum_by[$i] : '', 'average' => $questions_sum_type[$i] == 4 ? 1 : 0, 'cap' => (int) $questions_cap[$i]); $choices = array(); if ($new_type == 4 || $new_type == 5) { if ($questions_choices[$i] == '') { $questions_skip[$i] = true; continue; } foreach (array_map('trim', array_unique(explode(";", $questions_choices[$i]))) as $choice) { if ($choice == '') { continue; } $choices[] = htmlspecialchars(str_replace(',', '', $choice)); } } $questions_type[$i] = $new_type; $survey->add_question($question, $choices); $questions_id[$i] = $survey->get_question_id_from_label($questions_label[$i], -1); } // Convert the answers $sql = "SELECT user_id, answers FROM {$this->table_prefix}survey_answers WHERE survey_id = {$old_settings['survey_id']} ORDER BY response_order"; $result2 = $this->db->sql_query($sql); while ($row2 = $this->db->sql_fetchrow($result2)) { $username = array(); if (user_get_id_name($row2['user_id'], $username) == 'NO_USERS') { continue; } $raw_answers = explode('|', $row2['answers']); $answers = array(); $i = -1; foreach ($raw_answers as $answer) { ++$i; if ($i >= $num_questions || $questions_skip[$i]) { continue; } if ($questions_type[$i] == 5) { $answer = implode(',', array_map('trim', explode('&&', str_replace(',', '', $answer)))); } if ($questions_type[$i] == 4) { $answer = str_replace(',', '', trim($answer)); } if (!$survey->check_answer($answer, $questions_id[$i])) { continue; } $answers[$questions_id[$i]] = $answer; } $survey->add_entry($row2['user_id'], $answers); } $this->db->sql_freeresult($result2); unset($survey); } } $this->db->sql_freeresult($result); }
/** * Delete the survey which belongs to the topic by deleting all parts. * * @param object $event The event object * @return null * @access public */ public function delete_topic($event) { $this->survey->delete($event['topic_ids'], true); }