Cheetah
preValues.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( '../inc/header.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
11 require_once( CH_DIRECTORY_PATH_INC . 'prof.inc.php' );
12 
13 $logged['admin'] = member_auth( 1, true, true );
14 
15 $_page['extraCodeInHead'] = <<<EOJ
16 <script type="text/javascript" src="{$site['plugins']}jquery/jquery.js"></script>
17 EOJ;
18 
19 $aFields = array(
20  'Value' => _t('_adm_pvalues_help_value'),
21  'LKey' => _t('_adm_pvalues_help_lkey'),
22  'LKey2' => _t('_adm_pvalues_help_lkey2'),
23  'Extra' => _t('_adm_pvalues_help_extra'),
24 );
25 
26 if(ch_get('popup') !== false && (int)ch_get('popup') == 1) {
27  $iAmInPopup = true;
28 
29  $iNameIndex = 17;
30  $_page = array(
31  'name_index' => $iNameIndex,
32  'css_name' => array('predefined_values.css'),
33  'js_name' => array(),
34  'header' => _t('_adm_page_cpt_pvalues_manage'),
35  'header_text' => _t('_adm_box_cpt_pvalues_manage'),
36  );
37  $_page_cont[$iNameIndex]['page_main_code'] = PageCompPageMainCode();
38 } else {
39  $iAmInPopup = false;
40 
42  $_page = array(
43  'name_index' => $iNameIndex,
44  'css_name' => array('forms_adv.css', 'predefined_values.css'),
45  'js_name' => array(),
46  'header' => _t('_adm_page_cpt_pvalues_manage'),
47  'header_text' => _t('_adm_box_cpt_pvalues_manage'),
48  );
50 }
51 
53 
55 {
56  global $iAmInPopup;
58 
59  $sPopupAdd = $iAmInPopup ? '&popup=1' : '';
60  $sResultMsg = '';
61 
62  if( isset( $_POST['action'] ) and $_POST['action'] == 'Save' and isset( $_POST['PreList'] ) and is_array( $_POST['PreList'] ) ) {
63  if (true === saveList( $_POST['list'], $_POST['PreList'] ))
64  $sResultMsg = _t('_Success');
65  else
66  $sResultMsg = _t('_Failed to apply changes');
67  }
68 
69  //get lists
70  $aLists = array();
71  $aKeys = getPreKeys();
72  foreach ($aKeys as $aList)
73  $aLists[ $aList['Key'] ] = $aList['Key'];
74 
75  $sListIn = ch_get('list');
76  if ($sListIn !== false) {
77  $sList_db = process_db_input($sListIn);
78  $sList = process_pass_data($sListIn);
79 
80  $iCount = getPreValuesCount($sListIn);
81  if (!$iCount) //if no rows returned...
82  $aLists[ $sList ] = $sList; //create new list
83  } else {
84  $sList = '';
85  }
86 
87  ob_start();
88  if ($sResultMsg)
89  echo MsgBox($sResultMsg);
90  ?>
91  <script type="text/javascript">
92  function createNewList()
93  {
94  var sNewList = prompt( '<?php echo ch_js_string(_t('_adm_pvalues_msg_enter_list_name')); ?>' );
95 
96  if( sNewList == null )
97  return false;
98 
99  sNewList = $.trim( sNewList );
100 
101  if( !sNewList.length ) {
102  alert( '<?php echo ch_js_string(_t('_adm_pvalues_msg_enter_correct_name')); ?>' );
103  return false;
104  }
105 
106  window.location = '<?=$GLOBALS['site']['url_admin'] . 'preValues.php'; ?>?list=' + encodeURIComponent( sNewList ) + '<?= $sPopupAdd ?>';
107  }
108 
109  function addRow( eImg )
110  {
111  $( eImg ).parent().parent().before(
112  '<tr>' +
113  <?php
114  foreach( $aFields as $sField => $sHelp ) {
115  ?>
116  '<td><input type="text" class="value_input" name="PreList[' + iNextInd + '][<?= $sField ?>]" value="" /></td>' +
117  <?php
118  }
119  ?>
120  '<th class="row_controls">' +
121  '<a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:delRow(this);" title="<?php echo ch_html_attribute(_t('_Delete')); ?>"><i class="sys-icon times"></i></a>' +
122  '<a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:moveUpRow(this);" title="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_move_up')); ?>"><i class="sys-icon arrow-up"></i></a>' +
123  '<a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:moveDownRow(this);" title="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_move_down')); ?>"><i class="sys-icon arrow-down"></i></a>' +
124  '</th>' +
125  '</tr>'
126  );
127 
128  iNextInd ++;
129 
130  sortZebra();
131  }
132 
133  function delRow( eImg )
134  {
135  $( eImg ).parent().parent().remove();
136  sortZebra();
137  }
138 
139  function moveUpRow( eImg )
140  {
141  var oCur = $( eImg ).parent().parent();
142  var oPrev = oCur.prev( ':not(.headers)' );
143  if( !oPrev.length )
144  return;
145 
146  // swap elements values
147  var oCurElems = $('input', oCur.get(0));
148  var oPrevElems = $('input', oPrev.get(0));
149 
150  oCurElems.each( function(iInd) {
151  var oCurElem = $( this );
152  var oPrevElem = oPrevElems.filter( ':eq(' + iInd + ')' );
153 
154  // swap them
155  var sCurValue = oCurElem.val();
156  oCurElem.val( oPrevElem.val() );
157  oPrevElem.val( sCurValue );
158  } );
159  }
160 
161  function moveDownRow( eImg )
162  {
163  var oCur = $( eImg ).parent().parent();
164  var oPrev = oCur.next( ':not(.headers)' );
165  if( !oPrev.length )
166  return;
167 
168  // swap elements values
169  var oCurElems = $('input', oCur.get(0));
170  var oPrevElems = $('input', oPrev.get(0));
171 
172  oCurElems.each( function(iInd) {
173  var oCurElem = $( this );
174  var oPrevElem = oPrevElems.filter( ':eq(' + iInd + ')' );
175 
176  // swap them
177  var sCurValue = oCurElem.val();
178  oCurElem.val( oPrevElem.val() );
179  oPrevElem.val( sCurValue );
180  } );
181  }
182 
183  function sortZebra()
184  {
185  $( '#listEdit tr:even' ).removeClass( 'even odd' ).addClass( 'even' );
186  $( '#listEdit tr:odd' ).removeClass( 'even odd' ).addClass( 'odd' );
187  }
188 
189  //just a design
190  $( document ).ready( sortZebra );
191  </script>
192 
193  <form action="<?=$GLOBALS['site']['url_admin'] . 'preValues.php'; ?>" method="post" enctype="multipart/form-data">
194  <div class="adm-pv-cp-selector ch-def-margin-bottom">
195  <div class="adm-pv-cp-item">
196  <span><?php echo _t('_adm_pvalues_txt_select_list'); ?>:</span>
197  <div class="input_wrapper input_wrapper_select ch-def-margin-sec-leftright clearfix">
198  <select class="form_input_select ch-def-font-inputs" name="list" onchange="if( this.value != '' ) window.location = '<?=$GLOBALS['site']['url_admin'] . 'preValues.php'; ?>' + '?list=' + encodeURIComponent( this.value ) + '<?= $sPopupAdd ?>';"><?= genListOptions( $aLists, $sList ) ?></select>
199  </div>
200  </div>
201  <div class="input_wrapper input_wrapper_submit clearfix">
202  <input class="form_input_submit ch-btn" type="button" value="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_create_new')); ?>" onclick="createNewList();" />
203  </div>
204  </div>
205  <table class="ch-def-table" id="listEdit" cellpadding="0" cellspacing="1"><?php $iNextInd = $sList !== '' ? genListRows( $sList_db ) : 0; ?></table>
206  <div class="adm-pv-submit ch-def-margin-top">
207  <input type="hidden" name="popup" value="<?= $iAmInPopup ?>" />
208  <input type="hidden" name="action" value="Save" />
209  <div class="input_wrapper input_wrapper_submit clearfix">
210  <input class="form_input_submit ch-btn" type="submit" name="submit" value="<?= ch_html_attribute(_t('_Save')) ?>" />
211  </div>
212  </div>
213  <script type="text/javascript">
214  iNextInd = <?= $iNextInd ?>;
215  </script>
216  </form>
217  <?php
218  return $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => ob_get_clean()));
219 }
220 
221 function genListOptions( $aLists, $sActive )
222 {
223  asort($aLists);
224 
225  $sRet = '<option value="">' . _t('_Select') . '</option>';
226  foreach( $aLists as $sKey => $sValue )
227  $sRet .= '<option value="' . htmlspecialchars( $sKey ) . '"' . ( ( $sKey == $sActive ) ? ' selected="selected"' : '' ) . '>' . htmlspecialchars( $sValue ) . '</option>';
228 
229  return $sRet;
230 }
231 
232 function genListRows( $sList )
233 {
235 
236  $aRows = getPreValues($sList);
237  ?>
238  <tr class="headers">
239  <?php
240  foreach( $aFields as $sField => $sHelp ) {
241  ?>
242  <th>
243  <span class="tableLabel" onmouseover="showFloatDesc( '<?= ch_js_string($sHelp) ?>' );" onmousemove="moveFloatDesc( event );" onmouseout="hideFloatDesc();"><?= $sField ?></span>
244  </th>
245  <?php
246  }
247  ?>
248  <th>&nbsp;</th>
249  </tr>
250  <?php
251  $iCounter = 0;
252  foreach ($aRows as $aRow) {
253  ?>
254  <tr>
255  <?php
256  foreach( $aFields as $sField => $sHelp )
257  echo '<td><input type="text" class="value_input" name="PreList[' . $iCounter . '][' . $sField . ']" value="' . htmlspecialchars($aRow[$sField]) . '" /></td>';
258  ?>
259  <th class="row_controls"><a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:delRow(this);" title="<?php echo ch_html_attribute(_t('_Delete')); ?>"><i class="sys-icon times"></i></a><a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:moveUpRow(this);" title="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_move_up')); ?>"><i class="sys-icon arrow-up"></i></a><a class="row_control ch-def-margin-thd-left-auto" href="javascript:void(0)" onclick="javascript:moveDownRow(this);" title="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_move_down')); ?>"><i class="sys-icon arrow-down"></i></a></th>
260  </tr>
261  <?php
262  $iCounter ++;
263  }
264  ?>
265  <tr class="headers">
266  <td colspan="<?= count( $aFields ) ?>">&nbsp;</td>
267  <th class="row_controls">
268  <a class="row_control" href="javascript:void(0)" onclick="javascript:addRow(this);" title="<?php echo ch_html_attribute(_t('_adm_pvalues_txt_add_record')); ?>"><i class="sys-icon plus"></i></a>
269  </th>
270  </tr>
271  <?php
272 
273  return $iCounter;
274 }
275 
276 function saveList( $sList, $aData )
277 {
279  global $iAmInPopup;
280 
281  $sList_db = trim( process_db_input( $sList ) );
282 
283  if( $sList_db == '' )
284  return false;
285 
286  $sQuery = "DELETE FROM `" . CH_SYS_PRE_VALUES_TABLE . "` WHERE `Key` = '$sList_db'";
287 
288  db_res( $sQuery );
289 
290  $sValuesAlter = '';
291 
292  foreach( $aData as $iInd => $aRow ) {
293  $aRow['Value'] = str_replace( ',', '', trim( $aRow['Value'] ) );
294 
295  if( $aRow['Value'] == '' )
296  continue;
297 
298  $sValuesAlter .= "'" . process_db_input( $aRow['Value'] ) . "', ";
299 
300  $sInsFields = '';
301  $sInsValues = '';
302  foreach( $aFields as $sField => $sTemp ) {
303  $sValue = trim( process_db_input( $aRow[$sField] ) );
304 
305  $sInsFields .= "`$sField`, ";
306  $sInsValues .= "'$sValue', ";
307  }
308 
309  $sInsFields = substr( $sInsFields, 0, -2 ); //remove ', '
310  $sInsValues = substr( $sInsValues, 0, -2 );
311 
312  $sQuery = "INSERT INTO `" . CH_SYS_PRE_VALUES_TABLE . "` ( `Key`, $sInsFields, `Order` ) VALUES ( '$sList_db', $sInsValues, $iInd )";
313 
314  db_res( $sQuery );
315  }
316 
317  //alter Profiles table
318  $sValuesAlter = substr( $sValuesAlter, 0, -2 ); //remove ', '
319  $sQuery = "SELECT `Name` FROM `sys_profile_fields` WHERE `Type` = 'select_set' AND `Values` = '#!{$sList_db}'";
320  $rFields = db_res( $sQuery );
321  while( $aField = $rFields ->fetch() ) {
322  $sField = $aField['Name'];
323 
324  $sQuery = "ALTER TABLE `Profiles` CHANGE `$sField` `$sField` set($sValuesAlter) NOT NULL default ''";
325  db_res( $sQuery );
326  }
327 
329 
330  if( $iAmInPopup )
331  echo '<script type="text/javascript">window.close()</script>';
332 
333  return true;
334 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
$_page
$_page['extraCodeInHead']
Definition: preValues.php:15
document
Output SortAttr HTML Purifier will sort attributes by name before writing them back to the document
Definition: Output.SortAttr.txt:8
getPreValuesCount
getPreValuesCount($sKey, $aFields=array(), $iTagsFilter=CH_TAGS_NO_ACTION)
Definition: prof.inc.php:34
getPreKeys
getPreKeys()
Definition: prof.inc.php:15
$iNameIndex
$iNameIndex
Definition: preValues.php:41
getPreValues
getPreValues($sKey, $aFields=array(), $iTagsFilter=CH_TAGS_NO_ACTION)
Definition: prof.inc.php:20
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
site
HTML ForbiddenElements the most requested feature ever in HTML Purifier Please don t abuse it ! This is the logical inverse of HTML and it will override that or any other directive</p >< p > If HTML Allowed is recommended over this because it can sometimes be difficult to tell whether or not you ve forbidden all of the behavior you would like to disallow If you forbid< code > img</code > with the expectation of preventing images on your site
Definition: HTML.ForbiddenElements.txt:16
name
Core AllowHostnameUnderscore underscores are not permitted in host most browsers do the right thing when faced with an underscore in the host name
Definition: Core.AllowHostnameUnderscore.txt:11
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
php
saveList
saveList( $sList, $aData)
Definition: preValues.php:276
compilePreValues
compilePreValues()
Definition: prof.inc.php:40
a
Filter ExtractStyleBlocks Scope FilterParam ExtractStyleBlocksScope DESCRIPTION< p > If you would like users to be able to define external but only allow them to specify CSS declarations for a specific node and prevent them from fiddling with other use this directive It accepts any valid CSS and will prepend this to any CSS declaration extracted from the document For if this directive is set to< code > selector< code > a
Definition: Filter.ExtractStyleBlocks.Scope.txt:15
genListRows
genListRows( $sList)
Definition: preValues.php:232
this
HTML AllowedElements you can overload it with your own list of tags to allow If you change this
Definition: HTML.AllowedElements.txt:9
$_page_cont
$_page_cont[$iNameIndex]['page_main_code']
Definition: preValues.php:49
and
and
Definition: license.txt:18
$aFields
$aFields
Definition: preValues.php:19
$logged
$logged['admin']
Definition: preValues.php:13
table
and distribute a copy of this License along with the Library You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Library or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these other than as an argument passed when the facility is then you must make a good faith effort to ensure in the event an application does not supply such function or table
Definition: license.txt:180
type
if(!defined("USER_STATUS_TYPE")) define("USER_STATUS_TYPE" type
Definition: constants.inc.php:13
src
img src
Definition: URI.MungeResources.txt:8
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
value
URI Base such as when URI MakeAbsolute is on You may use a non absolute URI for this value
Definition: URI.Base.txt:11
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
method
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step method
Definition: license.txt:49
process_pass_data
process_pass_data($text, $strip_tags=0)
Definition: utils.inc.php:290
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
CH_SYS_PRE_VALUES_TABLE
const CH_SYS_PRE_VALUES_TABLE
Definition: prof.inc.php:8
PageCompPageMainCode
PageCompPageMainCode()
Definition: preValues.php:54
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
form
iii in the case of the organization that transmits the broadcast Work means the literary and or artistic work offered under the terms of this License including without limitation any production in the scientific and artistic whatever may be the mode or form of its expression including digital form
Definition: license.txt:19
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
genListOptions
genListOptions( $aLists, $sActive)
Definition: preValues.php:221