Location: PHPKode > projects > SQLite PHP Admin > spa/main.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 (isset($_REQUEST['newdb'])) { // we've chosen some database
	$_SESSION['currentdb'] = $_REQUEST['newdb'];
	$_SESSION['lim'] = 50;
	$_SESSION['page'] = 1;
	$_SESSION['lquery'] = '';
	header('Location: index.php?bd=1');
	die;
}

if(isset($_GET['php'])) { // show PHP information
	phpinfo();
	die;
}

//////////////// ALIASES EDITING ////////////////////////////////////
if(isset($_REQUEST['edit'])) {// aliases editing routings
	$title = 'Add new database alias';
	$alias = str_replace('|','',trim($_POST['alias']));
	$path = str_replace('|','',trim($_POST['path']));
	$descr = trim($_POST['description']);
	$oldpath = trim($_POST['oldpath']);
	$epath = base64_decode($_GET['path']);

	if (isset($_POST['insert'])) {
		if (!$alias) {
			raiseError("An alias name needs to be provided");
			exit();
		}
		if (!$path) {
			raiseError("The path to the database needs to be provided");
			exit();
		}
		$trk = ReadAliasCFG();
		$j = count($trk);
		for($i=0;$i<$j;$i++) {
			$row = explode('|',$trk[$i],3);
			if($row[1] == $oldpath) break;
		}
		$trk[$i] = "$alias|$path|$descr";
		SaveAliasCFG($trk);
		header("Location: index.php");
		exit;
	}

	if (isset($_GET['del'])) {
		$trk = ReadAliasCFG();
		$j = count($trk);
		for($i=0;$i<=$j;$i++) {
			if($i == $j) { // this is new PATH!
				raiseError("Bad path='$path'!",'File error');
			}
			$row = explode('|',$trk[$i],3);
			if($row[1] == $epath) break;
		}
		unset($trk[$i]);
		SaveAliasCFG($trk);
		header("Location: index.php");
		exit;
	}

	if (isset($_GET['path'])) {
		$trk = ReadAliasCFG();
		$j = count($trk);
		for($i=0;$i<=$j;$i++) {
			if($i == $j) raiseError("Bad path '$path'!",'File error');
			list($alias,$path,$descr) = explode('|',$trk[$i],3);
			if($path == $epath) break;
		}
		$title = 'Edit database alias';
	}
	$tar['epath'] = $epath;
	$tar['alias'] = $alias;
	$tar['path'] = $path;
	$tar['descr'] = $descr;
	$tar['title'] = $title;
	die(design_render('alias',$tar));
}

//////////////////////////  MAIN BODY /////////////////////
$dbs = '';
$trk = ReadAliasCFG();// format: alias|path|description
if(count($trk))
  foreach($trk as $val) {
	$row = explode('|',$val,3);//
	if(!$row[0]) continue;
	$dbs .= design_render('extra/alias',$row);
  }
if($dbs)
	$tar['dbases'] = $dbs;
else
	$tar['dbases'] = design_render('extra/nodb',array());

FindLicence();
if($LIC['lic'])	$tar['lic'] = design_render('extra/lic',$LIC);
else $tar['lic'] = design_render('extra/nolic');

die(design_render('main',$tar));
Return current item: SQLite PHP Admin