Cheetah
categories.php
Go to the documentation of this file.
1 <?php
2 
8 define('CH_CATEG_ACTION_ALL', 'all');
9 define('CH_CATEG_ACTION_COMMON', 'common');
10 define('CH_CATEG_ACTION_USERS', 'users');
11 define('CH_CATEG_ACTION_CALENDAR', 'calendar');
12 define('CH_CATEG_ACTION_SEARCH', 'search');
13 
14 require_once( 'inc/header.inc.php' );
15 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
16 
17 ch_import('ChTemplCategories');
18 ch_import('ChWsbPageView');
19 ch_import('ChTemplCalendar');
20 
21 $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
22 
23 function showCategories($aParam = array(), $iBoxId = 1, $sAction = '', $isBox = false, $bOrderPanel = false, $sTitle = '')
24 {
25  $oCateg = new ChTemplCategories();
26 
27  $oCateg->getTagObjectConfig($aParam);
28 
29  if (empty($oCateg->aTagObjects)) {
30  if ($isBox)
31  return DesignBoxContent($sTitle, MsgBox(_t('_Empty')), 1);
32  else
33  return MsgBox(_t('_Empty'));
34  }
35 
36  $aParam['type'] = isset($_GET['tags_mode']) && isset($oCateg->aTagObjects[$_GET['tags_mode']]) ? $_GET['tags_mode'] : $oCateg->getFirstObject();
37 
38  $sCode = $oCateg->display($aParam, $iBoxId, $sAction, $bOrderPanel, getParam('categ_show_columns'));
39 
40  if ($isBox) {
41  $aCaptionMenu = $oCateg->getCategTopMenuHtml($aParam, $iBoxId, $sAction);
42  $sCode = DesignBoxContent($sTitle, $sCode, 1, $aCaptionMenu);
43  $sCode = '<div id="page_block_' . $iBoxId . '">' . $sCode . '<div class="clear_both"></div></div>';
44  return $sCode;
45  } else
46  return array(
47  $sCode,
48  $oCateg->getCategTopMenu($aParam, $sAction),
49  array(),
50  ($sDate ? _t('_categ_by_day') . $sDate : '')
51  );
52 }
53 
55 {
57  {
58  parent::__construct($iYear, $iMonth);
59  }
60 
61  function display()
62  {
63  $sTopControls = $GLOBALS['oSysTemplate']->parseHtmlByName('calendar_top_controls.html', array(
64  'month_prev_url' => $this->getBaseUri () . "&year={$this->iPrevYear}&month={$this->iPrevMonth}",
65  'month_next_url' => $this->getBaseUri () . "&year={$this->iNextYear}&month={$this->iNextMonth}",
66  'month_current' => $this->getTitle(),
67  ));
68 
69  $sHtml = $GLOBALS['oSysTemplate']->parseHtmlByName('calendar.html', array (
70  'top_controls' => $sTopControls,
71  'ch_repeat:week_names' => $this->_getWeekNames (),
72  'ch_repeat:calendar_row' => $this->_getCalendar (),
73  'bottom_controls' => $sTopControls,
74  ));
75  $sHtml = preg_replace ('#<ch_repeat:events>.*?</ch_repeat:events>#s', '', $sHtml);
76  $GLOBALS['oSysTemplate']->addCss('calendar.css');
77  return $sHtml;
78  }
79 
80  function getData()
81  {
83 
84  return $oDb->getAll("SELECT *, DAYOFMONTH(`Date`) AS `Day`
85  FROM `sys_categories`
86  WHERE `Date` >= TIMESTAMP(?)
87  AND `Date` < TIMESTAMP(?)
88  AND `Owner` <> 0 AND `Status` = 'active'",
89  [
90  "{$this->iYear}-{$this->iMonth}-1",
91  "{$this->iNextYear}-{$this->iNextMonth}-1",
92  ]
93  );
94  }
95 
96  function getBaseUri()
97  {
98  return CH_WSB_URL_ROOT . 'categories.php?action=calendar';
99  }
100 
101  function getBrowseUri()
102  {
103  return CH_WSB_URL_ROOT . 'categories.php?action=calendar';
104  }
105 
106  function getEntriesNames ()
107  {
108  return array(_t('_categ_single'), _t('_categ_plural'));
109  }
110 
111  function _getCalendar ()
112  {
113  $sBrowseUri = $this->getBrowseUri();
114  list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames ();
115 
116  $this->_getCalendarGrid($aCalendarGrid);
117  $aRet = array ();
118  for ($i = 0; $i < 6; $i++) {
119 
120  $aRow = array ('ch_repeat:cell');
121  $isRowEmpty = true;
122 
123  for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
124 
125  $aCell = array ();
126 
127  if ($aCalendarGrid[$i][$j]['today']) {
128  $aCell['class'] = 'sys_cal_cell sys_cal_today';
129  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
130  $aCell['ch_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  } elseif (isset($aCalendarGrid[$i][$j]['day'])) {
137  $aCell['class'] = 'sys_cal_cell';
138  $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
139  $aCell['ch_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
140  'num' => $aCalendarGrid[$i][$j]['num'],
141  'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
142  'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
143  ));
144  $isRowEmpty = false;
145  } else {
146  $aCell['class'] = 'sys_cal_cell_blank';
147  $aCell['day'] = '';
148  $aCell['ch_if:num'] = array ('condition' => false, 'content' => array(
149  'num' => '',
150  'href' => '',
151  'entries' => '',
152  ));
153  }
154 
155  if ($aCell)
156  $aRow['ch_repeat:cell'][] = $aCell;
157  }
158 
159  if ($aRow['ch_repeat:cell'] && !$isRowEmpty) {
160  $aRet[] = $aRow;
161  }
162  }
163  return $aRet;
164  }
165 
166 }
167 
169 {
170  var $sPage;
171 
172  function __construct()
173  {
174  $this->sPage = 'categ_calendar';
175  parent::__construct($this->sPage);
176  }
177 
178  function getBlockCode_Calendar($iBlockId)
179  {
180  $sYear = isset($_GET['year']) ? (int)$_GET['year'] : '';
181  $sMonth = isset($_GET['month']) ? (int)$_GET['month'] : '';
182  $oCalendar = new CategoriesCalendar($sYear, $sMonth);
183 
184  return $oCalendar->display();
185  }
186 
187  function getBlockCode_CategoriesDate($iBlockId)
188  {
189  if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day'])) {
190  $aParam = array(
191  'pagination' => getParam('categ_perpage_browse'),
192  'date' => array(
193  'year' => (int)$_GET['year'],
194  'month' => (int)$_GET['month'],
195  'day' => (int)$_GET['day']
196  )
197  );
198 
199  return showCategories($aParam, $iBlockId, CH_CATEG_ACTION_CALENDAR, false, false, _t('_categ_caption_calendar'));
200  } else
201  return MsgBox(_t('_Empty'));
202  }
203 }
204 
206 {
208  var $oForm;
209  var $sPage;
210 
211  function __construct()
212  {
213  $this->sPage = 'categ_search';
214  parent::__construct($this->sPage);
215 
216  ch_import('ChTemplFormView');
217  $this->aSearchForm = array(
218  'form_attrs' => array(
219  'name' => 'form_search_categories',
220  'action' => '',
221  'method' => 'post',
222  ),
223 
224  'params' => array (
225  'db' => array(
226  'submit_name' => 'submit_form',
227  ),
228  ),
229 
230  'inputs' => array(
231  'Keyword' => array(
232  'type' => 'text',
233  'name' => 'Keyword',
234  'caption' => _t('_categ_caption_keyword'),
235  'required' => true,
236  'checker' => array (
237  'func' => 'length',
238  'params' => array(1, 100),
239  'error' => _t ('_categ_err_keyword'),
240  ),
241  'db' => array (
242  'pass' => 'Xss',
243  ),
244  ),
245  'Submit' => array (
246  'type' => 'submit',
247  'name' => 'submit_form',
248  'value' => _t('_Submit'),
249  'colspan' => true,
250  ),
251  ),
252  );
253 
254  $this->oForm = new ChTemplFormView($this->aSearchForm);
255  $this->oForm->initChecker();
256  }
257 
258  function getBlockCode_Form()
259  {
260  return $GLOBALS['oSysTemplate']->parseHtmlByName('search_tags_box.html', array('form' => $this->oForm->getCode()));
261  }
262 
263  function getBlockCode_Founded($iBlockId)
264  {
265  $aParam = array(
266  'pagination' => getParam('categ_perpage_browse')
267  );
268  $sFilter = ch_get('filter');
269  if ($sFilter !== false)
270  $aParam['filter'] = process_db_input($sFilter);
271  else if ($this->oForm->isSubmittedAndValid())
272  $aParam['filter'] = $this->oForm->getCleanValue('Keyword');
273 
274  if (isset($aParam['filter']))
275  return showCategories($aParam, $iBlockId, CH_CATEG_ACTION_SEARCH, false, false, _t('_categ_caption_founded_categ'));
276  else
277  return MsgBox(_t('_Empty'));
278  }
279 }
280 
281 function getPage_All()
282 {
283  $aParam = array(
284  'pagination' => getParam('categ_perpage_browse')
285  );
286 
287  return showCategories($aParam, 1, CH_CATEG_ACTION_ALL, true, true, _t('_categ_caption_all'));
288 }
289 
290 function getPage_Common()
291 {
292  $aParam = array(
293  'pagination' => getParam('categ_perpage_browse'),
294  'common' => true,
295  );
296 
297  return showCategories($aParam, 1, CH_CATEG_ACTION_COMMON, true, false, _t('_categ_caption_common'));
298 }
299 
300 function getPage_Users()
301 {
302  $aParam = array(
303  'pagination' => getParam('categ_perpage_browse'),
304  'common' => false
305  );
306 
307  return showCategories($aParam, 1, CH_CATEG_ACTION_USERS, true, false, _t('_categ_caption_users'));
308 }
309 
311 {
312  $oCalendarPage = new CategoriesCalendarPage();
313 
314  return $oCalendarPage->getCode();
315 }
316 
317 function getPage_Search()
318 {
319  $oSearchPage = new CategoriesSearchPage();
320 
321  return $oSearchPage->getCode();
322 }
323 
324 $sAction = empty($_GET['action']) ? '' : $_GET['action'];
325 switch ($sAction) {
328  break;
329 
332  break;
333 
336  break;
337 
340  break;
341 
342  default:
344 }
345 
346 if (!$bAjaxMode) {
347  global $_page;
349  $iIndex = 25;
350 
351  $_page['name_index'] = $iIndex;
352  $_page['css_name'] = 'tags.css';
353 
354  $_page['header'] = _t('_Categories');
355  $_page['header_text'] = _t('_Categories');
356  $_page_cont[$iIndex]['page_main_code'] = $sContent;
357 
358  check_logged();
359  PageCode();
360 } else
361  echo $sContent;
CH_CATEG_ACTION_SEARCH
const CH_CATEG_ACTION_SEARCH
Definition: categories.php:12
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
CategoriesCalendar\getBaseUri
getBaseUri()
Definition: categories.php:96
$bAjaxMode
$bAjaxMode
Definition: categories.php:21
ChWsbCalendar\$iMonth
$iMonth
Definition: ChWsbCalendar.php:50
ChTemplFormView
Definition: ChTemplFormView.php:11
true
if(!defined("TRUE_VAL")) define("TRUE_VAL" true
Definition: constants.inc.php:8
CategoriesSearchPage\getBlockCode_Form
getBlockCode_Form()
Definition: categories.php:258
CategoriesSearchPage\$sPage
$sPage
Definition: categories.php:209
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
check_logged
check_logged()
Definition: admin.inc.php:238
CategoriesSearchPage\$aSearchForm
$aSearchForm
Definition: categories.php:207
ChWsbPageView
Definition: ChWsbPageView.php:99
$sCode
$sCode
Definition: explanation.php:19
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
ChWsbCalendar\_getWeekNames
_getWeekNames($isMiniMode=false)
Definition: ChWsbCalendar.php:101
CategoriesCalendarPage\getBlockCode_Calendar
getBlockCode_Calendar($iBlockId)
Definition: categories.php:178
ChWsbCalendar\_getCalendarGrid
_getCalendarGrid(&$aCalendarGrid)
Definition: ChWsbCalendar.php:119
getPage_Common
getPage_Common()
Definition: categories.php:290
php
CategoriesCalendarPage\$sPage
$sPage
Definition: categories.php:170
$_page
$_page
Definition: categories.php:278
CategoriesCalendar\getData
getData()
Definition: categories.php:80
CategoriesCalendar
Definition: categories.php:55
getPage_All
getPage_All()
Definition: categories.php:281
CategoriesCalendar\__construct
__construct($iYear, $iMonth)
Definition: categories.php:56
CategoriesCalendar\_getCalendar
_getCalendar()
Definition: categories.php:111
getPage_Search
getPage_Search()
Definition: categories.php:317
ChTemplCategories
Definition: ChTemplCategories.php:11
CategoriesSearchPage
Definition: categories.php:206
ChWsbCalendar\getTitle
getTitle()
Definition: ChWsbCalendar.php:200
$_GET
$_GET['debug']
Definition: index.php:67
$iIndex
$iIndex
Definition: bottom_menu_compose.php:142
showCategories
showCategories($aParam=array(), $iBoxId=1, $sAction='', $isBox=false, $bOrderPanel=false, $sTitle='')
Definition: categories.php:23
and
and
Definition: license.txt:18
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
CategoriesCalendar\getBrowseUri
getBrowseUri()
Definition: categories.php:101
CategoriesSearchPage\$oForm
$oForm
Definition: categories.php:208
$sTitle
$sTitle
Definition: actions.inc.php:13
CH_CATEG_ACTION_ALL
const CH_CATEG_ACTION_ALL
Definition: categories.php:8
$oDb
global $oDb
Definition: db.inc.php:39
CategoriesCalendarPage\__construct
__construct()
Definition: categories.php:172
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
getPage_Users
getPage_Users()
Definition: categories.php:300
PageCode
PageCode($oTemplate=null)
Definition: design.inc.php:91
CH_CATEG_ACTION_CALENDAR
const CH_CATEG_ACTION_CALENDAR
Definition: categories.php:11
CategoriesCalendarPage\getBlockCode_CategoriesDate
getBlockCode_CategoriesDate($iBlockId)
Definition: categories.php:187
CH_CATEG_ACTION_USERS
const CH_CATEG_ACTION_USERS
Definition: categories.php:10
$_page_cont
$_page_cont[$iNameIndex]['page_main_code']
Definition: categories.php:284
CategoriesCalendar\getEntriesNames
getEntriesNames()
Definition: categories.php:106
CategoriesSearchPage\getBlockCode_Founded
getBlockCode_Founded($iBlockId)
Definition: categories.php:263
ChTemplCalendar
Definition: ChTemplCalendar.php:14
CategoriesCalendarPage
Definition: categories.php:169
CategoriesSearchPage\__construct
__construct()
Definition: categories.php:211
$sContent
$sContent
Definition: categories.php:276
getPage_Calendar
getPage_Calendar()
Definition: categories.php:310
$sAction
$sAction
Definition: categories.php:274
CategoriesCalendar\display
display()
Definition: categories.php:61
ChWsbCalendar\$iWeekEnd
$iWeekEnd
Definition: ChWsbCalendar.php:51
DesignBoxContent
DesignBoxContent($title, $content, $db_num=0, $caption_item='', $bottom_item='')
Definition: design.inc.php:78
CH_CATEG_ACTION_COMMON
const CH_CATEG_ACTION_COMMON
Definition: categories.php:9
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbCalendar\$iYear
$iYear
Definition: ChWsbCalendar.php:50
ChWsbDb\getInstance
static getInstance()
Definition: ChWsbDb.php:82
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10