<?php
/**
* Project: web.framework: the PHP5 MVC framework
* File: SQLQueries.MySQL.class.php
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* You may contact the authors of web.framework by e-mail at:
* hide@address.com
*
* The latest version of web.framework can be obtained from:
* http://sourceforge.net/projects/webframework
*
* @link http://sourceforge.net/projects/webframework
* @copyright 2005 Marcin Staniszczak
* @author Marcin Staniszczak <hide@address.com>
* @version 1.0.0
*/
/**
* SQL queries for LoginChecker advanced tester
*
* @name SQLQueries
* @version 1.0.0
* @package web.framework
* @subpackage AdvancedTesters
*
* @author Marcin Staniszczak
* @copyright 2005 Marcin Staniszczak
*/
class SQLQueries {
private static $strUsersTable = '';
private static $strDetailsTable = '';
private static $objDBConnection = null;
private static $strPasswordRow = '';
private static $strUserNameRow = '';
/**
* Set DBConnection
*
* @access public
* @static
* @param object DBConnection object
*/
static public function setDBConnection($objDBConnection) {
self::$objDBConnection = $objDBConnection;
}
/**
* Set users table name
*
* @access public
* @static
* @param string table name
*/
static public function setUsersTable($strUsersTable) {
self::$strUsersTable = $strUsersTable;
}
/**
* Set details table name
*
* @access public
* @static
* @param string table name
*/
static public function setDetailsTable($strDetailsTable) {
self::$strDetailsTable = $strDetailsTable;
}
/**
* Set password row name
*
* @access public
* @static
* @param string password row name
*/
static public function setPasswordRow($strFieldName) {
self::$strPasswordRow = $strFieldName;
}
/**
* Set user-name row name
*
* @access public
* @static
* @param string user-name row name
*/
static public function setUserNameRow($strFieldName) {
self::$strUserNameRow = $strFieldName;
}
/**
* Get user information
*
* @access public
* @static
* @param string user name
* @return array with user informations, or NULL if user get bad password/user don't exist
*/
static public function getUser($strUser) {
if (self::$objDBConnection instanceof AWebDBDriver) {
$strUser = self::$objDBConnection->quote($strUser);
$strQuery = 'SELECT * FROM '.self::$strUsersTable.' AS users LEFT JOIN '.self::$strDetailsTable.' AS details ON users.iduser=details.iduser WHERE '.self::$strUserNameRow.'='.$strUser;
if (($objRes = self::$objDBConnection->query($strQuery)) !== false) {
$objRes->next();
return $objRes->getValue();
}
} elseif (self::$objDBConnection instanceof PDO) {
$strQuery = 'SELECT * FROM '.self::$strUsersTable.' AS users LEFT JOIN '.self::$strDetailsTable.' AS details ON users.iduser=details.iduser WHERE '.self::$strUserNameRow.'=:userName';
$objStament = self::$objDBConnection->prepare($strQuery);
$objStament->bindParam(':userName', $strUser, PDO::PARAM_STR);
$objStament->execute();
$arrRet = $objStament->fetch(PDO::FETCH_ASSOC);
return $arrRet !== false ? $arrRet : null;
} elseif (self::$objDBConnection instanceof ADOConnection) {
$strQuery = 'SELECT * FROM '.self::$strUsersTable.' AS users LEFT JOIN '.self::$strDetailsTable.' AS details ON users.iduser=details.iduser WHERE '.self::$strUserNameRow.'=?';
$objStmt = self::$objDBConnection->Prepare($strQuery);
$objRes = self::$objDBConnection->Execute($objStmt, array($strUser));
if ($objRes->RecordCount()==1) {
return $objRes->fields;
} else {
return null;
}
}
}
static public function updateLoginTime($intIDUser) {
$strQuery = 'UPDATE '.self::$strDetailsTable.' SET lastlogin='.time().', trycount=0, lasttry=0 WHERE iduser='.intval($intIDUser);
if (self::$objDBConnection instanceof AWebDBDriver) {
self::$objDBConnection->query($strQuery);
} elseif (self::$objDBConnection instanceof PDO) {
self::$objDBConnection->exec($strQuery);
} elseif (self::$objDBConnection instanceof ADOConnection) {
self::$objDBConnection->Execute($strQuery);
}
}
static function updateTryCount($intIDUser, $intTryCount) {
$strQuery = 'UPDATE '.self::$strDetailsTable.' SET lasttry='.time().', trycount='.intval($intTryCount).' WHERE iduser='.intval($intIDUser);
if (self::$objDBConnection instanceof AWebDBDriver) {
self::$objDBConnection->query($strQuery);
} elseif (self::$objDBConnection instanceof PDO) {
self::$objDBConnection->exec($strQuery);
} elseif (self::$objDBConnection instanceof ADOConnection) {
self::$objDBConnection->Execute($strQuery);
}
}
}
?>