From 3f1dda1e19e1f77e908df1d49d028d0932d0f1a1 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 23 Apr 2009 07:41:28 +0000 Subject: A completely new forms class, to replace the old function based method. Also some work on a new config module, evenmtuelly to replace the old hardcoded values. --- utils/forms.php | 361 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 238 insertions(+), 123 deletions(-) (limited to 'utils/forms.php') diff --git a/utils/forms.php b/utils/forms.php index d5216f2..dd0a768 100644 --- a/utils/forms.php +++ b/utils/forms.php @@ -1,147 +1,262 @@ label = $label; + $this->name = $name; + $this->value = $value; + } -function beginform($action, $hasfile = false) -{ - global $m, $s; -?> -
enctype="multipart/form-data" - action="?page=admin&m=&s=&a="> -\n"; + $str .= $indent . "
". $this->label ."
\n"; + $str .= $indent . "
name."]\" value=\"".$this->value."\"/>
\n"; + $str .= $indent . "\n"; + return $str; + } } -function endform() -{ -?> -
- -
-
-
-
-label = $label; + $this->name = $name; + $this->accept = $accept; + } + + public function render($indent = "") + { + $str = $indent . "
\n"; + $str .= $indent . "
". $this->label . "
\n"; + $str .= $indent . "
name. "\" accept=\"". $this->accept ."\"/>
\n"; + $str .= $indent . "
\n"; + return $str; + } } -function lineedit($label, $name, $value = "") -{ -?> -
-
-
" value=""/>
-
-label = $label; + } + + public function render($indent = "") + { + $str = $indent . "
\n"; + $str .= $indent . "
\n"; + $str .= $indent . "
\n"; + $str .= $indent . "
\n"; + return $str; + } } -function fileupload($label, $name, $accept = "*") -{ -?> -
-
-
-
-label = $label; + $this->name = $name; + $this->value = $value; + } + + public function render($indent = "") + { + $str = $indent . "
\n"; + $str .= $indent . "
". $this->label ."
\n"; + $str .= $indent . "
name."]\" value=\"".$this->value."\"/>
\n"; + $str .= $indent . "
\n"; + return $str; + } } -function hidden($values) -{ - foreach($values as $key => $value) { -?> - " value=""/> -label = $label; + $this->name = $name; + $this->value = $value; + $this->values = $values; + } + + public function render($indent = "") + { + $str = $indent . "
\n"; + $str .= $indent . "
".$this->label."
\n"; + $str .= $indent . "
\n"; + $str .= $indent . " \n"; + $str .= $indent . "
\n"; + $str .= $indent . "
\n"; + return $str; + } } -function textedit($label, $name, $value = "") -{ -?> -
-
-
-
-values = $values; + } + + public function render($indent = "") + { + $str = ""; + foreach($this->values as $key => $value) { + $str .= $indent . "\n"; + } + return $str; + } } -function datetimeedit($label, $name, $timestamp = 0) -{ - if($timestamp == 0) $timestamp = time(); +class TextEdit { + private $label, $name, $value; + + function TextEdit($label, $name, $value = "") + { + $this->label = $label; + $this->name = $name; + $this->value = $value; + } - $second = date('s',$timestamp); - $minute = date('i',$timestamp); - $hour = date('G',$timestamp); - $day = date('d',$timestamp); - $month = date('m',$timestamp); - $year = date('Y',$timestamp); -?> -
-
-
- " value=""/>/" value=""/>/" value=""/> - - - " value=""/>:" value=""/>:" value=""/> -
-
-\n"; + $str .= $indent . "
". $this->label ."
\n"; + $str .= $indent . "
\n"; + $str .= $indent . "\n"; + return $str; + } } -function totimestamp($t, $name) -{ - $timestring = sprintf("%d", $t[$name."_year"]) ."/". - sprintf("%d", $t[$name."_month"]) ."/". - sprintf("%d", $t[$name."_day"]) ." ". - sprintf("%d", $t[$name."_hour"]) .":". - sprintf("%02d", $t[$name."_minute"]).":". - sprintf("%02d", $t[$name."_second"]); - - //echo $timestring; - - return strtotime($timestring); + +class DateTimeEdit { + private $label, $name, $timestamp; + + function DateTimeEdit($label, $name, $timestamp = 0) + { + $this->label = $label; + $this->name = $name; + $this->timestamp = $timestamp; + } + + function render($indent = "") + { + if($this->timestamp == 0) $t = time(); + else $t = $this->timestamp; + + $second = date('s',$t); + $minute = date('i',$t); + $hour = date('G',$t); + $day = date('d',$t); + $month = date('m',$t); + $year = date('Y',$t); + + $str = $indent . "
\n"; + $str .= $indent . "
".$this->label."
\n"; + $str .= $indent . "
\n"; + $str .= $indent . " name."_year]\" value=\"".$year."\"/>"; + $str .= "/name."_month]\" value=\"".$month."\"/>"; + $str .= "/name."_day]\" value=\"".$day."\"/>"; + $str .= " - "; + $str .= "name."_hour]\" value=\"".$hour."\"/>"; + $str .= ":name."_minute]\" value=\"".$minute."\"/>"; + $str .= ":name."_second]\" value=\"".$second."\"/>\n"; + $str .= $indent . "
\n"; + $str .= $indent . "
\n"; + + return $str; + } + + public function toTimestamp($t, $name) + { + $timestring = sprintf("%d", $t[$name."_year"]) ."/". + sprintf("%d", $t[$name."_month"]) ."/". + sprintf("%d", $t[$name."_day"]) ." ". + sprintf("%d", $t[$name."_hour"]) .":". + sprintf("%02d", $t[$name."_minute"]).":". + sprintf("%02d", $t[$name."_second"]); + + return strtotime($timestring); + } } -function combobox($label, $name, $value, $values) -{ -?> -
-
-
- -
-
-label = $label; + $this->name = $name; + $this->value = $value; + $this->values = $values; + } + + public function render($indent = "") + { + $str = $indent . "
\n"; + $str .= $indent . "
".$this->label."
\n"; + $str .= $indent . "
\n"; + $str .= $indent . " \n"; + $str .= $indent . "
\n"; + $str .= $indent . "
\n"; + return $str; + } } -function imagecombobox($label, $name, $value, $values) -{ -?> -
-
-
- -
-
-hasFileUpload = true; + array_push($this->widgets, $widget); + } + + public function render($indent = "") + { + global $m, $s; + $str = $indent . "
hasFileUpload) $str .= $indent . " enctype=\"multipart/form-data\"\n"; + $str .= $indent . " action=\"?page=admin&m=".$m."&s=".$s."&a=".$this->action."\">\n"; + foreach($this->widgets as $widget) { + $str .= $widget->render($indent . " "); + } + $str .= $indent . "
\n"; + echo $str; + } + + public function Form($action) + { + $this->action = $action; + } } ?> -- cgit v1.2.3