Cheetah
ChBaseFormView.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( CH_DIRECTORY_PATH_CLASSES . 'ChWsbForm.php' );
9 
11 {
12  var $bEnableErrorIcon = true;
13 
19  var $sCode;
20 
28  var $_sCodeAdd = '';
29 
30  var $_isTbodyOpened = false;
31 
32  var $_isDateControl = false;
33  var $_isDateTimeControl = false;
34 
46  function __construct($aInfo)
47  {
48  parent::__construct($aInfo);
49  }
50 
56  function getCode()
57  {
58  $sExtraScript .= "
59  <script>
60  function toggle_password(dbeye, dbid) {
61  $(dbeye).toggleClass('eye eye-slash');
62  if ($('#'+dbid).attr('type') == 'password') {
63  $('#'+dbid).attr('type', 'text');
64  } else {
65  $('#'+dbid).attr('type', 'password');
66  }
67  };
68  </script>
69  ";
70  return ($this->sCode = $this->genForm() . $sExtraScript);
71  }
72 
78  function genForm()
79  {
80  $sTable = $this->genTable();
81  if(!empty($this->aParams['remove_form']))
82  return $sTable;
83 
84  // add default className to attributes
85  $this->aFormAttrs['class'] = 'form_advanced' . (isset($this->aFormAttrs['class']) ? (' ' . $this->aFormAttrs['class']) : '');
86  $sFormAttrs = $this->convertArray2Attrs($this->aFormAttrs);
87 
88  return '<form ' . $sFormAttrs . '>' . $sTable . '</form>';
89  }
90 
96  function genTable()
97  {
98  // add default className to attributes
99  $this->aTableAttrs['class'] = 'form_advanced_table' . (isset($this->aTableAttrs['class']) ? (' ' . $this->aTableAttrs['class']) : '');
100 
101  // add CSRF token if it's needed.
102  if($GLOBALS['MySQL']->getParam('sys_security_form_token_enable') == 'on' && !defined('CH_WSB_CRON_EXECUTE') && (!isset($this->aParams['csrf']['disable']) || (isset($this->aParams['csrf']['disable']) && $this->aParams['csrf']['disable'] !== true)) && ($mixedCsrfToken = ChWsbForm::getCsrfToken()) !== false)
103  $this->aInputs['csrf_token'] = array(
104  'type' => 'hidden',
105  'name' => 'csrf_token',
106  'value' => $mixedCsrfToken,
107  'db' => array (
108  'pass' => 'Xss',
109  )
110  );
111 
112  // generate table contents
113  $sTableContent = '';
114  foreach ($this->aInputs as $aInput)
115  $sTableContent .= $this->genRow($aInput);
116 
117  $this->addCssJs($this->_isDateControl, $this->_isDateTimeControl);
118  return $this->_sCodeAdd . $GLOBALS['oSysTemplate']->parseHtmlByName('form_content.html', array(
119  'wrapper_id' => $this->id,
120  'table_attrs' => $this->convertArray2Attrs($this->aTableAttrs),
121  'content' => $this->getOpenTbody() . $sTableContent . $this->getCloseTbody(),
122  ));
123  }
124 
131  function genRow(&$aInput)
132  {
133  switch ($aInput['type']) {
134  case 'headers':
135  $sRow = $this->genRowHeaders($aInput);
136  break;
137 
138  case 'block_header':
139  $sRow = $this->genRowBlockHeader($aInput);
140  break;
141 
142  case 'block_end':
143  $sRow = $this->genBlockEnd($aInput);
144  break;
145 
146  case 'hidden':
147  // do not generate row for hidden inputs
148  $sRow = '';
149  $this->_sCodeAdd .= $this->genInput($aInput);
150  break;
151 
152  case 'select_box':
153  $sRow = $this->genRowSelectBox($aInput);
154  break;
155 
156  default:
157  $sRow = $this->genRowStandard($aInput);
158  }
159 
160  return $sRow;
161  }
162 
169  function genRowStandard(&$aInput)
170  {
171  $sCaption = !empty($aInput['caption']) ? $aInput['caption'] : '';
172  $sRequired = !empty($aInput['required']) ? '<span class="ch-form-required">*</span>' : '';
173  $sClassAdd = '';
174 
175  $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
176  $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
177 
178  $bMultiplyable = isset($aInput['attrs']) && isset($aInput['value']) && is_array($aInput['value']) && $aInput['attrs']['multiplyable'];
179  if($bMultiplyable) {
180  $sValFirst = array_shift($aInput['value']);
181  $aInputCopy = $aInput;
182  $aInputCopy['value'] = $sValFirst;
183  $sInputCopy = $this->genInput($aInputCopy);
184  $sInputCode = $this->genWrapperInput($aInputCopy, $sInputCopy);
185  $sInputCodeExtra = '';
186  foreach ($aInput['value'] AS $v) {
187  unset($aInputCopy['attrs']['multiplyable']);
188  $aInputCopy['attrs']['deletable'] = 'true';
189  $aInputCopy['value'] = $v;
190  $sInputCopy = $this->genInput($aInputCopy);
191  $sInputCodeExtra .= '<div class="clear_both"></div>' . $this->genWrapperInput($aInputCopy, $sInputCopy);
192  }
193  } else {
194  $sInput = $this->genInput($aInput);
195  $sInputCode = $this->genWrapperInput($aInput, $sInput);
196  }
197 
198  $sElementClass = '';
199  if(!empty($aInput['tr_attrs']['class'])) {
200  $sElementClass = ' ' . $aInput['tr_attrs']['class'];
201  unset($aInput['tr_attrs']['class']);
202  }
203 
204  if($bMultiplyable)
205  $sElementClass .= ' ch-form-element-multiplyable';
206 
207  if(!empty($aInput['error']))
208  $sElementClass .= ' ch-form-element-error';
209 
210  $sCode = '';
211  $sCode .= $this->getOpenTbody();
212  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_row_standard_' . (!empty($aInput['colspan']) ? 'colspan' : 'simple') . '.html', array(
213  'element_type' => 'ch-form-element-' . $aInput['type'],
214  'element_class' => $sElementClass,
215  'element_attrs' => $this->convertArray2Attrs(!empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : ''),
216  'class_add' => $sClassAdd,
217  'required' => $sRequired,
218  'caption' => $sCaption,
219  'input_code' => !empty($sInputCode) ? $sInputCode : '',
220  'info_icon' => !empty($sInfoIcon) ? $sInfoIcon : '',
221  'error_icon' => !empty($sErrorIcon) ? $sErrorIcon : '',
222  'input_code_extra' => !empty($sInputCodeExtra) ? $sInputCodeExtra : '',
223  'ch_if:show_toggle_html' => array(
224  'condition' => isset($aInput['html']) && (isset($aInput['html_toggle']) && $aInput['html_toggle']),
225  'content' => array(
226  'attrs_id' => (!isset($aInput['attrs']['id'])) ?: $aInput['attrs']['id'],
227  ),
228  ),
229  ));
230 
231  return $sCode;
232  }
233 
240  function genRowSelectBox(&$aInput)
241  {
242  $sCaption = (!empty($aInput['caption'])) ? $aInput['caption'] : '&nbsp;';
243  $sRequired = (!empty($aInput['required'])) ? '<span class="ch-form-required">*</span>' : '';
244  $sClassAdd = '';
245 
246  $sInfoIcon = (!empty($aInput['info'])) ? $this->genInfoIcon($aInput['info']) : '';
247  $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
248 
249  $sInput = $this->genInputSelectBox($aInput);
250 
251  $sElementClass = '';
252  if(!empty($aInput['tr_attrs']['class'])) {
253  $sElementClass = ' ' . $aInput['tr_attrs']['class'];
254  unset($aInput['tr_attrs']['class']);
255  }
256 
257  if(!empty($aInput['error']))
258  $sElementClass .= ' ch-form-element-error';
259 
260  $sCode = $this->getOpenTbody();
261  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_row_select_' . (!empty($aInput['colspan']) ? 'colspan' : 'simple') . '.html', array(
262  'element_type' => 'ch-form-element-' . $aInput['type'],
263  'element_class' => $sElementClass,
264  'element_attrs' => $this->convertArray2Attrs(!empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : ''),
265  'class_add' => $sClassAdd,
266  'required' => $sRequired,
267  'caption' => $sCaption,
268  'input_code' => $sInput,
269  'info_icon' => !empty($sInfoIcon) ? $sInfoIcon : '',
270  'error_icon' => !empty($sErrorIcon) ? $sErrorIcon : '',
271  ));
272 
273  return $sCode;
274  }
281  function genRowHeaders(&$aInput)
282  {
283  $sCode = $this->getCloseTbody();
284  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_row_headers.html', array(
285  'class' => isset($aInput['tr_class']) ? ' ' . $aInput['tr_class'] : '',
286  'header_first' => $aInput[0],
287  'header_second' => $aInput[1]
288  ));
289  $sCode .= $this->getOpenTbody();
290 
291  return $sCode;
292  }
293 
300  function genRowBlockHeader(&$aInput)
301  {
302  $sElementClass = '';
303  $aNextFieldsetAdd = false;
304  $bCollapsable = $bCollapsed = false;
305  if(isset($aInput['collapsable']) && $aInput['collapsable']) {
306  $bCollapsable = true;
307  $sElementClass = ' collapsable';
308 
309  if(isset($aInput['collapsed']) && $aInput['collapsed']) {
310  $bCollapsed = true;
311  $sElementClass .= ' collapsed';
312  $aNextFieldsetAdd = array(
313  'style' => 'display:none;',
314  );
315  }
316  }
317 
318  $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : '';
319 
320  $sClass = '';
321  if(isset($aAttrs['class'])) {
322  $sClass = ' ' . $aAttrs['class'];
323  unset($aAttrs['class']);
324  }
325 
326  $sCode = $this->getCloseTbody();
327  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_row_block_header.html', array(
328  'element_class' => $sElementClass,
329  'class' => $sClass,
330  'attrs' => $this->convertArray2Attrs($aAttrs),
331  'caption' => $aInput['caption'],
332  'ch_if:show_collapse' => array(
333  'condition' => $bCollapsable,
334  'content' => array(
335  'icon_name' => $bCollapsed ? 'chevron-down' : 'chevron-up'
336  )
337  )
338  ));
339  $sCode .= $this->getOpenTbody($aNextFieldsetAdd);
340 
341  return $sCode;
342  }
343 
344  function genBlockEnd()
345  {
346  return $this->getCloseTbody() . $this->getOpenTbody();
347  }
348 
349  function genWrapperInput($aInput, $sContent)
350  {
351  return $GLOBALS['oSysTemplate']->parseHtmlByName('form_input_wrapper.html', array(
352  'type' => $aInput['type'],
353  'class' => isset($aInput['wrap_text']) && $aInput['wrap_text'] ? 'input_wrapper_wraptext' : '',
354  'attrs' => isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $this->convertArray2Attrs($aInput['attrs_wrapper']) : '',
355  'content' => $sContent,
356  'content_add' => ''
357  ));
358  }
359 
366  function genInput(&$aInput)
367  {
368  $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
369 
370  switch ($aInput['type']) {
371 
372  // standard inputs (and non-standard, interpreted as standard)
373  case 'datetime':
374  $this->_isDateTimeControl = true;
375  case 'date':
376  $this->_isDateControl = true;
377  case 'text':
378  case 'number':
379  case 'email':
380  case 'url':
381  case 'checkbox':
382  case 'radio':
383  case 'image':
384  case 'slider':
385  case 'range':
386  case 'doublerange':
387  case 'hidden':
388  $sInput = $this->genInputStandard($aInput);
389  break;
390 
391  case 'password':
392  $sInput = $this->genInputStandard($aInput);
393  if(strpos($aInput['name'], 'confirm')) {
394  $dbid = 'form_input_' . $aInput['type'] . '_confirm';
395  } else {
396  $dbid = 'form_input_' . $aInput['type'];
397  }
398  $sInput .= '<i class="sys-icon eye toogle-password" onclick="toggle_password(this, \'' . $dbid . '\');"></i>';
399  break;
400 
401  case 'file':
402  if (!isset($aInput['attrs']['size']))
403  $aInput['attrs']['size'] = 12;
404  $sInput = $this->genInputStandard($aInput);
405  break;
406 
407  case 'button':
408  case 'reset':
409  case 'submit':
410  $sInput = $this->genInputButton($aInput);
411  break;
412 
413  case 'textarea':
414  $sInput = $this->genInputTextarea($aInput);
415  break;
416 
417  case 'select':
418  $sInput = $this->genInputSelect($aInput);
419  break;
420 
421  case 'select_multiple':
422  $sInput = $this->genInputSelectMultiple($aInput);
423  break;
424 
425  case 'checkbox_set':
426  $sInput = $this->genInputCheckboxSet($aInput);
427  break;
428 
429  case 'radio_set':
430  $sInput = $this->genInputRadioSet($aInput);
431  break;
432 
433  case 'input_set': // numeric array of inputs
434  $sInput = '';
435 
436  foreach ($aInput as $iKey => $aSubInput) {
437  if (!is_int($iKey) or !$aSubInput)
438  continue; // parse only integer keys and existing values
439 
440  $sInput .= $this->genInput($aSubInput); // recursive call
441  $sInput .= $sDivider;
442  }
443  break;
444 
445  case 'custom':
446  $sInput = isset($aInput['content']) ? $aInput['content'] : '';
447  break;
448 
449  case 'canvas':
450  //TODO: do we need canvas?
451  break;
452 
453  case 'captcha':
454  $sInput = $this->genInputCaptcha($aInput);
455  break;
456 
457  case 'value':
458  $sInput = $aInput['value'];
459  break;
460 
461  default:
462  //unknown control type
463  $sInput = 'Unknown control type';
464  }
465 
466  // create input label
467  $sInput .= $this->genLabel($aInput);
468 
469  return $sInput;
470  }
471 
478  function getInputId(&$aInput)
479  {
480  if (isset($aInput['id']))
481  return $aInput['id'];
482 
483  $sName = preg_replace("/[^a-z0-9]/i", '_', $aInput['name']);
484 
485  $sID = $this->id . '_input_' . $sName;
486 
487  if ( // multiple elements cause identical id's
488  (
489  (
490  $aInput['type'] == 'checkbox' and
491  substr($aInput['name'], -2) == '[]' // it is multiple element
492  ) or
493  $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
494  ) and
495  isset($aInput['value']) // if we can make difference
496  ) {
497  $sValue = md5($aInput['value']);
498 
499  // add value
500  $sID .= '_' . $sValue;
501  }
502 
503  $sID = trim($sID, '_');
504 
505  $aInput['id'] = $sID; // just for repeated calls
506 
507  return $sID;
508  }
509 
516  function genInputStandard(&$aInput)
517  {
518  $sInputName = 'input';
519 
520  // clone attributes for system use ;)
521  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
522 
523  // add default className to attributes
524  $aAttrs['class'] = "form_input_{$aInput['type']} ch-def-font-inputs" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
525 
526  if(isset($aInput['type'])) {
527  switch($aInput['type']) {
528  case 'datetime':
529  $aAttrs['type'] = 'date_time';
530  break;
531  case 'date':
532  $aAttrs['type'] = 'date_calendar';
533  break;
534  case 'file':
535  $sInputName = 'file';
536  $aAttrs['type'] = $aInput['type'];
537  break;
538  case 'password':
539  if(strpos($aInput['name'], 'confirm')) {
540  $aAttrs['id'] = 'form_input_' . $aInput['type'] . '_confirm';
541  } else {
542  $aAttrs['id'] = 'form_input_' . $aInput['type'];
543  }
544  $aAttrs['type'] = $aInput['type'];
545  break;
546  default:
547  $aAttrs['type'] = $aInput['type'];
548  }
549  }
550  if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
551  if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
552 
553  // for inputs with labels generate id
554  if (isset($aInput['label']))
555  $aAttrs['id'] = $this->getInputId($aInput);
556 
557  // for checkboxes
558  if (isset($aInput['checked']) and $aInput['checked'])
559  $aAttrs['checked'] = 'checked';
560 
561  $sInputAttrs = $this->convertArray2Attrs($aAttrs);
562  return $this->getInput($sInputName, $sInputAttrs);
563  }
564 
571  function genInputButton(&$aInput)
572  {
573  $aInput['colspan'] = 2;
574 
575  // clone attributes for system use ;)
576  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
577 
578  // add default className to attributes
579  $aAttrs['class'] = "form_input_{$aInput['type']} ch-btn" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
580  $aAttrs['type'] = $aInput['type'];
581  $aAttrs['name'] = $aInput['name'];
582  $aAttrs['value'] = $aInput['value'];
583 
584  // for inputs with labels generate id
585  if (isset($aInput['label']))
586  $aAttrs['id'] = $this->getInputId($aInput);
587 
588  // for checkboxes
589  if(isset($aInput['checked']) && $aInput['checked'])
590  $aAttrs['checked'] = 'checked';
591 
592  $sAttrs = $this->convertArray2Attrs($aAttrs);
593 
594  return $this->getInput('button', $sAttrs);
595  }
596 
603  function genInputTextarea(&$aInput)
604  {
605  // for inputs with labels generate id
606  if (!isset($aInput['attrs']['id']) && (isset($aInput['label']) || isset($aInput['html'])))
607  $aInput['attrs']['id'] = $this->getInputId($aInput);
608 
609  // clone attributes for system use ;)
610  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
611 
612  // add default className to attributes
613  $aAttrs['class'] =
614  "form_input_{$aInput['type']} ch-def-font-inputs" .
615  (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '') .
616  ((isset($aInput['html']) and $aInput['html'] and $this->addHtmlEditor($aInput['html'], $aInput)) ? ' form_input_html' : '');
617 
618  $aAttrs['name'] = $aInput['name'];
619 
620  $sAttrs = $this->convertArray2Attrs($aAttrs);
621 
622  $sValue = (isset($aInput['value'])) ? htmlspecialchars_adv($aInput['value']) : '';
623 
624  return $this->getInput('textarea', $sAttrs, $sValue);
625  }
626 
627  function addHtmlEditor($iViewMode, &$aInput)
628  {
629  ch_import('ChWsbEditor');
630  $oEditor = ChWsbEditor::getObjectInstance();
631  if (!$oEditor)
632  return false;
633 
634  if (isset($aInput['html_no_link_conversion']) && $aInput['html_no_link_conversion'])
635  $oEditor->setCustomConf ("remove_script_host: false,\nrelative_urls: false,\n");
636 
637  $this->_sCodeAdd .= $oEditor->attachEditor ((!empty($this->aFormAttrs['id']) ? '#' . $this->aFormAttrs['id'] . ' ': '') . '[name="'.$aInput['name'].'"]', $iViewMode, isset($aInput['dynamic']) ? $aInput['dynamic'] : false);
638  if (!isset($aInput['attrs_wrapper']['style']))
639  $aInput['attrs_wrapper']['style'] = '';
640  $aInput['attrs_wrapper']['style'] = 'width:' . $oEditor->getWidth($iViewMode) . $aInput['attrs_wrapper']['style'];
641 
642  return true;
643  }
644 
651  function genInputSelect(&$aInput)
652  {
653  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
654 
655  // add default className to attributes
656  $aAttrs['class'] = "form_input_{$aInput['type']} ch-def-font-inputs" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
657 
658  $aAttrs['name'] = $aInput['name'];
659 
660  // for inputs with labels generate id
661  if (isset($aInput['label']))
662  $aAttrs['id'] = $this->getInputId($aInput);
663 
664  $sAttrs = $this->convertArray2Attrs($aAttrs);
665 
666  // generate options
667  $sCurValue = isset($aInput['value']) ? $aInput['value'] : null;
668  $sOptions = '';
669 
670  if (isset($aInput['values']) and is_array($aInput['values'])) {
671  foreach ($aInput['values'] as $sValue => $sTitle) {
672  if(is_array($sTitle)) {
673  $sValue = $sTitle['key'];
674  $sTitle = $sTitle['value'];
675  }
676  $sValueC = htmlspecialchars_adv($sValue);
677  $sTitleC = htmlspecialchars_adv($sTitle);
678 
679  $aAttrsOption = array('value' => $sValueC);
680  if((string)$sValue === (string)$sCurValue)
681  $aAttrsOption['selected'] = 'selected';
682 
683  $sOptions .= $this->getInput('option', $this->convertArray2Attrs($aAttrsOption), $sTitleC);
684  }
685  }
686 
687  // generate element
688  return $this->getInput('select', $sAttrs, $sOptions);
689  }
690 
697  function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
698  {
699  $sCode = '';
700 
701  if (isset($aInput['value']) and is_array($aInput['value'])) {
702  $iCounter = 0;
703  foreach ($aInput['value'] as $sValue) {
704  $aNewInput = $aInput;
705 
706  $aNewInput['name'] .= '[]';
707  $aNewInput['value'] = $sValue;
708 
709  if (isset($aInput['values'][$sValue])) { // draw select if value exists in values
710 
711  $aNewInput['type'] = 'select';
712 
713  if ($iCounter == 0) { // for the first input create multiplyable select and add info and error icons (if set)
714  $aNewInput['attrs']['multiplyable'] = 'true';
715  $aNewInput['attrs']['add_other'] = isset($aNewInput['attrs']['add_other']) ? $aNewInput['attrs']['add_text'] : 'true';
716  $sInputAdd = $sInfo . ' ' . $sError;
717  } else { // for the others inputs create only deletable
718  $aNewInput['attrs']['deletable'] = 'true';
719  $sInputAdd = '';
720  }
721 
722  $iCounter ++;
723  } else { // draw text input for non-existent value (man, it is select_box, wow!)
724  $aNewInput['type'] = 'text';
725  $aNewInput['attrs']['deletable'] = 'true';
726  }
727 
728  $sInput = $this->genInput($aNewInput);
729 
730  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_input_wrapper.html', array(
731  'type' => $aInput['type'],
732  'class' => '',
733  'attrs' => '',
734  'content' => $sInput,
735  'content_add' => $sInputAdd
736  ));
737  }
738  }
739  else {
740  // clone
741  $aNewInput = $aInput;
742 
743  $aNewInput['type'] = 'select';
744  $aNewInput['name'] .= '[]';
745  $aNewInput['attrs']['multiplyable'] = 'true';
746  $aNewInput['attrs']['add_other'] =
747  isset($aNewInput['attrs']['add_other'])
748  ? (empty($aNewInput['attrs']['add_text']) ? '' : $aNewInput['attrs']['add_text'])
749  : 'true';
750 
751  $sInput = $this->genInput($aNewInput);
752 
753  $sCode .= $GLOBALS['oSysTemplate']->parseHtmlByName('form_input_wrapper.html', array(
754  'type' => $aInput['type'],
755  'class' => '',
756  'attrs' => '',
757  'content' => $sInput,
758  'content_add' => $sInfo . $sError
759  ));
760  }
761 
762  return $sCode;
763  }
764 
771  function genInputSelectMultiple(&$aInput)
772  {
773  $aAttrs = $aInput['attrs'];
774 
775  // add default className to attributes
776  $aAttrs['class'] = "form_input_{$aInput['type']} ch-def-font-inputs" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
777 
778  $aAttrs['name'] = $aInput['name'] . '[]';
779  $aAttrs['multiple'] = 'multiple';
780 
781  // for inputs with labels generate id
782  if (isset($aInput['label']))
783  $aAttrs['id'] = $this->getInputId($aInput);
784 
785  $sAttrs = $this->convertArray2Attrs($aAttrs);
786 
787  // generate options
788  $aCurValues = $aInput['value'] ? (is_array($aInput['value']) ? $aInput['value'] : array($aInput['value'])) : array();
789  $sOptions = '';
790 
791  if (isset($aInput['values']) and is_array($aInput['values'])) {
792  foreach ($aInput['values'] as $sValue => $sTitle) {
793  $sValueC = htmlspecialchars_adv($sValue);
794  $sTitleC = htmlspecialchars_adv($sTitle);
795 
796  $aAttrsOption = array('value' => $sValueC);
797  if(in_array($sValue, $aCurValues))
798  $aAttrsOption['selected'] = 'selected';
799 
800  $sOptions .= $this->getInput('option', $this->convertArray2Attrs($aAttrsOption), $sTitleC);
801 
802  }
803  }
804 
805  // generate element
806  return $this->getInput('select', $sAttrs, $sOptions);
807  }
808 
815  function genInputCheckboxSet(&$aInput)
816  {
817  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
818 
819  // add default className to attributes
820  $aAttrs['class'] = "form_input_{$aInput['type']}" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
821 
822  $aAttrs['name'] = $aInput['name'];
823 
824  // for inputs with labels generate id
825  if (isset($aInput['label']))
826  $aAttrs['id'] = $this->getInputId($aInput);
827 
828  $sAttrs = $this->convertArray2Attrs($aAttrs);
829 
830  // generate options
831  $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
832  $aCurValues = $aInput['value'] ? (is_array($aInput['value']) ? $aInput['value'] : array($aInput['value'])) : array();
833 
834  $sOptions = '';
835 
836  if (isset($aInput['values']) and is_array($aInput['values'])) {
837  if (count($aInput['values']) > 3 && $sDivider == ' ')
838  $sDivider = '<br />';
839  // generate complex input using simple standard inputs
840  foreach ($aInput['values'] as $sValue => $sLabel) {
841  // create new simple input
842  $aNewInput = array(
843  'type' => 'checkbox',
844  'name' => $aInput['name'] . '[]',
845  'value' => $sValue,
846  'checked' => in_array($sValue, $aCurValues),
847  'label' => $sLabel,
848  );
849 
850  $sNewInput = $this->genInput($aNewInput);
851 
852  // attach new input to complex
853  $sOptions .= ($sNewInput . $sDivider);
854  }
855  }
856 
857  // generate element
858  return $this->getInput('checkbox_set', $sAttrs, $sOptions);
859  }
866  function genInputRadioSet(&$aInput)
867  {
868  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
869 
870  // add default className to attributes
871  $aAttrs['class'] = "form_input_{$aInput['type']}" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
872 
873  $aAttrs['name'] = $aInput['name'];
874 
875  // for inputs with labels generate id
876  if (isset($aInput['label']))
877  $aAttrs['id'] = $this->getInputId($aInput);
878 
879  $sAttrs = $this->convertArray2Attrs($aAttrs);
880 
881  // generate options
882  $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
883  $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
884 
885  $sOptions = '';
886 
887  if (isset($aInput['values']) and is_array($aInput['values'])) {
888  if (count($aInput['values']) > 3 && $sDivider == ' ')
889  $sDivider = '<br />';
890  // generate complex input using simple standard inputs
891  foreach ($aInput['values'] as $sValue => $sLabel) {
892  // create new simple input
893  $aNewInput = array(
894  'type' => 'radio',
895  'name' => $aInput['name'],
896  'value' => $sValue,
897  'checked' => ((string)$sValue === (string)$sCurValue),
898  'label' => $sLabel,
899  );
900 
901  $sNewInput = $this->genInput($aNewInput);
902 
903  // attach new input to complex
904  $sOptions .= ($sNewInput . $sDivider);
905  }
906  }
907 
908  // generate element
909  return $this->getInput('radio_set', $sAttrs, $sOptions);
910  }
911 
912  function genInputCaptcha(&$aInput)
913  {
914  $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
915 
916  // add default className to attributes
917  $aAttrs['class'] = "form_input_{$aInput['type']}" . (isset($aAttrs['class']) ? (' ' . $aAttrs['class']) : '');
918 
919  // for inputs with labels generate id
920  if (isset($aInput['label']))
921  $aAttrs['id'] = $this->getInputId($aInput);
922 
923  $sAttrs = $this->convertArray2Attrs($aAttrs);
924 
925  ch_import('ChWsbCaptcha');
926  $oCaptcha = ChWsbCaptcha::getObjectInstance();
927  $sCaptcha = $oCaptcha ? $oCaptcha->display(isset($aInput['dynamic']) ? $aInput['dynamic'] : false) : _t('_sys_txt_captcha_not_available');
928  $sCaptcha .= $this->getInput('input', $this->convertArray2Attrs(array('type' => 'hidden', 'name' => $aInput['name'])));
929 
930  return $this->getInput('captcha', $sAttrs, $sCaptcha);
931  }
932 
940  function genLabel(&$aInput)
941  {
942  if (!isset($aInput['label']) or empty($aInput['label']))
943  return '';
944 
945  $sLabel = $aInput['label'];
946  $sInputID = $this->getInputId($aInput);
947 
948  return $this->getInput('label', $this->convertArray2Attrs(array('for' => $sInputID)), $sLabel);
949  }
950 
966  function convertArray2Attrs($a)
967  {
968  $sRet = '';
969 
970  if (is_array($a)) {
971  foreach ($a as $sKey => $sValue) {
972 
973  if (!isset($sValue) || is_null($sValue)) // pass NULL values
974  continue;
975 
976  $sValueC = htmlspecialchars_adv($sValue);
977 
978  $sRet .= " $sKey=\"$sValueC\"";
979  }
980  }
981 
982  return $sRet;
983  }
984 
985  function genInfoIcon($sInfo)
986  {
987  return $this->getInput('icon_info', $this->convertArray2Attrs(array(
988  'class' => 'sys-icon info-circle',
989  'float_info' => htmlspecialchars_adv($sInfo)
990  )));
991  }
992 
993  function genErrorIcon( $sError = '' )
994  {
995  if (!$this->bEnableErrorIcon)
996  return '';
997 
998  $sErrorH = ' '; // it has space because jquery doesnt accept it if it is empty
999  if ($sError) {
1000  $sError = str_replace( "\n", "\\n", $sError );
1001  $sError = str_replace( "\r", "", $sError );
1002  $sErrorH = htmlspecialchars_adv($sError);
1003  }
1004 
1005  return $this->getInput('icon_error', $this->convertArray2Attrs(array(
1006  'class' => 'sys-icon exclamation-circle',
1007  'float_info' => $sErrorH
1008  )));
1009  }
1010 
1011  function getOpenTbody($aAttrsAdd = false)
1012  {
1013  if($this->_isTbodyOpened)
1014  return '';
1015 
1016  $this->_isTbodyOpened = true;
1017 
1018  $aAttrsAdd['class'] = 'ch-form-fields-wrapper' . (!empty($aAttrsAdd['class']) ? ' ' . $aAttrsAdd['class'] : '');
1019 
1020  return '<fieldset ' . $this->convertArray2Attrs($aAttrsAdd) . '>';
1021  }
1022 
1023  function getCloseTbody()
1024  {
1025  if(!$this->_isTbodyOpened)
1026  return '';
1027 
1028  $this->_isTbodyOpened = false;
1029 
1030  return '</fieldset>';
1031  }
1032 
1033  function getInput($sType, $sAttrs, $sContent = '')
1034  {
1035  $sResult = '';
1036  switch($sType) {
1037  case 'input':
1038  $sResult = '<input ' . $sAttrs . ' />';
1039  break;
1040  case 'file':
1041  $sResult = '<label class="ch-btn form_input_multiply_select"><input ' . $sAttrs . ' /><span>' . _t('_Select file') . '</span></label>';
1042  break;
1043  case 'button':
1044  $sResult = '<input ' . $sAttrs . ' />';
1045  break;
1046  case 'textarea':
1047  $sResult = '<textarea ' . $sAttrs . '>' . $sContent . '</textarea>';
1048  break;
1049  case 'option':
1050  $sResult = '<option ' . $sAttrs . '>' . $sContent . '</option>';
1051  break;
1052  case 'select':
1053  $sResult = '<select ' . $sAttrs . '>' . $sContent . '</select>';
1054  break;
1055  case 'captcha':
1056  case 'radio_set':
1057  case 'checkbox_set':
1058  $sResult = '<div ' . $sAttrs . '>' . $sContent . '</div>';
1059  break;
1060  case 'label':
1061  $sResult = '<label ' . $sAttrs . '>' . $sContent . '</label>';
1062  break;
1063  case 'icon_info':
1064  $sResult = '<span class="ch-form-info"><i ' . $sAttrs . '></i></span>';
1065  break;
1066  case 'icon_error':
1067  $sResult = '<span class="ch-form-error"><i ' . $sAttrs . '></i></span>';
1068  break;
1069  }
1070  return $sResult;
1071  }
1072 
1073  function addCssJs($isDateControl = false, $isDateTimeControl = false)
1074  {
1075  $aTranslations = array(
1076  '_add',
1077  '_add_other',
1078  '_Remove'
1079  );
1080  $aJs = array(
1081  'jquery.ui.core.min.js',
1082  'jquery.ui.widget.min.js',
1083  'jquery.ui.mouse.min.js',
1084  'jquery.ui.slider.min.js',
1085  );
1086 
1087  $aCss = array(
1088  'forms_adv.css',
1089  'plugins/jquery/themes/|jquery-ui.css',
1090  );
1091 
1092  $aLang = ch_lang_info();
1093  $sLanguageCountry = str_replace('_', '-', $aLang['LanguageCountry']);
1094 
1095  if ($isDateControl || $isDateTimeControl) {
1096 
1097  $aUiLangs = array ('af' => 1, 'ar-DZ' => 1, 'ar' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bs' => 1, 'ca' => 1, 'cs' => 1, 'cy-GB' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'en-AU' => 1, 'en-GB' => 1, 'en-NZ' => 1, 'en' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr-CA' => 1, 'fr-CH' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'kk' => 1, 'km' => 1, 'ko' => 1, 'ky' => 1, 'lb' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'ml' => 1, 'ms' => 1, 'nb' => 1, 'nl-BE' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'rm' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-SR' => 1, 'sr' => 1, 'sv' => 1, 'ta' => 1, 'th' => 1, 'tj' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-HK' => 1, 'zh-TW' => 1);
1098 
1099  // detect language
1100  if (isset($aUiLangs[$sLanguageCountry]))
1101  $sLang = $sLanguageCountry;
1102  elseif (isset($aUiLangs[$aLang['Name']]))
1103  $sLang = $aLang['Name'];
1104  else
1105  $sLang = 'en';
1106 
1107  $aJs [] = 'jquery.ui.datepicker.min.js';
1108  $aJs [] = 'plugins/jquery/i18n/|jquery.ui.datepicker-' . $sLang . '.js';
1109  }
1110 
1111  if ($isDateTimeControl) {
1112 
1113  $aCalendarLangs = array ('af' => 1, 'am' => 1, 'bg' => 1, 'ca' => 1, 'cs' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hr' => 1, 'hu' => 1, 'id' => 1, 'it' => 1, 'ja' => 1, 'ko' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'nl' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sr-RS' => 1, 'sr-YU' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-TW' => 1);
1114 
1115  $aJs[] = 'jquery-ui-timepicker-addon.min.js';
1116  $aJs[] = 'jquery-ui-sliderAccess.js';
1117 
1118  // detect language
1119  if (isset($aCalendarLangs[$sLanguageCountry]))
1120  $aJs[] = 'plugins/jquery/i18n/|jquery-ui-timepicker-' . $sLanguageCountry . '.js';
1121  elseif (isset($aCalendarLangs[$aLang['Name']]))
1122  $aJs[] = 'plugins/jquery/i18n/|jquery-ui-timepicker-' . $aLang['Name'] . '.js';
1123 
1124  $aCss[] = 'plugins/jquery/themes/|jquery-ui-timepicker-addon.css';
1125  }
1126 
1127  if (isset($GLOBALS['oSysTemplate'])) {
1128  $GLOBALS['oSysTemplate']->addCss($aCss);
1129  $GLOBALS['oSysTemplate']->addJs($aJs);
1130  $GLOBALS['oSysTemplate']->addJsTranslation($aTranslations);
1131  }
1132  if (isset($GLOBALS['oAdmTemplate'])) {
1133  $GLOBALS['oAdmTemplate']->addJs($aJs);
1134  $GLOBALS['oAdmTemplate']->addCss($aCss);
1135  }
1136  }
1137 }
ChBaseFormView\genWrapperInput
genWrapperInput($aInput, $sContent)
Definition: ChBaseFormView.php:349
ChBaseFormView\getInput
getInput($sType, $sAttrs, $sContent='')
Definition: ChBaseFormView.php:1033
ChBaseFormView\$_isDateTimeControl
$_isDateTimeControl
Definition: ChBaseFormView.php:33
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
$sResult
$sResult
Definition: advanced_settings.php:26
ChBaseFormView\genInputSelectBox
genInputSelectBox(&$aInput, $sInfo='', $sError='')
Definition: ChBaseFormView.php:697
ChBaseFormView\$_sCodeAdd
$_sCodeAdd
Definition: ChBaseFormView.php:28
ChBaseFormView\genErrorIcon
genErrorIcon( $sError='')
Definition: ChBaseFormView.php:993
php
ChBaseFormView\$_isDateControl
$_isDateControl
Definition: ChBaseFormView.php:32
ChBaseFormView\getOpenTbody
getOpenTbody($aAttrsAdd=false)
Definition: ChBaseFormView.php:1011
ChBaseFormView\genInputStandard
genInputStandard(&$aInput)
Definition: ChBaseFormView.php:516
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
$aInfo
$aInfo
Definition: constants.inc.php:21
ch_lang_info
ch_lang_info()
Definition: languages.inc.php:562
ChBaseFormView\getCode
getCode()
Definition: ChBaseFormView.php:56
$sType
$sType
Definition: actions.inc.php:11
ChBaseFormView\$bEnableErrorIcon
$bEnableErrorIcon
Definition: ChBaseFormView.php:12
ChBaseFormView\genRowSelectBox
genRowSelectBox(&$aInput)
Definition: ChBaseFormView.php:240
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChBaseFormView\addCssJs
addCssJs($isDateControl=false, $isDateTimeControl=false)
Definition: ChBaseFormView.php:1073
ChWsbForm\getCsrfToken
static getCsrfToken()
Definition: ChWsbForm.php:289
ChBaseFormView\genRowStandard
genRowStandard(&$aInput)
Definition: ChBaseFormView.php:169
htmlspecialchars_adv
htmlspecialchars_adv($string)
Definition: utils.inc.php:302
ChBaseFormView\__construct
__construct($aInfo)
Definition: ChBaseFormView.php:46
ChBaseFormView\convertArray2Attrs
convertArray2Attrs($a)
Definition: ChBaseFormView.php:966
ChBaseFormView\getCloseTbody
getCloseTbody()
Definition: ChBaseFormView.php:1023
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChWsbForm
Definition: ChWsbForm.php:103
ChBaseFormView\$_isTbodyOpened
$_isTbodyOpened
Definition: ChBaseFormView.php:30
ChBaseFormView\$sCode
$sCode
Definition: ChBaseFormView.php:19
ChBaseFormView\genRowBlockHeader
genRowBlockHeader(&$aInput)
Definition: ChBaseFormView.php:300
ChBaseFormView\genInfoIcon
genInfoIcon($sInfo)
Definition: ChBaseFormView.php:985
$sCaption
$sCaption
Definition: tellfriend.php:39
ChBaseFormView\genTable
genTable()
Definition: ChBaseFormView.php:96
ChBaseFormView\genRowHeaders
genRowHeaders(&$aInput)
Definition: ChBaseFormView.php:281
$sError
$sError
Definition: index.php:425
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChBaseFormView\genForm
genForm()
Definition: ChBaseFormView.php:78
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChBaseFormView\genRow
genRow(&$aInput)
Definition: ChBaseFormView.php:131
ChBaseFormView
Definition: ChBaseFormView.php:11
ChBaseFormView\genInput
genInput(&$aInput)
Definition: ChBaseFormView.php:366
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
ChBaseFormView\genBlockEnd
genBlockEnd()
Definition: ChBaseFormView.php:344