[phplib-dev] cvs commit From: uw (phplib-dev <email protected>)
Date: 01/02/01

From: uw
Date: Tue Jan 2 16:49:49 2001
Modified files:
      php-lib/php/form/assistant.inc
      php-lib/php/form/form.inc
      php-lib/php/form/form_element.inc
      php-lib/php/form/form_element_buttonobject.inc
      php-lib/php/form/form_element_checkbox.inc
      php-lib/php/form/form_element_checkobject.inc
      php-lib/php/form/form_element_combo.inc
      php-lib/php/form/form_element_date.inc
      php-lib/php/form/form_element_file.inc
      php-lib/php/form/form_element_fileupload.inc
      php-lib/php/form/form_element_hidden.inc
      php-lib/php/form/form_element_image.inc
      php-lib/php/form/form_element_password.inc
      php-lib/php/form/form_element_radio.inc
      php-lib/php/form/form_element_reset.inc
      php-lib/php/form/form_element_select.inc
      php-lib/php/form/form_element_selectobject.inc
      php-lib/php/form/form_element_submit.inc
      php-lib/php/form/form_element_text.inc
      php-lib/php/form/form_element_textarea.inc
      php-lib/php/form/form_element_textobject.inc
      php-lib/php/form/form_element_tree.inc
      php-lib/php/form/form_error.inc
      php-lib/php/form/form_js_complex.js
      php-lib/php/form/form_js_simple.js
      php-lib/php/form/form_loader.inc
      php-lib/php/form/panemanager.inc
      php-lib/php/form/panemanager_gifimage.inc
      php-lib/php/form/template_bridge.inc

Log message:
- made form_element_date working
- some minor changes

Index: php-lib/php/form/assistant.inc
diff -u php-lib/php/form/assistant.inc:1.18 php-lib/php/form/assistant.inc:1.19
--- php-lib/php/form/assistant.inc:1.18 Tue Dec 19 14:34:14 2000
+++ php-lib/php/form/assistant.inc Tue Jan 2 16:49:27 2001
@@ -3,7 +3,7 @@
 * Assistant/wizard that guides a user through several forms.
 *
 *  <email protected> Ulf Wendel <ulf.wendel <email protected>>
