From: <abe...@us...> - 2015-08-05 22:45:01
|
Revision: 7181 http://sourceforge.net/p/astlinux/code/7181 Author: abelbeck Date: 2015-08-05 22:44:59 +0000 (Wed, 05 Aug 2015) Log Message: ----------- web interface, SQL-Data tab, version bump to phpLiteAdmin 1.9.6, modified for AstLinux Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/common/license-packages.txt branches/1.0/package/webinterface/altweb/common/phpliteadmin.js Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2015-08-04 23:30:23 UTC (rev 7180) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2015-08-05 22:44:59 UTC (rev 7181) @@ -1,38 +1,38 @@ <?php +// +// Project: phpLiteAdmin (https://bitbucket.org/phpliteadmin/public) +// Version: 1.9.6 +// Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web +// Last updated: 2015-07-05 +// Developers: +// Dane Iracleous (dan...@gm...) +// Ian Aldrighetti (ian...@gm...) +// George Flanagin & Digital Gaslight, Inc (ge...@di...) +// Christopher Kramer (cra...@gm..., http://en.christosoft.de) +// Ayman Teryaki (http://havalite.com) +// Dreadnaut (dre...@gm..., http://dreadnaut.altervista.org) +// +// +// Copyright (C) 2015, phpLiteAdmin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +// //////////////////////////////////////////////////////////////////////// +// +// Please report any bugs you may encounter to our issue tracker here: +// https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open -// -// Project: phpLiteAdmin (http://phpliteadmin.googlecode.com) -// Version: 1.9.4.1 -// Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web -// Last updated: 2013-03-18 -// Developers: -// Dane Iracleous (dan...@gm...) -// Ian Aldrighetti (ian...@gm...) -// George Flanagin & Digital Gaslight, Inc (ge...@di...) -// Christopher Kramer (cra...@gm..., http://en.christosoft.de) -// Ayman Teryaki (http://havalite.com) -// Dreadnaut (dre...@gm..., http://dreadnaut.altervista.org) -// -// -// Copyright (C) 2013 phpLiteAdmin -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. -// -/////////////////////////////////////////////////////////////////////////// - -//please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list - //AstLinux// Restrict to 'admin' or 'staff' user. function getPHPusername() { @@ -50,32 +50,19 @@ } //AstLinux// end of restrict to 'admin' or 'staff' user. -//BEGIN USER-DEFINED VARIABLES -////////////////////////////// - -// These are the default configuration value for phpLiteAdmin and will be overridden -// by the optional configuration file. Feel free to edit below if you want to use -// phpLiteAdmin as a single file; otherwise, rename phpliteadmin.config.sample.php to -// phpliteadmin.config.php and edit it. // -// Please see http://code.google.com/p/phpliteadmin/wiki/Configuration for more details +// This is sample configuration file +// +// You can configure phpliteadmin in one of 2 ways: +// 1. Rename phpliteadmin.config.sample.php to phpliteadmin.config.php and change parameters in there. +// You can set only your custom settings in phpliteadmin.config.php. All other settings will be set to defaults. +// 2. Change parameters directly in main phpliteadmin.php file +// +// Please see https://bitbucket.org/phpliteadmin/public/wiki/Configuration for more details //password to gain access $password = ''; -// Theme! If you want to change theme, save the CSS file in same folder of phpliteadmin or in folder 'themes' -$theme = 'phpliteadmin.css'; - -// the default language! If you want to change it, save the language file in same folder of phpliteadmin or in folder 'languages' -// More about localizations (downloads, how to translate etc.): http://code.google.com/p/phpliteadmin/wiki/Localization -$language = 'en'; - -// set default number of rows. You need to relog after changing the number -$rowsNum = 30; - -// reduce string characters by a number bigger than 10 -$charsNum = 300; - //directory relative to this file to search for databases (if false, manually list databases in the $databases variable) $directory = false; @@ -102,31 +89,57 @@ //AstLinux// end of define database files +/* ---- Interface settings ---- */ + +// Theme! If you want to change theme, save the CSS file in same folder of phpliteadmin or in folder "themes" +$theme = 'phpliteadmin.css'; + +// the default language! If you want to change it, save the language file in same folder of phpliteadmin or in folder "languages" +// More about localizations (downloads, how to translate etc.): https://bitbucket.org/phpliteadmin/public/wiki/Localization +$language = 'en'; + +// set default number of rows. You need to relog after changing the number +$rowsNum = 30; + +// reduce string characters by a number bigger than 10 +$charsNum = 300; + +// maximum number of SQL queries to save in the history +$maxSavedQueries = 10; + +/* ---- Custom functions ---- */ + //a list of custom functions that can be applied to columns in the databases //make sure to define every function below if it is not a core PHP function -$custom_functions = array('md5', 'sha1', 'time', 'strtotime'); +$custom_functions = array( + 'md5', 'sha1', 'time', 'strtotime', + // add the names of your custom functions to this array + /* 'leet_text', */ +); +// define your custom functions here +/* +function leet_text($value) +{ + return strtr($value, 'eaAsSOl', '344zZ01'); +} +*/ + + +/* ---- Advanced options ---- */ + //changing the following variable allows multiple phpLiteAdmin installs to work under the same domain. $cookie_name = 'pla3412'; //whether or not to put the app in debug mode where errors are outputted $debug = false; -// the user is allowed to create databases with only these extensions +// the user is allowed to create databases with only these extensions $allowed_extensions = array('db','db3','sqlite','sqlite3'); -//////////////////////////// -//END USER-DEFINED VARIABLES -// load optional configuration file -//$config_filename = './phpliteadmin.config.php'; -//if (is_readable($config_filename)) { -// include_once $config_filename; -//} - - -// Start English language-texts -// Read our wiki on how to translate: http://code.google.com/p/phpliteadmin/wiki/Localization +// English language-texts. +// Read our wiki on how to translate: https://bitbucket.org/phpliteadmin/public/wiki/Localization $lang = array( "direction" => "LTR", "date_format" => 'M d H:i:s T Y', //AstLinux// @@ -135,6 +148,7 @@ "to" => "to", "go" => "Go", "yes" => "Yes", + "no" => "No", "sql" => "SQL", "csv" => "CSV", "csv_tbl" => "Table that CSV pertains to", @@ -178,6 +192,9 @@ "autoincrement" => "Autoincrement", "not_null" => "Not NULL", "attention" => "Attention", + "none" => "None", + "as_defined" => "As defined", + "expression" => "Expression", "sqlite_ext" => "SQLite extension", "sqlite_ext_support" => "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use %s until you install at least one of them.", @@ -187,6 +204,7 @@ "sqlite_limit" => "Due to the limitations of SQLite, only the field name and data type can be modified.", "php_v" => "PHP version", + "new_version" => "There is a new version!", "db_dump" => "database dump", "db_f" => "database file", @@ -218,6 +236,8 @@ "bad_php_directive" => "It appears that the PHP directive, 'register_globals' is enabled. This is bad. You need to disable it before continuing.", "page_gen" => "Page generated in %s seconds.", "powered" => "Powered by", + "free_software" => "This is free software.", + "please_donate" => "Please donate.", "remember" => "Remember me", "no_db" => "Welcome to %s. It appears that you have selected to scan a directory for databases to manage. However, %s could not find any valid SQLite databases. You may use the form below to create your first database.", "no_db2" => "The directory you specified does not contain any existing databases to manage, and the directory is not writable. This means you can't create any new databases using %s. Either make the directory writable or manually upload databases to the directory.", @@ -279,15 +299,19 @@ "query_time" => "(Query took %s sec)", "syntax_err" => "There is a problem with the syntax of your query (Query was not executed)", "run_sql" => "Run SQL query/queries on database '%s'", + "recent_queries" => "Recent Queries", + "full_texts" => "Show full texts", + "no_full_texts" => "Shorten long texts", "ques_empty" => "Are you sure you want to empty the table '%s'?", "ques_drop" => "Are you sure you want to drop the table '%s'?", "ques_drop_view" => "Are you sure you want to drop the view '%s'?", "ques_del_rows" => "Are you sure you want to delete row(s) %s from table '%s'?", "ques_del_db" => "Are you sure you want to delete the database '%s'?", - "ques_del_col" => "Are you sure you want to delete column(s) %s from table '%s'?", + "ques_column_delete" => "Are you sure you want to delete column(s) %s from table '%s'?", "ques_del_index" => "Are you sure you want to delete index '%s'?", "ques_del_trigger" => "Are you sure you want to delete trigger '%s'?", + "ques_primarykey_add" => "Are you sure you want to add a primary key for the column(s) %s in table '%s'?", "export_struct" => "Export with structure", "export_data" => "Export with data", @@ -356,6 +380,7 @@ "warn0" => "You have been warned.", "warn_passwd" => "You are using the default password, which can be dangerous. You can change it easily at the top of %s.", "warn_dumbass" => "You didn't change the value dumbass ;-)", + "counting_skipped" => "Counting of records has been skipped for some tables because your database is comparably big and some tables don't have primary keys assigned to them so counting might be slow. Add a primary key to these tables or %sforce counting%s.", "sel_state" => "Select Statement", "delimit" => "Delimiter", "back_top" => "Back to Top", @@ -402,26 +427,37 @@ "help8_x" => "During the process for exporting to an SQL file, you may choose to wrap the queries around a TRANSACTION so that if an error occurs at any time during the importation process using the exported file, the database can be reverted to its previous state, preventing partially updated data from populating the database.", "help9" => "Add Comments to Exported SQL File", "help9_x" => "During the process for exporting to an SQL file, you may choose to include comments that explain each step of the process so that a human can better understand what is happening." - - ); +); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //there is no reason for the average user to edit anything below this comment //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +//- Initialization + +//AstLinux// +// load optional configuration file +//$config_filename = './phpliteadmin.config.php'; +//if (is_readable($config_filename)) { +// include_once $config_filename; +//} + //constants 1 define("PROJECT", "phpLiteAdmin"); -define("VERSION", "1.9.4.1"); +define("VERSION", "1.9.6"); define("PAGE", basename(__FILE__)); //AstLinux// Force PDO define("FORCETYPE", "PDO"); //force the extension that will be used (set to false in almost all circumstances except debugging) define("SYSTEMPASSWORD", $password); // Makes things easier. -define('PROJECT_URL','http://phpliteadmin.googlecode.com'); -define('PROJECT_BUGTRACKER_LINK','<a href="http://code.google.com/p/phpliteadmin/issues/list" target="_blank">http://code.google.com/p/phpliteadmin/issues/list</a>'); +define('PROJECT_URL','https://bitbucket.org/phpliteadmin/public'); +define('DONATE_URL','http://phpliteadmin.christosoft.de/donate.php'); +define('VERSION_CHECK_URL','https://phpliteadmin.christosoft.de/current_version.php'); +define('PROJECT_BUGTRACKER_LINK','<a href="https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open" target="_blank">https://bitbucket.org/phpliteadmin/public/issues?status=new&status=open</a>'); +define('PROJECT_INSTALL_LINK','<a href="https://bitbucket.org/phpliteadmin/public/wiki/Installation" target="_blank">https://bitbucket.org/phpliteadmin/public/wiki/Installation</a>'); // Resource output (css and javascript files) -//AstLinux// Remove all 'resource' related code, use external files instead +//AstLinux// Remove all 'resource' (?resource=) related code, use .js and .css external files instead // don't mess with this - required for the login session ini_set('session.cookie_httponly', '1'); @@ -452,10 +488,13 @@ // load language file if($language != 'en') { + $temp_lang=$lang; if(is_file('languages/lang_'.$language.'.php')) include('languages/lang_'.$language.'.php'); elseif(is_file('lang_'.$language.'.php')) include('lang_'.$language.'.php'); + $lang = array_merge($temp_lang, $lang); + unset($temp_lang); } // version-number added so after updating, old session-data is not used anylonger // cookies names cannot contain symbols, except underscores @@ -482,14 +521,13 @@ //data types array -$types = array("INTEGER", "REAL", "TEXT", "BLOB"); -define("DATATYPES", serialize($types)); +$sqlite_datatypes = array("INTEGER", "REAL", "TEXT", "BLOB","NUMERIC","BOOLEAN","DATETIME"); //available SQLite functions array (don't add anything here or there will be problems) -$functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper"); -define("FUNCTIONS", serialize($functions)); -define("CUSTOM_FUNCTIONS", serialize($custom_functions)); +$sqlite_functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper"); +//- Support functions + //function that allows SQL delimiter to be ignored inside comments or strings function explode_sql($delimiter, $sql) { @@ -582,7 +620,7 @@ function helpLink($name) { global $lang; - return "<a href='".PAGE."?help=1' onclick='openHelp(\"".$name."\"); return false;' class='helpq' title='".$lang['help'].": ".$name."' target='_blank'><span>[?]</span></a>"; + return "<a href='?help=1' onclick='openHelp(\"".$name."\"); return false;' class='helpq' title='".$lang['help'].": ".$name."' target='_blank'><span>[?]</span></a>"; } // function to encode value into HTML just like htmlentities, but with adjusted default settings @@ -602,19 +640,13 @@ function subString($str) { global $charsNum; - if($charsNum > 10){ - if(strlen($str)>$charsNum) $str = substr($str, 0, $charsNum).'...'; + if($charsNum > 10 && !$_SESSION[COOKIENAME.'fulltexts'] && strlen($str)>$charsNum) + { + $str = substr($str, 0, $charsNum).'...'; } return $str; } -function getRowId($table, $where=''){ - global $db; - $query = "SELECT ROWID FROM ".$db->quote_id($table).$where; - $result = $db->selectArray($query); - return $result; -} - // checks the (new) name of a database file function checkDbName($name) { @@ -649,7 +681,3538 @@ return false; } +// from a typename of a colun, get the type of the column's affinty +// see http://www.sqlite.org/datatype3.html section 2.1 for rules +function get_type_affinity($type) +{ + if (preg_match("/INT/i", $type)) + return "INTEGER"; + else if (preg_match("/(?:CHAR|CLOB|TEXT)/i", $type)) + return "TEXT"; + else if (preg_match("/BLOB/i", $type) || $type=="") + return "NONE"; + else if (preg_match("/(?:REAL|FLOA|DOUB)/i", $type)) + return "REAL"; + else + return "NUMERIC"; +} + + +//- Check user authentication, login and logout +$auth = new Authorization(); //create authorization object + +//AstLinux// +// check if user has attempted to log out +//if (isset($_POST['logout'])) +// $auth->revoke(); +// check if user has attempted to log in +//else if (isset($_POST['login']) && isset($_POST['password'])) +// $auth->attemptGrant($_POST['password'], isset($_POST['remember'])); + +//- Actions on database files and bulk data +if ($auth->isAuthorized()) +{ + + //- Create a new database + if(isset($_POST['new_dbname'])) + { + if($_POST['new_dbname']=='') + { + // TODO: Display an error message (do NOT echo here. echo below in the html-body!) + } + else + { + $str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']); + $dbname = $str; + $dbpath = $str; + if(checkDbName($dbname)) + { + $tdata = array(); + $tdata['name'] = $dbname; + $tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath; + $td = new Database($tdata); + $td->query("VACUUM"); + } else + { + if(is_file($dbname) || is_dir($dbname)) $dbexists = true; + else $extension_not_allowed=true; + } + } + } + + //- Scan a directory for databases + if($directory!==false) + { + if($directory[strlen($directory)-1]==DIRECTORY_SEPARATOR) //if user has a trailing slash in the directory, remove it + $directory = substr($directory, 0, strlen($directory)-1); + + if(is_dir($directory)) //make sure the directory is valid + { + if($subdirectories===true) + $arr = dir_tree($directory); + else + $arr = scandir($directory); + $databases = array(); + $j = 0; + for($i=0; $i<sizeof($arr); $i++) //iterate through all the files in the databases + { + if($subdirectories===false) + $arr[$i] = $directory.DIRECTORY_SEPARATOR.$arr[$i]; + + if(@!is_file($arr[$i])) continue; + $con = file_get_contents($arr[$i], NULL, NULL, 0, 60); + if(strpos($con, "** This file contains an SQLite 2.1 database **", 0)!==false || strpos($con, "SQLite format 3", 0)!==false) + { + $databases[$j]['path'] = $arr[$i]; + if($subdirectories===false) + $databases[$j]['name'] = basename($arr[$i]); + else + $databases[$j]['name'] = $arr[$i]; + $databases[$j]['writable'] = is_writable($databases[$j]['path']); + $databases[$j]['writable_dir'] = is_writable(dirname($databases[$j]['path'])); + $databases[$j]['readable'] = is_readable($databases[$j]['path']); + $j++; + } + } + // 22 August 2011: gkf fixed bug #50. + sort($databases); + if(isset($tdata)) + { + foreach($databases as $db_id => $database) + { + if($database['path'] == $tdata['path']) + { + $_SESSION[COOKIENAME.'currentDB'] = $database; + break; + } + } + } + } + else //the directory is not valid - display error and exit + { + echo "<div class='confirm' style='margin:20px;'>".$lang['not_dir']."</div>"; + exit(); + } + } + else + { + for($i=0; $i<sizeof($databases); $i++) + { + if(!file_exists($databases[$i]['path'])) + continue; //skip if file not found ! - probably a warning can be displayed - later + $databases[$i]['writable'] = is_writable($databases[$i]['path']); + $databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path'])); + $databases[$i]['readable'] = is_readable($databases[$i]['path']); + } + sort($databases); + } + // we now have the $databases array set. Check whethet currentDB is a managed Db (is in this array) + if(isset($_SESSION[COOKIENAME.'currentDB']) && isManagedDB($_SESSION[COOKIENAME.'currentDB']['path']) === false) + unset($_SESSION[COOKIENAME.'currentDB']); + + //- Delete an existing database + if(isset($_GET['database_delete'])) + { + $dbpath = $_POST['database_delete']; + // check whether $dbpath really is a db we manage + $checkDB = isManagedDB($dbpath); + if($checkDB !== false) + { + unlink($dbpath); + unset($_SESSION[COOKIENAME.'currentDB']); + unset($databases[$checkDB]); + } else die($lang['err'].': '.$lang['delete_only_managed']); + } + + //- Rename an existing database + if(isset($_GET['database_rename'])) + { + $oldpath = $_POST['oldname']; + $newpath = $_POST['newname']; + $oldpath_parts = pathinfo($oldpath); + $newpath_parts = pathinfo($newpath); + // only rename? + $newpath = $oldpath_parts['dirname'].DIRECTORY_SEPARATOR.basename($_POST['newname']); + if($newpath != $_POST['newname'] && $subdirectories) + { + // it seems that the file should not only be renamed but additionally moved. + // we need to make sure it stays within $directory... + $new_realpath = realpath($newpath_parts['dirname']).DIRECTORY_SEPARATOR; + $directory_realpath = realpath($directory).DIRECTORY_SEPARATOR; + if(strpos($new_realpath, $directory_realpath)===0) + { + // its okay, the new directory is within $directory + $newpath = $_POST['newname']; + } + else die($lang['err'].': '.$lang['db_moved_outside']); + } + + if(checkDbName($newpath)) + { + $checkDB = isManagedDB($oldpath); + if($checkDB !==false ) + { + rename($oldpath, $newpath); + $databases[$checkDB]['path'] = $newpath; + $databases[$checkDB]['name'] = basename($newpath); + $_SESSION[COOKIENAME.'currentDB'] = $databases[$checkDB]; + $justrenamed = true; + } + else die($lang['err'].': '.$lang['rename_only_managed']); + } + else + { + if(is_file($newpath) || is_dir($newpath)) $dbexists = true; + else $extension_not_allowed = true; + } + } + + + //- Export (download a dump) an existing database + if(isset($_POST['export'])) + { + $export_filename = str_replace(array("\r", "\n"), '',$_POST['filename']); // against http header injection (php < 5.1.2 only) + if($_POST['export_type']=="sql") + { + header('Content-Type: text/sql'); + header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";'); + if(isset($_POST['tables'])) + $tables = $_POST['tables']; + else + { + $tables = array(); + $tables[0] = $_POST['single_table']; + } + $drop = isset($_POST['drop']); + $structure = isset($_POST['structure']); + $data = isset($_POST['data']); + $transaction = isset($_POST['transaction']); + $comments = isset($_POST['comments']); + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + echo $db->export_sql($tables, $drop, $structure, $data, $transaction, $comments); + } + else if($_POST['export_type']=="csv") + { + header("Content-type: application/csv"); + header('Content-Disposition: attachment; filename="'.$export_filename.'.'.$_POST['export_type'].'";'); + header("Pragma: no-cache"); + header("Expires: 0"); + if(isset($_POST['tables'])) + $tables = $_POST['tables']; + else + { + $tables = array(); + $tables[0] = $_POST['single_table']; + } + $field_terminate = $_POST['export_csv_fieldsterminated']; + $field_enclosed = $_POST['export_csv_fieldsenclosed']; + $field_escaped = $_POST['export_csv_fieldsescaped']; + $null = $_POST['export_csv_replacenull']; + $crlf = isset($_POST['export_csv_crlf']); + $fields_in_first_row = isset($_POST['export_csv_fieldnames']); + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + echo $db->export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row); + } + exit(); + } + + //- Import a file into an existing database + if(isset($_POST['import'])) + { + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + $db->registerUserFunction($custom_functions); + //AstLinux// missing file fix. + if ($_FILES["file"]["tmp_name"] !== '') { + if($_POST['import_type']=="sql") + { + $data = file_get_contents($_FILES["file"]["tmp_name"]); + $importSuccess = $db->import_sql($data); + } + else + { + $field_terminate = $_POST['import_csv_fieldsterminated']; + $field_enclosed = $_POST['import_csv_fieldsenclosed']; + $field_escaped = $_POST['import_csv_fieldsescaped']; + $null = $_POST['import_csv_replacenull']; + $fields_in_first_row = isset($_POST['import_csv_fieldnames']); + $importSuccess = $db->import_csv($_FILES["file"]["tmp_name"], $_POST['single_table'], $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row); + } + } + else + { + $importSuccess = 'No File Selected, choose a file.'; + } + //AstLinux// end of missing file fix. + } + //- Download (backup) a database file (as SQLite file, not as dump) + if(isset($_GET['download']) && isManagedDB($_GET['download'])!==false) + { + header("Content-type: application/octet-stream"); + header('Content-Disposition: attachment; filename="'.basename($_GET['download']).'";'); + header("Pragma: no-cache"); + header("Expires: 0"); + readfile($_GET['download']); + exit; + } +} + +//- HTML: output starts here +header('Content-Type: text/html; charset=utf-8'); +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> --> +<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> +<title><?php echo PROJECT ?></title> + +<?php +//AstLinux// use external style sheet. +echo "<link href='/common/phpliteadmin.css' rel='stylesheet' type='text/css' />", PHP_EOL; +//- HTML: css/theme include +//if(isset($_GET['theme'])) $theme = basename($_GET['theme']); // +// allow themes to be dropped in subfolder "themes" +//if(is_file('themes/'.$theme)) $theme = 'themes/'.$theme; +// +//if (file_exists($theme)) +// // an external stylesheet exists - import it +// echo "<link href='{$theme}' rel='stylesheet' type='text/css' />", PHP_EOL; +//else +// // only use the default stylesheet if an external one does not exist +// echo "<link href='?resource=css' rel='stylesheet' type='text/css' />", PHP_EOL; +//AstLinux// + +// HTML: output help text, then exit +if(isset($_GET['help'])) +{ + //help section array + $help = array + ( + $lang['help1'] => sprintf($lang['help1_x'], PROJECT, PROJECT, PROJECT), $lang['help2'] => $lang['help2_x'], $lang['help3'] => $lang['help3_x'], + $lang['help4'] => $lang['help4_x'], $lang['help5'] => $lang['help5_x'], $lang['help6'] => $lang['help6_x'], + $lang['help7'] => $lang['help7_x'], $lang['help8'] => $lang['help8_x'], $lang['help9'] => $lang['help9_x'] + ); + ?> + </head> + <body style="direction:<?php echo $lang['direction']; ?>;"> + <div id='help_container'> + <?php + echo "<div class='help_list'>"; + echo "<span style='font-size:18px;'>".PROJECT." v".VERSION." ".$lang['help_doc']."</span><br/><br/>"; + foreach((array)$help as $key => $val) + { + echo "<a href='#".$key."'>".$key."</a><br/>"; + } + echo "</div>"; + echo "<br/><br/>"; + foreach((array)$help as $key => $val) + { + echo "<div class='help_outer'>"; + echo "<a class='headd' name='".$key."'>".$key."</a>"; + echo "<div class='help_inner'>"; + echo $val; + echo "</div>"; + echo "<a class='help_top' href='#top'>".$lang['back_top']."</a>"; + echo "</div>"; + } + ?> + </div> + </body> + </html> + <?php + exit(); +} + +//- Javascript include +?> +<!-- JavaScript Support --> +<script type='text/javascript' src='/common/phpliteadmin.js'></script> +</head> +<body style="direction:<?php echo $lang['direction']; ?>;"> +<?php +if(ini_get("register_globals") == "on" || ini_get("register_globals")=="1") //check whether register_globals is turned on - if it is, we need to not continue +{ + echo "<div class='confirm' style='margin:20px;'>".$lang['bad_php_directive']."</div>"; + echo "</body></html>"; + exit(); +} + +//- HTML: login screen if not authorized, exit +if(!$auth->isAuthorized()) +{ + echo "<div id='loginBox'>"; + echo "<h1><span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span></h1>"; + echo "<div style='padding:15px; text-align:center;'>"; + if ($auth->isFailedLogin()) + echo "<span class='warning'>".$lang['passwd_incorrect']."</span><br/><br/>"; + echo "<form action='".PAGE."' method='post'>"; + echo $lang['passwd'].": <input type='password' name='password'/><br/>"; + echo "<label><input type='checkbox' name='remember' value='yes' checked='checked'/> ".$lang['remember']."</label><br/><br/>"; + echo "<input type='submit' value='".$lang['login']."' class='btn'/>"; + echo "<input type='hidden' name='login' value='true' />"; + echo "</form>"; + echo "</div>"; + echo "</div>"; + echo "<br/>"; + //AstLinux// + //echo "<div style='text-align:center;'>"; + //echo "<span style='font-size:11px;'>".$lang['powered']." <a href='".PROJECT_URL."' target='_blank' style='font-size:11px;'>".PROJECT."</a> | "; + //printf($lang['page_gen'], $pageTimer); + //echo "</span></div>"; + echo "</body></html>"; + exit(); +} + +//- User is authorized, display the main application + +//- Select database (from session or first available) +if(!isset($_SESSION[COOKIENAME.'currentDB']) && count($databases)>0) +{ + //set the current database to the first existing one in the array (default) + $_SESSION[COOKIENAME.'currentDB'] = reset($databases); +} +if(sizeof($databases)>0) + $currentDB = $_SESSION[COOKIENAME.'currentDB']; +else // the database array is empty, offer to create a new database +{ + //- HTML: form to create a new database, exit + if($directory!==false && is_writable($directory)) + { + echo "<div class='confirm' style='margin:20px;'>"; + printf($lang['no_db'], PROJECT, PROJECT); + echo "</div>"; + if(isset($extension_not_allowed)) + { + echo "<div class='confirm' style='margin:10px 20px;'>"; + echo $lang['err'].': '.$lang['extension_not_allowed'].': '; + echo implode(', ', array_map('htmlencode', $allowed_extensions)); + echo '<br />'.$lang['add_allowed_extension']; + echo "</div><br/>"; + } + echo "<fieldset style='margin:15px;'><legend><b>".$lang['db_create']."</b></legend>"; + echo "<form name='create_database' method='post' action='".PAGE."'>"; + echo "<input type='text' name='new_dbname' style='width:150px;'/> <input type='submit' value='".$lang['create']."' class='btn'/>"; + echo "</form>"; + echo "</fieldset>"; + } + else + { + echo "<div class='confirm' style='margin:20px;'>"; + echo $lang['err'].": ".sprintf($lang['no_db2'], PROJECT); + echo "</div><br/>"; + } + exit(); +} + +//- Switch to a different database with drop-down menu +if(isset($_POST['database_switch'])) +{ + foreach($databases as $db_id => $database) + { + if($database['path'] == $_POST['database_switch']) + { + $_SESSION[COOKIENAME."currentDB"] = $database; + break; + } + } + $currentDB = $_SESSION[COOKIENAME.'currentDB']; +} +else if(isset($_GET['switchdb'])) +{ + foreach($databases as $db_id => $database) + { + if($database['path'] == $_GET['switchdb']) + { + $_SESSION[COOKIENAME."currentDB"] = $database; + break; + } + } + $currentDB = $_SESSION[COOKIENAME.'currentDB']; +} +if(isset($_SESSION[COOKIENAME.'currentDB']) && in_array($_SESSION[COOKIENAME.'currentDB'], $databases)) + $currentDB = $_SESSION[COOKIENAME.'currentDB']; + +//- Open database (creates a Database object) +$db = new Database($currentDB); //create the Database object +$db->registerUserFunction($custom_functions); + +// collect parameters early, just once +$target_table = isset($_GET['table']) ? $_GET['table'] : null; + +//- Switch on $_GET['action'] for operations without output +if(isset($_GET['action']) && isset($_GET['confirm'])) +{ + switch($_GET['action']) + { + //- Table actions + + //- Create table (=table_create) + case "table_create": + if ($global_user === 'staff') { //AstLinux// + $completed = "Failed: Insufficient 'staff' user privileges for action: ".$_GET['action']; + } else { + $num = intval($_POST['rows']); + $name = $_POST['tablename']; + $primary_keys = array(); + for($i=0; $i<$num; $i++) + { + if($_POST[$i.'_field']!="" && isset($_POST[$i.'_primarykey'])) + { + $primary_keys[] = $_POST[$i.'_field']; + } + } + $query = "CREATE TABLE ".$db->quote($name)." ("; + for($i=0; $i<$num; $i++) + { + if($_POST[$i.'_field']!="") + { + $query .= $db->quote($_POST[$i.'_field'])." "; + $query .= $_POST[$i.'_type']." "; + if(isset($_POST[$i.'_primarykey'])) + { + if(count($primary_keys)==1) + { + $query .= "PRIMARY KEY "; + if(isset($_POST[$i.'_autoincrement']) && $db->getType() != "SQLiteDatabase") + $query .= "AUTOINCREMENT "; + } + $query .= "NOT NULL "; + } + if(!isset($_POST[$i.'_primarykey']) && isset($_POST[$i.'_notnull'])) + $query .= "NOT NULL "; + if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr') + $query .= "DEFAULT ".$_POST[$i.'_defaultoption']." "; + elseif($_POST[$i.'_defaultoption']=='expr') + $query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") "; + elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined') + { + $typeAffinity = get_type_affinity($_POST[$i.'_type']); + if(($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC") && is_numeric($_POST[$i.'_defaultvalue'])) + $query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." "; + else + $query .= "DEFAULT ".$db->quote($_POST[$i.'_defaultvalue'])." "; + } + $query = substr($query, 0, sizeof($query)-2); + $query .= ", "; + } + } + if (count($primary_keys)>1) + { + $compound_key = ""; + foreach ($primary_keys as $primary_key) + { + $compound_key .= ($compound_key=="" ? "" : ", ") . $db->quote($primary_key); + } + $query .= "PRIMARY KEY (".$compound_key."), "; + } + $query = substr($query, 0, sizeof($query)-3); + $query .= ")"; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($_POST['tablename'])."' ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + } //AstLinux// + $backlinkParameters = "&action=column_view&table=".urlencode($name); + break; + + //- Empty table (=table_empty) + case "table_empty": + if ($global_user === 'staff') { //AstLinux// + $completed = "Failed: Insufficient 'staff' user privileges for action: ".$_GET['action']; + } else { + $query = "DELETE FROM ".$db->quote_id($_POST['tablename']); + $result = $db->query($query); + if($result===false) + $error = true; + $query = "VACUUM"; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($_POST['tablename'])."' ".$lang['emptied'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + } //AstLinux// + $backlinkParameters = "&action=row_view&table=".urlencode($name); + break; + + //- Create view (=view_create) + case "view_create": + if ($global_user === 'staff') { //AstLinux// + $completed = "Failed: Insufficient 'staff' user privileges for action: ".$_GET['action']; + } else { + $query = "CREATE VIEW ".$db->quote($_POST['viewname'])." AS ".$_POST['select']; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['view']." '".htmlencode($_POST['viewname'])."' ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + } //AstLinux// + $backlinkParameters = "&action=column_view&table=".urlencode($_POST['viewname']); + break; + + //- Drop table (=table_drop) + case "table_drop": + if ($global_user === 'staff') { //AstLinux// + $completed = "Failed: Insufficient 'staff' user privileges for action: ".$_GET['action']; + } else { + $query = "DROP TABLE ".$db->quote_id($_POST['tablename']); + $result=$db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($_POST['tablename'])."' ".$lang['dropped']."."; + } //AstLinux// + $backlinkParameters = ""; + break; + + //- Drop view (=view_drop) + case "view_drop": + if ($global_user === 'staff') { //AstLinux// + $completed = "Failed: Insufficient 'staff' user privileges for action: ".$_GET['action']; + } else { + $query = "DROP VIEW ".$db->quote_id($_POST['viewname']); + $result=$db->query($query); + if($result===false) + $error = true; + $completed = $lang['view']." '".htmlencode($_POST['viewname'])."' ".$lang['dropped']."."; + } //AstLinux// + $backlinkParameters = ""; + break; + + //- Rename table (=table_rename) + case "table_rename": + $query = "ALTER TABLE ".$db->quote_id($_POST['oldname'])." RENAME TO ".$db->quote($_POST['newname']); + if($db->getVersion()==3) + $result = $db->query($query, true); + else + $result = $db->query($query, false); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($_POST['oldname'])."' ".$lang['renamed']." '".htmlencode($_POST['newname'])."'.<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + $backlinkParameters = "&action=row_view&table=".urlencode($_POST['newname']); + break; + + //- Row actions + + //- Create row (=row_create) + case "row_create": + $completed = ""; + $num = $_POST['numRows']; + $fields = explode(":", $_POST['fields']); + $z = 0; + + $query = "PRAGMA table_info(".$db->quote_id($target_table).")"; + $result = $db->selectArray($query); + + for($i=0; $i<$num; $i++) + { + if(!isset($_POST[$i.":ignore"])) + { + $query_cols = ""; + $query_vals = ""; + $all_default = true; + for($j=0; $j<sizeof($fields); $j++) + { + // PHP replaces space with underscore + $fields[$j] = str_replace(" ","_",$fields[$j]); + + $null = isset($_POST[$i.":".$fields[$j]."_null"]); + if(!$null) + { + if(!isset($_POST[$i.":".$fields[$j]]) && $debug) + { + echo "MISSING POST INDEX (".$i.":".$fields[$j].")<br><pre />"; + var_dump($_POST); + echo "</pre><hr />"; + } + $value = $_POST[$i.":".$fields[$j]]; + } + else + $value = ""; + if($value===$result[$j]['dflt_value']) + { + // if the value is the default value, skip it + continue; + } else + $all_default = false; + $query_cols .= $db->quote_id($fields[$j]).","; + + $type = $result[$j]['type']; + $typeAffinity = get_type_affinity($type); + $function = $_POST["function_".$i."_".$fields[$j]]; + if($function!="") + $query_vals .= $function."("; + if(($typeAffinity=="TEXT" || $typeAffinity=="NONE") && !$null) + $query_vals .= $db->quote($value); + elseif(($typeAffinity=="INTEGER" || $typeAffinity=="REAL"|| $typeAffinity=="NUMERIC") && $value=="") + $query_vals .= "NULL"; + elseif($null) + $query_vals .= "NULL"; + else + $query_vals .= $db->quote($value); + if($function!="") + $query_vals .= ")"; + $query_vals .= ","; + } + $query = "INSERT INTO ".$db->quote_id($target_table); + if(!$all_default) + { + $query_cols = substr($query_cols, 0, strlen($query_cols)-1); + $query_vals = substr($query_vals, 0, strlen($query_vals)-1); + + $query.=" (". $query_cols . ") VALUES (". $query_vals. ")"; + } else { + $query .= " DEFAULT VALUES"; + } + $result1 = $db->query($query); + if($result1===false) + $error = true; + $completed .= "<span style='font-size:11px;'>".htmlencode($query)."</span><br/>"; + $z++; + } + } + $completed = $z." ".$lang['rows']." ".$lang['inserted'].".<br/><br/>".$completed; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Delete row (=row_delete) + case "row_delete": + $pks = json_decode($_GET['pk']); + + $query = "DELETE FROM ".$db->quote_id($target_table)." WHERE (".$db->wherePK($target_table,json_decode($pks[0])).")"; + for($i=1; $i<sizeof($pks); $i++) + { + $query .= " OR (".$db->wherePK($target_table,json_decode($pks[$i])).")"; + } + $result = $db->query($query); + if($result===false) + $error = true; + $completed = sizeof($pks)." ".$lang['rows']." ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + $backlinkParameters = "&action=row_view&table=".urlencode($target_table); + break; + + //- Edit row (=row_edit) + case "row_edit": + $pks = json_decode($_GET['pk']); + $fields = explode(":", $_POST['fieldArray']); + + $z = 0; + + $query = "PRAGMA table_info(".$db->quote_id($target_table).")"; + $result = $db->selectArray($query); + + if(isset($_POST['new_row'])) + $completed = ""; + else + $completed = sizeof($pks)." ".$lang['rows']." ".$lang['affected'].".<br/><br/>"; + + for($i=0; $i<sizeof($pks); $i++) + { + if(isset($_POST['new_row'])) + { + $query_cols = ""; + $query_vals = ""; + $all_default = true; + for($j=0; $j<sizeof($fields); $j++) + { + // PHP replaces space with underscore + $fields[$j] = str_replace(" ","_",$fields[$j]); + + $null = isset($_POST[$fields[$j]."_null"][$i]); + if(!$null) + { + $value = $_POST[$fields[$j]][$i]; + } + else + $value = ""; + if($value===$result[$j]['dflt_value']) + { + // if the value is the default value, skip it + continue; + } else + $all_default = false; + $query_cols .= $db->quote_id($fields[$j]).","; + + $type = $result[$j]['type']; + $typeAffinity = get_type_affinity($type); + $function = $_POST["function_".$fields[$j]][$i]; + if($function!="") + $query_vals .= $function."("; + if(($typeAffinity=="TEXT" || $typeAffinity=="NONE") && !$null) + $query_vals .= $db->quote($value); + elseif(($typeAffinity=="INTEGER" || $typeAffinity=="REAL"|| $typeAffinity=="NUMERIC") && $value=="") + $query_vals .= "NULL"; + elseif($null) + $query_vals .= "NULL"; + else + $query_vals .= $db->quote($value); + if($function!="") + $query_vals .= ")"; + $query_vals .= ","; + } + $query = "INSERT INTO ".$db->quote_id($target_table); + if(!$all_default) + { + $query_cols = substr($query_cols, 0, strlen($query_cols)-1); + $query_vals = substr($query_vals, 0, strlen($query_vals)-1); + + $query.=" (". $query_cols . ") VALUES (". $query_vals. ")"; + } else { + $query .= " DEFAULT VALUES"; + } + $result1 = $db->query($query); + if($result1===false) + $error = true; + $z++; + } + else + { + $query = "UPDATE ".$db->quote_id($target_table)." SET "; + for($j=0; $j<sizeof($fields); $j++) + { + $field_index = str_replace(" ","_",$fields[$j]); + $function = $_POST["function_".$field_index][$i]; + $null = isset($_POST[$field_index."_null"][$i]); + $query .= $db->quote_id($fields[$j])."="; + if($function!="") + $query .= $function."("; + if($null) + $query .= "NULL"; + else + $query .= $db->quote($_POST[$field_index][$i]); + if($function!="") + $query .= ")"; + $query .= ", "; + } + $query = substr($query, 0, sizeof($query)-3); + $query .= " WHERE ".$db->wherePK($target_table, json_decode($pks[$i])); + $result1 = $db->query($query); + if($result1===false) + { + $error = true; + } + } + $completed .= "<span style='font-size:11px;'>".htmlencode($query)."</span><br/>"; + } + if(isset($_POST['new_row'])) + $completed = $z." ".$lang['rows']." ".$lang['inserted'].".<br/><br/>".$completed; + $backlinkParameters = "&action=row_view&table=".urlencode($target_table); + break; + + //- Column actions + + //- Create column (=column_create) + case "column_create": + $num = intval($_POST['rows']); + for($i=0; $i<$num; $i++) + { + if($_POST[$i.'_field']!="") + { + $query = "ALTER TABLE ".$db->quote_id($target_table)." ADD ".$db->quote($_POST[$i.'_field'])." "; + $query .= $_POST[$i.'_type']." "; + if(isset($_POST[$i.'_primarykey'])) + $query .= "PRIMARY KEY "; + if(isset($_POST[$i.'_notnull'])) + $query .= "NOT NULL "; + if($_POST[$i.'_defaultoption']!='defined' && $_POST[$i.'_defaultoption']!='none' && $_POST[$i.'_defaultoption']!='expr') + $query .= "DEFAULT ".$_POST[$i.'_defaultoption']." "; + elseif($_POST[$i.'_defaultoption']=='expr') + $query .= "DEFAULT (".$_POST[$i.'_defaultvalue'].") "; + elseif(isset($_POST[$i.'_defaultvalue']) && $_POST[$i.'_defaultoption']=='defined') + { + $typeAffinity = get_type_affinity($_POST[$i.'_type']); + if(($typeAffinity=="INTEGER" || $typeAffinity=="REAL" || $typeAffinity=="NUMERIC") && is_numeric($_POST[$i.'_defaultvalue'])) + $query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." "; + else + $query .= "DEFAULT ".$db->quote($_POST[$i.'_defaultvalue'])." "; + } + if($db->getVersion()==3 && + ($_POST[$i.'_defaultoption']=='defined' || $_POST[$i.'_defaultoption']=='none' || $_POST[$i.'_defaultoption']=='NULL') + // Sqlite3 cannot add columns with default values that are not constant, so use AlterTable-workaround + && !isset($_POST[$i.'_primarykey'])) // sqlite3 cannot add primary key columns + $result = $db->query($query, true); + else + $result = $db->query($query, false); + if($result===false) + $error = true; + } + } + $completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered']."."; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Delete column (=column_delete) + case "column_delete": + $pks = explode(":", $_GET['pk']); + $query = "ALTER TABLE ".$db->quote_id($target_table).' DROP '.$db->quote_id($pks[0]); + for($i=1; $i<sizeof($pks); $i++) + { + $query .= ", DROP ".$db->quote_id($pks[$i]); + } + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered']."."; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Add a primary key (=primarykey_add) + case "primarykey_add": + $pks = explode(":", $_GET['pk']); + $query = "ALTER TABLE ".$db->quote_id($target_table).' ADD PRIMARY KEY ('.$db->quote_id($pks[0]); + for($i=1; $i<sizeof($pks); $i++) + { + $query .= ", ".$db->quote_id($pks[$i]); + } + $query .= ")"; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered']."."; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Edit column (=column_edit) + case "column_edit": + $query = "ALTER TABLE ".$db->quote_id($target_table).' CHANGE '.$db->quote_id($_POST['oldvalue'])." ".$db->quote($_POST['0_field'])." ".$_POST['0_type']; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['tbl']." '".htmlencode($target_table)."' ".$lang['altered']."."; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Delete trigger (=trigger_delete) + case "trigger_delete": + $query = "DROP TRIGGER ".$db->quote_id($_GET['pk']); + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['trigger']." '".htmlencode($_GET['pk'])."' ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Delete index (=index_delete) + case "index_delete": + $query = "DROP INDEX ".$db->quote_id($_GET['pk']); + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['index']." '".htmlencode($_GET['pk'])."' ".$lang['deleted'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Create trigger (=trigger_create) + case "trigger_create": + $str = "CREATE TRIGGER ".$db->quote($_POST['trigger_name']); + if($_POST['beforeafter']!="") + $str .= " ".$_POST['beforeafter']; + $str .= " ".$_POST['event']." ON ".$db->quote_id($target_table); + if(isset($_POST['foreachrow'])) + $str .= " FOR EACH ROW"; + if($_POST['whenexpression']!="") + $str .= " WHEN ".$_POST['whenexpression']; + $str .= " BEGIN"; + $str .= " ".$_POST['triggersteps']; + $str .= " END"; + $query = $str; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['trigger']." ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + + //- Create index (=index_create) + case "index_create": + $num = $_POST['num']; + if($_POST['name']=="") + { + $completed = $lang['blank_index']; + } + else if($_POST['0_field']=="") + { + $completed = $lang['one_index']; + } + else + { + $str = "CREATE "; + if($_POST['duplicate']=="no") + $str .= "UNIQUE "; + $str .= "INDEX ".$db->quote($_POST['name'])." ON ".$db->quote_id($target_table)." ("; + $str .= $db->quote_id($_POST['0_field']).$_POST['0_order']; + for($i=1; $i<$num; $i++) + { + if($_POST[$i.'_field']!="") + $str .= ", ".$db->quote_id($_POST[$i.'_field']).$_POST[$i.'_order']; + } + $str .= ")"; + $query = $str; + $result = $db->query($query); + if($result===false) + $error = true; + $completed = $lang['index']." ".$lang['created'].".<br/><span style='font-size:11px;'>".htmlencode($query)."</span>"; + } + $backlinkParameters = "&action=column_view&table=".urlencode($target_table); + break; + } +} + +// are we working on a view? let's check once here +$target_table_type = $target_table ? $db->getTypeOfTable($target_table) : null; + +//- HTML: sidebar +echo '<table class="body_tbl" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="left_td" style="width:100px; padding:9px 2px 9px 9px;">'; +echo "<div id='leftNav'>"; +//AstLinux// +//echo "<h1><a href='".PAGE."'>"; +//echo "<span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span>"; +//echo "</a></h1>"; +//echo "<div id='headerlinks'>"; +//echo "<a href='javascript:void' onclick='openHelp(\"top\");'>".$lang['docu']."</a> | "; +//echo "<a href='http://www.gnu.org/licenses/gpl.html' target='_blank'>".$lang['license']."</a> | "; +//echo "<a href='".PROJECT_URL."' target='_blank'>".$lang['proj_site']."</a>"; +//echo "</div>"; + +//- HTML: database list +echo "<fieldset style='margin:15px;'><legend><b>".$lang['db_ch']."</b></legend>"; +if(sizeof($databases)<10) //if there aren't a lot of databases, just show them as a list of links instead of drop down menu +{ + $i=0; + foreach($databases as $database) + { + $i++; + echo '[' . ($database['readable'] ? 'r':' ' ) . ($database['writable'] && $database['writable_dir'] ? 'w':' ' ) . '] '; + if($database == $_SESSION[COOKIENAME.'currentDB']) + echo "<a href='?switchdb=".urlencode($database['path'])."' class='active_db'>".htmlencode($database['name'])."</a> (<a href='?download=".urlencode($database['path'])."' title='".$lang['backup']."'>↓</a>)"; + else + echo "<a href='?switchdb=".urlencode($database['path'])."'>".htmlencode($database['name'])."</a> (<a href='?download=".urlencode($database['path'])."' title='".$lang['backup']."'>↓</a>)"; + if($i<sizeof($databases)) + echo "<br/>"; + } +} +else //there are a lot of databases - show a drop down menu +{ + echo "<form action='".PAGE."' method='post'>"; + echo "<select name='database_switch'>"; + foreach($databases as $database) + { + $perms_string = htmlencode('[' . ($database['readable'] ? 'r':' ' ) . ($database['writable'] && $database['writable_dir'] ? 'w':' ' ) . '] '); + if($database == $_SESSION[COOKIENAME.'currentDB']) + echo "<option value='".htmlencode($database['path'])."' selected='selected'>".$perms_string.htmlencode($database['name'])."</option>"; + else + echo "<option value='".htmlencode($database['path'])."'>".$perms_string.htmlencode($database['name'])."</option>"; + } + echo "</select> "; + echo "<input type='submit' value='".$lang['go']."' class='btn'>"; + echo "</form>"; +} +echo "</fieldset>"; +echo "<fieldset style='margin:15px;'><legend>"; +echo "<a href='".PAGE."'"; +if (!$target_table) + echo " class='active_table'"; +echo ">".htmlencode($currentDB['name'])."</a>"; +echo "</legend>"; + +//- HTML: table list +$query = "SELECT type, name FROM sqlite_master WHERE type='table' OR type='view' ORDER BY name"; +$result = $db->selectArray($query); +$j=0; +for($i=0; $i<sizeof($result); $i++) +{ + if(substr($result[$i]['name'], 0, 7)!="sqlite_" && $result[$i]['name']!="") + { + echo "<span class='sidebar_table'>[".$lang[$result[$i]['type']=='table'?'tbl':'view']."]</span> "; + echo "<a href='?action=row_view&table=".urlencode($result[$i]['name'])."'"; + if ($target_table == $result[$i]['name']) + echo " class='active_table'"; + echo ">".htmlencode($result[$i]['name'])."</a><br/>"; + $j++; + } +} +if($j==0) + echo $lang['no_tbl']; +echo "</fieldset>"; + +//- HTML: form to create a new database +if($directory!==false && is_writable($directory)) +{ + echo "<fieldset style='margin:15px;'><legend><b>".$lang['db_create']."</b> ".helpLink($lang['help2'])."</legend>"; + echo "<form name='create_database' method='post' action='".PAGE."'>"; + echo "<input type='text' name='new_dbname' style='width:150px;'/> <input type='submit' value='".$lang['create']."' class='btn'/>"; + echo "</form>"; + echo "</fieldset>"; +} + +//AstLinux// +//echo "<div style='text-align:center;'>"; +//echo "<form action='".PAGE."' method='post'>"; +//echo "<input type='submit' value='".$lang['logout']."' name='logout' class='btn'/>"; +//echo "</form>"; +//echo "</div>"; +echo "</div>"; +echo '</td><td valign="top" id="main_column" class="right_td" style="padding:9px 2px 9px 9px;">'; + +//- HTML: breadcrumb navigation +echo "<a href='".PAGE."'>".htmlencode($currentDB['name'])."</a>"; +if ($target_table) + echo " → <a href='?table=".urlencode($target_table)."&action=row_view'>".htmlencode($target_table)."</a>"; +echo "<br/><br/>"; + +//- HTML: confirmation panel +//if the user has performed some action, show the resulting message +if(isset($_GET['confirm'])) +{ + echo "<div id='main'>"; + echo "<div class='confirm'>"; + if(isset($error) && $error) //an error occured during the action, so show an error message + echo $lang['err'].": ".$db->getError()."<br/>".$lang['bug_report'].' '.PROJECT_BUGTRACKER_LINK; + else //action was performed successfully - show success message + echo $completed; + echo "</div>"; + if($_GET['action']=="row_delete" || $_GET['action']=="row_create" || $_GET['action']=="row_edit") + echo "<br/><br/><a href='?table=".urlencode($target_table)."&action=row_view'>".$lang['return']."</a>"; + else if($_GET['action']=="column_create" || $_GET['action']=="column_delete" || $_GET['action']=="column_edit" || $_GET['action']=="index_create" || $_GET['action']=="index_delete" || $_GET['action']=="trigger_delete" || $_GET['action']=="trigger_create") + echo "<br/><br/><a href='?table=".urlencode($target_table)."&action=column_view'>".$lang['return']."</a>"; + else + echo "<br/><br/><a href='".PAGE.(isset($backlinkParameters)?"?".$backlinkParameters:'')."'>".$lang['return']."</a>"; + echo "</div>"; +} + +//- Show the various tab views for a table +if(!isset($_GET['confirm']) && $target_table && isset($_GET['action']) && ($_GET['action']=="table_export" || $_GET['action']=="table_import" || $_GET['action']=="table_sql" || $_GET['action']=="row_view" || $_GET['action']=="row_create" || $_GET['action']=="column_view" || $_GET['action']=="table_rename" || $_GET['action']=="table_search" || $_GET['action']=="table_triggers")) +{ + //- HTML: tabs for tables + if($target_table_type == 'table') + { + echo "<a href='?table=".urlencode($target_table)."&action=row_view' "; + if($_GET['action']=="row_view") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['browse']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=column_view' "; + if($_GET['action']=="column_view") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['struct']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_sql' "; + if($_GET['action']=="table_sql") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['sql']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_search' "; + if($_GET['action']=="table_search") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['srch']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=row_create' "; + if($_GET['action']=="row_create") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['insert']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_export' "; + if($_GET['action']=="table_export") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['export']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_import' "; + if($_GET['action']=="table_import") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['import']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_rename' "; + if($_GET['action']=="table_rename") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['rename']."</a>"; + echo "<a href='?action=table_empty&table=".urlencode($target_table)."' "; + echo "class='tab empty'"; + echo ">".$lang['empty']."</a>"; + echo "<a href='?action=table_drop&table=".urlencode($target_table)."' "; + echo "class='tab drop'"; + echo ">".$lang['drop']."</a>"; + echo "<div style='clear:both;'></div>"; + } + else + //- HTML: tabs for views + { + echo "<a href='?table=".urlencode($target_table)."&action=row_view' "; + if($_GET['action']=="row_view") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['browse']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=column_view' "; + if($_GET['action']=="column_view") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['struct']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_sql' "; + if($_GET['action']=="table_sql") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['sql']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_search' "; + if($_GET['action']=="table_search") + echo "class='tab_pressed'"; + else + echo "class='tab'"; + echo ">".$lang['srch']."</a>"; + echo "<a href='?table=".urlencode($target_table)."&action=table_export' "; + if($_GET['action']=="table_export") + echo "class='tab_pressed'"; + else... [truncated message content] |