summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/classes/wizard.php')
-rw-r--r--frontend/classes/wizard.php110
1 files changed, 110 insertions, 0 deletions
diff --git a/frontend/classes/wizard.php b/frontend/classes/wizard.php
new file mode 100644
index 0000000..4d0d7b7
--- /dev/null
+++ b/frontend/classes/wizard.php
@@ -0,0 +1,110 @@
+<?php
+class wizard_step {
+ var $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 $conf;
+ 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=$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() {
+ global $request;
+ 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 query($q) {
+ return $GLOBALS['S']['pdo']->query($q);
+ }
+ 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" /> ':'&nbsp;').'<input style="float: right" type="submit" name="wizard_submit['.$this->step.']" value="'.($this->step == $this->module->numsteps?'Finish':'Next').'" /><br/>';
+ }
+}
+?>