-*  <email protected> $Id: assistant.inc,v 1.18 2000/12/19 13:34:14 uw Exp $
+*  <email protected> $Id: assistant.inc,v 1.19 2001/01/02 15:49:27 uw Exp $
 */
 class assistant extends panemanager {
         
@@ -28,7 +28,7 @@
         *
         * - must be restored by a session! -
         *
- *  <email protected> array $page_errors
+ *  <email protected> array $page_errors
         */
         var $page_errors = array();
         
@@ -37,29 +37,28 @@
         *
         * - must be restored by a session! -
         *
- *  <email protected> string $lastviewed
+ *  <email protected> integer
         */
         var $lastviewed = 0;
         
+ /**
+ * Which page was selected by the user?
+ *
+ *  <email protected> integer
+ */
+ var $selected = -1;
+
         /**
         * Which page will be show now?
         *
- *  <email protected> string $now
+ *  <email protected> integer
         */
         var $now = -1;
         
         /**
- * Show tabs?
- *
- *  <email protected> bool $show_tabs
- *  <email protected> show_tabs()
- */
- var $show_tabs = true;
-
- /**
         * Template object.
         *
- *  <email protected> object $tpl
+ *  <email protected> object template $tpl
         */
         var $tpl = "";
         
@@ -96,18 +95,6 @@
         */
         var $mode = "strict";
 
- s/**
- * Some labels.
- *
- *  <email protected> array $labels
- *  <email protected> setLabels()
- */
- var $labels = array (
- "next" => "",
- "prev" => "",
- "reset" => ""
- );
-
         /**
         * Nameprefix of all buttons generated by assistant.
         *
@@ -116,14 +103,6 @@
         var $buttonname = "assistant";
         
         /**
- * Show prev- and next-button?
- *
- *  <email protected> bool show_prevnext = true
- *  <email protected> setPrevNext()
- */
- var $show_prevnext = true;
-
- /**
         * Flag, set if specials.
         *
         *  <email protected> string $flag_specials
@@ -133,8 +112,6 @@
         
         /**
         * Restores the Assistant. Load the pages with values, sets validation flags etc.
- *s
- *  <email protected> private
         */
         function restoreAssistant() {
         
@@ -155,12 +132,12 @@
         *
         *  <email protected> string $template
         *  <email protected> bool $ok
- *  <email protected> FormError
+ *  <email protected> form_error
         *  <email protected> public
         */
         function setTemplatePath($template) {
                 if ("" == $template) {
- $this->exceptions[] = new FormError("setTemplatePath(), illegal function call",__FILE__, __LINE__);
+ $this->exceptions[] = new form_error("setTemplatePath(), illegal function call",__FILE__, __LINE__);
                         return false;
                 }
                 
@@ -171,14 +148,12 @@
         /**
         * Creates a new template object.
         *
- *  <email protected> bool $ok
- *  <email protected> FormError
- *  <email protected> private
- *  <email protected> assistant()
+ *  <email protected> boolean
+ *  <email protected> form_error
         */
         function newTemplate() {
                 if ("" == $this->template || 0 == count($this->template_files)) {
- $this->exceptions[] = new FormError("newTemplate(), illegal function call", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("newTemplate(), illegal function call", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -198,8 +173,8 @@
         /**
         * Set the template files
         *
- *  <email protected> array $files
- *  <email protected> template_files
+ *  <email protected> array
+ *  <email protected> $template_files
         *  <email protected> public
         */
         function setTemplateFiles($files) {
@@ -308,10 +283,21 @@
         } // end func get()
         
         /**
- * Get the values of the last form.
+ * Prints and returns the HTML code of the assistant.
         *
- *  <email protected> private
+ *  <email protected> get()
         */
+ function show() {
+
+ $html = $this->get();
+ print $html;
+
+ return $html;
+ } // end func show
+
+ /**
+ * Get the values of the last form.
+ */
         function saveFormValues() {
                 if ("" == $this->lastviewed)
                         return;
@@ -359,15 +345,14 @@
         /**
         * Returns the page_id (page__values/page_errors index) that belongs to a page name.
         *
- *  <email protected> string $page_name
- *  <email protected> int $page_id, if -1 the page was not found
- *  <email protected> private
- *  <email protected> FormError
- *  <email protected> isValid(), getPageValues()
+ *  <email protected> string
+ *  <email protected> integer -1: not found
+ *  <email protected> form_error
+ *  <email protected> isValid(), panemanager::getPageValues()
         */
         function PageNametoPageID($page_name) {
                 if ("" == $page_name) {
- $this->exceptions[] = new FormError("assistant -> PageNametoPageID(), illegal function call", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> PageNametoPageID(), illegal function call", __FILE__, __LINE__);
                         return -1;
                 }
                 
@@ -390,7 +375,7 @@
         */
         function isValid($page = "") {
                 if (0 == count($this->pages)) {
- $this->exceptions[] = new FormError("assistant -> isValid(), no pages in assistant", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> isValid(), no pages in assistant", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -398,7 +383,7 @@
                         
                         $p_id = $this->PageNametoPageID($page);
                         if (-1 == $p_id) {
- $this->exceptions[] = new FormError("assistant -> isValid(), unknown page '$page'", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> isValid(), unknown page '$page'", __FILE__, __LINE__);
                                 return false;
                         }
                         
@@ -424,7 +409,7 @@
         */
         function getNeighbour($now) {
                 if ("" == (string)$now) {
- $this->exceptions[] = new FormError(11, "assistant -> getNeighbour(), illegal function call");
+ $this->exceptions[] = new form_error(11, "assistant -> getNeighbour(), illegal function call");
                         return array("", "");
                 }
                 
@@ -448,7 +433,7 @@
         */
         function setPageErrors() {
                 if (0 == count($this->pages)) {
- $this->exceptions[] = new FormError("assistant -> setPageErrors(), no pages in assistant", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> setPageErrors(), no pages in assistant", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -468,9 +453,9 @@
         /**
         * If you override some page_values in Init() you have to update the page validation flags.
         *
- *  <email protected> string $pages name of one page, "" means update all
- *  <email protected> array $pages array with page names
- *  <email protected> bool $ok
+ *  <email protected> mixed Name of one page, or array of page names. The default of
+ * an empty string means all pages.
+ *  <email protected> boolean $ok
         *  <email protected> public
         */
         function updatePageErrors($pages = "") {
@@ -487,7 +472,7 @@
                         $pages = array($pages);
                 
                 if (0 == count($pages)) {
- $this->exceptions[] = new FormError("form -> updatePageErrors(), no pages defined?", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("form -> updatePageErrors(), no pages defined?", __FILE__, __LINE__);
                         return false;
                 }
                         
@@ -495,7 +480,7 @@
                 $unknown = "";
                                         
                 foreach ($pages as $k => $page) {
- if (isset($this->page_values[$page]) ) {
+ if (isset($this->page_values[$page])) {
                                 if (isset($this->pages[$page]["optional"]))
                                         continue;
                                 $obj = &$this->pages[$page]["object"];
@@ -506,7 +491,7 @@
                 }
                 
                 if ("" != $unknown) {
- $this->exceptions[] = new FormError("form -> updatePageErrors(), unknown pages: $unknown", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("form -> updatePageErrors(), unknown pages: $unknown", __FILE__, __LINE__);
                         $ok = false;
                 }
                         
@@ -516,7 +501,7 @@
         /**
         * Saves the number of the selected Page to $this->selected
         *
- *  <email protected> $selected, $buttunname, findPosition()
+ *  <email protected> $selected, $lastviewed, findPosition()
         *  <email protected> boolean
         */
         function findSelected() {
@@ -555,7 +540,6 @@
         * tests wheter the user is allowed to see the requested page or if
         * he should get rejected.
         *
- *  <email protected> private
         *  <email protected> findSelected()
         */
         function findPosition() {
@@ -600,11 +584,11 @@
         *
         *  <email protected> array $pagenames
         *  <email protected> public
- *  <email protected> FormError
+ *  <email protected> form_error
         */
         function getPageNames() {
                 if (0 == count($this->pages)) {
- $this->exceptions[] = new FormError("assistant -> getPagesNames(), no pages in assistant", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> getPagesNames(), no pages in assistant", __FILE__, __LINE__);
                         return array();
                 }
                 
@@ -624,15 +608,15 @@
         */
         function addPage($pagedata) {
                 if (!is_array($pagedata) || 0 == count($pagedata)) {
- $this->exceptions[] = new FormError("assistant -> addPage(), illegal function call", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> addPage(), illegal function call", __FILE__, __LINE__);
                         return false;
                 }
                 if (!isset($pagedata["name"]) || "" == $pagedata["name"]) {
- $this->exceptions[] = new FormError("assistant -> addPage(), you must specify a name for you page", __FILE__, __LINE__);
+ $this->exceptions[] = new form_error("assistant -> addPage(), you must specify a name for you page", __FILE__, __LINE__);
                         return false;
                 }
                 if ("" == $pagedata["object"]) {
- $this->exeptions[] = new FormError("assistant -> addPage(), you must specify a template object for this page", __FILE__, __LINE__);
+ $this->exeptions[] = new form_error("assistant -> addPage(), you must specify a template object for this page", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -668,65 +652,6 @@
         function setMode($mode) {
                 $this->mode = ("weak" == $mode) ? "weak" : "strong";
         } // end func mode
-
- /**
- * Sets the label and action for the button that finishes the assistant.
- *
- *  <email protected> string $label
- *  <email protected> string $action Fallback to $PHP_SELF
- *  <email protected> bool $ok
- *  <email protected> public
- *  <email protected> FormError
- */
- function setFinish($label, $action = "") {
- global $PHP_SELF;
-
- if ("" == $label) {
- $this->exceptions[] = new FormError("assistant -> setFinish(), illegal function call", __FILE__, __LINE__);
- return false;
- }
-
- $this->finish_button = array (
- "label" => $label,
- "action" => ("" == $action) ? $PHP_SELF : $action
- );
-
- return true;
- } // end func setFinish
 
- /**
- * Set the label of a button.
- *
- *  <email protected> mixed
- *  <email protected> string $value
- *  <email protected> bool $ok
- *  <email protected> $labels
- *  <email protected> public
- *  <email protected> FormError
- */
- function setLabel($labels, $value = "") {
- if (("" == $value && "" == $labels) || (!is_array($labels) && "" == $value)) {
- $this->exceptions[] = new FormError("assistant -> setLabel(), illegal function call", __FILE__, __LINE__);
- return false;
- }
-
- $ok = false;
- if (!is_array($labels)) {
- if (isset($this->labels[$labels])) {
- $this->labels[$labels] = $value;
- $ok = true;
- }
- } else {
-
- foreach($labels as $label => $value)
- if (isset($this->labels[$label])) {
- $this->labels[$label] = $value;
- $ok = true;
- }
- }
-
- return $ok;
- } // end func setLabel
-
 } // end class assistant
 ?>
Index: php-lib/php/form/form.inc
diff -u php-lib/php/form/form.inc:1.15 php-lib/php/form/form.inc:1.16
--- php-lib/php/form/form.inc:1.15 Mon Jan 1 15:50:45 2001
+++ php-lib/php/form/form.inc Tue Jan 2 16:49:29 2001
@@ -26,7 +26,7 @@
 * - tree (select box with options show as a tree)
 *
 *  <email protected> Ulf Wendel <ulf.wendel <email protected>>
-*  <email protected> $Id: form.inc,v 1.15 2001/01/01 14:50:45 uw Exp $
+*  <email protected> $Id: form.inc,v 1.16 2001/01/02 15:49:29 uw Exp $
 *  <email protected> public
 *  <email protected> Form
 */
@@ -847,31 +847,48 @@
                 $base_code = fread($fh, filesize($file));
                 fclose($fh);
                 
- // customize the error message
- $base_code = str_replace("{ERROR_MSG_PREFIX}", $this->js_error_prefix, $base_code);
- $base_code = str_replace("{ERROR_MSG_POSTFIX}", $this->js_error_postfix, $base_code);
-
                 // get JS code from every element of the form
                 $js = "";
+ $custom = "";
                 $get_value = "";
                 // list of already send get_value functions
- $send = array();
+ $send_func = array();
+ $send_gv_el = array();
                 
                 foreach ($this->elements as $name => $el) {
-
+
+ // all kinds of additional JS code
+ list($extra_func, $extra_fname) = $el->getExtraJS();
+ if ($extra_fname && !isset($send_func[$extra_fname])) {
+ $base_code .= $extra_func . ";";
+ $send_func[$extra_fname] = true;
+ }
+
+ // custom validator and get_value function
                         list($eldata, $getvalue_func, $getvalue_fname, $js_validator) = $el->getJS($complex);
                         if ($js_validator)
- $base_code = $base_code . "\n" . $js_validator;
+ $custom .= $js_validator . "\n";
                         
                         $js .= $eldata;
-
- // complex function needed to get the value of this form element
- if ($getvalue_fname && !isset($send[$getvalue_fname])) {
- $base_code = $base_code . "\n" . $getvalue_func;
- $get_value.= sprintf('"%s", "%s", ', $el->getName(), $getvalue_fname);
- $send[$getvalue_fname] = true;
- }
+
+ if ($getvalue_fname) {
+
+ $elname = $el->getName();
                                 
+ // don't send radio entries twice
+ if(!isset($send_gv_el[$elname])) {
+ $get_value.= sprintf('"%s", "%s", ', $elname, $getvalue_fname);
+ $send_gv_el[$elname] = true;
+ }
+
+ // complex function used to get the value of this form element
+ if (!isset($send_func[$getvalue_fname])) {
+ $base_code = $base_code . "\n" . $getvalue_func . ";";
+ $send_func[$getvalue_fname] = true;
+ }
+
+ }
+
                 }
 // form("forma", ["elname", [eldata], "elname", [eldata, flags]], ["elname", "gv"], ["val"]);
 // name, els, val, gv
@@ -888,19 +905,70 @@
                 else
                         $js = sprintf('[%s]', substr($js, 0, -2));
                         
+ // ;-) compress the JS code....
+ $base_code = $this->compressJS($base_code);
+
+ // customize the error message
+ $base_code = str_replace("{ERROR_MSG_PREFIX}", $this->js_error_prefix, $base_code);
+ $base_code = str_replace("{ERROR_MSG_POSTFIX}", $this->js_error_postfix, $base_code);
+
                 $js = sprintf('<script language="JavaScript1.2"><!--//
 %s
-
+%s
 var _%s = new form("%s", %s);
 //--></script>',
                                                                                         $base_code,
+ $custom,
                                                                                         $this->js_name,
                                                                                         $this->js_name,
                                                                                         $js
                                                                                 );
-
+
                 return $js;
         } // end func getJS
+
+ /**
+ * Removes tabs, spaces and newlines from the given JavaScript code.
+ *
+ * Warning: do not use this function with user supplied code.
+ *
+ * The function replaces most tabs and spaces with an empty string before
+ * it starts to remove some newlines. The resulting code is usually
+ * 15-25% shorter than the orginial code.
+ *
+ *  <email protected> string JavaScript code snippet
+ *  <email protected> string compressed code
+ *  <email protected> getJS()
+ */
+ function compressJS($code) {
+
+ $search = array("/function[ \t]+/i", "/new[ \t]+/i", "/var[ \t]+/i", "/return[ \t]+/i", "/[ \t]*else[ \t]*/i", "/[ \t]+in[ \t]+/i");
+ $meta = array("{FUNCTION_}", "{NEW_}", "{VAR_}", "{RETURN_}", "{_ELSE_}", "{_IN_}");
+ $final = array("function ", "new ", "var ", "return ", " else ", " in ");
+
+ // remove spaces and tabs
+ $code = preg_replace($search, $meta, $code);
+ $code = preg_replace("/[ \t]/", "", $code);
+
+ // remove some newlines
+ $tmp = array();
+ $code = explode("\n", $code);
+ $j = 0;
+ foreach ($code as $k => $line) {
+ if (strlen($tmp[$j]) < 120)
+ $tmp[$j] .= $line;
+ else
+ $tmp[++$j] = $line;
+ }
+ $code = implode("\n", $tmp);
+
+ // finish the work
+ foreach ($meta as $k => $v)
+ $meta[$k] = "/$v/";
+ $code = preg_replace($meta, $final, $code);
+
+ return $code;
+ } // end func compressJS
         
         /**
         *  <email protected> unfreeze()
Index: php-lib/php/form/form_element.inc
diff -u php-lib/php/form/form_element.inc:1.6 php-lib/php/form/form_element.inc:1.7
--- php-lib/php/form/form_element.inc:1.6 Mon Jan 1 15:50:48 2001
+++ php-lib/php/form/form_element.inc Tue Jan 2 16:49:29 2001
@@ -3,7 +3,7 @@
 * Superclass of all form elements.
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
-*  <email protected> $Id: form_element.inc,v 1.6 2001/01/01 14:50:48 uw Exp $
+*  <email protected> $Id: form_element.inc,v 1.7 2001/01/02 15:49:29 uw Exp $
 *  <email protected> public
 *  <email protected> Form
 *  <email protected>
@@ -776,13 +776,33 @@
         * e.g. "form_select". The (JS) function gets called with two arguments:
         * string formname, string elementname. It returns the value of the element, see
         * form_element_select for an example.
+ *
+ * The function returns the JavaScript code itself and a name for the code
+ * snippet that allows the form object to avoid sending the code twice.
         *
         *  <email protected> array [JavaScript function code, JavaScript function name]
- *
         */
         function getJSvalue() {
                 return array("", "");
         } // end func getJSvalue
+
+ /**
+ * Returns additional JavaScript required by some complex form elements.
+ *
+ * Some elements need extra JavaScript functionality to be
+ * full featured. Date for example is able to draw a "now" button. When the
+ * user clicks this button, the date selectors change their values to the
+ * current date. An additional JavaScript function "form_date_now" handles the click
+ * on the button.
+ *
+ * The function returns the JavaScript code itself and a name for the code
+ * snippet that allows the form object to avoid sending the code twice.
+ *
+ *  <email protected> array [JavaScript code, JavaScript code snippet name]
+ */
+ function getExtraJS() {
+ return array("", "");
+ }
         
         /**
         * Returns the HTML/JavaScript name of the element.
Index: php-lib/php/form/form_element_buttonobject.inc
diff -u php-lib/php/form/form_element_buttonobject.inc:1.5 php-lib/php/form/form_element_buttonobject.inc:1.6
--- php-lib/php/form/form_element_buttonobject.inc:1.5 Mon Jan 1 15:50:48 2001
+++ php-lib/php/form/form_element_buttonobject.inc Tue Jan 2 16:49:30 2001
@@ -3,7 +3,7 @@
 * Superclass of all buttons.
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
-*  <email protected> $Id: form_element_buttonobject.inc,v 1.5 2001/01/01 14:50:48 uw Exp $
+*  <email protected> $Id: form_element_buttonobject.inc,v 1.6 2001/01/02 15:49:30 uw Exp $
 *  <email protected> public
 *  <email protected>
 *  <email protected> Form
Index: php-lib/php/form/form_element_checkbox.inc
diff -u php-lib/php/form/form_element_checkbox.inc:1.6 php-lib/php/form/form_element_checkbox.inc:1.7
--- php-lib/php/form/form_element_checkbox.inc:1.6 Mon Jan 1 15:50:49 2001
+++ php-lib/php/form/form_element_checkbox.inc Tue Jan 2 16:49:31 2001
@@ -5,7 +5,7 @@
 *  <email protected> Ulf Wendel <ulf.wendel <email protected>>
 *  <email protected> public
 *  <email protected> Form
-*  <email protected> $Id: form_element_checkbox.inc,v 1.6 2001/01/01 14:50:49 uw Exp $
+*  <email protected> $Id: form_element_checkbox.inc,v 1.7 2001/01/02 15:49:31 uw Exp $
 */
 class form_element_checkbox extends form_element_checkobject {
         
@@ -49,7 +49,7 @@
         
                 return array('function form_checkbox(f, e) {
         with (document.forms[f].elements[e])
- return (checked) ? value : "";
+ return [(checked) ? value : "", ""];
 }', "form_checkbox");
 
         } // end func getJSValue
Index: php-lib/php/form/form_element_checkobject.inc
diff -u php-lib/php/form/form_element_checkobject.inc:1.6 php-lib/php/form/form_element_checkobject.inc:1.7
--- php-lib/php/form/form_element_checkobject.inc:1.6 Mon Jan 1 15:50:49 2001
+++ php-lib/php/form/form_element_checkobject.inc Tue Jan 2 16:49:31 2001
@@ -4,7 +4,7 @@
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
 *  <email protected> Form
-*  <email protected> $Id: form_element_checkobject.inc,v 1.6 2001/01/01 14:50:49 uw Exp $
+*  <email protected> $Id: form_element_checkobject.inc,v 1.7 2001/01/02 15:49:31 uw Exp $
 *  <email protected>
 */
 class form_element_checkobject extends form_element {
Index: php-lib/php/form/form_element_combo.inc
diff -u php-lib/php/form/form_element_combo.inc:1.6 php-lib/php/form/form_element_combo.inc:1.7
--- php-lib/php/form/form_element_combo.inc:1.6 Mon Jan 1 15:50:50 2001
+++ php-lib/php/form/form_element_combo.inc Tue Jan 2 16:49:32 2001
@@ -4,7 +4,7 @@
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
 *  <email protected> Form
-*  <email protected> $Id: form_element_combo.inc,v 1.6 2001/01/01 14:50:50 uw Exp $
+*  <email protected> $Id: form_element_combo.inc,v 1.7 2001/01/02 15:49:32 uw Exp $
 */
 class form_element_combo extends form_element_selectobject {
 
Index: php-lib/php/form/form_element_date.inc
diff -u php-lib/php/form/form_element_date.inc:1.6 php-lib/php/form/form_element_date.inc:1.7
--- php-lib/php/form/form_element_date.inc:1.6 Mon Jan 1 15:50:50 2001
+++ php-lib/php/form/form_element_date.inc Tue Jan 2 16:49:32 2001
@@ -5,7 +5,7 @@
 * Use this meta element to make sure that the user enters a valid date.
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
-*  <email protected> $Id: form_element_date.inc,v 1.6 2001/01/01 14:50:50 uw Exp $
+*  <email protected> $Id: form_element_date.inc,v 1.7 2001/01/02 15:49:32 uw Exp $
 *  <email protected> Form
 */
 class form_element_date extends form_element {
@@ -16,14 +16,21 @@
                                                                                                                                 
 
         var $optional_fields = array (
+ "now" => "string",
+
+ "preload" => "boolean",
+
                                                                                                                                         "language" => "string",
                                                                                                                                         
+ "intro" => "string",
+ "intro_e" => "string",
+
                                                                                                                                         "min_year_long" => "integer",
                                                                                                                                         "max_year_long" => "integer",
                                                                                                                                         
                                                                                                                                         "min_year_short" => "integer",
                                                                                                                                         "max_year_short" => "integer"
- );
+ );
         /**
         * String describing the format of the date/time that you can enter.
         *
@@ -67,8 +74,36 @@
         * Last year of a date("y") selector.
         *
         *  <email protected> $min_year_short
+ */
+ var $max_year_short = 10;
+
+ /**
+ * Intro option.
+ *
+ *  <email protected> string
+ */
+ var $intro = "";
+
+ /**
+ * Intro option error message.
+ *
+ *  <email protected> string
+ */
+ var $intro_e = "";
+
+ /**
+ * Preload selectors with the current date?
+ *
+ *  <email protected> boolean
+ */
+ var $preload = false;
+
+ /**
+ * Add a Submit button that allows the user to preload with the current date?
+ *
+ *  <email protected> boolean
         */
- var $max_year_short = 0;
+ var $now = "";
         
         /**
         * Word translation mapping.
@@ -87,7 +122,7 @@
                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                 "months_long" => array( "January", "February", "March", "April", "May",
                                                                                                                                                                                                                                                                                                         "June", "Juli", "August", "September", "October",
- "November", "December" )
+ "November", "December" )
                                                                                                                                         ),
                                                                                                                                         
                                                                                                         "de" => array (
@@ -97,10 +132,11 @@
                                                                                                                                                                                                                                                                                                         "Freitag", "Samstag", "Sonntag"),
                                                                                                                                                                                 
                                                                                                                                                                                 "months_short" => array ( "Jan", "Feb", "März", "April", "Mai", "Juni", "Juli",
- "Aug", "Sept", "Nov", "Dez"),
+ "Aug", "Sept", "Okt", "Nov", "Dez"),
                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                 "months_long" => array( "Januar", "Februar", "März", "April", "Mai", "Juni",
- "Juli", "August", "September", "November", "Dezember" )
+ "Juli", "August", "September", "Oktober", "November",
+ "Dezember" )
                                                                                                                                                                                 
                                                                                                                                         )
                                                                                                 );
@@ -121,12 +157,11 @@
         } // end func setup
         
         /**
- * FIXME - EVEN MORE FIXME: element_prefix
- * Returns the selected value.
+ * Returns an array with the values of the selected date.
         *
- * The date selector consists of several select boxes.
- * This function goes through $HTTP_[POST|GET]_VARS
- * and extracts the values of each select box.
+ * The assoziative array is indexed by the format string characters.
+ *
+ *  <email protected> array
         */
         function getValue() {
 
@@ -135,44 +170,20 @@
                 else
                         $data = &$GLOBALS["HTTP_POST_VARS"];
                         
+ $value = array();
                 $len = strlen($this->format);
-
                 for ($i = 0; $i < $len; $i++) {
                 
                         $sign = $this->format{$i};
-
- if (preg_match("/[aAdDfhHgGijlmnMswYyz]/", $sign, $regs)) {
-
+ if (preg_match("/[aAdDFhHgGijlmnMswYyz]/", $sign, $regs)) {
                                 $sign = $regs[1];
-
- if (isset($data[$sign . "_" . $this->name])) {
-
- $value = $data[$sign . "_" . $this->name];
-
- switch ($sign) {
- case "a":
- $this->value[$sign] = "";
- break;
- }
-
- }
-
+ $value[$sign] = $data[$this->name . "_" . $sign];
                         }
                         
                 }
-
- } // end func getValue
-
- function setValue($value) {
-
- if (is_array($value)) {
- $this->value = $value;
- return true;
- }
-
- return false;
- } // end func setValue
         
+ return $value;
+ } // end func getValue
         
         function get($value = "") {
 
@@ -282,8 +293,23 @@
                                         break;
                                         
                                 case "y":
- for ($j = $this->min_year_short; $j <= $this->max_year_short; $j++)
+
+ if ($this->min_year_short > $this->max_year_short) {
+
+ // range: [19]90 - [20]10
+ for ($j = $this->min_year_short; $j < 99; $j++)
+ $options[] = $j;
+ for ($j = 0; $j <= $this->max_year_short; $j++)
+ $options[] = $j;
+
+ } else {
+
+ // range: [19]90 - [19]99
+ for ($j = $this->min_year_short; $j <= $this->max_year_short; $j++)
                                                 $options[] = $j;
+
+ }
+
                                         $html .= $this->generateSelect("y", $options);
                                         break;
                                 
@@ -300,27 +326,155 @@
                         
                 }
                 
+ if ($this->now)
+ $html .= $this->generateButton();
+
                 return $html;
         } // end func get
         
+ function generateButton() {
+
+ return sprintf('<input type="submit" name="%s_button" value="%s" onClick="form_date_now(\'%s_\'); return false;">',
+ $this->name,
+ $this->now,
+ $this->name
+ );
+
+ } // end func generateButton
+
         /**
         * Generates a select box.
         *
         *  <email protected> string HTML select tag name attribute
         *  <email protected> array List of options
+ *  <email protected> mixed Selected option
         *  <email protected> string HTML
         */
         function generateSelect($name, $options) {
         
- $html = sprintf('<select name="%s_%s" size="1">%s', $name, $this->name, $this->CR_HTML);
+ $html = sprintf('<select name="%s_%s" size="1"%s>%s',
+ $this->name,
+ $name,
+ $this->getJSonActivation($name),
+ $this->CR_HTML
+ );
                 
+ if ($this->intro_e)
+ $html .= sprintf('<option value="%s">%s</option>%s', $this->intro, $this->intro, $this->CR_HTML);
+
                 foreach ($options as $k => $option)
- $html .= sprintf('<option value="%s">%s</option>%s', $option, $option, $this->CR_HTML);
+ $html .= sprintf('<option value="%s"%s>%s</option>%s',
+ $option,
+ ((isset($this->value[$name]) && $option == $this->value[$name]) || (!$selected && $this->preload && $option == $this->getPreloadValue($name))) ? " selected" : "",
+ $option,
+ $this->CR_HTML
+ );
                         
+
                 $html .= "</select>" . $this->CR_HTML;
                 
                 return $html;
         } // end func generateSelect
+
+ function getPreloadValue($name) {
+
+ $value = "";
+ switch ($name) {
+ case "M":
+ $value = $this->options[$this->language]["months_short"][date("n") - 1];
+ break;
+
+ case "l":
+ $value = $this->options[$this->language]["weekdays_long"][date("w")];
+ break;
+
+ case "D":
+ $value = $this->options[$this->language]["weekdays_short"][date("w")];
+ break;
+
+ case "F":
+ $value = $this->options[$this->language]["months_long"][date("n") - 1];
+ break;
+
+ default:
+ $value = date($name);
+ break;
+ }
+
+ return $value;
+ }
+
+ /**
+ *  <email protected> string Elementname Suffix
+ */
+ function getJSonActivation($name) {
+
+ if ("strong" == $this->js_mode)
+ return sprintf(' onChange="_%s.validate(\'%s_%s\')" ',
+ $this->form_name,
+ $this->name,
+ $name
+ );
+
+ } // end func getJSonActivation
+
+ function getJSvalue() {
+
+ $js = 'function form_date(f, e) {
+ var v = s = n = "";
+ var i = j = 0;
+ with (document.forms[f])
+ for ( ; i < length; i++) {
+ n = elements[i].name;
+ if (-1 != n.search(new RegExp(e + "_[aAdDFhHgGijlmnMswYyz]"))) {
+ if (!s)
+ s = n;
+ with (elements[i])
+ for (j = 0; j < options.length; j++)
+ if (options[j].selected)
+ v += options[j].value;
+ }
+ }
+ return [v, s];
+}';
+
+ return array($js, "form_date");
+ } // end func getJSvalue
+
+ function getExtraJS() {
+
+ $values = "";
+ $format = "";
+ $len = strlen($this->format);
+ for ($i = 0; $i < $len; $i++)
+ if (preg_match("/[aAdDFhHgGijlmnMswYyz]/", $this->format{$i})) {
+ $format .= $this->format{$i};
+ $values .= sprintf('"%s", ', $this->getPreloadValue($this->format{$i}));
+ }
+ $values = substr($values, 0, -2);
+
+ $js = sprintf('function form_date_now(e) {
+ var i = j = f = v = 0;
+
+ v = [%s];
+ f = "%s";
+
+ for (i = 0; i < f.length; i++)
+ with (document.forms["%s"].elements[e + f.substring(i, i + 1)])
+ for (j = 0; j < options.length; j++)
+ if (options[j].value.toString() == v[i]) {
+ options[j].selected = true;
+ break;
+ }
+
+}',
+ $values,
+ $format,
+ $this->form_name
+ );
+
+ return array($js, "form_date_now");
+ } // end func getExtraJS
         
 } // end class form_elements_date
 ?>
Index: php-lib/php/form/form_element_file.inc
diff -u php-lib/php/form/form_element_file.inc:1.6 php-lib/php/form/form_element_file.inc:1.7
--- php-lib/php/form/form_element_file.inc:1.6 Mon Jan 1 15:50:50 2001
+++ php-lib/php/form/form_element_file.inc Tue Jan 2 16:49:33 2001
@@ -8,7 +8,7 @@
 *  <email protected> Ulf Wendel <uw <email protected>>
 *  <email protected> Form
 *  <email protected> public
-*  <email protected> $Id: form_element_file.inc,v 1.6 2001/01/01 14:50:50 uw Exp $
+*  <email protected> $Id: form_element_file.inc,v 1.7 2001/01/02 15:49:33 uw Exp $
 */
 class form_element_file extends form_element_buttonobject {
 
Index: php-lib/php/form/form_element_fileupload.inc
diff -u php-lib/php/form/form_element_fileupload.inc:1.6 php-lib/php/form/form_element_fileupload.inc:1.7
--- php-lib/php/form/form_element_fileupload.inc:1.6 Mon Jan 1 15:50:51 2001
+++ php-lib/php/form/form_element_fileupload.inc Tue Jan 2 16:49:33 2001
@@ -7,7 +7,7 @@
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
 *  <email protected> Form
-*  <email protected> $Id: form_element_fileupload.inc,v 1.6 2001/01/01 14:50:51 uw Exp $
+*  <email protected> $Id: form_element_fileupload.inc,v 1.7 2001/01/02 15:49:33 uw Exp $
 *  <email protected> public
 */
 class form_element_fileupload extends form_element_file {
Index: php-lib/php/form/form_element_hidden.inc
diff -u php-lib/php/form/form_element_hidden.inc:1.5 php-lib/php/form/form_element_hidden.inc:1.6
--- php-lib/php/form/form_element_hidden.inc:1.5 Mon Jan 1 15:50:52 2001
+++ php-lib/php/form/form_element_hidden.inc Tue Jan 2 16:49:34 2001
@@ -3,7 +3,7 @@
 * Generates hidden elements.
 *
 *  <email protected> Ulf Wendel <uw <email protected>>
-*  <email protected> $Id: form_element_hidden.inc,v 1.5 2001/01/01 14:50:52 uw Exp $
+*  <email protected> $Id: form_element_hidden.inc,v 1.6 2001/01/02 15:49:34 uw Exp $
 *  <email protected> Form
 */
 class form_element_hidden extends form_element {
Index: php-lib/php/form/form_element_image.inc
diff -u php-lib/php/form/form_element_image.inc:1.6 php-lib/php/form/form_element_image.inc:1.7
--- php-lib/php/form/form_element_image.inc:1.6 Mon Jan 1 15:50:52 2001
+++ php-lib/php/form/form_element_image.inc Tue Jan 2 16:49:34 2001
@@ -5,7 +5,7 @@
 *  <email protected> Ulf Wendel <uw <email protected>>
 *  <email protected> Form
 *  <email protected> public
-*