'doList',
'archives' => 'doArchives',
'show' => 'doShow'
);
var $pageNum = null;
var $pagerLink = 'blog';
function AnnouncementShow(&$Doc, &$DBObj)
{
$this->DB_Grid($Doc, $DBObj);
}
function setAction($action)
{
$this->action = $action;
}
function exec()
{
if ($this->action == '') {
$this->action = $_REQUEST['action'];
}
if (!key_exists($this->action, $this->actions)) {
$actionNames = array_keys($this->actions);
$this->action = $actionNames[0];
}
$function = $this->actions[$this->action];
if ($this->isXmlHttpRequest()) {
$function .= 'Ajax';
}
if (method_exists($this, $function)) {
$this->$function();
} else {
exit;
}
}
function doList()
{
$this->_saveBackUrl();
$this->_showFilter();
$id_category = (int) $this->DBObj->getFilter('id_category');
$category = '';
if ($id_category) {
$categories = $this->DBObj->getCategories();
$category = $categories[$id_category];
$this->Doc->setTitle($this->Doc->getTitle() . ' / ' . $category);
}
$this->_showList();
//$this->_showArchive();
$this->_showCategories(true);
return $this;
}
protected function _showFilter($cancelUrl = null)
{
$filterFrom = $this->getFilterForm();
$filterFrom->setReturnForm(true);
$filter = $filterFrom->exportValues();
$this->DBObj->updateFilter($filter['search']);
if (null !== $cancelUrl) {
$filterFrom->updateElementAttr('cancel_btn', array('onclick' => 'document.location.href=\'' . $cancelUrl . '\''));
}
$form = $filterFrom->exec();
$this->Doc->addContent($form, '_anc_search_form');
return $this;
}
protected function _showList()
{
require_once('class/DB/List/List.php');
$DB_List = new DB_List($this->Doc, $this->DBObj, $this->functionalFields);
$DB_List->def_order_by = 'sorter';
$DB_List->tpl = 'tpl/Announcement/list.tpl';
$DB_List->setPagerLink(BASE_URL . '/' . $this->pagerLink);
$DB_List->urlVarNames[] = 'search';
if (!empty($this->pageNum)) {
$DB_List->pageNum = $this->pageNum;
}
$DB_List->exec();
return $this;
}
protected function _showArchive()
{
$list = $this->DBObj->getArchive();
if (strlen($this->archives) == 7) {
$date = $this->archives . '-01';
} else {
$date = (int) $this->archives;
}
$this->Doc->assign('_rightColumn', array('tpl' => 'Announcement/archives.tpl', 'items' => $list, 'currDate' => $date));
return $this;
}
function doShow()
{
$data = $this->DBObj->getFromDB($this->DBObj->id);
if (!is_array($data) || empty($data)) {
Session::setData(CURR_PAGE, 'error', 'Post not found.');
header('Location: ' . BASE_URL . '/' . CURR_PAGE);
exit();
}
$this->DBObj->addClick($this->DBObj->id);
//$data['document_extention'] = '';
//if (false !== ($pos = strrpos($data['document'], '.'))) {
// $data['document_extention'] = strtolower(substr($data['document'], $pos + 1));
//}
$item = array(
'tpl' => 'Announcement/show.tpl',
'data' => $data,
'back_url' => $this->getBackUrl(),
);
$this->Doc->addContent($item);
if (in_array(3, $data['id_type'])) { // poll
if ($this->Doc->MemberAuth->isLogged()) {
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '
'));
$poll = SiteMap::getObj('Poll/Show/ShowView.php');
$poll->_thank_tpl = 'Announcement/Poll/poll_thank.tpl';
$poll->_results_tpl = 'Announcement/Poll/poll_results.tpl';
$poll->_poll_form_tpl = 'tpl/Announcement/Poll/poll_form.tpl';
$poll->_poll_tpl = 'Announcement/Poll/poll_show.tpl';
$poll->setDoc($this->Doc);
$poll->setId($data['id_poll']);
$poll->initDBObj();
if ($poll->DBObj->exists($data['id_poll'])) {
$poll->showPoll(false);
}
$this->Doc->addContent(array('tpl' => 'text.tpl', 'text' => '
'));
} else {
$this->Doc->MemberAuth->setLogin2(CURR_PAGE_FULL);
$this->Doc->addContent(array('tpl' => 'Announcement/poll_login.tpl', 'login_url' => $this->Doc->MemberAuth->loginPage));
}
}
return true;
}
function doArchives()
{
$this->_saveBackUrl();
$date = $this->archives;
if (strlen($date) == 7) {
$date = date('F Y', strtotime($date . '-01'));
} else {
$date = (int) $date;
}
$this->Doc->assign('_show_back', true);
//$this->_showFilter(BASE_URL . '/' . CURR_PAGE_FULL);
$this->_showFilter(BASE_URL . '/' . CURR_PAGE);
$id_category = (int) $this->DBObj->getFilter('id_category');
$category = '';
if ($id_category) {
$categories = $this->DBObj->getCategories();
$category = $categories[$id_category] . ' ';
}
$this->Doc->setTitle($this->Doc->getTitle() . ' / Archive for ' . $category . $date);
$this->DBObj->updateFilter(array('archives' => $this->archives, 'excludeCategories' => array(3)));
$this->pagerLink = CURR_PAGE_FULL;
if (false !== strpos($this->pagerLink, '/page/')) {
$this->pagerLink = preg_replace("/page\/\d+/", '', $this->pagerLink);
$this->pagerLink = str_replace('//', '/', $this->pagerLink);
}
$this->_showList();
//$this->_showArchive();
$this->_showCategories(true);
return $this;
}
function getFilterForm()
{
$years = $this->DBObj->getArchive();
if (!empty($years)) {
$tmp = array();
$currYear = 0;
foreach ($years as $date) {
$date = strtotime($date);
$year = date('Y', $date);
if ($currYear != $year) {
$tmp['blog/archives/' . $year] = $year . ' Posts';
$currYear = $year;
}
//$tmp['blog/archives/' . date('Y/m', $date)] = date('F Y', $date) . ' Posts';
}
$years = $tmp;
}
$form = $this->_getBaseForm('get');
$form->tpl = ''; // на юзерці не використовується
$form->setRendType(FORM_RENDERER_ARRAY_SMARTY);
$form->addElement('text', 'search[query]');
//$form->addElement('select', 'search[id_category]', null, array('' => 'All') + $this->DBObj->getCategories(), array('onchange' => 'this.form.submit();'));
$form->addElement('hidden', 'search[id_category]', null);
$form->addElement('select', 'archives', null, array('' => 'All') + $years, array('id' => 'id_archives'));
$form->setConstants(array('archives' => CURR_PAGE_FULL));
$form->addElement('submit', 'submit_btn', 'Search', array('class' => 'btn'));
$id_category = $form->exportValue('search[id_category]');
$link = Constant::get('BASE_URL') . '/' . CURR_PAGE;
if ($id_category) {
$link .= '?search[id_category]=' . $id_category;
}
$form->addElement('button', 'cancel_btn', 'Cancel', array('class' => 'btn', 'onclick' => "document.location.href='" . $link . "'"));
return $form;
}
protected function _showCategories($isArchives = false)
{
$categories = $this->DBObj->getCategories();
if ($isArchives) {
unset($categories[3]); // dont show events for archives
}
$categories = array(0 => 'All Categories') + $categories;
$this->Doc->assign('_rightColumn', array('tpl' => 'Announcement/categories.tpl', 'items' => $categories, 'filter' => $this->DBObj->getFilter()));
return $this;
}
}