source: trunk/administration/nav_menu_compose.php

Last change on this file was 2, checked in by george, 14 years ago
  • Přidáno: Trunk revize 13719.
File size: 15.4 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 */
24
25define ('BX_SECURITY_EXCEPTIONS', true);
26$aBxSecurityExceptions = array ();
27$aBxSecurityExceptions[] = 'POST.Link';
28$aBxSecurityExceptions[] = 'REQUEST.Link';
29
30require_once( '../inc/header.inc.php' );
31require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
32require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
33require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
34require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
35require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );
36require_once( BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php' );
37bx_import('BxDolMenu');
38
39// Check if administrator is logged in. If not display login form.
40$logged['admin'] = member_auth(1, true, true);
41
42$GLOBALS['oAdmTemplate']->addJsTranslation(array(
43 '_adm_mbuilder_Sorry_could_not_insert_object',
44 '_adm_mbuilder_This_items_are_non_editable'
45));
46
47$oMenu = new BxDolMenu();
48
49if( $_REQUEST['action'] ) {
50 switch( $_REQUEST['action'] ) {
51 case 'edit_form':
52 $id = (int)$_REQUEST['id'];
53
54 $aItem = db_assoc_arr( "SELECT * FROM `sys_menu_top` WHERE `ID` = '{$id}'", 0 );
55 if( $aItem )
56 echo showEditForm( $aItem );
57 else
58 echoMenuEditMsg( _t('_Error occured'), 'red' );
59 exit;
60 case 'create_item':
61 $newID = createNewElement( $_GET['type'], (int)$_GET['source'] );
62 echo $newID;
63 exit;
64 case 'deactivate_item':
65 $res = db_res( "UPDATE `sys_menu_top` SET `Active`=0 WHERE `ID`=" . (int)$_GET['id'] );
66 echo db_affected_rows();
67 $oMenu -> compile();
68 exit;
69 case 'save_item':
70 $id = (int)$_POST['id'];
71 if(!$id)
72 $aResult = array('code' => 1, 'message' => _t('_Error occured'));
73 else {
74 $aItemFields = array('Name', 'Caption', 'Link', 'Picture', 'Icon');
75 $aItem = array();
76 foreach( $aItemFields as $field )
77 $aItem[$field] = $_POST[$field];
78
79 $aVis = array();
80 if( (int)$_POST['Visible_non'] )
81 $aVis[] = 'non';
82 if( (int)$_POST['Visible_memb'] )
83 $aVis[] = 'memb';
84
85 $aItem['Visible'] = implode( ',', $aVis );
86 $aItem['BQuickLink'] = (int)$_POST['BInQuickLink'] ? '1' : '0';
87 $aItem['Target'] = $_POST['Target'] == '_blank' ? '_blank' : '';
88
89 $aResult = saveItem( $id, $aItem );
90 }
91
92 $aResult['message'] = MsgBox($aResult['message']);
93
94 $oJson = new Services_JSON();
95 echo $oJson->encode($aResult);
96 exit;
97 case 'delete_item':
98 $id = (int)$_GET['id'];
99 if( !$id ) {
100 echo _t('_adm_mbuilder_Item_ID_not_specified');
101 exit;
102 }
103
104 $aItem = db_arr( "SELECT `Deletable` FROM `sys_menu_top` WHERE `ID` = '{$id}'" );
105 if( !$aItem ) {
106 echo _t('_adm_mbuilder_Item_not_found');
107 exit;
108 }
109
110 if( !(int)$aItem['Deletable'] ) {
111 echo _t('_adm_mbuilder_Item_is_non_deletable');
112 exit;
113 }
114
115 db_res( "DELETE FROM `sys_menu_top` WHERE `ID` = $id" );
116 if( db_affected_rows() )
117 echo 'OK';
118 else
119 echo _t('_adm_mbuilder_Could_not_delete_the_item');
120 $oMenu -> compile();
121 exit;
122 case 'save_orders':
123 $sTop = $_GET['top'];
124 $aCustom = $_GET['custom'];
125 saveOrders( $sTop, $aCustom );
126 echo 'OK';
127 exit;
128 }
129}
130
131$sTopQuery = "SELECT `ID`, `Name` FROM `sys_menu_top` WHERE `Active`=1 AND `Type`='top' ORDER BY `Order`";
132$rTopItems = db_res( $sTopQuery );
133
134$sSysQuery = "SELECT `ID`, `Name` FROM `sys_menu_top` WHERE `Active`=1 AND `Type`='system' ORDER BY `Order`";
135$rSysItems = db_res( $sSysQuery );
136
137$sAllQuery = "SELECT `ID`, `Name` FROM `sys_menu_top` WHERE `Type`!='system'";
138$rAllItems = db_res( $sAllQuery );
139
140$sAdminUrl = BX_DOL_URL_ADMIN;
141
142$sComposerInit = "
143 <script type=\"text/javascript\">
144 <!--
145 topParentID = 'menu_app_wrapper';
146 urlIconLoading = '{$sAdminUrl}images/loading.gif';
147 parserUrl = '{$_SERVER['PHP_SELF']}?';
148
149 allowNewItem = true;
150 allowAddToTop = true;
151 allowAddToCustom = true;
152 iInactivePerRow = 7;
153 sendSystemOrder = false;
154
155 aCoords = {};
156 aCoords['startX'] = 290;
157 aCoords['startY'] = 235;
158 aCoords['width'] = 92;
159 aCoords['height'] = 21;
160 aCoords['diffX'] = 122;
161 aCoords['diffY'] = 32;
162
163 aTopItems = {};
164 aCustomItems = {};
165 aSystemItems = {};
166 aAllItems = {};
167";
168
169while( $aTopItem = mysql_fetch_assoc( $rTopItems ) ) {
170 $sComposerInit .= "
171
172 aTopItems[{$aTopItem['ID']}] = '" . addslashes( $aTopItem['Name'] ) . "';
173 aCustomItems[{$aTopItem['ID']}] = {};";
174 $sQuery = "SELECT `ID`, `Name` FROM `sys_menu_top` WHERE `Active`=1 AND `Type`='custom' AND `Parent`={$aTopItem['ID']} ORDER BY `Order`";
175
176 $rCustomItems = db_res( $sQuery );
177 while( $aCustomItem = mysql_fetch_assoc( $rCustomItems ) ) {
178 $sComposerInit .= "
179 aCustomItems[{$aTopItem['ID']}][{$aCustomItem['ID']}] = '" . addslashes( $aCustomItem['Name'] ) . "';";
180 }
181}
182
183while( $aSystemItem = mysql_fetch_assoc( $rSysItems ) ) {
184 $sComposerInit .= "
185
186 aSystemItems[{$aSystemItem['ID']}] = '" . addslashes( $aSystemItem['Name'] ) . "';
187 aCustomItems[{$aSystemItem['ID']}] = {};";
188 $sQuery = "SELECT `ID`, `Name` FROM `sys_menu_top` WHERE `Active`=1 AND `Type`='custom' AND `Parent`={$aSystemItem['ID']} ORDER BY `Order`";
189
190 $rCustomItems = db_res( $sQuery );
191 while( $aCustomItem = mysql_fetch_assoc( $rCustomItems ) ) {
192 $sComposerInit .= "
193 aCustomItems[{$aSystemItem['ID']}][{$aCustomItem['ID']}] = '" . addslashes( $aCustomItem['Name'] ) . "';";
194 }
195}
196
197$sComposerInit .= "\n";
198while( $aAllItem = mysql_fetch_assoc( $rAllItems ) ) {
199 $sComposerInit .= "
200 aAllItems[{$aAllItem['ID']}] = '" . addslashes( $aAllItem['Name'] ) . "';";
201}
202$sComposerInit .= "
203 -->
204 </script>";
205
206$iNameIndex = 12;
207$_page = array(
208 'name_index' => $iNameIndex,
209 'css_name' => array('menu_compose.css', 'forms_adv.css'),
210 'js_name' => array('menu_compose.js', 'BxDolMenu.js'),
211 'header' => _t('_adm_mbuilder_title'),
212 'header_text' => _t('_adm_mbuilder_title_box'),
213);
214
215$_page_cont[$iNameIndex]['controls'] = null;
216$_page_cont[$iNameIndex]['page_main_code'] = $GLOBALS['oAdmTemplate']->parseHtmlByName('menu_compose.html', array(
217 'extra_js' => $sComposerInit
218));
219
220PageCodeAdmin();
221
222// Functions
223function showEditForm($aItem) {
224 $aForm = array(
225 'form_attrs' => array(
226 'id' => 'formItemEdit',
227 'name' => 'formItemEdit',
228 'action' => $_SERVER['PHP_SELF'],
229 'method' => 'post',
230 'enctype' => 'multipart/form-data',
231 ),
232 'inputs' => array (
233 'Name' => array(
234 'type' => 'text',
235 'name' => 'Name',
236 'caption' => _t('_adm_mbuilder_System_Name'),
237 'value' => $aItem['Name'],
238 'attrs' => array()
239 ),
240 'Caption' => array(
241 'type' => 'text',
242 'name' => 'Caption',
243 'caption' => _t('_adm_mbuilder_Language_Key'),
244 'value' => $aItem['Caption'],
245 'attrs' => array()
246 ),
247 'LangCaption' => array(
248 'type' => 'text',
249 'name' => 'LangCaption',
250 'caption' => _t('_adm_mbuilder_Default_Name'),
251 'value' => _t( $aItem['Caption'] ),
252 'attrs' => array()
253 ),
254 'Link' => array(
255 'type' => 'text',
256 'name' => 'Link',
257 'caption' => _t('_URL'),
258 'value' => htmlspecialchars_adv( $aItem['Link'] ),
259 'attrs' => array()
260 ),
261 'Picture' => array(
262 'type' => 'text',
263 'name' => 'Picture',
264 'caption' => _t('_Picture'),
265 'value' => htmlspecialchars_adv( $aItem['Picture'] ),
266 'attrs' => array()
267 ),
268 'Icon' => array(
269 'type' => 'text',
270 'name' => 'Icon',
271 'caption' => _t('_adm_mbuilder_icon'),
272 'value' => htmlspecialchars_adv( $aItem['Icon'] ),
273 'attrs' => array()
274 ),
275 'BInQuickLink' => array(
276 'type' => 'checkbox',
277 'name' => 'BInQuickLink',
278 'caption' => _t('_adm_mbuilder_Quick_Link'),
279 'value' => 'on',
280 'checked' => $aItem['BQuickLink'] != 0,
281 'attrs' => array()
282 ),
283 'Target' => array(
284 'type' => 'radio_set',
285 'name' => 'Target',
286 'caption' => _t('_adm_mbuilder_Target_Window'),
287 'value' => $aItem['Target'] == '_blank' ? '_blank' : '_self',
288 'values' => array(
289 '_self' => _t('_adm_mbuilder_Same'),
290 '_blank' => _t('_adm_mbuilder_New')
291 ),
292 'attrs' => array()
293 ),
294 'Visible' => array(
295 'type' => 'checkbox_set',
296 'name' => 'Visible',
297 'caption' => _t('_adm_mbuilder_Visible_for'),
298 'value' => array(),
299 'values' => array(
300 'non' => _t('_Guest'),
301 'memb' => _t('_Member')
302 ),
303 'attrs' => array()
304 ),
305 'submit' => array(
306 'type' => 'input_set',
307 array(
308 'type' => 'button',
309 'name' => 'save',
310 'value' => _t('_Save Changes'),
311 'attrs' => array(
312 'onclick' => 'javascript:saveItem(' . $aItem['ID'] . ');'
313 )
314 ),
315 array(
316 'type' => 'button',
317 'name' => 'delete',
318 'value' => _t('_Delete'),
319 'attrs' => array(
320 'onclick' => 'javascript:deleteItem(' . $aItem['ID'] . ');'
321 )
322 )
323 ),
324 )
325 );
326
327 foreach($aForm['inputs'] as $sKey => $aInput)
328 if(in_array($aInput['type'], array('text', 'checkbox')) && !$aItem['Editable'])
329 $aForm['inputs'][$sKey]['attrs']['disabled'] = "disabled";
330
331 if(strpos($aItem['Visible'], 'non') !== false)
332 $aForm['inputs']['Visible']['value'][] = 'non';
333 if(strpos($aItem['Visible'], 'memb') !== false)
334 $aForm['inputs']['Visible']['value'][] = 'memb';
335
336 $oForm = new BxTemplFormView($aForm);
337 return PopupBox('tmc_edit_popup', _t('_adm_mbuilder_edit_item'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $oForm->getCode() . LoadingBox('formItemEditLoading'))));
338}
339
340function createNewElement( $type, $source ) {
341 global $oMenu;
342
343 if( $source ) {
344 $sourceActive = db_value( "SELECT `Active` FROM `sys_menu_top` WHERE `ID`='{$source}'" );
345 if( !$sourceActive ) {
346 //convert to active
347 db_res( "UPDATE `sys_menu_top` SET `Active`=1, `Type`='{$type}' WHERE `ID`='{$source}'" );
348 $newID = $source;
349 } else {
350 //create from source
351 db_res( "INSERT INTO `sys_menu_top`
352 ( `Name`, `Caption`, `Link`, `Visible`, `Target`, `Onclick`, `Check`, `Type` )
353 SELECT
354 `Name`, `Caption`, `Link`, `Visible`, `Target`, `Onclick`, `Check`, '{$type}'
355 FROM `sys_menu_top`
356 WHERE `ID`='{$source}'" );
357 $newID = db_last_id();
358 }
359 } else {
360 //create new
361 db_res( "INSERT INTO `sys_menu_top` ( `Name`, `Type` ) VALUES ( 'NEW ITEM', '{$type}' )" );
362 $newID = db_last_id();
363 }
364
365 $oMenu -> compile();
366 return $newID;
367}
368
369function echoMenuEditMsg( $text, $color = 'black' ) {
370 echo <<<EOF
371<div onclick="hideEditForm();" style="color:{$color};text-align:center;">{$text}</div>
372<script type="text/javascript">setTimeout( 'hideEditForm();', 1000 )</script>
373EOF;
374}
375
376function saveItem( $id, $aItem ) {
377 global $oMenu;
378
379 $sSavedC = _t('_Saved');
380 $sItemNotFoundC = _t('_adm_mbuilder_Item_not_found');
381 $sItemNonEditableC = _t('_adm_mbuilder_Item_is_non_editable');
382
383 $aOldItem = db_arr( "SELECT * FROM `sys_menu_top` WHERE `ID`='{$id}'" );
384
385 if(!$aOldItem)
386 return array('code' => 2, 'message' => $sItemNotFoundC);
387
388 if((int)$aOldItem['Editable'] != 1)
389 return array('code' => 3, 'message' => $sItemNonEditableC);
390
391 $sQuerySet = '';
392 foreach( $aItem as $field => $value )
393 $sQuerySet .= ", `{$field}`='" . process_db_input( $value ) ."'";
394
395 $sQuerySet = substr( $sQuerySet, 1 );
396
397 $sQuery = "UPDATE `sys_menu_top` SET {$sQuerySet} WHERE `ID` = '{$id}'";
398
399 db_res( $sQuery );
400 $oMenu -> compile();
401
402 return array('code' => 0, 'message' => $sSavedC, 'timer' => 3);
403}
404
405function updateLangFile( $key, $string ) {
406 $langName = getParam( 'lang_default' );
407 $langID = db_value( "SELECT `ID` FROM `sys_localization_languages` WHERE `Name` = '" . addslashes( $langName ) . "'" );
408
409 $keyID = db_value( "SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = '" . process_db_input( $key ) . "'" );
410 if( $keyID ) {
411 db_res( "UPDATE `sys_localization_strings` SET `String` = '" .process_db_input( $string ) . "' WHERE `IDKey`='{$keyID}' AND `IDLanguage`='{$langID}'" );
412 } else {
413 db_res( "INSERT INTO `sys_localization_keys` SET `IDCategory` = 2, `Key` = '" . process_db_input( $key ) . "'" );
414 db_res( "INSERT INTO `sys_localization_strings` SET `IDKey` = " . db_last_id() . ", `IDLanguage` = '{$langID}', `String` = '" .process_db_input( $string ) . "'" );
415 }
416
417 compileLanguage($langID);
418}
419
420function saveOrders( $sTop, $aCustom ) {
421 global $oMenu;
422
423 db_res( "UPDATE `sys_menu_top` SET `Order` = 0, `Parent` = 0" );
424
425 $sTop = trim( $sTop, ' ,' );
426 $aTopIDs = explode( ',', $sTop );
427 foreach( $aTopIDs as $iOrd => $iID ) {
428 $iID = trim( $iID, ' ,' );
429 $iID = (int)$iID;
430
431 if( !$iID )
432 continue;
433
434 db_res( "UPDATE `sys_menu_top` SET `Order` = '{$iOrd}', `Type` = 'top' WHERE `ID` = '{$iID}'" );
435 }
436
437 foreach( $aCustom as $iParent => $sCustom ) {
438 $iParent = (int)$iParent;
439 $sCustom = trim( $sCustom, ' ,' );
440 $aCustomIDs = explode( ',', $sCustom );
441 foreach( $aCustomIDs as $iOrd => $iID ) {
442 $iID = trim( $iID, ' ,' );
443 $iID = (int)$iID;
444
445 if( !$iID )
446 continue;
447
448 db_res( "UPDATE `sys_menu_top` SET `Order` = '{$iOrd}', `Type` = 'custom', `Parent`='{$iParent}' WHERE `ID` = '{$iID}'" );
449 }
450 }
451 $oMenu -> compile();
452}
453
454?>
Note: See TracBrowser for help on using the repository browser.