|
From: <ope...@li...> - 2002-07-14 19:54:12
|
Update of /cvsroot/openposs/Server/includes
In directory usw-pr-cvs1:/tmp/cvs-serv24419
Added Files:
database.php functions.php vars.inc
Log Message:
Relocated files from ./Server
--- NEW FILE: database.php ---
<?php
#
# Filename: database.php
# Author : Brian A Cheeseman
# Date : April 6, 2002
# Purpose : To provide the database interface.
#
###############################################################################
# Last Update # Who # Changes Made #
#-------------#-----#---------------------------------------------------------#
# Apr 6, 2002 # BAC # Initial Creation #
###############################################################################
# Who Key
# BAC - Brian A Cheeseman
#
include_once('config.php'); // Include the database connection information.
define('ADODB_DIR', 'adodb'); // define the location of the adodb software.
include_once('adodb/adodb.inc.php'); // Include the adodb database code.
/******************************************************************************
* Function: DBInit() *
* -------------------------------------------------------------------------- *
* This function is used to open a database connection using the ADODB, *
* and then select a default database. Upon error, function will die, and *
* return an error message. *
* *
* Returned Values *
* None. *
* *
* Input Values *
* None. *
******************************************************************************/
function DBInit() {
global $DBConfig, $SystemConfig;
// Assign the database connection information to variables.
$DBServer=$DBConfig['Server'];
$DBUserName=$DBConfig['UserName'];
$DBPassword=$DBConfig['Password'];
$DBName=$DBConfig['DBName'];
$DBType=$DBConfig['DBType'];
$DBCurVers=$DBConfig['CurrentVersion'];
// Create a database connection.
global $DBConn;
$DBConn = ADONewConnection($DBType);
// Create a Handle to the database.
$DBHandle = $DBConn->Connect($DBServer, $DBUserName, $DBPassword, $DBName);
if (!$DBHandle) {
die("Failed to connect to $DBType://$DBUserName:$DBPassword@$DBServer/$DBName\n".$DBConn->ErrorMsg());
}
// We have a connection and handle on the database.
global $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$sql = "SELECT Value FROM Configuration WHERE Parameter='DBVersion'";
$results = $DBConn->Execute($sql);
list($DBVersion) = $results->fields;
if (strncmp($DBVersion, $DBCurVers, strlen($DBCurVers)) != 0) {
switch ($DBVersion) {
// Database Updating Code will be inserted here when a change is made to the schema.
// This code will only be placed into the production code, as only testing will be done
// by the dev team.
}
}
// OK, Lets load the system config.
$sql = "SELECT Parameter, Value FROM Configuration WHERE Parameter <> 'DBVersion'";
$results = $DBConn->Execute($sql);
while(list($Param, $Value) = $results->FetchRow()) {
$SystemConfig[$Param] = $Value;
}
//Check to see if the install routine has been completed
if($SystemConfig["systemInstalled"] == "No")
{
//The install routine has not been run. Direct them to it.
die("<center><h3>You must complete the install.php routine before you can use the OpenPOS System.
Please see the install documentation.<p> Note: Since the OpenPOS System is still in the
early stages of development, you will need to go into the table <i>configuration</i> of the
<i>openPOS</i> database and adjust the value of the field \"systemInstalled\" to \"Yes\". In
the near future, we will have a working install script, but that may be the last item completed
before release 0.1.0.</h3></center>");
}
return true;
}
/******************************************************************************
* Function: DBClose() *
* -------------------------------------------------------------------------- *
* This function is used to close the database connection. *
* *
* Returned Values *
* None. *
* *
* Input Values *
* None. *
******************************************************************************/
function DBClose()
{
global $DBConn;
$DBConn->Close();
return true;
}
/******************************************************************************
* Function: Validate_Password() *
* -------------------------------------------------------------------------- *
* This function is used to verify that a UserName/Password combo exists in *
* the SystemUsers table. *
* If the password/username combo exists in db, return users rights level, *
* if not in db, return false. *
* *
* Returned Values *
* $ret_val *
* *
* Input Values *
* $UserName, $Password *
******************************************************************************/
function Validate_Password($UserName, $Password)
{
GLOBAL $DBConn;
$ret_val = 0;
$sql = "SELECT Password, SuperUser FROM SystemUsers WHERE UserName=\"$UserName\"";
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$result = $DBConn->Execute($sql);
if ($result->NumRows() > 0)
{
list($pw,$rights) = $result->fields;
$pword = md5($Password);
if (strcmp($pw, $pword) == 0)
{
//Password validated!
$ret_val = $rights;
}
else
{
$ret_val = FALSE;
}
}
return $ret_val;
}
function DB_Query($query)
{
GLOBAL $DBConn;
$result = $DBConn->Execute("$query");
return $result;
}
function DB_Fetch_Data_Array($result)
{
GLOBAL $DBConn;
if ($result === false) die("failed");
while (!$result->EOF)
{
$data_array[] = $result->fields;
$result->MoveNext();
}
return $data_array;
}
?>
--- NEW FILE: functions.php ---
<?
/******************************************************************************
* Function: DisplayMainMenu() *
* -------------------------------------------------------------------------- *
* This function will display the main menu when the user is accessing the *
* system via a web browser. *
* *
* Returned Values *
* HTML Page text to return to the client. *
* *
* Input Values *
* None. *
******************************************************************************/
function DisplayMainMenu() {
GLOBAL $HTTP_SESSION_VARS,$CONFIG_VARS;
$Output = Theme_Menu_Open($CONFIG_VARS["MenuWidth"],_OPENPOSNAVTITLE);
if (isset($HTTP_SESSION_VARS["openPOSAuthTok"]))
{
$Output .= $HTTP_SESSION_VARS["openPOSAuthTok"]." Logged In<p>";
}
else
{
$Output .= "Not Logged In<p>";
}
$menuArray = GetMenuEntries();
$Output .= "\n";
foreach($menuArray as $tmp)
{
$Output .= "<a class=\"menu\" href=\"./module.php?module=$tmp[0]\">$tmp[0]</a><br>\n";
}
if($HTTP_SESSION_VARS["openPOSAuthRights"] == "127")
{
$Output .= Theme_Add_Menu_Link("./?action=admin", _OPENPOSADMINTITLE) . "<BR>";
}
if ( strcmp($SystemConfig['modUserLogin'], "On"))
{
if (isset($HTTP_SESSION_VARS["openPOSAuthTok"]))
{
$Output .= Theme_Add_Menu_Link("./?action=logout", "Logout") . "<br>";
}
else
{
$Output .= Theme_Add_Menu_Link("./?action=login", "Login") . "<br>";
}
}
$Output .= "\n<BR>";
$Output .= Theme_Menu_Close();
return $Output;
}
/******************************************************************************
* Function: GetMenuEntries() *
* -------------------------------------------------------------------------- *
* This function will access the db, and get all activem, showable menu *
* menu entries. *
* *
* Returned Values *
* $menuEntries of type Array *
* *
* Input Values *
* None. *
******************************************************************************/
function GetMenuEntries()
{
$query = "SELECT name FROM modules WHERE status='A' AND menu='Y'";
$result = DB_Query($query);
$menuEntires = DB_Fetch_Data_Array($result);
return $menuEntires;
}
/******************************************************************************
* Function: DisplayAdminMenu() *
* -------------------------------------------------------------------------- *
* This function will display the administration menu when the user is *
* accessing the system via a web browser. *
* *
* Returned Values *
* HTML Page text to return to the client. *
* *
* Input Values *
* None. *
******************************************************************************/
function DisplayAdminMenu() {
$Output = Theme_Open_Page(_OPENPOSADMINTITLE);
$Output .= Theme_Close_Page();
return $Output;
}
/******************************************************************************
* Function: DisplayError() *
* -------------------------------------------------------------------------- *
* This function will display the error messages to the user. *
* *
* Returned Values *
* HTML Page text to return to the client. *
* *
* Input Values *
* None. *
******************************************************************************/
function DisplayError()
{
$Output = Theme_Open_Page( _OPENPOSERRORTITLE );
$Output .= "<DIV ALIGN=\"CENTER\"><H3>ERROR: Incorrect Parameters sent to the server. Please contact your support section.</H3></DIV>";
$Output .= Theme_Close_Page();
return $Output;
}
/******************************************************************************
* Function: ProcessLoginRequest() *
* -------------------------------------------------------------------------- *
* This function will validate user, and then set cookie if user is valid. *
* *
* Returned Values *
* None. *
* *
* Input Values *
* None. *
******************************************************************************/
function ProcessLoginRequest($UserName,$Password) {
GLOBAL $HTTP_SESSION_VARS;
$rights = Validate_Password($UserName, $Password);
//echo "$rights";
if ($rights != FALSE)
{
$HTTP_SESSION_VARS["openPOSAuthTok"] = $UserName;
$HTTP_SESSION_VARS["openPOSAuthRights"] = $rights;
$HTTP_SESSION_VARS["action"] = "none";
$HTTP_SESSION_VARS["OutputLang"] = NULL;
$HTTP_SESSION_VARS["OutputTheme"] = "Default";
}
else
{
//Not a valid login. figure out a way to pass an error message
}
header("HTTP/1.0 303 See Other");
header("Location: ./");
return;
}
/******************************************************************************
* Function: ProcessLogoutRequest() *
* -------------------------------------------------------------------------- *
* This function will destroy the users session, logging them out *
* *
* Returned Values *
* None. *
* *
* Input Values *
* None. *
******************************************************************************/
function ProcessLogoutRequest()
{
GLOBAL $Action, $UserName;
if (isset($UserName))
{
session_unset();
session_destroy();
header("HTTP/1.0 303 See Other");
header("Location: ./");
}
return;
}
/*End Functions
*******************************************************************************/
?>
--- NEW FILE: vars.inc ---
<?
#
# Filename: vars.inc
# Author : Chris W Shaffer
# Date : June 27, 2002
# Purpose : To provide a holding file for system wide variables
#
#
###############################################################################
# Last Update | Who | Changes Made #
#-------------+-----+---------------------------------------------------------#
# Jun 26,2002 | CWS | Initial Creation #
###############################################################################
# Who Key
# CWS - Chris W Shaffer
#
//System Wide variables, control the look?
$CONFIG_VARS["MenuWidth"] = "175";
|