forked from science-ation/science-ation
Fix TableEditor-based pages including CMS & Documents
This commit is contained in:
parent
66aeb66fda
commit
a2d3e6112b
@ -79,7 +79,7 @@ if (get_value_from_array($_POST, 'action') == 'save') {
|
||||
?
|
||||
)");
|
||||
$q->execute([$filename,$insertdt,$lang,$text,get_value_from_array($_POST, $titlename, ''),get_value_from_array($_POST, $showlogoname, '')]);
|
||||
if ($pdo->errorInfo()) {
|
||||
if (!$pdo->errorInfo()) {
|
||||
echo error(i18n('An error occurred saving %1 in %2', array($filename, $langname)));
|
||||
$err = true;
|
||||
}
|
||||
@ -88,7 +88,7 @@ if (get_value_from_array($_POST, 'action') == 'save') {
|
||||
echo happy(i18n('%1 successfully saved', array($_POST['filename'])));
|
||||
}
|
||||
|
||||
if (get_value_from_array($_GET, 'filename', '') || get_value_from_array($_GET, 'action', 'create')) {
|
||||
if (get_value_from_array($_GET, 'filename') || get_value_from_array($_GET, 'action') == 'create') {
|
||||
echo "<a href=\"cms.php\"><< Back to file list</a><br />\n";
|
||||
echo '<form method="post" action="cms.php">';
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"save\">\n";
|
||||
@ -104,7 +104,7 @@ if (get_value_from_array($_GET, 'filename', '') || get_value_from_array($_GET, '
|
||||
echo '<tr><th colspan="2">';
|
||||
|
||||
$q = $pdo->prepare("SELECT * FROM cms WHERE filename=? AND lang=? ORDER BY dt DESC LIMIT 1");
|
||||
$q->execute([get_value_from_array($_GET, 'filename', ''),$lang]);
|
||||
$q->execute([$_GET['filename'],$lang]);
|
||||
if ($r = $q->fetch(PDO::FETCH_OBJ)) {
|
||||
if ($r->dt == '0000-00-00 00:00:00' || !$r->dt)
|
||||
$dt = 'Never';
|
||||
@ -163,8 +163,8 @@ if (get_value_from_array($_GET, 'filename', '') || get_value_from_array($_GET, '
|
||||
|
||||
echo '<tr><th>' . i18n('File History') . "</th></tr>\n";
|
||||
|
||||
$q = $pdo->prepare("SELECT DISTINCT(dt) FROM cms WHERE filename=? ORDER BY dt DESC LIMIT ?");
|
||||
$q->execute([get_value_from_array($_GET, 'filename', ''),$historylimit]);
|
||||
$q = $pdo->prepare("SELECT DISTINCT(dt) FROM cms WHERE filename=? ORDER BY dt DESC LIMIT $historylimit");
|
||||
$q->execute([get_value_from_array($_GET, 'filename')]);
|
||||
$first = true;
|
||||
if ($q->rowCount()) {
|
||||
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
|
||||
@ -203,12 +203,12 @@ if (get_value_from_array($_GET, 'filename', '') || get_value_from_array($_GET, '
|
||||
|
||||
echo '<table class="summarytable">';
|
||||
$q = $pdo->prepare('SELECT DISTINCT(filename) AS filename FROM cms ORDER BY filename');
|
||||
|
||||
$q->execute();
|
||||
echo '<tr><th>' . i18n('Filename') . '</th><th>' . i18n('Last Update') . '</th></tr>';
|
||||
while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
|
||||
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
|
||||
echo '<tr><td><a href="cms.php?filename=' . rawurlencode($r->filename) . "\">/web/$r->filename</a></td>";
|
||||
$q2 = $pdo->prepare("SELECT dt FROM cms WHERE filename=? ORDER BY dt DESC LIMIT 1");
|
||||
$q->execute([$r->filename]);
|
||||
$q2->execute([$r->filename]);
|
||||
$r2 = $q2->fetch(PDO::FETCH_OBJ);
|
||||
if ($r2->dt == '0000-00-00 00:00:00')
|
||||
$dt = 'Never';
|
||||
|
@ -45,7 +45,6 @@ $editor = new TableEditor('documents',
|
||||
'sel_category' => 'Category',
|
||||
'filename' => 'Filename',
|
||||
));
|
||||
|
||||
$editor->setPrimaryKey('id');
|
||||
$editor->setUploadPath('../data/documents');
|
||||
$editor->setDefaultSortField('sel_category,date');
|
||||
|
@ -79,6 +79,7 @@ if (!$icon_extension) {
|
||||
$icon_extension = 'png';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main class
|
||||
* @package tableeditor
|
||||
@ -141,7 +142,7 @@ class TableEditor
|
||||
* @param array $editfields
|
||||
* @param array $hiddenfields
|
||||
*/
|
||||
function TableEditor($classname, $listfields = null, $editfields = null, $hiddenfields = null)
|
||||
function __construct($classname, $listfields = null, $editfields = null, $hiddenfields = null)
|
||||
{
|
||||
// set defaults
|
||||
$this->timeformat = '12hrs';
|
||||
@ -368,8 +369,8 @@ class TableEditor
|
||||
$inputsize = 0;
|
||||
|
||||
// figure out what kind of input this should be
|
||||
$q = $pdo->prepare("SHOW COLUMNS FROM ? LIKE ?");
|
||||
$q->execute([$this->table,$f]);
|
||||
$q = $pdo->prepare("SHOW COLUMNS FROM $this->table LIKE '$f'");
|
||||
$q->execute();
|
||||
$r = $q->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
if (preg_match('/([a-z]*)\(([0-9,]*)\)/', $r->Type, $regs)) {
|
||||
@ -461,15 +462,16 @@ class TableEditor
|
||||
function defaultLoad()
|
||||
{
|
||||
global $pdo;
|
||||
$query = "SELECT ?";
|
||||
$query = "SELECT $this->primaryKey";
|
||||
foreach ($this->editfields AS $f => $n)
|
||||
$query .= ", ?";
|
||||
$query .= " FROM ?";
|
||||
$query .= " WHERE {$this->primaryKey}=?";
|
||||
$query .= ", `$f`";
|
||||
$query .= " FROM $this->table";
|
||||
$query .= " WHERE $this->primaryKey=". $_GET['edit'];
|
||||
if ($this->DEBUG)
|
||||
echo $query;
|
||||
|
||||
$editquery = $pdo->prepare($query);
|
||||
$editquery->execute([$this->primaryKey,$f,$this->table,$_GET['edit']]);
|
||||
$editquery->execute();
|
||||
$editdata = $editquery->fetch(PDO::FETCH_ASSOC);
|
||||
return $editdata;
|
||||
}
|
||||
@ -699,6 +701,7 @@ class TableEditor
|
||||
echo '<input type="hidden" name="TableEditorAction" value="editsave">';
|
||||
echo "<input type=\"hidden\" name=\"editsave\" value=\"{$_GET['edit']}\">";
|
||||
|
||||
$data = "";
|
||||
if ($this->classname)
|
||||
$data = new $this->classname($_GET['edit']);
|
||||
|
||||
@ -785,8 +788,8 @@ class TableEditor
|
||||
case 'enum':
|
||||
break;
|
||||
case 'select_or_text':
|
||||
$optq = $pdo->prepare("SELECT DISTINCT(?) AS ? FROM ? ORDER BY ?");
|
||||
$optq->execute([$f,$f,$this->table, $f]);
|
||||
$optq = $pdo->prepare("SELECT DISTINCT('$f') AS '$f' FROM $this->table ORDER BY '$f'");
|
||||
$optq->execute();
|
||||
if ($this->fieldInputOptions[$f])
|
||||
echo '<select ' . $this->fieldInputOptions[$f] . ' id="' . $f . '_select" name="' . $f . '_select">';
|
||||
else
|
||||
@ -958,6 +961,7 @@ class TableEditor
|
||||
global $icon_extension;
|
||||
global $editdata;
|
||||
global $pdo;
|
||||
global $config;
|
||||
|
||||
$query = "SELECT SQL_CALC_FOUND_ROWS $this->primaryKey";
|
||||
|
||||
@ -991,7 +995,7 @@ class TableEditor
|
||||
// just to make sure nothing funky is goin on.
|
||||
if ($offset < 0)
|
||||
$offset = 0;
|
||||
$query .= " LIMIT ?,?";
|
||||
$query .= " LIMIT $offset,$this->rowsPerPage";
|
||||
}
|
||||
|
||||
if ($this->allowAdding) {
|
||||
@ -1001,9 +1005,8 @@ class TableEditor
|
||||
if ($this->DEBUG)
|
||||
echo $query;
|
||||
|
||||
echo $query;
|
||||
$q = $pdo->prepare($query);
|
||||
$q->execute([$offset,$this->rowsPerPage]);
|
||||
$q->execute();
|
||||
|
||||
if ($q == false) {
|
||||
echo "Sorry, DB query failed: <pre>$query</pre><br />";
|
||||
@ -1101,11 +1104,12 @@ class TableEditor
|
||||
echo '</tr>';
|
||||
while ($r = $q->fetch(PDO::FETCH_OBJ)) {
|
||||
echo '<tr>';
|
||||
|
||||
foreach ($this->listfields AS $f => $n) {
|
||||
// figure out what kind of input this should be
|
||||
$typeq = $pdo->prepare("SHOW COLUMNS FROM ? LIKE ?");
|
||||
$typeq->execute([$this->table,$config['FAIRYEAR']]);
|
||||
$typer = $typeq->fetCh(PDO::FETCH_OBJ);
|
||||
$typeq = $pdo->prepare("SHOW COLUMNS FROM $this->table LIKE '$f'");
|
||||
$typeq->execute();
|
||||
$typer = $typeq->fetch(PDO::FETCH_OBJ);
|
||||
if ($typer->Type == 'time')
|
||||
echo '<td valign="top">' . $this->format_time($r->$f) . '</td>';
|
||||
else if ($typer->Type == 'date')
|
||||
|
Loading…
x
Reference in New Issue
Block a user