1
0

categories.php 12 KB

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