Location: PHPKode > projects > SQLite PHP Admin > spa/dbase.php
<?php
/***********************************************************************

		Copyright (c) 2011, Andrew V. Pleshakov	(hide@address.com)
		All rights reserved.

		This file is part of SPA (SQLite PHP Admin)
		See file LICENSE.txt for details

************************************************************************/

require_once('include.php');
if(!$current_db) {
	header('Location: main.php');
	die;
}

if (!isset($pla_db)) {
	$tar['err'] = '';
	if(isset($_GET['err']))
		$tar['err'] = str_replace("'","\\'",$_GET['err']);
	die(design_render('db/dbnew',$tar));
}

if ($pla_db->libVersion() == '0')
	die(design_render('db/dberr',$tar));
//////////////////////////////////////////////////////

if(!isset($_GET['object'])) {
	$dbinfo = $pla_db->dbInfo();
	$tar['size'] = strval(round($dbinfo['size']/1024,2));
	$tar['last_mod'] = $dbinfo['last_mod'];
	$tar['uname'] = '';
	if(function_exists('posix_getpwuid')) {
		$user = posix_getpwuid($dbinfo['owner']);
		$group = posix_getgrgid($user['gid']);
		$tar['uname'] = $user['name'];
		$tar['group'] = $group['name'];
	}
	if(is_readable($current_db)) $tar['rwd'] = 'read and ';else $tar['rwd'] = 'NO read and ';
	if(is_writable($current_db)) $tar['rwd'] .= 'write';else $tar['rwd'] .= 'NO write';
	$db_tab = '';
	$tbls = $pla_db->getTables();
	foreach($tbls as $row) {
		$db_tab .= "<tr><td>".strtoupper($row)."</td>\n";
		$numrows = $pla_db->numRows($row);
		$db_tab .= "<th>$numrows</th><td>\n";
		$db_tab .= table_links($row);
		$db_tab .= "</td></tr>\n";
	}
	if($tar['numtbls'] = count($tbls))
		$tar['tables'] = $db_tab;
	else $tar['tables'] = '';

	$pathi = pathinfo($current_db);
	$suf = '.'.$pathi['extension'];
	$rname = basename($current_db,$suf);// name without ext?
	$tar['mvdb'] = $pathi['dirname'].'/'.$rname.'_new'.$suf;
	$tar['cpdb'] = $pathi['dirname'].'/'.$rname.'_2'.$suf;
	$tar['bname'] = basename($current_db);

	die(design_render('db/dbase',$tar));
}
/////////////////////////// TABLE STRUCTURE /////////////////////////////////
$tar['table'] = $table = $_GET['object'];
$tar['cols'] = '';
$columns = $pla_db->getTableColumns($table);
$tar['columns'] = serialize($columns);
$tar['columns'] = str_replace("'","\\'",$tar['columns']);// for escaping eval errors
foreach ($columns as $row) {
	$row['name_url'] = urlencode($row['name']);
	$row['table_url'] = urlencode($table);
	$tar['cols'] .= design_render('extra/tcols',$row);
}
$tar['ccolumns'] = count($columns);
$tar['utable'] = urlencode($table);
$tar['numrows'] = $pla_db->numRows($table);

$idx = $pla_db->getIndexes($table);
$tar['cidx'] = count($idx);
if($tar['cidx']) {
	$tar['idx'] = '';
	foreach($idx as $ind)
		$tar['idx'] .= design_render('extra/tidx',$ind);
}
die(design_render('table/tinfo',$tar));
//////////////////////////////////////////////////////////////////
function select_columns($cols) {
	$cols = unserialize(stripslashes($cols));
	$s = '';
	foreach($cols as $col) 
		$s .= "\t<option value=\"{$col['name']}\">{$col['name']}</option>\n";
	return design_render('extra/selcols',array('opts'=>$s));
}
function put_addfileds($cols) {
	$cols = unserialize(stripslashes($cols));
	$rr['cols'] = '';
	$n = count($cols);
	if($n > 1)
		for($i = 1; $i < $n; $i++)
			$rr['cols'] .= design_render('extra/adcol',array('i'=>$i,'name'=>$cols[($i-1)]['name']));
	else $i = 1;
	$rr['i'] = $i;
	return design_render('extra/adcols',$rr);
}
Return current item: SQLite PHP Admin