OpenSQLManager/index.php

227 lines
4.6 KiB
PHP
Raw Normal View History

2012-01-26 16:09:05 -05:00
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
2012-03-28 11:23:08 -04:00
* @license http://philsturgeon.co.uk/code/dbad-license
2012-01-26 16:09:05 -05:00
*/
// --------------------------------------------------------------------------
/**
* Bootstrap file
*
* Initializes parent window and starts the GTK event loop
*/
// --------------------------------------------------------------------------
// Suppress errors that php-gtk puts out
error_reporting(-1 & ~(E_STRICT));
2012-01-31 16:41:30 -05:00
// Set the stupid timezone so PHP shuts up.
date_default_timezone_set('GMT');
// Set the current directory as the base for included files
2012-02-29 16:14:21 -05:00
define('BASE_DIR', dirname(__FILE__).'/sys');
define('SETTINGS_DIR', dirname(__FILE__));
// --------------------------------------------------------------------------
2012-01-31 16:41:30 -05:00
/**
* Log fatal errors
*/
function log_fatal()
{
// Catch the last error
2012-02-01 14:45:38 -05:00
$error = error_get_last();
2012-01-31 16:41:30 -05:00
2012-02-01 14:45:38 -05:00
// types of errors that are fatal
$fatal = array(E_ERROR, E_PARSE, E_RECOVERABLE_ERROR);
2012-01-31 16:41:30 -05:00
2012-02-02 11:27:42 -05:00
// Log error.
2012-02-01 14:45:38 -05:00
if(in_array($error['type'], $fatal))
{
file_put_contents('errors.txt', print_r($error, TRUE), FILE_APPEND);
}
2012-01-31 16:41:30 -05:00
}
register_shutdown_function('log_fatal');
2012-01-30 18:44:27 -05:00
// --------------------------------------------------------------------------
2012-01-31 17:52:46 -05:00
// Make sure php-gtk works
2012-03-28 11:23:08 -04:00
if ( ! class_exists('gtk'))
2012-01-26 16:09:05 -05:00
{
trigger_error("PHP-gtk not found. Please load the php-gtk2 extension in your php.ini", E_USER_ERROR);
die();
2012-01-26 16:09:05 -05:00
}
// Make sure pdo exists
if( ! class_exists('pdo'))
{
trigger_error("PHP support for PDO is required.", E_USER_ERROR);
die();
}
// --------------------------------------------------------------------------
2012-01-27 21:19:39 -05:00
2012-03-28 11:23:08 -04:00
/**
* Alias for require_once for array_map
*
* @param string $path
* @return void
*/
2012-01-27 12:58:03 -05:00
function do_include($path)
{
require_once($path);
}
// Load everything so that we don't have to do requires later
{
array_map('do_include', glob(BASE_DIR . "/common/*.php"));
array_map('do_include', glob(BASE_DIR . "/db/*.php"));
2012-03-28 11:23:08 -04:00
array_map('do_include', glob(BASE_DIR . "/windows/widgets/*.php"));
array_map('do_include', glob(BASE_DIR . "/windows/*.php"));
}
2012-01-26 16:09:05 -05:00
// --------------------------------------------------------------------------
// Load db classes based on capability
$path = BASE_DIR . "/db/drivers/";
foreach(pdo_drivers() as $d)
{
2012-03-06 21:07:34 -05:00
//Favor ibase over PDO firebird
if ($d === 'firebird')
{
continue;
}
$file = "{$path}{$d}.php";
2012-03-28 11:23:08 -04:00
if(is_file($file))
{
require_once("{$path}{$d}.php");
require_once("{$path}{$d}_sql.php");
}
}
// Load Firebird if there is support
2012-03-19 12:20:51 -04:00
if(function_exists('fbird_connect'))
{
2012-03-19 12:20:51 -04:00
require_once("{$path}firebird.php");
require_once("{$path}firebird_sql.php");
}
2012-03-28 11:23:08 -04:00
// --------------------------------------------------------------------------
// ! Global Functions
// --------------------------------------------------------------------------
2012-03-30 09:58:41 -04:00
/**
* Convert an array to an object
*
* @param array $array
* @return object
*/
function array_to_object($array)
{
if (is_object($array))
{
return $array;
}
$obj = new StdClass();
foreach($array as $k => $v)
{
$obj->$k = $v;
}
return $obj;
}
// --------------------------------------------------------------------------
/**
* Create info dialog to retun an informational message
*
2012-03-27 15:47:56 -04:00
* @param string $message
* @return void
*/
function alert($message)
{
$dialog = new GTKMessageDialog(
NULL,
Gtk::DIALOG_MODAL,
Gtk::MESSAGE_INFO,
Gtk::BUTTONS_OK,
$message
);
$dialog->set_position(Gtk::WIN_POS_CENTER);
$dialog->run();
$dialog->destroy();
}
// --------------------------------------------------------------------------
/**
* Create info dialog to retun an informational message
*
2012-03-27 15:47:56 -04:00
* @param string $message
* @return void
*/
function error($message)
{
$dialog = new GTKMessageDialog(
NULL,
Gtk::DIALOG_MODAL,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_OK,
$message
);
$dialog->set_position(Gtk::WIN_POS_CENTER);
$dialog->run();
$dialog->destroy();
}
// --------------------------------------------------------------------------
2012-03-27 15:47:56 -04:00
/**
* Creates a binary confirmation dialog
*
* @param string $message
* @return bool
*/
function confirm($message)
{
$dialog = new GTKMessageDialog(
NULL,
Gtk::DIALOG_MODAL,
Gtk::MESSAGE_QUESTION,
Gtk::BUTTONS_YES_NO,
$message
);
$dialog->set_position(Gtk::WIN_POS_CENTER);
2012-03-27 15:47:56 -04:00
$answer = $dialog->run();
$dialog->destroy();
return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE;
}
// --------------------------------------------------------------------------
2012-01-27 11:57:13 -05:00
// Create the main window
2012-02-02 06:26:59 -05:00
new Main();
2012-01-26 16:09:05 -05:00
2012-01-27 11:57:13 -05:00
// Start the GTK event loop
GTK::main();
2012-02-14 13:10:18 -05:00
// End of index.php