From 3e78e8d97d6f0073741040d24601e918254ee3e0 Mon Sep 17 00:00:00 2001 From: dave Date: Fri, 16 Nov 2007 17:41:34 +0000 Subject: [PATCH] - add support for 'datetime' to the tableeditor --- tableeditor.class.php | 73 +++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/tableeditor.class.php b/tableeditor.class.php index 992b663..b601837 100644 --- a/tableeditor.class.php +++ b/tableeditor.class.php @@ -414,7 +414,10 @@ class TableEditor break; case "time": $inputtype="time"; - break; + break; + case "datetime": + $inputtype="datetime"; + break; case "enum": //an enum is a select box, but we already know what the options should be //so rip out the options right now and add them @@ -555,12 +558,25 @@ class TableEditor } } - if($inputtype == 'date') //r->Type=="date") + if($inputtype == 'date' || $inputtype == 'datetime') //r->Type=="date") { if($_POST[$f."_year"] && $_POST[$f."_month"] && $_POST[$f."_day"]) { - $editdata[$f] = "'".mysql_escape_string(stripslashes($_POST[$f."_year"]))."-". - mysql_escape_string(stripslashes($_POST[$f."_month"]))."-". - mysql_escape_string(stripslashes($_POST[$f."_day"]))."'"; + $yy = intval($_POST[$f."_year"]); + $mm = intval($_POST[$f."_month"]); + $dd = intval($_POST[$f."_day"]); + + $editdata[$f] = "'$yy-$mm-$dd"; + + if($inputttype == 'date') { + $editdata[$f] .= "'"; + } else if($_POST[$f."_hour"]!="" && $_POST[$f."_minute"]!="") { + $hh = intval($_POST[$f."_hour"]); + $mi = intval($_POST[$f."_minute"]); + + $editdata[$f] .= " $hh:$mi:00'"; + } else { + $editdata[$f] = 'NULL'; + } } else { $editdata[$f] = 'NULL'; } @@ -832,33 +848,48 @@ class TableEditor break; case "date": - list($yy,$mm,$dd)=split("-",$editdata[$f]); - + case "datetime": + $a = split('[- :]',$editdata[$f]); + if($inputtype == 'date') { + list($yy,$mm,$dd)=$a; + $w = 10; + } else { + list($yy,$mm,$dd,$hh,$mi,$ss)=$a; + $w=15; + } //if we put a small width here, then it prevents it from expanding to whatever width it feels like. - echo ""; + echo "
"; echo ""; - echo "
"; $this->month_selector($f."_month",$mm); echo ""; $this->day_selector($f."_day",$dd); echo ""; $this->year_selector($f."_year",$yy); - echo "
"; - echo ""; - break; + echo ""; + if($inputtype == 'date') { + echo ""; + echo ""; + echo ""; + break; + } + /* Else, fall through, with hh, mi, ss already set */ case "time": - list($hh,$mm,$ss)=split(":",$editdata[$f]); + if($inputtype == 'time') { + list($hh,$mi,$ss)=split(":",$editdata[$f]); - echo ""; - echo ""; else if($typer->Type=="date") echo ""; + else if($typer->Type=="datetime") + echo ""; else if(substr($f,0,8)=="filename" && $this->uploadPath) { echo "
"; + echo ""; + echo ""; + } + /* Common code for time, and datetime */ + echo ""; echo "
"; $this->hour_selector($f."_hour",$hh,false,"12hr"); echo ""; - $this->minute_selector($f."_minute",$mm); + $this->minute_selector($f."_minute",$mi); echo "
"; - echo ""; + echo ""; break; case "file": if($editdata[$f]) @@ -1112,6 +1143,8 @@ class TableEditor echo "
".$this->format_time($r->$f)."".$this->format_date($r->$f)."".$this->format_datetime($r->$f).""; @@ -1355,6 +1388,12 @@ class TableEditor } return $ret; } + function format_datetime($d) + { + list($d,$t)=split(' ', $d); + $ret = $this->format_date($d).' '.$this->format_time($t); + return $ret; + } }