- 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

@ -414,7 +414,10 @@ class TableEditor
break; break;
case "time": case "time":
$inputtype="time"; $inputtype="time";
break; break;
case "datetime":
$inputtype="datetime";
break;
case "enum": case "enum":
//an enum is a select box, but we already know what the options should be //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 //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"]) { if($_POST[$f."_year"] && $_POST[$f."_month"] && $_POST[$f."_day"]) {
$editdata[$f] = "'".mysql_escape_string(stripslashes($_POST[$f."_year"]))."-". $yy = intval($_POST[$f."_year"]);
mysql_escape_string(stripslashes($_POST[$f."_month"]))."-". $mm = intval($_POST[$f."_month"]);
mysql_escape_string(stripslashes($_POST[$f."_day"]))."'"; $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 { } else {
$editdata[$f] = 'NULL'; $editdata[$f] = 'NULL';
} }
@ -832,33 +848,48 @@ class TableEditor
break; break;
case "date": 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. //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\" >"; echo "<tr><td class=\"tableedit\" >";
$this->month_selector($f."_month",$mm); $this->month_selector($f."_month",$mm);
echo "</td><td class=\"tableedit\">"; echo "</td><td class=\"tableedit\">";
$this->day_selector($f."_day",$dd); $this->day_selector($f."_day",$dd);
echo "</td><td class=\"tableedit\">"; echo "</td><td class=\"tableedit\">";
$this->year_selector($f."_year",$yy); $this->year_selector($f."_year",$yy);
echo "</td></tr>"; echo "</td>";
echo "</table>"; if($inputtype == 'date') {
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"date\">"; echo "</tr>";
break; echo "</table>";
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"date\">";
break;
}
/* Else, fall through, with hh, mi, ss already set */
case "time": 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 "<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"); $this->hour_selector($f."_hour",$hh,false,"12hr");
echo "</td><td class=\"tableedit\">"; echo "</td><td class=\"tableedit\">";
$this->minute_selector($f."_minute",$mm); $this->minute_selector($f."_minute",$mi);
echo "</td></tr>"; echo "</td></tr>";
echo "</table>"; echo "</table>";
echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"time\">"; echo "<input type=\"hidden\" name=\"tableeditor_fieldtype[$f]\" value=\"$inputtype\">";
break; break;
case "file": case "file":
if($editdata[$f]) if($editdata[$f])
@ -1112,6 +1143,8 @@ class TableEditor
echo "<td valign=\"top\">".$this->format_time($r->$f)."</td>"; echo "<td valign=\"top\">".$this->format_time($r->$f)."</td>";
else if($typer->Type=="date") else if($typer->Type=="date")
echo "<td valign=\"top\">".$this->format_date($r->$f)."</td>"; 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) else if(substr($f,0,8)=="filename" && $this->uploadPath)
{ {
echo "<td valign=\"top\">"; echo "<td valign=\"top\">";
@ -1355,6 +1388,12 @@ class TableEditor
} }
return $ret; return $ret;
} }
function format_datetime($d)
{
list($d,$t)=split(' ', $d);
$ret = $this->format_date($d).' '.$this->format_time($t);
return $ret;
}
} }