| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // TODO: reconsider almost all functionality in this file, according to new concept it should NOT be separate page with all categories, every module has its own page with tags |
|---|
| 4 | |
|---|
| 5 | /*************************************************************************** |
|---|
| 6 | * Dolphin Smart Community Builder |
|---|
| 7 | * ------------------- |
|---|
| 8 | * begin : Mon Mar 23 2006 |
|---|
| 9 | * copyright : (C) 2007 BoonEx Group |
|---|
| 10 | * website : http://www.boonex.com |
|---|
| 11 | * This file is part of Dolphin - Smart Community Builder |
|---|
| 12 | * |
|---|
| 13 | * Dolphin is free software; you can redistribute it and/or modify it under |
|---|
| 14 | * the terms of the GNU General Public License as published by the |
|---|
| 15 | * Free Software Foundation; either version 2 of the |
|---|
| 16 | * License, or any later version. |
|---|
| 17 | * |
|---|
| 18 | * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 19 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 20 | * See the GNU General Public License for more details. |
|---|
| 21 | * You should have received a copy of the GNU General Public License along with Dolphin, |
|---|
| 22 | * see license.txt file; if not, write to marketing@boonex.com |
|---|
| 23 | ***************************************************************************/ |
|---|
| 24 | |
|---|
| 25 | define('BX_CATEG_ACTION_ALL', 'all'); |
|---|
| 26 | define('BX_CATEG_ACTION_COMMON', 'common'); |
|---|
| 27 | define('BX_CATEG_ACTION_USERS', 'users'); |
|---|
| 28 | define('BX_CATEG_ACTION_CALENDAR', 'calendar'); |
|---|
| 29 | define('BX_CATEG_ACTION_SEARCH', 'search'); |
|---|
| 30 | |
|---|
| 31 | require_once( 'inc/header.inc.php' ); |
|---|
| 32 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' ); |
|---|
| 33 | |
|---|
| 34 | bx_import('BxDolTemplate'); |
|---|
| 35 | bx_import('BxTemplCategories'); |
|---|
| 36 | bx_import('BxDolPageView'); |
|---|
| 37 | bx_import('BxTemplCalendar'); |
|---|
| 38 | |
|---|
| 39 | $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false; |
|---|
| 40 | |
|---|
| 41 | function showCategories($aParam = array(), $iBoxId = 1, $sAction = '', $isBox = false, $bOrderPanel = false, $sTitle) |
|---|
| 42 | { |
|---|
| 43 | $oCateg = new BxTemplCategories(); |
|---|
| 44 | |
|---|
| 45 | $oCateg->getTagObjectConfig($aParam); |
|---|
| 46 | |
|---|
| 47 | if (empty($oCateg->aTagObjects)) |
|---|
| 48 | { |
|---|
| 49 | if ($isBox) |
|---|
| 50 | return DesignBoxContent($sTitle, MsgBox(_t('_Empty')), 1); |
|---|
| 51 | else |
|---|
| 52 | return MsgBox(_t('_Empty')); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | $aParam['type'] = isset($_GET['tags_mode']) && isset($oCateg->aTagObjects[$_GET['tags_mode']]) ? $_GET['tags_mode'] : $oCateg->getFirstObject(); |
|---|
| 56 | |
|---|
| 57 | $sCode = $oCateg->display($aParam, $iBoxId, $sAction, $bOrderPanel, getParam('categ_show_columns')); |
|---|
| 58 | |
|---|
| 59 | if ($isBox) |
|---|
| 60 | { |
|---|
| 61 | $aCaptionMenu = $oCateg->getCategTopMenuHtml($aParam, $iBoxId, $sAction); |
|---|
| 62 | $sCode = DesignBoxContent($sTitle, $sCode, 1, $aCaptionMenu); |
|---|
| 63 | $sCode = '<div id="page_block_' . $iBoxId . '">' . $sCode . '<div class="clear_both"></div></div>'; |
|---|
| 64 | return $sCode; |
|---|
| 65 | } |
|---|
| 66 | else |
|---|
| 67 | return array( |
|---|
| 68 | $sCode, |
|---|
| 69 | $oCateg->getCategTopMenu($aParam, $sAction), |
|---|
| 70 | array(), |
|---|
| 71 | ($sDate ? _t('_categ_by_day') . $sDate : '') |
|---|
| 72 | ); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | class CategoriesCalendar extends BxTemplCalendar |
|---|
| 77 | { |
|---|
| 78 | function CategoriesCalendar($iYear, $iMonth) |
|---|
| 79 | { |
|---|
| 80 | parent::BxTemplCalendar($iYear, $iMonth); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | function display() { |
|---|
| 84 | $aVars = array ( |
|---|
| 85 | 'bx_repeat:week_names' => $this->_getWeekNames (), |
|---|
| 86 | 'bx_repeat:calendar_row' => $this->_getCalendar (), |
|---|
| 87 | 'month_prev_url' => $this->getBaseUri () . "&year={$this->iPrevYear}&month={$this->iPrevMonth}", |
|---|
| 88 | 'month_prev_name' => _t('_month_prev'), |
|---|
| 89 | 'month_prev_icon' => getTemplateIcon('sys_back.png'), |
|---|
| 90 | 'month_next_url' => $this->getBaseUri () . "&year={$this->iNextYear}&month={$this->iNextMonth}", |
|---|
| 91 | 'month_next_name' => _t('_month_next'), |
|---|
| 92 | 'month_next_icon' => getTemplateIcon('sys_next.png'), |
|---|
| 93 | 'month_current' => $this->getTitle(), |
|---|
| 94 | ); |
|---|
| 95 | |
|---|
| 96 | $oSysTemplate = BxDolTemplate::getInstance(); |
|---|
| 97 | |
|---|
| 98 | $sHtml = $oSysTemplate->parseHtmlByName('calendar.html', $aVars); |
|---|
| 99 | $sHtml = preg_replace ('#<bx_repeat:events>.*?</bx_repeat:events>#s', '', $sHtml); |
|---|
| 100 | $oSysTemplate->addCss('calendar.css'); |
|---|
| 101 | return $sHtml; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | function getData() |
|---|
| 105 | { |
|---|
| 106 | $oDb = new BxDolDb(); |
|---|
| 107 | |
|---|
| 108 | return $oDb->getAll("SELECT *, DAYOFMONTH(`Date`) AS `Day` |
|---|
| 109 | FROM `sys_categories` |
|---|
| 110 | WHERE `Date` >= TIMESTAMP('{$this->iYear}-{$this->iMonth}-1') |
|---|
| 111 | AND `Date` < TIMESTAMP('{$this->iNextYear}-{$this->iNextMonth}-1') |
|---|
| 112 | AND `Owner` <> 0 AND `Status` = 'active'"); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | function getBaseUri() |
|---|
| 116 | { |
|---|
| 117 | return BX_DOL_URL_ROOT . 'categories.php?action=calendar'; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | function getBrowseUri() |
|---|
| 121 | { |
|---|
| 122 | return BX_DOL_URL_ROOT . 'categories.php?action=calendar'; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | function getEntriesNames () |
|---|
| 126 | { |
|---|
| 127 | return array(_t('_categ_single'), _t('_categ_plural')); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | function _getCalendar () |
|---|
| 131 | { |
|---|
| 132 | $sBrowseUri = $this->getBrowseUri(); |
|---|
| 133 | list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames (); |
|---|
| 134 | |
|---|
| 135 | $this->_getCalendarGrid($aCalendarGrid); |
|---|
| 136 | $aRet = array (); |
|---|
| 137 | for ($i = 0; $i < 6; $i++) { |
|---|
| 138 | |
|---|
| 139 | $aRow = array ('bx_repeat:cell'); |
|---|
| 140 | $isRowEmpty = true; |
|---|
| 141 | |
|---|
| 142 | for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) { |
|---|
| 143 | |
|---|
| 144 | $aCell = array (); |
|---|
| 145 | |
|---|
| 146 | if ($aCalendarGrid[$i][$j]['today']) { |
|---|
| 147 | $aCell['class'] = 'sys_cal_cell sys_cal_today'; |
|---|
| 148 | $aCell['day'] = $aCalendarGrid[$i][$j]['day']; |
|---|
| 149 | $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array( |
|---|
| 150 | 'num' => $aCalendarGrid[$i][$j]['num'], |
|---|
| 151 | 'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'], |
|---|
| 152 | 'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul, |
|---|
| 153 | )); |
|---|
| 154 | $isRowEmpty = false; |
|---|
| 155 | } elseif (isset($aCalendarGrid[$i][$j]['day'])) { |
|---|
| 156 | $aCell['class'] = 'sys_cal_cell'; |
|---|
| 157 | $aCell['day'] = $aCalendarGrid[$i][$j]['day']; |
|---|
| 158 | $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array( |
|---|
| 159 | 'num' => $aCalendarGrid[$i][$j]['num'], |
|---|
| 160 | 'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'], |
|---|
| 161 | 'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul, |
|---|
| 162 | )); |
|---|
| 163 | $isRowEmpty = false; |
|---|
| 164 | } else { |
|---|
| 165 | $aCell['class'] = 'sys_cal_cell_blank'; |
|---|
| 166 | $aCell['day'] = ''; |
|---|
| 167 | $aCell['bx_if:num'] = array ('condition' => false, 'content' => array( |
|---|
| 168 | 'num' => '', |
|---|
| 169 | 'href' => '', |
|---|
| 170 | 'entries' => '', |
|---|
| 171 | )); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | if ($aCell) |
|---|
| 175 | $aRow['bx_repeat:cell'][] = $aCell; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | if ($aRow['bx_repeat:cell'] && !$isRowEmpty) { |
|---|
| 179 | $aRet[] = $aRow; |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | return $aRet; |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | class CategoriesCalendarPage extends BxDolPageView |
|---|
| 188 | { |
|---|
| 189 | var $sPage; |
|---|
| 190 | |
|---|
| 191 | function CategoriesCalendarPage() |
|---|
| 192 | { |
|---|
| 193 | $this->sPage = 'categ_calendar'; |
|---|
| 194 | parent::BxDolPageView($this->sPage); |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | function getBlockCode_Calendar($iBlockId) |
|---|
| 198 | { |
|---|
| 199 | $sYear = isset($_GET['year']) ? (int)$_GET['year'] : ''; |
|---|
| 200 | $sMonth = isset($_GET['month']) ? (int)$_GET['month'] : ''; |
|---|
| 201 | $oCalendar = new CategoriesCalendar($sYear, $sMonth); |
|---|
| 202 | |
|---|
| 203 | return $oCalendar->display(); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | function getBlockCode_CategoriesDate($iBlockId) |
|---|
| 207 | { |
|---|
| 208 | if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day'])) |
|---|
| 209 | { |
|---|
| 210 | $aParam = array( |
|---|
| 211 | 'pagination' => getParam('categ_perpage_browse'), |
|---|
| 212 | 'date' => array( |
|---|
| 213 | 'year' => (int)$_GET['year'], |
|---|
| 214 | 'month' => (int)$_GET['month'], |
|---|
| 215 | 'day' => (int)$_GET['day'] |
|---|
| 216 | ) |
|---|
| 217 | ); |
|---|
| 218 | |
|---|
| 219 | return showCategories($aParam, $iBlockId, BX_CATEG_ACTION_CALENDAR, false, false, _t('_categ_caption_calendar')); |
|---|
| 220 | } |
|---|
| 221 | else |
|---|
| 222 | return MsgBox(_t('_Empty')); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | class CategoriesSearchPage extends BxDolPageView { |
|---|
| 227 | |
|---|
| 228 | var $aSearchForm; |
|---|
| 229 | var $oForm; |
|---|
| 230 | var $sPage; |
|---|
| 231 | |
|---|
| 232 | function CategoriesSearchPage() |
|---|
| 233 | { |
|---|
| 234 | $this->sPage = 'categ_search'; |
|---|
| 235 | parent::BxDolPageView($this->sPage); |
|---|
| 236 | |
|---|
| 237 | bx_import('BxTemplFormView'); |
|---|
| 238 | $this->aSearchForm = array( |
|---|
| 239 | 'form_attrs' => array( |
|---|
| 240 | 'name' => 'form_search_categories', |
|---|
| 241 | 'action' => '', |
|---|
| 242 | 'method' => 'post', |
|---|
| 243 | ), |
|---|
| 244 | |
|---|
| 245 | 'params' => array ( |
|---|
| 246 | 'db' => array( |
|---|
| 247 | 'submit_name' => 'submit_form', |
|---|
| 248 | ), |
|---|
| 249 | ), |
|---|
| 250 | |
|---|
| 251 | 'inputs' => array( |
|---|
| 252 | 'Keyword' => array( |
|---|
| 253 | 'type' => 'text', |
|---|
| 254 | 'name' => 'Keyword', |
|---|
| 255 | 'caption' => _t('_categ_caption_keyword'), |
|---|
| 256 | 'required' => true, |
|---|
| 257 | 'checker' => array ( |
|---|
| 258 | 'func' => 'length', |
|---|
| 259 | 'params' => array(1, 100), |
|---|
| 260 | 'error' => _t ('_categ_err_keyword'), |
|---|
| 261 | ), |
|---|
| 262 | 'db' => array ( |
|---|
| 263 | 'pass' => 'Xss', |
|---|
| 264 | ), |
|---|
| 265 | ), |
|---|
| 266 | 'Submit' => array ( |
|---|
| 267 | 'type' => 'submit', |
|---|
| 268 | 'name' => 'submit_form', |
|---|
| 269 | 'value' => _t('_Submit'), |
|---|
| 270 | 'colspan' => true, |
|---|
| 271 | ), |
|---|
| 272 | ), |
|---|
| 273 | ); |
|---|
| 274 | |
|---|
| 275 | $this->oForm = new BxTemplFormView($this->aSearchForm); |
|---|
| 276 | $this->oForm->initChecker(); |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | function getBlockCode_Form() { |
|---|
| 280 | return BxDolTemplate::getInstance()->parseHtmlByName('search_tags_box.html', array('form' => $this->oForm->getCode())); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | function getBlockCode_Founded($iBlockId) |
|---|
| 284 | { |
|---|
| 285 | $aParam = array( |
|---|
| 286 | 'pagination' => getParam('categ_perpage_browse') |
|---|
| 287 | ); |
|---|
| 288 | $sFilter = bx_get('filter'); |
|---|
| 289 | if ($sFilter !== false) |
|---|
| 290 | $aParam['filter'] = process_db_input($sFilter); |
|---|
| 291 | else if ($this->oForm->isSubmittedAndValid()) |
|---|
| 292 | $aParam['filter'] = $this->oForm->getCleanValue('Keyword'); |
|---|
| 293 | |
|---|
| 294 | if (isset($aParam['filter'])) |
|---|
| 295 | return showCategories($aParam, $iBlockId, BX_CATEG_ACTION_SEARCH, false, false, _t('_categ_caption_founded_categ')); |
|---|
| 296 | else |
|---|
| 297 | return MsgBox(_t('_Empty')); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | function getPage_All() |
|---|
| 302 | { |
|---|
| 303 | $aParam = array( |
|---|
| 304 | 'pagination' => getParam('categ_perpage_browse') |
|---|
| 305 | ); |
|---|
| 306 | |
|---|
| 307 | return showCategories($aParam, 1, BX_CATEG_ACTION_ALL, true, true, _t('_categ_caption_all')); |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | function getPage_Common() |
|---|
| 311 | { |
|---|
| 312 | $aParam = array( |
|---|
| 313 | 'pagination' => getParam('categ_perpage_browse'), |
|---|
| 314 | 'common' => true, |
|---|
| 315 | ); |
|---|
| 316 | |
|---|
| 317 | return showCategories($aParam, 1, BX_CATEG_ACTION_COMMON, true, false, _t('_categ_caption_common')); |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | function getPage_Users() |
|---|
| 321 | { |
|---|
| 322 | $aParam = array( |
|---|
| 323 | 'pagination' => getParam('categ_perpage_browse'), |
|---|
| 324 | 'common' => false |
|---|
| 325 | ); |
|---|
| 326 | |
|---|
| 327 | return showCategories($aParam, 1, BX_CATEG_ACTION_USERS, true, false, _t('_categ_caption_users')); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | function getPage_Calendar() |
|---|
| 331 | { |
|---|
| 332 | $oCalendarPage = new CategoriesCalendarPage(); |
|---|
| 333 | |
|---|
| 334 | return $oCalendarPage->getCode(); |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | function getPage_Search() |
|---|
| 338 | { |
|---|
| 339 | $oSearchPage = new CategoriesSearchPage(); |
|---|
| 340 | |
|---|
| 341 | return $oSearchPage->getCode(); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | $sAction = empty($_GET['action']) ? '' : $_GET['action']; |
|---|
| 345 | switch ($sAction) |
|---|
| 346 | { |
|---|
| 347 | case BX_CATEG_ACTION_COMMON: |
|---|
| 348 | $sContent = getPage_Common(); |
|---|
| 349 | break; |
|---|
| 350 | |
|---|
| 351 | case BX_CATEG_ACTION_USERS: |
|---|
| 352 | $sContent = getPage_Users(); |
|---|
| 353 | break; |
|---|
| 354 | |
|---|
| 355 | case BX_CATEG_ACTION_CALENDAR: |
|---|
| 356 | $sContent = getPage_Calendar(); |
|---|
| 357 | break; |
|---|
| 358 | |
|---|
| 359 | case BX_CATEG_ACTION_SEARCH: |
|---|
| 360 | $sContent = getPage_Search(); |
|---|
| 361 | break; |
|---|
| 362 | |
|---|
| 363 | default: |
|---|
| 364 | $sContent = getPage_All(); |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | if (!$bAjaxMode) { |
|---|
| 368 | $oTemplate = BxDolTemplate::getInstance(); |
|---|
| 369 | $oTemplate->setPageNameIndex(25); |
|---|
| 370 | $oTemplate->setPageParams(array( |
|---|
| 371 | 'header' => _t('_Categories'), |
|---|
| 372 | 'header_text' => _t('_Categories'), |
|---|
| 373 | )); |
|---|
| 374 | $oTemplate->setPageContent('page_main_code', $sContent); |
|---|
| 375 | |
|---|
| 376 | check_logged(); |
|---|
| 377 | PageCode(); |
|---|
| 378 | } |
|---|
| 379 | else |
|---|
| 380 | echo $sContent; |
|---|