summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-13 12:07:08 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-13 12:07:08 -0400
commita7fbbbfd71267f783fd8244712f7763146f3b3e2 (patch)
treea18d67363b737f243286ec8dda7aef1506800edc
parentMade bundling finished images separate from modules in backend; added metadat... (diff)
downloadingenue-a7fbbbfd71267f783fd8244712f7763146f3b3e2.tar.gz
ingenue-a7fbbbfd71267f783fd8244712f7763146f3b3e2.tar.bz2
ingenue-a7fbbbfd71267f783fd8244712f7763146f3b3e2.zip
Added data verification to config wizard API
-rw-r--r--frontend/classes/wizard_api.php102
-rw-r--r--shared/classes/1conf_build_common.php8
-rw-r--r--todo1
3 files changed, 96 insertions, 15 deletions
diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php
index a3b6fc8..c0d91b0 100644
--- a/frontend/classes/wizard_api.php
+++ b/frontend/classes/wizard_api.php
@@ -39,6 +39,14 @@ class wizard_step {
}
return $result;
}
+ public function verify() {
+ foreach ($this->data as $obj) {
+ if (!$obj->status=$obj->verify()) {
+ return false;
+ }
+ }
+ return true;
+ }
private function text($text) {
$this->data[]=new wizard_text($text);
}
@@ -72,6 +80,8 @@ abstract class wizard {
}
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;
@@ -93,6 +103,9 @@ abstract class wizard {
return false;
}
}
+ protected static function delete_opt($name) {
+ self::$configuration->delete_opt($name);
+ }
}
class wizard_text extends wizard {
protected $text;
@@ -105,6 +118,10 @@ class wizard_text extends wizard {
public function process() {
return true;
}
+ public function verify() {
+ return true;
+ }
+ public function clear() {}
}
abstract class wizard_input extends wizard {
protected $optname, $htmlname, $label;
@@ -114,7 +131,7 @@ abstract class wizard_input extends wizard {
$this->label=htmlentities($label);
}
public function output() {
- echo "$this->label ";
+ echo "$this->label: ";
}
public function process() {
global $request;
@@ -125,10 +142,17 @@ abstract class wizard_input extends wizard {
return false;
}
}
+ public function verify() {
+ return self::get_opt($this->optname)!==null;
+ }
+ public function clear() {
+ self::delete_opt($this->optname);
+ }
}
class wizard_text_input extends wizard_input {
public function output() {
parent::output();
+ echo "<input name=\"$this->htmlname\" /><br/>\n";
}
}
class wizard_select extends wizard_input {
@@ -140,18 +164,31 @@ class wizard_select extends wizard_input {
public function output() {
parent::output();
echo '<select name="'.$this->htmlname.'">'."\n";
+ $i=0;
foreach ($this->options as $val => $label) {
- echo "\t".'<option value="'.htmlentities($val).'"'.(self::opt_is($this->optname, $val)?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n";
+ echo "\t".'<option value="'.$i++.'"'.(self::opt_is($this->optname, $val)?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n";
}
echo '</select>'."\n";
}
+ public function process() {
+ 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]]);
+ return true;
+ } else return false;
+ }
+ public function verify() {
+ return ($val=self::get_opt($this->optname)) !== null && in_array($val, array_keys($this->options));
+ }
}
class wizard_radio extends wizard_select {
public function output() {
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=\"".htmlentities($val)."\"".(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."\"".(self::opt_is($this->optname, $val)?' checked="checked"':'')."\" /><label for=\"$this->htmlname-$i\">".htmlentities($label)."</label>\n";
+ $i++;
}
}
}
@@ -180,12 +217,22 @@ class wizard_checkbox_array extends wizard_input {
}
self::set_opt($this->optname, implode($this->delim, $vals));
}
- private static $opt_cache;
+ public function verify() {
+ if (($vals=self::get_opt($this->optname)) === null) return false;
+ $vals=explode($this->delim, $vals);
+ foreach ($vals as $i => $val) {
+ if (isset($this->array[$val])) {
+ unset($vals[$i]);
+ }
+ }
+ return count($vals) == 0;
+ }
protected static function opt_has($name, $val, $delim=' ') {
- if (!isset(self::$opt_cache[$name][$delim])) {
- self::$opt_cache[$name][$delim]=explode($delim, self::get_opt($name));
+ static $cache;
+ if (!isset($cache[$name][$delim])) {
+ $cache[$name][$delim]=explode($delim, self::get_opt($name));
}
- return in_array($val, self::$opt_cache[$name][$delim]);
+ return in_array($val, $cache[$name][$delim]);
}
}
class wizard_layered_checkbox_array extends wizard_checkbox_array {
@@ -209,6 +256,11 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
self::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;
+ $vals=explode($this->delim, $vals);
+ return count($this->r_verify($vals, $this->array)) == 0;
+ }
private function r_output(&$array, $depth=0, $path=null, $name=null) {
static $uid=0, $ucid=0;
$conf=&$this->metadata[0];
@@ -236,7 +288,7 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
}
echo '</div>';
echo "<script type=\"text/javascript\">\n<!--\nwlca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\n-->\n</script>\n";
- } elseif ($depth <= $this->depth) {
+ } else {
$meta=$this->metadata[$depth];
if (isset($meta['tag'])) {
echo '<'.$meta['tag'].' class="wlcae'.(isset($meta['search'])?' wlcas':'').(isset($meta['collapsed'])?' wlca'.($meta['collapsed']?'c':'C'):'').(isset($meta['class'])?' '.$meta['class']:'').'" id="'.self::b36($uid).'"'.($depth > 1 && isset($this->metadata[$depth-1]['collapsed']) && $this->metadata[$depth-1]['collapsed'] && false?' style="display: none"':'').'>';
@@ -245,15 +297,15 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
}
}
if (isset($meta['checkbox'])) {
- $hex=self::b36($ucid++);
- echo '<input type="checkbox" id="-'.$hex.'" name="'.$this->htmlname.'['.$hex.']"'.(self::opt_has($this->optname, $this->format_label($array, $meta['checkbox'], $path, $name), $this->delim)?' checked="checked"':'').' /><label for="-'.$hex.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n";
+ $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";
} elseif (isset($meta['label'])) {
echo '<span class="wlcal">'.$this->format_label($array, $meta['label'], $path, $name)."</span>\n";
}
if ($depth < $this->depth) {
foreach ($array as $name => &$val) {
$uid++;
- $this->r_output($val, $depth+1, (isset($path)?($path.$meta['delim']):'').$name, $name);
+ $this->r_output($val, $depth+1, $path.$meta['delim'].$name, $name);
}
}
if (isset($meta['tag'])) {
@@ -269,7 +321,7 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
$this->r_process($val, $depth+1, $name, $name);
}
return $r;
- } elseif ($depth <= $this->depth) {
+ } else {
$meta=$this->metadata[$depth];
if (isset($meta['checkbox'])) {
global $request;
@@ -278,11 +330,31 @@ class wizard_layered_checkbox_array extends wizard_checkbox_array {
}
$ucid++;
}
- if ($depth + 1 <= $this->depth) {
- foreach ($array as $name => &$val) {
- $this->r_process($val, $depth+1, (isset($path)?($path.$meta['delim']):'').$name, $name);
+ if ($depth < $this->depth) {
+ foreach ($array as $name => &$val)
+ $this->r_process($val, $depth+1, $path.$meta['delim'].$name, $name);
+ }
+ }
+ }
+ private function &r_verify(&$vals, &$array, $depth=0, $path=null, $name=null) {
+ if ($depth == 0) {
+ foreach($array as $name => &$val) {
+ $this->r_verify($vals, $val, $depth+1, $name, $name);
+ }
+ return $vals;
+ } else {
+ $meta=$this->metadata[$depth];
+ if (isset($meta['checkbox'])) {
+ $label=$this->format_label($array, $meta['checkbox'], $path, $name);
+ if ($i=array_search($label, $vals) !== false) {
+ unset($vals[$i]);
}
}
+ if ($depth < $this->depth) {
+ foreach($array as $name => &$val)
+ $this->r_verify($vals, $val, $depth+1, $path.$meta['delim'].$name, $name);
+ }
+ return $vals;
}
}
private function format_label(&$array, $label='%p', $path, $name) {
diff --git a/shared/classes/1conf_build_common.php b/shared/classes/1conf_build_common.php
index 4e74d09..aae1e42 100644
--- a/shared/classes/1conf_build_common.php
+++ b/shared/classes/1conf_build_common.php
@@ -88,5 +88,13 @@ abstract class conf_build_common extends sql_row_obj {
$this->opt_cache[$name]->write();
}
}
+ // Deletes the given option if it exists
+ public function delete_opt($name) {
+ $opts=$this->get_opts(true);
+ if (isset($opts[$name])) {
+ $opts[$name]->delete();
+ }
+ unset($opts[$name]);
+ }
}
?>
diff --git a/todo b/todo
index 94bf3ae..ef10f65 100644
--- a/todo
+++ b/todo
@@ -22,3 +22,4 @@ Simplify status to numeric on builds - varchar isn't necessary
Add config option to enable/disable user self-registration/invitations/admin-only invites
Move gentoo_profiles setup out of the general setup.php, allow per-module setup
Move bundler selection out of gentoo module and generalize it (switch to builds instead of configurations)
+Improve the quality of base system creation (if necessary)