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 |
|
|
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(); |
59 |
* |
* |
60 |
*/ |
*/ |
61 |
function FormWizard() { |
function FormWizard() { |
62 |
user_error(__CLASS__."::".__FUNCTION." - this class isn't done yet."); |
//user_error(__CLASS__."::".__FUNCTION__." - this class isn't done yet."); |
63 |
$this->_session_test(); |
$this->_session_test(); |
64 |
$this->set_form_name( "form_wizard" ); |
$this->set_form_name( "form_wizard" ); |
65 |
$this->set_form_action( $_SERVER["PHP_SELF"] ); |
$this->set_form_action( $_SERVER["PHP_SELF"] ); |
86 |
|
|
87 |
|
|
88 |
/** |
/** |
89 |
* This function renders the |
* This function renders the |
90 |
* FormWizard |
* FormWizard |
91 |
* |
* |
92 |
*/ |
*/ |
105 |
$container->add( $this->render_error($indent_level, $output_debug) ); |
$container->add( $this->render_error($indent_level, $output_debug) ); |
106 |
} else { |
} else { |
107 |
//there are no errors! |
//there are no errors! |
108 |
ddd( "have we visited?" ); |
debug( "have we visited?" ,null,4); |
109 |
//ddd( $_REQUEST ); |
//debug( $_REQUEST ); |
110 |
if (@$_REQUEST[FORM_VISITED] == 1) { |
if (isset($_REQUEST[FORM_VISITED]) && $_REQUEST[FORM_VISITED] == 1) { |
111 |
//looks like the form has been processed? |
//looks like the form has been processed? |
112 |
ddd( "confirmed = ".$this->_confirmed ); |
debug( "confirmed = ".$this->_confirmed ); |
113 |
ddd( "curr step = ".$this->_current_step() ); |
debug( "curr step = ".$this->_current_step() ); |
114 |
if (!$this->_confirmed && $this->_vars["on_confirm"]) { |
if (!$this->_confirmed && $this->_vars["on_confirm"]) { |
115 |
ddd("FINAL DUDE!"); |
debug("FINAL DUDE!"); |
116 |
$container->add( $this->render_confirm($indent_level, $output_debug) ); |
$container->add( $this->render_confirm($indent_level, $output_debug) ); |
117 |
} else { |
} else { |
118 |
//Looks like the action worked |
//Looks like the action worked |
119 |
$success = $this->_form_content->form_success(); |
$success = $this->_form_content->form_success(); |
120 |
|
debug("DO ACTION!"); |
121 |
if ($this->_form_success_render) { |
if ($this->_form_success_render) { |
122 |
$container->add( $this->render_form($indent_level, $output_debug, $success) ); |
$container->add( $this->render_form($indent_level, $output_debug, $success) ); |
123 |
} else { |
} else { |
157 |
//if it has been visited. Otherwise |
//if it has been visited. Otherwise |
158 |
//it just gets rendered. |
//it just gets rendered. |
159 |
if (@$_REQUEST[FORM_VISITED] == 1) { |
if (@$_REQUEST[FORM_VISITED] == 1) { |
160 |
ddd("PROCESS STEP ".$this->_current_step()); |
debug("PROCESS STEP ".$this->_current_step()); |
161 |
$this->_form_content->set_action($_REQUEST[FORM_ACTION]); |
$this->_form_content->set_action($_REQUEST[FORM_ACTION]); |
162 |
|
|
163 |
//let see if this was a confirmation page. |
//let see if this was a confirmation page. |
174 |
//need to validate the form. |
//need to validate the form. |
175 |
if ($this->can_validate()) { |
if ($this->can_validate()) { |
176 |
//looks like we should do validation |
//looks like we should do validation |
177 |
$this->do_validation(); |
if ($_REQUEST[WIZARD_ACTION] != WIZARD_PREV) { |
178 |
|
//we don't need to validate if we haven't |
179 |
|
//finished this step yet. |
180 |
|
$this->do_validation(); |
181 |
|
} |
182 |
} |
} |
183 |
if (!$this->_has_errors) { |
if (!$this->_has_errors) { |
184 |
//no errors were found |
//no errors were found |
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 |
$this->_step_visited( $current_step ); |
debug( "CURRENT STEP ".$current_step); |
|
ddd( "CURRENT STEP ".$current_step); |
|
192 |
|
|
193 |
switch ($_REQUEST[WIZARD_ACTION]) { |
switch ($_REQUEST[WIZARD_ACTION]) { |
194 |
case WIZARD_NEXT: |
case WIZARD_NEXT: |
195 |
ddd("NEXT"); |
debug("NEXT"); |
196 |
if ($current_step == $this->_vars["num_steps"]) { |
if ($current_step == $this->_vars["num_steps"]) { |
197 |
|
debug("SHOW CONFIRMATION"); |
198 |
//we need to show the confirmation |
//we need to show the confirmation |
199 |
//don't process |
//don't process |
200 |
$this->_vars["on_confirm"] = TRUE; |
$this->_vars["on_confirm"] = TRUE; |
201 |
ddd("ASS"); |
$this->_step_visited( $current_step ); |
202 |
|
$this->_set_current_step($current_step+1); |
203 |
} else { |
} else { |
204 |
|
$this->_step_visited( $current_step ); |
205 |
$this->_set_current_step($current_step+1); |
$this->_set_current_step($current_step+1); |
206 |
unset($_REQUEST[FORM_VISITED]); |
unset($_REQUEST[FORM_VISITED]); |
207 |
$this->_form_content = &$this->_steps[$this->_current_step()-1]["form"]; |
$this->_form_content = &$this->_steps[$this->_current_step()-1]["form"]; |
208 |
$this->_process_form(); |
//$this->_process_form(); |
209 |
} |
} |
210 |
break; |
break; |
211 |
|
|
212 |
case WIZARD_PREV: |
case WIZARD_PREV: |
213 |
|
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 |
ddd("PREV"); |
//$this->_process_form(); |
|
$this->_process_form(); |
|
218 |
break; |
break; |
219 |
} |
} |
220 |
} |
} |
221 |
} |
} |
222 |
} |
} |
223 |
} |
} |
224 |
ddd("bail"); |
debug("bail"); |
225 |
} |
} |
226 |
|
|
227 |
|
|
239 |
* @return string - the raw html |
* @return string - the raw html |
240 |
*/ |
*/ |
241 |
function render_confirm( $indent_level, $output_debug ) { |
function render_confirm( $indent_level, $output_debug ) { |
242 |
ddd("BUILD CONFIRM"); |
debug("BUILD CONFIRM"); |
243 |
//build the $this->_form object. |
//build the $this->_form object. |
244 |
$this->_build_form_tag(); |
$this->_build_form_tag(); |
245 |
|
|
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() { |
306 |
if (!isset($_REQUEST[WIZARD_VISITED])) { |
if (!isset($_REQUEST[WIZARD_VISITED])) { |
307 |
|
|
308 |
$this->_vars[WIZARD_ID] = uniqid("wizard_"); |
$this->_vars[WIZARD_ID] = uniqid("wizard_"); |
309 |
ddd( $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]; |
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 |
//ddd( $_SESSION ); |
//debug( $_SESSION ); |
325 |
|
|
326 |
//initialize all of the Forms |
//initialize all of the Forms |
327 |
//so they retain their data. |
//so they retain their data. |
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 |
*/ |
*/ |
409 |
*/ |
*/ |
410 |
function _build_toolbar() { |
function _build_toolbar() { |
411 |
$current_step = $this->_current_step(); |
$current_step = $this->_current_step(); |
412 |
|
xxx("current step ".$current_step); |
413 |
if ($this->_vars["on_confirm"]) { |
if ($this->_vars["on_confirm"]) { |
414 |
$current_step++; |
$current_step++; |
415 |
$step_title = "Confirmation"; |
$step_title = "Confirmation"; |
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 |
|
|
438 |
//add the confirmation step |
//add the confirmation step |
439 |
|
xxx($step_num); |
440 |
$c->add( $arrow ); |
$c->add( $arrow ); |
441 |
$c->add( $this->_build_step_image( $step_num, "Confirmation" ) ); |
$c->add( $this->_build_step_image( $step_num, "Confirmation" ) ); |
442 |
|
|
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"]) { |
if ($current_step == $this->_vars["num_steps"]+1) { |
469 |
$link = html_a("javascript:wizard_submit2('".WIZARD_NEXT."',".($current_step+1).");", |
$link = html_a("javascript:wizard_submit2('".WIZARD_FINAL."',".($current_step).");", |
|
html_img("/phphtmllib/images/wizard/next_step.png") ); |
|
|
$c->add( $link ); |
|
|
} else { |
|
|
$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 { |
474 |
|
$link = html_a("javascript:wizard_submit2('".WIZARD_NEXT."',".($current_step+1).");", |
475 |
|
html_img("/phphtmllib/images/wizard/next_step.png") ); |
476 |
|
$c->add( $link ); |
477 |
} |
} |
478 |
|
|
479 |
|
|
495 |
$title = "Step ".$step_num." "; |
$title = "Step ".$step_num." "; |
496 |
|
|
497 |
$current_step = $this->_current_step(); |
$current_step = $this->_current_step(); |
498 |
if ($this->_vars["on_confirm"]) { |
//if ($this->_vars["on_confirm"]) { |
499 |
$current_step++; |
//$current_step++; |
500 |
} |
//} |
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) || |
508 |
|
$current_step == $this->_vars["num_steps"]+1) { |
509 |
$title .= " (Completed) : ".$step_title; |
$title .= " (Completed) : ".$step_title; |
510 |
$img = html_img("/phphtmllib/images/wizard/".$step_num."_black.png", 30, 30 ,0, |
$img = html_img("/phphtmllib/images/wizard/".$step_num."_black.png", 30, 30 ,0, |
511 |
$title, NULL, $title); |
$title, NULL, $title); |
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 |
|
|
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); |
559 |
* @param int - the new step # |
* @param int - the new step # |
560 |
*/ |
*/ |
561 |
function _set_current_step($step) { |
function _set_current_step($step) { |
562 |
ddd( "SET STEP ".$step); |
debug( "SET STEP ".$step); |
563 |
$_SESSION[$this->_vars[WIZARD_ID]]["current_step"] = $step; |
$_SESSION[$this->_vars[WIZARD_ID]]["current_step"] = $step; |
564 |
} |
} |
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 |
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 |
/** |
/** |
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()) { |