DB_Grid($Doc, $DBObj); $this->actions['reorder'] = 'doReorderForm'; $this->actions['reorder_save'] = 'doReorderSave'; $this->actions['enable'] = 'doEnable'; } function _bindFormFields($form) { $langs = $this->DBObj->langs; $langs_count = count($langs); $title_title = _('Subject'); if ($langs_count > 1) { $form->addElement('header', 'title_header', $title_title); } $title = array(); foreach ($langs as $lng) { if ($langs_count > 1) { $field_title = $lng['title']; } else { $field_title = $title_title; } $field_name = "title[{$lng['name']}]"; $title[$lng['name']] =& $form->addElement('text', $field_name, $field_title, array()); $required_note = _('Subject is required') . ($langs_count > 1 ? " ({$lng['title']})" : ''); $form->addRule($field_name, $required_note, 'required'); $form->addRule($field_name, $required_note, 'required', null, 'client'); } $description_title = _('Description'); if ($langs_count > 1) { $form->addElement('header', 'description_header', $description_title); } $description = array(); foreach ($langs as $lng) { if ($langs_count > 1) { $field_title = $lng['title']; } else { $field_title = $description_title; } $field_name = "description[{$lng['name']}]"; $description[$lng['name']] =& $form->addElement('html_editor_basic', $field_name, $field_title, array('style' => 'height:50px;width:600px;')); //$required_note = _('Description is required') . ($langs_count > 1 ? " ({$lng['title']})" : ''); //$form->addRule($field_name, $required_note, 'required'); //$form->addRule($field_name, $required_note, 'required', null, 'client'); } $form->addElement('header', 'options_header', ' '); $date_options = array( //'language' => 'ru', //'format' => 'dMY', 'minYear' => 2008, 'maxYear' => date('Y') + 1, 'addEmptyOption' => false, 'emptyOptionValue' => '', 'emptyOptionText' => ' ', 'optionIncrement' => array('i' => 1, 's' => 1) ); $date_start =& $form->addElement('calendar', 'date_start', _('Start date'), $date_options); $date_end =& $form->addElement('calendar', 'date_end', _('End date'), $date_options); $show_results = $form->addGroup(array( $form->createElement('radio', 'show_results', '', 'Do not show poll results to users, just show "' . $this->DBObj->thank_text . '".', 'dont_show'), $form->createElement('radio', 'show_results', '', 'Show poll results to user at the same time that they take the poll.', 'show'), $form->createElement('radio', 'show_results', '', 'Show results to the user after they answer the poll question and also have a link for thie user just to see the poll results without participating.', 'after_ansver'), ), 'show_results_group', '*Showing Poll Results Options', '
', false); $form->addGroupRule('show_results_group', array('show_results' => array( array('Showing Poll Results Options is required', 'required'), array('Showing Poll Results Options is required', 'required', null, 'client'), ))); $enabled =& $form->addElement('advcheckbox', 'enabled', 'Show on site', '(This checkbox allows to show or not show this poll at the web site. Check it, if you would like this poll to be displayed at the web site.)', null, array('n', 'y')); $data = $this->DBObj->getData(); if (!is_array($data)) { $data = array(); $data['date_start'] = 'now'; $data['date_end'] = '+1 month'; } $form->setDefaults($data); $date_start->setValue(strtotime($data['date_start'])); $date_end->setValue(strtotime($data['date_end'])); $form->addFormRule(array(&$this, 'validateForm')); return $form; } function validateForm($data) { $err = array(); //vdie($data); if (!checkdate($data['date_start']['M'], $data['date_start']['d'], $data['date_start']['Y'])) { $err['date_start'] = 'Date is wrong'; } if (!checkdate($data['date_end']['M'], $data['date_end']['d'], $data['date_start']['Y'])) { $err['date_end'] = 'Date is wrong'; } if (empty($err['date_start']) && empty($err['date_end'])) { if ($this->DBObj->prepareFormDate($data['date_start']) >= $this->DBObj->prepareFormDate($data['date_end'])) { $err['date_end'] = 'End date shoud be after Start date'; } } return (!empty($err) ? $err : true); } function _doListBind(&$DB_List) { $DB_List->def_order_by = 'sorter'; $DB_List->bindCols(); $DB_List->insertColFirst( 'sorter', array( 'title' => '#', 'width' => 50, 'order_by' => 'sorter', 'tpl' => DB_LIST_CELL_SORTER, 'params' => array('sorter'), ) ); $DB_List->insertColAfter( 'title', array( 'title' => _('Subject'), 'width' => 230, 'order_by' => 'title', 'tpl' => DB_LIST_CELL_TEXT, 'params' => array('title'), ), 'sorter' ); $DB_List->insertColAfter( 'questions', array( 'title' => 'Edit Questions', 'width' => 70, 'url' => BASE_URL . '/' . CURR_PAGE . '/question?id_poll=', 'empty_title' => _('Edit'), 'tpl' => DB_LIST_CELL_LINK, 'params' => array('id', 'questions_num_title'), ), 'title' ); $DB_List->insertColAfter( 'term', array( 'title' => _('Date Start/End'), 'width' => 100, 'order_by' => '', 'tpl' => DB_LIST_CELL_TEXT_CENTER, 'params' => array('term'), ), 'questions' ); $DB_List->insertColAfter( 'url', array( 'title' => 'URL', 'width' => 250, 'order_by' => '', 'tpl' => BASE_PATH . '/app/Poll/tpl/poll_url.tpl', 'attr' => 'target="_blank"', 'url' => BASE_URL . '/poll/', 'params' => array('id', 'enabled'), ), 'term' ); $DB_List->insertColAfter('enabled', array( 'title' => 'Enabled', 'width' => 50, 'order_by' => 'enabled', 'tpl' => DB_LIST_CELL_LINK_ENUM, 'values' => array('y' => 'Yes', 'n' => 'No'), 'url' => BASE_URL . '/' . CURR_PAGE . '?action=enable&id=', 'target' => '', 'params' => array('enabled', 'id'), ), 'url' ); $DB_List->bind(); return true; } function doList() { /*$filtFrm = $this->getFilterForm(); $this->DBObj->setFilter($filtFrm->getElementValue('query')); $filtFrm->exec();*/ parent::doList(); } function addLink() { $link = Constant::get('BASE_URL') . '/' . CURR_PAGE; $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => array( array('link' => $link . '?action=new', 'title' => _('Add new Poll')), array('link' => $link . '?action=reorder', 'title' => _('Reorder Polls')), ) ); $this->Doc->addContent($addLink); } function _getReorderFrom() { $form = $this->_getBaseForm(); $list = array(); $list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter')); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = $val['title']; } $orderList = Form::createElement('select_edit', 'order_list', false, $list, array('style' => 'width:600px;')); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); return $form; } function doReorderForm() { $form = $this->_getReorderFrom(); $form->setTitle(_('Reorder Polls')); $form->addElement('hidden', 'action', 'reorder_save'); $form->exec(); } function doReorderSave() { $form = $this->_getReorderFrom(); $this->DBObj->reorder($form->getElementValue('order_list')); $this->doBack(); } function doEnable() { Session::setData(CURR_PAGE, 'msg', 'Poll is updated'); $this->DBObj->changeOption('enabled'); $this->doBack(); return true; } function doEdit() { parent::doEdit(); $res = $this->DBObj->getResults($this->id_poll); if (is_array($res) && !empty($res)) { $this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '

Current results

')); $this->Doc->addContent(array('tpl' => 'Poll/poll_results.tpl', 'item' => $res, 'question_edit_url' => BASE_URL . '/' . CURR_PAGE . '/question?action=edit')); } return true; } }