<?php $page->layout = 'admin'; if (!User::require_admin()) { header('Location: /admin'); exit; } if (!isset($_GET['table'])) { header('Location: /dbman/index'); exit; } $limit = 20; $num = isset($_GET['num']) ? $_GET['num'] : 1; $_GET['offset'] = ($num - 1) * $limit; $page->title = i18n_get('Table') . ': ' . $_GET['table']; $pkey = DBMan::primary_key($_GET['table']); $count = db_shift('select count(*) from `' . $_GET['table'] . '`'); $res = db_fetch_array('select * from `' . $_GET['table'] . '` limit ' . $limit . ' offset ' . $_GET['offset']); $more = $count > $_GET['offset'] + $limit; $prev = $_GET['offset'] - $limit; $next = $_GET['offset'] + $limit; if (count($res) > 0) { $headers = array_keys((array) $res[0]); } else { $headers = array(); } printf("<p><a href='/dbman/index'>« %s</a> | <a href='/dbman/add?table=%s'>%s</a></p>\n", i18n_get('Back'), $_GET['table'], i18n_get('Add Item')); echo '<p style="float: left">' . $count . ' ' . i18n_get('results') . ":</p>\n"; if ($count > $limit) { echo '<div style="float: right">' . $this->run('navigation/pager', array('style' => 'numbers', 'url' => '/dbman/browse?table=' . $_GET['table'] . '&num=%d', 'total' => $count, 'count' => count($res), 'limit' => $limit)) . '</div>'; }
<?php if (!User::require_admin()) { header('Location: /admin'); exit; } if (!isset($_GET['table'])) { header('Location: /dbman/index'); exit; } $page->layout = 'admin'; $sql = sprintf('delete from `%s` where %s = ?', $_GET['table'], DBMan::primary_key($_GET['table'])); if (db_execute($sql, $_GET['key'])) { $this->add_notification(i18n_get('Item deleted.')); $this->redirect('/dbman/browse?table=' . $_GET['table']); } $page->title = i18n_get('An Error Occurred'); printf("<p>%s</p>\n<p><a href='/dbman/browse?table=%s'>« %s</a></p>\n", db_error(), $_GET['table'], i18n_get('Back'));
$sql .= $sep . $k . ' = ?'; $params[] = $v; $sep = ', '; } $sql .= ' where ' . $pkey . ' = ?'; $params[] = $_GET['key']; if (!db_execute($sql, $params)) { $page->title = i18n_get('An Error Occurred'); printf("<p>%s</p>\n<p><a href='/dbman/browse?table=%s'>« %s</a></p>\n", db_error(), $_GET['table'], i18n_get('Back')); return; } $this->add_notification(i18n_get('Item updated.')); $this->redirect('/dbman/browse?table=' . $_GET['table']); } // get the initial object from the database $o = db_single(sprintf('select * from `%s` where %s = ?', $_GET['table'], DBMan::primary_key($_GET['table'])), $_GET['key']); // generate the form $o = $f->merge_values($o); $o->failed = $f->failed; echo "<form method='post'>\n"; $timepicker_loaded = false; // generate the form fields foreach ($fields as $field) { // disable auto-incrementing fields if (DBMan::is_auto_incrementing($field)) { printf('<input type="hidden" name="%s" value="%s" />' . "\n", $field->name, $o->{$field->name}); continue; } if (isset($f->rules[$field->name]['type']) && $f->rules[$field->name]['type'] == 'numeric') { $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a number for %s', $field->name) . '</span>'; } elseif (isset($f->rules[$field->name]['length'])) {