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

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

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

revision 1.2 by jonen, Thu May 6 16:27:23 2004 UTC revision 1.3 by jonen, Thu Aug 11 14:09:26 2005 UTC
# Line 4  Line 4 
4   *   *
5   * $Id$   * $Id$
6   *   *
7   * @author Walter A. Boring IV <waboring@buildabetterweb.com>   * @author Walter A. Boring IV <waboring@newsblob.com>
8   * @package phpHtmlLib   * @package phpHtmlLib
9   * @subpackage FormProcessing   * @subpackage FormProcessing
10   *   *
11   * @copyright LGPL - See LICENCE   * @copyright LGPL - See LICENCE
12     * @todo Finish this.  It doesn't work now.
13   *   *
14   */   */
15    
# Line 23  define("WIZARD_PREV", "PREV"); Line 24  define("WIZARD_PREV", "PREV");
24  define("WIZARD_JUMP", "JUMP");  define("WIZARD_JUMP", "JUMP");
25  define("WIZARD_FINAL", "FINAL");  define("WIZARD_FINAL", "FINAL");
26    
27    
28    /**
29     * This is a magic container that allows you
30     * to chain together multiple FormContent objects
31     * to automatically create a Wizard process.
32     *
33     * @package phpHtmlLib
34     * @subpackage FormProcessing
35     *
36     * @todo Finish this.  It doesn't work now.
37     */
38  class FormWizard extends FormProcessor {  class FormWizard extends FormProcessor {
39    
40      /**      /**
41       * This holds the array of       * This holds the array of
42       * step objects for the       * step objects for the
43       * wizard       * wizard
44       */       */
45      var $_steps = array();      var $_steps = array();
# Line 74  class FormWizard extends FormProcessor { Line 86  class FormWizard extends FormProcessor {
86    
87    
88      /**      /**
89       * This function renders the       * This function renders the
90       * FormWizard       * FormWizard
91       *       *
92       */       */
# Line 175  class FormWizard extends FormProcessor { Line 187  class FormWizard extends FormProcessor {
187                      if (!$this->_has_errors) {                      if (!$this->_has_errors) {
188                          //ok this step validated.  lets display the next.                          //ok this step validated.  lets display the next.
189                          //mark this step as visited                          //mark this step as visited
190                          $current_step = $this->_current_step();                                                  $current_step = $this->_current_step();
191                          debug( "CURRENT STEP ".$current_step);                          debug( "CURRENT STEP ".$current_step);
192    
193                          switch ($_REQUEST[WIZARD_ACTION]) {                          switch ($_REQUEST[WIZARD_ACTION]) {
194                          case WIZARD_NEXT:                                                                                case WIZARD_NEXT:
195                              debug("NEXT");                              debug("NEXT");
196                              if ($current_step == $this->_vars["num_steps"]) {                              if ($current_step == $this->_vars["num_steps"]) {
197                                  debug("SHOW CONFIRMATION");                                  debug("SHOW CONFIRMATION");
# Line 201  class FormWizard extends FormProcessor { Line 213  class FormWizard extends FormProcessor {
213                              debug("PREV");                              debug("PREV");
214                              $this->_set_current_step($current_step-1);                              $this->_set_current_step($current_step-1);
215                              unset($_REQUEST[FORM_VISITED]);                              unset($_REQUEST[FORM_VISITED]);
216                              $this->_form_content = &$this->_steps[$this->_current_step()-1]["form"];                                                          $this->_form_content = &$this->_steps[$this->_current_step()-1]["form"];
217                              //$this->_process_form();                              //$this->_process_form();
218                              break;                              break;
219                          }                          }
# Line 282  class FormWizard extends FormProcessor { Line 294  class FormWizard extends FormProcessor {
294    
295    
296      /**      /**
297       * This function initializes all of the fields we       * This function initializes all of the fields we
298       * need to keep track of for the internal state       * need to keep track of for the internal state
299       * of the wizard.  It also walks each of the       * of the wizard.  It also walks each of the
300       * step FormContent objects and initializes them.       * step FormContent objects and initializes them.
301       *       *
302       * We save some of the state of the wizard in       * We save some of the state of the wizard in
303       * the session.       * the session.
304       */       */
305      function _init() {      function _init() {
# Line 296  class FormWizard extends FormProcessor { Line 308  class FormWizard extends FormProcessor {
308              $this->_vars[WIZARD_ID] = uniqid("wizard_");              $this->_vars[WIZARD_ID] = uniqid("wizard_");
309              //debug( $this->_vars );              //debug( $this->_vars );
310    
311              $this->_init_session();                          $this->_init_session();
312              $this->_vars["to_step"] = 2;              $this->_vars["to_step"] = 2;
313          } else {          } else {
314              $this->_vars[WIZARD_ID] = $_REQUEST[WIZARD_ID];              $this->_vars[WIZARD_ID] = $_REQUEST[WIZARD_ID];
# Line 307  class FormWizard extends FormProcessor { Line 319  class FormWizard extends FormProcessor {
319              //    $this->_vars["to_step"] = WIZARD_FINAL;              //    $this->_vars["to_step"] = WIZARD_FINAL;
320              //} else {              //} else {
321              //    $this->_vars["to_step"] = WIZARD_NEXT;              //    $this->_vars["to_step"] = WIZARD_NEXT;
322              //}                                      //}
323          }          }
324          //debug( $_SESSION );          //debug( $_SESSION );
325    
# Line 322  class FormWizard extends FormProcessor { Line 334  class FormWizard extends FormProcessor {
334      /**      /**
335       * This function sets the _form_content       * This function sets the _form_content
336       * object for the current step we are operating on.       * object for the current step we are operating on.
337       * The parent FormProcessor needs this object set       * The parent FormProcessor needs this object set
338       * in order to process the step correctly.       * in order to process the step correctly.
339       *       *
340       */       */
# Line 413  class FormWizard extends FormProcessor { Line 425  class FormWizard extends FormProcessor {
425          $step_num = 1;          $step_num = 1;
426          foreach( $this->_steps as $step ) {          foreach( $this->_steps as $step ) {
427              $c->add( $this->_build_step_image( $step_num, $step["title"] ) );              $c->add( $this->_build_step_image( $step_num, $step["title"] ) );
428                
429              if ($step_num != $this->_vars["num_steps"]) {              if ($step_num != $this->_vars["num_steps"]) {
430                  $arrow = html_img("/phphtmllib/images/wizard/arrow.png");                  $arrow = html_img("/phphtmllib/images/wizard/arrow.png");
431                  $arrow->set_style("vertical-align:super");                  $arrow->set_style("vertical-align:super");
432                  $c->add( $arrow );                  $c->add( $arrow );
433              }              }
434                
435              $step_num++;              $step_num++;
436          }          }
437    
# Line 448  class FormWizard extends FormProcessor { Line 460  class FormWizard extends FormProcessor {
460          $c->set_style("padding-top: 5px;");          $c->set_style("padding-top: 5px;");
461    
462          if ($current_step != 1) {          if ($current_step != 1) {
463              $link = html_a("javascript:wizard_submit2('".WIZARD_PREV."',".($current_step-1).");",              $link = html_a("javascript:wizard_submit2('".WIZARD_PREV."',".($current_step-1).");",
464                             html_img("/phphtmllib/images/wizard/previous_step.png"));                             html_img("/phphtmllib/images/wizard/previous_step.png"));
465              $c->add( $link );              $c->add( $link );
466          }          }
467            
468          if ($current_step == $this->_vars["num_steps"]+1) {          if ($current_step == $this->_vars["num_steps"]+1) {
469              $link = html_a("javascript:wizard_submit2('".WIZARD_FINAL."',".($current_step).");",              $link = html_a("javascript:wizard_submit2('".WIZARD_FINAL."',".($current_step).");",
470                             html_img("/phphtmllib/images/wizard/finish_steps.png") );                             html_img("/phphtmllib/images/wizard/finish_steps.png") );
471    
472              $c->add( _HTML_SPACE, _HTML_SPACE, $link);                          $c->add( _HTML_SPACE, _HTML_SPACE, $link);
473          } else {          } else {
474              $link = html_a("javascript:wizard_submit2('".WIZARD_NEXT."',".($current_step+1).");",              $link = html_a("javascript:wizard_submit2('".WIZARD_NEXT."',".($current_step+1).");",
475                             html_img("/phphtmllib/images/wizard/next_step.png") );                             html_img("/phphtmllib/images/wizard/next_step.png") );
476              $c->add( $link );              $c->add( $link );
477          }          }
# Line 489  class FormWizard extends FormProcessor { Line 501  class FormWizard extends FormProcessor {
501    
502          if ($step_num == $current_step) {          if ($step_num == $current_step) {
503              $title .= " (Current) : ".$step_title;              $title .= " (Current) : ".$step_title;
504              $img = html_img("/phphtmllib/images/wizard/".$step_num."_red.png", 30, 30, 0,              $img = html_img("/phphtmllib/images/wizard/".$step_num."_red.png", 30, 30, 0,
505                              $title, NULL, $title);                              $title, NULL, $title);
506    
507          } else if ($this->_is_step_visited($step_num) ||          } else if ($this->_is_step_visited($step_num) ||
# Line 503  class FormWizard extends FormProcessor { Line 515  class FormWizard extends FormProcessor {
515              $img = html_img("/phphtmllib/images/wizard/".$step_num."_gray.png", 30,30,0,              $img = html_img("/phphtmllib/images/wizard/".$step_num."_gray.png", 30,30,0,
516                              $title, NULL, $title);                              $title, NULL, $title);
517          }          }
518            
519          return $img;          return $img;
520      }      }
521    
# Line 514  class FormWizard extends FormProcessor { Line 526  class FormWizard extends FormProcessor {
526      /*****************************************/      /*****************************************/
527    
528      /**      /**
529       * This method initializes the session       * This method initializes the session
530       * variable that we use       * variable that we use
531       *       *
532       */       */
533      function _init_session() {      function _init_session() {
534          //create a unique id for this wizard          //create a unique id for this wizard
535          //so we can have multple wizards          //so we can have multple wizards
536          //running per session.          //running per session.
537          $_SESSION[$this->_vars[WIZARD_ID]] = array();          $_SESSION[$this->_vars[WIZARD_ID]] = array();
538          $_SESSION[$this->_vars[WIZARD_ID]];          $_SESSION[$this->_vars[WIZARD_ID]];
539          $this->_set_current_step(1);          $this->_set_current_step(1);
540            
541          //mark all steps as NOT visited          //mark all steps as NOT visited
542          for ($i=0; $i<=$this->_vars["num_steps"]-1; $i++) {          for ($i=0; $i<=$this->_vars["num_steps"]-1; $i++) {
543              $this->_step_visited($i, FALSE);              $this->_step_visited($i, FALSE);
# Line 553  class FormWizard extends FormProcessor { Line 565  class FormWizard extends FormProcessor {
565    
566    
567      /**      /**
568       * This sets the state variable for the       * This sets the state variable for the
569       * step to let us know it has been visited or not       * step to let us know it has been visited or not
570       *       *
571       * @param int - the step to mark       * @param int - the step to mark
# Line 574  class FormWizard extends FormProcessor { Line 586  class FormWizard extends FormProcessor {
586              return $_SESSION[$this->_vars[WIZARD_ID]]["visited_steps"][$step_num];              return $_SESSION[$this->_vars[WIZARD_ID]]["visited_steps"][$step_num];
587          } else {          } else {
588              return FALSE;              return FALSE;
589          }                  }
590      }      }
591    
592      /**      /**
# Line 589  class FormWizard extends FormProcessor { Line 601  class FormWizard extends FormProcessor {
601    
602      /**      /**
603       * This ensures that we have sessions started       * This ensures that we have sessions started
604       *       *
605       */       */
606      function _session_test() {      function _session_test() {
607          if (!session_id()) {          if (!session_id()) {

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

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