Commit 26b51dbafd714e28c0e33d3d49a654c3a6cbd82e

Authored by Edmar Moretti
1 parent 4af571d0

Inclusão da biblioteca phpliteadmin

ms_configura.php
... ... @@ -221,7 +221,7 @@ if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
221 221 Tipo:
222 222 {array}
223 223 */
224   - $editores = array("127.0.0.1","localhost");
  224 + $editores = "";//array("127.0.0.1","localhost");
225 225 /*
226 226 Variable: dir_tmp
227 227  
... ...
pacotes/phpliteadmin/README.txt 0 → 100644
... ... @@ -0,0 +1,45 @@
  1 +INSTALLATION:
  2 +
  3 + 1. Open phpliteadmin.php in a text editor.
  4 +
  5 + 2. If you want to have a directory scanned for your databases instead of listing them manually, specify the directory as the value of the $directory variable and skip to step 4.
  6 +
  7 + 3. If you want to specify your databases manually, set the value of the $directory variable as false and modify the $databases array to hold the databases you would like to manage.
  8 +
  9 + - The path field is the file path of the database relative to where phpliteadmin.php will be located on the server. For example, if phpliteadmin.php is located at "databases/manager/phpliteadmin.php" and you want to manage "databases/yourdatabase.sqlite", the path value would be "../yourdatabase.sqlite".
  10 +
  11 + - The name field is the human-friendly way of referencing the database within the application. It can be anything you want.
  12 +
  13 + 4. Modify the $password variable to be the password used for gaining access to the phpLiteAdmin tool.
  14 +
  15 + 5. If you want to have multiple installations of phpLiteAdmin on the same server, change the $cookie_name variable to be unique for each installation (optional).
  16 +
  17 + 6. Save and upload phpliteadmin.php to your web server.
  18 +
  19 + 7. Open a web browser and navigate to the uploaded phpliteadmin.php file. You will be prompted to enter a password. Use the same password you set in step 4.
  20 +
  21 +INSTALLING A THEME:
  22 +
  23 + 1. Download the themes package from the project Downloads page.
  24 +
  25 + 2. Unzip the file and choose your desired theme.
  26 +
  27 + 3. Upload phpliteadmin.css from the theme's directory alongside phpliteadmin.php.
  28 +
  29 + 4. Your theme will automatically override the default.
  30 +
  31 +REQUIREMENTS:
  32 +
  33 + - a server with PHP installed
  34 +
  35 + - at least one PHP SQLite library extension installed and enabled: PDO, SQLite3, or SQLiteDatabase
  36 +
  37 +
  38 +GETTING HELP:
  39 +
  40 + The project's wiki provides information on how to do certain things and is located at http://code.google.com/p/phpliteadmin/w/list. In addition, the project's discussion group is located at http://groups.google.com/group/phpliteadmin.
  41 +
  42 +
  43 +REPORTING ERRORS AND BUGS:
  44 +
  45 + If you find any issues while using the tool, please report them at http://code.google.com/p/phpliteadmin/issues/list.
0 46 \ No newline at end of file
... ...
pacotes/phpliteadmin/phpliteadmin.php 0 → 100644
... ... @@ -0,0 +1,3168 @@
  1 +<?php
  2 +
  3 +//
  4 +// Project: phpLiteAdmin (http://phpliteadmin.googlecode.com)
  5 +// Version: 1.8.6
  6 +// Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web
  7 +// Last updated: 5/31/11
  8 +// Developers:
  9 +// Dane Iracleous (daneiracleous@gmail.com)
  10 +// Ian Aldrighetti (ian.aldrighetti@gmail.com)
  11 +// George Flanagin & Digital Gaslight, Inc (george@digitalgaslight.com)
  12 +//
  13 +//
  14 +// Copyright (C) 2011 phpLiteAdmin
  15 +//
  16 +// This program is free software: you can redistribute it and/or modify
  17 +// it under the terms of the GNU General Public License as published by
  18 +// the Free Software Foundation, either version 3 of the License, or
  19 +// (at your option) any later version.
  20 +//
  21 +// This program is distributed in the hope that it will be useful,
  22 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
  23 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24 +// GNU General Public License for more details.
  25 +//
  26 +// You should have received a copy of the GNU General Public License
  27 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
  28 +//
  29 +///////////////////////////////////////////////////////////////////////////
  30 +//adicionado por edmar
  31 +include_once ("../../ms_configura.php");
  32 +$editor = false;
  33 +if (strtolower($_SERVER['HTTP_HOST']) == "localhost")
  34 +{$editor = true;}
  35 +if($editores != ""){
  36 + foreach ($editores as $e){
  37 + $ip = "UNKNOWN";
  38 + if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
  39 + else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
  40 + else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
  41 + else $ip = "UNKNOWN";
  42 + if ($e == $ip){$editor=true;}
  43 + }
  44 +}
  45 +if($editor == false)
  46 +{echo "Vc n&atilde;o &eacute; um editor cadastrado em i3geo/ms_configura.php";exit;}
  47 +
  48 +//please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list
  49 +
  50 +//password to gain access (change this to something more secure than 'admin')
  51 +//$password = "admin";
  52 +include_once("senha.php");
  53 +if($conexaoadmin == ""){
  54 + //directory relative to this file to search for SQLite databases (if false, manually list databases below)
  55 + $directory = "../../admin";
  56 + //an array of databases that will appear in the application (if $directory is anything but false, $databases will be ignored)
  57 + //if any of the databases do not exist as they are referenced by their path, they will be created automatically if possible
  58 + //the SQLite version of each database is determined automatically
  59 + $databases = array
  60 + (
  61 + array
  62 + (
  63 + "path"=> "admin.db",
  64 + "name"=> "admin.db"
  65 + )
  66 + );
  67 +}
  68 +else{
  69 + include_once($conexaoadmin);
  70 + //$arquivosqlite = $locaplic."/sfb/admin.db";
  71 + $directory = dirname($arquivosqlite);
  72 + $databases = array
  73 + (
  74 + array
  75 + (
  76 + "path"=> basename($arquivosqlite),
  77 + "name"=> "admin.db"
  78 + )
  79 + );
  80 + $conAdmin = "";
  81 + $conAdminw = "";
  82 + $dbhw = "";
  83 + $dbh = "";
  84 +}
  85 +// What should the name of the cookie be which contains the current password?
  86 +// Changing this allows multiple phpLiteAdmin installs to work under the same domain.
  87 +$cookie_name = 'pla3412';
  88 +
  89 +//end of the variables you may need to edit
  90 +
  91 +session_start(); //don't mess with this - required for the login session
  92 +date_default_timezone_set(date_default_timezone_get()); //needed to fix STRICT warnings about timezone issues
  93 +
  94 +//toggle error reporting
  95 +//ini_set("display_errors", 1);
  96 +//error_reporting(E_STRICT | E_ALL);
  97 +
  98 +$startTimeTot = microtime(true); //start the timer to record page load time
  99 +
  100 +//the salt and password encrypting is probably unnecessary protection but is done just for the sake of being very secure
  101 +//create a random salt for this session if a cookie doesn't already exist for it
  102 +if(!isset($_SESSION[$cookie_name.'_salt']) && !isset($_COOKIE[$cookie_name.'_salt']))
  103 +{
  104 + $n = rand(10e16, 10e20);
  105 + $_SESSION[$cookie_name.'_salt'] = base_convert($n, 10, 36);
  106 +}
  107 +else if(!isset($_SESSION[$cookie_name.'_salt']) && isset($_COOKIE[$cookie_name.'_salt'])) //session doesn't exist, but cookie does so grab it
  108 +{
  109 + $_SESSION[$cookie_name.'_salt'] = $_COOKIE[$cookie_name.'_salt'];
  110 +}
  111 +
  112 +//build the basename of this file for later reference
  113 +$info = pathinfo($_SERVER['PHP_SELF']);
  114 +$thisName = $info['basename'];
  115 +
  116 +//constants
  117 +define("PROJECT", "phpLiteAdmin");
  118 +define("VERSION", "1.8.6");
  119 +define("PAGE", $thisName);
  120 +define("COOKIENAME", $cookie_name);
  121 +define("SYSTEMPASSWORD", $password); // Makes things easier.
  122 +define("SYSTEMPASSWORDENCRYPTED", md5($password."_".$_SESSION[$cookie_name.'_salt'])); //extra security - salted and encrypted password used for checking
  123 +define("FORCETYPE", false); //force the extension that will be used (set to false in almost all circumstances except debugging)
  124 +
  125 +//data types array
  126 +$types = array("INTEGER", "REAL", "TEXT", "BLOB");
  127 +define("DATATYPES", serialize($types));
  128 +
  129 +//available SQLite functions array
  130 +$functions = array("abs", "date", "datetime", "hex", "julianday", "length", "lower", "ltrim", "random", "round", "rtrim", "soundex", "time", "trim", "typeof", "upper");
  131 +define("FUNCTIONS", serialize($functions));
  132 +
  133 +//if the user wants to scan a directory for databases, do so
  134 +if($directory!==false)
  135 +{
  136 + if($directory[strlen($directory)-1]=="/") //if user has a trailing slash in the directory, remove it
  137 + $directory = substr($directory, 0, strlen($directory)-1);
  138 +
  139 + if(is_dir($directory)) //make sure the directory is valid
  140 + {
  141 + $arr = scandir($directory);
  142 + $databases = array();
  143 + $j = 0;
  144 + for($i=0; $i<sizeof($arr); $i++) //iterate through all the files in the databases
  145 + {
  146 + $file = pathinfo($arr[$i]);
  147 + if(isset($file['extension']))
  148 + {
  149 + $ext = strtolower($file['extension']);
  150 + if($ext=="sqlite" || $ext=="db" || $ext=="sqlite3" || $ext=="db3") //make sure the file is a valid SQLite database by checking its extension
  151 + {
  152 + $databases[$j]['path'] = $directory."/".$arr[$i];
  153 + $databases[$j]['name'] = $arr[$i];
  154 + $j++;
  155 + }
  156 + }
  157 + }
  158 + }
  159 + else //the directory is not valid - display error and exit
  160 + {
  161 + echo "<div class='confirm' style='margin:20px;'>";
  162 + echo "The directory you specified to scan for databases does not exist or is not a directory.";
  163 + echo "</div>";
  164 + exit();
  165 + }
  166 +}
  167 +//
  168 +// Authorization class
  169 +// Maintains user's logged-in state and security of application
  170 +//
  171 +class Authorization
  172 +{
  173 + public function grant($remember)
  174 + {
  175 + if($remember) //user wants to be remembered, so set a cookie
  176 + {
  177 + $expire = time()+60*60*24*30; //set expiration to 1 month from now
  178 + setcookie(COOKIENAME, SYSTEMPASSWORD, $expire);
  179 + setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire);
  180 + }
  181 + else
  182 + {
  183 + //user does not want to be remembered, so destroy any potential cookies
  184 + setcookie(COOKIENAME, "", time()-86400);
  185 + setcookie(COOKIENAME."_salt", "", time()-86400);
  186 + unset($_COOKIE[COOKIENAME]);
  187 + unset($_COOKIE[COOKIENAME.'_salt']);
  188 + }
  189 +
  190 + $_SESSION[COOKIENAME.'password'] = SYSTEMPASSWORDENCRYPTED;
  191 + }
  192 + public function revoke()
  193 + {
  194 + //destroy everything - cookies and session vars
  195 + setcookie(COOKIENAME, "", time()-86400);
  196 + setcookie(COOKIENAME."_salt", "", time()-86400);
  197 + unset($_COOKIE[COOKIENAME]);
  198 + unset($_COOKIE[COOKIENAME.'_salt']);
  199 + session_unset();
  200 + session_destroy();
  201 + }
  202 + public function isAuthorized()
  203 + {
  204 + // Is this just session long? (What!?? -DI)
  205 + if((isset($_SESSION[COOKIENAME.'password']) && $_SESSION[COOKIENAME.'password'] == SYSTEMPASSWORDENCRYPTED) || (isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && md5($_COOKIE[COOKIENAME]."_".$_COOKIE[COOKIENAME.'_salt']) == SYSTEMPASSWORDENCRYPTED))
  206 + return true;
  207 + else
  208 + {
  209 + return false;
  210 + }
  211 + }
  212 +}
  213 +
  214 +//
  215 +// Database class
  216 +// Generic database abstraction class to manage interaction with database without worrying about SQLite vs. PHP versions
  217 +//
  218 +class Database
  219 +{
  220 + protected $db; //reference to the DB object
  221 + protected $type; //the extension for PHP that handles SQLite
  222 + protected $data;
  223 + protected $lastResult;
  224 +
  225 + public function __construct($data)
  226 + {
  227 + $this->data = $data;
  228 + try
  229 + {
  230 + if(file_exists($this->data["path"]) && !is_writable($this->data["path"])) //make sure the actual database file is writable
  231 + {
  232 + echo "<div class='confirm' style='margin:20px;'>";
  233 + echo "The database, '".$this->data["path"]."', is not writable. The application is unusable until you make it writable.";
  234 + echo "<form action='".PAGE."' method='post'/>";
  235 + echo "<input type='submit' value='Log Out' name='logout' class='btn'/>";
  236 + echo "</form>";
  237 + echo "</div><br/>";
  238 + exit();
  239 + }
  240 +
  241 + if(!file_exists($this->data["path"]) && !is_writable(dirname($this->data["path"]))) //make sure the containing directory is writable if the database does not exist
  242 + {
  243 + echo "<div class='confirm' style='margin:20px;'>";
  244 + echo "The database, '".$this->data["path"]."', does not exist and cannot be created because the containing directory, '".dirname($this->data["path"])."', is not writable. The application is unusable until you make it writable.";
  245 + echo "<form action='".PAGE."' method='post'/>";
  246 + echo "<input type='submit' value='Log Out' name='logout' class='btn'/>";
  247 + echo "</form>";
  248 + echo "</div><br/>";
  249 + exit();
  250 + }
  251 +
  252 + $ver = $this->getVersion();
  253 +
  254 + switch(true)
  255 + {
  256 + case (FORCETYPE=="PDO" || ((FORCETYPE==false || $ver!=-1) && class_exists("PDO") && ($ver==-1 || $ver==3))):
  257 + $this->db = new PDO("sqlite:".$this->data['path']);
  258 + if($this->db!=NULL)
  259 + {
  260 + $this->type = "PDO";
  261 + break;
  262 + }
  263 + case (FORCETYPE=="SQLite3" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLite3") && ($ver==-1 || $ver==3))):
  264 + $this->db = new SQLite3($this->data['path']);
  265 + if($this->db!=NULL)
  266 + {
  267 + $this->type = "SQLite3";
  268 + break;
  269 + }
  270 + case (FORCETYPE=="SQLiteDatabase" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLiteDatabase") && ($ver==-1 || $ver==2))):
  271 + $this->db = new SQLiteDatabase($this->data['path']);
  272 + if($this->db!=NULL)
  273 + {
  274 + $this->type = "SQLiteDatabase";
  275 + break;
  276 + }
  277 + default:
  278 + $this->showError();
  279 + exit();
  280 + }
  281 + }
  282 + catch(Exception $e)
  283 + {
  284 + $this->showError();
  285 + exit();
  286 + }
  287 + }
  288 +
  289 + public function showError()
  290 + {
  291 + $classPDO = class_exists("PDO");
  292 + $classSQLite3 = class_exists("SQLite3");
  293 + $classSQLiteDatabase = class_exists("SQLiteDatabase");
  294 + if($classPDO)
  295 + $strPDO = "installed";
  296 + else
  297 + $strPDO = "not installed";
  298 + if($classSQLite3)
  299 + $strSQLite3 = "installed";
  300 + else
  301 + $strSQLite3 = "not installed";
  302 + if($classSQLiteDatabase)
  303 + $strSQLiteDatabase = "installed";
  304 + else
  305 + $strSQLiteDatabase = "not installed";
  306 + echo "<div class='confirm' style='margin:20px;'>";
  307 + echo "There was a problem setting up your database, ".$this->getPath().". An attempt will be made to find out what's going on so you can fix the problem more easily.<br/><br/>";
  308 + echo "<i>Checking supported SQLite PHP extensions...<br/><br/>";
  309 + echo "<b>PDO</b>: ".$strPDO."<br/>";
  310 + echo "<b>SQLite3</b>: ".$strSQLite3."<br/>";
  311 + echo "<b>SQLiteDatabase</b>: ".$strSQLiteDatabase."<br/><br/>...done.</i><br/><br/>";
  312 + if(!$classPDO && !$classSQLite3 && !$classSQLiteDatabase)
  313 + echo "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use ".PROJECT." until you install at least one of them.";
  314 + else
  315 + {
  316 + if(!$classPDO && !$classSQLite3 && $this->getVersion()==3)
  317 + echo "It appears that your database is of SQLite version 3 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 2.";
  318 + else if(!$classSQLiteDatabase && $this->getVersion()==2)
  319 + echo "It appears that your database is of SQLite version 2 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 3.";
  320 + else
  321 + echo "The problem cannot be diagnosed properly. Please email me at daneiracleous@gmail.com with your database as an attachment and the contents of this error message. It may be that your database is simply not a valid SQLite database, but this is not certain.";
  322 + }
  323 + echo "</div><br/>";
  324 + }
  325 +
  326 + public function __destruct()
  327 + {
  328 + if($this->db)
  329 + $this->close();
  330 + }
  331 +
  332 + //get the exact PHP extension being used for SQLite
  333 + public function getType()
  334 + {
  335 + return $this->type;
  336 + }
  337 +
  338 + //get the name of the database
  339 + public function getName()
  340 + {
  341 + return $this->data["name"];
  342 + }
  343 +
  344 + //get the filename of the database
  345 + public function getPath()
  346 + {
  347 + return $this->data["path"];
  348 + }
  349 +
  350 + //get the version of the database
  351 + public function getVersion()
  352 + {
  353 + if(file_exists($this->data['path'])) //make sure file exists before getting its contents
  354 + {
  355 + $content = strtolower(file_get_contents($this->data['path'], NULL, NULL, 0, 40)); //get the first 40 characters of the database file
  356 + $p = strpos($content, "** this file contains an sqlite 2"); //this text is at the beginning of every SQLite2 database
  357 + if($p!==false) //the text is found - this is version 2
  358 + return 2;
  359 + else
  360 + return 3;
  361 + }
  362 + else //return -1 to indicate that it does not exist and needs to be created
  363 + {
  364 + return -1;
  365 + }
  366 + }
  367 +
  368 + //get the size of the database
  369 + public function getSize()
  370 + {
  371 + return round(filesize($this->data["path"])*0.0009765625, 1)." Kb";
  372 + }
  373 +
  374 + //get the last modified time of database
  375 + public function getDate()
  376 + {
  377 + return date("g:ia \o\\n F j, Y", filemtime($this->data["path"]));
  378 + }
  379 +
  380 + //get number of affected rows from last query
  381 + public function getAffectedRows()
  382 + {
  383 + if($this->type=="PDO")
  384 + return $this->lastResult->rowCount();
  385 + else if($this->type=="SQLite3")
  386 + return $this->db->changes();
  387 + else if($this->type=="SQLiteDatabase")
  388 + return $this->db->changes();
  389 + }
  390 +
  391 + public function close()
  392 + {
  393 + if($this->type=="PDO")
  394 + $this->db = NULL;
  395 + else if($this->type=="SQLite3")
  396 + $this->db->close();
  397 + else if($this->type=="SQLiteDatabase")
  398 + $this->db = NULL;
  399 + }
  400 +
  401 + public function beginTransaction()
  402 + {
  403 + $this->query("BEGIN");
  404 + }
  405 +
  406 + public function commitTransaction()
  407 + {
  408 + $this->query("COMMIT");
  409 + }
  410 +
  411 + public function rollbackTransaction()
  412 + {
  413 + $this->query("ROLLBACK");
  414 + }
  415 +
  416 + //generic query wrapper
  417 + public function query($query, $ignoreAlterCase=false)
  418 + {
  419 + if(strtolower(substr(ltrim($query),0,5))=='alter' && $ignoreAlterCase==false) //this query is an ALTER query - call the necessary function
  420 + {
  421 + $queryparts = preg_split("/[\s]+/", $query, 4, PREG_SPLIT_NO_EMPTY);
  422 + $tablename = $queryparts[2];
  423 + $alterdefs = $queryparts[3];
  424 + //echo $query;
  425 + $result = $this->alterTable($tablename, $alterdefs);
  426 + }
  427 + else //this query is normal - proceed as normal
  428 + $result = $this->db->query($query);
  429 + if(!$result)
  430 + return NULL;
  431 + $this->lastResult = $result;
  432 + return $result;
  433 + }
  434 +
  435 + //wrapper for an INSERT and returns the ID of the inserted row
  436 + public function insert($query)
  437 + {
  438 + $result = $this->query($query);
  439 + if($this->type=="PDO")
  440 + return $this->db->lastInsertId();
  441 + else if($this->type=="SQLite3")
  442 + return $this->db->lastInsertRowID();
  443 + else if($this->type=="SQLiteDatabase")
  444 + return $this->db->lastInsertRowid();
  445 + }
  446 +
  447 + //returns an array for SELECT
  448 + public function select($query, $mode="both")
  449 + {
  450 + $result = $this->query($query);
  451 + if(!$result) //make sure the result is valid
  452 + return NULL;
  453 + if($this->type=="PDO")
  454 + {
  455 + if($mode=="assoc")
  456 + $mode = PDO::FETCH_ASSOC;
  457 + else if($mode=="num")
  458 + $mode = PDO::FETCH_NUM;
  459 + else
  460 + $mode = PDO::FETCH_BOTH;
  461 + return $result->fetch($mode);
  462 + }
  463 + else if($this->type=="SQLite3")
  464 + {
  465 + if($mode=="assoc")
  466 + $mode = SQLITE3_ASSOC;
  467 + else if($mode=="num")
  468 + $mode = SQLITE3_NUM;
  469 + else
  470 + $mode = SQLITE3_BOTH;
  471 + return $result->fetchArray($mode);
  472 + }
  473 + else if($this->type=="SQLiteDatabase")
  474 + {
  475 + if($mode=="assoc")
  476 + $mode = SQLITE_ASSOC;
  477 + else if($mode=="num")
  478 + $mode = SQLITE_NUM;
  479 + else
  480 + $mode = SQLITE_BOTH;
  481 + return $result->fetch($mode);
  482 + }
  483 + }
  484 +
  485 + //returns an array of arrays after doing a SELECT
  486 + public function selectArray($query, $mode="both")
  487 + {
  488 + $result = $this->query($query);
  489 + if(!$result) //make sure the result is valid
  490 + return NULL;
  491 + if($this->type=="PDO")
  492 + {
  493 + if($mode=="assoc")
  494 + $mode = PDO::FETCH_ASSOC;
  495 + else if($mode=="num")
  496 + $mode = PDO::FETCH_NUM;
  497 + else
  498 + $mode = PDO::FETCH_BOTH;
  499 + return $result->fetchAll($mode);
  500 + }
  501 + else if($this->type=="SQLite3")
  502 + {
  503 + if($mode=="assoc")
  504 + $mode = SQLITE3_ASSOC;
  505 + else if($mode=="num")
  506 + $mode = SQLITE3_NUM;
  507 + else
  508 + $mode = SQLITE3_BOTH;
  509 + $arr = array();
  510 + $i = 0;
  511 + while($res = $result->fetchArray($mode))
  512 + {
  513 + $arr[$i] = $res;
  514 + $i++;
  515 + }
  516 + return $arr;
  517 + }
  518 + else if($this->type=="SQLiteDatabase")
  519 + {
  520 + if($mode=="assoc")
  521 + $mode = SQLITE_ASSOC;
  522 + else if($mode=="num")
  523 + $mode = SQLITE_NUM;
  524 + else
  525 + $mode = SQLITE_BOTH;
  526 + return $result->fetchAll($mode);
  527 + }
  528 + }
  529 +
  530 + //function that is called for an alter table statement in a query
  531 + //code borrowed with permission from http://code.jenseng.com/db/
  532 + public function alterTable($table, $alterdefs)
  533 + {
  534 + if($alterdefs != '')
  535 + {
  536 + $tempQuery = "SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC";
  537 + $result = $this->query($tempQuery);
  538 + $resultArr = $this->selectArray($tempQuery);
  539 +
  540 + if(sizeof($resultArr)>0)
  541 + {
  542 + $row = $this->select($tempQuery); //table sql
  543 + $tmpname = 't'.time();
  544 + $origsql = trim(preg_replace("/[\s]+/", " ", str_replace(",", ", ",preg_replace("/[\(]/", "( ", $row['sql'], 1))));
  545 + $createtemptableSQL = 'CREATE TEMPORARY '.substr(trim(preg_replace("'".$table."'", $tmpname, $origsql, 1)), 6);
  546 + $createindexsql = array();
  547 + $i = 0;
  548 + $defs = preg_split("/[,]+/",$alterdefs, -1, PREG_SPLIT_NO_EMPTY);
  549 + $prevword = $table;
  550 + $oldcols = preg_split("/[,]+/", substr(trim($createtemptableSQL), strpos(trim($createtemptableSQL), '(')+1), -1, PREG_SPLIT_NO_EMPTY);
  551 + $newcols = array();
  552 + for($i=0; $i<sizeof($oldcols); $i++)
  553 + {
  554 + $colparts = preg_split("/[\s]+/", $oldcols[$i], -1, PREG_SPLIT_NO_EMPTY);
  555 + $oldcols[$i] = $colparts[0];
  556 + $newcols[$colparts[0]] = $colparts[0];
  557 + }
  558 + $newcolumns = '';
  559 + $oldcolumns = '';
  560 + reset($newcols);
  561 + while(list($key, $val) = each($newcols))
  562 + {
  563 + $newcolumns .= ($newcolumns?', ':'').$val;
  564 + $oldcolumns .= ($oldcolumns?', ':'').$key;
  565 + }
  566 + $copytotempsql = 'INSERT INTO '.$tmpname.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$table;
  567 + $dropoldsql = 'DROP TABLE '.$table;
  568 + $createtesttableSQL = $createtemptableSQL;
  569 + foreach($defs as $def)
  570 + {
  571 + $defparts = preg_split("/[\s]+/", $def,-1, PREG_SPLIT_NO_EMPTY);
  572 + $action = strtolower($defparts[0]);
  573 + switch($action)
  574 + {
  575 + case 'add':
  576 + if(sizeof($defparts) <= 2)
  577 + return false;
  578 + $createtesttableSQL = substr($createtesttableSQL, 0, strlen($createtesttableSQL)-1).',';
  579 + for($i=1;$i<sizeof($defparts);$i++)
  580 + $createtesttableSQL.=' '.$defparts[$i];
  581 + $createtesttableSQL.=')';
  582 + break;
  583 + case 'change':
  584 + if(sizeof($defparts) <= 3)
  585 + {
  586 + return false;
  587 + }
  588 + if($severpos = strpos($createtesttableSQL,' '.$defparts[1].' '))
  589 + {
  590 + if($newcols[$defparts[1]] != $defparts[1])
  591 + return false;
  592 + $newcols[$defparts[1]] = $defparts[2];
  593 + $nextcommapos = strpos($createtesttableSQL,',',$severpos);
  594 + $insertval = '';
  595 + for($i=2;$i<sizeof($defparts);$i++)
  596 + $insertval.=' '.$defparts[$i];
  597 + if($nextcommapos)
  598 + $createtesttableSQL = substr($createtesttableSQL,0,$severpos).$insertval.substr($createtesttableSQL,$nextcommapos);
  599 + else
  600 + $createtesttableSQL = substr($createtesttableSQL,0,$severpos-(strpos($createtesttableSQL,',')?0:1)).$insertval.')';
  601 + }
  602 + else
  603 + return false;
  604 + break;
  605 + case 'drop':
  606 + if(sizeof($defparts) < 2)
  607 + return false;
  608 + if($severpos = strpos($createtesttableSQL,' '.$defparts[1].' '))
  609 + {
  610 + $nextcommapos = strpos($createtesttableSQL,',',$severpos);
  611 + if($nextcommapos)
  612 + $createtesttableSQL = substr($createtesttableSQL,0,$severpos).substr($createtesttableSQL,$nextcommapos + 1);
  613 + else
  614 + $createtesttableSQL = substr($createtesttableSQL,0,$severpos-(strpos($createtesttableSQL,',')?0:1) - 1).')';
  615 + unset($newcols[$defparts[1]]);
  616 + }
  617 + else
  618 + return false;
  619 + break;
  620 + default:
  621 + return false;
  622 + }
  623 + $prevword = $defparts[sizeof($defparts)-1];
  624 + }
  625 + //this block of code generates a test table simply to verify that the columns specifed are valid in an sql statement
  626 + //this ensures that no reserved words are used as columns, for example
  627 + $tempResult = $this->query($createtesttableSQL);
  628 + if(!$tempResult)
  629 + return false;
  630 + $droptempsql = 'DROP TABLE '.$tmpname;
  631 + $tempResult = $this->query($droptempsql);
  632 + //end block
  633 +
  634 + $createnewtableSQL = 'CREATE '.substr(trim(preg_replace("'".$tmpname."'", $table, $createtesttableSQL, 1)), 17);
  635 + $newcolumns = '';
  636 + $oldcolumns = '';
  637 + reset($newcols);
  638 + while(list($key,$val) = each($newcols))
  639 + {
  640 + $newcolumns .= ($newcolumns?', ':'').$val;
  641 + $oldcolumns .= ($oldcolumns?', ':'').$key;
  642 + }
  643 + $copytonewsql = 'INSERT INTO '.$table.'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$tmpname;
  644 +
  645 + $this->query($createtemptableSQL); //create temp table
  646 + $this->query($copytotempsql); //copy to table
  647 + $this->query($dropoldsql); //drop old table
  648 +
  649 + $this->query($createnewtableSQL); //recreate original table
  650 + $this->query($copytonewsql); //copy back to original table
  651 + $this->query($droptempsql); //drop temp table
  652 + }
  653 + else
  654 + {
  655 + return false;
  656 + }
  657 + return true;
  658 + }
  659 + }
  660 +
  661 + //multiple query execution
  662 + public function multiQuery($query)
  663 + {
  664 + if($this->type=="PDO")
  665 + {
  666 + $this->db->exec($query);
  667 + }
  668 + else if($this->type=="SQLite3")
  669 + {
  670 + $this->db->exec($query);
  671 + }
  672 + else
  673 + {
  674 + $this->db->queryExec($query);
  675 + }
  676 + }
  677 +
  678 + //get number of rows in table
  679 + public function numRows($table)
  680 + {
  681 + $result = $this->select("SELECT Count(*) FROM ".$table);
  682 + return $result[0];
  683 + }
  684 +
  685 + //correctly escape a string to be injected into an SQL query
  686 + public function quote($value)
  687 + {
  688 + if($this->type=="PDO")
  689 + {
  690 + return $this->db->quote($value);
  691 + }
  692 + else if($this->type=="SQLite3")
  693 + {
  694 + return $this->db->escapeString($value);
  695 + }
  696 + else
  697 + {
  698 + return "'".$value."'";
  699 + }
  700 + }
  701 +
  702 + //correctly format a string value from a table before showing it
  703 + public function formatString($value)
  704 + {
  705 + return htmlspecialchars(stripslashes($value));
  706 + }
  707 +
  708 + //import
  709 + public function import($query)
  710 + {
  711 + $this->multiQuery($query);
  712 + }
  713 +
  714 + //export
  715 + public function export($tables, $drop, $structure, $data, $transaction, $comments)
  716 + {
  717 + if($comments)
  718 + {
  719 + echo "----\r\n";
  720 + echo "-- phpLiteAdmin database dump (http://phpliteadmin.googlecode.com)\r\n";
  721 + echo "-- phpLiteAdmin version: ".VERSION."\r\n";
  722 + echo "-- Exported on ".date('M jS, Y, h:i:sA')."\r\n";
  723 + echo "-- Database file: ".$this->getPath()."\r\n";
  724 + echo "----\r\n";
  725 + }
  726 + $query = "SELECT * FROM sqlite_master WHERE type='table' OR type='index' ORDER BY type DESC";
  727 + $result = $this->selectArray($query);
  728 +
  729 + //iterate through each table
  730 + for($i=0; $i<sizeof($result); $i++)
  731 + {
  732 + $valid = false;
  733 + for($j=0; $j<sizeof($tables); $j++)
  734 + {
  735 + if($result[$i]['tbl_name']==$tables[$j])
  736 + $valid = true;
  737 + }
  738 + if($valid)
  739 + {
  740 + if($drop)
  741 + {
  742 + if($comments)
  743 + {
  744 + echo "\r\n----\r\n";
  745 + if($result[$i]['type']=="table")
  746 + echo "-- Drop table for ".$result[$i]['tbl_name']."\r\n";
  747 + else
  748 + echo "-- Drop index for ".$result[$i]['name']."\r\n";
  749 + echo "----\r\n";
  750 + }
  751 + if($result[$i]['type']=="table")
  752 + echo "DROP TABLE '".$result[$i]['tbl_name']."';\r\n";
  753 + else
  754 + echo "DROP INDEX '".$result[$i]['name']."';\r\n";
  755 + }
  756 + if($structure)
  757 + {
  758 + if($comments)
  759 + {
  760 + echo "\r\n----\r\n";
  761 + if($result[$i]['type']=="table")
  762 + echo "-- Table structure for ".$result[$i]['tbl_name']."\r\n";
  763 + else
  764 + echo "-- Structure for index ".$result[$i]['name']." on table ".$result[$i]['tbl_name']."\r\n";
  765 + echo "----\r\n";
  766 + }
  767 + echo $result[$i]['sql'].";\r\n";
  768 + }
  769 + if($data && $result[$i]['type']=="table")
  770 + {
  771 + $query = "SELECT * FROM ".$result[$i]['tbl_name'];
  772 + $arr = $this->selectArray($query, "assoc");
  773 +
  774 + if($comments)
  775 + {
  776 + echo "\r\n----\r\n";
  777 + echo "-- Data dump for ".$result[$i]['tbl_name'].", a total of ".sizeof($arr)." rows\r\n";
  778 + echo "----\r\n";
  779 + }
  780 + $query = "PRAGMA table_info('".$result[$i]['tbl_name']."')";
  781 + $temp = $this->selectArray($query);
  782 + $cols = array();
  783 + $vals = array();
  784 + for($z=0; $z<sizeof($temp); $z++)
  785 + $cols[$z] = $temp[$z][1];
  786 + for($z=0; $z<sizeof($arr); $z++)
  787 + {
  788 + for($y=0; $y<sizeof($cols); $y++)
  789 + {
  790 + if(!isset($vals[$z]))
  791 + $vals[$z] = array();
  792 + $vals[$z][$cols[$y]] = $this->quote($arr[$z][$cols[$y]]);
  793 + }
  794 + }
  795 + if($transaction)
  796 + echo "BEGIN TRANSACTION;\r\n";
  797 + for($j=0; $j<sizeof($vals); $j++)
  798 + echo "INSERT INTO ".$result[$i]['tbl_name']." (".implode(",", $cols).") VALUES (".implode(",", $vals[$j]).");\r\n";
  799 + if($transaction)
  800 + echo "COMMIT;\r\n";
  801 + }
  802 + }
  803 + }
  804 + }
  805 +}
  806 +
  807 +$auth = new Authorization(); //create authorization object
  808 +if(isset($_POST['logout'])) //user has attempted to log out
  809 + $auth->revoke();
  810 +else if(isset($_POST['login']) || isset($_POST['proc_login'])) //user has attempted to log in
  811 +{
  812 + $_POST['login'] = true;
  813 +
  814 + if($_POST['password']==SYSTEMPASSWORD) //make sure passwords match before granting authorization
  815 + {
  816 + if(isset($_POST['remember']))
  817 + $auth->grant(true);
  818 + else
  819 + $auth->grant(false);
  820 + }
  821 +}
  822 +
  823 +//user is downloading the exported database file
  824 +if(isset($_POST['export']))
  825 +{
  826 + header('Content-Type: text/sql');
  827 + header('Content-Disposition: attachment; filename="'.$_POST['filename'].'.'.$_POST['export_type'].'";');
  828 + if(isset($_POST['tables']))
  829 + $tables = $_POST['tables'];
  830 + else
  831 + {
  832 + $tables = array();
  833 + $tables[0] = $_POST['single_table'];
  834 + }
  835 + $drop = isset($_POST['drop']);
  836 + $structure = isset($_POST['structure']);
  837 + $data = isset($_POST['data']);
  838 + $transaction = isset($_POST['transaction']);
  839 + $comments = isset($_POST['comments']);
  840 + $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]);
  841 + echo $db->export($tables, $drop, $structure, $data, $transaction, $comments);
  842 + exit();
  843 +}
  844 +
  845 +//user is importing a file
  846 +if(isset($_POST['import']))
  847 +{
  848 + $data = file_get_contents($_FILES["file"]["tmp_name"]);
  849 + $db = new Database($databases[$_SESSION[COOKIENAME.'currentDB']]);
  850 + $db->import($data);
  851 +}
  852 +
  853 +// here begins the HTML.
  854 +?>
  855 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  856 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  857 +<head>
  858 +<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  859 +<title><?php echo PROJECT ?></title>
  860 +
  861 +<?php
  862 +if(!file_exists("phpliteadmin.css")) //only use the inline stylesheet if an external one does not exist
  863 +{
  864 +?>
  865 +<!-- begin the customizable stylesheet/theme -->
  866 +<style type="text/css">
  867 +/* overall styles for entire page */
  868 +body
  869 +{
  870 + margin: 0px;
  871 + padding: 0px;
  872 + font-family: Arial, Helvetica, sans-serif;
  873 + font-size: 14px;
  874 + color: #000000;
  875 + background-color: #e0ebf6;
  876 +}
  877 +/* general styles for hyperlink */
  878 +a
  879 +{
  880 + color: #03F;
  881 + text-decoration: none;
  882 + cursor :pointer;
  883 +}
  884 +hr
  885 +{
  886 + height: 1px;
  887 + border: 0;
  888 + color: #bbb;
  889 + background-color: #bbb;
  890 + width: 100%;
  891 +}
  892 +a:hover
  893 +{
  894 + color: #06F;
  895 +}
  896 +/* logo text containing name of project */
  897 +h1
  898 +{
  899 + margin: 0px;
  900 + padding: 5px;
  901 + font-size: 24px;
  902 + background-color: #f3cece;
  903 + text-align: center;
  904 + margin-bottom: 10px;
  905 + color: #000;
  906 + border-top-left-radius:5px;
  907 + border-top-right-radius:5px;
  908 + -moz-border-radius-topleft:5px;
  909 + -moz-border-radius-topright:5px;
  910 +}
  911 +/* version text within the logo */
  912 +h1 #version
  913 +{
  914 + color: #000000;
  915 + font-size: 16px;
  916 +}
  917 +/* logo text within logo */
  918 +h1 #logo
  919 +{
  920 + color:#000;
  921 +}
  922 +/* general header for various views */
  923 +h2
  924 +{
  925 + margin:0px;
  926 + padding:0px;
  927 + font-size:14px;
  928 + margin-bottom:20px;
  929 +}
  930 +/* input buttons and areas for entering text */
  931 +input, select, textarea
  932 +{
  933 + font-family:Arial, Helvetica, sans-serif;
  934 + background-color:#eaeaea;
  935 + color:#03F;
  936 + border-color:#03F;
  937 + border-style:solid;
  938 + border-width:1px;
  939 + margin:5px;
  940 + border-radius:5px;
  941 + -moz-border-radius:5px;
  942 + padding:3px;
  943 +}
  944 +/* just input buttons */
  945 +input.btn
  946 +{
  947 + cursor:pointer;
  948 +}
  949 +input.btn:hover
  950 +{
  951 + background-color:#ccc;
  952 +}
  953 +/* general styles for hyperlink */
  954 +fieldset
  955 +{
  956 + padding:15px;
  957 + border-color:#03F;
  958 + border-width:1px;
  959 + border-style:solid;
  960 + border-radius:5px;
  961 + -moz-border-radius:5px;
  962 + background-color:#f9f9f9;
  963 +}
  964 +/* outer div that holds everything */
  965 +#container
  966 +{
  967 + padding:10px;
  968 +}
  969 +/* div of left box with log, list of databases, etc. */
  970 +#leftNav
  971 +{
  972 + float:left;
  973 + width:250px;
  974 + padding:0px;
  975 + border-color:#03F;
  976 + border-width:1px;
  977 + border-style:solid;
  978 + background-color:#FFF;
  979 + padding-bottom:15px;
  980 + border-radius:5px;
  981 + -moz-border-radius:5px;
  982 +}
  983 +/* div holding the content to the right of the leftNav */
  984 +#content
  985 +{
  986 + overflow:hidden;
  987 + padding-left:10px;
  988 +}
  989 +/* div holding the login fields */
  990 +#loginBox
  991 +{
  992 + width:500px;
  993 + margin-left:auto;
  994 + margin-right:auto;
  995 + margin-top:50px;
  996 + border-color:#03F;
  997 + border-width:1px;
  998 + border-style:solid;
  999 + background-color:#FFF;
  1000 + border-radius:5px;
  1001 + -moz-border-radius:5px;
  1002 +}
  1003 +/* div under tabs with tab-specific content */
  1004 +#main
  1005 +{
  1006 + border-color:#03F;
  1007 + border-width:1px;
  1008 + border-style:solid;
  1009 + padding:15px;
  1010 + overflow:auto;
  1011 + background-color:#FFF;
  1012 + border-bottom-left-radius:5px;
  1013 + border-bottom-right-radius:5px;
  1014 + border-top-right-radius:5px;
  1015 + -moz-border-radius-bottomleft:5px;
  1016 + -moz-border-radius-bottomright:5px;
  1017 + -moz-border-radius-topright:5px;
  1018 +}
  1019 +/* odd-numbered table rows */
  1020 +.td1
  1021 +{
  1022 + background-color:#f9e3e3;
  1023 + text-align:right;
  1024 + font-size:12px;
  1025 + padding-left:10px;
  1026 + padding-right:10px;
  1027 +}
  1028 +/* even-numbered table rows */
  1029 +.td2
  1030 +{
  1031 + background-color:#f3cece;
  1032 + text-align:right;
  1033 + font-size:12px;
  1034 + padding-left:10px;
  1035 + padding-right:10px;
  1036 +}
  1037 +/* table column headers */
  1038 +.tdheader
  1039 +{
  1040 + border-color:#03F;
  1041 + border-width:1px;
  1042 + border-style:solid;
  1043 + font-weight:bold;
  1044 + font-size:12px;
  1045 + padding-left:10px;
  1046 + padding-right:10px;
  1047 + background-color:#e0ebf6;
  1048 + border-radius:5px;
  1049 + -moz-border-radius:5px;
  1050 +}
  1051 +/* div holding the confirmation text of certain actions */
  1052 +.confirm
  1053 +{
  1054 + border-color:#03F;
  1055 + border-width:1px;
  1056 + border-style:dashed;
  1057 + padding:15px;
  1058 + background-color:#e0ebf6;
  1059 +}
  1060 +/* tab navigation for each table */
  1061 +.tab
  1062 +{
  1063 + display:block;
  1064 + padding:5px;
  1065 + padding-right:8px;
  1066 + padding-left:8px;
  1067 + border-color:#03F;
  1068 + border-width:1px;
  1069 + border-style:solid;
  1070 + margin-right:5px;
  1071 + float:left;
  1072 + border-bottom-style:none;
  1073 + position:relative;
  1074 + top:1px;
  1075 + padding-bottom:4px;
  1076 + background-color:#eaeaea;
  1077 + border-top-left-radius:5px;
  1078 + border-top-right-radius:5px;
  1079 + -moz-border-radius-topleft:5px;
  1080 + -moz-border-radius-topright:5px;
  1081 +}
  1082 +/* pressed state of tab */
  1083 +.tab_pressed
  1084 +{
  1085 + display:block;
  1086 + padding:5px;
  1087 + padding-right:8px;
  1088 + padding-left:8px;
  1089 + border-color:#03F;
  1090 + border-width:1px;
  1091 + border-style:solid;
  1092 + margin-right:5px;
  1093 + float:left;
  1094 + border-bottom-style:none;
  1095 + position:relative;
  1096 + top:1px;
  1097 + background-color:#FFF;
  1098 + cursor:default;
  1099 + border-top-left-radius:5px;
  1100 + border-top-right-radius:5px;
  1101 + -moz-border-radius-topleft:5px;
  1102 + -moz-border-radius-topright:5px;
  1103 +}
  1104 +/* tooltip styles */
  1105 +#tt
  1106 +{
  1107 + position:absolute;
  1108 + display:block;
  1109 +}
  1110 +#tttop
  1111 +{
  1112 + display:block;
  1113 + height:5px;
  1114 + margin-left:5px;
  1115 + overflow:hidden
  1116 +}
  1117 +#ttcont
  1118 +{
  1119 + display:block;
  1120 + padding:2px 12px 3px 7px;
  1121 + margin-left:5px;
  1122 + background:#f3cece;
  1123 + color:#333
  1124 +}
  1125 +#ttbot
  1126 +{
  1127 + display:block;
  1128 + height:5px;
  1129 + margin-left:5px;
  1130 + overflow:hidden
  1131 +}
  1132 +</style>
  1133 +<!-- end the customizable stylesheet/theme -->
  1134 +<?php
  1135 +}
  1136 +else //an external stylesheet exists - import it
  1137 +{
  1138 + echo "<link href='phpliteadmin.css' rel='stylesheet' type='text/css' />";
  1139 +}
  1140 +?>
  1141 +<!-- JavaScript Support -->
  1142 +<script type="text/javascript">
  1143 +//makes sure autoincrement can only be selected when integer type is selected
  1144 +function toggleAutoincrement(i)
  1145 +{
  1146 + var type = document.getElementById(i+'_type');
  1147 + var autoincrement = document.getElementById(i+'_autoincrement');
  1148 + if(type.value=="INTEGER")
  1149 + autoincrement.disabled = false;
  1150 + else
  1151 + {
  1152 + autoincrement.disabled = true;
  1153 + autoincrement.checked = false;
  1154 + }
  1155 +}
  1156 +//finds and checks all checkboxes for all rows on the Browse or Structure tab for a table
  1157 +function checkAll(field)
  1158 +{
  1159 + var i=0;
  1160 + while(document.getElementById('check_'+i)!=undefined)
  1161 + {
  1162 + document.getElementById('check_'+i).checked = true;
  1163 + i++;
  1164 + }
  1165 +}
  1166 +//finds and unchecks all checkboxes for all rows on the Browse or Structure tab for a table
  1167 +function uncheckAll(field)
  1168 +{
  1169 + var i=0;
  1170 + while(document.getElementById('check_'+i)!=undefined)
  1171 + {
  1172 + document.getElementById('check_'+i).checked = false;
  1173 + i++;
  1174 + }
  1175 +}
  1176 +//unchecks the ignore checkbox if user has typed something into one of the fields for adding new rows
  1177 +function changeIgnore(area, e)
  1178 +{
  1179 + if(area.value!="")
  1180 + document.getElementById(e).checked = false;
  1181 +}
  1182 +//moves fields from select menu into query textarea for SQL tab
  1183 +function moveFields()
  1184 +{
  1185 + var fields = document.getElementById("fieldcontainer");
  1186 + var selected = new Array();
  1187 + for(var i=0; i<fields.options.length; i++)
  1188 + if(fields.options[i].selected)
  1189 + selected.push(fields.options[i].value);
  1190 + for(var i=0; i<selected.length; i++)
  1191 + insertAtCaret("queryval", "`"+selected[i]+"`");
  1192 +}
  1193 +//helper function for moveFields
  1194 +function insertAtCaret(areaId,text)
  1195 +{
  1196 + var txtarea = document.getElementById(areaId);
  1197 + var scrollPos = txtarea.scrollTop;
  1198 + var strPos = 0;
  1199 + var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ));
  1200 + if(br=="ie")
  1201 + {
  1202 + txtarea.focus();
  1203 + var range = document.selection.createRange();
  1204 + range.moveStart ('character', -txtarea.value.length);
  1205 + strPos = range.text.length;
  1206 + }
  1207 + else if(br=="ff")
  1208 + strPos = txtarea.selectionStart;
  1209 +
  1210 + var front = (txtarea.value).substring(0,strPos);
  1211 + var back = (txtarea.value).substring(strPos,txtarea.value.length);
  1212 + txtarea.value=front+text+back;
  1213 + strPos = strPos + text.length;
  1214 + if(br=="ie")
  1215 + {
  1216 + txtarea.focus();
  1217 + var range = document.selection.createRange();
  1218 + range.moveStart ('character', -txtarea.value.length);
  1219 + range.moveStart ('character', strPos);
  1220 + range.moveEnd ('character', 0);
  1221 + range.select();
  1222 + }
  1223 + else if(br=="ff")
  1224 + {
  1225 + txtarea.selectionStart = strPos;
  1226 + txtarea.selectionEnd = strPos;
  1227 + txtarea.focus();
  1228 + }
  1229 + txtarea.scrollTop = scrollPos;
  1230 +}
  1231 +//tooltip help feature
  1232 +var tooltip=function()
  1233 +{
  1234 + var id = 'tt';
  1235 + var top = 3;
  1236 + var left = 3;
  1237 + var maxw = 300;
  1238 + var speed = 10;
  1239 + var timer = 20;
  1240 + var endalpha = 95;
  1241 + var alpha = 0;
  1242 + var tt,t,c,b,h;
  1243 + var ie = document.all ? true : false;
  1244 + return{
  1245 + show:function(v,w)
  1246 + {
  1247 + if(tt == null)
  1248 + {
  1249 + tt = document.createElement('div');
  1250 + tt.setAttribute('id',id);
  1251 + t = document.createElement('div');
  1252 + t.setAttribute('id',id + 'top');
  1253 + c = document.createElement('div');
  1254 + c.setAttribute('id',id + 'cont');
  1255 + b = document.createElement('div');
  1256 + b.setAttribute('id',id + 'bot');
  1257 + tt.appendChild(t);
  1258 + tt.appendChild(c);
  1259 + tt.appendChild(b);
  1260 + document.body.appendChild(tt);
  1261 + tt.style.opacity = 0;
  1262 + tt.style.filter = 'alpha(opacity=0)';
  1263 + document.onmousemove = this.pos;
  1264 + }
  1265 + tt.style.display = 'block';
  1266 + c.innerHTML = v;
  1267 + tt.style.width = w ? w + 'px' : 'auto';
  1268 + if(!w && ie)
  1269 + {
  1270 + t.style.display = 'none';
  1271 + b.style.display = 'none';
  1272 + tt.style.width = tt.offsetWidth;
  1273 + t.style.display = 'block';
  1274 + b.style.display = 'block';
  1275 + }
  1276 + if(tt.offsetWidth > maxw)
  1277 + tt.style.width = maxw + 'px'
  1278 + h = parseInt(tt.offsetHeight) + top;
  1279 + clearInterval(tt.timer);
  1280 + tt.timer = setInterval(function(){tooltip.fade(1)},timer);
  1281 + },
  1282 + pos:function(e)
  1283 + {
  1284 + var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
  1285 + var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
  1286 + tt.style.top = (u - h) + 'px';
  1287 + tt.style.left = (l + left) + 'px';
  1288 + },
  1289 + fade:function(d)
  1290 + {
  1291 + var a = alpha;
  1292 + if((a != endalpha && d == 1) || (a != 0 && d == -1))
  1293 + {
  1294 + var i = speed;
  1295 + if(endalpha - a < speed && d == 1)
  1296 + i = endalpha - a;
  1297 + else if(alpha < speed && d == -1)
  1298 + i = a;
  1299 + alpha = a + (i * d);
  1300 + tt.style.opacity = alpha * .01;
  1301 + tt.style.filter = 'alpha(opacity=' + alpha + ')';
  1302 + }
  1303 + else
  1304 + {
  1305 + clearInterval(tt.timer);
  1306 + if(d == -1)
  1307 + tt.style.display = 'none';
  1308 + }
  1309 + },
  1310 + hide:function()
  1311 + {
  1312 + clearInterval(tt.timer);
  1313 + tt.timer = setInterval(function()
  1314 + {
  1315 + tooltip.fade(-1)
  1316 + },timer);
  1317 + }
  1318 + };
  1319 +}();
  1320 +</script>
  1321 +</head>
  1322 +<body>
  1323 +<?php
  1324 +if(ini_get("register_globals")) //check whether register_globals is turned on - if it is, we need to not continue
  1325 +{
  1326 + echo "<div class='confirm' style='margin:20px;'>";
  1327 + echo "It appears that the PHP directive, 'register_globals' is enabled. This is bad. You need to disable it before continuing.";
  1328 + echo "</div>";
  1329 + exit();
  1330 +}
  1331 +
  1332 +if(!$auth->isAuthorized()) //user is not authorized - display the login screen
  1333 +{
  1334 + echo "<div id='loginBox'>";
  1335 + echo "<h1><span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span></h1>";
  1336 + echo "<div style='padding:15px; text-align:center;'>";
  1337 + if(isset($_POST['login']))
  1338 + echo "<span style='color:red;'>Incorrect password.</span><br/><br/>";
  1339 + echo "<form action='".PAGE."' method='post'>";
  1340 + echo "Password: <input type='password' name='password'/><br/>";
  1341 + echo "<input type='checkbox' name='remember' value='yes' checked='checked'/> Remember me<br/><br/>";
  1342 + echo "N&atilde;o sabe a senha? Veja no arquivo i3geo/pacotes/phpliteadmin/senha.php<br><br>";
  1343 + echo "Al&eacute;m de saber a senha, voc&ecirc; precisa ser um administrador cadastrado em i3geo/ms_configura.php<br><br>";
  1344 + echo "<input type='submit' value='Log In' name='login' class='btn'/>";
  1345 + echo "<input type='hidden' name='proc_login' value='true' />";
  1346 + echo "</form>";
  1347 + echo "</div>";
  1348 + echo "</div>";
  1349 + echo "<br/>";
  1350 + echo "<div style='text-align:center;'>";
  1351 + $endTimeTot = microtime(true);
  1352 + $timeTot = round(($endTimeTot - $startTimeTot), 4);
  1353 + echo "<span style='font-size:11px;'>Powered by <a href='http://phpliteadmin.googlecode.com' target='_blank' style='font-size:11px;'>".PROJECT."</a> | Page generated in ".$timeTot." seconds.</span>";
  1354 + echo "</div>";
  1355 +}
  1356 +else //user is authorized - display the main application
  1357 +{
  1358 + if(!isset($_SESSION[COOKIENAME.'currentDB']))
  1359 + $_SESSION[COOKIENAME.'currentDB'] = 0;
  1360 + //set the current database to the first in the array (default)
  1361 + if(sizeof($databases)>0)
  1362 + $currentDB = $databases[0];
  1363 + else //the database array is empty - show error and halt execution
  1364 + {
  1365 + echo "<div class='confirm' style='margin:20px;'>";
  1366 + echo "Error: you have not specified any databases to manage.";
  1367 + echo "</div><br/>";
  1368 + exit();
  1369 + }
  1370 +
  1371 + if(isset($_POST['database_switch'])) //user is switching database with drop-down menu
  1372 + {
  1373 + $_SESSION[COOKIENAME."currentDB"] = $_POST['database_switch'];
  1374 + $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']];
  1375 + }
  1376 + else if(isset($_GET['switchdb']))
  1377 + {
  1378 + $_SESSION[COOKIENAME."currentDB"] = $_GET['switchdb'];
  1379 + $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']];
  1380 + }
  1381 + if(isset($_SESSION[COOKIENAME.'currentDB']))
  1382 + $currentDB = $databases[$_SESSION[COOKIENAME.'currentDB']];
  1383 +
  1384 + //create the objects
  1385 + $db = new Database($currentDB); //create the Database object
  1386 +
  1387 + //switch board for various operations a user could have requested - these actions are invisible and produce no output
  1388 + if(isset($_GET['action']) && isset($_GET['confirm']))
  1389 + {
  1390 + switch($_GET['action'])
  1391 + {
  1392 + //table actions
  1393 + /////////////////////////////////////////////// create table
  1394 + case "table_create":
  1395 + $num = intval($_POST['rows']);
  1396 + $name = $_POST['tablename'];
  1397 + $query = "CREATE TABLE ".$name."(";
  1398 + for($i=0; $i<$num; $i++)
  1399 + {
  1400 + if($_POST[$i.'_field']!="")
  1401 + {
  1402 + $query .= $_POST[$i.'_field']." ";
  1403 + $query .= $_POST[$i.'_type']." ";
  1404 + if(isset($_POST[$i.'_primarykey']))
  1405 + $query .= "PRIMARY KEY ";
  1406 + if(isset($_POST[$i.'_notnull']))
  1407 + $query .= "NOT NULL ";
  1408 + if($_POST[$i.'_defaultvalue']!="")
  1409 + {
  1410 + if($_POST[$i.'_type']=="INTEGER")
  1411 + $query .= "default ".$_POST[$i.'_defaultvalue']." ";
  1412 + else
  1413 + $query .= "default '".$_POST[$i.'_defaultvalue']."' ";
  1414 + }
  1415 + $query = substr($query, 0, sizeof($query)-2);
  1416 + $query .= ", ";
  1417 + }
  1418 + }
  1419 + $query = substr($query, 0, sizeof($query)-3);
  1420 + $query .= ")";
  1421 + $result = $db->query($query);
  1422 + if(!$result)
  1423 + $error = true;
  1424 + $completed = "Table '".$_POST['tablename']."' has been created.<br/><span style='font-size:11px;'>".$query."</span>";
  1425 + break;
  1426 + /////////////////////////////////////////////// empty table
  1427 + case "table_empty":
  1428 + $query = "DELETE FROM ".$_POST['tablename'];
  1429 + $result = $db->query($query);
  1430 + if(!$result)
  1431 + $error = true;
  1432 + $query = "VACUUM";
  1433 + $result = $db->query($query);
  1434 + if(!$result)
  1435 + $error = true;
  1436 + $completed = "Table '".$_POST['tablename']."' has been emptied.<br/><span style='font-size:11px;'>".$query."</span>";
  1437 + break;
  1438 + /////////////////////////////////////////////// drop table
  1439 + case "table_drop":
  1440 + $query = "DROP TABLE ".$_POST['tablename'];
  1441 + $db->query($query);
  1442 + $completed = "Table '".$_POST['tablename']."' has been dropped.";
  1443 + break;
  1444 + /////////////////////////////////////////////// rename table
  1445 + case "table_rename":
  1446 + $query = "ALTER TABLE ".$_POST['oldname']." RENAME TO ".$_POST['newname'];
  1447 + if($db->getVersion()==3)
  1448 + $result = $db->query($query, true);
  1449 + else
  1450 + $result = $db->query($query, false);
  1451 + if(!$result)
  1452 + $error = true;
  1453 + $completed = "Table '".$_POST['oldname']."' has been renamed to '".$_POST['newname']."'.<br/><span style='font-size:11px;'>".$query."</span>";
  1454 + break;
  1455 + //row actions
  1456 + /////////////////////////////////////////////// create row
  1457 + case "row_create":
  1458 + $completed = "";
  1459 + $num = $_POST['numRows'];
  1460 + $fields = explode(":", $_POST['fields']);
  1461 + $z = 0;
  1462 + for($i=0; $i<$num; $i++)
  1463 + {
  1464 + if(!isset($_POST[$i.":ignore"]))
  1465 + {
  1466 + $query = "INSERT INTO ".$_GET['table']." (";
  1467 + for($j=0; $j<sizeof($fields); $j++)
  1468 + {
  1469 + $query .= $fields[$j].",";
  1470 + }
  1471 + $query = substr($query, 0, sizeof($query)-2);
  1472 + $query .= ") VALUES (";
  1473 + for($j=0; $j<sizeof($fields); $j++)
  1474 + {
  1475 + $value = $_POST[$i.":".$fields[$j]];
  1476 + $function = $_POST["function_".$i."_".$fields[$j]];
  1477 + if($function!="")
  1478 + $query .= $function."(";
  1479 + if($value=="")
  1480 + $query .= "NULL";
  1481 + else
  1482 + $query .= $db->quote($value);
  1483 + if($function!="")
  1484 + $query .= ")";
  1485 + $query .= ",";
  1486 + }
  1487 + $query = substr($query, 0, sizeof($query)-2);
  1488 + $query .= ")";
  1489 + $result = $db->query($query);
  1490 + if(!$result)
  1491 + $error = true;
  1492 + $completed .= "<span style='font-size:11px;'>".$query."</span><br/>";
  1493 + $z++;
  1494 + }
  1495 + }
  1496 + $completed = $z." row(s) inserted.<br/><br/>".$completed;
  1497 + break;
  1498 + /////////////////////////////////////////////// delete row
  1499 + case "row_delete":
  1500 + $pks = explode(":", $_GET['pk']);
  1501 + $str = $pks[0];
  1502 + $query = "DELETE FROM ".$_GET['table']." WHERE ROWID = ".$pks[0];
  1503 + for($i=1; $i<sizeof($pks); $i++)
  1504 + {
  1505 + $str .= ", ".$pks[$i];
  1506 + $query .= " OR ROWID = ".$pks[$i];
  1507 + }
  1508 + $result = $db->query($query);
  1509 + if(!$result)
  1510 + $error = true;
  1511 + $completed = sizeof($pks)." row(s) deleted.<br/><span style='font-size:11px;'>".$query."</span>";
  1512 + break;
  1513 + /////////////////////////////////////////////// edit row
  1514 + case "row_edit":
  1515 + $pks = explode(":", $_GET['pk']);
  1516 + $fields = explode(":", $_POST['fieldArray']);
  1517 +
  1518 + $completed = sizeof($pks)." row(s) affected.<br/><br/>";
  1519 +
  1520 + for($i=0; $i<sizeof($pks); $i++)
  1521 + {
  1522 + $query = "UPDATE ".$_GET['table']." SET ";
  1523 + for($j=0; $j<sizeof($fields); $j++)
  1524 + {
  1525 + $function = $_POST["function_".$pks[$i]."_".$fields[$j]];
  1526 + $query .= $fields[$j]."=";
  1527 + if($function!="")
  1528 + $query .= $function."(";
  1529 + $query .= $db->quote($_POST[$pks[$i].":".$fields[$j]]);
  1530 + if($function!="")
  1531 + $query .= ")";
  1532 + $query .= ", ";
  1533 + }
  1534 + $query = substr($query, 0, sizeof($query)-3);
  1535 + $query .= " WHERE ROWID = ".$pks[$i];
  1536 + $result = $db->query($query);
  1537 + if(!$result)
  1538 + {
  1539 + $error = true;
  1540 + }
  1541 + $completed .= "<span style='font-size:11px;'>".$query."</span><br/>";
  1542 + }
  1543 + break;
  1544 + //column actions
  1545 + /////////////////////////////////////////////// create column
  1546 + case "column_create":
  1547 + $num = intval($_POST['rows']);
  1548 + for($i=0; $i<$num; $i++)
  1549 + {
  1550 + if($_POST[$i.'_field']!="")
  1551 + {
  1552 + $query = "ALTER TABLE ".$_GET['table']." ADD ".$_POST[$i.'_field']." ";
  1553 + $query .= $_POST[$i.'_type']." ";
  1554 + if(isset($_POST[$i.'_primarykey']))
  1555 + $query .= "PRIMARY KEY ";
  1556 + if(isset($_POST[$i.'_notnull']))
  1557 + $query .= "NOT NULL ";
  1558 + if($_POST[$i.'_defaultvalue']!="")
  1559 + {
  1560 + if($_POST[$i.'_type']=="INTEGER")
  1561 + $query .= "DEFAULT ".$_POST[$i.'_defaultvalue']." ";
  1562 + else
  1563 + $query .= "DEFAULT '".$_POST[$i.'_defaultvalue']."' ";
  1564 + }
  1565 + if($db->getVersion()==3)
  1566 + $result = $db->query($query, true);
  1567 + else
  1568 + $result = $db->query($query, false);
  1569 + if(!$result)
  1570 + $error = true;
  1571 + }
  1572 + }
  1573 + $completed = "Table '".$_GET['table']."' has been altered successfully.";
  1574 + break;
  1575 + /////////////////////////////////////////////// delete column
  1576 + case "column_delete":
  1577 + $pks = explode(":", $_GET['pk']);
  1578 + $str = $pks[0];
  1579 + $query = "ALTER TABLE ".$_GET['table']." DROP ".$pks[0];
  1580 + for($i=1; $i<sizeof($pks); $i++)
  1581 + {
  1582 + $str .= ", ".$pks[$i];
  1583 + $query .= ", DROP ".$pks[$i];
  1584 + }
  1585 + $result = $db->query($query);
  1586 + if(!$result)
  1587 + $error = true;
  1588 + $completed = "Table '".$_GET['table']."' has been altered successfully.";
  1589 + break;
  1590 + /////////////////////////////////////////////// edit column
  1591 + case "column_edit":
  1592 + $query = "ALTER TABLE ".$_GET['table']." CHANGE ".$_POST['field_old']." ".$_POST['field']." ".$_POST['type'];
  1593 + $result = $db->query($query);
  1594 + if(!$result)
  1595 + $error = true;
  1596 + $completed = "Table '".$_GET['table']."' has been altered successfully.";
  1597 + break;
  1598 + /////////////////////////////////////////////// delete index
  1599 + case "index_delete":
  1600 + $query = "DROP INDEX ".$_GET['pk'];
  1601 + $result = $db->query($query);
  1602 + if(!$result)
  1603 + $error = true;
  1604 + $completed = "Index '".$_GET['pk']."' deleted.<br/><span style='font-size:11px;'>".$query."</span>";
  1605 + break;
  1606 + /////////////////////////////////////////////// create index
  1607 + case "index_create":
  1608 + $num = $_POST['num'];
  1609 +
  1610 + $str = "CREATE ";
  1611 + if($_POST['duplicate']=="no")
  1612 + $str .= "UNIQUE ";
  1613 + $str .= "INDEX ".$_POST['name']." ON ".$_GET['table']." (";
  1614 + $str .= $_POST['0_field'].$_POST['0_order'];
  1615 + for($i=1; $i<$num; $i++)
  1616 + {
  1617 + if($_POST[$i.'_field']!="--Ignore--")
  1618 + $str .= ", ".$_POST[$i.'_field'].$_POST[$i.'_order'];
  1619 + }
  1620 + $str .= ")";
  1621 + $query = $str;
  1622 + $result = $db->query($query);
  1623 + if(!$result)
  1624 + $error = true;
  1625 + $completed = "Index created.<br/><span style='font-size:11px;'>".$query."</span>";
  1626 + break;
  1627 + }
  1628 + }
  1629 +
  1630 + echo "<div id='container'>";
  1631 + echo "<div id='leftNav'>";
  1632 + echo "<h1>";
  1633 + echo "<a href='".PAGE."'>";
  1634 + echo "<span id='logo'>".PROJECT."</span> <span id='version'>v".VERSION."</span>";
  1635 + echo "</a>";
  1636 + echo "</h1>";
  1637 + echo "<fieldset style='margin:15px;'><legend><b>Change Database</b></legend>";
  1638 + 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
  1639 + {
  1640 + for($i=0; $i<sizeof($databases); $i++)
  1641 + {
  1642 + if($i==$_SESSION[COOKIENAME.'currentDB'])
  1643 + echo "<a href='".PAGE."?switchdb=".$i."' style='text-decoration:underline;'>".$databases[$i]['name']."</a>";
  1644 + else
  1645 + echo "<a href='".PAGE."?switchdb=".$i."'>".$databases[$i]['name']."</a>";
  1646 + if($i<sizeof($databases)-1)
  1647 + echo "<br/>";
  1648 + }
  1649 + }
  1650 + else //there are a lot of databases - show a drop down menu
  1651 + {
  1652 + echo "<form action='".PAGE."' method='post'>";
  1653 + echo "<select name='database_switch'>";
  1654 + for($i=0; $i<sizeof($databases); $i++)
  1655 + {
  1656 + if($i==$_SESSION[COOKIENAME.'currentDB'])
  1657 + echo "<option value='".$i."' selected='selected'>".$databases[$i]['name']."</option>";
  1658 + else
  1659 + echo "<option value='".$i."'>".$databases[$i]['name']."</option>";
  1660 + }
  1661 + echo "</select> ";
  1662 + echo "<input type='submit' value='Go' class='btn'>";
  1663 + echo "</form>";
  1664 + }
  1665 + echo "</fieldset>";
  1666 + echo "<fieldset style='margin:15px;'><legend>";
  1667 + echo "<a href='".PAGE."'";
  1668 + if(!isset($_GET['table']))
  1669 + echo " style='text-decoration:underline;'";
  1670 + echo ">".$currentDB['name']."</a>";
  1671 + echo "</legend>";
  1672 + //Display list of tables
  1673 + $query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
  1674 + $result = $db->selectArray($query);
  1675 + $j=0;
  1676 + for($i=0; $i<sizeof($result); $i++)
  1677 + {
  1678 + if(substr($result[$i]['name'], 0, 7)!="sqlite_" && $result[$i]['name']!="")
  1679 + {
  1680 + echo "<a href='".PAGE."?action=row_view&table=".$result[$i]['name']."'";
  1681 + if(isset($_GET['table']) && $_GET['table']==$result[$i]['name'])
  1682 + echo " style='text-decoration:underline;'";
  1683 + echo ">".$result[$i]['name']."</a><br/>";
  1684 + $j++;
  1685 + }
  1686 + }
  1687 + if($j==0)
  1688 + echo "No tables in database.";
  1689 + echo "</fieldset>";
  1690 + echo "<div style='text-align:center;'>";
  1691 + echo "<form action='".PAGE."' method='post'/>";
  1692 + echo "<input type='submit' value='Log Out' name='logout' class='btn'/>";
  1693 + echo "</form>";
  1694 + echo "</div>";
  1695 + echo "</div>";
  1696 + echo "<div id='content'>";
  1697 +
  1698 + //breadcrumb navigation
  1699 + echo "<a href='".PAGE."'>".$currentDB['name']."</a>";
  1700 + if(isset($_GET['table']))
  1701 + echo " &rarr; <a href='".PAGE."?table=".$_GET['table']."&action=row_view'>".$_GET['table']."</a>";
  1702 + echo "<br/><br/>";
  1703 +
  1704 + //user has performed some action so show the resulting message
  1705 + if(isset($_GET['confirm']))
  1706 + {
  1707 + echo "<div id='main'>";
  1708 + echo "<div class='confirm'>";
  1709 + if(isset($error) && $error) //an error occured during the action, so show an error message
  1710 + echo "An error occured. This may be a bug that needs to be reported at <a href='http://code.google.com/p/phpliteadmin/issues/list' target='_blank'>code.google.com/p/phpliteadmin/issues/list</a>";
  1711 + else //action was performed successfully - show success message
  1712 + echo $completed;
  1713 + echo "</div>";
  1714 + if($_GET['action']=="row_delete" || $_GET['action']=="row_create" || $_GET['action']=="row_edit")
  1715 + echo "<br/><br/><a href='".PAGE."?table=".$_GET['table']."&action=row_view'>Return</a>";
  1716 + else if($_GET['action']=="column_create" || $_GET['action']=="column_delete" || $_GET['action']=="column_edit" || $_GET['action']=="index_create" || $_GET['action']=="index_delete")
  1717 + echo "<br/><br/><a href='".PAGE."?table=".$_GET['table']."&action=column_view'>Return</a>";
  1718 + else
  1719 + echo "<br/><br/><a href='".PAGE."'>Return</a>";
  1720 + echo "</div>";
  1721 + }
  1722 +
  1723 + //show the various tab views for a table
  1724 + if(!isset($_GET['confirm']) && isset($_GET['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"))
  1725 + {
  1726 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=row_view' ";
  1727 + if($_GET['action']=="row_view")
  1728 + echo "class='tab_pressed'";
  1729 + else
  1730 + echo "class='tab'";
  1731 + echo ">Browse</a>";
  1732 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=column_view' ";
  1733 + if($_GET['action']=="column_view")
  1734 + echo "class='tab_pressed'";
  1735 + else
  1736 + echo "class='tab'";
  1737 + echo ">Structure</a>";
  1738 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_sql' ";
  1739 + if($_GET['action']=="table_sql")
  1740 + echo "class='tab_pressed'";
  1741 + else
  1742 + echo "class='tab'";
  1743 + echo ">SQL</a>";
  1744 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_search' ";
  1745 + if($_GET['action']=="table_search")
  1746 + echo "class='tab_pressed'";
  1747 + else
  1748 + echo "class='tab'";
  1749 + echo ">Search</a>";
  1750 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=row_create' ";
  1751 + if($_GET['action']=="row_create")
  1752 + echo "class='tab_pressed'";
  1753 + else
  1754 + echo "class='tab'";
  1755 + echo ">Insert</a>";
  1756 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_export' ";
  1757 + if($_GET['action']=="table_export")
  1758 + echo "class='tab_pressed'";
  1759 + else
  1760 + echo "class='tab'";
  1761 + echo ">Export</a>";
  1762 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_import' ";
  1763 + if($_GET['action']=="table_import")
  1764 + echo "class='tab_pressed'";
  1765 + else
  1766 + echo "class='tab'";
  1767 + echo ">Import</a>";
  1768 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_rename' ";
  1769 + if($_GET['action']=="table_rename")
  1770 + echo "class='tab_pressed'";
  1771 + else
  1772 + echo "class='tab'";
  1773 + echo ">Rename</a>";
  1774 + echo "<a href='".PAGE."?action=table_empty&table=".$_GET['table']."' ";
  1775 + echo "class='tab' style='color:red;'";
  1776 + echo ">Empty</a>";
  1777 + echo "<a href='".PAGE."?action=table_drop&table=".$_GET['table']."' ";
  1778 + echo "class='tab' style='color:red;'";
  1779 + echo ">Drop</a>";
  1780 + echo "<div style='clear:both;'></div>";
  1781 + }
  1782 +
  1783 + //switch board for the page display
  1784 + if(isset($_GET['action']) && !isset($_GET['confirm']))
  1785 + {
  1786 + echo "<div id='main'>";
  1787 + switch($_GET['action'])
  1788 + {
  1789 + //table actions
  1790 + /////////////////////////////////////////////// create table
  1791 + case "table_create":
  1792 + echo "<h2>Creating new table: '".$_POST['tablename']."'</h2>";
  1793 + if($_POST['tablefields']=="" || intval($_POST['tablefields'])<=0)
  1794 + echo "You must specify the number of table fields.";
  1795 + else if($_POST['tablename']=="")
  1796 + echo "You must specify a table name.";
  1797 + else
  1798 + {
  1799 + $num = intval($_POST['tablefields']);
  1800 + $name = $_POST['tablename'];
  1801 + echo "<form action='".PAGE."?action=table_create&confirm=1' method='post'>";
  1802 + echo "<input type='hidden' name='tablename' value='".$name."'/>";
  1803 + echo "<input type='hidden' name='rows' value='".$num."'/>";
  1804 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  1805 + echo "<tr>";
  1806 + $headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value");
  1807 + for($k=0; $k<count($headings); $k++)
  1808 + echo "<td class='tdheader'>" . $headings[$k] . "</td>";
  1809 + echo "</tr>";
  1810 +
  1811 + for($i=0; $i<$num; $i++)
  1812 + {
  1813 + $tdWithClass = "<td class='td" . ($i%2 ? "1" : "2") . "'>";
  1814 + echo "<tr>";
  1815 + echo $tdWithClass;
  1816 + echo "<input type='text' name='".$i."_field' style='width:200px;'/>";
  1817 + echo "</td>";
  1818 + echo $tdWithClass;
  1819 + echo "<select name='".$i."_type' id='".$i."_type' onchange='toggleAutoincrement(".$i.");'>";
  1820 + $types = unserialize(DATATYPES);
  1821 + for($z=0; $z<sizeof($types); $z++)
  1822 + echo "<option value='".$types[$z]."'>".$types[$z]."</option>";
  1823 + echo "</select>";
  1824 + echo "</td>";
  1825 + echo $tdWithClass;
  1826 + echo "<input type='checkbox' name='".$i."_primarykey'/> Yes";
  1827 + echo "</td>";
  1828 + echo $tdWithClass;
  1829 + echo "<input type='checkbox' name='".$i."_autoincrement' id='".$i."_autoincrement'/> Yes";
  1830 + echo "</td>";
  1831 + echo $tdWithClass;
  1832 + echo "<input type='checkbox' name='".$i."_notnull'/> Yes";
  1833 + echo "</td>";
  1834 + echo $tdWithClass;
  1835 + echo "<input type='text' name='".$i."_defaultvalue' style='width:100px;'/>";
  1836 + echo "</td>";
  1837 + echo "</tr>";
  1838 + }
  1839 + echo "<tr>";
  1840 + echo "<td class='tdheader' style='text-align:right;' colspan='6'>";
  1841 + echo "<input type='submit' value='Create' class='btn'/> ";
  1842 + echo "<a href='".PAGE."'>Cancel</a>";
  1843 + echo "</td>";
  1844 + echo "</tr>";
  1845 + echo "</table>";
  1846 + echo "</form>";
  1847 + }
  1848 + break;
  1849 + /////////////////////////////////////////////// perform SQL query on table
  1850 + case "table_sql":
  1851 + $isSelect = false;
  1852 + if(isset($_POST['query']) && $_POST['query']!="")
  1853 + {
  1854 + $delimiter = $_POST['delimiter'];
  1855 + $queryStr = stripslashes($_POST['queryval']);
  1856 + $query = explode($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter
  1857 +
  1858 + for($i=0; $i<sizeof($query); $i++) //iterate through the queries exploded by the delimiter
  1859 + {
  1860 + if(str_replace(" ", "", str_replace("\n", "", str_replace("\r", "", $query[$i])))!="") //make sure this query is not an empty string
  1861 + {
  1862 + $startTime = microtime(true);
  1863 + if(strpos(strtolower($query[$i]), "select ")!==false)
  1864 + {
  1865 + $isSelect = true;
  1866 + $result = $db->selectArray($query[$i], "assoc");
  1867 + }
  1868 + else
  1869 + {
  1870 + $isSelect = false;
  1871 + $result = $db->query($query[$i]);
  1872 + }
  1873 + $endTime = microtime(true);
  1874 + $time = round(($endTime - $startTime), 4);
  1875 +
  1876 + echo "<div class='confirm'>";
  1877 + echo "<b>";
  1878 + if($isSelect && $result)
  1879 + {
  1880 + if($isSelect)
  1881 + {
  1882 + $affected = sizeof($result);
  1883 + echo "Showing ".$affected." row(s). ";
  1884 + }
  1885 + else
  1886 + {
  1887 + $affected = $db->getAffectedRows();
  1888 + echo $affected." row(s) affected. ";
  1889 + }
  1890 + echo "(Query took ".$time." sec)</b><br/>";
  1891 + }
  1892 + else
  1893 + {
  1894 + echo "There is a problem with the syntax of your query ";
  1895 + echo "(Query was not executed)</b><br/>";
  1896 + }
  1897 + echo "<span style='font-size:11px;'>".$query[$i]."</span>";
  1898 + echo "</div><br/>";
  1899 + if($isSelect)
  1900 + {
  1901 + if(sizeof($result)>0)
  1902 + {
  1903 + $headers = array_keys($result[0]);
  1904 +
  1905 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  1906 + echo "<tr>";
  1907 + for($j=0; $j<sizeof($headers); $j++)
  1908 + {
  1909 + echo "<td class='tdheader'>";
  1910 + echo $headers[$j];
  1911 + echo "</td>";
  1912 + }
  1913 + echo "</tr>";
  1914 + for($j=0; $j<sizeof($result); $j++)
  1915 + {
  1916 + $tdWithClass = "<td class='td".($j%2 ? "1" : "2")."'>";
  1917 + echo "<tr>";
  1918 + for($z=0; $z<sizeof($headers); $z++)
  1919 + {
  1920 + echo $tdWithClass;
  1921 + echo $result[$j][$headers[$z]];
  1922 + echo "</td>";
  1923 + }
  1924 + echo "</tr>";
  1925 + }
  1926 + echo "</table><br/><br/>";
  1927 + }
  1928 + }
  1929 + }
  1930 + }
  1931 + }
  1932 + else
  1933 + {
  1934 + $delimiter = ";";
  1935 + $queryStr = "SELECT * FROM `".$_GET['table']."` WHERE 1";
  1936 + }
  1937 +
  1938 + echo "<fieldset>";
  1939 + echo "<legend><b>Run SQL query/queries on database '".$db->getName()."'</b></legend>";
  1940 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=table_sql' method='post'>";
  1941 + echo "<div style='float:left; width:70%;'>";
  1942 + echo "<textarea style='width:97%; height:300px;' name='queryval' id='queryval'>".$queryStr."</textarea>";
  1943 + echo "</div>";
  1944 + echo "<div style='float:left; width:28%; padding-left:10px;'>";
  1945 + echo "Fields<br/>";
  1946 + echo "<select multiple='multiple' style='width:100%;' id='fieldcontainer'>";
  1947 + $query = "PRAGMA table_info('".$_GET['table']."')";
  1948 + $result = $db->selectArray($query);
  1949 + for($i=0; $i<sizeof($result); $i++)
  1950 + {
  1951 + echo "<option value='".$result[$i][1]."'>".$result[$i][1]."</option>";
  1952 + }
  1953 + echo "</select>";
  1954 + echo "<input type='button' value='<<' onclick='moveFields();' class='btn'/>";
  1955 + echo "</div>";
  1956 + echo "<div style='clear:both;'></div>";
  1957 + echo "Delimiter <input type='text' name='delimiter' value='".$delimiter."' style='width:50px;'/> ";
  1958 + echo "<input type='submit' name='query' value='Go' class='btn'/>";
  1959 + echo "</form>";
  1960 + break;
  1961 + /////////////////////////////////////////////// empty table
  1962 + case "table_empty":
  1963 + echo "<form action='".PAGE."?action=table_empty&confirm=1' method='post'>";
  1964 + echo "<input type='hidden' name='tablename' value='".$_GET['table']."'/>";
  1965 + echo "<div class='confirm'>";
  1966 + echo "Are you sure you want to empty the table '".$_GET['table']."'?<br/><br/>";
  1967 + echo "<input type='submit' value='Confirm' class='btn'/> ";
  1968 + echo "<a href='".PAGE."'>Cancel</a>";
  1969 + echo "</div>";
  1970 + break;
  1971 + /////////////////////////////////////////////// drop table
  1972 + case "table_drop":
  1973 + echo "<form action='".PAGE."?action=table_drop&confirm=1' method='post'>";
  1974 + echo "<input type='hidden' name='tablename' value='".$_GET['table']."'/>";
  1975 + echo "<div class='confirm'>";
  1976 + echo "Are you sure you want to drop the table '".$_GET['table']."'?<br/><br/>";
  1977 + echo "<input type='submit' value='Confirm' class='btn'/> ";
  1978 + echo "<a href='".PAGE."'>Cancel</a>";
  1979 + echo "</div>";
  1980 + break;
  1981 + /////////////////////////////////////////////// export table
  1982 + case "table_export":
  1983 + echo "<form method='post' action='".PAGE."'>";
  1984 + echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>Export</b></legend>";
  1985 + echo "<input type='hidden' value='".$_GET['table']."' name='single_table'/>";
  1986 + echo "<input type='radio' name='export_type' checked='checked' value='sql'/> SQL";
  1987 + echo "</fieldset>";
  1988 + echo "<fieldset style='float:left;'><legend><b>Options</b></legend>";
  1989 + echo "<input type='checkbox' checked='checked' name='structure'/> Export with structure [<a onmouseover='tooltip.show(\"Creates the queries to add the tables and their columns\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  1990 + echo "<input type='checkbox' checked='checked' name='data'/> Export with data [<a onmouseover='tooltip.show(\"Creates the queries to insert the table rows\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  1991 + echo "<input type='checkbox' name='drop'/> Add DROP TABLE [<a onmouseover='tooltip.show(\"Creates the queries to remove the tables before potentially adding them so that errors do not occur if they already exist\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  1992 + echo "<input type='checkbox' checked='checked' name='transaction'/> Add TRANSACTION [<a onmouseover='tooltip.show(\"Performs queries within transactions so that if an error occurs, the table is not returned to a partially incomplete and unusable state\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  1993 + echo "<input type='checkbox' checked='checked' name='comments'/> Comments [<a onmouseover='tooltip.show(\"Adds comments to the file to explain what is happening in each part of it\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  1994 + echo "</fieldset>";
  1995 + echo "<div style='clear:both;'></div>";
  1996 + echo "<br/><br/>";
  1997 + echo "<fieldset style='float:left;'><legend><b>Save As</b></legend>";
  1998 + echo "<input type='hidden' name='database_num' value='".$_SESSION[COOKIENAME.'currentDB']."'/>";
  1999 + echo "<input type='text' name='filename' value='".$db->getPath().".".$_GET['table'].".".date("n-j-y").".dump' style='width:400px;'/> <input type='submit' name='export' value='Export' class='btn'/>";
  2000 + echo "</fieldset>";
  2001 + echo "</form>";
  2002 + break;
  2003 + /////////////////////////////////////////////// import table
  2004 + case "table_import":
  2005 + if(isset($_POST['import']))
  2006 + {
  2007 + echo "<div class='confirm'>";
  2008 + echo "Import was successful.";
  2009 + echo "</div><br/>";
  2010 + }
  2011 + echo "<form method='post' action='".PAGE."?table=".$_GET['action']."&action=table_import' enctype='multipart/form-data'>";
  2012 + echo "<fieldset><legend><b>File to import</b></legend>";
  2013 + echo "<input type='radio' name='export_type' checked='checked' value='sql'/> SQL";
  2014 + echo "<br/><br/>";
  2015 + echo "<input type='file' value='Choose File' name='file' style='background-color:transparent; border-style:none;'/> <input type='submit' value='Import' name='import' class='btn'/>";
  2016 + echo "</fieldset>";
  2017 + break;
  2018 + /////////////////////////////////////////////// rename table
  2019 + case "table_rename":
  2020 + echo "<form action='".PAGE."?action=table_rename&confirm=1' method='post'>";
  2021 + echo "<input type='hidden' name='oldname' value='".$_GET['table']."'/>";
  2022 + echo "Rename table '".$_GET['table']."' to <input type='text' name='newname' style='width:200px;'/> <input type='submit' value='Rename' name='rename' class='btn'/>";
  2023 + echo "</form>";
  2024 + break;
  2025 + /////////////////////////////////////////////// search table
  2026 + case "table_search":
  2027 + if(isset($_GET['done']))
  2028 + {
  2029 + $query = "PRAGMA table_info('".$_GET['table']."')";
  2030 + $result = $db->selectArray($query);
  2031 + $str = "";
  2032 + $j = 0;
  2033 + $arr = array();
  2034 + for($i=0; $i<sizeof($result); $i++)
  2035 + {
  2036 + $field = $result[$i][1];
  2037 + $operator = $_POST[$field.":operator"];
  2038 + $value = $_POST[$field];
  2039 + if($value!="" || $operator=="!= ''" || $operator=="= ''")
  2040 + {
  2041 + if($operator=="= ''" || $operator=="!= ''")
  2042 + $arr[$j] .= $field." ".$operator;
  2043 + else
  2044 + $arr[$j] .= $field." ".$operator." ".$db->quote($value);
  2045 + $j++;
  2046 + }
  2047 + }
  2048 + $query = "SELECT * FROM ".$_GET['table'];
  2049 + if(sizeof($arr)>0)
  2050 + {
  2051 + $query .= " WHERE ".$arr[0];
  2052 + for($i=1; $i<sizeof($arr); $i++)
  2053 + {
  2054 + $query .= " AND ".$arr[$i];
  2055 + }
  2056 + }
  2057 + $startTime = microtime(true);
  2058 + $result = $db->selectArray($query, "assoc");
  2059 + $endTime = microtime(true);
  2060 + $time = round(($endTime - $startTime), 4);
  2061 +
  2062 + echo "<div class='confirm'>";
  2063 + echo "<b>";
  2064 + if($result)
  2065 + {
  2066 + $affected = sizeof($result);
  2067 + echo "Showing ".$affected." row(s). ";
  2068 + echo "(Query took ".$time." sec)</b><br/>";
  2069 + }
  2070 + else
  2071 + {
  2072 + echo "There is a problem with the syntax of your query ";
  2073 + echo "(Query was not executed)</b><br/>";
  2074 + }
  2075 + echo "<span style='font-size:11px;'>".$query."</span>";
  2076 + echo "</div><br/>";
  2077 +
  2078 + if(sizeof($result)>0)
  2079 + {
  2080 + $headers = array_keys($result[0]);
  2081 +
  2082 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2083 + echo "<tr>";
  2084 + for($j=0; $j<sizeof($headers); $j++)
  2085 + {
  2086 + echo "<td class='tdheader'>";
  2087 + echo $headers[$j];
  2088 + echo "</td>";
  2089 + }
  2090 + echo "</tr>";
  2091 + for($j=0; $j<sizeof($result); $j++)
  2092 + {
  2093 + $tdWithClass = "<td class='td".($j%2 ? "1" : "2")."'>";
  2094 + echo "<tr>";
  2095 + for($z=0; $z<sizeof($headers); $z++)
  2096 + {
  2097 + echo $tdWithClass;
  2098 + echo $result[$j][$headers[$z]];
  2099 + echo "</td>";
  2100 + }
  2101 + echo "</tr>";
  2102 + }
  2103 + echo "</table><br/><br/>";
  2104 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=table_search'>Do Another Search</a>";
  2105 + }
  2106 + }
  2107 + else
  2108 + {
  2109 + $query = "PRAGMA table_info('".$_GET['table']."')";
  2110 + $result = $db->selectArray($query);
  2111 +
  2112 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=table_search&done=1' method='post'>";
  2113 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2114 + echo "<tr>";
  2115 + echo "<td class='tdheader'>Field</td>";
  2116 + echo "<td class='tdheader'>Type</td>";
  2117 + echo "<td class='tdheader'>Operator</td>";
  2118 + echo "<td class='tdheader'>Value</td>";
  2119 + echo "</tr>";
  2120 +
  2121 + for($i=0; $i<sizeof($result); $i++)
  2122 + {
  2123 + $field = $result[$i][1];
  2124 + $type = $result[$i][2];
  2125 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2126 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2127 + echo "<tr>";
  2128 + echo $tdWithClassLeft;
  2129 + echo $field;
  2130 + echo "</td>";
  2131 + echo $tdWithClassLeft;
  2132 + echo $type;
  2133 + echo "</td>";
  2134 + echo $tdWithClassLeft;
  2135 + echo "<select name='".$field.":operator'>";
  2136 + echo "<option value='='>=</option>";
  2137 + if($type=="INTEGER" || $type=="REAL")
  2138 + {
  2139 + echo "<option value='>'>></option>";
  2140 + echo "<option value='>='>>=</option>";
  2141 + echo "<option value='<'><</option>";
  2142 + echo "<option value='<='><=</option>";
  2143 + }
  2144 + else if($type=="TEXT" || $type=="BLOB")
  2145 + {
  2146 + echo "<option value='= '''>= ''</option>";
  2147 + echo "<option value='!= '''>!= ''</option>";
  2148 + }
  2149 + echo "<option value='!='>!=</option>";
  2150 + if($type=="TEXT" || $type=="BLOB")
  2151 + echo "<option value='LIKE' selected='selected'>LIKE</option>";
  2152 + else
  2153 + echo "<option value='LIKE'>LIKE</option>";
  2154 + echo "<option value='NOT LIKE'>NOT LIKE</option>";
  2155 + echo "</select>";
  2156 + echo "</td>";
  2157 + echo $tdWithClassLeft;
  2158 + if($type=="INTEGER" || $type=="REAL" || $type=="NULL")
  2159 + echo "<input type='text' name='".$field."'/>";
  2160 + else
  2161 + echo "<textarea name='".$field."' wrap='hard' rows='1' cols='60'></textarea>";
  2162 + echo "</td>";
  2163 + echo "</tr>";
  2164 + }
  2165 + echo "<tr>";
  2166 + echo "<td class='tdheader' style='text-align:right;' colspan='4'>";
  2167 + echo "<input type='submit' value='Search' class='btn'/>";
  2168 + echo "</td>";
  2169 + echo "</tr>";
  2170 + echo "</table>";
  2171 + echo "</form>";
  2172 + }
  2173 + break;
  2174 + //row actions
  2175 + /////////////////////////////////////////////// view row
  2176 + case "row_view":
  2177 + if(!isset($_POST['startRow']))
  2178 + $_POST['startRow'] = 0;
  2179 +
  2180 + if(isset($_POST['numRows']))
  2181 + $_SESSION[COOKIENAME.'numRows'] = $_POST['numRows'];
  2182 +
  2183 + if(!isset($_SESSION[COOKIENAME.'numRows']))
  2184 + $_SESSION[COOKIENAME.'numRows'] = 30;
  2185 +
  2186 + if(isset($_SESSION[COOKIENAME.'currentTable']) && $_SESSION[COOKIENAME.'currentTable']!=$_GET['table'])
  2187 + {
  2188 + unset($_SESSION[COOKIENAME.'sort']);
  2189 + unset($_SESSION[COOKIENAME.'order']);
  2190 + }
  2191 +
  2192 + $query = "SELECT Count(*) FROM ".$_GET['table'];
  2193 + $rowCount = $db->select($query);
  2194 + $rowCount = intval($rowCount[0]);
  2195 + $lastPage = intval($rowCount / $_SESSION[COOKIENAME.'numRows']);
  2196 + $remainder = intval($rowCount % $_SESSION[COOKIENAME.'numRows']);
  2197 + if($remainder==0)
  2198 + $remainder = $_SESSION[COOKIENAME.'numRows'];
  2199 +
  2200 + echo "<div style='overflow:hidden;'>";
  2201 + //previous button
  2202 + if($_POST['startRow']>0)
  2203 + {
  2204 + echo "<div style='float:left; overflow:hidden;'>";
  2205 + echo "<form action='".PAGE."?action=row_view&table=".$_GET['table']."' method='post'>";
  2206 + echo "<input type='hidden' name='startRow' value='0'/>";
  2207 + echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> ";
  2208 + echo "<input type='submit' value='&larr;&larr;' name='previous' class='btn'/> ";
  2209 + echo "</form>";
  2210 + echo "</div>";
  2211 + echo "<div style='float:left; overflow:hidden; margin-right:20px;'>";
  2212 + echo "<form action='".PAGE."?action=row_view&table=".$_GET['table']."' method='post'>";
  2213 + echo "<input type='hidden' name='startRow' value='".intval($_POST['startRow']-$_SESSION[COOKIENAME.'numRows'])."'/>";
  2214 + echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> ";
  2215 + echo "<input type='submit' value='&larr;' name='previous_full' class='btn'/> ";
  2216 + echo "</form>";
  2217 + echo "</div>";
  2218 + }
  2219 +
  2220 + //show certain number buttons
  2221 + echo "<div style='float:left; overflow:hidden;'>";
  2222 + echo "<form action='".PAGE."?action=row_view&table=".$_GET['table']."' method='post'>";
  2223 + echo "<input type='submit' value='Show : ' name='show' class='btn'/> ";
  2224 + echo "<input type='text' name='numRows' style='width:50px;' value='".$_SESSION[COOKIENAME.'numRows']."'/> ";
  2225 + echo "row(s) starting from record # ";
  2226 + if(intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows']) < $rowCount)
  2227 + echo "<input type='text' name='startRow' style='width:90px;' value='".intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])."'/>";
  2228 + else
  2229 + echo "<input type='text' name='startRow' style='width:90px;' value='0'/>";
  2230 + echo "</form>";
  2231 + echo "</div>";
  2232 +
  2233 + //next button
  2234 + if(intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])<$rowCount)
  2235 + {
  2236 + echo "<div style='float:left; overflow:hidden; margin-left:20px; '>";
  2237 + echo "<form action='".PAGE."?action=row_view&table=".$_GET['table']."' method='post'>";
  2238 + echo "<input type='hidden' name='startRow' value='".intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])."'/>";
  2239 + echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> ";
  2240 + echo "<input type='submit' value='&rarr;' name='next' class='btn'/> ";
  2241 + echo "</form>";
  2242 + echo "</div>";
  2243 + echo "<div style='float:left; overflow:hidden;'>";
  2244 + echo "<form action='".PAGE."?action=row_view&table=".$_GET['table']."' method='post'>";
  2245 + echo "<input type='hidden' name='startRow' value='".intval($rowCount-$remainder)."'/>";
  2246 + echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> ";
  2247 + echo "<input type='submit' value='&rarr;&rarr;' name='next_full' class='btn'/> ";
  2248 + echo "</form>";
  2249 + echo "</div>";
  2250 + }
  2251 + echo "<div style='clear:both;'></div>";
  2252 + echo "</div>";
  2253 +
  2254 + if(!isset($_GET['sort']))
  2255 + $_GET['sort'] = NULL;
  2256 + if(!isset($_GET['order']))
  2257 + $_GET['order'] = NULL;
  2258 +
  2259 + $table = $_GET['table'];
  2260 + $numRows = $_SESSION[COOKIENAME.'numRows'];
  2261 + $startRow = $_POST['startRow'];
  2262 + if(isset($_GET['sort']))
  2263 + {
  2264 + $_SESSION[COOKIENAME.'sort'] = $_GET['sort'];
  2265 + $_SESSION[COOKIENAME.'currentTable'] = $_GET['table'];
  2266 + }
  2267 + if(isset($_GET['order']))
  2268 + {
  2269 + $_SESSION[COOKIENAME.'order'] = $_GET['order'];
  2270 + $_SESSION[COOKIENAME.'currentTable'] = $_GET['table'];
  2271 + }
  2272 + $_SESSION[COOKIENAME.'numRows'] = $numRows;
  2273 + $query = "SELECT *, ROWID FROM ".$table;
  2274 + $queryDisp = "SELECT * FROM ".$table;
  2275 + $queryAdd = "";
  2276 + if(isset($_SESSION[COOKIENAME.'sort']))
  2277 + $queryAdd .= " ORDER BY ".$_SESSION[COOKIENAME.'sort'];
  2278 + if(isset($_SESSION[COOKIENAME.'order']))
  2279 + $queryAdd .= " ".$_SESSION[COOKIENAME.'order'];
  2280 + $queryAdd .= " LIMIT ".$startRow.", ".$numRows;
  2281 + $query .= $queryAdd;
  2282 + $queryDisp .= $queryAdd;
  2283 + $startTime = microtime(true);
  2284 + $arr = $db->selectArray($query);
  2285 + $endTime = microtime(true);
  2286 + $time = round(($endTime - $startTime), 4);
  2287 + $total = $db->numRows($table);
  2288 +
  2289 + if(sizeof($arr)>0)
  2290 + {
  2291 + echo "<br/><div class='confirm'>";
  2292 + echo "<b>Showing rows ".$startRow." - ".($startRow + sizeof($arr)-1)." (".$total." total, Query took ".$time." sec)</b><br/>";
  2293 + echo "<span style='font-size:11px;'>".$queryDisp."</span>";
  2294 + echo "</div><br/>";
  2295 +
  2296 + echo "<form action='".PAGE."?action=row_editordelete&table=".$table."' method='post' name='checkForm'>";
  2297 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2298 + $query = "PRAGMA table_info('".$table."')";
  2299 + $result = $db->selectArray($query);
  2300 + $rowidColumn = sizeof($result);
  2301 +
  2302 + echo "<tr>";
  2303 + echo "<td colspan='3'>";
  2304 + echo "</td>";
  2305 +
  2306 + for($i=0; $i<sizeof($result); $i++)
  2307 + {
  2308 + echo "<td class='tdheader'>";
  2309 + echo "<a href='".PAGE."?action=row_view&table=".$table."&sort=".$result[$i][1];
  2310 + if(isset($_SESSION[COOKIENAME.'sort']))
  2311 + $orderTag = ($_SESSION[COOKIENAME.'sort']==$result[$i][1] && $_SESSION[COOKIENAME.'order']=="ASC") ? "DESC" : "ASC";
  2312 + else
  2313 + $orderTag = "ASC";
  2314 + echo "&order=".$orderTag;
  2315 + echo "'>".$result[$i][1]."</a>";
  2316 + if(isset($_SESSION[COOKIENAME.'sort']) && $_SESSION[COOKIENAME.'sort']==$result[$i][1])
  2317 + echo (($_SESSION[COOKIENAME.'order']=="ASC") ? " <b>&uarr;</b>" : " <b>&darr;</b>");
  2318 + echo "</td>";
  2319 + }
  2320 + echo "</tr>";
  2321 +
  2322 + for($i=0; $i<sizeof($arr); $i++)
  2323 + {
  2324 + // -g-> $pk will always be the last column in each row of the array because we are doing a "SELECT *, ROWID FROM ..."
  2325 + $pk = $arr[$i][$rowidColumn];
  2326 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2327 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2328 + echo "<tr>";
  2329 + echo $tdWithClass;
  2330 + echo "<input type='checkbox' name='check[]' value='".$pk."' id='check_".$i."'/>";
  2331 + echo "</td>";
  2332 + echo $tdWithClass;
  2333 + // -g-> Here, we need to put the ROWID in as the link for both the edit and delete.
  2334 + echo "<a href='".PAGE."?table=".$table."&action=row_editordelete&pk=".$pk."&type=edit'>edit</a>";
  2335 + echo "</td>";
  2336 + echo $tdWithClass;
  2337 + echo "<a href='".PAGE."?table=".$table."&action=row_editordelete&pk=".$pk."&type=delete' style='color:red;'>delete</a>";
  2338 + echo "</td>";
  2339 + for($j=0; $j<sizeof($result); $j++)
  2340 + {
  2341 + if(strtolower($result[$j][2])=="integer" || strtolower($result[$j][2])=="float" || strtolower($result[$j][2])=="real")
  2342 + echo $tdWithClass;
  2343 + else
  2344 + echo $tdWithClassLeft;
  2345 + // -g-> although the inputs do not interpret HTML on the way "in", when we print the contents of the database the interpretation cannot be avoided.
  2346 + echo $db->formatString($arr[$i][$j]);
  2347 + echo "</td>";
  2348 + }
  2349 + echo "</tr>";
  2350 + }
  2351 + echo "</table>";
  2352 + echo "<a onclick='checkAll()'>Check All</a> / <a onclick='uncheckAll()'>Uncheck All</a> <i>With selected:</i> ";
  2353 + echo "<select name='type'>";
  2354 + echo "<option value='edit'>Edit</option>";
  2355 + echo "<option value='delete'>Delete</option>";
  2356 + echo "</select> ";
  2357 + echo "<input type='submit' value='Go' name='massGo' class='btn'/>";
  2358 + echo "</form>";
  2359 + }
  2360 + else if($rowCount>0)//no rows - do nothing
  2361 + {
  2362 + echo "<br/><br/>There are no rows in the table for the range you selected.";
  2363 + }
  2364 + else
  2365 + {
  2366 + echo "<br/><br/>This table is empty. <a href='".PAGE."?table=".$_GET['table']."&action=row_create'>Click here</a> to insert rows.";
  2367 + }
  2368 +
  2369 + break;
  2370 + /////////////////////////////////////////////// create row
  2371 + case "row_create":
  2372 + $fieldStr = "";
  2373 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=row_create' method='post'>";
  2374 + echo "Restart insertion with ";
  2375 + echo "<select name='num'>";
  2376 + for($i=1; $i<=40; $i++)
  2377 + {
  2378 + if(isset($_POST['num']) && $_POST['num']==$i)
  2379 + echo "<option value='".$i."' selected='selected'>".$i."</option>";
  2380 + else
  2381 + echo "<option value='".$i."'>".$i."</option>";
  2382 + }
  2383 + echo "</select>";
  2384 + echo " rows ";
  2385 + echo "<input type='submit' value='Go' class='btn'/>";
  2386 + echo "</form>";
  2387 + echo "<br/>";
  2388 + $query = "PRAGMA table_info('".$_GET['table']."')";
  2389 + $result = $db->selectArray($query);
  2390 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=row_create&confirm=1' method='post'>";
  2391 + if(isset($_POST['num']))
  2392 + $num = $_POST['num'];
  2393 + else
  2394 + $num = 1;
  2395 + echo "<input type='hidden' name='numRows' value='".$num."'/>";
  2396 + for($j=0; $j<$num; $j++)
  2397 + {
  2398 + if($j>0)
  2399 + echo "<input type='checkbox' value='ignore' name='".$j.":ignore' id='".$j."_ignore' checked='checked'/> Ignore<br/>";
  2400 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2401 + echo "<tr>";
  2402 + echo "<td class='tdheader'>Field</td>";
  2403 + echo "<td class='tdheader'>Type</td>";
  2404 + echo "<td class='tdheader'>Function</td>";
  2405 + echo "<td class='tdheader'>Value</td>";
  2406 + echo "</tr>";
  2407 +
  2408 + for($i=0; $i<sizeof($result); $i++)
  2409 + {
  2410 + $field = $result[$i][1];
  2411 + if($j==0)
  2412 + $fieldStr .= ":".$field;
  2413 + $type = $result[$i][2];
  2414 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2415 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2416 + echo "<tr>";
  2417 + echo $tdWithClassLeft;
  2418 + echo $field;
  2419 + echo "</td>";
  2420 + echo $tdWithClassLeft;
  2421 + echo $type;
  2422 + echo "</td>";
  2423 + echo $tdWithClassLeft;
  2424 + echo "<select name='function_".$j."_".$field."'>";
  2425 + echo "<option value=''></option>";
  2426 + $functions = unserialize(FUNCTIONS);
  2427 + for($z=0; $z<sizeof($functions); $z++)
  2428 + {
  2429 + echo "<option value='".$functions[$z]."'>".$functions[$z]."</option>";
  2430 + }
  2431 + echo "</select>";
  2432 + echo "</td>";
  2433 + echo $tdWithClassLeft;
  2434 + if($type=="INTEGER" || $type=="REAL" || $type=="NULL")
  2435 + echo "<input type='text' name='".$j.":".$field."' onblur='changeIgnore(this, \"".$j."_ignore\")'/>";
  2436 + else
  2437 + echo "<textarea name='".$j.":".$field."' wrap='hard' rows='1' cols='60' onblur='changeIgnore(this, \"".$j."_ignore\")'></textarea>";
  2438 + echo "</td>";
  2439 + echo "</tr>";
  2440 + }
  2441 + echo "<tr>";
  2442 + echo "<td class='tdheader' style='text-align:right;' colspan='4'>";
  2443 + echo "<input type='submit' value='Insert' class='btn'/>";
  2444 + echo "</td>";
  2445 + echo "</tr>";
  2446 + echo "</table><br/>";
  2447 + }
  2448 + $fieldStr = substr($fieldStr, 1);
  2449 + echo "<input type='hidden' name='fields' value='".$fieldStr."'/>";
  2450 + echo "</form>";
  2451 + break;
  2452 + /////////////////////////////////////////////// edit or delete row
  2453 + case "row_editordelete":
  2454 + if(isset($_POST['check']))
  2455 + $pks = $_POST['check'];
  2456 + else if(isset($_GET['pk']))
  2457 + $pks = array($_GET['pk']);
  2458 + $str = $pks[0];
  2459 + $pkVal = $pks[0];
  2460 + for($i=1; $i<sizeof($pks); $i++)
  2461 + {
  2462 + $str .= ", ".$pks[$i];
  2463 + $pkVal .= ":".$pks[$i];
  2464 + }
  2465 + if($str=="") //nothing was selected so show an error
  2466 + {
  2467 + echo "<div class='confirm'>";
  2468 + echo "Error: You did not select anything.";
  2469 + echo "</div>";
  2470 + echo "<br/><br/><a href='".PAGE."?table=".$_GET['table']."&action=row_view'>Return</a>";
  2471 + }
  2472 + else
  2473 + {
  2474 + if((isset($_POST['type']) && $_POST['type']=="edit") || (isset($_GET['type']) && $_GET['type']=="edit")) //edit
  2475 + {
  2476 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=row_edit&confirm=1&pk=".$pkVal."' method='post'>";
  2477 + $query = "PRAGMA table_info('".$_GET['table']."')";
  2478 + $result = $db->selectArray($query);
  2479 +
  2480 + //build the POST array of fields
  2481 + $fieldStr = $result[0][1];
  2482 + for($j=1; $j<sizeof($result); $j++)
  2483 + $fieldStr .= ":".$result[$j][1];
  2484 +
  2485 + echo "<input type='hidden' name='fieldArray' value='".$fieldStr."'/>";
  2486 +
  2487 + for($j=0; $j<sizeof($pks); $j++)
  2488 + {
  2489 + $query = "SELECT * FROM ".$_GET['table']." WHERE ROWID = ".$pks[$j];
  2490 + $result1 = $db->select($query);
  2491 +
  2492 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2493 + echo "<tr>";
  2494 + echo "<td class='tdheader'>Field</td>";
  2495 + echo "<td class='tdheader'>Type</td>";
  2496 + echo "<td class='tdheader'>Function</td>";
  2497 + echo "<td class='tdheader'>Value</td>";
  2498 + echo "</tr>";
  2499 +
  2500 + for($i=0; $i<sizeof($result); $i++)
  2501 + {
  2502 + $field = $result[$i][1];
  2503 + $type = $result[$i][2];
  2504 + $value = $result1[$i];
  2505 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2506 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2507 + echo "<tr>";
  2508 + echo $tdWithClass;
  2509 + echo $field;
  2510 + echo "</td>";
  2511 + echo $tdWithClass;
  2512 + echo $type;
  2513 + echo "</td>";
  2514 + echo $tdWithClassLeft;
  2515 + echo "<select name='function_".$pks[$j]."_".$field."'>";
  2516 + echo "<option value=''></option>";
  2517 + $functions = unserialize(FUNCTIONS);
  2518 + for($z=0; $z<sizeof($functions); $z++)
  2519 + {
  2520 + echo "<option value='".$functions[$z]."'>".$functions[$z]."</option>";
  2521 + }
  2522 + echo "</select>";
  2523 + echo "</td>";
  2524 + echo $tdWithClassLeft;
  2525 + if($type=="INTEGER" || $type=="REAL" || $type=="NULL")
  2526 + echo "<input type='text' name='".$pks[$j].":".$field."' value='".$db->formatString($value)."'/>";
  2527 + else
  2528 + echo "<textarea name='".$pks[$j].":".$field."' wrap='hard' rows='1' cols='60'>".$db->formatString($value)."</textarea>";
  2529 + echo "</td>";
  2530 + echo "</tr>";
  2531 + }
  2532 + echo "<tr>";
  2533 + echo "<td class='tdheader' style='text-align:right;' colspan='4'>";
  2534 + echo "<input type='submit' value='Save Changes' class='btn'/> ";
  2535 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=row_view'>Cancel</a>";
  2536 + echo "</td>";
  2537 + echo "</tr>";
  2538 + echo "</table>";
  2539 + echo "<br/>";
  2540 + }
  2541 + echo "</form>";
  2542 + }
  2543 + else //delete
  2544 + {
  2545 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=row_delete&confirm=1&pk=".$pkVal."' method='post'>";
  2546 + echo "<div class='confirm'>";
  2547 + echo "Are you sure you want to delete row(s) ".$str." from table '".$_GET['table']."'?<br/><br/>";
  2548 + echo "<input type='submit' value='Confirm' class='btn'/> ";
  2549 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=row_view'>Cancel</a>";
  2550 + echo "</div>";
  2551 + }
  2552 + }
  2553 + break;
  2554 + //column actions
  2555 + /////////////////////////////////////////////// view column
  2556 + case "column_view":
  2557 + $query = "PRAGMA table_info('".$_GET['table']."')";
  2558 + $result = $db->selectArray($query);
  2559 +
  2560 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=column_delete' method='post' name='checkForm'>";
  2561 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2562 + echo "<tr>";
  2563 + echo "<td colspan='2'>";
  2564 + echo "</td>";
  2565 + echo "<td class='tdheader'>Column #</td>";
  2566 + echo "<td class='tdheader'>Field</td>";
  2567 + echo "<td class='tdheader'>Type</td>";
  2568 + echo "<td class='tdheader'>Not Null</td>";
  2569 + echo "<td class='tdheader'>Default Value</td>";
  2570 + echo "<td class='tdheader'>Primary Key</td>";
  2571 + echo "</tr>";
  2572 +
  2573 + for($i=0; $i<sizeof($result); $i++)
  2574 + {
  2575 + $colVal = $result[$i][0];
  2576 + $fieldVal = $result[$i][1];
  2577 + $typeVal = $result[$i][2];
  2578 + $notnullVal = $result[$i][3];
  2579 + $defaultVal = $result[$i][4];
  2580 + $primarykeyVal = $result[$i][5];
  2581 +
  2582 + if(intval($notnullVal)!=0)
  2583 + $notnullVal = "yes";
  2584 + else
  2585 + $notnullVal = "no";
  2586 + if(intval($primarykeyVal)!=0)
  2587 + $primarykeyVal = "yes";
  2588 + else
  2589 + $primarykeyVal = "no";
  2590 +
  2591 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2592 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2593 + echo "<tr>";
  2594 + echo $tdWithClass;
  2595 + echo "<input type='checkbox' name='check[]' value='".$fieldVal."' id='check_".$i."'/>";
  2596 + echo "</td>";
  2597 + echo $tdWithClass;
  2598 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=column_delete&pk=".$fieldVal."' style='color:red;'>delete</a>";
  2599 + echo "</td>";
  2600 + echo $tdWithClass;
  2601 + echo $colVal;
  2602 + echo "</td>";
  2603 + echo $tdWithClassLeft;
  2604 + echo $fieldVal;
  2605 + echo "</td>";
  2606 + echo $tdWithClassLeft;
  2607 + echo $typeVal;
  2608 + echo "</td>";
  2609 + echo $tdWithClassLeft;
  2610 + echo $notnullVal;
  2611 + echo "</td>";
  2612 + echo $tdWithClassLeft;
  2613 + echo $defaultVal;
  2614 + echo "</td>";
  2615 + echo $tdWithClassLeft;
  2616 + echo $primarykeyVal;
  2617 + echo "</td>";
  2618 + echo "</tr>";
  2619 + }
  2620 +
  2621 + echo "</table>";
  2622 +
  2623 + echo "<a onclick='checkAll()'>Check All</a> / <a onclick='uncheckAll()'>Uncheck All</a> <i>With selected:</i> ";
  2624 + echo "<select name='massType'>";
  2625 + //echo "<option value='edit'>Edit</option>";
  2626 + echo "<option value='delete'>Delete</option>";
  2627 + echo "</select> ";
  2628 + echo "<input type='hidden' name='structureDel' value='true'/>";
  2629 + echo "<input type='submit' value='Go' name='massGo' class='btn'/>";
  2630 + echo "</form>";
  2631 +
  2632 + echo "<br/>";
  2633 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=column_create' method='post'>";
  2634 + echo "<input type='hidden' name='tablename' value='".$_GET['table']."'/>";
  2635 + echo "Add <input type='text' name='tablefields' style='width:30px;' value='1'/> field(s) at end of table <input type='submit' value='Go' name='addfields' class='btn'/>";
  2636 + echo "</form>";
  2637 + echo "<br/><hr/><br/>";
  2638 + //$query = "SELECT * FROM sqlite_master WHERE type='index' AND tbl_name='".$_GET['table']."'";
  2639 + $query = "PRAGMA index_list(".$_GET['table'].")";
  2640 + $result = $db->selectArray($query);
  2641 + if(sizeof($result)>0)
  2642 + {
  2643 + echo "<h2>Indexes:</h2>";
  2644 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2645 + echo "<tr>";
  2646 + echo "<td colspan='1'>";
  2647 + echo "</td>";
  2648 + echo "<td class='tdheader'>Name</td>";
  2649 + echo "<td class='tdheader'>Unique</td>";
  2650 + echo "<td class='tdheader'>Seq. No.</td>";
  2651 + echo "<td class='tdheader'>Column #</td>";
  2652 + echo "<td class='tdheader'>Field</td>";
  2653 + echo "</tr>";
  2654 + for($i=0; $i<sizeof($result); $i++)
  2655 + {
  2656 + if($result[$i]['unique']==0)
  2657 + $unique = "no";
  2658 + else
  2659 + $unique = "yes";
  2660 +
  2661 + $query = "PRAGMA index_info(".$result[$i]['name'].")";
  2662 + $info = $db->selectArray($query);
  2663 + $span = sizeof($info);
  2664 +
  2665 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2666 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2667 + $tdWithClassSpan = "<td class='td".($i%2 ? "1" : "2")."' rowspan='".$span."'>";
  2668 + $tdWithClassLeftSpan = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;' rowspan='".$span."'>";
  2669 + echo "<tr>";
  2670 + echo $tdWithClassSpan;
  2671 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=index_delete&pk=".$result[$i]['name']."' style='color:red;'>delete</a>";
  2672 + echo "</td>";
  2673 + echo $tdWithClassLeftSpan;
  2674 + echo $result[$i]['name'];
  2675 + echo "</td>";
  2676 + echo $tdWithClassLeftSpan;
  2677 + echo $unique;
  2678 + echo "</td>";
  2679 + for($j=0; $j<$span; $j++)
  2680 + {
  2681 + if($j!=0)
  2682 + echo "<tr>";
  2683 + echo $tdWithClassLeft;
  2684 + echo $info[$j]['seqno'];
  2685 + echo "</td>";
  2686 + echo $tdWithClassLeft;
  2687 + echo $info[$j]['cid'];
  2688 + echo "</td>";
  2689 + echo $tdWithClassLeft;
  2690 + echo $info[$j]['name'];
  2691 + echo "</td>";
  2692 + echo "</tr>";
  2693 + }
  2694 + }
  2695 + echo "</table>";
  2696 + }
  2697 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=index_create' method='post'>";
  2698 + echo "<input type='hidden' name='tablename' value='".$_GET['table']."'/>";
  2699 + echo "<br/><div class='tdheader'>";
  2700 + echo "Create an index on <input type='text' name='numcolumns' style='width:30px;' value='1'/> columns <input type='submit' value='Go' name='addindex' class='btn'/>";
  2701 + echo "</div>";
  2702 + echo "</form>";
  2703 + break;
  2704 + /////////////////////////////////////////////// create column
  2705 + case "column_create":
  2706 + echo "<h2>Adding new field(s) to table '".$_POST['tablename']."'</h2>";
  2707 + if($_POST['tablefields']=="" || intval($_POST['tablefields'])<=0)
  2708 + echo "You must specify the number of table fields.";
  2709 + else if($_POST['tablename']=="")
  2710 + echo "You must specify a table name.";
  2711 + else
  2712 + {
  2713 + $num = intval($_POST['tablefields']);
  2714 + $name = $_POST['tablename'];
  2715 + echo "<form action='".PAGE."?table=".$_POST['tablename']."&action=column_create&confirm=1' method='post'>";
  2716 + echo "<input type='hidden' name='tablename' value='".$name."'/>";
  2717 + echo "<input type='hidden' name='rows' value='".$num."'/>";
  2718 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2719 + echo "<tr>";
  2720 + $headings = array("Field", "Type", "Primary Key", "Autoincrement", "Not NULL", "Default Value");
  2721 + for($k=0; $k<count($headings); $k++)
  2722 + echo "<td class='tdheader'>" . $headings[$k] . "</td>";
  2723 + echo "</tr>";
  2724 +
  2725 + for($i=0; $i<$num; $i++)
  2726 + {
  2727 + $tdWithClass = "<td class='td" . ($i%2 ? "1" : "2") . "'>";
  2728 + echo "<tr>";
  2729 + echo $tdWithClass;
  2730 + echo "<input type='text' name='".$i."_field' style='width:200px;'/>";
  2731 + echo "</td>";
  2732 + echo $tdWithClass;
  2733 + echo "<select name='".$i."_type' id='".$i."_type' onchange='toggleAutoincrement(".$i.");'>";
  2734 + $types = unserialize(DATATYPES);
  2735 + for($z=0; $z<sizeof($types); $z++)
  2736 + echo "<option value='".$types[$z]."'>".$types[$z]."</option>";
  2737 + echo "</select>";
  2738 + echo "</td>";
  2739 + echo $tdWithClass;
  2740 + echo "<input type='checkbox' name='".$i."_primarykey'/> Yes";
  2741 + echo "</td>";
  2742 + echo $tdWithClass;
  2743 + echo "<input type='checkbox' name='".$i."_autoincrement' id='".$i."_autoincrement'/> Yes";
  2744 + echo "</td>";
  2745 + echo $tdWithClass;
  2746 + echo "<input type='checkbox' name='".$i."_notnull'/> Yes";
  2747 + echo "</td>";
  2748 + echo $tdWithClass;
  2749 + echo "<input type='text' name='".$i."_defaultvalue' style='width:100px;'/>";
  2750 + echo "</td>";
  2751 + echo "</tr>";
  2752 + }
  2753 + echo "<tr>";
  2754 + echo "<td class='tdheader' style='text-align:right;' colspan='6'>";
  2755 + echo "<input type='submit' value='Add Field(s)' class='btn'/> ";
  2756 + echo "<a href='".PAGE."?table=".$_POST['tablename']."&action=column_view'>Cancel</a>";
  2757 + echo "</td>";
  2758 + echo "</tr>";
  2759 + echo "</table>";
  2760 + echo "</form>";
  2761 + }
  2762 + break;
  2763 + /////////////////////////////////////////////// delete column
  2764 + case "column_delete":
  2765 + if(isset($_POST['check']))
  2766 + $pks = $_POST['check'];
  2767 + else if(isset($_GET['pk']))
  2768 + $pks = array($_GET['pk']);
  2769 + $str = $pks[0];
  2770 + $pkVal = $pks[0];
  2771 + for($i=1; $i<sizeof($pks); $i++)
  2772 + {
  2773 + $str .= ", ".$pks[$i];
  2774 + $pkVal .= ":".$pks[$i];
  2775 + }
  2776 + if($str=="") //nothing was selected so show an error
  2777 + {
  2778 + echo "<div class='confirm'>";
  2779 + echo "Error: You did not select anything.";
  2780 + echo "</div>";
  2781 + echo "<br/><br/><a href='".PAGE."?table=".$_GET['table']."&action=column_view'>Return</a>";
  2782 + }
  2783 + else
  2784 + {
  2785 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=column_delete&confirm=1&pk=".$pkVal."' method='post'>";
  2786 + echo "<div class='confirm'>";
  2787 + echo "Are you sure you want to delete column(s) ".$str." from table '".$_GET['table']."'?<br/><br/>";
  2788 + echo "<input type='submit' value='Confirm' class='btn'/> ";
  2789 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=column_view'>Cancel</a>";
  2790 + echo "</div>";
  2791 + }
  2792 + break;
  2793 + /////////////////////////////////////////////// edit column
  2794 + case "column_edit":
  2795 + //this section will contain the code for editing a column
  2796 + break;
  2797 + /////////////////////////////////////////////// delete index
  2798 + case "index_delete":
  2799 + echo "<form action='".PAGE."?table=".$_GET['table']."&action=index_delete&pk=".$_GET['pk']."&confirm=1' method='post'>";
  2800 + echo "<div class='confirm'>";
  2801 + echo "Are you sure you want to delete index '".$_GET['pk']."'?<br/><br/>";
  2802 + echo "<input type='submit' value='Confirm' class='btn'/> ";
  2803 + echo "<a href='".PAGE."?table=".$_GET['table']."&action=column_view'>Cancel</a>";
  2804 + echo "</div>";
  2805 + echo "</form>";
  2806 + break;
  2807 + /////////////////////////////////////////////// create index
  2808 + case "index_create":
  2809 + echo "<h2>Creating new index on table '".$_POST['tablename']."'</h2>";
  2810 + if($_POST['numcolumns']=="" || intval($_POST['numcolumns'])<=0)
  2811 + echo "You must specify the number of table fields.";
  2812 + else if($_POST['tablename']=="")
  2813 + echo "You must specify a table name.";
  2814 + else
  2815 + {
  2816 + echo "<form action='".PAGE."?table=".$_POST['tablename']."&action=index_create&confirm=1' method='post'>";
  2817 + $num = intval($_POST['numcolumns']);
  2818 + $query = "PRAGMA table_info('".$_POST['tablename']."')";
  2819 + $result = $db->selectArray($query);
  2820 + echo "<fieldset><legend>Define index properties</legend>";
  2821 + echo "Index name: <input type='text' name='name'/><br/>";
  2822 + echo "Duplicate values: ";
  2823 + echo "<select name='duplicate'>";
  2824 + echo "<option value='yes'>Allowed</option>";
  2825 + echo "<option value='no'>Not Allowed</option>";
  2826 + echo "</select><br/>";
  2827 + echo "</fieldset>";
  2828 + echo "<br/>";
  2829 + echo "<fieldset><legend>Define index columns</legend>";
  2830 + for($i=0; $i<$num; $i++)
  2831 + {
  2832 + echo "<select name='".$i."_field'>";
  2833 + echo "<option value=''>--Ignore--</option>";
  2834 + for($j=0; $j<sizeof($result); $j++)
  2835 + echo "<option value='".$result[$j][1]."'>".$result[$j][1]."</option>";
  2836 + echo "</select> ";
  2837 + echo "<select name='".$i."_order'>";
  2838 + echo "<option value=''></option>";
  2839 + echo "<option value=' ASC'>Ascending</option>";
  2840 + echo "<option value=' DESC'>Descending</option>";
  2841 + echo "</select><br/>";
  2842 + }
  2843 + echo "</fieldset>";
  2844 + echo "<br/><br/>";
  2845 + echo "<input type='hidden' name='num' value='".$num."'/>";
  2846 + echo "<input type='submit' value='Create Index' class='btn'/> ";
  2847 + echo "<a href='".PAGE."?table=".$_POST['tablename']."&action=column_view'>Cancel</a>";
  2848 + echo "</form>";
  2849 + }
  2850 + break;
  2851 + }
  2852 + echo "</div>";
  2853 + }
  2854 + $view = "structure";
  2855 + if(!isset($_GET['table']) && !isset($_GET['confirm']) && (!isset($_GET['action']) || (isset($_GET['action']) && $_GET['action']!="table_create"))) //the absence of these fields means we are viewing the database homepage
  2856 + {
  2857 + if(isset($_GET['view']))
  2858 + $view = $_GET['view'];
  2859 + else
  2860 + $view = "structure";
  2861 +
  2862 + echo "<a href='".PAGE."?view=structure' ";
  2863 + if($view=="structure")
  2864 + echo "class='tab_pressed'";
  2865 + else
  2866 + echo "class='tab'";
  2867 + echo ">Structure</a>";
  2868 + echo "<a href='".PAGE."?view=sql' ";
  2869 + if($view=="sql")
  2870 + echo "class='tab_pressed'";
  2871 + else
  2872 + echo "class='tab'";
  2873 + echo ">SQL</a>";
  2874 + echo "<a href='".PAGE."?view=export' ";
  2875 + if($view=="export")
  2876 + echo "class='tab_pressed'";
  2877 + else
  2878 + echo "class='tab'";
  2879 + echo ">Export</a>";
  2880 + echo "<a href='".PAGE."?view=import' ";
  2881 + if($view=="import")
  2882 + echo "class='tab_pressed'";
  2883 + else
  2884 + echo "class='tab'";
  2885 + echo ">Import</a>";
  2886 + echo "<a href='".PAGE."?view=vacuum' ";
  2887 + if($view=="vacuum")
  2888 + echo "class='tab_pressed'";
  2889 + else
  2890 + echo "class='tab'";
  2891 + echo ">Vacuum</a>";
  2892 + echo "<div style='clear:both;'></div>";
  2893 + echo "<div id='main'>";
  2894 +
  2895 + if($view=="structure") //database structure - view of all the tables
  2896 + {
  2897 + $query = "SELECT sqlite_version() AS sqlite_version";
  2898 + $queryVersion = $db->select($query);
  2899 + $realVersion = $queryVersion['sqlite_version'];
  2900 +
  2901 + echo "<b>Database name</b>: ".$db->getName()."<br/>";
  2902 + echo "<b>Path to database</b>: ".$db->getPath()."<br/>";
  2903 + echo "<b>Size of database</b>: ".$db->getSize()."<br/>";
  2904 + echo "<b>Database last modified</b>: ".$db->getDate()."<br/>";
  2905 + echo "<b>SQLite version</b>: ".$realVersion."<br/>";
  2906 + echo "<b>SQLite extension</b>: ".$db->getType()."<br/>";
  2907 + echo "<b>PHP version</b>: ".phpversion()."<br/><br/>";
  2908 +
  2909 + $query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
  2910 + $result = $db->selectArray($query);
  2911 +
  2912 + $j = 0;
  2913 + for($i=0; $i<sizeof($result); $i++)
  2914 + if(substr($result[$i]['name'], 0, 7)!="sqlite_" && $result[$i]['name']!="")
  2915 + $j++;
  2916 +
  2917 + if($j==0)
  2918 + echo "No tables in database.<br/><br/>";
  2919 + else
  2920 + {
  2921 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  2922 + echo "<tr>";
  2923 + echo "<td class='tdheader'>Table</td>";
  2924 + echo "<td class='tdheader' colspan='10'>Action</td>";
  2925 + echo "<td class='tdheader'>Records</td>";
  2926 + echo "</tr>";
  2927 +
  2928 + $totalRecords = 0;
  2929 + for($i=0; $i<sizeof($result); $i++)
  2930 + {
  2931 + if(substr($result[$i]['name'], 0, 7)!="sqlite_" && $result[$i]['name']!="")
  2932 + {
  2933 + $records = $db->numRows($result[$i]['name']);
  2934 + $totalRecords += $records;
  2935 + $tdWithClass = "<td class='td".($i%2 ? "1" : "2")."'>";
  2936 + $tdWithClassLeft = "<td class='td".($i%2 ? "1" : "2")."' style='text-align:left;'>";
  2937 +
  2938 + echo "<tr>";
  2939 + echo $tdWithClassLeft;
  2940 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=row_view'>".$result[$i]['name']."</a><br/>";
  2941 + echo "</td>";
  2942 + echo $tdWithClass;
  2943 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=row_view'>Browse</a>";
  2944 + echo "</td>";
  2945 + echo $tdWithClass;
  2946 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=column_view'>Structure</a>";
  2947 + echo "</td>";
  2948 + echo $tdWithClass;
  2949 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_sql'>SQL</a>";
  2950 + echo "</td>";
  2951 + echo $tdWithClass;
  2952 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_search'>Search</a>";
  2953 + echo "</td>";
  2954 + echo $tdWithClass;
  2955 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=row_create'>Insert</a>";
  2956 + echo "</td>";
  2957 + echo $tdWithClass;
  2958 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_export'>Export</a>";
  2959 + echo "</td>";
  2960 + echo $tdWithClass;
  2961 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_import'>Import</a>";
  2962 + echo "</td>";
  2963 + echo $tdWithClass;
  2964 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_rename'>Rename</a>";
  2965 + echo "</td>";
  2966 + echo $tdWithClass;
  2967 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_empty' style='color:red;'>Empty</a>";
  2968 + echo "</td>";
  2969 + echo $tdWithClass;
  2970 + echo "<a href='".PAGE."?table=".$result[$i]['name']."&action=table_drop' style='color:red;'>Drop</a>";
  2971 + echo "</td>";
  2972 + echo $tdWithClass;
  2973 + echo $records;
  2974 + echo "</td>";
  2975 + echo "</tr>";
  2976 + }
  2977 + }
  2978 + echo "<tr>";
  2979 + echo "<td class='tdheader' colspan='11'>".sizeof($result)." table(s) total</td>";
  2980 + echo "<td class='tdheader' colspan='1' style='text-align:right;'>".$totalRecords."</td>";
  2981 + echo "</tr>";
  2982 + echo "</table>";
  2983 + echo "<br/>";
  2984 + }
  2985 + echo "<fieldset>";
  2986 + echo "<legend><b>Create new table on database '".$db->getName()."'</b></legend>";
  2987 + echo "<form action='".PAGE."?action=table_create' method='post'>";
  2988 + echo "Name: <input type='text' name='tablename' style='width:200px;'/> ";
  2989 + echo "Number of Fields: <input type='text' name='tablefields' style='width:90px;'/> ";
  2990 + echo "<input type='submit' name='createtable' value='Go' class='btn'/>";
  2991 + echo "</form>";
  2992 + echo "</fieldset>";
  2993 + }
  2994 + else if($view=="sql") //database SQL editor
  2995 + {
  2996 + $isSelect = false;
  2997 + if(isset($_POST['query']) && $_POST['query']!="")
  2998 + {
  2999 + $delimiter = $_POST['delimiter'];
  3000 + $queryStr = stripslashes($_POST['queryval']);
  3001 + $query = explode($delimiter, $queryStr); //explode the query string into individual queries based on the delimiter
  3002 +
  3003 + for($i=0; $i<sizeof($query); $i++) //iterate through the queries exploded by the delimiter
  3004 + {
  3005 + if(str_replace(" ", "", str_replace("\n", "", str_replace("\r", "", $query[$i])))!="") //make sure this query is not an empty string
  3006 + {
  3007 + $startTime = microtime(true);
  3008 + if(strpos(strtolower($query[$i]), "select ")!==false)
  3009 + {
  3010 + $isSelect = true;
  3011 + $result = $db->selectArray($query[$i], "assoc");
  3012 + }
  3013 + else
  3014 + {
  3015 + $isSelect = false;
  3016 + $result = $db->query($query[$i]);
  3017 + }
  3018 + $endTime = microtime(true);
  3019 + $time = round(($endTime - $startTime), 4);
  3020 +
  3021 + echo "<div class='confirm'>";
  3022 + echo "<b>";
  3023 + if($isSelect && $result)
  3024 + {
  3025 + if($isSelect)
  3026 + {
  3027 + $affected = sizeof($result);
  3028 + echo "Showing ".$affected." row(s). ";
  3029 + }
  3030 + else
  3031 + {
  3032 + $affected = $db->getAffectedRows();
  3033 + echo $affected." row(s) affected. ";
  3034 + }
  3035 + echo "(Query took ".$time." sec)</b><br/>";
  3036 + }
  3037 + else
  3038 + {
  3039 + echo "There is a problem with the syntax of your query ";
  3040 + echo "(Query was not executed)</b><br/>";
  3041 + }
  3042 + echo "<span style='font-size:11px;'>".$query[$i]."</span>";
  3043 + echo "</div><br/>";
  3044 + if($isSelect)
  3045 + {
  3046 + if(sizeof($result)>0)
  3047 + {
  3048 + $headers = array_keys($result[0]);
  3049 +
  3050 + echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>";
  3051 + echo "<tr>";
  3052 + for($j=0; $j<sizeof($headers); $j++)
  3053 + {
  3054 + echo "<td class='tdheader'>";
  3055 + echo $headers[$j];
  3056 + echo "</td>";
  3057 + }
  3058 + echo "</tr>";
  3059 + for($j=0; $j<sizeof($result); $j++)
  3060 + {
  3061 + $tdWithClass = "<td class='td".($j%2 ? "1" : "2")."'>";
  3062 + echo "<tr>";
  3063 + for($z=0; $z<sizeof($headers); $z++)
  3064 + {
  3065 + echo $tdWithClass;
  3066 + echo $result[$j][$headers[$z]];
  3067 + echo "</td>";
  3068 + }
  3069 + echo "</tr>";
  3070 + }
  3071 + echo "</table><br/><br/>";
  3072 + }
  3073 + }
  3074 + }
  3075 + }
  3076 + }
  3077 + else
  3078 + {
  3079 + $delimiter = ";";
  3080 + $queryStr = "";
  3081 + }
  3082 +
  3083 + echo "<fieldset>";
  3084 + echo "<legend><b>Run SQL query/queries on database '".$db->getName()."'</b></legend>";
  3085 + echo "<form action='".PAGE."?view=sql' method='post'>";
  3086 + echo "<textarea style='width:100%; height:300px;' name='queryval'>".$queryStr."</textarea>";
  3087 + echo "Delimiter <input type='text' name='delimiter' value='".$delimiter."' style='width:50px;'/> ";
  3088 + echo "<input type='submit' name='query' value='Go' class='btn'/>";
  3089 + echo "</form>";
  3090 + }
  3091 + else if($view=="vacuum")
  3092 + {
  3093 + if(isset($_POST['vacuum']))
  3094 + {
  3095 + $query = "VACUUM";
  3096 + $db->query($query);
  3097 + echo "<div class='confirm'>";
  3098 + echo "The database, '".$db->getName()."', has been VACUUMed.";
  3099 + echo "</div><br/>";
  3100 + }
  3101 + echo "<form method='post' action='".PAGE."?view=vacuum'>";
  3102 + echo "Large databases sometimes need to be VACUUMed to reduce their footprint on the server. Click the button below to VACUUM the database, '".$db->getName()."'.";
  3103 + echo "<br/><br/>";
  3104 + echo "<input type='submit' value='VACUUM' name='vacuum' class='btn'/>";
  3105 + echo "</form>";
  3106 + }
  3107 + else if($view=="export")
  3108 + {
  3109 + echo "<form method='post' action='".PAGE."?view=export'>";
  3110 + echo "<fieldset style='float:left; width:260px; margin-right:20px;'><legend><b>Export</b></legend>";
  3111 + echo "<select multiple='multiple' size='10' style='width:240px;' name='tables[]'>";
  3112 + $query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
  3113 + $result = $db->selectArray($query);
  3114 + for($i=0; $i<sizeof($result); $i++)
  3115 + {
  3116 + if(substr($result[$i]['name'], 0, 7)!="sqlite_" && $result[$i]['name']!="")
  3117 + echo "<option value='".$result[$i]['name']."' selected='selected'>".$result[$i]['name']."</option>";
  3118 + }
  3119 + echo "</select>";
  3120 + echo "<br/><br/>";
  3121 + echo "<input type='radio' name='export_type' checked='checked' value='sql'/> SQL";
  3122 + echo "</fieldset>";
  3123 + echo "<fieldset style='float:left;'><legend><b>Options</b></legend>";
  3124 + echo "<input type='checkbox' checked='checked' name='structure'/> Export with structure [<a onmouseover='tooltip.show(\"Creates the queries to add the tables and their columns\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  3125 + echo "<input type='checkbox' checked='checked' name='data'/> Export with data [<a onmouseover='tooltip.show(\"Creates the queries to insert the table rows\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  3126 + echo "<input type='checkbox' name='drop'/> Add DROP TABLE [<a onmouseover='tooltip.show(\"Creates the queries to remove the tables before potentially adding them so that errors do not occur if they already exist\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  3127 + echo "<input type='checkbox' checked='checked' name='transaction'/> Add TRANSACTION [<a onmouseover='tooltip.show(\"Performs queries within transactions so that if an error occurs, the table is not returned to a partially incomplete and unusable state\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  3128 + echo "<input type='checkbox' checked='checked' name='comments'/> Comments [<a onmouseover='tooltip.show(\"Adds comments to the file to explain what is happening in each part of it\");' onmouseout='tooltip.hide();'>?</a>]<br/>";
  3129 + echo "</fieldset>";
  3130 + echo "<div style='clear:both;'></div>";
  3131 + echo "<br/><br/>";
  3132 + echo "<fieldset style='float:left;'><legend><b>Save As</b></legend>";
  3133 + echo "<input type='hidden' name='database_num' value='".$_SESSION[COOKIENAME.'currentDB']."'/>";
  3134 + echo "<input type='text' name='filename' value='".$db->getPath().".".date("n-j-y").".dump' style='width:400px;'/> <input type='submit' name='export' value='Export' class='btn'/>";
  3135 + echo "</fieldset>";
  3136 + echo "</form>";
  3137 + }
  3138 + else if($view=="import")
  3139 + {
  3140 + if(isset($_POST['import']))
  3141 + {
  3142 + echo "<div class='confirm'>";
  3143 + echo "Import was successful.";
  3144 + echo "</div><br/>";
  3145 + }
  3146 + echo "<form method='post' action='".PAGE."?view=import' enctype='multipart/form-data'>";
  3147 + echo "<fieldset><legend><b>File to import</b></legend>";
  3148 + echo "<input type='radio' name='export_type' checked='checked' value='sql'/> SQL";
  3149 + echo "<br/><br/>";
  3150 + echo "<input type='file' value='Choose File' name='file' style='background-color:transparent; border-style:none;'/> <input type='submit' value='Import' name='import' class='btn'/>";
  3151 + echo "</fieldset>";
  3152 + }
  3153 +
  3154 + echo "</div>";
  3155 + }
  3156 +
  3157 + echo "<br/>";
  3158 + $endTimeTot = microtime(true); //get the current time at this point in the execution
  3159 + $timeTot = round(($endTimeTot - $startTimeTot), 4); //calculate the total time for page load
  3160 + echo "<span style='font-size:11px;'>Powered by <a href='http://code.google.com/p/phpliteadmin/' target='_blank' style='font-size:11px;'>".PROJECT."</a> | Page generated in ".$timeTot." seconds.</span>";
  3161 + echo "</div>";
  3162 + echo "</div>";
  3163 + $db->close(); //close the database
  3164 +}
  3165 +echo "</body>";
  3166 +echo "</html>";
  3167 +
  3168 +?>
0 3169 \ No newline at end of file
... ...
pacotes/phpliteadmin/senha.php 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<?php
  2 +$password = "admin";
  3 +?>
0 4 \ No newline at end of file
... ...