DBObj)) { $user = $this->Doc->MemberAuth->getData(); $this->DBObj = SiteMap::getObj('Poll/Poll.php', null, $user); $this->DBObj->setEnabledOnly(true); } } function _getPollForm() { require_once 'class/Form/Form.class.php'; $form = new Form($this->Doc, 'poll_form', 'POST', BASE_URL . '/' . CURR_PAGE_FULL); $form->_jsPrefix = _('You have not answered following questions') . ':'; $form->_jsPostfix = _('Please answer the specified questions') . '.'; $form->setCancelType(null); $form->setSubmitTitle(_('Vote')); $form->setRequiredNote(''); //$form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->setTpl($this->_poll_form_tpl); $form->addElement('hidden', 'action', 'vote'); $form->addElement('hidden', 'id_poll', $this->id_poll); $form = $this->_bindFormFields($form); return $form; } function _bindFormFields($form) { $questions = $this->DBObj->getQuestions($this->id_poll, CURR_LANG); if (is_array($questions)) { foreach ($questions as $q) { $form->addElement('static', 'title_' . (int)$q['id'], null, $q['title']); foreach ($q['answers'] as $a_id => $a) { $form->addElement('radio', 'question[' . (int)$q['id'] . ']', null, $a, (int)$a_id, array()); $form->addRule('question[' . (int)$q['id'] . ']', 'Plase answer on questions', 'required'); $form->addRule('question[' . (int)$q['id'] . ']', "{$q['title']}", 'required', null, 'client'); } } } return $form; } function _showQuestions($poll_data) { $allow_vote = $this->DBObj->isAllowVote($this->id_poll); switch ($poll_data['show_results']) { case 'show': $this->_showResults(); break; case 'after_ansver': if (!$allow_vote) { $this->_showResults(); } else { $this->_showResults(true); } break; default: case 'dont_show': if (!$allow_vote && $this->Doc->MemberAuth->isLogged()) { $this->Doc->addContent(array('tpl' => $this->_thank_tpl, 'text' => $this->DBObj->thank_text)); } break; } if ($allow_vote) { $form = $this->_getPollForm(); if ($_REQUEST['action'] == 'vote') { if ($form->validate()) { $this->DBObj->vote($form->exportValues()); header('Location: ' . BASE_URL . '/' . CURR_PAGE_FULL); exit(); } else { $form->exec(); } } else { $form->exec(); } } return true; } function _showResults($hidden = false) { $res = $this->DBObj->getResults($this->id_poll); if (is_array($res) && !empty($res)) { $res['hidden'] = $hidden; $this->Doc->addContent(array('tpl' => $this->_results_tpl, 'item' => $res)); } return true; } function showPoll($showListUrl = true) { $qs = (string)Session::getData(PARENT_PAGE, 'QUERY_STRING'); if ($qs != '' && '?' != substr($qs, 0, 1)) { $qs = '?' . $qs; } $poll = array('tpl' => $this->_poll_tpl, 'item' => $this->DBObj->getFromDB($this->id_poll), 'QUERY_STRING' => $qs, 'show_list_url' => $showListUrl); $poll['item']['title'] = $poll['item']['title'][CURR_LANG]; $poll['item']['description'] = $poll['item']['description'][CURR_LANG]; $this->Doc->addContent($poll); // блок з описом опитування $this->_showQuestions($poll['item']); // результати і запитання } function setDoc($Doc) { $this->Doc = $Doc; } function setId($id) { $id = (int) $id; if ($id) { $this->id_poll = $id; } return $htis; } function getId() { if (!$this->id_poll) { $this->id_poll = (int) $this->options['_restAlias']; } return $this->id_poll; } function exec($Doc) { $this->setDoc($Doc); $this->initDBObj(); $id_poll = $this->getId(); if ($id_poll) { if ($this->DBObj->exists($id_poll)) { unset($this->Doc->content['ITEMS'][0]); // забираю перший хтмл-блок, при перегляді опитування він не потрібний $this->showPoll($id_poll); } else { $NotFound = SiteMap::getObj('NotFound/NotFoundView.php'); $NotFound->exec(&$Doc); } } else if ($this->_enable_list) { Session::setData(CURR_PAGE, 'QUERY_STRING', $_SERVER['QUERY_STRING']); require_once 'class/DB/List/List.php'; $DB_List = new DB_List(&$Doc, $this->DBObj); //$DB_List->ipp = 15; $DB_List->def_order_by = "{$this->DBObj->tableName}.sorter"; $DB_List->tpl = 'tpl/Poll/poll_list.tpl'; $DB_List->bind(); $DB_List->exec(); } return true; } }