1
0

BxSampleForm.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreSamples Samples
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section form Form
  12. */
  13. /**
  14. -- SQL dump of table with sample data:
  15. CREATE TABLE IF NOT EXISTS `sample_input_types` (
  16. `id` int(11) NOT NULL AUTO_INCREMENT,
  17. `text` varchar(255) NOT NULL,
  18. `date` int(11) NOT NULL,
  19. `datetime` int(11) NOT NULL,
  20. `number` int(11) NOT NULL,
  21. `checkbox` varchar(255) NOT NULL,
  22. `password` varchar(255) NOT NULL,
  23. `slider` int(11) NOT NULL,
  24. `doublerange` varchar(255) NOT NULL,
  25. `switcher` varchar(255) NOT NULL,
  26. `textarea` text NOT NULL,
  27. `select` int(11) NOT NULL,
  28. `select_multiple` varchar(255) NOT NULL,
  29. `checkbox_set` varchar(255) NOT NULL,
  30. `radio_set` int(11) NOT NULL,
  31. `custom` varchar(255) NOT NULL,
  32. PRIMARY KEY (`id`)
  33. );
  34. -- SQL dump of form object:
  35. INSERT INTO `sys_objects_form` (`object`, `module`, `title`, `action`, `form_attrs`, `submit_name`, `table`, `key`, `uri`, `uri_title`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES
  36. ('sample_form_objects', 'custom', 'Sample Form Object', 'samples/form_objects.php', '', 'do_submit', 'sample_input_types', 'id', '', '', 'a:1:{s:14:"checker_helper";s:25:"BxSampleFormCheckerHelper";}', 1, 1, 'BxSampleForm', 'samples/BxSampleForm.php');
  37. -- SQL dump of form displays:
  38. INSERT INTO `sys_form_displays` (`display_name`, `module`, `object`, `title`) VALUES
  39. ('sample_form_objects_add', 'custom', 'sample_form_objects', 'Add'),
  40. ('sample_form_objects_edit', 'custom', 'sample_form_objects', 'Edit');
  41. -- SQL dump of form inputs:
  42. INSERT INTO `sys_form_inputs` (`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES
  43. ('sample_form_objects', 'custom', 'id', '', '', 0, 'hidden', 'ID', 'ID', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
  44. ('sample_form_objects', 'custom', 'header_contact', '', '', 0, 'block_header', 'All input types block', 'All possible form input types', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  45. ('sample_form_objects', 'custom', 'text', '', '', 0, 'text', 'Text', 'Text', '', 1, 0, 0, '', '', '', 'avail', '', 'Text is required', 'Xss', '', 1, 1),
  46. ('sample_form_objects', 'custom', 'date', '', '', 0, 'datepicker', 'Date', 'Date', '', 1, 0, 0, '', '', '', 'avail', '', 'Date is required', 'Date', '', 1, 1),
  47. ('sample_form_objects', 'custom', 'datetime', '', '', 0, 'datetime', 'Datetime', 'Datetime', '', 0, 0, 0, '', '', '', '', '', '', 'DateTime', '', 1, 1),
  48. ('sample_form_objects', 'custom', 'number', '42', '', 0, 'number', 'Number', 'Number', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 1),
  49. ('sample_form_objects', 'custom', 'checkbox', '1', '', 0, 'checkbox', 'Checkbox', 'Checkbox', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 1),
  50. ('sample_form_objects', 'custom', 'file', '', '', 0, 'file', 'File', 'File', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  51. ('sample_form_objects', 'custom', 'image', '', '', 0, 'image', 'Image', 'Image', '', 0, 0, 0, 'a:1:{s:3:"src";s:85:"http://demo.boonex.com/m/photos/get_image/browse/d7bd9bb01ce45617d709dfd47826d4a3.jpg";}', '', '', '', '', '', '', '', 1, 1),
  52. ('sample_form_objects', 'custom', 'password', '', '', 0, 'password', 'Password', 'Password', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 1),
  53. ('sample_form_objects', 'custom', 'slider', '21', '', 0, 'slider', 'Slider', 'Slider', '', 0, 0, 0, 'a:2:{s:3:"min";i:16;s:3:"max";i:99;}', '', '', '', '', '', 'Int', '', 1, 1),
  54. ('sample_form_objects', 'custom', 'doublerange', '20-35', '', 0, 'doublerange', 'Doublerange', 'Doublerange', '', 0, 0, 0, 'a:2:{s:3:"min";i:16;s:3:"max";i:99;}', '', '', '', '', '', 'Xss', '', 1, 1),
  55. ('sample_form_objects', 'custom', 'hidden', '', '', 0, 'hidden', 'Hidden', 'Hidden', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  56. ('sample_form_objects', 'custom', 'switcher', '1', '', 0, 'switcher', 'Switcher', 'Switcher', '', 0, 0, 0, '', '', '', '', '', '', 'Xss', '', 1, 1),
  57. ('sample_form_objects', 'custom', 'button', '_Befriend', '', 0, 'button', 'Button', 'Button', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  58. ('sample_form_objects', 'custom', 'reset', '_Befriend', '', 0, 'reset', 'Reset', 'Reset', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  59. ('sample_form_objects', 'custom', 'submit', '_Befriend', '', 0, 'submit', 'Submit', 'Submit', '', 0, 0, 0, 'a:1:{s:5:"class";s:23:"bx-def-margin-sec-right";}', '', '', '', '', '', '', '', 1, 1),
  60. ('sample_form_objects', 'custom', 'textarea', '', '', 0, 'textarea', 'Textarea', 'Textarea', '', 0, 0, 1, '', '', '', '', '', '', 'XssHtml', '', 1, 1),
  61. ('sample_form_objects', 'custom', 'select', '', '#!Language', 0, 'select', 'Select', 'Select', '', 0, 0, 0, '', '', '', '', '', '', 'int', '', 1, 1),
  62. ('sample_form_objects', 'custom', 'select_multiple', '', '#!Sex', 0, 'select_multiple', 'Select Multiple', 'Select Multiple', '', 0, 0, 0, '', '', '', '', '', '', 'Set', '', 1, 1),
  63. ('sample_form_objects', 'custom', 'checkbox_set', '', '#!Sex', 0, 'checkbox_set', 'Checkbox Set', 'Checkbox Set', '', 0, 0, 0, '', '', '', '', '', '', 'Set', '', 1, 1),
  64. ('sample_form_objects', 'custom', 'radio_set', '', '#!Sex', 0, 'radio_set', 'Radio Set', 'Radio Set', '', 0, 0, 0, '', '', '', '', '', '', 'Int', '', 1, 1),
  65. ('sample_form_objects', 'custom', 'input_set', '', 'submit,reset', 0, 'input_set', 'Input Set', 'Input Set', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  66. ('sample_form_objects', 'custom', 'custom', '', '', 0, 'custom', 'Custom', 'Custom', '', 0, 0, 0, '', '', '', '', '', '', 'Rgb', '', 1, 1),
  67. ('sample_form_objects', 'custom', 'value', 'вот...', '', 0, 'value', 'Value', 'Value', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  68. ('sample_form_objects', 'custom', 'captcha', '', '', 0, 'captcha', 'Captcha', 'Captcha', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  69. ('sample_form_objects', 'custom', 'header_submit', '', '', 0, 'block_header', 'Submit form block', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1),
  70. ('sample_form_objects', 'custom', 'do_submit', '_Submit', '', 0, 'submit', 'Submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 1);
  71. -- SQL dump of form inputs association with form display:
  72. INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES
  73. ('sample_form_objects_add', 'header_contact', 2147483647, 1, 10),
  74. ('sample_form_objects_add', 'text', 2147483647, 1, 20),
  75. ('sample_form_objects_add', 'date', 2147483647, 1, 30),
  76. ('sample_form_objects_add', 'datetime', 2147483647, 1, 40),
  77. ('sample_form_objects_add', 'number', 2147483647, 1, 50),
  78. ('sample_form_objects_add', 'checkbox', 2147483647, 1, 60),
  79. ('sample_form_objects_add', 'file', 2147483647, 1, 70),
  80. ('sample_form_objects_add', 'image', 2147483647, 1, 80),
  81. ('sample_form_objects_add', 'password', 2147483647, 1, 90),
  82. ('sample_form_objects_add', 'slider', 2147483647, 1, 100),
  83. ('sample_form_objects_add', 'doublerange', 2147483647, 1, 110),
  84. ('sample_form_objects_add', 'hidden', 2147483647, 1, 120),
  85. ('sample_form_objects_add', 'switcher', 2147483647, 1, 130),
  86. ('sample_form_objects_add', 'button', 2147483647, 1, 140),
  87. ('sample_form_objects_add', 'reset', 2147483647, 1, 150),
  88. ('sample_form_objects_add', 'submit', 2147483647, 1, 160),
  89. ('sample_form_objects_add', 'textarea', 2147483647, 1, 170),
  90. ('sample_form_objects_add', 'select', 2147483647, 1, 180),
  91. ('sample_form_objects_add', 'select_multiple', 2147483647, 1, 190),
  92. ('sample_form_objects_add', 'checkbox_set', 2147483647, 1, 200),
  93. ('sample_form_objects_add', 'radio_set', 2147483647, 1, 210),
  94. ('sample_form_objects_add', 'input_set', 2147483647, 1, 220),
  95. ('sample_form_objects_add', 'custom', 2147483647, 1, 230),
  96. ('sample_form_objects_add', 'captcha', 2147483647, 1, 240),
  97. ('sample_form_objects_add', 'value', 2147483647, 1, 250),
  98. ('sample_form_objects_add', 'header_submit', 2147483647, 1, 1000),
  99. ('sample_form_objects_add', 'do_submit', 2147483647, 1, 1001),
  100. ('sample_form_objects_edit', 'id', 2147483647, 1, 10),
  101. ('sample_form_objects_edit', 'text', 2147483647, 0, 20),
  102. ('sample_form_objects_edit', 'date', 2147483647, 1, 30),
  103. ('sample_form_objects_edit', 'datetime', 2147483647, 1, 40),
  104. ('sample_form_objects_edit', 'number', 2147483647, 1, 50),
  105. ('sample_form_objects_edit', 'checkbox', 2147483647, 1, 60),
  106. ('sample_form_objects_edit', 'password', 2147483647, 1, 70),
  107. ('sample_form_objects_edit', 'slider', 2147483647, 1, 80),
  108. ('sample_form_objects_edit', 'doublerange', 2147483647, 1, 90),
  109. ('sample_form_objects_edit', 'switcher', 2147483647, 1, 100),
  110. ('sample_form_objects_edit', 'textarea', 2147483647, 1, 110),
  111. ('sample_form_objects_edit', 'select', 2147483647, 1, 120),
  112. ('sample_form_objects_edit', 'select_multiple', 2147483647, 1, 130),
  113. ('sample_form_objects_edit', 'checkbox_set', 2147483647, 1, 140),
  114. ('sample_form_objects_edit', 'radio_set', 2147483647, 1, 150),
  115. ('sample_form_objects_edit', 'custom', 2147483647, 1, 160),
  116. ('sample_form_objects_edit', 'do_submit', 2147483647, 1, 1000);
  117. */
  118. class BxSampleForm extends BxTemplFormView
  119. {
  120. public function __construct ($aInfo, $oTemplate = false)
  121. {
  122. parent::__construct ($aInfo, $oTemplate);
  123. }
  124. /**
  125. * display input with 'custom' name
  126. */
  127. protected function genCustomInputCustom ($aInput)
  128. {
  129. return
  130. 'r: <input type="text" size="2" value="'.(isset($aInput['value'][0]) ? $aInput['value'][0] : '').'" name="'.$aInput['name'].'[]" />' .
  131. 'g: <input type="text" size="2" value="'.(isset($aInput['value'][1]) ? $aInput['value'][1] : '').'" name="'.$aInput['name'].'[]" />' .
  132. 'b: <input type="text" size="2" value="'.(isset($aInput['value'][2]) ? $aInput['value'][2] : '').'" name="'.$aInput['name'].'[]" />';
  133. }
  134. }
  135. class BxSampleFormCheckerHelper extends BxDolFormCheckerHelper
  136. {
  137. protected $_sDiv = ',';
  138. /**
  139. * prepare RBG values to save to the DB
  140. */
  141. function passRgb ($s)
  142. {
  143. if (!is_array($s))
  144. return false;
  145. $sRet = '';
  146. foreach ($s as $k => $v)
  147. $sRet .= (int)trim($v) . $this->_sDiv;
  148. return trim($sRet, $this->_sDiv);
  149. }
  150. /**
  151. * prepare RGB values to output to the screen
  152. */
  153. function displayRgb ($s)
  154. {
  155. return explode($this->_sDiv, $s);
  156. }
  157. }
  158. /** @} */