Cheetah
menu_compose_admin.php
Go to the documentation of this file.
1 <?php
2 
8 /*
9  * Page for displaying and editing profile fields.
10  */
11 require_once( '../inc/header.inc.php' );
12 require_once( CH_DIRECTORY_PATH_INC . 'profiles.inc.php' );
13 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
14 require_once( CH_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
15 require_once( CH_DIRECTORY_PATH_INC . 'utils.inc.php' );
16 require_once( CH_DIRECTORY_PATH_INC . 'languages.inc.php' );
17 
18 // Check if administrator is logged in. If not display login form.
19 $logged['admin'] = member_auth( 1, true, true );
20 
21 if(ch_get('action') !== false) {
22  switch(ch_get('action')) {
23  case 'edit_form':
24  $id = (int)ch_get('id');
25 
26  if( $id < 1000 ) {
27  $aItem = db_assoc_arr( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$id}'", 0 );
28  if( $aItem )
29  echo showEditFormCustom( $aItem );
30  else
31  echo echoMenuEditMsg( _t('_Error'), 'red' );
32  } else {
33  $id = $id - 1000;
34  $aItem = db_assoc_arr( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$id}' AND `parent_id`='0'", 0 );
35  if( $aItem )
36  echo showEditFormTop( $aItem );
37  else
38  echo echoMenuEditMsg( _t('_Error'), 'red' );
39  }
40  exit;
41  case 'create_item':
42  $newID = createNewElement($_POST['type'], (int)$_POST['source']);
43  echo $newID;
44  exit;
45  case 'deactivate_item':
46  $id = (int)ch_get('id');
47  if( $id > 1000 ) {
48  $id = $id - 1000;
49  $res = db_res( "DELETE FROM `sys_menu_admin` WHERE `id`='{$id}' AND `parent_id`='0'" );
50  echo db_affected_rows($res);
51  } else
52  echo 1;
53  exit;
54  case 'save_item':
55  $id = (int)$_POST['id'];
56  if( !$id ) {
57  $aResult = array('code' => 1, 'message' => _t('_Error occured'));
58  } else {
59  if( $id < 1000 ) {
60  $aItemFields = array( 'title', 'url', 'description', 'check', 'icon' );
61  $aItem = array();
62  foreach( $aItemFields as $field )
63  $aItem[$field] = $_POST[$field];
64  } else {
65  $id = $id - 1000;
66  $aItemFields = array( 'title', 'icon', 'icon_large' );
67  $aItem = array();
68  foreach( $aItemFields as $field )
69  $aItem[$field] = $_POST[$field];
70  }
71  $aResult = saveItem( $id, $aItem );
72  }
73  $aResult['message'] = MsgBox($aResult['message']);
74 
75  echo json_encode($aResult);
76  exit;
77  case 'delete_item':
78  $id = (int)$_POST['id'];
79  if( !$id ) {
80  echo _t('_adm_mbuilder_Item_ID_not_specified');
81  exit;
82  }
83 
84  if( $id > 1000 ) {
85  $id = $id - 1000;
86 
87  $res = db_res( "DELETE FROM `sys_menu_admin` WHERE `id` = '{$id}' AND `parent_id`='0'" );
88  } else {
89  $res = db_res( "DELETE FROM `sys_menu_admin` WHERE `id` = '{$id}'" );
90  }
91 
92  if( db_affected_rows($res) )
93  echo 'OK';
94  else
95  echo _t('_adm_mbuilder_Could_not_delete_the_item');
96  exit;
97  case 'save_orders':
98  saveOrders(ch_get('top'), ch_get('custom'));
99  echo 'OK';
100  exit;
101  }
102 }
103 
104 $sTopQuery = "SELECT `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='0' ORDER BY `order`";
106 
107 $sAllTopQuery = "SELECT * FROM (SELECT `id` + 1000 AS `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='0' UNION SELECT `id`, `title` FROM `sys_menu_admin`) AS `t`";
108 $aAllTopItems = $GLOBALS['MySQL']->getPairs($sAllTopQuery, 'id', 'title');
109 
111  <script type=\"text/javascript\">
112  topParentID = 'menu_app_wrapper';
113  parserUrl = '" . $GLOBALS['site']['url_admin'] . "menu_compose_admin.php?';
114 
115  allowNewItem = true;
116  allowAddToTop = true;
117  allowAddToCustom = true;
118  iInactivePerRow = 7;
119  sendSystemOrder = false;
120 
121  aCoords = {};
122  aCoords['startX'] = 6;
123  aCoords['startY'] = 24;
124  aCoords['width'] = 117;
125  aCoords['height'] = 28;
126  aCoords['diffX'] = 122;
127  aCoords['diffY'] = 32;
128 
129  aTopItems = {};
130  aCustomItems = {};
131  aSystemItems = {};
132  aAllItems = {};
133 ";
134 
136 while(($aTopItem = $rTopItems->fetch()) !== false) {
137  $sTopestTitle = ch_js_string(_t($aTopItem['title']), CH_ESCAPE_STR_APOS);
138  $sComposerInit .= "
139 
140  aTopItems[$iIndex] = [" . ($aTopItem['id'] + 1000) . ", '{$sTopestTitle}', 3];
141  aCustomItems[$iIndex] = {};";
142  $sQuery = "SELECT `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='{$aTopItem['id']}' ORDER BY `order`";
143 
144  $iSubIndex = 0;
145  $rCustomItems = db_res( $sQuery );
146  while(($aCustomItem = $rCustomItems->fetch()) !== false) {
147  $sCustomTitle = ch_js_string(_t($aCustomItem['title']), CH_ESCAPE_STR_APOS);
148  $sComposerInit .= "
149  aCustomItems[$iIndex][" . ($iSubIndex++) . "] = [{$aCustomItem['id']}, '{$sCustomTitle}', 3];";
150  }
151 
152  $iIndex++;
153 }
154 
155 $sComposerInit .= "\n";
156 
157 foreach ($aAllTopItems as $iId => $sLangKey)
158  $aAllTopItems[$iId] = _t($sLangKey);
159 
160 asort($aAllTopItems);
161 
162 foreach ($aAllTopItems as $iId => $sTitle) {
163  $sTopTitle = ch_js_string($sTitle, CH_ESCAPE_STR_APOS);
164  $sComposerInit .= "
165  aAllItems['{$iId} '] = '{$sTopTitle}';";
166 }
167 
168 $sComposerInit .= "
169  </script>
170 ";
171 
173 $_page = array(
174  'name_index' => $iNameIndex,
175  'css_name' => array('menu_compose.css', 'forms_adv.css'),
176  'js_name' => array('menu_compose.js', 'ChWsbMenu.js'),
177  'header' => _t('_adm_ambuilder_title')
178 );
179 
180 $sContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('menu_compose.html', array(
181  'extra_js' => $sComposerInit
182 ));
183 
184 $_page_cont[$iNameIndex]['page_main_code'] = DesignBoxAdmin(_t('_adm_ambuilder_title'), $sContent);
185 
186 PageCodeAdmin();
187 
188 // Functions
189 function showEditFormCustom( $aItem )
190 {
191  $aForm = array(
192  'form_attrs' => array(
193  'id' => 'formItemEdit',
194  'name' => 'formItemEdit',
195  'action' => $GLOBALS['site']['url_admin'] . 'menu_compose_admin.php',
196  'method' => 'post',
197  'enctype' => 'multipart/form-data',
198  ),
199  'inputs' => array (
200  'Title' => array(
201  'type' => 'text',
202  'name' => 'title',
203  'caption' => _t('_Title'),
204  'value' => $aItem['title'],
205  'attrs' => array()
206  ),
207  'Url' => array(
208  'type' => 'text',
209  'name' => 'url',
210  'caption' => _t('_URL'),
211  'value' => $aItem['url'],
212  'attrs' => array()
213  ),
214  'Check' => array(
215  'type' => 'text',
216  'name' => 'check',
217  'caption' => _t('_adm_ambuilder_Check'),
218  'value' => htmlspecialchars_adv( $aItem['check'] ),
219  'attrs' => array()
220  ),
221  'Description' => array(
222  'type' => 'text',
223  'name' => 'description',
224  'caption' => _t('_Description'),
225  'value' => htmlspecialchars_adv( $aItem['description'] ),
226  'attrs' => array()
227  ),
228  'Icon' => array(
229  'type' => 'text',
230  'name' => 'icon',
231  'caption' => _t('_adm_ambuilder_Icon'),
232  'value' => htmlspecialchars_adv( $aItem['icon'] ),
233  'attrs' => array()
234  ),
235  'submit' => array(
236  'type' => 'input_set',
237  array(
238  'type' => 'button',
239  'name' => 'save',
240  'value' => _t('_Save Changes'),
241  'attrs' => array(
242  'onclick' => 'javascript:saveItem(' . $aItem['id'] . ');'
243  )
244  ),
245  array(
246  'type' => 'button',
247  'name' => 'delete',
248  'value' => _t('_Delete'),
249  'attrs' => array(
250  'onclick' => 'javascript:deleteItem(' . $aItem['id'] . ');'
251  )
252  )
253  ),
254  )
255  );
256 
258  return PopupBox('amc_edit_popup_custom', _t('_adm_mbuilder_edit_item'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . LoadingBox('formItemEditLoading'))));
259 }
260 
261 function showEditFormTop( $aItem )
262 {
263  $aForm = array(
264  'form_attrs' => array(
265  'id' => 'formItemEdit',
266  'name' => 'formItemEdit',
267  'action' => $GLOBALS['site']['url_admin'] . 'menu_compose_admin.php',
268  'method' => 'post',
269  'enctype' => 'multipart/form-data',
270  ),
271  'inputs' => array (
272  'Title' => array(
273  'type' => 'text',
274  'name' => 'title',
275  'caption' => _t('_Title'),
276  'value' => $aItem['title'],
277  'attrs' => array()
278  ),
279  'BigIcon' => array(
280  'type' => 'text',
281  'name' => 'icon',
282  'caption' => _t('_adm_ambuilder_Small_Icon'),
283  'value' => htmlspecialchars_adv( $aItem['icon'] ),
284  'attrs' => array()
285  ),
286  'SmallIcon' => array(
287  'type' => 'text',
288  'name' => 'icon_large',
289  'caption' => _t('_adm_ambuilder_Big_Icon'),
290  'value' => htmlspecialchars_adv( $aItem['icon_large'] ),
291  'attrs' => array()
292  ),
293  'submit' => array(
294  'type' => 'input_set',
295  array(
296  'type' => 'button',
297  'name' => 'save',
298  'value' => _t('_Save Changes'),
299  'attrs' => array(
300  'onclick' => 'javascript:saveItem(' . ($aItem['id'] + 1000) . ');'
301  )
302  ),
303  array(
304  'type' => 'button',
305  'name' => 'delete',
306  'value' => _t('_Delete'),
307  'attrs' => array(
308  'onclick' => 'javascript:deleteItem(' . ($aItem['id'] + 1000) . ');'
309  )
310  )
311  ),
312  )
313  );
314 
316  return PopupBox('amc_edit_popup_top', _t('_adm_mbuilder_edit_item'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . LoadingBox('formItemEditLoading'))));
317 }
318 
319 function createNewElement( $type, $source )
320 {
321  if( $source ) {
322  if( $type == 'top' and $source > 1000 ) {
323  $source = $source - 1000;
324 
325  db_res( "
326  INSERT INTO `sys_menu_admin`
327  (`title`, `icon`, `icon_large`)
328  SELECT
329  `title`, `icon`, `icon_large`
330  FROM `sys_menu_admin`
331  WHERE `id` = '{$source}'
332  " );
333  $newID = db_last_id();
334  } elseif( $type == 'custom' and $source < 1000 ) {
335  $aItem = db_res( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$source}'" );
336 
337  if( $aItem['parent_id'] == 0 )
338  $newID = $source;
339  else {
340  db_res( "
341  INSERT INTO `sys_menu_admin`
342  (`title`, `url`, `description`, `check`, `icon`)
343  SELECT
344  `title`, `url`, `description`, `check`, `icon`
345  FROM `sys_menu_admin`
346  WHERE `id` = '{$source}'
347  " );
348  $newID = db_last_id();
349  }
350  } elseif( $type == 'custom' and $source > 1000 ) {
351  $source = $source - 1000;
352 
353  db_res( "
354  INSERT INTO `sys_menu_admin`
355  (`title`)
356  SELECT
357  `title`
358  FROM `sys_menu_admin`
359  WHERE `id` = '{$source}'
360  " );
361  $newID = db_last_id();
362  } elseif( $type == 'top' and $source < 1000 ) {
363  db_res( "
364  INSERT INTO `sys_menu_admin`
365  (`title`)
366  SELECT
367  `title`
368  FROM `sys_menu_admin`
369  WHERE `id` = '{$source}'
370  " );
371  $newID = db_last_id();
372  }
373  } else {
374  db_res( "INSERT INTO `sys_menu_admin` SET `title` = 'NEW ITEM'" );
375  $newID = db_last_id();
376  }
377  return $newID;
378 }
379 
380 function echoMenuEditMsg( $text, $color = 'black' )
381 {
382  return <<<EOF
383 <div onclick="hideEditForm();" style="color:{$color};text-align:center;">{$text}</div>
384 EOF;
385 }
386 
387 function saveItem( $id, $aItem )
388 {
389  $sSavedC = _t('_Saved');
390 
391  $aOldItem = db_arr( "SELECT * FROM `sys_menu_admin` WHERE `id`='{$id}'" );
392 
393  if( !$aOldItem )
394  return array('code' => 2, 'message' => _t('_Error') . ' ' . _t('_adm_mbuilder_Item_not_found'));
395 
396  $sQuerySet = '';
397  foreach( $aItem as $field => $value )
398  $sQuerySet .= ", `{$field}`='" . process_db_input( $value ) ."'";
399 
400  $sQuerySet = substr( $sQuerySet, 1 );
401 
402  $sQuery = "UPDATE `sys_menu_admin` SET {$sQuerySet} WHERE `id` = '{$id}'";
403  db_res( $sQuery );
404 
405  return array('code' => 0, 'message' => $sSavedC, 'timer' => 3);
406 }
407 
408 function saveOrders( $sTop, $aCustom )
409 {
410  db_res( "UPDATE `sys_menu_admin` SET `order` = 0, `parent_id` = 0" );
411 
412  $sTop = trim( $sTop, ' ,' );
413  $aTopIDs = explode( ',', $sTop );
414  foreach( $aTopIDs as $iOrd => $iID ) {
415  $iID = trim( $iID, ' ,' );
416  $iID = (int)$iID;
417 
418  if( !$iID )
419  continue;
420 
421  $iID = $iID - 1000;
422 
423  db_res( "UPDATE `sys_menu_admin` SET `order` = {$iOrd} WHERE `id` = '{$iID}'" );
424  }
425 
426  foreach( $aCustom as $iParent => $sCustom ) {
427  $iParent = (int)$iParent;
428  $iParent = $iParent - 1000;
429 
430  $sCustom = trim( $sCustom, ' ,' );
431  $aCustomIDs = explode( ',', $sCustom );
432 
433  foreach( $aCustomIDs as $iOrd => $iID ) {
434  $iID = trim( $iID, ' ,' );
435  $iID = (int)$iID;
436 
437  if( !$iID )
438  continue;
439 
440  if($iID > 1000)
441  $iID -= 1000;
442 
443  db_res( "UPDATE `sys_menu_admin` SET `order` = '{$iOrd}', `parent_id`='{$iParent}' WHERE `id` = '{$iID}'" );
444  }
445  }
446 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
$sContent
$sContent
Definition: menu_compose_admin.php:180
echoMenuEditMsg
echoMenuEditMsg( $text, $color='black')
Definition: menu_compose_admin.php:380
ChTemplFormView
Definition: ChTemplFormView.php:11
db_assoc_arr
db_assoc_arr($query, $bindings=[])
Definition: db.inc.php:86
LoadingBox
LoadingBox($sName)
Definition: design.inc.php:185
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
showEditFormCustom
showEditFormCustom( $aItem)
Definition: menu_compose_admin.php:189
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
$sAllTopQuery
$sAllTopQuery
Definition: menu_compose_admin.php:107
$aResult
$aResult
Definition: index.php:19
$aAllTopItems
$aAllTopItems
Definition: menu_compose_admin.php:108
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
php
$iId
$iId
Definition: license.php:15
$sTopQuery
if(ch_get('action') !==false) $sTopQuery
Definition: menu_compose_admin.php:104
saveItem
saveItem( $id, $aItem)
Definition: menu_compose_admin.php:387
$oForm
$oForm
Definition: host_tools.php:42
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
db_arr
db_arr($query, $bindings=[])
Definition: db.inc.php:76
exit
exit
Definition: cart.php:21
and
and
Definition: license.txt:18
$sTitle
$sTitle
Definition: actions.inc.php:13
htmlspecialchars_adv
htmlspecialchars_adv($string)
Definition: utils.inc.php:302
db_last_id
db_last_id()
Definition: db.inc.php:47
$iNameIndex
$iNameIndex
Definition: menu_compose_admin.php:172
$rTopItems
$rTopItems
Definition: menu_compose_admin.php:105
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
$logged
$logged['admin']
Definition: menu_compose_admin.php:19
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
db_affected_rows
db_affected_rows($oStmt=null)
Definition: db.inc.php:56
CH_ESCAPE_STR_APOS
const CH_ESCAPE_STR_APOS
escape apostrophes only, for js strings enclosed in apostrophes, for use in
Definition: utils.inc.php:33
$iIndex
$iIndex
Definition: menu_compose_admin.php:135
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
PopupBox
PopupBox($sName, $sTitle, $sContent, $aActions=array())
Definition: design.inc.php:189
$sComposerInit
$sComposerInit
Definition: menu_compose_admin.php:110
createNewElement
createNewElement( $type, $source)
Definition: menu_compose_admin.php:319
$_page_cont
$_page_cont[$iNameIndex]['page_main_code']
Definition: menu_compose_admin.php:184
$aForm
$aForm
Definition: forgot.php:43
saveOrders
saveOrders( $sTop, $aCustom)
Definition: menu_compose_admin.php:408
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
showEditFormTop
showEditFormTop( $aItem)
Definition: menu_compose_admin.php:261
$_page
$_page
Definition: menu_compose_admin.php:173
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10