- add support for 'datetime' to the tableeditor

This commit is contained in:
dave 2007-11-16 17:41:34 +00:00
parent 1c42ab77ae
commit 3e78e8d97d

View File

@ -415,6 +415,9 @@ class TableEditor
case "time":
$inputtype="time";
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 "<table width=\"10\" align=\"left\" cellspacing=0 cellpadding=0>";
echo "<table width=\"$w\" align=\"left\" cellspacing=0 cellpadding=0>";
echo "<tr><td class=\"tableedit\" >";
$this->month_selector($f."_month",$mm);
echo "</td><td class=\"tableedit\">";
$this->day_selector($f."_day",$dd);
echo "</td><td class=\"tableedit\">";
$this->year_selector($f."_year",$yy);
echo "</td></tr>";
echo "</td>";
if($inputtype == 'date') {
echo "</tr>";
echo "</table>";
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"date\">";
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 "<table width=\"10\" cellspacing=0 cellpadding=0>";
echo "<tr><td class=\"tableedit\">";
echo "<tr>";
}
/* Common code for time, and datetime */
echo "<td class=\"tableedit\">";
$this->hour_selector($f."_hour",$hh,false,"12hr");
echo "</td><td class=\"tableedit\">";
$this->minute_selector($f."_minute",$mm);
$this->minute_selector($f."_minute",$mi);
echo "</td></tr>";
echo "</table>";
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"time\">";
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"$inputtype\">";
break;
case "file":
if($editdata[$f])
@ -1112,6 +1143,8 @@ class TableEditor
echo "<td valign=\"top\">".$this->format_time($r->$f)."</td>";
else if($typer->Type=="date")
echo "<td valign=\"top\">".$this->format_date($r->$f)."</td>";
else if($typer->Type=="datetime")
echo "<td valign=\"top\">".$this->format_datetime($r->$f)."</td>";
else if(substr($f,0,8)=="filename" && $this->uploadPath)
{
echo "<td valign=\"top\">";
@ -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;
}
}