blob: 31d02e91d02aa0f539507eb31af673020d803f21 (
plain)
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
|
<?php
class wizard_step extends form {
public $configuration, $module, $step, $title, $next;
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();
}
parent::output($rw, $this->get_opts());
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;
$vals=parent::process();
foreach ($vals as $name => $value) {
if ($this->elements[$name]->status) {
$this->set_opt($name, $value);
} else {
$result=$this->step;
debug('wizard', htmlentities("$name incomplete ($value)"));
}
}
return $result;
}
public function verify() {
return parent::verify($this->get_opts());
}
private function get_opts() {
$vals=array();
foreach ($this->elements as $name => &$el) {
if (!is_object($el)) continue;
$vals[$name]=$this->get_opt($name);
}
return $vals;
}
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/>';
}
}
?>
|