From: <ope...@li...> - 2002-06-28 02:13:25
|
Update of /cvsroot/openposs/Server In directory usw-pr-cvs1:/tmp/cvs-serv6860 Modified Files: database.php Log Message: Added functions. Index: database.php =================================================================== RCS file: /cvsroot/openposs/Server/database.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** database.php 25 Jun 2002 03:18:53 -0000 1.3 --- database.php 28 Jun 2002 02:13:23 -0000 1.4 *************** *** 1,85 **** ! <?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() { ! 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; ! } ! return true; ! } ! ! function DBClose() { ! global $DBConn; ! $DBConn->Close(); ! ! return true; ! } ! ! function Validate_Password($UserName, $Password) { ! GLOBAL $DBConn; ! $ret_val = 0; ! $sql = "SELECT Password FROM SystemUsers WHERE UserName=\"$UserName\""; ! $result = $DBConn->Execute($sql); ! if ($result->NumRows() > 0) { ! list($pw) = $result->fields; ! $pword = md5($Password); ! if (strcmp($pw, $pword) == 0) { ! $ret_val = 1; ! } ! } ! return $ret_val; ! } ! ! ?> --- 1,158 ---- ! <?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; ! } ! 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 * ! ******************************************************************************/ ! //Perhaps this should be moved to an all purpose 'funcitons' file? cws ! ! 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); ! //$rows = $result->NumRows(); ! //echo "$rows <br>"; ! 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[0]; ! $result->MoveNext(); ! } ! return $data_array; ! } ! ! ! ?> |