[phplib-dev] cvs commit From: uw (phplib-dev <email protected>)
Date: 12/11/00

From: uw
Date: Mon Dec 11 21:01:14 2000
Modified files:
      php-lib/php/form/assistant.inc

Log message:
- even more cleanup

Index: php-lib/php/form/assistant.inc
diff -u php-lib/php/form/assistant.inc:1.14 php-lib/php/form/assistant.inc:1.15
--- php-lib/php/form/assistant.inc:1.14 Mon Dec 11 19:08:56 2000
+++ php-lib/php/form/assistant.inc Mon Dec 11 21:01:12 2000
@@ -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.14 2000/12/11 18:08:56 uw Exp $
+*  <email protected> $Id: assistant.inc,v 1.15 2000/12/11 20:01:12 uw Exp $
 */
 class assistant extends panemanager {
         
@@ -380,7 +380,7 @@
         /**
         * Are all pages valid, is the requested page valid?
         *
- *  <email protected> string $page = "", if empty test all
+ *  <email protected> string
         *  <email protected> bool $ok
         *  <email protected> public
         */
@@ -398,15 +398,14 @@
                                 return false;
                         }
                         
- if (isset($this->page_errors[$p_id]))
- return $this->page_errors[$p_id];
- return false;
+ return (isset($this->page_errors[$p_id])) ? $this->page_errors[$p_id] : false;
                         
                 } else {
                 
                         foreach ($this->page_errors as $p_id => $value)
                                 if (!$valid)
                                         return false;
+
                         return true;
                         
                 }
@@ -425,9 +424,9 @@
                         return array("", "");
                 }
                 
- $len = count($this->pages)-1;
- $next = $now+1;
- $prev = $now-1;
+ $len = count($this->pages) - 1;
+ $next = $now + 1;
+ $prev = $now - 1;
                 
                 if ($next > $len)
                         $next = 1;
@@ -510,6 +509,12 @@
                 return $ok;
         } // end func updatePageErrors
         
+ /**
+ * Saves the number of the selected Page to $this->selected
+ *
+ *  <email protected> $selected, $buttunname, findPosition()
+ *  <email protected> boolean
+ */
         function findSelected() {
                 
                 $data = ("GET" == $this->method) ? &$GLOBALS["HTTP_GET_VARS"] : &$GLOBALS["HTTP_POST_VARS"];
@@ -528,19 +533,26 @@
                 }
 
                 $len = strlen($this->buttonname);
