Thread: [Phphtmllib-devel] SF.net SVN: phphtmllib:[3127] branches/BRANCH_2_X/phphtmllib/form/ form_elements
Status: Beta
Brought to you by:
hemna
From: <mpw...@us...> - 2008-08-02 01:15:33
|
Revision: 3127 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3127&view=rev Author: mpwalsh8 Date: 2008-08-02 01:15:40 +0000 (Sat, 02 Aug 2008) Log Message: ----------- Added FEDay class to select day and month pair. Modified Paths: -------------- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc Modified: branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc =================================================================== --- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2008-08-02 01:14:40 UTC (rev 3126) +++ branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2008-08-02 01:15:40 UTC (rev 3127) @@ -1562,8 +1562,332 @@ } +/** + * This class builds a widget that shows a group of select boxes (FEMonths, FEDays) representing a date. + * + * FEDate will display two drop down lists representing a date. You can set + * the order in which these elements are displayed. + * + * Like in FEMonths you should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale} + * function to affect the language used for the month list. + * + * Example as it would appear in FormContent::form_init_elements(): + * <code> + * // set the locale to dutch + * setlocale(LC_TIME, 'nl_NL'); + * $date_element = new FEDay("FEDay label", false, null, null, 'Fd'); + * </code> + * + * the $format parameter conforms the the php {@link http://www.php.net/manual/en/function.setlocale.php date} function + * format argument specification (for years, months and days only). + * + * @author Culley Harrelson <cu...@fa...> + * @author Suren Markosian <su...@em...> + * @author Mike Walsh <mik...@mi...> + * @see FEMonths + * @see FEDays + * + */ +class FEDay extends FEBoxElement { + /** + * The order in which to show the elements. This variable must be 3 + * characters long and contain only one m only one d and only one y. + * + * @var string + * @access private + */ + var $_format = 'md'; + + /** + * A printf style format string used to add punctuation to the confirmation + * display. Defaults to space separated. The placeholders are filled + * according to the order set in $_format + * + * @var string + * @access private + */ + var $_text_format = '%s %s'; + + /** + * The month form element + * + * @var FEMonths + * @access private + */ + var $_month; + + /** + * The day form element + * + * @var FEDays + * @access private + */ + var $_day; + + /** + * The constructor + * + * @param string text label for the element + * @param boolean is this a required element? + * @param int element width in characters, pixels (px), percentage (%) or elements (em) + * @param int element height in px + * @param string date format string. M m F d D are valid. 2 characters max. + * @see FEDay for an example + * @todo we need to blow up somehow if the format string is bogus + * @access public + * + */ + + function FEDay($label, $required = TRUE, $width = NULL, $height = NULL, + $format = 'md'){ + + $this->_set_format($format); + + //call the parent constructor first + //so the element_name is built. + parent::FEBoxElement($label, $required, $width, $height); + + //now create the child elements. + $this->_month = new FEMonths($this->_element_name . '_months', $required, null, null, preg_replace('/[d]/i', '', $this->_format)); + $this->_day = new FEDays($this->_element_name . '_days', $required, null, null); + } + + /** + * We need to override this so we get + * the form name set in the child elements + * so the id attributes are set correctly. + */ + function set_form_name($name) { + $this->_form_name = $name; + $this->_month->set_form_name($name); + $this->_day->set_form_name($name); + } + + /** + * This function builds and returns the + * form element object + * + * @return object + * @access public + */ + function get_element(){ + + $container = new Container(); + + // add the elements in the order specified. + $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY); + foreach ($chars as $char){ + switch ($char) { + case 'm': + case 'F': + $container->add($this->_month->get_element()); + break; + case 'd': + $container->add($this->_day->get_element()); + break; + } + } + + return $container; + } + + /** + * This function will return the elements value as an array or month, day and year + * + * @return array + * @access public + */ + function get_value(){ + $value= array("day"=>$this->_day->get_value(), + "month"=>$this->_month->get_value()); + + return $value; + + + } + + /** + * Set the value of the element + * + * This function sets the default values for the date element The + * parameter should be a string representation of the date in ISO 8601 + * format. + * + * @param string + * @access public + */ + function set_value($value){ + if ($value) { + if (is_array($value)) { + $this->_month->set_value($value['month']); + $this->_day->set_value($value['day']); + } else { + $date_parts = explode('-', $value); + $this->_month->set_value($date_parts[1]); + $this->_day->set_value($date_parts[2]); + } + } + + + } + + /** + * This returns a formatted string used for the confirmation display (and possibly elsewhere) + * + * @return string + * @access public + */ + function get_value_text(){ + + // loop through the characters in $_format to properly set the placeholders + // determined in $_text_format + $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY); + $i = 1; + foreach ($chars as $char){ + + switch ($char) { + case 'm': + case 'F': + $value = $this->_month->get_value_text(); + break; + case 'd': + $value = $this->_day->get_value_text(); + break; + } + + switch ($i) { + case 1: + $one = $value; + break; + case 2: + $two = $value; + break; + } + + $i++; + } + + return sprintf($this->_text_format, $one, $two); + } + + /** + * + * This function is responsible for performing complete + * validation and setting the appropriate error message + * in case of a failed validation + * + * @param FormValidation + * @access public + * @return boolean success or failure + */ + function validate(&$_FormValidation){ + $value = $this->get_value(); + + //we make sure that the date is valid, spoof the year + //this may break on February 29th .... + if (!checkdate($value["month"], $value["day"], date("Y"))) { + $this->set_error_message("Invalid date"); + return FALSE; + } + return TRUE; + } + + /** + * this method sets the display order for the elements in the widget + * + * @param string + * @return bool success or failure + * @access private + */ + function _set_format($format){ + + // must be 2 or 3 characters + if (strlen($format) != 2) { + return FALSE; + } + + // month can be represented by F m or M + if (strstr($format, 'F')) { + $month = 'f'; + } else { + $month = 'm'; + } + + // compare the characters sent with the characters needed. only set + // the property if one of each is present + $search_for = array ($month, 'd'); + $chars = preg_split('//', strtolower($format), -1, PREG_SPLIT_NO_EMPTY); + + if (count(array_diff($search_for, $chars)) > 0) { + return FALSE; + } + + $this->_format = $format; + return TRUE; + + + } + + /** + * Set the text format for confirmation + * + * this method sets the format string used in get_value_text(). Use this + * method to set special punctuation for the confirmation display. It is + * fed through sprintf + * + * Examples: + * <code> + * $date_element->set_text_format("%s %s"); + * $date_element->set_text_format("%02d-%02d"); + * </code> + * + * @param string + * @access public + * @link http://www.php.net/manual/en/function.sprintf.php + * + */ + function set_text_format($format){ + + $this->_text_format = $format; + } + + /** + * This method returns the hidden version of this element for a confirmation page. + * + * NOTE: This is called by the FormProcessor only. + * It shouldn't be called manually. + * + * @return container + * @access public + */ + function get_confirm_element(){ + $element_name = $this->get_element_name(); + + $c = container(); + $c->add(form_hidden($this->_month->get_element_name(), $this->_month->get_value())); + $c->add(form_hidden($this->_day->get_element_name(), $this->_day->get_value())); + return $c; + } + + + /** + * Sets the disabled element flag + * + * @param bool disabled + */ + function set_disabled($flag) { + $this->_is_disabled = $flag; + $this->_month->set_disabled($flag); + $this->_day->set_disabled($flag); + } + +} + + + + /** * this class is used for building a listbox for * displaying Hours. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpw...@us...> - 2008-08-02 01:19:21
|
Revision: 3128 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3128&view=rev Author: mpwalsh8 Date: 2008-08-02 01:19:30 +0000 (Sat, 02 Aug 2008) Log Message: ----------- Added FEComboListVertical widget to build a ComboListBox with a vertical arrangement. Modified Paths: -------------- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc Modified: branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc =================================================================== --- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2008-08-02 01:15:40 UTC (rev 3127) +++ branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2008-08-02 01:19:30 UTC (rev 3128) @@ -1085,6 +1085,133 @@ } /** + * This builds a complex dual select box + * with buttons to move entries from one + * select box to another. The boxes are + * stacked vertically instead of horizontally. + * + * From + * ------------------------ + * |----------------------| + * |----------------------| + * |----------------------| + * |----------------------| Add >> + * |----------------------| Add All + * |----------------------| + * |----------------------| + * |----------------------| + * ------------------------ + * To + * ------------------------ + * |----------------------| + * |----------------------| + * |----------------------| + * |----------------------| << Remove + * |----------------------| Remove All + * |----------------------| + * |----------------------| + * |----------------------| + * ------------------------ + * + * @author Mike Walsh <mik...@mi...> + * @see FEComboListBox + */ +class FEComboListBoxVertical extends FEComboListBox +{ + /** + * This function builds and returns the + * form element object + * + * @return object + */ + function get_element() { + $table = html_table(); + + $from_select = form_select($this->_element_name.'_available', + $this->_data_list,'', TRUE); + + if ($this->onChangeJS != null) { + $from_select->set_tag_attribute("onChange", $this->onChangeJS); + } + + $from_select->set_tag_attribute('id', $this->build_id_name().'_from'); + + $style = ''; + if ($this->_height) { + $style .= "height: ".$this->_height.";"; + } + if ($this->_width) { + $style .= "width: ".$this->_width.";"; + } + + //build the buttons + $button_style = 'width: 90px;'; + $f_name = $this->_element_name."_move_around"; + $add = form_button($this->_element_name.'_add', 'Add >>', array('style' => $button_style, + 'onclick' => $f_name."('right',false);")); + $add_all = form_button($this->_element_name.'_add_all', 'Add All', array('style' => $button_style, + "onclick" => $f_name."('right', true);")); + + $remove = form_button($this->_element_name.'_remove', '<< Remove', array('style' => $button_style, + 'onclick' => $f_name."('left', false);")); + $remove_all = form_button($this->_element_name.'_remove_all', 'Remove All', array('style' => $button_style, + 'onclick' => $f_name."('left', true);")); + + $to_select = form_select($this->_element_name.'[]', + $this->_data_list_to, '', TRUE); + + if (strlen($style) > 0) { + $from_select->set_style($style); + $to_select->set_style($style); + } + + //check to see if we are disabled + if ($this->is_disabled()) { + $from_select->set_tag_attribute('disabled'); + $add->set_tag_attribute('disabled'); + $add_all->set_tag_attribute('disabled'); + $remove->set_tag_attribute('disabled'); + $remove_all->set_tag_attribute('disabled'); + $to_select->set_tag_attribute('disabled'); + } + + $to_select->set_tag_attribute('id', $this->build_id_name().'_to'); + + + $button_td = new TDtag(array('align' => 'left'), + $add, html_br(), $add_all, html_br(2), + $remove, html_br(), $remove_all); + + $f_name = $this->_element_name."_order"; + + $move_up = form_button('Move Up', 'Move Up', array('onclick' => "javascript: ".$f_name."(0)")); + $move_down = form_button('Move Down', 'Move Down', array('onclick' => "javascript: ".$f_name."(1)")); + + //IE sucks. + + $add_button_td = new TDtag(array('align' => 'left'), + $add, html_br(), $add_all); + $add_button_td->set_collapse(); + + $remove_button_td = new TDtag(array('align' => 'left'), + $remove, html_br(), $remove_all); + $remove_button_td->set_collapse(); + + + $table->add_row($this->_from_label) ; + $table->add_row($from_select, $add_button_td) ; + $table->add_row($this->_to_label) ; + $table->add_row($to_select, $remove_button_td) ; + + if ($this->_ordering) { + $table->add_row(container($move_up, $move_down)); + } + + return $table; + } +} + +/** * This class builds a FEDataList that shows a select box for Months of the year * * You should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpw...@us...> - 2011-02-04 15:19:18
|
Revision: 3545 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3545&view=rev Author: mpwalsh8 Date: 2011-02-04 15:19:12 +0000 (Fri, 04 Feb 2011) Log Message: ----------- Fixed errors found from PHP5.3.x testing. Modified Paths: -------------- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc Modified: branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc =================================================================== --- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2011-01-28 14:52:09 UTC (rev 3544) +++ branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2011-02-04 15:19:12 UTC (rev 3545) @@ -89,7 +89,7 @@ function FEYesNoListBox($label, $required = TRUE, $width = NULL, $height = NULL, $yes_value="yes", $no_value="no") { $options = array("Yes" => $yes_value, "No" => $no_value); - $this->FEListBox($label, $required, $width, $height, $options); + parent::FEListBox($label, $required, $width, $height, $options); } } @@ -458,7 +458,7 @@ * @param array data_list - list of data elements (name=>value) */ function FEUnitedStates($label, $required = TRUE, $width = NULL, $height = NULL) { - $this->FEListBox($label, $required, $width, $height, $this->_states); + parent::FEListBox($label, $required, $width, $height, $this->_states); } } @@ -509,7 +509,7 @@ * @param array data_list - list of data elements (name=>value) */ function FEEuropeanUnion($label, $required = TRUE, $width = NULL, $height = NULL) { - $this->FEListBox($label, $required, $width, $height, $this->_states); + parent::FEListBox($label, $required, $width, $height, $this->_states); } } @@ -1257,7 +1257,7 @@ $months[$i] = strftime($format, strtotime("$i/12/2004")); } - $this->FEListBox($label, $required, $width, $height, array_flip($months)); + parent::FEListBox($label, $required, $width, $height, array_flip($months)); } @@ -1289,7 +1289,7 @@ foreach ($list as $year){ $years[$year] = $year; } - $this->FEListBox($label, $required, $width, $height, $years); + parent::FEListBox($label, $required, $width, $height, $years); } } @@ -1321,7 +1321,7 @@ $new_day = sprintf('%02d', $day); $days[$new_day] = $day; } - $this->FEListBox($label, $required, $width, $height, $days); + parent::FEListBox($label, $required, $width, $height, $days); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpw...@us...> - 2012-08-28 18:47:38
|
Revision: 3564 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3564&view=rev Author: mpwalsh8 Date: 2012-08-28 18:47:32 +0000 (Tue, 28 Aug 2012) Log Message: ----------- Added missing child constructor which broke the constructor chain in early PHP 5.3.x builds. Modified Paths: -------------- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc Modified: branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc =================================================================== --- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2012-03-12 22:23:45 UTC (rev 3563) +++ branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2012-08-28 18:47:32 UTC (rev 3564) @@ -60,6 +60,16 @@ } return $tag; } + + /** + * Constructor - needed for early PHP 5.3.x compatibility + * + * @param Parent Constructor + * @param array of Constructor Arguments + */ + function FEListBox() { + call_user_func_array('parent::FEDataList', func_get_args()) ; + } } /** @@ -1258,8 +1268,6 @@ } parent::FEListBox($label, $required, $width, $height, array_flip($months)); - - } } @@ -2025,7 +2033,7 @@ * * @author Walter A. Boring IV */ -class FEHoursListBox extends FEListbox { +class FEHoursListBox extends FEListBox { /** * Flag to tell us to use 12 or 24 hour format @@ -2060,7 +2068,7 @@ * * @author Walter A. Boring IV */ -class FEMinutesListBox extends FEListbox { +class FEMinutesListBox extends FEListBox { /** * The constructor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mpw...@us...> - 2012-09-03 13:47:49
|
Revision: 3568 http://phphtmllib.svn.sourceforge.net/phphtmllib/?rev=3568&view=rev Author: mpwalsh8 Date: 2012-09-03 13:47:40 +0000 (Mon, 03 Sep 2012) Log Message: ----------- Updated PHP5.3 compatible constructor to play nice with PHP5.2.x. Modified Paths: -------------- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc Modified: branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc =================================================================== --- branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2012-09-03 13:47:13 UTC (rev 3567) +++ branches/BRANCH_2_X/phphtmllib/form/form_elements/FEListBox.inc 2012-09-03 13:47:40 UTC (rev 3568) @@ -68,7 +68,8 @@ * @param array of Constructor Arguments */ function FEListBox() { - call_user_func_array('parent::FEDataList', func_get_args()) ; + $args = func_get_args() ; + call_user_func_array(array('FEDataList', 'FEDataList'), $args) ; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |