public function onEdit(GWF_VoteMulti $poll, GWF_User $user) { $form = $this->getForm($poll, $user); if (false !== ($errors = $form->validate($this->module))) { return $errors; } $global = isset($_POST['public']); if ($global && !Module_Votes::mayAddGlobalPoll($user)) { return $this->module->error('err_global_poll'); } $options = 0; $options |= $global ? 0 : GWF_VoteMulti::INTERNAL_VOTE; $options |= isset($_POST['enabled']) ? GWF_VoteMulti::ENABLED : 0; $options |= isset($_POST['guest']) ? GWF_VoteMulti::GUEST_VOTES : 0; $options |= isset($_POST['multi']) ? GWF_VoteMulti::MULTIPLE_CHOICE : 0; $options |= $form->getVar('view'); if (false === $poll->saveVars(array('vm_title' => $form->getVar('title'), 'vm_gid' => $form->getVar('gid'), 'vm_level' => $form->getVar('level'), 'vm_options' => $options))) { return GWF_HTML::err('ERR_DATABASE', array(__FILE__, __LINE__)); } return $this->module->message('msg_poll_edit'); }
public function getForm() { $data = array('opt' => array(GWF_Form::VALIDATOR)); $buttons = array('add_opt' => $this->module->lang('btn_add_opt'), 'rem_opts' => $this->module->lang('btn_rem_opts'), 'create' => $this->module->lang('btn_create')); $data['title'] = array(GWF_Form::STRING, '', $this->module->lang('th_title')); $data['reverse'] = array(GWF_Form::CHECKBOX, true, $this->module->lang('th_reverse')); $data['multi'] = array(GWF_Form::CHECKBOX, false, $this->module->lang('th_multi')); $data['guests'] = array(GWF_Form::CHECKBOX, false, $this->module->lang('th_guests')); if (Module_Votes::mayAddGlobalPoll(GWF_Session::getUser())) { $data['public'] = array(GWF_Form::CHECKBOX, false, $this->module->lang('th_vm_public')); } $data['view'] = array(GWF_Form::SELECT, GWF_VoteMulti::getViewSelect($this->module, 'view', intval(Common::getPost('view', GWF_VoteMulti::SHOW_RESULT_VOTED))), $this->module->lang('th_mvview')); $data['gid'] = array(GWF_Form::SELECT, GWF_GroupSelect::single('gid', Common::getPostString('gid', '0')), $this->module->lang('th_vm_gid')); $data['level'] = array(GWF_Form::INT, '0', $this->module->lang('th_vm_level')); $i = 1; foreach (GWF_Session::getOrDefault(self::SESS_OPTIONS, array()) as $item) { $data['opt[' . $i . ']'] = array(GWF_Form::STRING, $item, $this->module->lang('th_option', array($i))); $i++; } $data['cmds'] = array(GWF_Form::SUBMITS, $buttons); return new GWF_Form($this, $data); }