Location: PHPKode > projects > Web Application Gateway > wagateway/common/dbappconnect.php
<?

/*************************************************************************************

    COPYRIGHT NOTICE

    This copyright notice must appear at the top of all scripts which are part of
    the Web Application Gateway package.

    Copyright (C) 2001-2008 Gregory Engel
    
    All rights reserved
    
    8547 E Arapahoe Rd, #J-504
    Greenwood Village, CO  80112 USA
    hide@address.com

    This program is free software; you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free Software
    Foundation; either version 2 of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

    The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
    A copy is included with the WAG package and is found in the text file gpl.txt

    You should have received a copy of the GNU General Public License (gpl.txt, gpl.html)
    along with the WAG distribution package; if not, the GNU General Public License can
    be found at http://www.gnu.org/copyleft/gpl.html, or by writing to:
    
    Free Software Foundation, Inc.
    59 Temple Place - Suite 330
    Boston, MA  02111-1307, USA.

    This script is part of the Web Application Gateway (WAG) Project. The WAG software
    is free, subject to the terms of the GNU General Public License as published by the
    Free Software Foundation, either version 2 of the License, or (at your option) any
    later version.
    
    $Revision: 43 $
    $LastChangedDate: 2008-01-14 14:12:43 -0700 (Mon, 14 Jan 2008) $
    $LastChangedBy: gpeangel $
    
*************************************************************************************/

// Check if any of the DB session variables have expired

if (!isset($_SESSION[$app_guid]["APPDB_SERVER"]) || !isset($_SESSION[$app_guid]["APPDB_USERNAME"]) || !isset($_SESSION[$app_guid]["APPDB_PASSWORD"]) || !isset($_SESSION[$app_guid]["APPDB_DATABASE"]))
    {
    
    // Web server directory path to the WAG installation directory
    
    $ary_path = explode("/", dirname($_SERVER['PHP_SELF']));
    
    $install_path = "";
    
    foreach ($ary_path as $value)
        {
        if (strlen(trim($value)) > 0)
            {
            
            $install_path .= "/".$value;
            
            if (is_file($_SERVER["DOCUMENT_ROOT"].$install_path."/index.php"))
                {
                header("Location: http://".$_SERVER["HTTP_HOST"].$install_path."/index.php");
                break;
                }
            }
        } 
    }
else
    {
    $app_db_conn = mysql_connect($_SESSION[$app_guid]["APPDB_SERVER"], $_SESSION[$app_guid]["APPDB_USERNAME"], $_SESSION[$app_guid]["APPDB_PASSWORD"]) or die ($query."<br><br>".mysql_errno().": ".mysql_error()."<br>");
    mysql_select_db($_SESSION[$app_guid]["APPDB_DATABASE"], $app_db_conn) or die ($query."<br><br>".mysql_errno().": ".mysql_error()."<br>");
    }    

function APPDBError($strError)
    {
    
    echo "<p style=\"font-family: arial; font-weight: bold;\">An error has occurred with the database.</p>";
    
    $str_temp = "Server: ".$_SERVER["HTTP_HOST"]."\n";
    $str_temp .= "User: ".$_SESSION["WAGATEWAY"]["USR_FIRST_NAME"]." ".$_SESSION["WAGATEWAY"]["USR_LAST_NAME"]." (".$_SESSION["WAGATEWAY"]["USR_ID"].")\n";
    $strError = $str_temp."\n".$strError;
    
    if (strlen(trim($_SESSION["WAGATEWAY"]["ADMIN_EMAIL"])) > 0)
        {
        if (mail($_SESSION["WAGATEWAY"]["ADMIN_EMAIL"], "Application DB Error", $strError, "From: ".$_SESSION["WAGATEWAY"]["ADMIN_EMAIL"]."\r\n"."Reply-To: ".$_SESSION["WAGATEWAY"]["ADMIN_EMAIL"]."\r\n"."X-Mailer: PHP/".phpversion()))
            {
            echo "<p style=\"font-family: arial; font-weight: bold;\">A detailed message has been sent to the administrator.</p>";
            }
        else
            {
            echo "<p style=\"font-family: arial; font-weight: bold;\">".$strError."</p>";
            }
        }
    else
        {
        echo "<p style=\"font-family: arial; font-weight: bold;\">".$strError."</p>";
        }
    }
?>
Return current item: Web Application Gateway