style_button.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Base class for <input /> form elements
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  17. * @author Bertrand Mansion <bmansion@mamasam.com>
  18. * @copyright 2001-2007 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: input.php 17344 2008-12-17 08:55:29Z Scara84 $
  21. * @link http://pear.php.net/package/HTML_QuickForm
  22. */
  23. /**
  24. * Base class for form elements
  25. */
  26. //require_once 'HTML/QuickForm/element.php';
  27. /**
  28. * Base class for <button></button> form elements
  29. *
  30. * @category HTML
  31. * @package HTML_QuickForm
  32. * @author Hans De Bisschop <hans.de.bisschop@ehb.be>
  33. * @abstract
  34. */
  35. class HTML_QuickForm_stylebutton extends HTML_QuickForm_element
  36. {
  37. /**
  38. * Class constructor
  39. *
  40. * @param string Input field name attribute
  41. * @param mixed Label(s) for the input field
  42. * @param mixed Either a typical HTML attribute string or an associative array
  43. * @since 1.0
  44. * @access public
  45. * @return void
  46. */
  47. public function HTML_QuickForm_stylebutton($elementName = null, $elementLabel = null, $attributes = null)
  48. {
  49. $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  50. }
  51. /** Returns an HTML formatted attribute string
  52. * @param array $attributes
  53. * @return string
  54. * @access private
  55. */
  56. public function _getAttrString($attributes) {
  57. $strAttr = '';
  58. if (is_array($attributes)) {
  59. foreach ($attributes as $key => $value) {
  60. if ($key != 'value') {
  61. $strAttr .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
  62. }
  63. }
  64. }
  65. return $strAttr;
  66. }
  67. public function setType($type)
  68. {
  69. $this->_type = $type;
  70. $this->updateAttributes(array('type'=>$type));
  71. }
  72. /**
  73. * Sets the input field name
  74. *
  75. * @param string $name Input field name attribute
  76. * @since 1.0
  77. * @access public
  78. * @return void
  79. */
  80. public function setName($name)
  81. {
  82. $this->updateAttributes(array('name'=>$name));
  83. }
  84. /**
  85. * Returns the element name
  86. *
  87. * @since 1.0
  88. * @access public
  89. * @return string
  90. */
  91. public function getName()
  92. {
  93. return $this->getAttribute('name');
  94. }
  95. /**
  96. * Sets the value of the form element
  97. *
  98. * @param string $value Default value of the form element
  99. * @since 1.0
  100. * @access public
  101. * @return void
  102. */
  103. public function setValue($value)
  104. {
  105. $this->updateAttributes(array('value'=>$value));
  106. }
  107. /**
  108. * Returns the value of the form element
  109. *
  110. * @since 1.0
  111. * @access public
  112. * @return string
  113. */
  114. public function getValue()
  115. {
  116. //return $this->getAttribute('value');
  117. return $this->_attributes['value'];
  118. }
  119. /**
  120. * Returns the input field in HTML
  121. *
  122. * @since 1.0
  123. * @access public
  124. * @return string
  125. */
  126. public function toHtml()
  127. {
  128. if ($this->_flagFrozen) {
  129. return $this->getFrozenHtml();
  130. } else {
  131. // Adding the btn class
  132. if (isset($this->_attributes['class'])) {
  133. $this->_attributes['class'] = 'btn '.$this->_attributes['class'];
  134. }
  135. $addIcon = null;
  136. if (strpos($this->_attributes['class'], 'search')) {
  137. $this->_attributes['class'] = 'btn btn-primary';
  138. $addIcon = '<i class="fa fa-search fa-lg"></i> ';
  139. }
  140. if (strpos($this->_attributes['class'], 'minus')) {
  141. $this->_attributes['class'] = 'btn btn-danger';
  142. $addIcon = '<i class="fa fa-minus-circle fa-lg"></i> ';
  143. }
  144. if (strpos($this->_attributes['class'], 'plus')) {
  145. $this->_attributes['class'] = 'btn btn-success';
  146. $addIcon = '<i class="fa fa-plus-circle fa-lg"></i> ';
  147. }
  148. if (strpos($this->_attributes['class'], 'save')) {
  149. $this->_attributes['class'] = 'btn btn-primary';
  150. $addIcon = '<i class="fa fa-check fa-lg"></i> ';
  151. }
  152. if (strpos($this->_attributes['class'], 'add')) {
  153. $this->_attributes['class'] = 'btn btn-primary';
  154. $addIcon = '<i class="fa fa-plus"></i></i> ';
  155. }
  156. return $this->_getTabs().
  157. '<button '.$this->_getAttrString($this->_attributes).' >'.$addIcon.$this->getValue() .'</button>';
  158. }
  159. }
  160. /**
  161. * Called by HTML_QuickForm whenever form event is made on this element
  162. *
  163. * @param string $event Name of event
  164. * @param mixed $arg event arguments
  165. * @param object &$caller calling object
  166. * @since 1.0
  167. * @access public
  168. * @return void
  169. * @throws
  170. */
  171. public function onQuickFormEvent($event, $arg, &$caller)
  172. {
  173. // do not use submit values for button-type elements
  174. $type = $this->getType();
  175. if (('updateValue' != $event) ||
  176. ('submit' != $type && 'reset' != $type && 'button' != $type)) {
  177. parent::onQuickFormEvent($event, $arg, $caller);
  178. } else {
  179. $value = $this->_findValue($caller->_constantValues);
  180. if (null === $value) {
  181. $value = $this->_findValue($caller->_defaultValues);
  182. }
  183. if (null !== $value) {
  184. $this->setValue($value);
  185. }
  186. }
  187. return true;
  188. }
  189. /**
  190. * We don't need values from button-type elements (except submit) and files
  191. * @param $submitValues
  192. * @param bool $assoc
  193. * @return mixed|null
  194. */
  195. public function exportValue(&$submitValues, $assoc = false)
  196. {
  197. $type = $this->getType();
  198. if ('reset' == $type || 'button' == $type) {
  199. return null;
  200. } else {
  201. return parent::exportValue($submitValues, $assoc);
  202. }
  203. }
  204. }