<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// WebSite: http://www.rvglobalsoft.com
// Unauthorized copying is strictly forbidden and may result in severe legal action.
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
//
// =====YOU MUST KEEP THIS COPYRIGHTS NOTICE INTACT AND CAN NOT BE REMOVE =======
// Copyright (c) 2006 RV Global Soft Co.,Ltd. All rights reserved.
// This Agreement is a legal contract, which specifies the terms of the license
// and warranty limitation between you and RV Global Soft Co.,Ltd. and RV Site Builder.
// You should carefully read the following terms and conditions before
// installing or using this software. Unless you have a different license
// agreement obtained from RV Global Soft Co.,Ltd., installation or use of this software
// indicates your acceptance of the license and warranty limitation terms
// contained in this Agreement. If you do not agree to the terms of this
// Agreement, promptly delete and destroy all copies of the Software.
//
// ===== Grant of License =======
// The Software may only be installed and used on a single host machine.
//
// ===== Disclaimer of Warranty =======
// THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION ARE PROVIDED "AS IS" AND
// WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER
// WARRANTIES WHETHER EXPRESSED OR IMPLIED. BECAUSE OF THE VARIOUS HARDWARE
// AND SOFTWARE ENVIRONMENTS INTO WHICH RV SITE BUILDER MAY BE USED, NO WARRANTY OF
// FITNESS FOR A PARTICULAR PURPOSE IS OFFERED. THE USER MUST ASSUME THE
// ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF RV GLOBAL SOFT CO.,LTD. WILL BE
// LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE.
// IN NO CASE SHALL RV GLOBAL SOFT CO.,LTD. BE LIABLE FOR ANY INCIDENTAL, SPECIAL OR
// CONSEQUENTIAL DAMAGES OR LOSS, INCLUDING, WITHOUT LIMITATION, LOST PROFITS
// OR THE INABILITY TO USE EQUIPMENT OR ACCESS DATA, WHETHER SUCH DAMAGES ARE
// BASED UPON A BREACH OF EXPRESS OR IMPLIED WARRANTIES, BREACH OF CONTRACT,
// NEGLIGENCE, STRICT TORT, OR ANY OTHER LEGAL THEORY. THIS IS TRUE EVEN IF
// RV GLOBAL SOFT CO.,LTD. IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO CASE WILL
// RV GLOBAL SOFT CO.,LTD.'S LIABILITY EXCEED THE AMOUNT OF THE LICENSE FEE ACTUALLY PAID
// BY LICENSEE TO RV GLOBAL SOFT CO.,LTD.
// +---------------------------------------------------------------------------+
// $Id$
// +---------------------------------------------------------------------------+
/**
* Data access methods for the user of RVSiteBuilder
*
* @package sitebuilder
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @author Parinya <parinya@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
class UsrDao extends DbWrapper implements SitebuilderInf
{
function UsrDao()
{
parent::DbWrapper();
}
/**
* Returns a singleton UsrDao instance.
*
* @param bool $autoload
* @return obj
*/
public static function singleton($autoload=false)
{
static $instance;
// If the instance is not there, create one
if (!isset($instance) || $autoload) {
$class = __CLASS__;
$instance = new $class();
}
return $instance;
}
/**
* Find usr id by username
*
* @author Parinya Chaipetch
* @param string $username
* @param string $fetchmode; getassoc, getall, getrow
* @access public
* @return array
*/
public function findUsrIdByUsername($username = null, $fetchmode = 'getassoc', $aResultFields = array('rvs_usr_id'))
{
SGL::logMessage('username: '. $username . ' table:' . $this->aConf['table']['rvs_usr'], PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
if (!is_null($username)) {
$oUsr->user_name = $username;
}
$oUsr->find();
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
$oUsr->_resultFields = DbWrapper::buildResultFields($oUsr, $aResultFields);
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchmode);
}
/**************************************************
* Select
**************************************************/
/** Find usr id,user_name order by username
* Resulting SQL
* SELECT
* rvs_usr_id
* , user_name
* FROM
* rvs_usr
* ORDER BY
* user_name
* $aUser = $this->dbh->getAll($query, DB_FETCHMODE_ASSOC);
* @author Darawan Taorong
* @param string $fetchmode; getassoc, getall, getrow
* @access public
* @return array
*/
public function findUsrIdUsrNameOrderByUsrName($fetchmode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
$oUsr->selectAdd();
$oUsr->selectAdd('rvs_usr_id,user_name');
$oUsr->orderby('user_name');
$oUsr->find();
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
DB_DataObject::debugLevel(0);
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchmode);
}
/**
* Find usr id by project_id
*
* @author Witoon Jansri
* @param string $projectId
* @param string $fetchmode; getassoc, getall, getrow, getarray
* @access public
* @return array
*/
public function findUserIdByProjectId($projectId = null , $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
$oProject->selectAdd();
$oProject->selectAdd('rvs_usr_id');
if (!is_null($projectId)) {
$oProject->project_id = $projectId;
}
$oProject->find();
$aCloneData = array();
while ($oProject->fetch()) {
$aCloneData[$oProject->rvs_usr_id] = clone($oProject);
}
return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
}
/**
* Find all usr in all project from table rvs_project and rvs_usr
*
* @author Witoon Jansri
* @param string $fetchmode; getassoc, getall, getrow, getarray
* @access public
* @return array
*/
public function findAllUserInAllProject($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
$query = sprintf("
SELECT DISTINCT
rvs_usr.rvs_usr_id, rvs_usr.user_name
FROM
%s , %s
WHERE
rvs_project.rvs_usr_id = rvs_usr.rvs_usr_id
ORDER BY
rvs_usr.rvs_usr_id
"
, $this->aConf['table']['rvs_project']
, $this->aConf['table']['rvs_usr']
);
$oUsr->query($query);
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchMode);
}
/**
* find UsrId From RvsUsr from table rvs_usr
* SELECT
* `rvs_usr_id`
* FROM
* {$this->conf['table']['rvs_usr']}
*
* @author Pornthip Phothong
* @param string $fetchmode; getassoc, getall, getrow, getarray
* @return array
*/
public function findUsrIdFromRvsUsr($fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
$query = sprintf('
SELECT
`rvs_usr_id`
FROM
%s
'
, $this->aConf['table']['rvs_usr']
);
$oUsr->query($query);
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchMode);
}
function insertUsr($rvsUsrId=null, $userName=null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
///Fix PHP5.3 (use MDB2)
if (is_null($rvsUsrId) === false && !empty($rvsUsrId)) {
$oUsr->rvs_usr_id = $rvsUsrId;
}
if (is_null($userName) === false && !empty($userName)) {
$oUsr->user_name = $userName;
}
///Fix PHP5.3 (use MDB2)
return $oUsr->insert();
}
/**
* find user in fo by user name
* @author Pharadol
* @param <string> $table
* @param <string> $username
* @param <string> $fecthMode
* @return array
* cCompornentAndUserFrameWorkMgr.php
*/
public function findUserInfoByUserName($table = null , $username = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($table);
$oUsr->selectAdd();
$oUsr->selectAdd('first_name');
$oUsr->selectAdd('last_name');
$oUsr->selectAdd('email');
if (!is_null($oUsr)) {
$oUsr->username = $username;
}
$oUsr->find();
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->first_name] = clone($oUsr);
}
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchMode);
}
public function findUserInfoGetOneByUserName($table = null, $username = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($table);
if (!is_null($table) && !is_null($username)) {
$query = sprintf('
SELECT
first_name
, last_name
, email
FROM
%s
WHERE
username = %s
'
, $table
, RvsLibs_String::quoteSmart($username)
);
$oUsr->query($query);
}
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[] = clone($oUsr);
}
$_aResultFields = DbWrapper::buildResultFields($oUsr, $aResultFields = array());
return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
}
/**
* find usrid by usrname and usrid
* @othor pharadol
* @param <string> $usrId
* @param <string> $username
* @param <string> $fetchmode
* @return array
*/
public function findUsrIdByUsernameAndusrId($usrId, $username = null, $fetchmode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
if (!is_null($usrId) && !is_null($username)) {
$query = sprintf('
SELECT
rvs_usr_id
FROM
%s
WHERE
rvs_usr_id = %s
AND user_name != %s
'
, $this->aConf['table']['rvs_usr']
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($username)
);
$oUsr->query($query);
}
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
return DbWrapper::fetchDatas($oUsr->_resultFields, $aCloneData, $fetchmode);
}
public function findUsrByUsrId($usrId = null, $fetchmode='getassoc', $aResultFields =array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
if (!is_null($usrId)) {
$oUsr->rvs_usr_id = $usrId;
}
$oUsr->find();
$aCloneData = array();
while ($oUsr->fetch()) {
$aCloneData[$oUsr->rvs_usr_id] = clone($oUsr);
}
$_aResultFields = DbWrapper::buildResultFields($oUsr, $aResultFields);
return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchmode);
}
public function findSpecialVariableByUserId($usrId = null, $fetchmode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$oSpecialVar = DB_DataObject::factory($this->aConf['table']['rvs_special_variable']);
if (!is_null($usrId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
rvs_usr_id = %s
ORDER BY
last_update
DESC
'
, $this->aConf['table']['rvs_special_variable']
, RvsLibs_String::quoteSmart($usrId)
);
$oSpecialVar->query($query);
}
$aCloneData = array();
while ($oSpecialVar->fetch()) {
$aCloneData[$oSpecialVar->variable_id] = clone($oSpecialVar);
}
return DbWrapper::fetchDatas($oSpecialVar->_resultFields, $aCloneData, $fetchmode);
}
public function insertSpecialVariableNameAndValue($usrId = null, $VariableId, $variableName, $variableValue, $fetchmode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oSpecialVar = DB_DataObject::factory($this->aConf['table']['rvs_special_variable']);
$query = sprintf('
INSERT INTO
%s (
variable_id
,rvs_usr_id
,variable_name
,variable_value
,last_update
)
VALUES (
%s
,%s
,%s
,%s
,%s
)
'
, $this->aConf['table']['rvs_special_variable']
, RvsLibs_String::quoteSmart($VariableId)
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($variableName)
, RvsLibs_String::quoteSmart($variableValue)
,time()
);
$res = $oSpecialVar->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res) ? true : false;
}
public function updateSpecialVariableNameAndValue($usrId, $VariableId, $variableName, $variableValue)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oSpecialVar = DB_DataObject::factory($this->aConf['table']['rvs_special_variable']);
$query = sprintf('
UPDATE
%s
SET
variable_name = %s
, variable_value = %s
, last_update = %s
WHERE
variable_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_special_variable']
, RvsLibs_String::quoteSmart($variableName)
, RvsLibs_String::quoteSmart($variableValue)
, time()
, RvsLibs_String::quoteSmart($VariableId)
, RvsLibs_String::quoteSmart($usrId)
);
$res = $oSpecialVar->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res) ? true : false;
}
public function updateLangByUserId($userId = null, $charsetId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oUser = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
if (!is_null($userId) && !is_null($charsetId)) {
$oUser->get('rvs_usr_id', $userId);
$oUser->charset_id = $charsetId;
$oUser->update();
}
return 0;
}
public function deleteUserByUserName($userName = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oTemplate = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
if (!is_null($userName)){
$query = sprintf('
DELETE
%s
FROM
%s
WHERE
user_name = %s
'
, $this->aConf['table']['rvs_usr']
, $this->aConf['table']['rvs_usr']
, RvsLibs_String::quoteSmart($userName)
);
$res = $oTemplate->query($query);
}
return $res;
}
public function deleteSpecialVariable($usrId, $VariableId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oSpecialVar = DB_DataObject::factory($this->aConf['table']['rvs_special_variable']);
if (!is_null($usrId)){
$query = sprintf('
DELETE
%s
FROM
%s
WHERE
variable_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_special_variable']
, $this->aConf['table']['rvs_special_variable']
, RvsLibs_String::quoteSmart($VariableId)
, RvsLibs_String::quoteSmart($usrId)
);
$res = $oSpecialVar->query($query);
}
return $res;
}
public function backupsql($projectId, $usrId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
/// Backup table rvs_usr
$oUsr = $this->findUsrByUsrId($usrId, 'getDataObject');
foreach ($oUsr as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
/// Backup table rvs_special_variable
$oSpecialVal = $this->findSpecialVariableByUserId($usrId, 'getDataObject');
foreach ($oSpecialVal as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
return $aSQLData;
}
public function deleteProjectOfUserId($projectId, $usrId, $aProjectPageId = array()) {
SGL::logMessage(null, PEAR_LOG_DEBUG);
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez