/** 
	Run the actual setup process
*/
function DoSetup()
{
    $lock_file_name = '../data/setup.lock';
    //Check if the lock file already exists
    if (!file_exists($lock_file_name)) {
        echo GetLocalizedString('setup-creating-lock') . "\n";
        //Warn if ignore_setup_lock is enabled
        if (ReadConfigInt('ignore_setup_lock', '0')) {
            echo GetLocalizedString('setup-lock-pointless') . "\n";
        }
        //Create the lock file
        touch($lock_file_name);
    } else {
        //Ignore the lock file and blow away the db
        if (ReadConfigInt('ignore_setup_lock', '0')) {
            echo GetLocalizedString('setup-trampling') . "\n";
        } else {
            die(GetLocalizedString('setup-already-run')) . "\n";
        }
    }
    //If we get to this point the lock either doesn't exist or has been ignored. Start the setup process.
    //Run the setup queries
    global $g_dbconn;
    if (!$g_dbconn->multi_query(file_get_contents('../setup/setup.sql'))) {
        die(DatabaseError());
    }
    while ($g_dbconn->more_results()) {
        if (!$g_dbconn->next_result()) {
            die(DatabaseError());
        }
    }
    echo GetLocalizedString('setup-done');
}
Exemple #2
0
 function query($strSQL)
 {
     global $aQueries;
     // Save the query.
     $aQueries[] = $strSQL;
     // Execute the query.
     $this->objResult = @mysql_query($strSQL);
     // Return the result.
     if ($this->objResult === FALSE) {
         DatabaseError();
     } else {
         return TRUE;
     }
 }
Exemple #3
0
 function query($strSQL)
 {
     global $aQueries;
     // Save the query.
     $aQueries[] = $strSQL;
     // Execute the query.
     $querySuccess = pg_send_query($this->objConnection, $strSQL);
     $this->objResult = @pg_get_result($this->objConnection);
     // Return the result.
     if ($querySuccess === FALSE) {
         DatabaseError();
     } else {
         return TRUE;
     }
 }
Exemple #4
0
//                                                                           //
//  This program is free software. You may use, modify, and/or redistribute  //
//  it under the terms of the MIT License.                                   //
//                                                                           //
//***************************************************************************//
// Load the database information.
require './includes/dbinfo.inc.php';
// Load the database driver.
if (!@(include "./includes/{$aDBInfo['type']}.inc.php")) {
    die('<span style="font-family: verdana, arial, helvetica, sans-serif; font-size: 13px;">Please upload a database driver!</span>');
}
// Create a new database connection.
$dbConn = new DBConnection($aDBInfo);
// Make sure we connected.
if (!$dbConn->objConnection || !$dbConn->objSelect) {
    DatabaseError();
}
// *************************************************************************** \\
// Tells the user when there's a problem with the database.
function DatabaseError()
{
    global $CFG, $dbConn, $strDBEMail;
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="SHORTCUT ICON" href="favicon.ico" />
<title>Database Error</title>
/** 
	@brief Set up the database connection and initialize the current session
*/
function SessionInit()
{
    //connect to database
    global $g_dbconn;
    $g_dbconn = new mysqli(ReadConfigString('db_server', 'localhost'), ReadConfigString('db_user', 'penguin'), ReadConfigString('db_pass', ''), ReadConfigString('db_name', 'penguin'), ReadConfigInt('db_port', 3306));
    if ($g_dbconn->connect_error) {
        DatabaseError();
    }
    //create session and set up default variables
    session_start();
    if (!isset($_SESSION['uid'])) {
        $_SESSION['uid'] = -1;
    }
}
function RenameCategory()
{
    global $g_dbconn;
    $catid = ReadPOSTInt('catid', '-1');
    $name = DatabaseSanitize(ReadPOSTString('name', ''));
    $result = $g_dbconn->query('update deviceCategory set name = \'' . $name . '\' where deviceCategory_id = \'' . $catid . '\' limit 1');
    if (!$result) {
        $json_out['status'] = 'fail';
        $json_out['error_code'] = DatabaseError();
    } else {
        $json_out['status'] = 'ok';
    }
    echo json_encode($json_out);
}