Cheetah
ChWsbPFM.php
Go to the documentation of this file.
1 <?php
2 
11 class ChWsbPFM
12 {
13  function __construct( $iArea )
14  {
15  $this -> aColNames = array (
16  1 => array( 'Page' => 'Join', 'Order' => 'JoinOrder', 'Block' => 'JoinBlock', 'ShowSysItems' => 'Couple,Captcha,TermsOfUse,ProfilePhoto', 'EditAdd' => array( 'JoinPage' ) ),
17 
18  2 => array( 'Page' => 'Edit', 'Order' => 'EditOwnOrder', 'Block' => 'EditOwnBlock' ),
19  3 => array( 'Page' => 'Edit', 'Order' => 'EditAdmOrder', 'Block' => 'EditAdmBlock', 'ShowSysItems' => 'Featured,Status,Membership' ),
20  4 => array( 'Page' => 'Edit', 'Order' => 'EditModOrder', 'Block' => 'EditModBlock', 'ShowSysItems' => 'Featured,Status,Membership' ),
21 
22  5 => array( 'Page' => 'View', 'Order' => 'ViewAdmOrder', 'Block' => 'ViewAdmBlock', 'ShowSysItems' => 'ID,DateReg,DateLastEdit,DateLastLogin,DateLastNav,Status,Age' ),
23  6 => array( 'Page' => 'View', 'Order' => 'ViewMembOrder', 'Block' => 'ViewMembBlock', 'ShowSysItems' => 'ID,DateReg,DateLastEdit,DateLastLogin,DateLastNav,Status,Age' ),
24  7 => array( 'Page' => 'View', 'Order' => 'ViewModOrder', 'Block' => 'ViewModBlock', 'ShowSysItems' => 'ID,DateReg,DateLastEdit,DateLastLogin,DateLastNav,Status,Age' ),
25  8 => array( 'Page' => 'View', 'Order' => 'ViewVisOrder', 'Block' => 'ViewVisBlock', 'ShowSysItems' => 'ID,DateReg,DateLastEdit,DateLastLogin,DateLastNav,Status,Age' ),
26 
27  9 => array( 'Page' => 'Search', 'Order' => 'SearchSimpleOrder', 'Block' => 'SearchSimpleBlock', 'EditAdd' => array( 'SearchParams' ), 'ShowSysItems' => 'ID,Keyword,Location,Couple' ),
28  10 => array( 'Page' => 'Search', 'Order' => 'SearchQuickOrder', 'Block' => 'SearchQuickBlock', 'EditAdd' => array( 'SearchParams' ), 'ShowSysItems' => 'ID,Keyword,Location,Couple' ),
29  11 => array( 'Page' => 'Search', 'Order' => 'SearchAdvOrder', 'Block' => 'SearchAdvBlock', 'EditAdd' => array( 'SearchParams' ), 'ShowSysItems' => 'ID,Keyword,Location,Couple' ),
30  );
31 
32  $this -> sLinkPref = '#!'; //prefix for values links (@see predefined links)
33 
34  $this -> aTypes = array(
35  'text' => 'Text',
36  'area' => 'TextArea',
37  'html_area' => 'HtmlTextArea',
38  'pass' => 'Password',
39  'date' => 'Date',
40  'select_one' => 'Selector',
41  'select_set' => 'Multiple Selector',
42  'num' => 'Number',
43  'range' => 'Range',
44  'bool' => 'Boolean (checkbox)'
45  );
46 
47  //altering table properties
48  $this -> aTypesAlter = array(
49  'text' => "varchar(255) NOT NULL {default}",
50  'area' => "text NOT NULL",
51  'html_area' => "text NOT NULL",
52  'pass' => "varchar(40) NOT NULL",
53  'date' => "date NOT NULL {default}",
54  'select_one' => "enum({values})",
55  'select_one_linked' => "varchar(255) NOT NULL default ''",
56  'select_set' => "set({values}) NOT NULL default ''",
57  'select_set_linked' => "set({values}) NOT NULL default ''",
58  'num' => "int(10) unsigned NOT NULL {default}",
59  'range' => "varchar(255) NOT NULL {default}",
60  'bool' => "tinyint(1) NOT NULL {default}"
61  );
62 
63  $this -> iAreaID = (int)$iArea;
64  if( !( $this -> iAreaID > 0 and isset( $this -> aColNames[$this -> iAreaID] ) ) )
65  return false;
66 
67  // retrieve default language
68  $sLangDfl = getParam('lang_default');
69  $sQuery = "SELECT `ID` FROM `sys_localization_languages` WHERE `Name` = ?";
70  $this -> sLangID = (int)db_value( $sQuery, [$sLangDfl]);
71 
72  if( !$this -> sLangID )
73  die('Cannot continue. Default language not found. Check the Basic Settings.');
74 
75  $this -> areaPageName = $this -> aColNames[$this -> iAreaID]['Page'];
76  $this -> areaOrderCol = $this -> aColNames[$this -> iAreaID]['Order'];
77  $this -> areaBlockCol = $this -> aColNames[$this -> iAreaID]['Block'];
78  $this -> areaSysItems = $this -> aColNames[$this -> iAreaID]['ShowSysItems'];
79 
80  $this -> areaEditAddCols = $this -> aColNames[$this -> iAreaID]['EditAdd'];
81 
82  $this -> aBlocks = array();
83  $this -> aItems = array();
84 
85  $this -> aBlocksInac = array();
86  $this -> aItemsInac = array();
87 
88  }
89 
90  function genJSON()
91  {
92  $this -> fillMyArrays();
93  $this -> oJSONObject = new ChWsbPFMAreaJSONObj( $this );
94  return json_encode( $this -> oJSONObject );
95  }
96 
97  function fillMyArrays()
98  {
99  if (!$this -> areaOrderCol)
100  return false;
101 
102  //collect active fields
103 
104  //blocks
105  $sBlocksQuery = "
106  SELECT
107  `ID`,
108  `Name`
109  FROM `sys_profile_fields`
110  WHERE
111  `{$this -> areaOrderCol}` IS NOT NULL AND
112  `Type` = 'block'
113  ORDER BY
114  `{$this -> areaOrderCol}`
115  ";
116 
117  $rBlocks = db_res( $sBlocksQuery );
118 
119  while( $aBlock = $rBlocks ->fetch() ) {
120  $iBlockID = $aBlock['ID'];
121 
122  $this -> aBlocks[ $iBlockID ] = $aBlock['Name'];
123 
124  //get items of this block
125  $sItemsQuery = "
126  SELECT
127  `ID`,
128  `Name`
129  FROM `sys_profile_fields`
130  WHERE
131  `Type` != 'block' AND
132  `{$this -> areaOrderCol}` IS NOT NULL AND
133  `{$this -> areaBlockCol}` = $iBlockID AND
134  (
135  `Type` != 'system' OR
136  (
137  `Type` = 'system' AND
138  FIND_IN_SET( `Name`, '{$this -> areaSysItems}' )
139  )
140  )
141  ORDER BY
142  `{$this -> areaOrderCol}`
143  ";
144 
145  $rItems = db_res( $sItemsQuery );
146 
147  while( $aItem = $rItems ->fetch() )
148  $this -> aItems[ $aItem['ID'] ] = array( $aItem['Name'], $iBlockID );
149  }
150 
151  //collect inactive fields
152 
153  //blocks
154  $sBlocksInacQuery = "
155  SELECT
156  `ID`,
157  `Name`
158  FROM `sys_profile_fields`
159  WHERE
160  `{$this -> areaOrderCol}` IS NULL AND
161  `Type` = 'block'
162  ";
163 
164  $rBlocksInac = db_res( $sBlocksInacQuery );
165 
166  while( $aBlock = $rBlocksInac ->fetch() )
167  $this -> aBlocksInac[ $aBlock['ID'] ] = $aBlock['Name'];
168 
169  //items
170  $sActiveBlocksList = implode( ',', array_keys( $this -> aBlocks ) );
171  if( $sActiveBlocksList == '' )
172  $sActiveBlocksList = "NULL";
173 
174  $sItemsInacQuery = "
175  SELECT
176  `ID`,
177  `Name`
178  FROM `sys_profile_fields`
179  WHERE
180  `Type` != 'block' AND (
181  `{$this -> areaBlockCol}` = 0 OR
182  `{$this -> areaBlockCol}` NOT IN ($sActiveBlocksList)
183  ) AND (
184  `Type` != 'system' OR (
185  `Type` = 'system' AND
186  FIND_IN_SET( `Name`, '{$this -> areaSysItems}' )
187  )
188  )
189  ";
190 
191  $rItemsInac = db_res( $sItemsInacQuery );
192 
193  while( $aItem = $rItemsInac ->fetch() )
194  $this -> aItemsInac[ $aItem['ID'] ] = $aItem['Name'];
195 
196  //echoDbg( $this );exit;
197  }
198 
199  function savePositions( $aInArrays )
200  {
201  db_res( "UPDATE `sys_profile_fields` SET `{$this -> areaOrderCol}` = NULL" );
202  db_res( "UPDATE `sys_profile_fields` SET `{$this -> areaBlockCol}` = 0" );
203 
204  if( is_array( $aInArrays['blocks'] ) ) {
205  foreach( $aInArrays['blocks'] as $iBlockID ) {
206  $iBlockID = (int)$iBlockID;
207 
208  $iBlockOrd = (int)db_value( "
209  SELECT MAX( `{$this -> areaOrderCol}` )
210  FROM `sys_profile_fields`
211  WHERE `Type` = 'block'
212  " ) + 1;
213 
214  db_res( "
215  UPDATE `sys_profile_fields`
216  SET `{$this -> areaOrderCol}` = $iBlockOrd
217  WHERE `ID` = $iBlockID
218  " );
219  }
220 
221  if( is_array( $aInArrays['items'] ) and is_array( $aInArrays['items_blocks'] ) ) {
222  foreach( $aInArrays['items'] as $iItemID ) {
223  $iItemID = (int)$iItemID;
224  $iItemBlockID = (int)$aInArrays['items_blocks'][$iItemID];
225 
226  if( in_array( $iItemBlockID, $aInArrays['blocks'] ) ) {
227  $iItemOrd = db_value( "
228  SELECT MAX( `{$this -> areaOrderCol}` )
229  FROM `sys_profile_fields`
230  WHERE `Type` != 'block' AND `{$this -> areaBlockCol}` = $iItemBlockID
231  " ) + 1;
232 
233  db_res( "
234  UPDATE `sys_profile_fields`
235  SET
236  `{$this -> areaOrderCol}` = $iItemOrd,
237  `{$this -> areaBlockCol}` = $iItemBlockID
238  WHERE `ID` = $iItemID
239  " );
240  }
241  }
242  }
243  }
244 
245  echo 'OK';
246  }
247 
248  function genFieldEditForm( $iItemID )
249  {
250  $sQuery = "
251  SELECT
252  `Name`,
253  `Type`,
254  `Control`,
255  `Extra`,
256  `Min`,
257  `Max`,
258  `Values`,
259  `UseLKey`,
260  `Check`,
261  `Unique`,
262  `Default`,
263  `Mandatory`,
264  `Deletable`,
265  `MatchField`,
266  `MatchPercent`" .
267 
268  ( $this -> areaEditAddCols ?
269  ( ', `' . implode( '`, `', $this -> areaEditAddCols ) . '`' ) :
270  ''
271  ) . "
272 
273  FROM `sys_profile_fields` WHERE `ID` = $iItemID";
274 
275  $aField = db_assoc_arr( $sQuery );
276 
277  if( !$aField ) {
278  echo _t('_adm_fields_error_field_not_found');
279  return;
280  }
281 
282  $sGeneralC = _t('_adm_fields_general');
283  $sAdvancedC = _t('_adm_fields_advanced');
284  $sMessagesC = _t('_adm_fields_messages');
285  $sMatchingC = _t('_adm_fields_matching');
286  $sNameC = _t('_adm_mbuilder_System_Name');
287  $sCaptionC = _t('_Caption');
288  $sDescriptionC = _t('_Description');
289  $sNameDescC = _t('_adm_fields_name_desc');
290  $sTypeC = _t('_Type');
291  $sJoinPageC = _t('_adm_fields_join_page');
292  $sSearchInFieldsC = _t('_adm_fields_search_in_fields');
293  $sSearchInFieldsDescC = _t('_adm_fields_search_in_fields_desc');
294  $sMutualCpFieldsC = _t('_adm_fields_mutual_couple_fields');
295  $sMutualCpFieldsDescC = _t('_adm_fields_mutual_couple_fields_desc');
296  $sSureDeleteItemC = addslashes(_t('_adm_fields_delete_item_desc'));
297 
298  // field title and description
299  $this -> fieldCaption = "_FieldCaption_{$aField['Name']}_{$this -> areaPageName}"; // _FieldCaption_Sex_Join
300  $this -> fieldDesc = "_FieldDesc_{$aField['Name']}_{$this -> areaPageName}"; // _FieldDesc_Sex_Join
301 
302  $this -> showFormTabs = ( $aField['Type'] != 'block' and $aField['Type'] != 'system' );
303 
304  $sCaptionDescC = _t('_adm_fields_caption_desc', $this -> areaPageName, $this -> fieldCaption);
305  $sDescriptionDescC = _t('_adm_fields_description_desc', $this -> areaPageName, $this -> fieldDesc);
306 
307  ?>
308  <input type="hidden" name="action" value="saveItem" />
309  <input type="hidden" name="id" value="<?= $iItemID ?>" />
310  <input type="hidden" name="area" value="<?= $this -> iAreaID ?>" />
311 
312  <?php
313  if( $this -> showFormTabs ) {
314  ?>
315  <ul id="form_tabs_switcher">
316  <li><a href="#f1"><?= $sGeneralC ?></a></li>
317  <li><a href="#f2"><?= $sAdvancedC ?></a></li>
318  <li><a href="#f3"><?= $sMessagesC ?></a></li>
319  <li><a href="#f4"><?= $sMatchingC ?></a></li>
320  </ul>
321  <?php
322  }
323  ?>
324 
325  <table class="field_edit_tab" id="f1"> <!-- General -->
326  <tr>
327  <td class="label"><?= $sNameC ?>:</td>
328  <td class="value">
329  <input type="text" maxlength="255" class="input_text" name="Name"
330  value="<?= htmlspecialchars( $aField['Name'] ); ?>"
331  <?php if( $aField['Type'] == 'system' or !$aField['Deletable'] ) echo 'readonly="readonly"'; ?> />
332  </td>
333  <td class="info">
334  <?php
335  if( $aField['Type'] != 'block' and $aField['Type'] != 'system' )
336  echo $this -> getInfoIcon(addslashes($sNameDescC));
337  else
338  echo '&nbsp;';
339  ?>
340  </td>
341  </tr>
342  <tr>
343  <td class="label"><?= $sCaptionC ?>:</td>
344  <td class="value">
345  <input type="text" maxlength="255" class="input_text" name="Caption"
346  value="<?= htmlspecialchars( $this -> getLangString( $this -> fieldCaption ) ); ?>" />
347  </td>
348  <td class="info">
349  <?= $this -> getInfoIcon(addslashes($sCaptionDescC)) ?>
350  </td>
351  </tr>
352  <tr>
353  <td class="label"><?= $sDescriptionC ?>:</td>
354  <td class="value">
355  <textarea class="input_text" name="Desc"><?= htmlspecialchars( $this -> getLangString( $this -> fieldDesc ) ); ?></textarea>
356  </td>
357  <td class="info">
358  <?= $this -> getInfoIcon(addslashes($sDescriptionDescC)) ?>
359  </td>
360  </tr>
361  <?php
362 
363  if( $aField['Type'] == 'block' ) {
364  if( $this -> iAreaID == 1 ) { //Join
365  ?>
366  <tr>
367  <td class="label"><?= $sJoinPageC ?>:</td>
368  <td class="value">
369  <?= $this -> getJoinPagesSelector( $aField['JoinPage'] ) ?>
370  </td>
371  <td class="info">&nbsp;</td>
372  </tr>
373  <?php
374  }
375  } else {
376  ?>
377  <tr>
378  <td class="label"><?= $sTypeC ?>:</td>
379  <td class="value">
380  <?php
381  if( $aField['Type'] == 'system' )
382  echo 'System';
383  else {
384  ?>
385  <select name="Type" class="select_type" onchange="changeFieldType( this.value );">
386  <?= $this -> getTypeOptions( $aField['Type'] ) ?>
387  </select>
388  <?php
389  }
390  ?>
391  </td>
392  <td class="info">&nbsp;</td>
393  </tr>
394  <?php
395  }
396 
397  //system fields properties
398  if( $aField['Name'] == 'Keyword' ) {
399  ?>
400  <tr>
401  <td class="label"><?= $sSearchInFieldsC ?>:</td>
402  <td class="value">
403  <select name="KeywordFields[]" class="select_multiple" multiple="multiple">
404  <?= $this -> getFieldsOptionsList( $aField['Extra'], 'Keyword' ) ?>
405  </select>
406  </td>
407  <td class="info">
408  <?= $this -> getInfoIcon(addslashes($sSearchInFieldsDescC)) ?>
409  </td>
410  </tr>
411  <?php
412  } elseif( $aField['Name'] == 'Couple' ) {
413  ?>
414  <tr>
415  <td class="label"><?= $sMutualCpFieldsC ?>:</td>
416  <td class="value">
417  <select name="CoupleFields[]" class="select_multiple" multiple="multiple">
418  <?= $this -> getFieldsOptionsList( $aField['Extra'], 'Couple' ) ?>
419  </select>
420  </td>
421  <td class="info">
422  <?= $this -> getInfoIcon(addslashes($sMutualCpFieldsDescC)) ?>
423  </td>
424  </tr>
425  <?php
426  }
427 
428  ?>
429  </table>
430 
431  <?php
432 
433  if( $this -> showFormTabs ) {
434  $this -> genFormAdvTab( $aField );
435  $this -> genFormMiscTab( $aField );
436  $this -> genFormMatchTab( $aField );
437  }
438 
439  ?>
440  <table class="field_edit_tab ch-def-margin-sec-topbottom"> <!--Controls-->
441  <tr>
442  <td class="buttons" colspan="2">
443  <input type="submit" name="action-save" value="<?= ch_html_attribute(_t('_Save')) ?>" class="ch-btn ch-btn-small" />
444  <?php
445 
446  if( $aField['Type'] != 'system' and $aField['Deletable'] ) {
447  ?>
448  <input type="submit" name="action-delete" value="<?= ch_html_attribute(_t('_Delete')) ?>" onclick="return confirm('<?= $sSureDeleteItemC ?>');" class="ch-btn ch-btn-small" />
449  <?php
450  }
451  ?>
452  </td>
453  </tr>
454  </table>
455 
456  <script type="text/javascript">
457  $(document).ready( function(){
458  $('.edit_item_table_cont:first').tabs({selected:0});
459  changeFieldType( '<?= $aField['Type'] ?>' );
460  } );
461  </script>
462  <?php
463  }
464 
465  function getFieldsOptionsList( $sSelected, $sType )
466  {
467  $aSelected = explode( "\n", $sSelected );
468  foreach( $aSelected as $iKey => $sValue )
469  $aSelected[$iKey] = trim( $sValue );
470 
471  switch( $sType ) {
472  case 'Keyword': $sWhere = "`Type` = 'text' OR `Type` = 'area' OR `Type` = 'html_area'"; break;
473  case 'Couple' : $sWhere = "`Type` != 'block' AND `Type` != 'system' AND `Deletable` = 1"; break;
474  default : $sWhere = "0";
475  }
476 
477  $sQuery = "SELECT `Name` FROM `sys_profile_fields` WHERE $sWhere";
478  $rFields = db_res( $sQuery );
479 
480  $sRet = '';
481  while( $aField = $rFields ->fetch() ) {
482  $sRet .= '<option value="' . $aField['Name'] . '"' .
483  ( in_array( $aField['Name'], $aSelected ) ? 'selected="selected"' : '' ) . '>' .
484  $aField['Name'] . '</option>';
485  }
486 
487  return $sRet;
488  }
489 
490  function getJoinPagesSelector( $iCurrent )
491  {
492  $sQuery = "SELECT MAX( `JoinPage` ) FROM `sys_profile_fields`";
493  $iMaxPage = (int)db_value( $sQuery );
494 
495  $sRet = '<select name="JoinPage" class="select_page">';
496  for( $iPage = 0; $iPage <= ( $iMaxPage + 1 ); $iPage ++ ) {
497  $sRet .=
498  '<option value="' . $iPage . '"' .
499  ( ( $iPage == $iCurrent ) ? ' selected="selected"' : '' ) . '>' .
500  $iPage . '</option>';
501  }
502  $sRet .= '</select>';
503 
504  return $sRet;
505  }
506 
507  function genFormMatchTab( $aField )
508  {
509  $aForm = array(
510  'MatchField' => array(
511  'label' => _t('_adm_fields_match_with_field'),
512  'type' => 'select',
513  'info' => addslashes(_t('_adm_fields_match_with_field_desc')),
514  'value' => $aField['MatchField'],
515  'values' => $this -> getMatchFields( $aField )
516  ),
517  'MatchPercent' => array(
518  'label' => _t('_adm_fields_match_percent'),
519  'type' => 'text',
520  'info' => addslashes(_t('_adm_fields_match_percent_desc')),
521  'value' => $aField['MatchPercent']
522  )
523  );
524 
525  $this -> genTableEdit( $aForm, 'f4' );
526  }
527 
528  function getMatchFields( $aField )
529  {
530  $aSelectFields = array( $aField['Type'] );
531 
532  switch( $aField['Type'] ) {
533  case 'select_set':
534  $aSelectFields[] = 'select_one';
535  break;
536 
537  case 'select_one':
538  $aSelectFields[] = 'select_set';
539  break;
540 
541  case 'range':
542  $aSelectFields[] = 'num';
543  $aSelectFields[] = 'date';
544  break;
545  }
546 
547  $sQuery = "SELECT `ID`, `Name` FROM `sys_profile_fields` WHERE FIND_IN_SET( `Type`, '" . implode( ',', $aSelectFields ) . "' )";
548  $rMyFields = db_res( $sQuery );
549 
550  $aMyFields = array( '0' => '-Not set-' );
551  while( $aMyField = $rMyFields ->fetch() ) {
552  $aMyFields[ $aMyField['ID'] ] = $aMyField['Name'];
553  }
554 
555  return $aMyFields;
556  }
557 
558  function genFormAdvTab( $aField )
559  {
560  $aForm = array(
561  'Control_one' => array(
562  'label' => _t('_adm_fields_selector_control'),
563  'type' => 'select',
564  'info' => addslashes(_t('_adm_fields_selector_control_desc')),
565  'value' => $aField['Control'],
566  'row_id' => 'field_control_select_one',
567  'values' => array(
568  'select' => 'Select (Dropdown box)',
569  'radio' => 'Radio-buttons'
570  )
571  ),
572  'Control_set' => array(
573  'label' => _t('_adm_fields_multiple_selector_control'),
574  'type' => 'select',
575  'info' => addslashes(_t('_adm_fields_multiple_selector_control_desc')),
576  'value' => $aField['Control'],
577  'row_id' => 'field_control_select_set',
578  'values' => array(
579  'select' => 'Select (Box)',
580  'checkbox' => 'Checkboxes'
581  )
582  ),
583  'Mandatory' => array(
584  'label' => _t('_adm_fields_mandatory'),
585  'type' => 'checkbox',
586  'info' => addslashes(_t('_adm_fields_mandatory_desc')),
587  'value' => $aField['Mandatory']
588  ),
589  'Min' => array(
590  'label' => _t('_adm_fields_minimum_value'),
591  'type' => 'text',
592  'info' => addslashes(_t('_adm_fields_minimum_value_desc')),
593  'value' => $aField['Min'],
594  'row_id' => 'field_minimum'
595  ),
596  'Max' => array(
597  'label' => _t('_adm_fields_maximum_value'),
598  'type' => 'text',
599  'info' => addslashes(_t('_adm_fields_maximum_value_desc')),
600  'value' => $aField['Max'],
601  'row_id' => 'field_maximum'
602  ),
603  'Unique' => array(
604  'label' => _t('_adm_fields_unique'),
605  'type' => 'checkbox',
606  'info' => addslashes(_t('_adm_fields_unique_desc')),
607  'value' => $aField['Unique'],
608  'row_id' => 'field_unique'
609  ),
610  'Check' => array(
611  'label' => _t('_adm_ambuilder_Check'),
612  'type' => 'textarea',
613  'info' => addslashes(_t('_adm_ambuilder_Check_desc')),
614  'value' => $aField['Check'],
615  'row_id' => 'field_check'
616  ),
617  'Values' => array(
618  'label' => _t('_adm_fields_possible_values'),
619  'type' => 'values',
620  'info' => addslashes(_t('_adm_fields_possible_values_desc')),
621  'value' => $aField['Values'],
622  'row_id' => 'field_values'
623  ),
624  'UseLKey' => array(
625  'label' => _t('_adm_fields_used_lang_key'),
626  'type' => 'select',
627  'info' => addslashes(_t('_adm_fields_used_lang_key_desc')),
628  'value' => $aField['UseLKey'],
629  'row_id' => 'field_lkey',
630  'values' => array(
631  'LKey' => 'LKey',
632  'LKey2' => 'LKey2',
633  'LKey3' => 'LKey3',
634  )
635  ),
636  'Default' => array(
637  'label' => _t('_adm_fields_default_value'),
638  'type' => 'text',
639  'info' => addslashes(_t('_adm_fields_default_value_desc')),
640  'value' => $aField['Default'],
641  'row_id' => 'field_default'
642  )
643  );
644 
645  $this -> genTableEdit( $aForm, 'f2' );
646  }
647 
648  function genTableEdit( $aForm, $sID = '' )
649  {
650  ?>
651  <table class="field_edit_tab" <?= $sID ? ( 'id="' . $sID . '"' ) : '' ?>>
652 
653  <?php
654  foreach( $aForm as $sInputName => $aInput ) {
655  ?>
656  <tr <?= $aInput['row_id'] ? ( 'id="' . $aInput['row_id'] . '"' ) : '' ?>>
657  <td class="label"><?= $aInput['label'] ?>:</td>
658  <td class="value">
659  <?php
660  switch( $aInput['type'] ) {
661  case 'textarea':
662  ?>
663  <textarea name="<?= $sInputName ?>" class="input_text"><?= htmlspecialchars( $aInput['value'] ) ?></textarea>
664  <?php
665  break;
666  case 'checkbox':
667  ?>
668  <input type="checkbox" name="<?= $sInputName ?>" value="yes" class="input_checkbox"
669  <?= $aInput['value'] ? 'checked="checked"' : '' ?> />
670  <?php
671  break;
672  case 'text':
673  ?>
674  <input type="text" name="<?= $sInputName ?>" value="<?= htmlspecialchars( $aInput['value'] ) ?>" class="input_text" />
675  <?php
676  break;
677  case 'select':
678  ?>
679  <select name="<?= $sInputName ?>" class="select_type">
680  <?php
681  foreach( $aInput['values'] as $sKey => $sValue ) {
682  ?>
683  <option value="<?= $sKey ?>" <?= ( $sKey == $aInput['value'] ) ? 'selected="selected"' : '' ?>><?= $sValue ?></option>
684  <?php
685  }
686  ?>
687  </select>
688  <?php
689  break;
690  case 'values':
691  if( substr( $aInput['value'], 0, 2 ) == $this -> sLinkPref ) { //it is link
692  $sLink = substr( $aInput['value'], 2 );
693  ?>
694  <input type="hidden" name="<?= $sInputName ?>" value="<?= htmlspecialchars( $aInput['value'] ) ?>" />
695  <a href="preValues.php?list=<?= urlencode( $sLink ) ?>" target="_blank"
696  onclick="return !window.open( this.href + '&popup=1', 'preValuesEdit', 'width=635,height=700,resizable=yes,scrollbars=yes,toolbar=no,status=no,menubar=no' );"
697  title="Edit list"><?= $sLink ?></a>
698 
699  <a href="javascript:void(0);" onclick="activateValuesEdit( this );" title="Change link" style="margin-left:20px;">
700  <img src="../templates/base/images/icons/edit.gif" alt="Change" />
701  </a>
702  <?php
703  } else { //it is simple list
704  ?>
705  <textarea class="input_text" name="<?= $sInputName ?>"><?= htmlspecialchars( $aInput['value'] ) ?></textarea>
706  <?php
707  }
708  break;
709  }
710  ?>
711  </td>
712  <td class="info">
713  <?= $this -> getInfoIcon( $aInput['info'] ) ?>
714  </td>
715  </tr>
716  <?php
717  }
718  ?>
719 
720  </table>
721  <?php
722  }
723 
724  //used for parsing extra parameters
725  function parseParams( $sParams )
726  {
727  if( $sParams == '' )
728  return array();
729 
730  $aParams = array();
731 
732  $aParamLines = explode( "\n", $sParams );
733 
734  foreach( $aParamLines as $sLine ) {
735  list( $sKey, $sValue) = explode( ':', $sLine, 2 );
736  $aParams[$sKey] = $sValue;
737  }
738 
739  return $aParams;
740  }
741 
742  function genFormMiscTab( $aField )
743  {
744  $aForm = array(
745  'Mandatory_msg' => array(
746  'label' => _t('_adm_fields_mandatory_error_message'),
747  'type' => 'textarea',
748  'info' => addslashes(_t('_adm_fields_mandatory_error_message_desc', $aField['Name'])),
749  'value' => $this -> getLangString( "_FieldError_{$aField['Name']}_Mandatory" ),
750  /*'row_id' => 'field_mandatory_msg'*/
751  ),
752  'Min_msg' => array(
753  'label' => _t('_adm_fields_minimum_exceed_error_message'),
754  'type' => 'textarea',
755  'info' => addslashes(_t('_adm_fields_minimum_exceed_error_message_desc', $aField['Name'])),
756  'value' => $this -> getLangString( "_FieldError_{$aField['Name']}_Min" ),
757  'row_id' => 'field_minimum_msg'
758  ),
759  'Max_msg' => array(
760  'label' => _t('_adm_fields_maximum_exceed_error_message'),
761  'type' => 'textarea',
762  'info' => addslashes(_t('_adm_fields_maximum_exceed_error_message_desc', $aField['Name'])),
763  'value' => $this -> getLangString( "_FieldError_{$aField['Name']}_Max" ),
764  'row_id' => 'field_maximum_msg'
765  ),
766  'Unique_msg' => array(
767  'label' => _t('_adm_fields_non_unique_error_message'),
768  'type' => 'textarea',
769  'info' => addslashes(_t('_adm_fields_non_unique_error_message_desc', $aField['Name'])),
770  'value' => $this -> getLangString( "_FieldError_{$aField['Name']}_Unique" ),
771  'row_id' => 'field_unique_msg'
772  ),
773  'Check_msg' => array(
774  'label' => _t('_adm_fields_check_error_message'),
775  'type' => 'textarea',
776  'info' => addslashes(_t('_adm_fields_check_error_message_desc', $aField['Name'])),
777  'value' => $this -> getLangString( "_FieldError_{$aField['Name']}_Check" ),
778  'row_id' => 'field_check_msg'
779  )
780  );
781 
782  $this -> genTableEdit( $aForm, 'f3' );
783  }
784 
785  function getInfoIcon( $sText )
786  {
787  return '
788  <img src="../templates/base/images/icons/info.gif" class="info_icon"
789  onmouseover="showFloatDesc(\'' . htmlspecialchars( $sText ) . '\');"
790  onmousemove="moveFloatDesc( event )"
791  onmouseout="hideFloatDesc();" />
792  ';
793  }
794 
795  function getTypeOptions( $sActive )
796  {
797  $sRet = '';
798 
799  foreach( $this -> aTypes as $sKey => $sValue ) {
800  $sRet .= '<option value="' . $sKey . '" ' . ( $sActive == $sKey ? 'selected="selected"' : '') . '>' . $sValue . '</option>';
801  }
802 
803  return $sRet;
804  }
805 
806  function getLangString( $sKey )
807  {
808  if( $sKey == '' )
809  return '';
810 
811  $sQuery = "SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = ?";
812  $iKeyID = (int)db_value( $sQuery , [$sKey]);
813 
814  if( !$iKeyID )
815  return '';
816 
817  $sQuery = "
818  SELECT `String` FROM `sys_localization_strings`
819  WHERE `IDKey` = $iKeyID AND `IDLanguage` = {$this -> sLangID}";
820 
821  return (string)db_value( $sQuery );
822  }
823 
824  function saveItem( $aData )
825  {
826  $this -> genSaveItemHeader();
827  $this -> isHaveErrors = false;
828  //echoDbg( $aData );
829  $iItemID = (int)$aData['id'];
830 
831  $aItem = db_assoc_arr( "SELECT * FROM `sys_profile_fields` WHERE `ID` = $iItemID" );
832 
833  if( !$aItem ) {
834  $this -> genSaveItemError(_t('_adm_fields_warning_field_not_found'));
835  $this -> genSaveItemFooter();
836  return false;
837  }
838 
839  // just a flag
840  $bHaveErrors = false;
841 
842  // this array will be put into db
843  $aUpdate = array();
844 
845  // check name
846  if( $aItem['Type'] != 'system' and $aItem['Deletable'] ) { //we can change the name
847 
848  $sName = trim( strip_tags( process_pass_data( $aData['Name'] ) ) );
849 
850  $aReservedNames = array('starttime', 'youremail', 'reg_email', 'reg_name', 'reg_nickname');
851 
852  if( $sName === '' ) {
853  $this -> genSaveItemError( _t('_adm_fields_error_you_must_enter_name'), 'Name' );
854  $bHaveErrors = true;
855  } elseif( in_array($sName, $aReservedNames) ) {
856  $this -> genSaveItemError( _t('_adm_fields_error_reserved_name'), 'Name' );
857  $bHaveErrors = true;
858  } elseif( $aItem['Type'] != 'block' and !preg_match( '/^[a-z][a-z0-9_]*$/i', $sName ) ) {
859  $this -> genSaveItemError( _t('_adm_fields_error_name_latin'), 'Name' );
860  $bHaveErrors = true;
861  } elseif($GLOBALS['MySQL']->getOne("SELECT COUNT(*) FROM `sys_profile_fields` WHERE `Name`='" . $sName . "' AND `ID`<>'" . $iItemID . "'") || ($sName != $aItem['Name'] && $GLOBALS['MySQL']->isFieldExists('Profiles', $sName))) {
862  $this -> genSaveItemError( _t('_adm_fields_error_name_already_exists'), 'Name' );
863  $bHaveErrors = true;
864  } elseif( $sName == $aItem['Name'] ) {
865  // all ok. don't change
866  } else
867  $aUpdate['Name'] = $sName; //change
868  }
869 
870  $sNewName = isset( $aUpdate['Name'] ) ? $aUpdate['Name'] : $aItem['Name'];
871 
872  $this -> fieldCaption = "_FieldCaption_{$sNewName}_{$this -> areaPageName}"; // _FieldCaption_Sex_Join
873  $this -> fieldDesc = "_FieldDesc_{$sNewName}_{$this -> areaPageName}"; // _FieldDesc_Sex_Join
874 
875  // check Caption
876  $sCaption = trim( process_pass_data( $aData['Caption'] ) );
877 
878  if( $sCaption === '' ) {
879  $this -> genSaveItemError( _t('_adm_fields_error_you_must_enter_caption'), 'Caption' );
880  $bHaveErrors = true;
881  } elseif( $this -> getLangString( $this -> fieldCaption ) == $sCaption ) {
882  // all ok dont change
883  } else
884  $this -> updateLangString( $this -> fieldCaption, $sCaption );
885 
886  // check Description
887  $sDesc = trim( process_pass_data( $aData['Desc'] ) );
888  if( $this -> getLangString( $this -> fieldDesc ) != $sDesc )
889  $this -> updateLangString( $this -> fieldDesc, $sDesc );
890 
891  // check type
892  if( $aItem['Type'] != 'system' and $aItem['Type'] != 'block' ) {
893 
894  //we can change the type
895  $sType = trim( strip_tags( process_pass_data( $aData['Type'] ) ) );
896 
897  if( !isset( $this -> aTypes[$sType] ) ) {
898  $this -> genSaveItemError( _t('_adm_fields_error_i_dont_know_this_type'), 'Type' );
899  $bHaveErrors = true;
900  } elseif( $sType == $aItem['Type'] ) {
901  // all ok. don't change
902  } else
903  $aUpdate['Type'] = $sType; //change
904 
905  // check the additional properties
906  if( !$bHaveErrors ) { // do not continue if have errors
907 
908  // check selectors controls
909  if( $sType == 'select_one' ) {
910  if( $aData['Control_one'] == $aItem['Control'] ) {
911  //all ok
912  } elseif( $aData['Control_one'] == 'select' or $aData['Control_one'] == 'radio' ) {
913  $aUpdate['Control'] = $aData['Control_one'];
914  } else {
915  $this -> genSaveItemError( _t('_adm_fields_error_i_dont_know_this_control_type'), 'Control_one' );
916  $bHaveErrors = true;
917  }
918  } elseif( $sType == 'select_set' ) {
919  if( $aData['Control_set'] == $aItem['Control'] ) {
920  //all ok
921  } elseif( $aData['Control_set'] == 'select' or $aData['Control_set'] == 'checkbox' ) {
922  $aUpdate['Control'] = $aData['Control_set'];
923  } else {
924  $this -> genSaveItemError( _t('_adm_fields_error_i_dont_know_this_control_type'), 'Control_set' );
925  $bHaveErrors = true;
926  }
927  } else
928  $aUpdate['Control'] = null;
929 
930  //check Min
931  $iMin = trim($aData['Min']);
932  if($iMin === '' || $sType == 'bool' || $sType == 'select_one' || $sType == 'select_set')
933  $iMin = null;
934  else {
935  $iMin = (int)$iMin;
936  if(($sType == 'area' || $sType == 'html_area') && $iMin > 65534)
937  $iMin = 65534;
938  else if($sType != 'area' && $sType != 'html_area' && $iMin > 254)
939  $iMin = 254;
940  else if($iMin < 0)
941  $iMin = 0;
942  }
943  $aUpdate['Min'] = $iMin;
944 
945  //check Max
946  $iMax = trim($aData['Max']);
947  if($iMax === '' || $sType == 'bool' || $sType == 'select_one' || $sType == 'select_set' )
948  $iMax = null;
949  else {
950  $iMax = (int)$iMax;
951  if(($sType == 'area' || $sType == 'html_area') && $iMax > 65534)
952  $iMax = 65534;
953  else if($sType != 'area' && $sType != 'html_area' && $iMax > 254)
954  $iMax = 254;
955  else if($iMax < 0)
956  $iMax = 0;
957  }
958  $aUpdate['Max'] = $iMax;
959 
960  // set min and max search age
961  if( $sNewName == 'DateOfBirth' )
962  $this -> setMinMaxAge( ( $iMin ? $iMin : 18 ), ( $iMax ? $iMax : 75 ) );
963 
964  //check Check :)
965  if( $sType == 'select_one' or $sType == 'select_set' or $sType == 'bool' )
966  $aUpdate['Check'] = '';
967  else {
968  $sCheck = trim( process_pass_data( $aData['Check'] ) );
969 
970  if( $aItem['Check'] != $sCheck )
971  $aUpdate['Check'] = $sCheck;
972  }
973 
974  //Unique
975  $aUpdate['Unique'] = (
976  isset( $aData['Unique'] ) and
977  $aData['Unique'] == 'yes' and
978  ( $sType == 'text' or $sType == 'area' or $sType == 'html_area' or $sType == 'num' )
979  ) ? 1 : 0;
980 
981  //Mandatory
982  $aUpdate['Mandatory'] = ( isset( $aData['Mandatory'] ) and $aData['Mandatory'] == 'yes' ) ? 1 : 0;
983 
984  //check Values
985  if( $sType == 'select_one' or $sType == 'select_set' ) {
986  $sValues = trim( strip_tags( process_pass_data( $aData['Values'] ) ) );
987 
988  $sValues = str_replace( ",", "", $sValues ); // commas aren't allowed
989 
990  $sValues = str_replace( "\r", "\n", $sValues ); // for mac
991  $sValues = str_replace( "\n\n", "\n", $sValues ); // for win
992  ; // for *nix ;)
993 
994  if( $sValues === '' ) {
995  $this -> genSaveItemError( _t('_adm_fields_error_you_must_enter_values'), 'Values' );
996  $bHaveErrors = true;
997  } elseif( $sValues != $aItem['Values'] ) {
998  if( substr( $sValues, 0, 2 ) == $this -> sLinkPref and !$this -> checkValuesLink( substr( $sValues, 2 ) ) ) {
999  $this -> genSaveItemError( _t('_adm_fields_error_you_entered_incorrect_link'), 'Values' );
1000  $bHaveErrors = true;
1001  } else
1002  $aUpdate['Values'] = $sValues;
1003  }
1004 
1005  // get LKey
1006  $sUseLKey = trim( process_pass_data( $aData['UseLKey'] ) );
1007  if( !$sUseLKey )
1008  $sUseLKey = 'LKey';
1009 
1010  $aUpdate['UseLKey'] = $sUseLKey;
1011 
1012  if( substr( $sValues, 0, 2 ) != $this -> sLinkPref ) { // if not a link
1013  //Add Lang key for each value: _FieldValues_Example
1014 
1015  $aValues2LF = explode("\n", $sValues);
1016  foreach ( $aValues2LF as $sValues2LF ) {
1017  $sLFKey = '_FieldValues_' . $sValues2LF;
1018  $sLFValue = $sValues2LF;
1019  //print "{$sLFKey}<br />";
1020  if( $this -> getLangString( $sLFKey ) != $sLFValue )
1021  $this -> updateLangString( $sLFKey, $sLFValue );
1022  }
1023  }
1024 
1025  } elseif( $aItem['Values'] != '' )
1026  $aUpdate['Values'] = '';
1027 
1028  if( !$bHaveErrors ) {
1029  //Default
1030  switch( $sType ) {
1031  case 'text':
1032  $aUpdate['Default'] = trim( process_pass_data( $aData['Default'] ) );
1033  break;
1034  case 'pass':
1035  case 'area':
1036  case 'html_area':
1037  case 'select_set':
1038  $aUpdate['Default'] = '';
1039  break;
1040  case 'num':
1041  $aUpdate['Default'] = (int)$aData['Default'];
1042  break;
1043  case 'bool':
1044  $aUpdate['Default'] = (int)(bool)$aData['Default'];
1045  break;
1046  case 'range':
1047  if( trim( $aData['Default'] ) == '' )
1048  $aUpdate['Default'] = '';
1049  else {
1050  list( $sFirst, $sSecond ) = explode( '-', trim( $aData['Default'], 2 ) );
1051  $sFirst = (int)trim( $sFirst );
1052  $sSecond = (int)trim( $sSecond );
1053  $aUpdate['Default'] = "$sFirst-$sSecond";
1054  }
1055  break;
1056  case 'date':
1057  if( $aData['Default'] === '' )
1058  $aUpdate['Default'] = '';
1059  else
1060  $aUpdate['Default'] = date( 'Y-m-d', strtotime( trim( process_pass_data( $aData['Default'] ) ) ) );
1061  break;
1062 
1063  case 'select_one':
1064  $sDefault = trim( process_pass_data( $aData['Default'] ) );
1065  if( $sDefault === '' )
1066  $aUpdate['Default'] = '';
1067  else {
1068  if( $this -> checkSelectDefault( $sValues, $sDefault ) )
1069  $aUpdate['Default'] = $sDefault;
1070  else {
1071  $this -> genSaveItemError(_t('_adm_fields_error_you_entered_incorrect_value'), 'Default' );
1072  $bHaveErrors = true;
1073  }
1074  }
1075  break;
1076  }
1077 
1078  //matching. not implemented yet
1079  }
1080  }
1081  }
1082 
1083  if( $aItem['Type'] == 'block' and $this -> iAreaID == 1 ) { //Join
1084  //get JoinPage
1085  $iJoinPage = (int)$aData['JoinPage'];
1086  if( $aItem['JoinPage'] != $iJoinPage )
1087  $aUpdate['JoinPage'] = $iJoinPage;
1088  }
1089 
1090  //system fields properties
1091  if( $aItem['Name'] == 'Keyword' ) {
1092  if( is_array( $aData['KeywordFields'] ) ) {
1093  $sKeywordFields = implode( "\n", $aData['KeywordFields'] );
1094 
1095  if( process_pass_data( $sKeywordFields ) != $aItem['Extra'] )
1096  $aUpdate['Extra'] = $sKeywordFields;
1097  }
1098  }
1099 
1100  if( $aItem['Name'] == 'Couple' ) {
1101  if( is_array( $aData['CoupleFields'] ) ) {
1102  $sKeywordFields = implode( "\n", $aData['CoupleFields'] );
1103 
1104  if( process_pass_data( $sKeywordFields ) != $aItem['Extra'] )
1105  $aUpdate['Extra'] = $sKeywordFields;
1106  }
1107  }
1108 
1109  // update error messages
1110  foreach( array( 'Mandatory', 'Min', 'Max', 'Unique', 'Check' ) as $sErrName ) {
1111  $sErrMsg = trim( process_pass_data( $aData[$sErrName . '_msg'] ) );
1112  if( empty($sErrMsg) )
1113  continue;
1114 
1115  $sErrKey = "_FieldError_{$sNewName}_{$sErrName}";
1116 
1117  $this -> updateLangString( $sErrKey, $sErrMsg );
1118  }
1119 
1120  // add matching
1121  if( isset( $aData['MatchField'] ) and (int)$aData['MatchField'] != $aItem['MatchField'] )
1122  $aUpdate['MatchField'] = (int)$aData['MatchField'];
1123 
1124  if( isset( $aData['MatchPercent'] ) and (int)$aData['MatchPercent'] != $aItem['MatchPercent'] )
1125  $aUpdate['MatchPercent'] = (int)$aData['MatchPercent'];
1126 
1127  if( !empty( $aUpdate ) and !$bHaveErrors ) {
1128  $this -> doUpdateItem( $aItem, $aUpdate );
1129  if( isset( $aUpdate['Name'] ) )
1130  $this -> genSaveItemFormUpdate( 'updateItem', $iItemID, $aUpdate['Name'] );
1131 
1132  if( $aItem['Type'] == 'block' and $aUpdate['Name'] ) {
1133  $sQuery = "
1134  UPDATE `sys_page_compose` SET
1135  `Caption` = '_FieldCaption_" . $GLOBALS['MySQL']->escape( $sNewName, false ) . "_View'
1136  WHERE
1137  `Func` = 'PFBlock' AND
1138  `Content` = '$iItemID'
1139  ";
1140 
1141  db_res( $sQuery );
1142  }
1143  }
1144 
1145  if( !$bHaveErrors )
1146  $this -> genSaveItemFormClose();
1147 
1148  $this -> genSaveItemFooter();
1149  }
1150 
1151  function setMinMaxAge( $iMin, $iMax )
1152  {
1153  setParam( 'search_start_age', $iMin );
1154  setParam( 'search_end_age', $iMax );
1155  }
1156 
1157  function checkValuesLink( $sKey )
1158  {
1159  global $aPreValues;
1160 
1161  return isset( $aPreValues[$sKey] );
1162  }
1163 
1164  function checkSelectDefault( $sValues, $sDefault )
1165  {
1166  global $aPreValues;
1167 
1168  if( substr( $sValues, 0, 2 ) == $this -> sLinkPref ) { //it is link
1169  $sKey = substr( $sValues, 2 );
1170  return isset( $aPreValues[$sKey][$sDefault] );
1171  } else {
1172  $aValues = explode( "\n", $sValues );
1173  return in_array( $sDefault, $aValues );
1174  }
1175  }
1176 
1177  function doUpdateItem( $aItem, $aUpdate )
1178  {
1179  global $aPreValues;
1180 
1181  $aUpdateStrs = array();
1182  foreach( $aUpdate as $sKey => $sValue ) {
1183  if( is_null( $sValue ) )
1184  $aUpdateStrs[] = "`$sKey` = NULL";
1185  else
1186  $aUpdateStrs[] = "`$sKey` = {$GLOBALS['MySQL']->escape( $sValue )}";
1187  }
1188 
1189  $sQuery = "
1190  UPDATE `sys_profile_fields` SET
1191  " . implode( ",
1192  ", $aUpdateStrs ) . "
1193  WHERE `ID` = {$aItem['ID']}";
1194 
1195  db_res( $sQuery );
1196 
1197  if( //we need alter Profiles table
1198  $aItem['Type'] != 'block' and (
1199  isset( $aUpdate['Type'] ) or
1200  isset( $aUpdate['Name'] ) or
1201  isset( $aUpdate['Values'] ) or
1202  isset( $aUpdate['Default'] )
1203  )
1204  ) {
1205  $aAlter = array(
1206  'Type' => isset( $aUpdate['Type'] ) ? $aUpdate['Type'] : $aItem['Type'],
1207  'Name' => isset( $aUpdate['Name'] ) ? $aUpdate['Name'] : $aItem['Name'],
1208  'Values' => isset( $aUpdate['Values'] ) ? $aUpdate['Values'] : $aItem['Values'],
1209  'Default' => isset( $aUpdate['Default'] ) ? $aUpdate['Default'] : $aItem['Default'],
1210  );
1211 
1212  if( substr( $aAlter['Values'], 0, 2 ) == $this -> sLinkPref )
1213  $aAlter['Type'] .= '_linked';
1214 
1215  $sQuery = "ALTER TABLE `Profiles` CHANGE `{$aItem['Name']}` `{$aAlter['Name']}` {$this -> aTypesAlter[$aAlter['Type']]}";
1216  $sReplacedVal = ($aAlter['Default'] != '') ? "default '" . $GLOBALS['MySQL']->escape( $aAlter['Default'], false ) . "'" : "";
1217  $sQuery = str_replace( '{default}', $sReplacedVal, $sQuery );
1218 
1219  if( $aAlter['Type'] == 'select_one' or $aAlter['Type'] == 'select_set' ) { //insert values
1220  $aValuesAlter = explode( "\n", $aAlter['Values'] ); //explode values to array
1221 
1222  foreach( $aValuesAlter as $iKey => $sValue ){ //add slashes to every value
1223  $sValue = str_replace( '\\', '\\\\', $sValue );
1224  $sValue = str_replace( '\'', '\\\'', $sValue );
1225  $aValuesAlter[$iKey] = $sValue;
1226  }
1227 
1228  $sValuesAlter = " '" . implode( "', '", $aValuesAlter ) . "' "; // implode values to string like 'a','b','c\'d'
1229  $sQuery = str_replace( '{values}', $sValuesAlter, $sQuery ); //replace it in place
1230  } elseif( $aAlter['Type'] == 'select_set_linked' ) {
1231  $sLink = substr( $aAlter['Values'], 2 );
1232  $aValuesAlter = array_keys( $aPreValues[$sLink] );
1233 
1234  $sValuesAlter = implode( ', ', $aValuesAlter );
1235  $sValuesAlter = str_replace( '\\', '\\\\', $sValuesAlter );
1236  $sValuesAlter = str_replace( '\'', '\\\'', $sValuesAlter );
1237 
1238  $sValuesAlter = "'" .str_replace( ', ', "', '", $sValuesAlter ) ."'";
1239 
1240  $sQuery = str_replace( '{values}', $sValuesAlter, $sQuery ); //replace it in place
1241  }
1242 
1243  db_res( $sQuery );
1244  }
1245  }
1246 
1247  function createNewField()
1248  {
1249  $iNewID = 0;
1250 
1251  //try to insert new item
1252  if( db_res( "INSERT INTO `sys_profile_fields` (`Name`, `Type` ) VALUES ('NEW_ITEM', 'text')", 0 ) and $iNewID = db_last_id() ) {
1253  //if success - try to alter table
1254  if( !db_res( "ALTER TABLE `Profiles` ADD `NEW_ITEM` varchar(255) NOT NULL default ''", 0 ) ) {
1255  //if couldn't alter - delete inserted field
1256  db_res( "DELETE FROM `sys_profile_fields` WHERE `ID` = $iNewID" );
1257  $iNewID = 0;
1258  }
1259  }
1260 
1261  return $iNewID;
1262  }
1263 
1264  function createNewBlock()
1265  {
1266  db_res( "INSERT INTO `sys_profile_fields` (`Name`, `Type` ) VALUES ('NEW BLOCK', 'block')", 0 );
1267  $iNewID = db_last_id();
1268 
1269  db_res( "
1270  INSERT INTO `sys_page_compose`
1271  ( `Desc`, `Caption`, `Visible`, `Func`, `Content`, `Page` )
1272  VALUES
1273  ( 'Profile Fields Block', '_FieldCaption_NEW BLOCK_View', 'non,memb', 'PFBlock', '$iNewID', 'profile' )
1274  " );
1275 
1276  db_res( "
1277  INSERT INTO `sys_page_compose`
1278  ( `Desc`, `Caption`, `Visible`, `Func`, `Content`, `Page` )
1279  VALUES
1280  ( 'Profile Fields Block', '_FieldCaption_NEW BLOCK_View', 'non,memb', 'PFBlock', '$iNewID', 'profile_info' )
1281  " );
1282 
1283  return $iNewID;
1284  }
1285 
1286  function updateLangString( $sKey, $sString )
1287  {
1288  if( $sKey == '' )
1289  return false;
1290 
1291  $sQuery = "SELECT `ID` FROM `sys_localization_keys` WHERE `Key` = ?";
1292  $iKeyID = (int)db_value( $sQuery, [$sKey]);
1293 
1294  if( !$iKeyID ) { //create key
1295  $sQuery = "INSERT INTO `sys_localization_keys` (`IDCategory`,`Key`) VALUES (?, ?)";
1296  db_res( $sQuery, [32, $sKey]);
1297  $iKeyID = db_last_id();
1298  }
1299 
1300  $sQuery = "
1301  SELECT COUNT( * ) FROM `sys_localization_strings`
1302  WHERE `IDKey` = $iKeyID AND `IDLanguage` = {$this -> sLangID}";
1303 
1304  $iCount = (int)db_value( $sQuery );
1305 
1306  if( $iCount ) {
1307  $sQuery = "
1308  UPDATE `sys_localization_strings`
1309  SET `String` = ?
1310  WHERE `IDKey` = ? AND `IDLanguage` = ?";
1311 
1312  db_res( $sQuery, [$sString, $iKeyID, $this->sLangID] );
1313  } else {
1314  $sQuery = "INSERT INTO `sys_localization_strings` VALUES ( ?, ?, ? )";
1315  db_res( $sQuery, [$iKeyID, $this->sLangID, $sString]);
1316  }
1317 
1318  compileLanguage( $this -> sLangID );
1319  }
1320 
1322  {
1323  ?>
1324 <html><script type="text/javascript">
1325  <?php
1326  }
1327 
1328  function genSaveItemError( $sText, $sField = '' )
1329  {
1330  $this -> isHaveErrors = true;
1331 
1332  if( !$sField )
1333  echo "alert( '" . addslashes( $sText ) . "' );";
1334  else {
1335  ?>
1336  parent.genEditFormError( '<?= $sField ?>', '<?= addslashes( $sText ) ?>' );
1337  <?php
1338  }
1339  }
1340 
1342  {
1343  ?>
1344 
1345 </script></html>
1346  <?php
1347  }
1348 
1349  function deleteItem( $iItemID )
1350  {
1351  $this -> genSaveItemHeader();
1352 
1353  $aItem = db_assoc_arr( "SELECT * FROM `sys_profile_fields` WHERE `ID` = $iItemID" );
1354 
1355  if( !$aItem )
1356  $this -> genSaveItemError(_t('_adm_fields_warning_item_not_found'));
1357  elseif( $aItem['Type'] == 'system' or !(int)$aItem['Deletable'] )
1358  $this -> genSaveItemError(_t('_adm_fields_error_field_cannot_be_deleted'));
1359  else{
1360  $sQuery = "DELETE FROM `sys_profile_fields` WHERE `ID` = $iItemID";
1361  db_res( $sQuery );
1362 
1363  if( $aItem['Type'] == 'block' )
1364  db_res( "DELETE FROM `sys_page_compose` WHERE `Func` = 'PFBlock' AND `Content` = '$iItemID'" );
1365  else
1366  db_res( "ALTER TABLE `Profiles` DROP `{$aItem['Name']}`" );
1367 
1368  $this -> genSaveItemFormUpdate( 'deleteItem', $iItemID );
1369  //$this -> genSaveItemFormClose();
1370  }
1371  $this -> genSaveItemFooter();
1372  }
1373 
1374  function genSaveItemFormUpdate( $sText, $iItemID, $sNewName = '' )
1375  {
1376  ?>
1377  parent.updateBuilder( '<?= $sText ?>', <?= $iItemID ?>, '<?= addslashes( $sNewName ) ?>' );
1378  <?php
1379  }
1380 
1382  {
1383  ?>
1384  parent.hideEditForm();
1385  <?php
1386  }
1387 }
1388 
1390 {
1391  function __construct( $oArea )
1392  {
1393  $this -> id = $oArea -> iAreaID;
1394 
1395  $this -> active_blocks = array();
1396  $this -> inactive_blocks = array();
1397  $this -> active_items = array();
1398  $this -> inactive_items = array();
1399 
1400  foreach( $oArea -> aBlocks as $iID => $sName )
1401  $this -> active_blocks[] = new ChWsbPFMItem( $iID, $sName );
1402 
1403  foreach( $oArea -> aItems as $iID => $aItem )
1404  $this -> active_items[] = new ChWsbPFMItem( $iID, $aItem[0], $aItem[1] );
1405 
1406  foreach( $oArea -> aBlocksInac as $iID => $sName )
1407  $this -> inactive_blocks[] = new ChWsbPFMItem( $iID, $sName );
1408 
1409  foreach( $oArea -> aItemsInac as $iID => $sName )
1410  $this -> inactive_items[] = new ChWsbPFMItem( $iID, $sName );
1411  }
1412 }
1413 
1414 /* Used for JSON generation */
1416 {
1417  function __construct( $iID, $sName, $iBlock = 0 )
1418  {
1419  $this -> id = $iID;
1420  $this -> name = $sName;
1421 
1422  $this -> block = $iBlock;
1423  }
1424 }
1425 
1426 
1427 
1432 {
1434 
1435  function __construct()
1436  {
1437  //additional properties for caching blocks
1438  $aAddBlockProps = array(
1439  'Join' => array(
1440  'Caption' => '_FieldCaption_{Name}_Join',
1441  //'Desc' => '_FieldDesc_{Name}_Join'
1442  ),
1443  'Edit' => array(
1444  'Caption' => '_FieldCaption_{Name}_Edit',
1445  //'Desc' => '_FieldDesc_{Name}_Edit'
1446  ),
1447  'View' => array(
1448  'Caption' => '_FieldCaption_{Name}_View',
1449  //'Desc' => '_FieldDesc_{Name}_View'
1450  ),
1451  'Search' => array(
1452  'Caption' => '_FieldCaption_{Name}_Search',
1453  //'Desc' => '_FieldDesc_{Name}_Search'
1454  )
1455  );
1456 
1457  //additional properties for caching items
1458  $aAddProps = array(
1459  'Join' => array(
1460  'Caption' => '_FieldCaption_{Name}_Join',
1461  'Desc' => '_FieldDesc_{Name}_Join',
1462  'MandatoryMsg' => '_FieldError_{Name}_Mandatory',
1463  'MinMsg' => '_FieldError_{Name}_Min',
1464  'MaxMsg' => '_FieldError_{Name}_Max',
1465  'UniqueMsg' => '_FieldError_{Name}_Unique',
1466  'CheckMsg' => '_FieldError_{Name}_Check'
1467  ),
1468  'Edit' => array(
1469  'Caption' => '_FieldCaption_{Name}_Edit',
1470  'Desc' => '_FieldDesc_{Name}_Edit',
1471  'MandatoryMsg' => '_FieldError_{Name}_Mandatory',
1472  'MinMsg' => '_FieldError_{Name}_Min',
1473  'MaxMsg' => '_FieldError_{Name}_Max',
1474  'UniqueMsg' => '_FieldError_{Name}_Unique',
1475  'CheckMsg' => '_FieldError_{Name}_Check'
1476  ),
1477  'View' => array(
1478  'Caption' => '_FieldCaption_{Name}_View',
1479  'Desc' => '_FieldDesc_{Name}_View'
1480  ),
1481  'Search' => array(
1482  'Caption' => '_FieldCaption_{Name}_Search',
1483  'Desc' => '_FieldDesc_{Name}_Search'
1484  )
1485  );
1486 
1487  $this -> aAreasProps = array (
1488  1 => array( 'Title' => 'Join', 'Order' => 'JoinOrder', 'Block' => 'JoinBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,Check,Unique,Mandatory,UseLKey,Default', 'AddBlockProps' => $aAddBlockProps['Join'], 'AddProps' => $aAddProps['Join'] ),
1489 
1490  2 => array( 'Title' => 'Edit (Owner)', 'Order' => 'EditOwnOrder', 'Block' => 'EditOwnBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,Check,Unique,Mandatory,UseLKey', 'AddBlockProps' => $aAddBlockProps['Edit'], 'AddProps' => $aAddProps['Edit'] ),
1491  3 => array( 'Title' => 'Edit (Admin)', 'Order' => 'EditAdmOrder', 'Block' => 'EditAdmBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,Check,Unique,Mandatory,UseLKey', 'AddBlockProps' => $aAddBlockProps['Edit'], 'AddProps' => $aAddProps['Edit'] ),
1492  4 => array( 'Title' => 'Edit (Moder)', 'Order' => 'EditModOrder', 'Block' => 'EditModBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,Check,Unique,Mandatory,UseLKey', 'AddBlockProps' => $aAddBlockProps['Edit'], 'AddProps' => $aAddProps['Edit'] ),
1493 
1494  5 => array( 'Title' => 'View (Admin)', 'Order' => 'ViewAdmOrder', 'Block' => 'ViewAdmBlock', 'AddSelect' => 'Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['View'], 'AddProps' => $aAddProps['View'] ),
1495  6 => array( 'Title' => 'View (Member)', 'Order' => 'ViewMembOrder', 'Block' => 'ViewMembBlock', 'AddSelect' => 'Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['View'], 'AddProps' => $aAddProps['View'] ),
1496  7 => array( 'Title' => 'View (Moder)', 'Order' => 'ViewModOrder', 'Block' => 'ViewModBlock', 'AddSelect' => 'Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['View'], 'AddProps' => $aAddProps['View'] ),
1497  8 => array( 'Title' => 'View (Visitor)', 'Order' => 'ViewVisOrder', 'Block' => 'ViewVisBlock', 'AddSelect' => 'Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['View'], 'AddProps' => $aAddProps['View'] ),
1498 
1499  9 => array( 'Title' => 'Search (Simple)', 'Order' => 'SearchSimpleOrder', 'Block' => 'SearchSimpleBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['Search'], 'AddProps' => $aAddProps['Search'] ),
1500  10 => array( 'Title' => 'Search (Quick)', 'Order' => 'SearchQuickOrder', 'Block' => 'SearchQuickBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['Search'], 'AddProps' => $aAddProps['Search'] ),
1501  11 => array( 'Title' => 'Search (Adv)', 'Order' => 'SearchAdvOrder', 'Block' => 'SearchAdvBlock', 'AddSelect' => 'Control,Extra,Min,Max,Values,UseLKey', 'AddBlockProps' => $aAddBlockProps['Search'], 'AddProps' => $aAddProps['Search'] ),
1502 
1503  //special areas
1504  100 => array( 'Title' => 'All Fields. PC cache', 'AddSelect' => 'Default,Unique,Extra' ),
1505  101 => array( 'Title' => 'Matching Fields', 'AddSelect' => 'MatchField,MatchPercent' ),
1506  );
1507 
1508  }
1509 
1510  function createCache()
1511  {
1512  // clear page blocks cache for join and search form blocks
1513  ch_import('ChWsbPageViewAdmin'); // for clear caching abilities
1514  $oPageViewCacher = new ChWsbPageViewCacher ('', '');
1515  $oCacheBlocks = $oPageViewCacher->getBlocksCacheObject ();
1516  $aBlockIds = array (4, 146, 147, 156);
1517  $aKeys = array (
1518  true.'tab'.false,
1519  false.'tab'.false,
1520  true.'popup'.false,
1521  false.'popup'.false,
1522  true.'tab'.true,
1523  false.'tab'.true,
1524  true.'popup'.true,
1525  false.'popup'.true
1526  );
1527  foreach ($aBlockIds as $iBlockId)
1528  foreach ($aKeys as $sKey)
1529  $oCacheBlocks->delData($oPageViewCacher->genBlocksCacheKey ($iBlockId.$sKey));
1530 
1531 
1532 
1533 
1534  $sCacheString = "// cache of Profile Fields\n\nreturn array(\n //areas\n";
1535 
1536  // get areas
1537  foreach ($this -> aAreasProps as $iAreaID => $aArea) {
1538  $oArea = new ChWsbProfileFieldsArea( $iAreaID, $this );
1539 
1540  $sCacheString .= $oArea -> getCacheString();
1541  }
1542 
1543  $sCacheString .= ");\n";
1544 
1545 
1546  $aCacheArray = eval($sCacheString);
1547 
1548  $oCache = $GLOBALS['MySQL']->getDbCacheObject();
1549  return $oCache->setData ($GLOBALS['MySQL']->genDbCacheKey('sys_profile_fields'), $aCacheArray);
1550  }
1551 
1552 }
1553 
1559 {
1560  var $id;
1562  var $sTitle;
1566  var $aPages;
1567 
1568  function __construct( $iAreaID, &$oParent )
1569  {
1570  $this -> id = $iAreaID;
1571  $this -> oParent = &$oParent;
1572 
1573  $this -> sTitle = $this -> oParent -> aAreasProps[ $this -> id ]['Title'];
1574  $this -> sBlockCol = $this -> oParent -> aAreasProps[ $this -> id ]['Block'];
1575  $this -> sOrderCol = $this -> oParent -> aAreasProps[ $this -> id ]['Order'];
1576  $this -> sAddSelect = $this -> oParent -> aAreasProps[ $this -> id ]['AddSelect'];
1577  $this -> aAddBlockProps = $this -> oParent -> aAreasProps[ $this -> id ]['AddBlockProps'];
1578  $this -> aAddProps = $this -> oParent -> aAreasProps[ $this -> id ]['AddProps'];
1579  }
1580 
1581  function getCacheString()
1582  {
1583  $sCacheString = "\n //{$this -> sTitle}\n {$this -> id} => array(\n";
1584 
1585  if( $this -> id == 1 ) {
1586  $this -> aPages = $this -> getJoinPages();
1587 
1588  $sCacheString .= " //pages\n";
1589  foreach( $this -> aPages as $iPage ){
1590  $this -> aBlocks = $this -> getBlocks( "`JoinPage` = $iPage" );
1591 
1592  $sCacheString .= " $iPage => array(\n";
1593  $sCacheString .= $this -> getBlocksCacheString( ' ' );
1594  $sCacheString .= " ),\n";
1595  }
1596  } else {
1597  if( $this -> id == 100 or $this -> id == 101 )
1598  $this -> aBlocks = array( 0 => '' );
1599  else
1600  $this -> aBlocks = $this -> getBlocks();
1601 
1602  $sCacheString .= $this -> getBlocksCacheString();
1603  }
1604 
1605  $sCacheString .= " ),\n";
1606 
1607  return $sCacheString;
1608  }
1609 
1610  function getBlocksCacheString( $sPrefix = '' )
1611  {
1612  $sCacheString = "$sPrefix //blocks\n";
1613 
1614  foreach ($this -> aBlocks as $iBlockID => $sBlockName) {
1615  $sBlockName = $this -> addSlashes( $sBlockName );
1616  $sCacheString .= "$sPrefix $iBlockID => array(\n";
1617  $sCacheString .= "$sPrefix //block properties\n";
1618 
1619  // add additional properties
1620  if( is_array($this -> aAddBlockProps) )
1621  foreach ($this -> aAddBlockProps as $sProp => $sValue) {
1622  $sPropValue = str_replace( '{Name}', $sBlockName, $sValue );
1623  $sCacheString .= "$sPrefix '$sProp' => '$sPropValue',\n";
1624  }
1625 
1626  //process items
1627  $aItems = $this -> getItemsOfBlock($iBlockID);
1628 
1629  $sCacheString .= "$sPrefix 'Items' => array(\n";
1630  foreach ($aItems as $iBlockID => $aItem) {
1631  $sCacheString .= "$sPrefix $iBlockID => array(\n";
1632  $sCacheString .= "$sPrefix //item properties\n";
1633 
1634  // add additional properties
1635  if( is_array($this -> aAddProps) )
1636  foreach ($this -> aAddProps as $sProp => $sValue) {
1637  $aItem[ $sProp ] = str_replace( '{Name}', $aItem['Name'], $sValue );
1638  }
1639 
1640  foreach ($aItem as $sProp => $sValue) {
1641  if( $sProp == 'ID' )
1642  continue; //do not process ID it is already in key
1643 
1644  $sCacheString .= "$sPrefix '$sProp' => " . $this -> processValue4CacheString( $sProp, $sValue, "$sPrefix " ) . ",\n";
1645  }
1646 
1647  $sCacheString .= "$sPrefix ),\n";
1648  }
1649 
1650  $sCacheString .= "$sPrefix ),\n"; //close items
1651  $sCacheString .= "$sPrefix ),\n"; //close block
1652  }
1653 
1654  return $sCacheString;
1655  }
1656 
1657  function processValue4CacheString( $sProp, $sValue, $sPrefix = '' )
1658  {
1659  if( is_null( $sValue ) )
1660  return 'null'; //just a null
1661 
1662  switch( $sProp ) {
1663  case 'Name':
1664  case 'Type':
1665  case 'Caption':
1666  case 'Desc':
1667  case 'MandatoryMsg':
1668  case 'MinMsg':
1669  case 'MaxMsg':
1670  case 'UniqueMsg':
1671  case 'CheckMsg':
1672  return "'$sValue'"; // string in single quotes, simple text (without quotes)
1673  case 'Min':
1674  case 'Max':
1675  case 'MatchPercent':
1676  case 'MatchField':
1677  return "$sValue"; //integer
1678  case 'Mandatory':
1679  case 'Unique':
1680  return ( $sValue == '1' ? 'true' : 'false' ); //boolean
1681  case 'Values':
1682  if( $sValue == '' )
1683  return "''";
1684  elseif( substr( $sValue, 0, 2) == '#!' )
1685  return '"' . $this -> addSlashesDblQuot( $sValue ) . '"'; //string in double quotes
1686  else {
1687  // WOOW! Lets make it array! >:-E
1688  $aValues = explode( "\n", $sValue );
1689 
1690  $sRet = "array(\n";
1691 
1692  foreach( $aValues as $iKey => $sValue1 ) {
1693  $sValue1 = $this -> addSlashes( $sValue1 );
1694  $sRet .= "$sPrefix '$sValue1',\n";
1695  }
1696 
1697  $sRet .= "$sPrefix)";
1698 
1699  return $sRet;
1700  }
1701  default:
1702  return '"' . $this -> addSlashesDblQuot( $sValue ) . '"'; //string in double quotes
1703  }
1704  }
1705 
1706  function addSlashes( $sText )
1707  {
1708  $sText = str_replace( "\\", "\\\\", $sText );
1709  $sText = str_replace( "'", "\\'", $sText );
1710 
1711  return $sText;
1712  }
1713 
1714  function addSlashesDblQuot( $sText )
1715  {
1716  $sText = str_replace( '\\', '\\\\', $sText );
1717  $sText = str_replace( '"', '\"', $sText );
1718  $sText = str_replace( '$', '\$', $sText );
1719  $sText = str_replace( "\r", '\r', $sText );
1720  $sText = str_replace( "\n", '\n', $sText );
1721  $sText = str_replace( "\t", '\t', $sText );
1722  $sText = str_replace( "\x0", '\x0', $sText );
1723 
1724  return $sText;
1725  }
1726 
1727 
1728  function getJoinPages()
1729  {
1730  $aPages = array();
1731 
1732  $sQuery = "
1733  SELECT
1734  DISTINCT `JoinPage`
1735  FROM `sys_profile_fields`
1736  WHERE
1737  `Type` = 'block' AND
1738  `JoinOrder` IS NOT NULL
1739  ORDER BY `JoinPage` ASC
1740  ";
1741 
1742  $rPages = db_res( $sQuery );
1743 
1744  while( $aPage = $rPages ->fetch() ) {
1745  $aPages[] = (int)$aPage['JoinPage'];
1746  }
1747 
1748  return $aPages;
1749  }
1750 
1751  //`JoinPage` = $iPage
1752  function getBlocks( $sAddSort = '1' )
1753  {
1754  $aBlocks = array();
1755 
1756  $sQuery = "
1757  SELECT
1758  `ID`,
1759  `Name`
1760  FROM `sys_profile_fields`
1761  WHERE
1762  `Type` = 'block' AND
1763  `{$this -> sOrderCol}` IS NOT NULL AND
1764  $sAddSort
1765  ORDER BY
1766  `{$this -> sOrderCol}`
1767  ";
1768 
1769  $rBlocks = db_res( $sQuery );
1770 
1771  while( $aBlock = $rBlocks ->fetch() ) {
1772  $aBlocks[ $aBlock['ID'] ] = $aBlock['Name'];
1773  }
1774 
1775  return $aBlocks;
1776  }
1777 
1778  function getItemsOfBlock( $iBlockID )
1779  {
1780  $aItems = array();
1781 
1782  $sAddSelect = '`' . str_replace( ',', '`, `', $this -> sAddSelect ) . '`';
1783 
1784  if( $this -> id == 100 )
1785  $sWhere = '1';
1786  elseif( $this -> id == 101 )
1787  $sWhere = "`MatchField` != ''";
1788  else
1789  $sWhere = "`{$this -> sBlockCol}` = $iBlockID AND `{$this -> sOrderCol}` IS NOT NULL";
1790 
1791  $sOrderCol = isset( $this -> sOrderCol ) ? $this -> sOrderCol : 'ID';
1792 
1793  $sQuery = "
1794  SELECT
1795  `ID`,
1796  `Name`,
1797  `Type`,
1798  $sAddSelect
1799  FROM
1800  `sys_profile_fields`
1801  WHERE
1802  `Type` != 'block' AND
1803  $sWhere
1804  ORDER BY
1805  `$sOrderCol`
1806  ";
1807 
1808  $rItems = db_res( $sQuery );
1809 
1810  while( $aItem = $rItems->fetch() ) {
1811  $aItems[ $aItem['ID'] ] = $aItem;
1812  }
1813 
1814  return $aItems;
1815  }
1816 }
ChWsbPFM\getJoinPagesSelector
getJoinPagesSelector( $iCurrent)
Definition: ChWsbPFM.php:490
document
Output SortAttr HTML Purifier will sort attributes by name before writing them back to the document
Definition: Output.SortAttr.txt:8
ChWsbPFM\genFormMiscTab
genFormMiscTab( $aField)
Definition: ChWsbPFM.php:742
ChWsbPFM\genSaveItemFormClose
genSaveItemFormClose()
Definition: ChWsbPFM.php:1381
ChWsbPFM\parseParams
parseParams( $sParams)
Definition: ChWsbPFM.php:725
ChWsbProfileFieldsArea\addSlashesDblQuot
addSlashesDblQuot( $sText)
Definition: ChWsbPFM.php:1714
ChWsbPFMAreaJSONObj\__construct
__construct( $oArea)
Definition: ChWsbPFM.php:1391
ChWsbProfileFieldsArea\$id
$id
Definition: ChWsbPFM.php:1560
db_assoc_arr
db_assoc_arr($query, $bindings=[])
Definition: db.inc.php:86
ChWsbPFM\genSaveItemFormUpdate
genSaveItemFormUpdate( $sText, $iItemID, $sNewName='')
Definition: ChWsbPFM.php:1374
compileLanguage
compileLanguage($langID=0)
Definition: languages.inc.php:301
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
ChWsbPFMItem\__construct
__construct( $iID, $sName, $iBlock=0)
Definition: ChWsbPFM.php:1417
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChWsbPFM\createNewBlock
createNewBlock()
Definition: ChWsbPFM.php:1264
ChWsbPFM\genSaveItemFooter
genSaveItemFooter()
Definition: ChWsbPFM.php:1341
ChWsbPFMCacher\createCache
createCache()
Definition: ChWsbPFM.php:1510
php
ChWsbPFMItem
Definition: ChWsbPFM.php:1416
ChWsbProfileFieldsArea\__construct
__construct( $iAreaID, &$oParent)
Definition: ChWsbPFM.php:1568
ChWsbProfileFieldsArea\$sOrderCol
$sOrderCol
Definition: ChWsbPFM.php:1564
ChWsbProfileFieldsArea\$sTitle
$sTitle
Definition: ChWsbPFM.php:1562
ChWsbProfileFieldsArea\$aPages
$aPages
Definition: ChWsbPFM.php:1566
ChWsbPFM\getInfoIcon
getInfoIcon( $sText)
Definition: ChWsbPFM.php:785
ChWsbPageViewCacher
Definition: ChWsbPageViewAdmin.php:944
ChWsbProfileFieldsArea\processValue4CacheString
processValue4CacheString( $sProp, $sValue, $sPrefix='')
Definition: ChWsbPFM.php:1657
$oCache
$oCache
Definition: prof.inc.php:10
ChWsbPFM\checkValuesLink
checkValuesLink( $sKey)
Definition: ChWsbPFM.php:1157
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
ChWsbPFM\genSaveItemError
genSaveItemError( $sText, $sField='')
Definition: ChWsbPFM.php:1328
ChWsbPFM\__construct
__construct( $iArea)
Definition: ChWsbPFM.php:13
ChWsbPFM\genJSON
genJSON()
Definition: ChWsbPFM.php:90
$sType
$sType
Definition: actions.inc.php:11
and
and
Definition: license.txt:18
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbPFMCacher\$aAreasProps
$aAreasProps
Definition: ChWsbPFM.php:1433
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
ChWsbPFM\savePositions
savePositions( $aInArrays)
Definition: ChWsbPFM.php:199
db_last_id
db_last_id()
Definition: db.inc.php:47
ChWsbProfileFieldsArea\getItemsOfBlock
getItemsOfBlock( $iBlockID)
Definition: ChWsbPFM.php:1778
ChWsbPFMAreaJSONObj
Definition: ChWsbPFM.php:1390
ChWsbPFM\checkSelectDefault
checkSelectDefault( $sValues, $sDefault)
Definition: ChWsbPFM.php:1164
type
if(!defined("USER_STATUS_TYPE")) define("USER_STATUS_TYPE" type
Definition: constants.inc.php:13
ChWsbPFM\setMinMaxAge
setMinMaxAge( $iMin, $iMax)
Definition: ChWsbPFM.php:1151
ChWsbPFM\updateLangString
updateLangString( $sKey, $sString)
Definition: ChWsbPFM.php:1286
src
img src
Definition: URI.MungeResources.txt:8
ChWsbPFM\genFieldEditForm
genFieldEditForm( $iItemID)
Definition: ChWsbPFM.php:248
ChWsbProfileFieldsArea\getBlocks
getBlocks( $sAddSort='1')
Definition: ChWsbPFM.php:1752
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_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
ChWsbPFM\deleteItem
deleteItem( $iItemID)
Definition: ChWsbPFM.php:1349
ChWsbPFM\genSaveItemHeader
genSaveItemHeader()
Definition: ChWsbPFM.php:1321
ChWsbPFM\getFieldsOptionsList
getFieldsOptionsList( $sSelected, $sType)
Definition: ChWsbPFM.php:465
ChWsbProfileFieldsArea\$oParent
$oParent
Definition: ChWsbPFM.php:1561
ChWsbPFM\genFormAdvTab
genFormAdvTab( $aField)
Definition: ChWsbPFM.php:558
ChWsbProfileFieldsArea\getBlocksCacheString
getBlocksCacheString( $sPrefix='')
Definition: ChWsbPFM.php:1610
ChWsbProfileFieldsArea\$aBlocks
$aBlocks
Definition: ChWsbPFM.php:1565
setParam
setParam($sParamName, $sParamValue)
Definition: db.inc.php:149
process_pass_data
process_pass_data($text, $strip_tags=0)
Definition: utils.inc.php:290
$iPage
$iPage
Definition: browse.php:50
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
ChWsbPFM\genTableEdit
genTableEdit( $aForm, $sID='')
Definition: ChWsbPFM.php:648
default
Attr AllowedFrameTargets _parent and _top Values should be as validation will be done in a case sensitive manner despite W3C s recommendation XHTML Strict does not permit the target attribute so this directive will have no effect in that doctype XHTML does not enable the Target module by default
Definition: Attr.AllowedFrameTargets.txt:10
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
ChWsbPFM\getLangString
getLangString( $sKey)
Definition: ChWsbPFM.php:806
ID
HTML Attr Name UseCDATA not ID
Definition: HTML.Attr.Name.UseCDATA.txt:6
$aForm
$aForm
Definition: forgot.php:43
ChWsbPFM
Definition: ChWsbPFM.php:12
$sCaption
$sCaption
Definition: tellfriend.php:39
ChWsbPFM\genFormMatchTab
genFormMatchTab( $aField)
Definition: ChWsbPFM.php:507
ChWsbProfileFieldsArea
Definition: ChWsbPFM.php:1559
ChWsbPFM\fillMyArrays
fillMyArrays()
Definition: ChWsbPFM.php:97
ChWsbPFM\getTypeOptions
getTypeOptions( $sActive)
Definition: ChWsbPFM.php:795
ChWsbPFM\getMatchFields
getMatchFields( $aField)
Definition: ChWsbPFM.php:528
ChWsbPFMCacher\__construct
__construct()
Definition: ChWsbPFM.php:1435
ChWsbProfileFieldsArea\$sBlockCol
$sBlockCol
Definition: ChWsbPFM.php:1563
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$sDesc
$sDesc
Definition: actions.inc.php:21
ChWsbProfileFieldsArea\addSlashes
addSlashes( $sText)
Definition: ChWsbPFM.php:1706
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
ChWsbProfileFieldsArea\getJoinPages
getJoinPages()
Definition: ChWsbPFM.php:1728
ChWsbPFM\createNewField
createNewField()
Definition: ChWsbPFM.php:1247
ChWsbPFMCacher
Definition: ChWsbPFM.php:1432
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
or
Voluntary License Schemes The Licensor waives the right to collect whether individually or
Definition: license.txt:37
ChWsbPFM\doUpdateItem
doUpdateItem( $aItem, $aUpdate)
Definition: ChWsbPFM.php:1177
ChWsbProfileFieldsArea\getCacheString
getCacheString()
Definition: ChWsbPFM.php:1581
if
if(!defined("VERSION")) define("VERSION"
Definition: header.inc.php:13