PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/plugin/packages/xajax/xajax_controls/form.inc.php

http://osezno-php-framework.googlecode.com/
PHP | 315 lines | 167 code | 34 blank | 114 comment | 28 complexity | 80957156dd7ba80731738c8a15d7d82e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /*
  3. File: form.inc.php
  4. HTML Control Library - Form Level Tags
  5. Title: xajax HTML control class library
  6. Please see <copyright.inc.php> for a detailed description, copyright
  7. and license information.
  8. */
  9. /*
  10. @package xajax
  11. @version $Id: form.inc.php 362 2007-05-29 15:32:24Z calltoconstruct $
  12. @copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
  13. @copyright Copyright (c) 2008-2009 by Joseph Woolley, Steffen Konerow, Jared White & J. Max Wilson
  14. @license http://www.xajaxproject.org/bsd_license.txt BSD License
  15. */
  16. /*
  17. Section: Description
  18. This file contains the class declarations for the following HTML Controls:
  19. - form
  20. - input, textarea, select, optgroup, option
  21. - label
  22. - fieldset, legend
  23. The following tags are deprecated as of HTML 4.01, therefore, they will not
  24. be supported:
  25. - isindex
  26. */
  27. class clsForm extends xajaxControlContainer
  28. {
  29. function clsForm($aConfiguration=array())
  30. {
  31. if (false == isset($aConfiguration['attributes']))
  32. $aConfiguration['attributes'] = array();
  33. if (false == isset($aConfiguration['attributes']['method']))
  34. $aConfiguration['attributes']['method'] = 'POST';
  35. if (false == isset($aConfiguration['attributes']['action']))
  36. $aConfiguration['attributes']['action'] = '#';
  37. xajaxControlContainer::xajaxControlContainer('form', $aConfiguration);
  38. }
  39. }
  40. class clsInput extends xajaxControl
  41. {
  42. function clsInput($aConfiguration=array())
  43. {
  44. xajaxControl::xajaxControl('input', $aConfiguration);
  45. }
  46. }
  47. class clsInputWithLabel extends clsInput
  48. {
  49. var $objLabel;
  50. var $sWhere;
  51. var $objBreak;
  52. function clsInputWithLabel($sLabel, $sWhere, $aConfiguration=array())
  53. {
  54. clsInput::clsInput($aConfiguration);
  55. $this->objLabel =& new clsLabel(array(
  56. 'child' => new clsLiteral($sLabel)
  57. ));
  58. $this->objLabel->setControl($this);
  59. $this->sWhere = $sWhere;
  60. $this->objBreak =& new clsBr();
  61. }
  62. function printHTML($sIndent='')
  63. {
  64. if ('left' == $this->sWhere || 'above' == $this->sWhere)
  65. $this->objLabel->printHTML($sIndent);
  66. if ('above' == $this->sWhere)
  67. $this->objBreak->printHTML($sIndent);
  68. clsInput::printHTML($sIndent);
  69. if ('below' == $this->sWhere)
  70. $this->objBreak->printHTML($sIndent);
  71. if ('right' == $this->sWhere || 'below' == $this->sWhere)
  72. $this->objLabel->printHTML($sIndent);
  73. }
  74. }
  75. /*
  76. Class: clsSelect
  77. A <xajaxControlContainer> derived class that assists in the construction
  78. of an HTML select control.
  79. This control can only accept <clsOption> controls as children.
  80. */
  81. class clsSelect extends xajaxControlContainer
  82. {
  83. /*
  84. Function: clsSelect
  85. Construct and initialize an instance of the class. See <xajaxControlContainer>
  86. for details regarding the aConfiguration parameter.
  87. */
  88. function clsSelect($aConfiguration=array())
  89. {
  90. xajaxControlContainer::xajaxControlContainer('select', $aConfiguration);
  91. }
  92. /*
  93. Function: addOption
  94. Used to add a single option to the options list.
  95. sValue - (string): The value that is returned as the form value
  96. when this option is the selected option.
  97. sText - (string): The text that is displayed in the select box when
  98. this option is the selected option.
  99. */
  100. function addOption($sValue, $sText)
  101. {
  102. $optionNew =& new clsOption();
  103. $optionNew->setValue($sValue);
  104. $optionNew->setText($sText);
  105. $this->addChild($optionNew);
  106. }
  107. /*
  108. Function: addOptions
  109. Used to add a list of options.
  110. aOptions - (associative array): A list of key/value pairs that will
  111. be passed to <clsSelect->addOption>.
  112. */
  113. function addOptions($aOptions, $aFields=array())
  114. {
  115. if (0 == count($aFields))
  116. foreach ($aOptions as $sValue => $sText)
  117. $this->addOption($sValue, $sText);
  118. else if (1 < count($aFields))
  119. foreach ($aOptions as $aOption)
  120. $this->addOption($aOption[$aFields[0]], $aOption[$aFields[1]]);
  121. else
  122. trigger_error('Invalid list of fields passed to clsSelect::addOptions; should be array of two strings.'
  123. . $this->backtrace(),
  124. E_USER_ERROR
  125. );
  126. }
  127. }
  128. /*
  129. Class: clsOptionGroup
  130. A <xajaxControlContainer> derived class that can be used around a list of <clsOption>
  131. objects to help the user find items in a select list.
  132. */
  133. class clsOptionGroup extends xajaxControlContainer
  134. {
  135. function clsOptionGroup($aConfiguration=array())
  136. {
  137. xajaxControlContainer::xajaxControlContainer('optgroup', $aConfiguration);
  138. }
  139. /*
  140. Function: addOption
  141. Used to add a single option to the options list.
  142. sValue - (string): The value that is returned as the form value
  143. when this option is the selected option.
  144. sText - (string): The text that is displayed in the select box when
  145. this option is the selected option.
  146. */
  147. function addOption($sValue, $sText)
  148. {
  149. $optionNew =& new clsOption();
  150. $optionNew->setValue($sValue);
  151. $optionNew->setText($sText);
  152. $this->addChild($optionNew);
  153. }
  154. /*
  155. Function: addOptions
  156. Used to add a list of options.
  157. aOptions - (associative array): A list of key/value pairs that will
  158. be passed to <clsSelect->addOption>.
  159. */
  160. function addOptions($aOptions, $aFields=array())
  161. {
  162. if (0 == count($aFields))
  163. foreach ($aOptions as $sValue => $sText)
  164. $this->addOption($sValue, $sText);
  165. else if (1 < count($aFields))
  166. foreach ($aOptions as $aOption)
  167. $this->addOption($aOption[$aFields[0]], $aOption[$aFields[1]]);
  168. else
  169. trigger_error('Invalid list of fields passed to clsOptionGroup::addOptions; should be array of two strings.'
  170. . $this->backtrace(),
  171. E_USER_ERROR
  172. );
  173. }
  174. }
  175. /*
  176. Class: clsOption
  177. A <xajaxControlContainer> derived class that assists with the construction
  178. of HTML option tags that will be assigned to an HTML select tag.
  179. This control can only accept <clsLiteral> objects as children.
  180. */
  181. class clsOption extends xajaxControlContainer
  182. {
  183. /*
  184. Function: clsOption
  185. Constructs and initializes an instance of this class. See <xajaxControlContainer>
  186. for more information regarding the aConfiguration parameter.
  187. */
  188. function clsOption($aConfiguration=array())
  189. {
  190. xajaxControlContainer::xajaxControlContainer('option', $aConfiguration);
  191. }
  192. /*
  193. Function: setValue
  194. Used to set the value associated with this option. The value is sent as the
  195. value of the select control when this is the selected option.
  196. */
  197. function setValue($sValue)
  198. {
  199. $this->setAttribute('value', $sValue);
  200. }
  201. /*
  202. Function: setText
  203. Sets the text to be shown in the select control when this is the
  204. selected option.
  205. */
  206. function setText($sText)
  207. {
  208. $this->clearChildren();
  209. $this->addChild(new clsLiteral($sText));
  210. }
  211. }
  212. class clsTextArea extends xajaxControlContainer
  213. {
  214. function clsTextArea($aConfiguration=array())
  215. {
  216. xajaxControlContainer::xajaxControlContainer('textarea', $aConfiguration);
  217. $this->sClass = '%block';
  218. }
  219. }
  220. class clsLabel extends xajaxControlContainer
  221. {
  222. var $objFor;
  223. function clsLabel($aConfiguration=array())
  224. {
  225. xajaxControlContainer::xajaxControlContainer('label', $aConfiguration);
  226. }
  227. function setControl(&$objControl)
  228. {
  229. if (false == is_a($objControl, 'xajaxControl'))
  230. trigger_error(
  231. 'Invalid control passed to clsLabel::setControl(); should be xajaxControl.'
  232. . $this->backtrace(),
  233. E_USER_ERROR);
  234. $this->objFor =& $objControl;
  235. }
  236. function printHTML($sIndent='')
  237. {
  238. $this->aAttributes['for'] = $this->objFor->aAttributes['id'];
  239. xajaxControlContainer::printHTML($sIndent);
  240. }
  241. }
  242. class clsFieldset extends xajaxControlContainer
  243. {
  244. function clsFieldset($aConfiguration=array())
  245. {
  246. xajaxControlContainer::xajaxControlContainer('fieldset', $aConfiguration);
  247. $this->sClass = '%block';
  248. }
  249. }
  250. class clsLegend extends xajaxControlContainer
  251. {
  252. function clsLegend($aConfiguration=array())
  253. {
  254. xajaxControlContainer::xajaxControlContainer('legend', $aConfiguration);
  255. $this->sClass = '%inline';
  256. }
  257. }