summaryrefslogtreecommitdiff
blob: c2b5c206143c27d8c9b0720f9e422d011a73d2b4 (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
<?php
class wizard_step extends form {
	public $configuration, $module, $step, $title, $next;
	function __construct(&$c, $step, $noload=false) {
		global $S;
		parent::__construct(url('config/'.$c->id));
		$this->configuration=&$c;
		$this->module=new module($c->module);
		$this->step=$step;
		$this->title=$this->module->steps[$step-1];
		$scale=$S['conf']['progressbar_width']/$this->module->numsteps;
		$this->rw_text('<a style="float: right" href="'.url('config/'.$this->configuration->id.'/status').'">Status</a><h3>Step '.$this->step.': '.$this->title."</h3>\n".'<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->buttons();
		if (!$noload) {
			$file=$this->module->dir."/step$step.php";
			if (!is_readable($file)) {
				throw_exception("$mod step $step doesn't exist!");
			}
			require($file);
		}
		$this->next=isset($next)?$next:($this->step == $this->module->numsteps?null:$step+1);
	}
	public function output($rw=true) {
		if ($rw) { // We're assuming that one page never gets output rw twice in one page load
			$this->rw_text('<br/>');
			$this->buttons();
		}
		echo "<div class=\"wizard\" id=\"step$this->step\">";
		parent::output($this->get_opts(), $rw);
		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) {
			$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 buttons() {
		$this->rw_text(($this->step > 1?'<input type="button" onclick="window.location=\''.url('config/'.$this->configuration->id.'/'.($this->step-1)).'\'" value="Back" /> ':'&nbsp;').'<input style="float: right" type="submit" name="wizard_submit['.$this->step.']" value="'.($this->step == $this->module->numsteps?'Finish':'Next').'" /><br/>');
	}
}
?>