source: trunk/administration/menu_compose_admin.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 14.6 KB
Line 
1<?php
2
3/***************************************************************************
4* Dolphin Smart Community Builder
5* -----------------
6* begin : Mon Mar 23 2006
7* copyright : (C) 2006 BoonEx Group
8* website : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21/*
22 * Page for displaying and editing profile fields.
23 */
24require_once( '../inc/header.inc.php' );
25require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
26require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
27require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
28require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
29require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );
30require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
31
32// Check if administrator is logged in. If not display login form.
33$logged['admin'] = member_auth( 1, true, true );
34
35if( $_REQUEST['action'] ) {
36 switch( $_REQUEST['action'] ) {
37 case 'edit_form':
38 $id = (int)$_REQUEST['id'];
39
40 if( $id < 1000 ) {
41 $aItem = db_assoc_arr( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$id}'", 0 );
42 if( $aItem )
43 echo showEditFormCustom( $aItem );
44 else
45 echo echoMenuEditMsg( _t('_Error'), 'red' );
46 } else {
47 $id = $id - 1000;
48 $aItem = db_assoc_arr( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$id}' AND `parent_id`='0'", 0 );
49 if( $aItem )
50 echo showEditFormTop( $aItem );
51 else
52 echo echoMenuEditMsg( _t('_Error'), 'red' );
53 }
54 exit;
55 case 'create_item':
56 $newID = createNewElement( $_REQUEST['type'], (int)$_REQUEST['source'] );
57 echo $newID;
58 exit;
59 case 'deactivate_item':
60 $id = (int)$_REQUEST['id'];
61 if( $id > 1000 ) {
62 $id = $id - 1000;
63 db_res( "DELETE FROM `sys_menu_admin` WHERE `id`='{$id}' AND `parent_id`='0'" );
64 echo db_affected_rows();
65 } else
66 echo 1;
67 exit;
68 case 'save_item':
69 $id = (int)$_REQUEST['id'];
70 if( !$id ) {
71 $aResult = array('code' => 1, 'message' => _t('_Error occured'));
72 } else {
73 if( $id < 1000 ) {
74 $aItemFields = array( 'title', 'url', 'description', 'check', 'icon' );
75 $aItem = array();
76 foreach( $aItemFields as $field )
77 $aItem[$field] = $_REQUEST[$field];
78 } else {
79 $id = $id - 1000;
80 $aItemFields = array( 'title', 'icon', 'icon_large' );
81 $aItem = array();
82 foreach( $aItemFields as $field )
83 $aItem[$field] = $_REQUEST[$field];
84 }
85 $aResult = saveItem( $id, $aItem );
86 }
87 $aResult['message'] = MsgBox($aResult['message']);
88
89 $oJson = new Services_JSON();
90 echo $oJson->encode($aResult);
91 exit;
92 case 'delete_item':
93 $id = (int)$_REQUEST['id'];
94 if( !$id ) {
95 echo _t('_adm_mbuilder_Item_ID_not_specified');
96 exit;
97 }
98
99 if( $id > 1000 ) {
100 $id = $id - 1000;
101
102 db_res( "DELETE FROM `sys_menu_admin` WHERE `id` = '{$id}' AND `parent_id`='0'" );
103 } else {
104 db_res( "DELETE FROM `sys_menu_admin` WHERE `id` = '{$id}'" );
105 }
106
107 if( db_affected_rows() )
108 echo 'OK';
109 else
110 echo _t('_adm_mbuilder_Could_not_delete_the_item');
111 exit;
112 case 'save_orders':
113 $sTop = $_REQUEST['top'];
114 $aCustom = $_REQUEST['custom'];
115 saveOrders( $sTop, $aCustom );
116 echo 'OK';
117 exit;
118 }
119}
120
121$sTopQuery = "SELECT `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='0' ORDER BY `order`";
122$rTopItems = db_res( $sTopQuery );
123
124$sAllQuery = "SELECT `id`, `title` FROM `sys_menu_admin`";
125$rAllItems = db_res( $sAllQuery );
126
127$sAllTopQuery = "SELECT `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='0'";
128$rAllTopItems = db_res( $sAllTopQuery );
129
130$sComposerInit = "
131 <script type=\"text/javascript\">
132 topParentID = 'menu_app_wrapper';
133 urlIconLoading = '{$site['url_admin']}images/loading.gif';
134 parserUrl = '{$_SERVER['PHP_SELF']}?';
135
136 allowNewItem = true;
137 allowAddToTop = true;
138 allowAddToCustom = true;
139 iInactivePerRow = 7;
140 sendSystemOrder = false;
141
142 aCoords = {};
143 aCoords['startX'] = 270;
144 aCoords['startY'] = 235;
145 aCoords['width'] = 92;
146 aCoords['height'] = 21;
147 aCoords['diffX'] = 122;
148 aCoords['diffY'] = 32;
149
150 aTopItems = {};
151 aCustomItems = {};
152 aSystemItems = {};
153 aAllItems = {};
154";
155
156while( $aTopItem = mysql_fetch_assoc( $rTopItems ) ) {
157 $sTopestTitle = _t($aTopItem['title']);
158 $sComposerInit .= "
159
160 aTopItems[" . ( $aTopItem['id'] + 1000 ) . "] = '{$sTopestTitle}';
161 aCustomItems[" . ( $aTopItem['id'] + 1000 ) . "] = {};";
162 $sQuery = "SELECT `id`, `title` FROM `sys_menu_admin` WHERE `parent_id`='{$aTopItem['id']}' ORDER BY `order`";
163
164 $rCustomItems = db_res( $sQuery );
165 while( $aCustomItem = mysql_fetch_assoc( $rCustomItems ) ) {
166 $sCustomTitle = _t($aCustomItem['title']);
167 $sComposerInit .= "
168 aCustomItems[" . ( $aTopItem['id'] + 1000 ) . "][{$aCustomItem['id']}] = '{$sCustomTitle}';";
169 }
170}
171
172$sComposerInit .= "\n";
173while( $aAllTopItem = mysql_fetch_assoc( $rAllTopItems ) ) {
174 $sTopTitle = _t($aAllTopItem['title']);
175 $sComposerInit .= "
176 aAllItems[" . ( $aAllTopItem['id'] + 1000 ) . "] = '{$sTopTitle}';";
177}
178
179$sComposerInit .= "\n";
180while( $aAllItem = mysql_fetch_assoc( $rAllItems ) ) {
181 $sOrdTitle = _t($aAllItem['title']);
182 $sComposerInit .= "
183 aAllItems[{$aAllItem['id']}] = '{$sOrdTitle}';";
184}
185
186$sComposerInit .= "
187 </script>
188";
189
190$iNameIndex = 12;
191$_page = array(
192 'name_index' => $iNameIndex,
193 'css_name' => array('menu_compose.css', 'forms_adv.css'),
194 'js_name' => array('menu_compose.js', 'BxDolMenu.js'),
195 'header' => _t('_adm_ambuilder_title'),
196 'header_text' => _t('_adm_ambuilder_title')
197);
198$_page_cont[$iNameIndex]['page_main_code'] = $GLOBALS['oAdmTemplate']->parseHtmlByName('menu_compose.html', array(
199 'extra_js' => $sComposerInit,
200 'content' => getMainPageCode(),
201));
202
203PageCodeAdmin();
204
205// Functions
206function getMainPageCode() {
207 $sAdminUrl = BX_DOL_URL_ADMIN;
208 $sAllItemsC = _t('_adm_mbuilder_All_Items');
209 $sActiveItemsC = _t('_adm_mbuilder_Active_Items');
210
211 return <<<EOF
212 <div class="pseudo_wrapper">
213 <div class="pseudo_head">{$sActiveItemsC}</div>
214 <div id="pseudo1">
215 <img src="{$sAdminUrl}images/loading.gif" />
216 </div>
217 <div class="pseudo_head">{$sAllItemsC}</div>
218 <div id="pseudo2">
219 <img src="{$sAdminUrl}images/loading.gif" />
220 </div>
221 </div>
222EOF;
223}
224
225function showEditFormCustom( $aItem ) {
226 $aForm = array(
227 'form_attrs' => array(
228 'id' => 'formItemEdit',
229 'name' => 'formItemEdit',
230 'action' => $_SERVER['PHP_SELF'],
231 'method' => 'post',
232 'enctype' => 'multipart/form-data',
233 ),
234 'inputs' => array (
235 'Title' => array(
236 'type' => 'text',
237 'name' => 'title',
238 'caption' => _t('_Title'),
239 'value' => $aItem['title'],
240 'attrs' => array()
241 ),
242 'Url' => array(
243 'type' => 'text',
244 'name' => 'url',
245 'caption' => _t('_URL'),
246 'value' => $aItem['url'],
247 'attrs' => array()
248 ),
249 'Check' => array(
250 'type' => 'text',
251 'name' => 'check',
252 'caption' => _t('_adm_ambuilder_Check'),
253 'value' => htmlspecialchars_adv( $aItem['check'] ),
254 'attrs' => array()
255 ),
256 'Description' => array(
257 'type' => 'text',
258 'name' => 'description',
259 'caption' => _t('_Description'),
260 'value' => htmlspecialchars_adv( $aItem['description'] ),
261 'attrs' => array()
262 ),
263 'Icon' => array(
264 'type' => 'text',
265 'name' => 'Icon',
266 'caption' => _t('_adm_ambuilder_Icon'),
267 'value' => htmlspecialchars_adv( $aItem['icon'] ),
268 'attrs' => array()
269 ),
270 'submit' => array(
271 'type' => 'input_set',
272 array(
273 'type' => 'button',
274 'name' => 'save',
275 'value' => _t('_Save Changes'),
276 'attrs' => array(
277 'onclick' => 'javascript:saveItem(' . $aItem['id'] . ');'
278 )
279 ),
280 array(
281 'type' => 'button',
282 'name' => 'delete',
283 'value' => _t('_Delete'),
284 'attrs' => array(
285 'onclick' => 'javascript:deleteItem(' . $aItem['id'] . ');'
286 )
287 )
288 ),
289 )
290 );
291
292 $oForm = new BxTemplFormView($aForm);
293 return PopupBox('amc_edit_popup_custom', _t('_adm_mbuilder_edit_item'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . LoadingBox('formItemEditLoading'))));
294}
295
296function showEditFormTop( $aItem ) {
297 $aForm = array(
298 'form_attrs' => array(
299 'id' => 'formItemEdit',
300 'name' => 'formItemEdit',
301 'action' => $_SERVER['PHP_SELF'],
302 'method' => 'post',
303 'enctype' => 'multipart/form-data',
304 ),
305 'inputs' => array (
306 'Title' => array(
307 'type' => 'text',
308 'name' => 'title',
309 'caption' => _t('_Title'),
310 'value' => $aItem['title'],
311 'attrs' => array()
312 ),
313 'BigIcon' => array(
314 'type' => 'text',
315 'name' => 'icon',
316 'caption' => _t('_adm_ambuilder_Small_Icon'),
317 'value' => htmlspecialchars_adv( $aItem['icon'] ),
318 'attrs' => array()
319 ),
320 'SmallIcon' => array(
321 'type' => 'text',
322 'name' => 'icon_large',
323 'caption' => _t('_adm_ambuilder_Big_Icon'),
324 'value' => htmlspecialchars_adv( $aItem['icon_large'] ),
325 'attrs' => array()
326 ),
327 'submit' => array(
328 'type' => 'input_set',
329 array(
330 'type' => 'button',
331 'name' => 'save',
332 'value' => _t('_Save Changes'),
333 'attrs' => array(
334 'onclick' => 'javascript:saveItem(' . ($aItem['id'] + 1000) . ');'
335 )
336 ),
337 array(
338 'type' => 'button',
339 'name' => 'delete',
340 'value' => _t('_Delete'),
341 'attrs' => array(
342 'onclick' => 'javascript:deleteItem(' . ($aItem['id'] + 1000) . ');'
343 )
344 )
345 ),
346 )
347 );
348
349 $oForm = new BxTemplFormView($aForm);
350 return PopupBox('amc_edit_popup_top', _t('_adm_mbuilder_edit_item'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . LoadingBox('formItemEditLoading'))));
351}
352
353function createNewElement( $type, $source ) {
354 if( $source ) {
355 if( $type == 'top' and $source > 1000 ) {
356 $source = $source - 1000;
357
358 db_res( "
359 INSERT INTO `sys_menu_admin`
360 (`title`, `icon`, `icon_large`)
361 SELECT
362 `title`, `icon`, `icon_large`
363 FROM `sys_menu_admin`
364 WHERE `id` = '{$source}'
365 " );
366 $newID = db_last_id();
367 } elseif( $type == 'custom' and $source < 1000 ) {
368 $aItem = db_res( "SELECT * FROM `sys_menu_admin` WHERE `id` = '{$source}'" );
369
370 if( $aItem['parent_id'] == 0 )
371 $newID = $source;
372 else {
373 db_res( "
374 INSERT INTO `sys_menu_admin`
375 (`title`, `url`, `description`, `check`, `icon`)
376 SELECT
377 `title`, `url`, `description`, `check`, `icon`
378 FROM `sys_menu_admin`
379 WHERE `id` = '{$source}'
380 " );
381 $newID = db_last_id();
382 }
383 } elseif( $type == 'custom' and $source > 1000 ) {
384 $source = $source - 1000;
385
386 db_res( "
387 INSERT INTO `sys_menu_admin`
388 (`title`)
389 SELECT
390 `title`
391 FROM `sys_menu_admin`
392 WHERE `id` = '{$source}'
393 " );
394 $newID = db_last_id();
395 } elseif( $type == 'top' and $source < 1000 ) {
396 db_res( "
397 INSERT INTO `sys_menu_admin`
398 (`title`)
399 SELECT
400 `title`
401 FROM `sys_menu_admin`
402 WHERE `id` = '{$source}'
403 " );
404 $newID = db_last_id();
405 }
406 } else {
407 db_res( "INSERT INTO `sys_menu_admin` SET `title` = 'NEW ITEM'" );
408 $newID = db_last_id();
409 }
410 return $newID;
411}
412
413function echoMenuEditMsg( $text, $color = 'black' ) {
414 return <<<EOF
415<div onclick="hideEditForm();" style="color:{$color};text-align:center;">{$text}</div>
416EOF;
417}
418
419function saveItem( $id, $aItem ) {
420 $sSavedC = _t('_Saved');
421
422 $aOldItem = db_arr( "SELECT * FROM `sys_menu_admin` WHERE `id`='{$id}'" );
423
424 if( !$aOldItem )
425 return array('code' => 2, 'message' => _t('_Error') . ' ' . _t('_adm_mbuilder_Item_not_found'));
426
427 $sQuerySet = '';
428 foreach( $aItem as $field => $value )
429 $sQuerySet .= ", `{$field}`='" . process_db_input( $value ) ."'";
430
431 $sQuerySet = substr( $sQuerySet, 1 );
432
433 $sQuery = "UPDATE `sys_menu_admin` SET {$sQuerySet} WHERE `id` = '{$id}'";
434 db_res( $sQuery );
435
436 return array('code' => 0, 'message' => $sSavedC, 'timer' => 3);
437}
438
439function saveOrders( $sTop, $aCustom ) {
440 db_res( "UPDATE `sys_menu_admin` SET `order` = 0" );
441 db_res( "UPDATE `sys_menu_admin` SET `order` = 0, `parent_id` = 0" );
442
443 $sTop = trim( $sTop, ' ,' );
444 $aTopIDs = explode( ',', $sTop );
445 foreach( $aTopIDs as $iOrd => $iID ) {
446 $iID = trim( $iID, ' ,' );
447 $iID = (int)$iID;
448
449 if( !$iID )
450 continue;
451
452 $iID = $iID - 1000;
453
454 db_res( "UPDATE `sys_menu_admin` SET `order` = {$iOrd} WHERE `id` = '{$iID}'" );
455 }
456
457 foreach( $aCustom as $iParent => $sCustom ) {
458 $iParent = (int)$iParent;
459 $iParent = $iParent - 1000;
460
461 $sCustom = trim( $sCustom, ' ,' );
462 $aCustomIDs = explode( ',', $sCustom );
463
464 foreach( $aCustomIDs as $iOrd => $iID ) {
465 $iID = trim( $iID, ' ,' );
466 $iID = (int)$iID;
467
468 if( !$iID )
469 continue;
470
471 db_res( "UPDATE `sys_menu_admin` SET `order` = '{$iOrd}', `parent_id`='{$iParent}' WHERE `id` = '{$iID}'" );
472 }
473 }
474}
475
476?>
Note: See TracBrowser for help on using the repository browser.