Пример #1
0
<?php

$page->layout = 'admin';
if (!User::require_admin()) {
    header('Location: /admin');
    exit;
}
$page->title = 'DB Manager';
$tables = DBMan::list_tables();
echo $tpl->render('dbman/index', array('tables' => $tables));
Пример #2
0
<?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'>&laquo; %s</a></p>\n", db_error(), $_GET['table'], i18n_get('Back'));
Пример #3
0
<?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'>&laquo; %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>';
}
Пример #4
0
<?php

$page->layout = 'admin';
if (!User::require_admin()) {
    header('Location: /admin');
    exit;
}
$page->title = i18n_get('Table Info') . ': ' . $_GET['table'];
$columns = DBMan::table_info($_GET['table']);
echo $tpl->render('dbman/info', array('table' => $_GET['table'], 'columns' => $columns));
Пример #5
0
 /**
  * Determine whether the specified field is auto-incrementing.
  */
 public static function is_auto_incrementing($field)
 {
     // skip auto-incrementing fields
     if (DBMan::driver() == 'sqlite' && $field->type == 'integer' && $field->key == 'Primary') {
         return true;
     }
     if (strtolower($field->extra) == 'auto_increment') {
         return true;
     }
     return false;
 }
Пример #6
0
        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'])) {
        $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a value for %s no longer than %s', $field->name, $field->length) . '</span>';
    } elseif (isset($f->rules[$field->name]['not empty'])) {
        $rule = ' <span class="notice" id="' . $field->name . '-notice">' . i18n_getf('You must enter a value for %s', $field->name) . '</span>';
    } else {
        $rule = '';
    }
    switch ($field->type) {
        case 'text':
            printf('<p>%s:<br /><textarea name="%s" cols="60" rows="8">%s</textarea>%s</p>' . "\n", $field->name, $field->name, Template::quotes($o->{$field->name}), $rule);