- reset($data);
- while (list($varname, $v)=each($data))
- if ($this->buttonname == substr($varname, 0, $len)) {
- if (preg_match(sprintf("/%s_([0-9]+)_[xy]{1}/i", $this->buttonname), $varname, $regs))
+ foreach ($data as $varname => $v)
+ if (substr($varname, 0, $len) == $this->buttonname) {
+ if (preg_match(sprintf("/^%s_([0-9]+)_[x|y]$/i", $this->buttonname), $varname, $regs))
                                         $this->selected = (int)$regs[1];
                                 else
- $this->selected = (int)substr($varname, $len+1);
+ $this->selected = (int)substr($varname, $len + 1);
                         }
+
                 return true;
- }
+ } // end func findSelected
+
         /**
- * Find the page that was selected by the user
+ * Find the page that was gets shown next.
+ *
+ * findSelected() searches the ID of the requested page. findPosition()
+ * 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() {
                 
@@ -559,7 +571,7 @@
                         $this->flag_specials = "exit";
                 }
                 
- if ("strict"!=$this->mode) {
+ if ("weak" == $this->mode) {
                         $this->now = $this->selected;
                         return;
                 }
@@ -578,20 +590,22 @@
         } // end func findPosition
         
         /**
- * Returns an array with the names of all pages
+ * Returns an array with the names of all pages.
+ *
         * page_id => name
+ *
         *  <email protected> array $pagenames
         *  <email protected> public
+ *  <email protected> FormError
         */
         function getPageNames() {
- if (0==count($this->pages)) {
- $this->setError(9, "assistant -> getPagesNames(), no pages in assistant");
+ if (0 == count($this->pages)) {
+ $this->exceptions[] = new FormError("assistant -> getPagesNames(), no pages in assistant", __FILE__, __LINE__);
                         return array();
                 }
                 
                 $pagenames = array();
- reset($this->pages);
- while (list($p_id, $data)=each($this->pages))
+ foreach ($this->pages as $p_id => $data)
                         $pagenames[$p_id] = $data["name"];
                 
                 return $pagenames;
@@ -599,21 +613,22 @@
                 
         /**
         * Add a page to the assistant
+ *
         *  <email protected> array $pagedata
         *  <email protected> bool $ok
         *  <email protected> public
         */
         function addPage($pagedata) {
- if (!is_array($pagedata) || 0==count($pagedata)) {
- $this->setError(2, "assistant -> addPage(), illegal function call");
+ if (!is_array($pagedata) || 0 == count($pagedata)) {
+ $this->exceptions[] = new FormError("assistant -> addPage(), illegal function call", __FILE__, __LINE__);
                         return false;
                 }
                 if (!isset($pagedata["name"]) || "" == $pagedata["name"]) {
- $this->setError(3, "assistant -> addPage(), you must specify a name for you page");
+ $this->exceptions[] = new FormError("assistant -> addPage(), you must specify a name for you page", __FILE__, __LINE__);
                         return false;
                 }
- if ("" == (string)$pagedata["object"]) {
- $this->setError(40, "assistant -> addPage(), you must specify a template object for this page");
+ if ("" == $pagedata["object"]) {
+ $this->exeptions[] = new FormError("assistant -> addPage(), you must specify a template object for this page", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -624,7 +639,7 @@
                         
                 $this->pages[] = $pagedata;
                 
- $p_id = count($this->pages)-1;
+ $p_id = count($this->pages) - 1;
                 if (!isset($this->page_errors[$p_id])) {
                         if (isset($pagedata["optional"]))
                                 $this->page_errors[$p_id] = true;
@@ -636,63 +651,58 @@
         } // end func addPage
         
         /**
- * Sets the "switching mode". If set to "strict" the
- * user must complete a form before he gets to the
+ * Sets the "switching mode".
+ *
+ * If set to "strict" the user must complete a form before he gets to the
         * next tab. If set to "weak" he's free to switch between the tabs.
         * In both cases he's not allowed to finish the assistant before
         * all forms/tabs that are not declared as optional are without errors
- *  <email protected> enum(strict|weak) $mode
+ *
+ *  <email protected> string
         *  <email protected> public
         */
         function setMode($mode) {
- if ("" == $mode) {
- $this->setError(4, "assistant -> mode(), illegal function call");
- return false;
- }
-
- if ("strict"!=$mode)
- $this->mode = "weak";
- else
- $this->mode = $mode;
-
- return true;
+ $this->mode = ("weak" == $mode) ? "weak" : "strong";
         } // end func mode
         
         /**
- * Sets the label and action for the button that finishes the form
+ * Sets the label and action for the button that finishes the assistant.
+ *
         *  <email protected> string $label
- *  <email protected> string $action, fallback on $PHP_SELF
+ *  <email protected> string $action Fallback to $PHP_SELF
         *  <email protected> bool $ok
         *  <email protected> public
+ *  <email protected> FormError
         */
- function setFinish($label, $action="") {
+ function setFinish($label, $action = "") {
                 global $PHP_SELF;
+
                 if ("" == $label) {
- $this->setError(5, "assistant -> setFinish(), illegal function call");
+ $this->exceptions[] = new FormError("assistant -> setFinish(), illegal function call", __FILE__, __LINE__);
                         return false;
                 }
- if ("" == $action)
- $action = $PHP_SELF;
-
+
                 $this->finish_button = array (
                                                                                                                 "label" => $label,
- "action" => $PHP_SELF
+ "action" => ("" == $action) ? $PHP_SELF : $action
                                                                                                         );
                 
                 return true;
         } // end func setFinish
 
         /**
- * Set the labels of some buttons
- *  <email protected> string|array $labels
+ * Set the label of a button.
+ *
+ *  <email protected> mixed
         *  <email protected> string $value
         *  <email protected> bool $ok
- *  <email protected> labels
+ *  <email protected> $labels
         *  <email protected> public
+ *  <email protected> FormError
         */
- function setLabel($labels, $value="") {
+ function setLabel($labels, $value = "") {
                 if (("" == $value && "" == $labels) || (!is_array($labels) && "" == $value)) {
- $this->setError(16, "assistant -> setLabel(), illegal function call");
+ $this->exceptions[] = new FormError("assistant -> setLabel(), illegal function call", __FILE__, __LINE__);
                         return false;
                 }
                 
@@ -704,8 +714,7 @@
                         }
                 } else {
                         
- reset($labels);
- while (list($label, $value)=each($labels))
+ foreach($labels as $label => $value)
                                 if (isset($this->labels[$label])) {
                                         $this->labels[$label] = $value;
                                         $ok = true;

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-dev-unsubscribe <email protected>
For additional commands, e-mail: phplib-dev-help <email protected>