1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?php
class wizard_step {
public $configuration, $module, $step, $title, $next, $data=array();
function __construct(&$c, $step, $noload=false) {
$this->configuration=&$c;
$this->module=new module($c->module);
$this->step=$step;
if (!$noload) {
$file=$this->module->dir."/step$step.php";
if (!is_readable($file)) {
throw_exception("$mod step $step doesn't exist!");
}
require($file);
}
$this->title=$this->module->steps[$step-1];
$this->next=isset($next)?$next:($this->step == $this->module->numsteps?null:$step+1);
}
public function output($rw=true) {
global $S;
echo "<div class=\"wizard\" id=\"step$this->step\">";
if ($rw)
echo '<form action="'.url('config/'.$this->configuration->id).'" method="post"><a style="float: right" href="'.url('config/'.$this->configuration->id.'/status').'">Status</a>';
if ($rw) {
echo '<h3>Step '.$this->step.': '.$this->title."</h3>\n";
$scale=$S['conf']['progressbar_width']/$this->module->numsteps;
echo '<img src="'.url('images/full.gif').'" style="border-left: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.$this->step*$scale.'px; height: 15px" /><img src="'.url('images/empty.gif').'" style="border-right: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.(count($this->module->steps)-$this->step)*$scale.'px; height: 15px" /><br/>'."\n";
$this->echo_buttons();
}
foreach ($this->data as $obj) {
if (is_array($obj)) {
if (!$obj[0]->status) {
echo print_warning('Please complete this field:');
}
$obj[0]->output($rw, $this->get_opt($obj[1]));
} else {
echo $obj;
}
}
if ($rw) {
echo '<br/>';
$this->echo_buttons();
}
echo '</div>'."\n";
}
public function process() {
if (!isset($_REQUEST['wizard_submit'][$this->step])) {
return $this->step;
}
$result=$this->next;
foreach ($this->data as $obj) {
if (is_array($obj)) {
$value=$obj[0]->process();
$obj[0]->status=($value !== false);
if ($obj[0]->status) {
$this->set_opt($obj[1], $value);
} else {
$result=$this->step;
debug('wizard', htmlentities("{$obj[1]} incomplete ($value)"));
}
}
}
return $result;
}
public function verify() {
foreach ($this->data as $obj) {
if (!is_array($obj)) continue;
if (($val=$this->get_opt($obj[1])) === false) {
return null;
} elseif (!($obj[0]->status=$obj[0]->verify($val))) {
return false;
}
}
return true;
}
private function text($text) {
$this->data[]=$text;
}
private function text_input($optname, $htmlname, $label) {
$this->data[]=array(new text_input($htmlname, $label), $optname);
}
private function select($optname, $htmlname, $label, $options) {
$this->data[]=array(new select($htmlname, $label, $options), $optname);
}
private function radio_array($optname, $htmlname, $label, $options) {
$this->data[]=array(new radio_array($htmlname, $label, $options), $optname);
}
private function checkbox_array($optname, $htmlname, $label, $array, $delim=' ') {
$this->data[]=array(new checkbox_array($htmlname, $label, $array, $delim=' '), $optname);
}
private function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) {
$this->data[]=array(new layered_checkbox_array($htmlname, $label, $array, $delim, $metadata), $optname);
}
private function set_opt($opt, $val) {
return $this->configuration->set_opt($opt, $val);
}
private function get_opt($opt) {
return $this->configuration->get_opt($opt);
}
private function delete_opt($name) {
return $this->configuration->delete_opt($name);
}
private function echo_buttons() {
echo ($this->step > 1?'<input type="button" onclick="window.location=\''.url('config/'.$this->configuration->id.'/'.($this->step-1)).'\'" value="Back" /> ':' ').'<input style="float: right" type="submit" name="wizard_submit['.$this->step.']" value="'.($this->step == $this->module->numsteps?'Finish':'Next').'" /><br/>';
}
}
?>
|