summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/classes/wizard_api.php')
-rw-r--r--frontend/classes/wizard_api.php146
1 files changed, 76 insertions, 70 deletions
diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php
index 48fe637..381a267 100644
--- a/frontend/classes/wizard_api.php
+++ b/frontend/classes/wizard_api.php
@@ -1,30 +1,36 @@
<?php
class wizard_step {
- var $module, $step, $title, $next, $data=array();
- function __construct($mod, $step) {
- $this->module=new module($mod);
+ 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;
- $file=$this->module->dir."/step$step.php";
- if (!is_readable($file)) {
- throw_exception("$mod step $step doesn't exist!");
+ if (!$noload) {
+ $file=$this->module->dir."/step$step.php";
+ if (!is_readable($file)) {
+ throw_exception("$mod step $step doesn't exist!");
+ }
+ require($file);
}
- require($file);
- $this->title="Step $step/{$this->module->steps}".($title?" - $title":'');
- $this->next=isset($next)?$next:($this->step == $this->module->steps?null:$step+1);
+ $this->title=$this->module->steps[$step-1];
+ $this->next=isset($next)?$next:($this->step == $this->module->numsteps?null:$step+1);
}
public function output() {
global $conf;
- echo "<h3>$this->title</h3>\n";
- $scale=$conf['progressbar_width']/$this->module->steps;
- 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: '.($this->module->steps-$this->step)*$scale.'px; height: 15px" /><br/>'."\n";
- echo '<form action="'.url('config/'.wizard::$configuration->id).'" method="post">';
+ echo "<div class=\"wizard\" id=\"step$this->step\">";
+ echo '<form action="'.url('config/'.$this->configuration->id).'" method="post"><a style="float: right" href="'.url('config/'.$this->configuration->id.'/status').'">Status</a><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 (!$obj->status) {
echo print_warning('Please complete this field.');
}
$obj->output();
}
- echo '<br/><input type="submit" name="wizard_submit['.$this->step.']" value="Continue" />'."\n";
+ echo '<br/>';
+ $this->echo_buttons();
+ echo '</div>'."\n";
}
public function process() {
global $request;
@@ -41,75 +47,72 @@ class wizard_step {
}
public function verify() {
foreach ($this->data as $obj) {
- if (!$obj->status=$obj->verify()) {
- return false;
+ if (!($obj->status=$obj->verify())) {
+ return $obj->status;
}
}
return true;
}
private function text($text) {
- $this->data[]=new wizard_text($text);
+ $this->data[]=new wizard_text($this->configuration, $text);
}
private function text_input($optname, $htmlname, $label) {
- $this->data[]=new wizard_text_input($optname, $htmlname, $label);
+ $this->data[]=new wizard_text_input($this->configuration, $optname, $htmlname, $label);
}
private function select($optname, $htmlname, $label, $options) {
- $this->data[]=new wizard_select($optname, $htmlname, $label, $options);
+ $this->data[]=new wizard_select($this->configuration, $optname, $htmlname, $label, $options);
}
private function radio($optname, $htmlname, $label, $options) {
- $this->data[]=new wizard_radio($optname, $htmlname, $label, $options);
+ $this->data[]=new wizard_radio($this->configuration, $optname, $htmlname, $label, $options);
}
private function checkbox_array($optname, $htmlname, $label, $array, $delim=' ') {
- $this->data[]=new wizard_checkbox_array($optname, $htmlname, $label, $array, $delim=' ');
+ $this->data[]=new wizard_checkbox_array($this->configuration, $optname, $htmlname, $label, $array, $delim=' ');
}
private function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) {
- $this->data[]=new wizard_layered_checkbox_array($optname, $htmlname, $label, $array, $delim, $metadata);
+ $this->data[]=new wizard_layered_checkbox_array($this->configuration, $optname, $htmlname, $label, $array, $delim, $metadata);
}
private function query($q) {
return $GLOBALS['S']['pdo']->query($q);
}
private function get_opt($opt) {
- return wizard::get_opt($opt);
+ return $this->configuration->get_opt($opt);
+ }
+ private function echo_buttons() {
+ echo '<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="Next" /><br/>';
}
}
abstract class wizard {
- public $status=true;
- public static $configuration;
- public static function set_configuration(&$c) {
- self::$configuration=&$c;
+ public $status=true, $configuration;
+ function __construct(&$c) {
+ $this->configuration=&$c;
}
abstract public function output();
abstract public function process();
abstract public function verify();
abstract public function clear();
- public static function get_opt($name) {
- $opts=self::$configuration->get_opts();
- return isset($opts[$name])?$opts[$name]:null;
+ protected function get_opt($name) {
+ return $this->configuration->get_opt($name);
}
- protected static function set_opt($name, $val) {
+ protected function set_opt($name, $val) {
debug('wizard', "$name=$val");
if (substr($name, 0, 1) == ':') {
- self::$configuration->$name=$val;
- self::$configuration->write();
+ $this->configuration->$name=$val;
+ $this->configuration->write();
} else {
- self::$configuration->set_opt($name, $val);
+ $this->configuration->set_opt($name, $val);
}
}
- protected static function opt_is($name, $val) {
- $opts=self::$configuration->get_opts();
- if (isset($opts[$name]) && $opts[$name] === $val) {
- return true;
- } else {
- return false;
- }
+ protected function opt_is($name, $val) {
+ return $this->configuration->opt_is($name, $val);
}
- protected static function delete_opt($name) {
- self::$configuration->delete_opt($name);
+ protected function delete_opt($name) {
+ return $this->configuration->delete_opt($name);
}
}
class wizard_text extends wizard {
protected $text;
- function __construct($text) {
+ function __construct(&$c, $text) {
+ parent::__construct($c);
$this->text=$text;
}
public function output() {
@@ -125,7 +128,8 @@ class wizard_text extends wizard {
}
abstract class wizard_input extends wizard {
protected $optname, $htmlname, $label;
- function __construct($optname, $htmlname, $label) {
+ function __construct(&$c, $optname, $htmlname, $label) {
+ parent::__construct($c);
$this->optname=$optname;
$this->htmlname=htmlentities($htmlname);
$this->label=htmlentities($label);
@@ -143,10 +147,10 @@ abstract class wizard_input extends wizard {
}
}
public function verify() {
- return self::get_opt($this->optname)!==null;
+ return $this->get_opt($this->optname)!==null;
}
public function clear() {
- self::delete_opt($this->optname);
+ return $this->delete_opt($this->optname);
}
}
class wizard_text_input extends wizard_input {
@@ -157,8 +161,8 @@ class wizard_text_input extends wizard_input {
}
class wizard_select extends wizard_input {
private $options;
- function __construct($optname, $htmlname, $label, $options) {
- parent::__construct($optname, $htmlname, $label);
+ function __construct(&$c, $optname, $htmlname, $label, $options) {
+ parent::__construct($c, $optname, $htmlname, $label);
$this->options=$options;
}
public function output() {
@@ -166,7 +170,7 @@ class wizard_select extends wizard_input {
echo '<select name="'.$this->htmlname.'">'."\n";
$i=0;
foreach ($this->options as $val => $label) {
- echo "\t".'<option value="'.$i++.'"'.(self::opt_is($this->optname, $val)?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n";
+ echo "\t".'<option value="'.$i++.'"'.($this->opt_is($this->optname, $val)?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n";
}
echo '</select>'."\n";
}
@@ -174,12 +178,13 @@ class wizard_select extends wizard_input {
global $request;
$vals=array_keys($this->options);
if (isset($request[$this->htmlname]) && is_numeric($request[$this->htmlname]) && isset($vals[$request[$this->htmlname]])) {
- self::set_opt($this->optname, $vals[$request[$this->htmlname]]);
+ $this->set_opt($this->optname, $vals[$request[$this->htmlname]]);
return true;
} else return false;
}
public function verify() {
- return ($val=self::get_opt($this->optname)) !== null && in_array($val, array_keys($this->options));
+ if (($val=$this->get_opt($this->optname)) === null) return null;
+ return isset($this->options[$val]);
}
}
class wizard_radio extends wizard_select {
@@ -187,15 +192,15 @@ class wizard_radio extends wizard_select {
echo "$this->label:<br/>\n";
$i=0;
foreach ($this->options as $val => $label) {
- echo "\t<input type=\"radio\" id=\"$this->htmlname-$i\" name=\"$this->htmlname\" value=\"".$i."\"".(self::opt_is($this->optname, $val)?' checked="checked"':'')."\" /><label for=\"$this->htmlname-$i\">".htmlentities($label)."</label>\n";
+ echo "\t<input type=\"radio\" id=\"$this->htmlname-$i\" name=\"$this->htmlname\" value=\"".$i."\"".($this->opt_is($this->optname, $val)?' checked="checked"':'')."\" /><label for=\"$this->htmlname-$i\">".htmlentities($label)."</label>\n";
$i++;
}
}
}
class wizard_checkbox_array extends wizard_input {
protected $array;
- function __construct($optname, $htmlname, $label, $array, $delim=' ') {
- parent::__construct($optname, $htmlname, $label);
+ function __construct(&$c, $optname, $htmlname, $label, $array, $delim=' ') {
+ parent::__construct($c, $optname, $htmlname, $label);
$this->array=$array;
$this->delim=$delim;
}
@@ -203,22 +208,22 @@ class wizard_checkbox_array extends wizard_input {
echo "$this->label:<br/>\n";
$i=0;
foreach ($this->array as $val => $label) {
- echo "\t<input type=\"checkbox\" id=\"$this->htmlname-$i\" name=\"$this->htmlname[$i]\"".(self::opt_has($this->optname, $val, $this->delim)?' checked="checked"':'')." /><label for=\"$this->htmlname-$i\">$label</label><br/>\n";
+ echo "\t<input type=\"checkbox\" id=\"$this->htmlname-$i\" name=\"$this->htmlname[$i]\"".($this->opt_has($this->optname, $val, $this->delim)?' checked="checked"':'')." /><label for=\"$this->htmlname-$i\">$label</label><br/>\n";
$i++;
}
}
public function process() {
global $request;
$val=array();
- // FIXME we're assuming that array_keys order is determinate and the same as the foreach in output()
$vals=array_keys($this->array);
foreach ($request[$this->htmlname] as $i) {
$val[]=$vals[$i];
}
- self::set_opt($this->optname, implode($this->delim, $vals));
+ $this->set_opt($this->optname, implode($this->delim, $vals));
}
public function verify() {
- if (($vals=self::get_opt($this->optname)) === null) return false;
+ if (($vals=$this->get_opt($this->optname)) === null) return null;
+ if (strlen($vals) == 0) return true;
$vals=explode($this->delim, $vals);
foreach ($vals as $i => $val) {
if (isset($this->array[$val])) {
@@ -227,18 +232,18 @@ class wizard_checkbox_array extends wizard_input {
}
return count($vals) == 0;
}
- protected static function opt_has($name, $val, $delim=' ') {
- static $cache;
- if (!isset($cache[$name][$delim])) {
- $cache[$name][$delim]=explode($delim, self::get_opt($name));
+ private static $opt_cache;
+ protected function opt_has($name, $val, $delim=' ') {
+ if (!isset(self::$opt_cache[$name][$delim])) {
+ self::$opt_cache[$name][$delim]=explode($delim, $this->get_opt($name));
}
- return in_array($val, $cache[$name][$delim]);
+ return in_array($val, self::$opt_cache[$name][$delim]);
}
}
class wizard_layered_checkbox_array extends wizard_checkbox_array {
private $depth=0, $path_delims=array('', '/', '-');
- function __construct($optname, $htmlname, $label, &$array, $delim=' ', $metadata) {
- parent::__construct($optname, $htmlname, $label, &$array, $delim);
+ function __construct(&$c, $optname, $htmlname, $label, &$array, $delim=' ', $metadata) {
+ parent::__construct($c, $optname, $htmlname, $label, &$array, $delim);
$this->metadata=$metadata;
for ($i=current(&$array); is_array($i); $i=current($i)) $this->depth++;
global $S;
@@ -253,11 +258,12 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
$this->r_output($this->array);
}
public function process() {
- self::set_opt($this->optname, implode($this->delim, $this->r_process($this->array)));
+ $this->set_opt($this->optname, implode($this->delim, $this->r_process($this->array)));
return true;
}
public function verify() {
- if (($vals=self::get_opt($this->optname)) === null) return false;
+ if (($vals=$this->get_opt($this->optname)) === null) return null;
+ if (strlen($vals) == 0) return true;
$vals=explode($this->delim, $vals);
$r=$this->r_verify($vals, $this->array);
debug('wlca', 'got results: '.implode(' ',$r));
@@ -288,7 +294,7 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
$this->r_output($val, $depth+1, $name, $name);
$uid++;
}
- echo '</div>';
+ echo '<h3 style="display: none">No results</h3></div>';
echo "<script type=\"text/javascript\">\n<!--\nif (wlca_show_checked(document.getElementById('{$conf['id']}'), 0, $this->depth) == 0) wlca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\n-->\n</script>\n";
} else {
$meta=$this->metadata[$depth];
@@ -300,7 +306,7 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
}
if (isset($meta['checkbox'])) {
$enc=self::b36($ucid++);
- echo '<input type="checkbox" id="-'.$enc.'" name="'.$this->htmlname.'['.$enc.']"'.(self::opt_has($this->optname, $this->format_label($array, $meta['checkbox'], $path, $name), $this->delim)?' checked="checked"':'').' /><label for="-'.$enc.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n";
+ echo '<input type="checkbox" id="-'.$enc.'" name="'.$this->htmlname.'['.$enc.']"'.($this->opt_has($this->optname, $this->format_label($array, $meta['checkbox'], $path, $name), $this->delim)?' checked="checked"':'').' /><label for="-'.$enc.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n";
} elseif (isset($meta['label'])) {
echo '<span class="wlcal">'.$this->format_label($array, $meta['label'], $path, $name)."</span>\n";
}