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 | require_once( '../inc/header.inc.php' );
|
---|
22 | require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
|
---|
23 | require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
|
---|
24 |
|
---|
25 | $logged['admin'] = member_auth( 1, true, true );
|
---|
26 |
|
---|
27 | $_page['extraCodeInHead'] = <<<EOJ
|
---|
28 | <script type="text/javascript" src="{$site['plugins']}jquery/jquery.js"></script>
|
---|
29 | EOJ;
|
---|
30 |
|
---|
31 | $aFields = array(
|
---|
32 | 'Value' => 'The value stored in the database',
|
---|
33 | 'LKey' => 'Primary language key used for displaying',
|
---|
34 | 'LKey2' => 'Secondary language key used for displaying in some other places',
|
---|
35 | 'LKey3' => 'Miscelaniuos language key used for displaying in some other places.',
|
---|
36 | 'Extra' => 'Extra parameter. Used for example as link to profile image for Sex list.',
|
---|
37 | 'Extra2' => 'Miscelanious extra parameter',
|
---|
38 | 'Extra3' => 'Miscelanious extra parameter'
|
---|
39 | );
|
---|
40 |
|
---|
41 | if( isset( $_REQUEST['popup'] ) and $_REQUEST['popup'] == 1 ) {
|
---|
42 | $iAmInPopup = true;
|
---|
43 |
|
---|
44 | $iNameIndex = 17;
|
---|
45 | $_page = array(
|
---|
46 | 'name_index' => $iNameIndex,
|
---|
47 | 'css_name' => array('predefined_values.css'),
|
---|
48 | 'js_name' => array(),
|
---|
49 | 'header' => _t('_adm_page_cpt_pvalues_manage'),
|
---|
50 | 'header_text' => _t('_adm_box_cpt_pvalues_manage'),
|
---|
51 | );
|
---|
52 | $_page_cont[$iNameIndex]['page_main_code'] = PageCompPageMainCode();
|
---|
53 | } else {
|
---|
54 | $iAmInPopup = false;
|
---|
55 |
|
---|
56 | $iNameIndex = 0;
|
---|
57 | $_page = array(
|
---|
58 | 'name_index' => $iNameIndex,
|
---|
59 | 'css_name' => array('predefined_values.css'),
|
---|
60 | 'js_name' => array(),
|
---|
61 | 'header' => _t('_adm_page_cpt_pvalues_manage'),
|
---|
62 | 'header_text' => _t('_adm_box_cpt_pvalues_manage'),
|
---|
63 | );
|
---|
64 | $_page_cont[$iNameIndex]['page_main_code'] = PageCompPageMainCode();
|
---|
65 | }
|
---|
66 |
|
---|
67 | PageCodeAdmin();
|
---|
68 |
|
---|
69 | function PageCompPageMainCode() {
|
---|
70 | global $iAmInPopup;
|
---|
71 | global $aFields;
|
---|
72 |
|
---|
73 | $sDeleteIcon = $GLOBALS['oAdmTemplate']->getImageUrl('minus1.gif');
|
---|
74 | $sUpIcon = $GLOBALS['oAdmTemplate']->getImageUrl('arrow_up.gif');
|
---|
75 | $sDownIcon = $GLOBALS['oAdmTemplate']->getImageUrl('arrow_down.gif');
|
---|
76 |
|
---|
77 | $sPopupAdd = $iAmInPopup ? '&popup=1' : '';
|
---|
78 | $sResultMsg = '';
|
---|
79 |
|
---|
80 | if( isset( $_POST['action'] ) and $_POST['action'] == 'Save' and isset( $_POST['PreList'] ) and is_array( $_POST['PreList'] ) ) {
|
---|
81 | if (true === saveList( $_POST['list'], $_POST['PreList'] ))
|
---|
82 | $sResultMsg = _t('_Success');
|
---|
83 | else
|
---|
84 | $sResultMsg = _t('_Failed to apply changes');
|
---|
85 | }
|
---|
86 |
|
---|
87 | //get lists
|
---|
88 | $aLists = array( '' => '- Select -' );
|
---|
89 | $sQuery = "SELECT DISTINCT `Key` FROM `sys_pre_values`";
|
---|
90 | $rLists = db_res( $sQuery );
|
---|
91 | while( $aList = mysql_fetch_assoc( $rLists ) ) {
|
---|
92 | $aLists[ $aList['Key'] ] = $aList['Key'];
|
---|
93 | }
|
---|
94 |
|
---|
95 | if( isset( $_REQUEST['list'] ) ) {
|
---|
96 | $sList_db = process_db_input( $_REQUEST['list'] );
|
---|
97 | $sList = process_pass_data( $_REQUEST['list'] );
|
---|
98 |
|
---|
99 | $sQuery = "SELECT * FROM `sys_pre_values` WHERE `Key` = '$sList_db' ORDER BY `Order`";
|
---|
100 | $rValues = db_res( $sQuery );
|
---|
101 |
|
---|
102 | if( !mysql_num_rows( $rValues ) ) //if no rows returned...
|
---|
103 | $aLists[ $sList ] = $sList; //create new list
|
---|
104 | } else {
|
---|
105 | $sList = '';
|
---|
106 | }
|
---|
107 |
|
---|
108 | ob_start();
|
---|
109 |
|
---|
110 | if ($sResultMsg)
|
---|
111 | echo MsgBox($sResultMsg);
|
---|
112 | ?>
|
---|
113 | <script type="text/javascript">
|
---|
114 | function createNewList() {
|
---|
115 | var sNewList = prompt( 'Please enter name of new list' );
|
---|
116 |
|
---|
117 | if( sNewList == null )
|
---|
118 | return false;
|
---|
119 |
|
---|
120 | sNewList = $.trim( sNewList );
|
---|
121 |
|
---|
122 | if( !sNewList.length ) {
|
---|
123 | alert( 'You should enter correct name' );
|
---|
124 | return false;
|
---|
125 | }
|
---|
126 |
|
---|
127 | window.location = '<?= $_SERVER['PHP_SELF'] ?>?list=' + encodeURIComponent( sNewList ) + '<?= $sPopupAdd ?>';
|
---|
128 | }
|
---|
129 |
|
---|
130 | function addRow( eImg ) {
|
---|
131 |
|
---|
132 | $( eImg ).parent().parent().before(
|
---|
133 | '<tr>' +
|
---|
134 | <?
|
---|
135 | foreach( $aFields as $sField => $sHelp ) {
|
---|
136 | ?>
|
---|
137 | '<td><input type="text" class="value_input" name="PreList[' + iNextInd + '][<?= $sField ?>]" value="" /></td>' +
|
---|
138 | <?
|
---|
139 | }
|
---|
140 | ?>
|
---|
141 | '<th>' +
|
---|
142 | '<img src="<?= $sDeleteIcon ?>" class="row_control" title="Delete" alt="Delete" onclick="delRow( this );" />' +
|
---|
143 | '<img src="<?= $sUpIcon ?>" class="row_control" title="Move up" alt="Move up" onclick="moveUpRow( this );" />' +
|
---|
144 | '<img src="<?= $sDownIcon ?>" class="row_control" title="Move down" alt="Move down" onclick="moveDownRow( this );" />' +
|
---|
145 | '</th>' +
|
---|
146 | '</tr>'
|
---|
147 | );
|
---|
148 |
|
---|
149 | iNextInd ++;
|
---|
150 |
|
---|
151 | sortZebra();
|
---|
152 | }
|
---|
153 |
|
---|
154 | function delRow( eImg ) {
|
---|
155 | $( eImg ).parent().parent().remove();
|
---|
156 | sortZebra();
|
---|
157 | }
|
---|
158 |
|
---|
159 | function moveUpRow( eImg ) {
|
---|
160 | var oCur = $( eImg ).parent().parent();
|
---|
161 | var oPrev = oCur.prev( ':not(.headers)' );
|
---|
162 | if( !oPrev.length )
|
---|
163 | return;
|
---|
164 |
|
---|
165 | // swap elements values
|
---|
166 | var oCurElems = $('input', oCur.get(0));
|
---|
167 | var oPrevElems = $('input', oPrev.get(0));
|
---|
168 |
|
---|
169 | oCurElems.each( function(iInd) {
|
---|
170 | var oCurElem = $( this );
|
---|
171 | var oPrevElem = oPrevElems.filter( ':eq(' + iInd + ')' );
|
---|
172 |
|
---|
173 | // swap them
|
---|
174 | var sCurValue = oCurElem.val();
|
---|
175 | oCurElem.val( oPrevElem.val() );
|
---|
176 | oPrevElem.val( sCurValue );
|
---|
177 | } );
|
---|
178 | }
|
---|
179 |
|
---|
180 | function moveDownRow( eImg ) {
|
---|
181 | var oCur = $( eImg ).parent().parent();
|
---|
182 | var oPrev = oCur.next( ':not(.headers)' );
|
---|
183 | if( !oPrev.length )
|
---|
184 | return;
|
---|
185 |
|
---|
186 | // swap elements values
|
---|
187 | var oCurElems = $('input', oCur.get(0));
|
---|
188 | var oPrevElems = $('input', oPrev.get(0));
|
---|
189 |
|
---|
190 | oCurElems.each( function(iInd) {
|
---|
191 | var oCurElem = $( this );
|
---|
192 | var oPrevElem = oPrevElems.filter( ':eq(' + iInd + ')' );
|
---|
193 |
|
---|
194 | // swap them
|
---|
195 | var sCurValue = oCurElem.val();
|
---|
196 | oCurElem.val( oPrevElem.val() );
|
---|
197 | oPrevElem.val( sCurValue );
|
---|
198 | } );
|
---|
199 | }
|
---|
200 |
|
---|
201 | function sortZebra() {
|
---|
202 | $( '#listEdit tr:even' ).removeClass( 'even odd' ).addClass( 'even' );
|
---|
203 | $( '#listEdit tr:odd' ).removeClass( 'even odd' ).addClass( 'odd' );
|
---|
204 | }
|
---|
205 |
|
---|
206 | //just a design
|
---|
207 | $( document ).ready( sortZebra );
|
---|
208 | </script>
|
---|
209 |
|
---|
210 | <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
|
---|
211 | <table id="listEdit" cellpadding="0" cellspacing="0">
|
---|
212 | <tr>
|
---|
213 | <th colspan="<?= count( $aFields ) + 1 ?>">
|
---|
214 | Select a list:
|
---|
215 | <select name="list"
|
---|
216 | onchange="if( this.value != '' ) window.location = '<?= $_SERVER['PHP_SELF'] ?>' + '?list=' + encodeURIComponent( this.value ) + '<?= $sPopupAdd ?>';">
|
---|
217 | <?= genListOptions( $aLists, $sList ) ?>
|
---|
218 | </select>
|
---|
219 | <input type="button" value="Create New" onclick="createNewList();" />
|
---|
220 | </th>
|
---|
221 | </tr>
|
---|
222 | <?
|
---|
223 | if( $sList !== '' ) {
|
---|
224 | $iNextInd = genListRows( $sList_db );
|
---|
225 | ?>
|
---|
226 | <tr>
|
---|
227 | <th colspan="8">
|
---|
228 | <input type="hidden" name="popup" value="<?= $iAmInPopup ?>" />
|
---|
229 | <input type="submit" name="action" value="Save" />
|
---|
230 | </th>
|
---|
231 | </tr>
|
---|
232 | <?
|
---|
233 | } else
|
---|
234 | $iNextInd = 0;
|
---|
235 | ?>
|
---|
236 | </table>
|
---|
237 |
|
---|
238 | <script type="text/javascript">
|
---|
239 | iNextInd = <?= $iNextInd ?>;
|
---|
240 | </script>
|
---|
241 | </form>
|
---|
242 | <?
|
---|
243 | return $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => ob_get_clean()));
|
---|
244 | }
|
---|
245 |
|
---|
246 | function genListOptions( $aLists, $sActive ) {
|
---|
247 | $sRet = '';
|
---|
248 | foreach( $aLists as $sKey => $sValue ) {
|
---|
249 | $sRet .= '
|
---|
250 | <option value="' .
|
---|
251 | htmlspecialchars( $sKey ) .
|
---|
252 | '"' . ( ( $sKey == $sActive ) ? ' selected="selected"' : '' ) .
|
---|
253 | '>' . htmlspecialchars( $sValue ) . '</option>';
|
---|
254 | }
|
---|
255 |
|
---|
256 | return $sRet;
|
---|
257 | }
|
---|
258 |
|
---|
259 | function genListRows( $sList_db ) {
|
---|
260 | global $aFields;
|
---|
261 |
|
---|
262 | $sDeleteIcon = $GLOBALS['oAdmTemplate']->getImageUrl('minus1.gif');
|
---|
263 | $sUpIcon = $GLOBALS['oAdmTemplate']->getImageUrl('arrow_up.gif');
|
---|
264 | $sDownIcon = $GLOBALS['oAdmTemplate']->getImageUrl('arrow_down.gif');
|
---|
265 |
|
---|
266 | $sQuery = "SELECT * FROM `sys_pre_values` WHERE `Key` = '$sList_db' ORDER BY `Order`";
|
---|
267 | $rList = db_res( $sQuery );
|
---|
268 |
|
---|
269 | ?>
|
---|
270 | <tr class="headers">
|
---|
271 | <?
|
---|
272 | foreach( $aFields as $sField => $sHelp ) {
|
---|
273 | ?>
|
---|
274 | <th>
|
---|
275 | <span class="tableLabel"
|
---|
276 | onmouseover="showFloatDesc( '<?= addslashes( htmlspecialchars( $sHelp ) ) ?>' );"
|
---|
277 | onmousemove="moveFloatDesc( event );"
|
---|
278 | onmouseout="hideFloatDesc();">
|
---|
279 | <?= $sField ?>
|
---|
280 | </span>
|
---|
281 | </th>
|
---|
282 | <?
|
---|
283 | }
|
---|
284 | ?>
|
---|
285 | <th> </th>
|
---|
286 | </tr>
|
---|
287 | <?
|
---|
288 |
|
---|
289 | $iCounter = 0;
|
---|
290 |
|
---|
291 | while( $aRow = mysql_fetch_assoc( $rList ) ) {
|
---|
292 | ?>
|
---|
293 | <tr>
|
---|
294 | <?
|
---|
295 | foreach( $aFields as $sField => $sHelp ) {
|
---|
296 | ?>
|
---|
297 | <td><input type="text" class="value_input" name="PreList[<?= $iCounter ?>][<?= $sField ?>]" value="<?= htmlspecialchars( $aRow[$sField] ) ?>" /></td>
|
---|
298 | <?
|
---|
299 | }
|
---|
300 | ?>
|
---|
301 | <th><img src="<?=$sDeleteIcon?>" class="row_control" title="Delete" alt="Delete" onclick="delRow( this );" /><img src="<?= $sUpIcon ?>" class="row_control" title="Move up" alt="Move up" onclick="moveUpRow( this );" /><img src="<?= $sDownIcon ?>" class="row_control" title="Move down" alt="Move down" onclick="moveDownRow( this );" /></th>
|
---|
302 | </tr>
|
---|
303 | <?
|
---|
304 |
|
---|
305 | $iCounter ++;
|
---|
306 | }
|
---|
307 | ?>
|
---|
308 | <tr class="headers">
|
---|
309 | <td colspan="<?= count( $aFields ) ?>"> </td>
|
---|
310 | <th>
|
---|
311 | <img src="<?= $GLOBALS['oAdmTemplate']->getImageUrl('plus1.gif') ?>" class="row_control" title="Add" alt="Add" onclick="addRow( this );" />
|
---|
312 | </th>
|
---|
313 | </tr>
|
---|
314 | <?
|
---|
315 |
|
---|
316 | return $iCounter;
|
---|
317 | }
|
---|
318 |
|
---|
319 | function saveList( $sList, $aData ) {
|
---|
320 | global $aFields;
|
---|
321 | global $iAmInPopup;
|
---|
322 |
|
---|
323 | $sList_db = trim( process_db_input( $sList ) );
|
---|
324 |
|
---|
325 | if( $sList_db == '' )
|
---|
326 | return false;
|
---|
327 |
|
---|
328 | $sQuery = "DELETE FROM `sys_pre_values` WHERE `Key` = '$sList_db'";
|
---|
329 |
|
---|
330 | db_res( $sQuery );
|
---|
331 |
|
---|
332 | $sValuesAlter = '';
|
---|
333 |
|
---|
334 | foreach( $aData as $iInd => $aRow ) {
|
---|
335 | $aRow['Value'] = str_replace( ',', '', trim( $aRow['Value'] ) );
|
---|
336 |
|
---|
337 | if( $aRow['Value'] == '' )
|
---|
338 | continue;
|
---|
339 |
|
---|
340 | $sValuesAlter .= "'" . process_db_input( $aRow['Value'] ) . "', ";
|
---|
341 |
|
---|
342 | $sInsFields = '';
|
---|
343 | $sInsValues = '';
|
---|
344 | foreach( $aFields as $sField => $sTemp ) {
|
---|
345 | $sValue = trim( process_db_input( $aRow[$sField] ) );
|
---|
346 |
|
---|
347 | $sInsFields .= "`$sField`, ";
|
---|
348 | $sInsValues .= "'$sValue', ";
|
---|
349 | }
|
---|
350 |
|
---|
351 | $sInsFields = substr( $sInsFields, 0, -2 ); //remove ', '
|
---|
352 | $sInsValues = substr( $sInsValues, 0, -2 );
|
---|
353 |
|
---|
354 | $sQuery = "INSERT INTO `sys_pre_values` ( `Key`, $sInsFields, `Order` ) VALUES ( '$sList_db', $sInsValues, $iInd )";
|
---|
355 |
|
---|
356 | db_res( $sQuery );
|
---|
357 | }
|
---|
358 |
|
---|
359 | //alter Profiles table
|
---|
360 | $sValuesAlter = substr( $sValuesAlter, 0, -2 ); //remove ', '
|
---|
361 | $sQuery = "SELECT `Name` FROM `sys_profile_fields` WHERE `Type` = 'select_set' AND `Values` = '#!{$sList_db}'";
|
---|
362 | $rFields = db_res( $sQuery );
|
---|
363 | while( $aField = mysql_fetch_assoc( $rFields ) ) {
|
---|
364 | $sField = $aField['Name'];
|
---|
365 |
|
---|
366 | $sQuery = "ALTER TABLE `Profiles` CHANGE `$sField` `$sField` set($sValuesAlter) NOT NULL default ''";
|
---|
367 | db_res( $sQuery );
|
---|
368 | }
|
---|
369 |
|
---|
370 | compilePreValues();
|
---|
371 |
|
---|
372 | if ($sList == 'Sex' or $sList == 'Country') {
|
---|
373 | clearCacheFile( BX_DIRECTORY_PATH_DBCACHE . 'GlobalMembersStat.inc' );
|
---|
374 | }
|
---|
375 |
|
---|
376 | if( $iAmInPopup )
|
---|
377 | echo '<script type="text/javascript">window.close()</script>';
|
---|
378 |
|
---|
379 | return true;
|
---|
380 | }
|
---|
381 |
|
---|
382 | function compilePreValues() {
|
---|
383 | $sQuery = "SELECT DISTINCT `Key` FROM `sys_pre_values`";
|
---|
384 | $rKeys = db_res( $sQuery );
|
---|
385 |
|
---|
386 | $rProf = @fopen( BX_DIRECTORY_PATH_INC . 'prof.inc.php', 'w' );
|
---|
387 | if( !$rProf ) {
|
---|
388 | echo '<b>Warning!</b> Couldn\'t compile prof.inc.php. Please check permissions.';
|
---|
389 | return false;
|
---|
390 | }
|
---|
391 |
|
---|
392 | fwrite( $rProf, "<?\n\$aPreValues = array(\n" );
|
---|
393 |
|
---|
394 | while( $aKey = mysql_fetch_assoc( $rKeys ) ) {
|
---|
395 | $sKey = $aKey['Key'];
|
---|
396 | $sKey_db = addslashes( $sKey );
|
---|
397 |
|
---|
398 | fwrite( $rProf, " '$sKey_db' => array(\n" );
|
---|
399 |
|
---|
400 | $sQuery = "SELECT * FROM `sys_pre_values` WHERE `Key` = '$sKey_db' ORDER BY `Order`";
|
---|
401 | $rRows = db_res( $sQuery );
|
---|
402 |
|
---|
403 | while( $aRow = mysql_fetch_assoc( $rRows ) ) {
|
---|
404 | $sValue_db = addslashes( $aRow['Value'] );
|
---|
405 | fwrite( $rProf, " '{$sValue_db}' => array( " );
|
---|
406 |
|
---|
407 | foreach( $aRow as $sValKey => $sValue ) {
|
---|
408 | if( $sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order' )
|
---|
409 | continue; //skip key, value and order. they already used
|
---|
410 |
|
---|
411 | if( !strlen( $sValue ) )
|
---|
412 | continue; //skip empty values
|
---|
413 |
|
---|
414 | fwrite( $rProf, "'$sValKey' => '" . addslashes( $sValue ) . "', " );
|
---|
415 | }
|
---|
416 |
|
---|
417 | fwrite( $rProf, "),\n" );
|
---|
418 | }
|
---|
419 |
|
---|
420 | fwrite( $rProf, " ),\n" );
|
---|
421 | }
|
---|
422 |
|
---|
423 | fwrite( $rProf, ");\n" );
|
---|
424 | fwrite( $rProf, '
|
---|
425 | $aPreValues[\'Country\'] = sortArrByLang( $aPreValues[\'Country\'] );
|
---|
426 |
|
---|
427 | function sortArrByLang( $aArr ) {
|
---|
428 | if( !function_exists( \'_t\' ) )
|
---|
429 | return $aArr;
|
---|
430 |
|
---|
431 | $aSortArr = array();
|
---|
432 | foreach( $aArr as $sKey => $aValue )
|
---|
433 | $aSortArr[$sKey] = _t( $aValue[\'LKey\'] );
|
---|
434 |
|
---|
435 | asort( $aSortArr );
|
---|
436 |
|
---|
437 | $aNewArr = array();
|
---|
438 | foreach( $aSortArr as $sKey => $sVal )
|
---|
439 | $aNewArr[$sKey] = $aArr[$sKey];
|
---|
440 |
|
---|
441 | return $aNewArr;
|
---|
442 | }
|
---|
443 | ' );
|
---|
444 |
|
---|
445 | fclose( $rProf );
|
---|
446 |
|
---|
447 | return true;
|
---|
448 | }
|
---|
449 |
|
---|
450 | ?>
|
---|