<?PHP
// Database maintenance functions
//
// Version: $Revision: 1.4 $
// Date: $Date: 2008/05/18 13:26:05 $
//
// Copyright (c) 2006 - 2008 Benjamin Oshrin
// License restrictions apply, see LICENSE for details.
// We use adodb and axmls for database abstraction
include($topdir.'../adodb/adodb.inc.php');
include($topdir.'../adodb/adodb-xmlschema03.inc.php');
// Start a connection here, since we'll pretty much always use one
if($config['dbhome'] != "") {
putenv($config['dbhome']);
}
$dbc = ADONewConnection($config['db']);
if(!$dbc->Connect($config['dbhost'],
$config['dbuser'],
$config['dbpass'],
$config['dbname']))
{
echo $tx['db.err.connect'] .": " . $dbc->ErrorMsg() . "<P>";
exit;
}
// Retrieve data as associative arrays
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
function db_create_tables()
{
// Create the tables required by mrsbs.
// Returns: true if fully successful, false otherwise.
// We use AXMLS to turn an XML file into a db.
global $dbc;
global $topdir;
$schema = new adoSchema($dbc);
$sql = $schema->ParseSchema($topdir.'../lib/database-schema.xml');
if($schema->ExecuteSchema() == 2) // !!!
return(true);
else
return(false);
}
function db_create_tables_print_sql()
{
// Display the SQL needed to create the tables required by mrsbs.
// Returns: true if fully successful, false otherwise.
// We use AXMLS to turn an XML file into a set of SQL statements.
global $dbc;
global $topdir;
$schema = new adoSchema($dbc);
$sql = $schema->ParseSchema($topdir.'../lib/database-schema.xml');
print $schema->PrintSQL('TEXT') . "\n";
}
function db_drop_tables()
{
// Drop the tables required by mrsbs.
// Returns: true if fully successful, false otherwise.
// We use AXMLS to turn an XML file into a db.
global $dbc;
global $topdir;
// Drop sequences separately
$dbc->DropSequence('mrsbs_contactid_seq');
$dbc->DropSequence('mrsbs_locationid_seq');
$dbc->DropSequence('mrsbs_mtgid_seq');
$dbc->DropSequence('mrsbs_windowid_seq');
$schema = new adoSchema($dbc);
$sql = $schema->RemoveSchema($topdir.'../lib/database-schema.xml');
if($schema->ExecuteSchema() == 2) // !!!
return(true);
else
return(false);
}
function db_drop_tables_print_sql()
{
// Display the SQL needed to drop the tables required by mrsbs.
// Returns: true if fully successful, false otherwise.
// We use AXMLS to turn an XML file into a set of SQL statements.
global $dbc;
global $topdir;
print "-- WARNING: You must manually drop the following sequences:\n";
print "-- mrsbs_contactid_seq, mrsbs_locationid_seq, mrsbs_mtgid_seq, mrsbs_windowid_seq\n\n";
$schema = new adoSchema($dbc);
$sql = $schema->RemoveSchema($topdir.'../lib/database-schema.xml');
print $schema->PrintSQL('TEXT') . "\n";
}
function db_reset_tables($mode)
{
// Drop data from the database. If $mode is "all", all data is dropped.
// If $mode is "meeting", only meeting related data is dropped.
// Returns: true if fully successful, false otherwise.
global $dbc;
$dbc->StartTrans();
if($mode == "all" || $mode == "meeting")
{
// Drop meeting related data
$dbc->Execute("DELETE FROM mrsbs_meeting_info");
$dbc->Execute("DELETE FROM mrsbs_history");
$dbc->Execute("DELETE FROM mrsbs_invitees");
$dbc->Execute("DELETE FROM mrsbs_potential_locations");
$dbc->Execute("DELETE FROM mrsbs_reply_locations");
$dbc->Execute("DELETE FROM mrsbs_reply_windows");
$dbc->Execute("DELETE FROM mrsbs_windows");
$dbc->Execute("DELETE FROM mrsbs_recent_invitees");
}
if($mode == "all")
{
// Drop other data
$dbc->Execute("DELETE FROM mrsbs_acls");
$dbc->Execute("DELETE FROM mrsbs_contacts");
$dbc->Execute("DELETE FROM mrsbs_delegates");
$dbc->Execute("DELETE FROM mrsbs_locations");
}
return($dbc->CompleteTrans());
}
?>