diff options
-rw-r--r-- | frontend/classes/forms.php | 284 | ||||
-rw-r--r-- | frontend/classes/wizard.php | 110 | ||||
-rw-r--r-- | frontend/classes/wizard_api.php | 429 | ||||
-rw-r--r-- | frontend/css/lca.css (renamed from frontend/css/wlca.css) | 8 | ||||
-rw-r--r-- | frontend/js/lca.js (renamed from frontend/js/wlca.js) | 54 | ||||
-rw-r--r-- | frontend/modules/gentoo/step4.php | 2 | ||||
-rw-r--r-- | shared/classes/1conf_build_common.php | 6 | ||||
-rw-r--r-- | shared/classes/gentoo_profile.php | 6 | ||||
-rw-r--r-- | todo | 1 |
9 files changed, 433 insertions, 467 deletions
diff --git a/frontend/classes/forms.php b/frontend/classes/forms.php new file mode 100644 index 0000000..39843e9 --- /dev/null +++ b/frontend/classes/forms.php @@ -0,0 +1,284 @@ +<?php +abstract class form_element { + protected $htmlname, $label; + public $status=true; + function __construct($htmlname, $label) { + $this->htmlname=htmlentities($htmlname); + $this->label=htmlentities($label); + } + public function output($rw=true, $val=false) { + echo "$this->label: "; + } + public function process() { + global $request; + return isset($request[$this->htmlname])?$request[$this->htmlname]:false; + } + public function verify($val) { + return $val !== false; + } +} +class text_input extends form_element { + public function output($rw=true, $val=false) { + parent::output($rw, $val); + echo $rw?"<input name=\"$this->htmlname\"".($val===false?'':'value="'.htmlentities($val).'"').' />':($val===false?'':htmlentities($val)); + echo "<br/>\n"; + } +} +class select extends form_element { + private $options; + function __construct($htmlname, $label, $options) { + parent::__construct($htmlname, $label); + $this->options=$options; + } + public function output($rw=true, $val=false) { + parent::output($rw, $val); + if ($rw) { + echo '<select name="'.$this->htmlname.'">'."\n"; + $i=0; + } + foreach ($this->options as $value => $label) { + if ($rw) + echo "\t".'<option value="'.$i++.'"'.($value == $val?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n"; + elseif ($value == $val) + echo htmlentities($label); + } + if ($rw) + echo '</select>'; + echo "<br/>\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]])) { + return $vals[$request[$this->htmlname]]; + } else return false; + } + public function verify($val) { + return isset($this->options[$val]); + } +} +class radio_array extends select { + public function output($rw=true, $val=false) { + if (!$rw) return parent::output($rw, $val); + echo "$this->label:<br/>\n"; + $i=0; + foreach ($this->options as $value => $label) { + echo "\t<input type=\"radio\" id=\"$this->htmlname-$i\" name=\"$this->htmlname\" value=\"".$i."\"".($value == $val?' checked="checked"':'')."\" /><label for=\"$this->htmlname-$i\">".htmlentities($label)."</label><br/>\n"; + $i++; + } + } +} +class checkbox_array extends form_element { + protected $array; + function __construct($htmlname, $label, $array, $delim=' ') { + parent::__construct($htmlname, $label); + $this->array=$array; + $this->delim=$delim; + } + public function output($rw=true, $val=false) { + $this->set_val($val); + if (strlen($this->label)) + echo "<b>$this->label:</b><br/>\n"; + $i=0; + foreach ($this->array as $value => $label) { + $label=htmlentities($label); + if ($rw) + echo "\t<input type=\"checkbox\" id=\"$this->htmlname-$i\" name=\"$this->htmlname[$i]\"".($this->val_has($value)?' checked="checked"':'')." /><label for=\"$this->htmlname-$i\">$label</label><br/>\n"; + elseif ($this->val_has($value)) + echo "$label<br/>\n"; + $i++; + } + } + public function process() { + global $request; + $val=array(); + if (isset($request[$this->htmlname])) { + $vals=array_keys($this->array); + foreach ($request[$this->htmlname] as $i => $null) { + $val[]=$vals[$i]; + } + } + return implode($this->delim, $val); + } + public function verify($val) { + if ($val === false) return false; + if (strlen($val) == 0) return true; + $val=explode($this->delim, $val); + foreach ($val as $i => $value) { + if (isset($this->array[$value])) { + unset($val[$i]); + } + } + return count($val) == 0; + } + private $vals; + protected function set_val($val) { + $this->vals=explode($this->delim, $val); + } + protected function val_has($needle) { + return in_array($needle, $this->vals); + } +} +class layered_checkbox_array extends checkbox_array { + private $depth=0, $path_delims=array('', '/', '-'); + function __construct($htmlname, $label, &$array, $delim=' ', $metadata) { + parent::__construct($htmlname, $label, &$array, $delim); + $this->metadata=$metadata; + for ($i=current(&$array); is_array($i); $i=current($i)) $this->depth++; + global $S; + if (!in_array('lca', $S['scripts'])) { + $S['scripts'][]='lca'; + } + } + public function output($rw=true, $val=false) { + $this->set_val($val); + if ($this->label) { + echo '<h4>'.htmlentities($this->label).'</h4>'; + } + if ($rw) + $this->r_output($this->array); + else + $this->r_ro_output($this->array); + } + public function process() { + return implode($this->delim, $this->r_process($this->array)); + } + public function verify($val) { + if ($val === false) return false; + if (strlen($val) == 0) return true; + $val=explode($this->delim, $val); + $r=$this->r_verify($val, $this->array); + debug('lca', 'verify leftovers: '.implode(' ',$r)); + return count($r) == 0; + } + private function r_output(&$array, $depth=0, $path=null, $name=null) { + static $uid=0, $ucid=0; + $conf=&$this->metadata[0]; + if ($depth == 0) { + $search=$autosize=0; + for ($i=1; $i<count($this->metadata); $i++) { + $m=&$this->metadata[$i]; + if (isset($m['tag'])) { + $autosize++; + } + if (isset($m['search'])) { + $search++; + } + } + if ($search) { + if (!isset($conf['id'])) { + $conf['id']=self::b36($uid++); + } + echo 'Search: <input id="'.$conf['id'].'-q" onkeyup="lca_search(this.value, document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$conf['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:lca_show_checked(document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; + } + echo '<div class="lca'.(isset($conf['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$conf['id'].'">'."\n"; + foreach ($array as $name => &$val) { + $this->r_output($val, $depth+1, $name, $name); + $uid++; + } + echo '<h3 style="display: none">No results</h3></div>'; + echo "<script type=\"text/javascript\">\n<!--\nif (lca_show_checked(document.getElementById('{$conf['id']}'), 0, $this->depth) == 0) lca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\n-->\n</script>\n"; + } else { + $meta=$this->metadata[$depth]; + if (isset($meta['tag'])) { + echo '<'.$meta['tag'].' class="lcae'.(isset($meta['search'])?' lcas':'').(isset($meta['collapsed'])?' lca'.($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"':'').'>'; + if (isset($meta['collapsed']) && $depth < $this->depth) { + echo '<a href="javascript:lcat(\''.self::b36($uid).'\')">±</a>'; + } + } + if (isset($meta['checkbox'])) { + $enc=self::b36($ucid++); + echo '<input type="checkbox" id="-'.$enc.'" name="'.$this->htmlname.'['.$enc.']"'.($this->val_has($this->format_label($array, $meta['checkbox'], $path, $name))?' checked="checked"':'').' /><label for="-'.$enc.'">'.$this->format_label($array, $meta['label'], $path, $name).'</label>'."\n"; + } elseif (isset($meta['label'])) { + echo '<span class="lcal">'.$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, $path.$meta['delim'].$name, $name); + } + } + if (isset($meta['tag'])) { + echo '</'.$meta['tag'].">\n"; + } + } + } + private function r_process(&$array, $depth=0, $path=null, $name=null) { + static $ucid=0, $r; + if ($depth == 0) { + $r=array(); + foreach ($array as $name => &$val) { + $this->r_process($val, $depth+1, $name, $name); + } + return $r; + } else { + $meta=$this->metadata[$depth]; + if (isset($meta['checkbox'])) { + global $request; + if (isset($request[$this->htmlname][self::b36($ucid)])) { + $r[]=$this->format_label($array, $meta['checkbox'], $path, $name); + } + $ucid++; + } + 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 r_ro_output(&$array, $depth=0, $path=null, $name=null) { + if ($depth == 0) { + foreach ($array as $name => &$val) { + $this->r_ro_output($val, $depth+1, $name, $name); + } + } else { + $meta=$this->metadata[$depth]; + if (isset($meta['checkbox'])) { + $val=$this->format_label($array, $meta['checkbox'], $path, $name); + if ($this->val_has($val)) { + echo $this->format_label($array, $meta['label'], $path, $name)."<br/>\n"; + } + } + if ($depth < $this->depth) { + foreach ($array as $name => &$val) + $this->r_ro_output($val, $depth+1, $path.$meta['delim'].$name, $name); + } + } + } + private function format_label(&$array, $label='%p', $path, $name) { + $arg=$array; + $out=str_replace(array('%p', '%n'), array($path, $name), $label); + if (strpos($label, '$')) { + while (is_array(current($arg))) { + $arg=current($arg); + } + $out=eval("extract(\$arg, EXTR_PREFIX_INVALID, 'var_');\n".(strpos($label, 'return')===0?$out:"return <<<_XQ1\n$out\n_XQ1").";\n"); + } + return strpos($label, 'return')===0?$out:htmlentities($out); + } + private static function b36($n) { + return base_convert($n, 10, 36); + } +} +?> 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" /> ':' ').'<input style="float: right" type="submit" name="wizard_submit['.$this->step.']" value="'.($this->step == $this->module->numsteps?'Finish':'Next').'" /><br/>'; + } +} +?> diff --git a/frontend/classes/wizard_api.php b/frontend/classes/wizard_api.php deleted file mode 100644 index 46814b5..0000000 --- a/frontend/classes/wizard_api.php +++ /dev/null @@ -1,429 +0,0 @@ -<?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) { - // print warning if rw is false? - if (!$obj->status) { - echo print_warning('Please complete this field.'); - } - $obj->output($rw); - } - 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 (!$obj->status=$obj->process()) { - $result=$this->step; - } - } - return $result; - } - public function verify() { - foreach ($this->data as $obj) { - if (!($obj->status=$obj->verify())) { - return $obj->status; - } - } - return true; - } - private function text($text) { - $this->data[]=new wizard_text($this->configuration, $text); - } - private function 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($this->configuration, $optname, $htmlname, $label, $options); - } - private function 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($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($this->configuration, $optname, $htmlname, $label, $array, $delim, $metadata); - } - private function query($q) { - return $GLOBALS['S']['pdo']->query($q); - } - private function get_opt($opt) { - return $this->configuration->get_opt($opt); - } - 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/>'; - } -} -abstract class wizard { - public $status=true, $configuration; - function __construct(&$c) { - $this->configuration=&$c; - } - abstract public function output($rw=true); - abstract public function process(); - abstract public function verify(); - abstract public function clear(); - protected function get_opt($name) { - return $this->configuration->get_opt($name); - } - protected function set_opt($name, $val) { - debug('wizard', "$name=$val"); - if (substr($name, 0, 1) == ':') { - $this->configuration->$name=$val; - $this->configuration->write(); - } else { - $this->configuration->set_opt($name, $val); - } - } - protected function opt_is($name, $val) { - return $this->configuration->opt_is($name, $val); - } - protected function delete_opt($name) { - return $this->configuration->delete_opt($name); - } -} -class wizard_text extends wizard { - protected $text; - function __construct(&$c, $text) { - parent::__construct($c); - $this->text=$text; - } - public function output($rw=true) { - echo $this->text; - } - public function process() { - return true; - } - public function verify() { - return true; - } - public function clear() {} -} -abstract class wizard_input extends wizard { - protected $optname, $htmlname, $label; - function __construct(&$c, $optname, $htmlname, $label) { - parent::__construct($c); - $this->optname=$optname; - $this->htmlname=htmlentities($htmlname); - $this->label=htmlentities($label); - } - public function output($rw=true) { - echo "$this->label: "; - } - public function process() { - global $request; - if (isset($request[$this->optname])) { - self::set_opt($this->optname, $request[$this->optname]); - return true; - } else { - return false; - } - } - public function verify() { - return $this->get_opt($this->optname)!==null; - } - public function clear() { - return $this->delete_opt($this->optname); - } -} -class wizard_text_input extends wizard_input { - public function output($rw=true) { - parent::output($rw); - echo $rw?"<input name=\"$this->htmlname\"".(($val=$this->get_opt($this->optname)) === null?'':'value="'.htmlentities($val).'"').' />':htmlentities($this->get_opt($this->optname)); - echo "<br/>\n"; - } -} -class wizard_select extends wizard_input { - private $options; - function __construct(&$c, $optname, $htmlname, $label, $options) { - parent::__construct($c, $optname, $htmlname, $label); - $this->options=$options; - } - public function output($rw=true) { - parent::output($rw); - if ($rw) { - echo '<select name="'.$this->htmlname.'">'."\n"; - $i=0; - } - foreach ($this->options as $val => $label) { - if ($rw) - echo "\t".'<option value="'.$i++.'"'.($this->opt_is($this->optname, $val)?' selected="selected"':'').'>'.htmlentities($label).'</option>'."\n"; - elseif ($this->opt_is($this->optname, $val)) - echo htmlentities($label); - } - if ($rw) - echo '</select>'; - echo "<br/>\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]])) { - $this->set_opt($this->optname, $vals[$request[$this->htmlname]]); - return true; - } else return false; - } - public function verify() { - if (($val=$this->get_opt($this->optname)) === null) return null; - return isset($this->options[$val]); - } -} -class wizard_radio extends wizard_select { - public function output($rw=true) { - if (!$rw) return parent::output($rw); - 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."\"".($this->opt_is($this->optname, $val)?' checked="checked"':'')."\" /><label for=\"$this->htmlname-$i\">".htmlentities($label)."</label><br/>\n"; - $i++; - } - } -} -class wizard_checkbox_array extends wizard_input { - protected $array; - function __construct(&$c, $optname, $htmlname, $label, $array, $delim=' ') { - parent::__construct($c, $optname, $htmlname, $label); - $this->array=$array; - $this->delim=$delim; - } - public function output($rw=true) { - if (strlen($this->label)) - echo "<b>$this->label:</b><br/>\n"; - $i=0; - foreach ($this->array as $val => $label) { - $label=htmlentities($label); - if ($rw) - 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"; - elseif ($this->opt_has($this->optname, $val, $this->delim)) - echo "$label<br/>\n"; - $i++; - } - } - public function process() { - global $request; - $val=array(); - if (isset($request[$this->htmlname])) { - $vals=array_keys($this->array); - foreach ($request[$this->htmlname] as $i => $null) { - $val[]=$vals[$i]; - } - } - $this->set_opt($this->optname, implode($this->delim, $val)); - return true; - } - public function verify() { - 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])) { - unset($vals[$i]); - } - } - return count($vals) == 0; - } - 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, self::$opt_cache[$name][$delim]); - } -} -class wizard_layered_checkbox_array extends wizard_checkbox_array { - private $depth=0, $path_delims=array('', '/', '-'); - 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; - if (!in_array('wlca', $S['scripts'])) { - $S['scripts'][]='wlca'; - } - } - public function output($rw=true) { - if ($this->label) { - echo '<h4>'.htmlentities($this->label).'</h4>'; - } - if ($rw) - $this->r_output($this->array); - else - $this->r_ro_output($this->array); - } - public function process() { - $this->set_opt($this->optname, implode($this->delim, $this->r_process($this->array))); - return true; - } - public function verify() { - 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)); - return count($r) == 0; - } - private function r_output(&$array, $depth=0, $path=null, $name=null) { - static $uid=0, $ucid=0; - $conf=&$this->metadata[0]; - if ($depth == 0) { - $search=$autosize=0; - for ($i=1; $i<count($this->metadata); $i++) { - $m=&$this->metadata[$i]; - if (isset($m['tag'])) { - $autosize++; - } - if (isset($m['search'])) { - $search++; - } - } - if ($search) { - if (!isset($conf['id'])) { - $conf['id']=self::b36($uid++); - } - echo 'Search: <input id="'.$conf['id'].'-q" onkeyup="wlca_search(this.value, document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$conf['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:wlca_show_checked(document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; - } - echo '<div class="wlca'.(isset($conf['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$conf['id'].'">'."\n"; - foreach ($array as $name => &$val) { - $this->r_output($val, $depth+1, $name, $name); - $uid++; - } - 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]; - 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"':'').'>'; - if (isset($meta['collapsed']) && $depth < $this->depth) { - echo '<a href="javascript:wlcat(\''.self::b36($uid).'\')">±</a>'; - } - } - if (isset($meta['checkbox'])) { - $enc=self::b36($ucid++); - 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"; - } - if ($depth < $this->depth) { - foreach ($array as $name => &$val) { - $uid++; - $this->r_output($val, $depth+1, $path.$meta['delim'].$name, $name); - } - } - if (isset($meta['tag'])) { - echo '</'.$meta['tag'].">\n"; - } - } - } - private function r_process(&$array, $depth=0, $path=null, $name=null) { - static $ucid=0, $r; - if ($depth == 0) { - $r=array(); - foreach ($array as $name => &$val) { - $this->r_process($val, $depth+1, $name, $name); - } - return $r; - } else { - $meta=$this->metadata[$depth]; - if (isset($meta['checkbox'])) { - global $request; - if (isset($request[$this->htmlname][self::b36($ucid)])) { - $r[]=$this->format_label($array, $meta['checkbox'], $path, $name); - } - $ucid++; - } - 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 r_ro_output(&$array, $depth=0, $path=null, $name=null) { - if ($depth == 0) { - foreach ($array as $name => &$val) { - $this->r_ro_output($val, $depth+1, $name, $name); - } - } else { - $meta=$this->metadata[$depth]; - if (isset($meta['checkbox'])) { - $val=$this->format_label($array, $meta['checkbox'], $path, $name); - if ($this->opt_has($this->optname, $val, $this->delim)) { - echo $this->format_label($array, $meta['label'], $path, $name)."<br/>\n"; - } - } - if ($depth < $this->depth) { - foreach ($array as $name => &$val) - $this->r_ro_output($val, $depth+1, $path.$meta['delim'].$name, $name); - } - } - } - private function format_label(&$array, $label='%p', $path, $name) { - $arg=$array; - $out=str_replace(array('%p', '%n'), array($path, $name), $label); - if (strpos($label, '$')) { - while (is_array(current($arg))) { - $arg=current($arg); - } - $out=eval("extract(\$arg, EXTR_PREFIX_INVALID, 'var_');\n".(strpos($label, 'return')===0?$out:"return <<<_XQ1\n$out\n_XQ1").";\n"); - } - return strpos($label, 'return')===0?$out:htmlentities($out); - } - private static function b36($n) { - return base_convert($n, 10, 36); - } -} -?> diff --git a/frontend/css/wlca.css b/frontend/css/lca.css index 2ff94a9..90a4429 100644 --- a/frontend/css/wlca.css +++ b/frontend/css/lca.css @@ -1,7 +1,7 @@ -.wlca.autosize .wlcae { +.lca.autosize .lcae { font-size: 87%; } -.wlca.autosize .wlcae .wlcae { +.lca.autosize .lcae .lcae { padding-left: 2em; } #plist { @@ -11,12 +11,12 @@ padding: 5px; border: 1px dotted black; } -.wlcae a { +.lcae a { text-decoration: none; } #plist div.masked { color: red; } -.wlcae label { +.lcae label { cursor: pointer; } diff --git a/frontend/js/wlca.js b/frontend/js/lca.js index 7c1b13e..39dc96d 100644 --- a/frontend/js/wlca.js +++ b/frontend/js/lca.js @@ -1,10 +1,10 @@ -var wlca_last_search; -var wlca_search_timeout; -var wlca_found_last; -function wlcat(id, set) { // Short for 'toggle' +var lca_last_search; +var lca_search_timeout; +var lca_found_last; +function lcat(id, set) { // Short for 'toggle' tag=document.getElementById(id); for (var i=1; i<tag.childNodes.length; i++) { - if (tag.childNodes[i].className && tag.childNodes[i].className.indexOf('wlcae') != -1) { + if (tag.childNodes[i].className && tag.childNodes[i].className.indexOf('lcae') != -1) { if (typeof(set) == 'undefined') { set=tag.childNodes[i].style.display=="none"?"":"none"; } @@ -12,43 +12,43 @@ function wlcat(id, set) { // Short for 'toggle' } } } -function wlca_expand(id) { - wlcat(id, ""); +function lca_expand(id) { + lcat(id, ""); } -function wlca_collapse(id) { - wlcat(id, "none"); +function lca_collapse(id) { + lcat(id, "none"); } -function wlca_search(q, el, depth, maxdepth, t) { +function lca_search(q, el, depth, maxdepth, t) { if (!t) { - clearTimeout(wlca_search_timeout); - wlca_search_timeout=setTimeout(function () {wlca_found_last=wlca_search(q, el, depth, maxdepth, true)}, 300); + clearTimeout(lca_search_timeout); + lca_search_timeout=setTimeout(function () {lca_found_last=lca_search(q, el, depth, maxdepth, true)}, 300); return; } if (depth == 0) { - if (q == wlca_last_search) return wlca_found_last; - if (wlca_found_last == 0 && q.indexOf(wlca_last_search) != -1) { - debug('wlca', 'Already had no results, not searching "'+q+'"'); + if (q == lca_last_search) return lca_found_last; + if (lca_found_last == 0 && q.indexOf(lca_last_search) != -1) { + debug('lca', 'Already had no results, not searching "'+q+'"'); return 0; } - wlca_last_search=q; - debug('wlca', 'Searching "'+q+'"'); + lca_last_search=q; + debug('lca', 'Searching "'+q+'"'); } var found=0; for (var i=0; i<el.childNodes.length; i++) { - if (el.childNodes[i].nodeName == "LABEL" || (el.childNodes[i].className && el.childNodes[i].className.indexOf('wlcal') != -1)) { - found+=(el.childNodes[i].innerHTML.indexOf(q) == -1?0:1); + if (el.childNodes[i].nodeName == "LABEL" || (el.childNodes[i].className && el.childNodes[i].className.indexOf('lcal') != -1)) { + found+=(el.childNodes[i].innerHTML.toLowerCase().indexOf(q.toLowerCase()) == -1?0:1); break; } } if (depth < maxdepth) { for (var i=0; i<el.childNodes.length; i++) { - if (!(el.childNodes[i].className && el.childNodes[i].className.indexOf('wlcae') != -1)) continue; - var lfound=wlca_search(q, el.childNodes[i], depth+1, maxdepth, true); + if (!(el.childNodes[i].className && el.childNodes[i].className.indexOf('lcae') != -1)) continue; + var lfound=lca_search(q, el.childNodes[i], depth+1, maxdepth, true); found+=lfound; el.childNodes[i].style.display=(q.length == 0 || lfound > 0?"":"none"); } - if (q.length == 0 && el.className.indexOf('wlcac') != -1) { - wlca_collapse(el.id); + if (q.length == 0 && el.className.indexOf('lcac') != -1) { + lca_collapse(el.id); } } if (depth == 0) { @@ -56,9 +56,9 @@ function wlca_search(q, el, depth, maxdepth, t) { } return found; } -function wlca_show_checked(el, depth, maxdepth) { +function lca_show_checked(el, depth, maxdepth) { if (depth == 0) { - wlca_last_search=undefined; + lca_last_search=undefined; } var found=0; for (var i=0; i<el.childNodes.length; i++) { @@ -66,8 +66,8 @@ function wlca_show_checked(el, depth, maxdepth) { found++; } if (depth < maxdepth) { - if (!(el.childNodes[i].className && el.childNodes[i].className.indexOf('wlcae') != -1)) continue; - var lfound=wlca_show_checked(el.childNodes[i], depth+1, maxdepth); + if (!(el.childNodes[i].className && el.childNodes[i].className.indexOf('lcae') != -1)) continue; + var lfound=lca_show_checked(el.childNodes[i], depth+1, maxdepth); found+=lfound; el.childNodes[i].style.display=(lfound > 0?"":"none"); } diff --git a/frontend/modules/gentoo/step4.php b/frontend/modules/gentoo/step4.php index 3e2e73a..11d0c1e 100644 --- a/frontend/modules/gentoo/step4.php +++ b/frontend/modules/gentoo/step4.php @@ -1,6 +1,6 @@ <?php $profile=new sql_gentoo_profile($this->get_opt('profile')); -$pkgs=$profile->get_packages(); +$pkgs=$profile->get_packages(true); $meta=array( array('id' => 'plist', 'autosize'=> true), array('delim' => '', 'tag' => 'div', 'label' => '%n', 'collapsed' => true), diff --git a/shared/classes/1conf_build_common.php b/shared/classes/1conf_build_common.php index 35ba6e6..f5721a4 100644 --- a/shared/classes/1conf_build_common.php +++ b/shared/classes/1conf_build_common.php @@ -41,14 +41,14 @@ abstract class conf_build_common extends sql_row_obj { } return $opts; } - // Returns the value (or object if $get_obj is true) of the option given by $name, or null if unset + // Returns the value (or object if $get_obj is true) of the option given by $name, or false if unset public function get_opt($name, $get_obj=false) { $opts=$this->get_opts($get_obj); - return isset($opts[$name])?$opts[$name]:null; + return array_key_exists($name, $opts)?$opts[$name]:false; } // Returns true if the given option is set and equals the given value, false otherwise public function opt_is($name, $val) { - return (($r=$this->get_opt($name)) !== null && $r == $val); + return ($this->get_opt($name) == $val); } // Generates a unique id and sets status to 1, writes self to db and returns id public function init() { diff --git a/shared/classes/gentoo_profile.php b/shared/classes/gentoo_profile.php index b29bf05..51cc5a4 100644 --- a/shared/classes/gentoo_profile.php +++ b/shared/classes/gentoo_profile.php @@ -195,13 +195,15 @@ class sql_gentoo_profile extends sql_row_obj { } return true; } - public function &get_packages() { + public function &get_packages($omit_masked=false) { global $S; $r=$S['pdo']->query('SELECT * FROM `gentoo_packages` WHERE `profile`='.$this->id); $p=array(); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=new sql_gentoo_package($pkg); - $p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version]=$pkg->to_array(); + $array=$pkg->to_array(); + if (!($omit_masked && $array['masked'])) + $p[$pkg->bcat][$pkg->lcat][$pkg->name][$pkg->version]=$array; } return $p; } @@ -1,7 +1,6 @@ Write a live git ebuild Add a profiles management page/backend utility Add cleanup functions to the frontend and backend (tasks dir in backend containing scripts that can be launched through frontend) -Support ~arch installation (when ~arch not in ACCEPT_KEYWORDS) Move bundler selection out of gentoo module and generalize it Allow config viewing for builds, not just configurations Add `flags` column to configurations, builds, use it to implement public and private things |