/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FEListBox.inc
ViewVC logotype

Diff of /nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FEListBox.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by jonen, Thu May 6 16:27:27 2004 UTC revision 1.4 by jonen, Thu Aug 11 14:09:59 2005 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /**  /**
3   * This file contains the FEListBox, FEMultiListBox   * This file contains the FEListBox, FEMultiListBox
4   *   *
5   * $Id$   * $Id$
6   *   *
7   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
8   * @author Suren Markosyan <suren@bcsweb.com>   * @author Suren Markosyan <suren@bcsweb.com>
9   * @package phpHtmlLib   * @package phpHtmlLib
10   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 14  Line 14 
14   */   */
15    
16  /**  /**
17   * This is the ListBox FormElement which builds a   * This is the ListBox FormElement which builds a
18   * select field with all of its options.   * select field with all of its options.
19   * It has no validation method.   * It has no validation method.
  *  
20   *   *
21   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   *
22     * @author Walter A. Boring IV <waboring@newsblob.com>
23   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
24   * @package phpHtmlLib   * @package phpHtmlLib
25   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 50  class FEListBox extends FEDataList { Line 50  class FEListBox extends FEDataList {
50    
51              $attributes = array("value"=>$value);              $attributes = array("value"=>$value);
52              if ($value == $selected_value) {              if ($value == $selected_value) {
53                  $attributes[] = "selected";                  $attributes['selected'] = "selected";
54              }              }
55              if (isset($this->_disabled_items[$name])) {              if (isset($this->_disabled_items[$name])) {
56                  $attributes[] = "disabled";                  $attributes['disabled'] = "disabled";
57              }              }
58    
59              $tag->add(new OPTIONtag($attributes, $name));              $tag->add(new OPTIONtag($attributes, htmlspecialchars($name)));
60          }          }
61          return $tag;          return $tag;
62      }      }
# Line 65  class FEListBox extends FEDataList { Line 65  class FEListBox extends FEDataList {
65  /**  /**
66   * Build a Yes/No Select box   * Build a Yes/No Select box
67   *   *
68   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
69   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
70   * @package phpHtmlLib   * @package phpHtmlLib
71   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 76  class FEYesNoListBox extends FEListBox { Line 76  class FEYesNoListBox extends FEListBox {
76    
77      /**      /**
78       * The Constructor       * The Constructor
79       *       *
80       * @param label string - text label for the element       * @param label string - text label for the element
81       * @param bool required - is this a required element       * @param bool required - is this a required element
82       * @param array data_list - list of data elements (name=>value)       * @param array data_list - list of data elements (name=>value)
# Line 97  class FEYesNoListBox extends FEListBox { Line 97  class FEYesNoListBox extends FEListBox {
97  /**  /**
98   * This class builds a nested select box that   * This class builds a nested select box that
99   * is used to select an entry from nested levels.   * is used to select an entry from nested levels.
100   *   *
101   * NOTE: The data array must be in the format                           * NOTE: The data array must be in the format
102   *       array("test" => "testvalue",   *       array("test" => "testvalue",
103   *             "nestedtest" => array("value" => "nestedtestvalue",   *             "nestedtest" => array("value" => "nestedtestvalue",
104   *                                   "items" => array( "foo" => "foovalue",   *                                   "items" => array( "foo" => "foovalue",
105   *                                                     "bar" => "barvalue"));   *                                                     "bar" => "barvalue"));
106   *   *
107   * Example   * Example
108   * $data = array("Test" => 1,   * $data = array("Test" => 1,
109   *               "Foo" => array("value" => 2,   *               "Foo" => array("value" => 2,
# Line 113  class FEYesNoListBox extends FEListBox { Line 113  class FEYesNoListBox extends FEListBox {
113   *                              "items" => array("testing" => array("value" => 6,   *                              "items" => array("testing" => array("value" => 6,
114   *                                                                  "items" => array("ugh" => 7)),   *                                                                  "items" => array("ugh" => 7)),
115   *                                               "again" => 8)));   *                                               "again" => 8)));
116   *   *
117   * would result in   * would result in
118   *   *
119   * <select >   * <select >
120   *  <option value="1">Test</option>   *  <option value="1">Test</option>
121   *  <option value="2">Foo</option>   *  <option value="2">Foo</option>
# Line 126  class FEYesNoListBox extends FEListBox { Line 126  class FEYesNoListBox extends FEListBox {
126   *  <option value="7">&nbsp;&nbsp;&nbsp;&nbsp;ugh</option>   *  <option value="7">&nbsp;&nbsp;&nbsp;&nbsp;ugh</option>
127   *  <option value="8">&nbsp;&nbsp;again</option>   *  <option value="8">&nbsp;&nbsp;again</option>
128   * </select>   * </select>
129   *                                     *
130   *     *
131   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
132   * @package phpHtmlLib   * @package phpHtmlLib
133   * @subpackage FormProcessing   * @subpackage FormProcessing
134   *   *
# Line 148  class FENestedListBox extends FEDataList Line 148  class FENestedListBox extends FEDataList
148    
149          if ($this->_height) {          if ($this->_height) {
150              $attributes["size"] = 5;              $attributes["size"] = 5;
151          }                  }
152    
153          $tag = new SELECTtag($attributes);          $tag = new SELECTtag($attributes);
154    
# Line 175  class FENestedListBox extends FEDataList Line 175  class FENestedListBox extends FEDataList
175          }          }
176          return TRUE;          return TRUE;
177      }      }
178        
179        
180      function _array_search_r($needle, $haystack, &$item){      function _array_search_r($needle, $haystack, &$item) {
181          //xxx($needle);          //xxx($needle);
182          $match = FALSE;          $match = FALSE;
183    
184          foreach($haystack as $name=>$value){          foreach($haystack as $name=>$value) {
185              if (is_array($value)) {              if (is_array($value)) {
186                  if ($value["value"] == $needle) {                  if ($value["value"] == $needle) {
187                      $item = $name;                      $item = $name;
# Line 189  class FENestedListBox extends FEDataList Line 189  class FENestedListBox extends FEDataList
189                  } else {                  } else {
190                      $match = $this->_array_search_r($needle, $value["items"], $item);                      $match = $this->_array_search_r($needle, $value["items"], $item);
191                      $item = $name."::".$item;                      $item = $name."::".$item;
192                  }                                  }
193              } else if ($value==$needle) {              } else if ($value==$needle) {
194                  $item = $name;                  $item = $name;
195                  $match = TRUE;                  $match = TRUE;
196              }              }
197    
198              if ($match)              if ($match)
199                  return TRUE;                  return TRUE;
200          }          }
201          return $match;          return $match;
# Line 205  class FENestedListBox extends FEDataList Line 205  class FENestedListBox extends FEDataList
205      /**      /**
206       * This provides a method       * This provides a method
207       * for the FormContent       * for the FormContent
208       * to get access to the       * to get access to the
209       * text associated with a       * text associated with a
210       * field.  This is only available       * field.  This is only available
211       * on FormElements that have text       * on FormElements that have text
# Line 215  class FENestedListBox extends FEDataList Line 215  class FENestedListBox extends FEDataList
215       * @return string - the text associated       * @return string - the text associated
216       */       */
217      function get_value_text() {      function get_value_text() {
218          $ret = $this->_array_search_r($this->get_value(),          $ret = $this->_array_search_r($this->get_value(),
219                                        $this->_data_list, $item);                                        $this->_data_list, $item);
220          return $item;          return $item;
221      }      }
222    
223    
224      /**      /**
225       * This is a recursive function used to add       * This is a recursive function used to add
226       * an array of layers to the select box.       * an array of layers to the select box.
227       *       *
228       * @param array - the next level of name=>value pairs       * @param array - the next level of name=>value pairs
229       * @param int - the level       * @param int - the level
230       * @param SELECTtag - the SELECTtag object to add the options       * @param SELECTtag - the SELECTtag object to add the options
# Line 239  class FENestedListBox extends FEDataList Line 239  class FENestedListBox extends FEDataList
239              if (is_array($value)) {              if (is_array($value)) {
240                  $tag->add( $this->_build_option($name, $value["value"], $level));                  $tag->add( $this->_build_option($name, $value["value"], $level));
241                  $this->_add_array($value["items"], $level+1, $tag);                  $this->_add_array($value["items"], $level+1, $tag);
242              } else {                              } else {
243                    
244                  $tag->add($this->_build_option($name, $value, $level));                  $tag->add($this->_build_option($name, $value, $level));
245              }              }
246          }          }
# Line 248  class FENestedListBox extends FEDataList Line 248  class FENestedListBox extends FEDataList
248    
249      /**      /**
250       * This method builds the actual OPTIONtag object       * This method builds the actual OPTIONtag object
251       *       *
252       * @param string the name       * @param string the name
253       * @param string the value       * @param string the value
254       * @param int the level       * @param int the level
# Line 256  class FENestedListBox extends FEDataList Line 256  class FENestedListBox extends FEDataList
256       */       */
257      function _build_option($name, $value, $level) {      function _build_option($name, $value, $level) {
258          $selected_value = $this->get_value();          $selected_value = $this->get_value();
259            
260          $attributes = array("value"=>$value);          $attributes = array("value"=>$value);
261          if ($value == $selected_value) {          if ($value == $selected_value) {
262              $attributes[] = "selected";              $attributes['selected'] = "selected";
263          }          }
264            
265          if (isset($this->_disabled_items[$name])) {          if (isset($this->_disabled_items[$name])) {
266              $attributes[] = "disabled";              $attributes['disabled'] = "disabled";
267          }          }
268            
269          return new OPTIONtag($attributes, $this->_layer_name($name, $level));          return new OPTIONtag($attributes, $this->_layer_name($name, $level));
270      }      }
271    
272      /**      /**
273       * This builds a layer's name       * This builds a layer's name
274       *       *
275       * @param string - original name       * @param string - original name
276       * @param int the layer level       * @param int the layer level
277       * @return string the new name       * @return string the new name
# Line 284  class FENestedListBox extends FEDataList Line 284  class FENestedListBox extends FEDataList
284          } else {          } else {
285              $newname .= str_repeat(_HTML_SPACE, $level*2).$name;              $newname .= str_repeat(_HTML_SPACE, $level*2).$name;
286          }          }
287            
288          return $newname;          return $newname;
289      }      }
290  }  }
291    
292    
293  /**  /**
294   * This is the MultiListBox FormElement which builds a   * This is the MultiListBox FormElement which builds a
295   * select field with all of its options.  It enables   * select field with all of its options.  It enables
296   * the ability to have multiple selections.   * the ability to have multiple selections.
297   * It has no validation method.   * It has no validation method.
  *  
298   *   *
299   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   *
300     * @author Walter A. Boring IV <waboring@newsblob.com>
301   * @author Suren Markossian <suren@bcsweb.com>   * @author Suren Markossian <suren@bcsweb.com>
302   * @package phpHtmlLib   * @package phpHtmlLib
303   * @subpackage FormProcessing   * @subpackage FormProcessing
# Line 324  class FEMultiListBox extends FEListBox { Line 324  class FEMultiListBox extends FEListBox {
324    
325      /**      /**
326       * build the string for the confirmation page       * build the string for the confirmation page
327       *       *
328       * @return string       * @return string
329       */       */
330      function get_value_text() {      function get_value_text() {
# Line 350  class FEMultiListBox extends FEListBox { Line 350  class FEMultiListBox extends FEListBox {
350    
351          $attributes = $this->_build_element_attributes();          $attributes = $this->_build_element_attributes();
352    
353          $attributes[] = "multiple";          $attributes['multiple'] = "multiple";
354    
355          if ($this->_height) {          if ($this->_height) {
356              $attributes["size"] = 5;              $attributes["size"] = 5;
# Line 364  class FEMultiListBox extends FEListBox { Line 364  class FEMultiListBox extends FEListBox {
364    
365              $attributes = array("value"=>$value);              $attributes = array("value"=>$value);
366              if (is_array($selected_values) && in_array($value, $selected_values)) {              if (is_array($selected_values) && in_array($value, $selected_values)) {
367                  $attributes[] = "selected";                  $attributes['selected'] = "selected";
368              }              }
369              if (isset($this->_disabled_items[$name])) {              if (isset($this->_disabled_items[$name])) {
370                  $attributes[] = "disabled";                  $attributes['disabled'] = "disabled";
371              }              }
372    
373              $tag->add(new OPTIONtag($attributes, $name));              $tag->add(new OPTIONtag($attributes, $name));
# Line 379  class FEMultiListBox extends FEListBox { Line 379  class FEMultiListBox extends FEListBox {
379  /**  /**
380   * This class builds a FEDataList that shows   * This class builds a FEDataList that shows
381   * a select box for States of the U.S.A.   * a select box for States of the U.S.A.
382   *   *
383   * @author Walter A. Boring IV   * @author Walter A. Boring IV
384   */   */
385  class FEUnitedStates extends FEListBox {  class FEUnitedStates extends FEListBox {
# Line 446  class FEUnitedStates extends FEListBox { Line 446  class FEUnitedStates extends FEListBox {
446                           "Guam" => "GU",                           "Guam" => "GU",
447                           "American Samoa" => "AS",                           "American Samoa" => "AS",
448                           "Palau" => "PW",                           "Palau" => "PW",
449                           );                          );
450    
451      /**      /**
452       * The constructor       * The constructor
453       *       *
454       * @param string text label for the element       * @param string text label for the element
455       * @param boolean is this a required element?       * @param boolean is this a required element?
456       * @param int element width in characters, pixels (px), percentage (%) or elements (em)       * @param int element width in characters, pixels (px), percentage (%) or elements (em)
# Line 462  class FEUnitedStates extends FEListBox { Line 462  class FEUnitedStates extends FEListBox {
462      }      }
463  }  }
464    
465    /**
466     * This class builds a FEDataList that shows
467     * a select box for states of the European Union.
468     */
469    class FEEuropeanUnion extends FEListBox {
470        /**
471         * The states array
472         * @var array
473         */
474        var $_states = array("Select State" => "",
475                             "Belgium" => "be",
476                             "Denmark" => "dk",
477                             "Germany" => "de",
478                             "Greece" => "gr",
479                             "Spain" => "es",
480                             "France" => "fr",
481                             "Ireland" => "ie",
482                             "Italy" => "it",
483                             "Luxembourg" => "lu",
484                             "The Netherlands" => "nl",
485                             "Austria" => "at",
486                             "Portugal" => "pt",
487                             "Finland" => "fi",
488                             "Sweden" => "se",
489                             "United Kingdom" => "uk",
490                             "Czech Republic" => "cz",
491                             "Estonia" => "ee",
492                             "Cyprus" => "cy",
493                             "Latvia" => "lv",
494                             "Lithuania" => "lt",
495                             "Hungary" => "hu",
496                             "Malta" => "mt",
497                             "Poland" => "pl",
498                             "Slovenia" => "si",
499                             "Slovakia" => "sk",
500                            );
501    
502        /**
503         * The constructor
504         *
505         * @param string text label for the element
506         * @param boolean is this a required element?
507         * @param int element width in characters, pixels (px), percentage (%) or elements (em)
508         * @param int element height in px
509         * @param array data_list - list of data elements (name=>value)
510         */
511        function FEEuropeanUnion($label, $required = TRUE, $width = NULL, $height = NULL) {
512            $this->FEListBox($label, $required, $width, $height, $this->_states);
513        }
514    }
515    
516    
517  /**  /**
518   * This builds a complex dual select box   * This builds a complex dual select box
519   * with buttons to move entries from one   * with buttons to move entries from one
520   * select box to another.   * select box to another.
521   *   *
522   * From      Actions    To   * From      Actions    To
523   * --------  Add >>     --------   * --------  Add >>     --------
524   * |------|  Add All    |------|   * |------|  Add All    |------|
# Line 477  class FEUnitedStates extends FEListBox { Line 528  class FEUnitedStates extends FEListBox {
528   * |------|  Remove All |------|   * |------|  Remove All |------|
529   * |------|             |------|   * |------|             |------|
530   * --------             --------   * --------             --------
531   *   *
532   * @author Walter A. Boring IV   * @author Walter A. Boring IV
533   */   */
534  class FEComboListBox extends FEDataList {  class FEComboListBox extends FEDataList {
# Line 485  class FEComboListBox extends FEDataList Line 536  class FEComboListBox extends FEDataList
536    
537      /**      /**
538       * Holds the list of available       * Holds the list of available
539       * data elements for the 'to'       * data elements for the 'to'
540       * box.       * box.
541       *       *
542       */       */
# Line 493  class FEComboListBox extends FEDataList Line 544  class FEComboListBox extends FEDataList
544    
545      /**      /**
546       * The from field's label       * The from field's label
547       *       *
548       * @var string       * @var string
549       */       */
550      var $_from_label = 'Available';      var $_from_label = 'Available';
551    
552      /**      /**
553       * The to field's label       * The to field's label
554       *       *
555       * @var string       * @var string
556       */       */
557      var $_to_label = 'Selected';      var $_to_label = 'Selected';
558    
559      /**      /**
560       * This Form Element needs to       * This Form Element needs to
561       * propogate some js to the       * propogate some js to the
562       * Form tag's onsubmit attribute       * Form tag's onsubmit attribute
563       *       *
564       * @var string       * @var string
565       */       */
566      var $_has_form_on_submit = true;      var $_has_form_on_submit = true;
# Line 517  class FEComboListBox extends FEDataList Line 568  class FEComboListBox extends FEDataList
568    
569      /**      /**
570       * The constructor       * The constructor
571       *       *
572       * @param string text label for the element       * @param string text label for the element
573       * @param boolean is this a required element?       * @param boolean is this a required element?
574       * @param int element width in characters, pixels (px), percentage (%) or elements (em)       * @param int element width in characters, pixels (px), percentage (%) or elements (em)
# Line 525  class FEComboListBox extends FEDataList Line 576  class FEComboListBox extends FEDataList
576       * @param array list of 'from' field data elements (name=>value)       * @param array list of 'from' field data elements (name=>value)
577       * @param array list of 'to' field data elements (name=>value)       * @param array list of 'to' field data elements (name=>value)
578       */       */
579      function FEComboListBox($label, $required = TRUE, $width="200px", $height="100px",      function FEComboListBox($label, $required = TRUE, $width="200px", $height="100px",
580                              $from_data_list = array(), $to_data_list = array()) {                              $from_data_list = array(), $to_data_list = array()) {
581          $this->set_to_list_data($to_data_list);          $this->set_to_list_data($to_data_list);
582          $this->FEDataList($label, $required, $width, $height, $from_data_list);                  $this->FEDataList($label, $required, $width, $height, $from_data_list);
583      }      }
584    
585      /**      /**
# Line 544  class FEComboListBox extends FEDataList Line 595  class FEComboListBox extends FEDataList
595      /**      /**
596       * Use this method to set the label for the       * Use this method to set the label for the
597       * 'from' field       * 'from' field
598       *       *
599       * @param string       * @param string
600       * @return none       * @return none
601       */       */
# Line 555  class FEComboListBox extends FEDataList Line 606  class FEComboListBox extends FEDataList
606      /**      /**
607       * Use this method to set the label for the       * Use this method to set the label for the
608       * 'to' field       * 'to' field
609       *       *
610       * @param string       * @param string
611       * @return none       * @return none
612       */       */
# Line 565  class FEComboListBox extends FEDataList Line 616  class FEComboListBox extends FEDataList
616    
617    
618      /**      /**
619         * This returns the initial value of
620         * the element
621         *
622         * @return mixed
623         */
624        function get_init_value() {
625            if ($this->_data_list_to) {
626                return $this->_data_list_to;
627            } else {
628                return parent::get_init_value();
629            }
630        }
631    
632    
633        /**
634       * This function will set the       * This function will set the
635       * initial value for the element       * initial value for the element
636       *       *
# Line 572  class FEComboListBox extends FEDataList Line 638  class FEComboListBox extends FEDataList
638       */       */
639      function set_value($value) {      function set_value($value) {
640          //we need to see if we need to modify the          //we need to see if we need to modify the
641          //the 2 data sets so the values of each are          //the 2 data sets so the values of each are
642          //correctly displayed.          //correctly displayed.
643            
644          if (isset($_REQUEST[FORM_VISITED])) {  
645            if (array_key_exists($this->_element_name, $_REQUEST)) {
646              $all_list = array_merge( $this->_data_list, $this->_data_list_to);              $all_list = array_merge( $this->_data_list, $this->_data_list_to);
647    
648              if (isset($_REQUEST[$this->_element_name])) {              if (isset($_REQUEST[$this->_element_name])) {
649                  $diff = array_diff( $all_list, $_REQUEST[$this->_element_name]);                  $diff = array_diff( $all_list, $_REQUEST[$this->_element_name]);
650                  $this->set_list_data( $diff );                  $this->set_list_data( $diff );
651                  $to_list = array();                  $to_list = array();
652                    
653                  if (is_array($_REQUEST[$this->_element_name])) {                  if (is_array($_REQUEST[$this->_element_name])) {
654                      foreach( $_REQUEST[$this->_element_name] as $value ) {                      foreach( $_REQUEST[$this->_element_name] as $value ) {
655                          $key = array_search($value, $all_list);                          $key = array_search($value, $all_list);
656                          if ($key) {                          if ($key) {
657                              $to_list[$key] = $value;                              $to_list[$key] = $value;
658                          }                                                  }
659                      }                      }
660                  } else {                  } else {
661                      if (!empty($_REQUEST[$this->_element_name])) {                      if (!empty($_REQUEST[$this->_element_name])) {
662                          $to_list[array_search($_REQUEST[$this->_element_name], $all_list)] = $_REQUEST[$this->_element_name];                          $to_list[array_search($_REQUEST[$this->_element_name], $all_list)] = $_REQUEST[$this->_element_name];
663                      }                                        }
664                  }                  }
665                  $this->set_to_list_data( $to_list );                  $this->set_to_list_data( $to_list );
666              } else {              } else {
# Line 601  class FEComboListBox extends FEDataList Line 668  class FEComboListBox extends FEDataList
668                  $this->set_list_data( $all_list );                  $this->set_list_data( $all_list );
669                  $this->set_to_list_data(array());                  $this->set_to_list_data(array());
670              }              }
671          } else {                      } else {
672              $this->_value = $value;              $this->set_to_list_data($value);
673          }                  }
674    
675      }      }
676    
677    
# Line 616  class FEComboListBox extends FEDataList Line 684  class FEComboListBox extends FEDataList
684       */       */
685      function get_element() {      function get_element() {
686          $table = html_table();          $table = html_table();
687          $table->add_row($this->_from_label, _HTML_SPACE,          $table->add_row($this->_from_label, _HTML_SPACE,
688                          $this->_to_label);                          $this->get_label(NULL,$this->_to_label, FALSE));
689    
690          $from_select = form_select($this->_element_name.'_available',          $from_select = form_select($this->_element_name.'_available',
691                                     $this->_data_list,'', TRUE);                                     $this->_data_list,'', TRUE);
692    
693            if ($this->onChangeJS != null) {
694                $from_select->set_tag_attribute("onChange", $this->onChangeJS);
695            }
696    
697          $style = '';          $style = '';
698          if ($this->_height) {          if ($this->_height) {
699              $style .= "height: ".$this->_height.";";              $style .= "height: ".$this->_height.";";
700          }          }
701          if ($this->_width) {          if ($this->_width) {
702              $style .= "width: ".$this->_width.";";              $style .= "width: ".$this->_width.";";
703          }                  }
704    
705          //build the buttons          //build the buttons
706          $button_style = 'width: 90px;';          $button_style = 'width: 90px;';
# Line 650  class FEComboListBox extends FEDataList Line 723  class FEComboListBox extends FEDataList
723              $to_select->set_style($style);              $to_select->set_style($style);
724          }          }
725    
726          $table->add_row( $from_select,          //check to see if we are disabled
727                           new TDtag(array('align' => 'left'),          if ($this->is_disabled()) {
728                $from_select->set_tag_attribute('disabled');
729                $add->set_tag_attribute('disabled');
730                $add_all->set_tag_attribute('disabled');
731                $remove->set_tag_attribute('disabled');
732                $remove_all->set_tag_attribute('disabled');
733                $to_select->set_tag_attribute('disabled');
734            }
735    
736    
737            $button_td = new TDtag(array('align' => 'left'),
738                                     $add, html_br(), $add_all, html_br(2),                                     $add, html_br(), $add_all, html_br(2),
739                                     $remove, html_br(), $remove_all),                                     $remove, html_br(), $remove_all);
740            //IE sucks.
741            $button_td->set_collapse();
742            $table->add_row( $from_select,
743                             $button_td,
744                           $to_select );                           $to_select );
745    
746          return $table;          return $table;
# Line 664  class FEComboListBox extends FEDataList Line 751  class FEComboListBox extends FEDataList
751       * This function is responsible for performing complete       * This function is responsible for performing complete
752       * validation and setting the appropriate error message       * validation and setting the appropriate error message
753       * in case of a failed validation       * in case of a failed validation
754       *       *
755       * NOTE: This makes sure that the data submitted for both       * NOTE: This makes sure that the data submitted for both
756       *       fields is in the original list.       *       fields is in the original list.
757       *       *
# Line 701  class FEComboListBox extends FEDataList Line 788  class FEComboListBox extends FEDataList
788      /**      /**
789       * This provides a method       * This provides a method
790       * for the FormContent       * for the FormContent
791       * to get access to the       * to get access to the
792       * text associated with a       * text associated with a
793       * field.  This is only available       * field.  This is only available
794       * on FormElements that have text       * on FormElements that have text
# Line 718  class FEComboListBox extends FEDataList Line 805  class FEComboListBox extends FEDataList
805      /**      /**
806       * This is a method for getting the JS needed       * This is a method for getting the JS needed
807       * for the form tag's onsubmit attribute.       * for the form tag's onsubmit attribute.
808       *       *
809       * @return string       * @return string
810       */       */
811      function form_tag_onsubmit() {      function form_tag_onsubmit() {
# Line 727  class FEComboListBox extends FEDataList Line 814  class FEComboListBox extends FEDataList
814    
815    
816      /**      /**
817       * This method builds the Javascript needed for this       * This method builds the Javascript needed for this
818       * element.       * element.
819       *       *
820       * @return string The javascript.       * @return string The javascript.
821       */       */
822      function javascript() {      function javascript() {
823    
824          $js =  "function ".$this->_element_name."_move_around(direction, all) {          $js =  "function ".$this->_element_name."_move_around(direction, all) {\n".
825              if (direction==\"right\") {                 "  if (direction==\"right\") {\n".
826                  box1 = \"".$this->_element_name."_available\";                 "    box1 = \"".$this->_element_name."_available\";\n".
827                  box2 = \"".$this->_element_name."[]\";                 "    box2 = \"".$this->_element_name."[]\";\n".
828              } else {                 "  } else {\n".
829                  box1 = \"".$this->_element_name."[]\";                 "    box1 = \"".$this->_element_name."[]\";\n".
830                  box2 = \"".$this->_element_name."_available\" + \"\";                 "    box2 = \"".$this->_element_name."_available\" + \"\";\n".
831              }                                                             "  }\n".
832                
833              for (var i=0;i<document.forms[0].elements[box1].length;i++) {                 "  for (var i=0;i<document.forms[0].elements[box1].length;i++) {\n".
834                  if (document.forms[0].elements[box1][i].selected || all) {                 "    if (document.forms[0].elements[box1][i].selected || all) {\n".
835                  // add to the other list box                 "      // add to the other list box\n".
836                  document.forms[0].elements[box2].options[document.forms[0].elements[box2].length] =                 "      document.forms[0].elements[box2].options[document.forms[0].elements[box2].length] =".
837                  new Option(document.forms[0].elements[box1].options[i].text, document.forms[0].elements[box1][i].value);                 "    new Option(document.forms[0].elements[box1].options[i].text, document.forms[0].elements[box1][i].value);\n".
838                  // remove from the current listbox                 "      // remove from the current listbox\n".
839                  document.forms[0].elements[box1][i] = null;                 "      document.forms[0].elements[box1][i] = null;\n".
840                  i--;                 "      i--;\n".
841                  }                 "    }\n".
842              }                 "   }\n".
843          }";                 "}\n";
844                
845                
846          $js .= "\nfunction ".$this->_element_name."_check_submit() {                      $js .= "\nfunction ".$this->_element_name."_check_submit() {\n".
847              // select all items in the added ip list                 "  // select all items in the added ip list\n".
848              // in order to include in the post data                 "  // in order to include in the post data\n".
849              box = \"".$this->_element_name."[]\";                 "  box = \"".$this->_element_name."[]\";\n".
850              if (document.forms[0].elements[box]) {                 "  if (document.forms[0].elements[box]) {\n".
851                  for (var i=0;i<document.forms[0].elements[box].length;i++) {                 "    for (var i=0;i<document.forms[0].elements[box].length;i++) {\n".
852                      document.forms[0].elements[box][i].selected = true;                 "      document.forms[0].elements[box][i].selected = true;\n".
853                  }                 "    }\n".
854              }                 "  }\n".
855                
856              // disable the buttons                 "  // disable the buttons\n".
857              //document.forms[0]._form_action1.disabled = true;                 "  //document.forms[0]._form_action1.disabled = true;\n".
858              //if (document.forms[0]._form_action2)                 "  //if (document.forms[0]._form_action2)\n".
859              //    document.forms[0]._form_action2.disabled = true;                 "  //    document.forms[0]._form_action2.disabled = true;\n".
860              //document.forms[0].cancel.disabled = true;                 "  //document.forms[0].cancel.disabled = true;\n".
861              return true;                 "  return true;\n".
862          }";                 "}\n";
863    
864          return trim($js);          return trim($js);
865      }      }
# Line 783  class FEComboListBox extends FEDataList Line 870  class FEComboListBox extends FEDataList
870       *       *
871       * @return mixed       * @return mixed
872       */       */
873      function get_value() {      function get_value(){
874          return $this->_data_list_to;          return $this->_data_list_to;
875      }      }
876    
877    
878      /**      /**
879       * This method returns the hidden version of this       * This method returns the hidden version of this
880       * element for a confirmation page.         * element for a confirmation page.
881       *       *
882       * NOTE: This is called by the FormProcessor only.         * NOTE: This is called by the FormProcessor only.
883       * It shouldn't be called manually.       * It shouldn't be called manually.
884       *       *
885       * @return INPUTtag of type hidden       * @return INPUTtag of type hidden
886       */       */
887      function get_confirm_element() {      function get_confirm_element(){
888          $name = $this->get_element_name();          $name = $this->get_element_name();
889    
890          $c = container();          $c = container();
891          if (is_array( $_REQUEST[$name]) ) {          if (is_array( $_REQUEST[$name]) ) {
892              foreach( $_REQUEST[$name] as $value ) {              foreach( $_REQUEST[$name] as $value ){
893                  $c->add(form_hidden( $name."[]", $value));                  $c->add(form_hidden( $name."[]", $value));
894              }                          }
895          } else {          } else {
896              $c->add(form_hidden($name."[]", $_REQUEST[$name] ));              $c->add(form_hidden($name."[]", $_REQUEST[$name] ));
897          }          }
# Line 814  class FEComboListBox extends FEDataList Line 901  class FEComboListBox extends FEDataList
901  }  }
902    
903  /**  /**
904   * This class builds a FEDataList that shows   * This class builds the FEComboList with buttons below each element
905   * a select box for Months of the year   *
906   *   * @author Sumedh Thakar
907     */
908    class FEComboListButtonsBox extends FEComboListBox {
909    
910        /**
911         * This variable holds the button array
912         */
913        var $_button_info = array();
914        /**
915         * this function sets the array of buttons and related info
916         * array is of format
917         * array('left' => array(
918         *                       array(
919         *                        'name'=> 'expand',
920         *                        'value' => 'Expand it",
921         *                        'onclick'=> 'some_function()',
922         *                        'js' => 'function some_function(){ alert('hi'); }'     *                        ),
923         *                  )
924         *       )
925         * @author Sumedh Thakar
926         * @param array of buttons and related info
927         */
928        function set_button_array($button_array){
929            $this->_button_info = $button_array;
930        }
931    
932        function javascript(){
933            $js = parent::javascript();
934            if(count($this->_button_info)){
935                foreach ($this->_button_info as $side){
936                    foreach ($side as $button){
937                        if(isset($button['js'])) $js .= " ".$button['js']." ";
938                    }
939                }
940            }
941            return $js;
942        }
943    
944        function get_element(){
945            $table = parent::get_element();
946            if(empty($this->_button_info)) return $table;
947            if (isset($this->_button_info['left'])){
948                    $lbuttons = new TDtag();
949                    foreach($this->_button_info['left'] as $butt) {
950                    
951                        $attributes = array();
952                        if (strlen($butt['value'])>12) $attributes["style"] = "padding-left:6px;padding-right:6px;";
953                    else $attributes["style"] = "width:100px;";
954                    $attributes["onClick"] = $butt['onclick'];
955    
956                            $lbuttons->add(form_button(
957                                            $butt['name'],
958                                            $butt['value'],
959                                            $attributes),
960                                            _HTML_SPACE);
961                    }
962            }else{
963                    $lbuttons = _HTML_SPACE;
964            }
965            if (isset($this->_button_info['right'])){
966                    $rbuttons = new TDtag();
967                    foreach($this->_button_info['right'] as $butt) {
968                    
969                        $attributes = array();
970                        if (strlen($butt['value'])>12) $attributes["style"] = "padding-left:6px;padding-right:6px;";
971                    else $attributes["style"] = "width:100px;";
972                    $attributes["onClick"] = $butt['onclick'];
973    
974                    $rbuttons->add(form_button(
975                                            $butt['name'],
976                                            $butt['value'],
977                                            $attributes),
978                                            _HTML_SPACE);
979                    }
980            }else{
981                    $rbuttons = _HTML_SPACE;
982            }
983            $table->add_row($lbuttons,
984                                _HTML_SPACE,
985                            $rbuttons
986                            );
987            return $table;
988    
989        }
990    
991    
992    }
993    
994    /**
995     * This class builds a FEDataList that shows a select box for Months of the year
996     *
997     * You should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale}
998     * function to affect the language used for the month list.
999     *
1000   * @author Culley Harrelson <culley@fastmail.fm>   * @author Culley Harrelson <culley@fastmail.fm>
1001     * @see FEDate
1002   *   *
1003   */   */
1004    
# Line 825  class FEMonths extends FEListBox { Line 1006  class FEMonths extends FEListBox {
1006    
1007      /**      /**
1008       * The constructor       * The constructor
1009       *       *
1010       * @param string text label for the element       * @param string text label for the element
1011       * @param boolean is this a required element?       * @param boolean is this a required element?
1012       * @param int element width in characters, pixels (px), percentage (%) or elements (em)       * @param int element width in characters, pixels (px), percentage (%) or elements (em)
1013       * @param int element height in px       * @param int element height in px
1014       * @param string format should be F m or M:  Full month name, digit, abbreviated month name       * @param string format should be F m or M:  Full month name, digit, abbreviated month name
1015         *
1016       */       */
1017      function FEMonths($label, $required = TRUE, $width = NULL, $height = NULL, $format = 'F') {      function FEMonths($label, $required = TRUE, $width = NULL, $height = NULL, $format = 'F'){
1018            
1019          // $format should be M m or F.  Default to F if the user passes in garbage.          // $format should be M m or F.  Default to F if the user passes in garbage.
1020          switch ($format) {          switch ($format) {
1021              case 'M':          case 'M':
1022                  $format = '%b';              $format = '%b';
1023                  break;              break;
1024              case 'm':          case 'm':
1025                  $format = '%m';              $format = '%m';
1026                  break;              break;
1027              default:          default:
1028                  $format = '%B';              $format = '%B';
1029                  break;              break;
1030          }          }
1031    
1032          for ($i = 1; $i < 13; $i++) {          for ($i = 1; $i < 13; $i++) {
# Line 853  class FEMonths extends FEListBox { Line 1035  class FEMonths extends FEListBox {
1035    
1036          $this->FEListBox($label, $required, $width, $height, array_flip($months));          $this->FEListBox($label, $required, $width, $height, array_flip($months));
1037    
1038    
1039      }      }
1040  }  }
1041    
1042  /**  /**
1043   * This class builds a FEDataList that shows   * This class builds a FEDataList that shows a select box listing a range of years
1044   * a select box listing a range of years   *
  *  
1045   * @author Culley Harrelson <culley@fastmail.fm>   * @author Culley Harrelson <culley@fastmail.fm>
1046     * @see FEDate
1047   *   *
1048   */   */
1049    
# Line 868  class FEYears extends FEListBox { Line 1051  class FEYears extends FEListBox {
1051    
1052      /**      /**
1053       * The constructor       * The constructor
1054       *       *
1055       * @param string text label for the element       * @param string text label for the element
1056       * @param boolean is this a required element?       * @param boolean is this a required element?
1057       * @param int element width in characters, pixels (px), percentage (%) or elements (em)       * @param int element width in characters, pixels (px), percentage (%) or elements (em)
# Line 876  class FEYears extends FEListBox { Line 1059  class FEYears extends FEListBox {
1059       * @param int min_year       * @param int min_year
1060       * @param int max_year       * @param int max_year
1061       */       */
1062      function FEYears($label, $required = TRUE, $width = NULL, $height = NULL, $min_year = 2000, $max_year = 2010) {      function FEYears($label, $required = TRUE, $width = NULL, $height = NULL, $min_year = 2000, $max_year = 2010){
1063          // this will be cleaner in php5 with array_combine()          // this will be cleaner in php5 with array_combine()
1064          $list = range($min_year, $max_year);          $list = range($min_year, $max_year);
1065          foreach ($list as $year) {          foreach ($list as $year){
1066              $years[$year] = $year;              $years[$year] = $year;
1067          }          }
1068          $this->FEListBox($label, $required, $width, $height, $years);          $this->FEListBox($label, $required, $width, $height, $years);
# Line 887  class FEYears extends FEListBox { Line 1070  class FEYears extends FEListBox {
1070  }  }
1071    
1072  /**  /**
1073   * This class builds a FEDataList that shows   * This class builds a FEDataList that shows a select box listing the days of the month
1074   * a select box listing the days of the month   *
  *  
1075   * @author Culley Harrelson <culley@fastmail.fm>   * @author Culley Harrelson <culley@fastmail.fm>
1076     * @see FEDate
1077   *   *
1078   */   */
1079    
# Line 898  class FEDays extends FEListBox { Line 1081  class FEDays extends FEListBox {
1081    
1082      /**      /**
1083       * The constructor       * The constructor
1084       *       *
1085       * @param string text label for the element       * @param string text label for the element
1086       * @param boolean is this a required element?       * @param boolean is this a required element?
1087       * @param int element width in characters, pixels (px), percentage (%) or elements (em)       * @param int element width in characters, pixels (px), percentage (%) or elements (em)
1088       * @param int element height in px       * @param int element height in px
1089       */       */
1090    
1091      function FEDays($label, $required = TRUE, $width = NULL, $height = NULL) {      function FEDays($label, $required = TRUE, $width = NULL, $height = NULL){
1092    
1093          // this will be cleaner in php5 with array_combine()          // this will be cleaner in php5 with array_combine()
1094          $list = range(1, 31);          $list = range(1, 31);
1095          foreach ($list as $day) {          foreach ($list as $day){
1096              // pad the single digit days with zeros              // pad the single digit days with zeros
1097              $day = sprintf('%02d', $day);              $new_day = sprintf('%02d', $day);
1098              $days[$day] = $day;              $days[$new_day] = $day;
1099          }          }
1100          $this->FEListBox($label, $required, $width, $height, $days);          $this->FEListBox($label, $required, $width, $height, $days);
1101    
1102    
1103      }      }
1104  }  }
1105    
1106  /**  /**
1107   * This class builds a FEDataList that shows a group of select boxes   * This class builds a widget that shows a group of select boxes (FEYears, FEMonths, FEDays) representing a date.
1108   * (FEYears, FEMonths, FEDays) representing a date.   *
1109     * FEDate will display three drop down lists representing a date.  You can set
1110     * the order in which these elements are displayed and the minimum and maximum
1111     * years displayed.
1112     *
1113     * Like in FEMonths you should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale}
1114     * function to affect the language used for the month list.
1115     *
1116     * Example as it would appear in FormContent::form_init_elements():
1117     * <code>
1118     *      // set the locale to dutch
1119     *      setlocale(LC_TIME, 'nl_NL');
1120     *      $date_element = new FEDate("FEDate label", false, null, null, 'Fdy', 1970, 1975);
1121     * </code>
1122     *
1123     * the $format parameter conforms the the php {@link http://www.php.net/manual/en/function.setlocale.php date} function
1124     * format argument specification (for years, months and days only).
1125   *   *
1126   * @author Culley Harrelson <culley@fastmail.fm>   * @author Culley Harrelson <culley@fastmail.fm>
1127   * @author Suren Markosian <suren@emicron.net>   * @author Suren Markosian <suren@emicron.net>
1128     * @see FEMonths
1129     * @see FEDays
1130     * @see FEYears
1131   *   *
1132   */   */
1133    
# Line 932  class FEDate extends FEBoxElement { Line 1135  class FEDate extends FEBoxElement {
1135    
1136      /**      /**
1137       * The earliest year shown in the year list.       * The earliest year shown in the year list.
1138       * @var int       * @var integer
1139         * @access private
1140       */       */
1141      var $_min_year;      var $_min_year;
1142    
1143      /**      /**
1144       * The latest year shown in the year list.       * The latest year shown in the year list.
1145       * @var string       * @var string
1146         * @access private
1147       */       */
1148      var $_max_year;      var $_max_year;
1149    
# Line 947  class FEDate extends FEBoxElement { Line 1152  class FEDate extends FEBoxElement {
1152       * characters long and contain only one m only one d and only one y.       * characters long and contain only one m only one d and only one y.
1153       *       *
1154       * @var string       * @var string
1155         * @access private
1156       */       */
1157      var $_format = 'mdy';      var $_format = 'mdy';
1158    
# Line 956  class FEDate extends FEBoxElement { Line 1162  class FEDate extends FEBoxElement {
1162       * according to the order set in $_format       * according to the order set in $_format
1163       *       *
1164       * @var string       * @var string
1165         * @access private
1166       */       */
1167      var $_text_format = '%s %s %s';      var $_text_format = '%s %s %s';
1168    
# Line 963  class FEDate extends FEBoxElement { Line 1170  class FEDate extends FEBoxElement {
1170       * The year form element       * The year form element
1171       *       *
1172       * @var FEYears       * @var FEYears
1173         * @access private
1174       */       */
1175      var $_year;      var $_year;
1176    
# Line 970  class FEDate extends FEBoxElement { Line 1178  class FEDate extends FEBoxElement {
1178       * The month form element       * The month form element
1179       *       *
1180       * @var FEMonths       * @var FEMonths
1181         * @access private
1182       */       */
1183      var $_month;      var $_month;
1184    
# Line 977  class FEDate extends FEBoxElement { Line 1186  class FEDate extends FEBoxElement {
1186       * The day form element       * The day form element
1187       *       *
1188       * @var FEDays       * @var FEDays
1189         * @access private
1190       */       */
1191      var $_day;      var $_day;
1192    
# Line 990  class FEDate extends FEBoxElement { Line 1200  class FEDate extends FEBoxElement {
1200       * @param string date format string.  M m F Y y d D are valid. 3 characters max.       * @param string date format string.  M m F Y y d D are valid. 3 characters max.
1201       * @param int min value for year drop down list       * @param int min value for year drop down list
1202       * @param int max value for year drop down list       * @param int max value for year drop down list
1203         * @see FEDate for an example
1204         * @todo we need to blow up somehow if the format string is bogus
1205         * @access public
1206       *       *
1207       */       */
1208    
1209      function FEDate($label, $required = TRUE, $width = NULL, $height = NULL, $format = 'mdy', $min_year = 2000, $max_year = 2010) {      function FEDate($label, $required = TRUE, $width = NULL, $height = NULL,
1210                        $format = 'mdy', $min_year = 2000, $max_year = 2010){
1211    
1212          $this->_set_format($format);          $this->_set_format($format);
1213          $this->_min_year = $min_year;          $this->_min_year = $min_year;
# Line 1006  class FEDate extends FEBoxElement { Line 1220  class FEDate extends FEBoxElement {
1220      }      }
1221    
1222      /**      /**
1223         * We need to override this so we get
1224         * the form name set in the child elements
1225         * so the id attributes are set correctly.
1226         */
1227        function set_form_name($name) {
1228            $this->_form_name = $name;
1229            $this->_year->set_form_name($name);
1230            $this->_month->set_form_name($name);
1231            $this->_day->set_form_name($name);
1232        }
1233    
1234        /**
1235       * This function builds and returns the       * This function builds and returns the
1236       * form element object       * form element object
1237       *       *
1238       * @return object       * @return object
1239         * @access public
1240       */       */
1241      function get_element() {      function get_element(){
1242    
1243          $container = new Container();          $container = new Container();
1244    
1245          // add the elements in the order specified.          // add the elements in the order specified.
1246          $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY);          $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY);
1247          foreach ($chars as $char) {          foreach ($chars as $char){
1248              switch ($char) {              switch ($char) {
1249                  case 'y':              case 'y':
1250                      $container->add($this->_year->get_element());                  $container->add($this->_year->get_element());
1251                      break;                  break;
1252                  case 'm':              case 'm':
1253                  case 'F':              case 'F':
1254                      $container->add($this->_month->get_element());                  $container->add($this->_month->get_element());
1255                      break;                  break;
1256                  case 'd':              case 'd':
1257                      $container->add($this->_day->get_element());                  $container->add($this->_day->get_element());
1258                      break;                  break;
1259              }              }
1260          }          }
1261    
# Line 1036  class FEDate extends FEBoxElement { Line 1263  class FEDate extends FEBoxElement {
1263      }      }
1264    
1265      /**      /**
1266       * This function will return the elements value as an array or month, day       * This function will return the elements value as an array or month, day and year
      * and year  
1267       *       *
1268       * @return array       * @return array
1269      */       * @access public
1270      function get_value() {       */
1271        function get_value(){
1272            $value= array("day"=>$this->_day->get_value(),
1273                          "month"=>$this->_month->get_value(),
1274                          "year"=>$this->_year->get_value());
1275    
1276            return $value;
1277    
         return $this->_value;  
1278    
1279      }      }
1280    
1281      /**      /**
1282         * Set the value of the element
1283         *
1284       * This function sets the default values for the date element  The       * This function sets the default values for the date element  The
1285       * parameter should be a string representation of the date in ISO 8601       * parameter should be a string representation of the date in ISO 8601
1286       * format.       * format.
1287       *       *
1288       * @param string       * @param string
1289         * @access public
1290      */      */
1291      function set_value($value) {      function set_value($value){
1292            if ($value) {
1293                if (is_array($value)) {
1294                    $this->_year->set_value($value['year']);
1295                    $this->_month->set_value($value['month']);
1296                    $this->_day->set_value($value['day']);
1297                } else {
1298                    $date_parts = explode('-', $value);
1299                    $this->_year->set_value($date_parts[0]);
1300                    $this->_month->set_value($date_parts[1]);
1301                    $this->_day->set_value($date_parts[2]);
1302                }
1303            }
1304    
         $date_parts = explode('-', $value);  
         $this->_year->set_value($date_parts[0]);  
         $this->_month->set_value($date_parts[1]);  
         $this->_day->set_value($date_parts[2]);  
1305    
1306      }      }
1307    
1308      /**      /**
1309       * This returns a formatted string used for the confirmation display (and       * This returns a formatted string used for the confirmation display (and possibly elsewhere)
1310       * possibly elsewhere)       *
      *  
1311       * @return string       * @return string
1312         * @access public
1313       */       */
1314      function get_value_text() {      function get_value_text(){
1315    
1316          // loop through the characters in $_format to properly set the placeholders          // loop through the characters in $_format to properly set the placeholders
1317          // determined in $_text_format          // determined in $_text_format
1318          $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY);          $chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY);
1319          $i = 1;          $i = 1;
1320          foreach ($chars as $char) {          foreach ($chars as $char){
1321    
1322              switch ($char) {              switch ($char) {
1323                  case 'y':              case 'y':
1324                      $value = $this->_year->get_value_text();                  $value = $this->_year->get_value_text();
1325                      break;                  break;
1326                  case 'm':              case 'm':
1327                  case 'F':              case 'F':
1328                      $value = $this->_month->get_value_text();                  $value = $this->_month->get_value_text();
1329                      break;                  break;
1330                  case 'd':              case 'd':
1331                      $value = $this->_day->get_value_text();                  $value = $this->_day->get_value_text();
1332                      break;                  break;
1333              }              }
1334    
1335              switch ($i) {              switch ($i) {
1336                  case 1:              case 1:
1337                      $one = $value;                  $one = $value;
1338                      break;                  break;
1339                  case 2:              case 2:
1340                      $two = $value;                  $two = $value;
1341                      break;                  break;
1342                  case 3:              case 3:
1343                      $three = $value;                  $three = $value;
1344                      break;                  break;
1345              }              }
1346    
1347              $i++;              $i++;
# Line 1114  class FEDate extends FEBoxElement { Line 1356  class FEDate extends FEBoxElement {
1356       * validation and setting the appropriate error message       * validation and setting the appropriate error message
1357       * in case of a failed validation       * in case of a failed validation
1358       *       *
1359       * @param FormValidation object       * @param FormValidation
1360         * @access public
1361         * @return boolean success or failure
1362       */       */
1363      function validate(&$_FormValidation) {      function validate(&$_FormValidation){
1364          $value = $this->get_value();          $value = $this->get_value();
1365    
1366  //         we make sure that the date is valid  //         we make sure that the date is valid
# Line 1132  class FEDate extends FEBoxElement { Line 1376  class FEDate extends FEBoxElement {
1376       *       *
1377       * @param string       * @param string
1378       * @return bool success or failure       * @return bool success or failure
1379         * @access private
1380       */       */
1381      function _set_format($format) {      function _set_format($format){
1382    
1383          // must be 3 characters          // must be 2 or 3 characters
1384          if (strlen($format) != 3) {          if (strlen($format) != 3) {
1385              return FALSE;              return FALSE;
1386          }          }
# Line 1159  class FEDate extends FEBoxElement { Line 1404  class FEDate extends FEBoxElement {
1404          $this->_format = $format;          $this->_format = $format;
1405          return TRUE;          return TRUE;
1406    
1407    
1408      }      }
1409    
1410      /**      /**
1411         * Set the text format for confirmation
1412         *
1413       * this method sets the format string used in get_value_text().  Use this       * this method sets the format string used in get_value_text().  Use this
1414       * method to set special punctuation for the confirmation display.       * method to set special punctuation for the confirmation display.  It is
1415         * fed through sprintf
1416         *
1417         * Examples:
1418         * <code>
1419         *  $date_element->set_text_format("%s %s, %s");
1420         *  $date_element->set_text_format("%04d-%02d-%02d");
1421         * </code>
1422       *       *
1423       * @param string       * @param string
1424         * @access public
1425         * @link http://www.php.net/manual/en/function.sprintf.php
1426       *       *
1427       */       */
1428      function set_text_format($format) {      function set_text_format($format){
1429    
1430          $this->_text_format = $format;          $this->_text_format = $format;
1431      }      }
1432    
1433      /**      /**
1434       * This method returns the hidden version of this       * This method returns the hidden version of this element for a confirmation page.
1435       * element for a confirmation page.         *
1436       *       * NOTE: This is called by the FormProcessor only.
      * NOTE: This is called by the FormProcessor only.    
1437       * It shouldn't be called manually.       * It shouldn't be called manually.
1438       *       *
1439       * @return container       * @return container
1440         * @access public
1441       */       */
1442      function get_confirm_element() {      function get_confirm_element(){
1443          $element_name = $this->get_element_name();          $element_name = $this->get_element_name();
1444    
1445          $c = container();          $c = container();
1446          $c->add(form_hidden("{$element_name}[year]", $this->_year->get_value()));          $c->add(form_hidden($this->_year->get_element_name(), $this->_year->get_value()));
1447          $c->add(form_hidden("{$element_name}[month]", $this->_month->get_value()));          $c->add(form_hidden($this->_month->get_element_name(), $this->_month->get_value()));
1448          $c->add(form_hidden("{$element_name}[day]", $this->_day->get_value()));          $c->add(form_hidden($this->_day->get_element_name(), $this->_day->get_value()));
1449          return $c;          return $c;
1450      }      }
1451    
1452    
1453        /**
1454         * Sets the disabled element flag
1455         *
1456         * @param bool disabled
1457         */
1458        function set_disabled($flag) {
1459            $this->_is_disabled = $flag;
1460            $this->_year->set_disabled($flag);
1461            $this->_month->set_disabled($flag);
1462            $this->_day->set_disabled($flag);
1463        }
1464    
1465    }
1466    
1467    
1468    
1469    /**
1470     * this class is used for building a listbox for
1471     * displaying Hours.
1472     *
1473     * @author Walter A. Boring IV
1474     */
1475    class FEHoursListBox extends FEListbox {
1476    
1477        /**
1478         * Flag to tell us to use 12 or 24 hour format
1479         */
1480        var $_extended_hours = TRUE;
1481    
1482        /**
1483         * The constructor
1484         *
1485         * @param string the label
1486         * @param boolean required flag or not
1487         * @param boolean show 24 hour format?
1488         */
1489        function FEHoursListBox($label='Hours', $required=FALSE, $extended_hours=TRUE) {
1490            if ($extended_hours) {
1491                $hours = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5,
1492                               '06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10, '11'=>11,
1493                               '12'=>12, '13'=>13, '14'=>14, '15'=>15, '16'=>16, '17'=>17,
1494                               '18'=>18, '19'=>19, '20'=>20, '21'=>21, '22'=>22, '23'=>23);
1495            } else {
1496                $hours = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5,
1497                               '06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10, '11'=>11,
1498                               '12'=>12);
1499            }
1500            parent::FEListBox($label, $required, null, null, $hours);
1501        }
1502    }
1503    
1504    /**
1505     * this class is used for building a listbox for
1506     * displaying Minutes.
1507     *
1508     * @author Walter A. Boring IV
1509     */
1510    class FEMinutesListBox extends FEListbox {
1511    
1512        /**
1513         * The constructor
1514         *
1515         * @param string the label (default = 'Minutes')
1516         * @param boolean required flag or not
1517         */
1518        function FEMinutesListBox($label='Minutes', $required=FALSE) {
1519            $minutes = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5,
1520                             '06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10);
1521    
1522            for($x=11;$x<=59;$x++) {
1523                $minutes[$x]=$x;
1524            }
1525    
1526            parent::FEListBox($label, $required, null, null, $minutes);
1527        }
1528    }
1529    
1530    /**
1531     * this class is used for building a listbox for
1532     * displaying Seconds.
1533     *
1534     * @author Walter A. Boring IV
1535     */
1536    class FESecondsListBox extends FEMinutesListbox {
1537    
1538        /**
1539         * The constructor
1540         *
1541         * @param string the label (default = 'Seconds')
1542         * @param boolean required flag or not
1543         */
1544        function FESecondsListBox($label='Seconds', $required=FALSE) {
1545            parent::FEMinutesListBox($label, $required);
1546        }
1547    }
1548    
1549    
1550    /**
1551     * This class is used to build a ListBox for
1552     * GMT timezone selection
1553     *
1554     * @author Walter A. Boring IV
1555     */
1556    class FEGMTTimeZoneListBox extends FEListBox {
1557    
1558        /**
1559         * The timezone selections
1560         */
1561        var $_zones=array("GMT -12 : Eniwetok, Kwajalein"=>-12,
1562                          "GMT -11 : Midway Islands, Samoa"=>-11,
1563                          "GMT -10 : Hawaii"=>-10,
1564                          "GMT -09 : Alaska"=>-9,
1565                          "GMT -08 : Pacific (USA, Canada), Tijuana"=>-8,
1566                          "GMT -07 : Arizona"=>-7,
1567                          "GMT -06 : Central (USA, Canada), Mexico"=>-6,
1568                          "GMT -05 : Bogota, Lima, Quito, East (USA, Canada)"=>-5,
1569                          "GMT -04 : Caracas, La Paz, Atlantic (Canada)"=>-4,
1570                          "GMT -03 : Terre Neuve, Brasilia, Georgetown"=>-3,
1571                          "GMT -02 : Atlantic Center"=>-2,
1572                          "GMT -01 : Azores"=>-1,
1573                          "GMT +00 : Casablanca, London, Dublin, Lisbon"=>0,
1574                          "GMT +01 : Paris, Amsterdam, Berlin, Rome, Vienna"=>1,
1575                          "GMT +02 : Athens, Bucharest, Riga, Cairo, Israel"=>2,
1576                          "GMT +03 : Nairobi, Moscow, Baghdad"=>3,
1577                          "GMT +04 : Abu Dhabi, Kabul"=>4,
1578                          "GMT +05 : Islamabad"=>5,
1579                          "GMT +06 : Colombo"=>6,
1580                          "GMT +07 : Bangkok, Hanoi, Jakarta"=>7,
1581                          "GMT +08 : Beijing, Hong Kong, Singapore, Taipei"=>8,
1582                          "GMT +09 : Tokyo, Seoul"=>9,
1583                          "GMT +10 : Sydney, Vladivostok"=>10,
1584                          "GMT +11 : New Caledonia"=>11,
1585                          "GMT +12 : Wellington"=>12);
1586    
1587        /**
1588         * The constructor
1589         *
1590         * @param string the label (default = 'Minutes')
1591         * @param boolean required flag or not
1592         */
1593        function FEGMTTimeZoneListBox($label='TimeZone', $required=FALSE) {
1594            parent::FEListBox($label, $required, null,null, $this->_zones);
1595        }
1596    }
1597    
1598    /**
1599     * This Form Element builds a list box of the days of the week.
1600     *
1601     * Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
1602     *
1603     * @author Walter A. Boring IV
1604     */
1605    class FEWeekdaysListBox extends FEListBox {
1606        var $_weekdays = array('Sunday' => 0, 'Monday' => 1,
1607                               'Tuesday' => 2, 'Wednesday' => 3,
1608                               'Thursday' => 4, 'Friday' => 5,
1609                               'Saturday' => 6);
1610    
1611        function FEWeekdaysListBox($label='Weekdays', $required=FALSE) {
1612            parent::FEListBox($label, $required, null,null, $this->_weekdays);
1613        }
1614  }  }
1615    
1616  ?>  ?>

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed