function getAjaxDate()
{
    global $SETTINGS;
    // error checking
    if (!@$_REQUEST['timezone']) {
        die("no timezone value specified!");
    }
    // error checking
    $timeZoneOffsetSeconds = abs(date("Z"));
    if ($timeZoneOffsetSeconds > 12 * 60 * 60) {
        $error = "Offset cannot be more than +/- 12 hours from GMT!";
        echo json_encode(array('', '', $error));
        exit;
    }
    // set timezones
    date_default_timezone_set($_REQUEST['timezone']) || die(__FUNCTION__ + ": error setting timezone to '{$_REQUEST['timezone']}' with date_default_timezone_set.  Invalid timezone name.");
    $error = setMySqlTimezone('returnError');
    // get local date
    $offsetSeconds = date("Z");
    $offsetString = convertSecondsToTimezoneOffset($offsetSeconds);
    $localDate = date("D, M j, Y - g:i:s A") . " ({$offsetString})";
    // get mysql date
    $result = mysql_query("SELECT NOW(), @@session.time_zone");
    list($mySqlDate, $mySqlOffset) = mysql_fetch_row($result);
    $mysqlDate = date("D, M j, Y - g:i:s A", strtotime($mySqlDate)) . " ({$mySqlOffset})";
    if (is_resource($result)) {
        mysql_free_result($result);
    }
    // return dates
    echo json_encode(array($localDate, $mysqlDate, $error));
    exit;
}
function connectToMySQL($returnErrors = false)
{
    global $SETTINGS, $DBH;
    ### Get connection details
    $hostname = getFirstDefinedValue(@$SETTINGS["mysql:{$_SERVER['HTTP_HOST']}"]['hostname'], $SETTINGS['mysql']['hostname']);
    $username = getFirstDefinedValue(@$SETTINGS["mysql:{$_SERVER['HTTP_HOST']}"]['username'], $SETTINGS['mysql']['username']);
    $password = getFirstDefinedValue(@$SETTINGS["mysql:{$_SERVER['HTTP_HOST']}"]['password'], $SETTINGS['mysql']['password']);
    $database = getFirstDefinedValue(@$SETTINGS["mysql:{$_SERVER['HTTP_HOST']}"]['database'], $SETTINGS['mysql']['database']);
    $textOnlyErrors = coalesce(inCLI(), @$SETTINGS["mysql:{$_SERVER['HTTP_HOST']}"]['textOnlyErrors'], $SETTINGS['mysql']['textOnlyErrors']);
    ##  SLOW REMOTE CONNECTION
    ##  If you are connecting to a remote database that is intolerably slow, try
    ##  updating the mysql configuration file (often "/etc/my.cfg") by adding the
    ##  following option to the [mysqld] section:
    ##
    ##     skip-name-resolve
    ##
    ##  Here is the MySQL documentation for this option:
    ##
    ##    --skip-name-resolve
    ##    Do not resolve host names when checking client connections. Use only IP addresses.
    ##    If you use this option, all Host column values in the grant tables must be IP addresses or localhost.
    ### Connect to database
    $DBH = @mysql_connect($hostname, $username, $password);
    if (!$DBH) {
        $connectionError = mysql_error();
        if ($returnErrors) {
            return "Error connecting to MySQL:<br/>\n{$connectionError}";
        } elseif ($textOnlyErrors) {
            die("Error connecting to MySQL: {$connectionError}");
        } else {
            $libDir = pathinfo(__FILE__, PATHINFO_DIRNAME);
            // viewers may be in different dirs
            include "{$libDir}/menus/dbConnectionError.php";
        }
        exit;
    }
    // select db
    $isDbSelected = mysql_select_db($database);
    if (!$isDbSelected) {
        mysql_query("CREATE DATABASE `{$database}`") or die("MySQL Error: " . mysql_error() . "\n");
        mysql_select_db($database) or die("MySQL Error: " . mysql_error() . "\n");
    }
    ### check for required mysql version
    $currentVersion = preg_replace("/[^0-9\\.]/", '', mysql_get_server_info());
    if (version_compare(REQUIRED_MYSQL_VERSION, $currentVersion, '>')) {
        $error = "This program requires MySQL v" . REQUIRED_MYSQL_VERSION . " or newer. This server has v{$currentVersion} installed.<br/>\n";
        $error .= "Please ask your server administrator to install MySQL v" . REQUIRED_MYSQL_VERSION . " or newer.<br/>\n";
        if ($returnErrors) {
            return $error;
        }
        die($error);
    }
    ### Set Character Set
    # note: set through PHP 'set_charset' function so mysql_real_escape string() knows what charset to use. setting the charset
    # ... through mysql queries with 'set names' didn't cause mysql_client_encoding() to return a different value
    mysql_set_charset("utf8") or die("Error loading character set utf8: " . mysql_error() . '');
    # set MySQL strict mode - http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
    mysqlStrictMode(true);
    # set MySQL timezone offset
    setMySqlTimezone();
    //
    return '';
}