CHips L MINI SHELL

CHips L pro

Current Path : /opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/lib/RVSGL/SitebuilderDao/
Upload File :
Current File : //opt/cpanel/ea-php54/root/usr/share/pear/RVSeagullMod/lib/RVSGL/SitebuilderDao/ProjectDao.php

<?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 projects of RVSiteBuilder
 *
 * @package sitebuilder
 * @author  Pairote Manunphol <pairote@rvglobalsoft.com>
 * @author  Parinya <parinya@rvglobalsoft.com>
 * @version $Revision$
 * @since   PHP 5.1
 */


class ProjectDao extends DbWrapper implements SitebuilderInf
{

	function ProjectDao()
	{
		parent::DbWrapper();
	}

	/**
	 * Returns a singleton ProjectDao instance.
	 * @access public
	 * @author Parinya Chatpetch
	 * @param bool $autoload
	 *
	 * @return obj
	 */
	public static function singleton($autoload=false)
    {
        static $instanceDao;
        // If the instance is not there, create one
        if (!isset($instanceDao) || $autoload) {
            $class = __CLASS__;
            $instanceDao = new $class();
        }
        return $instanceDao;
    }

    /**
     * Example 1
     * Function for Selete all Projects from table 'rvs_project' and 'rvs_project_info'
     * by user ID with usage SQL query
     * @access private
     * @author Parinya Chatpetch
     * @param string $rvsuserId
     *
     * @return <array obj>
     */
    private function Ex1_findAllProjectByUsrId($rvsUsrId=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
		$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);

		if (!is_null($rvsUsrId)) {
			$query = sprintf('
				SELECT
					project_id
					, project_name
					, last_update
				FROM
					%s as a
					, %s as b
				WHERE
					rvs_usr_id = %s
					AND a.project_info_id = b.project_info_id
				ORDER BY
					project_name
			'
				, $this->aConf['table']['rvs_project']
				, $this->aConf['table']['rvs_project_info']
				, RvsLibs_String::quoteSmart($rvsUsrId)
			);
			$oProject->query($query);
		}
		$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[$oProject->project_id] = clone($oProject);
		}
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, 'getassoc');
    }

    /**
     * Example 2
     * Function for Selete all Projects from table 'rvs_project' and 'rvs_project_info'
     * by user ID with usage DB_DataObject methods
     * @access private
     * @author Parinya Chatpetch
     * @param string $rvsuserId
     *
     * @return <array obj>
     */
    private function Ex2_findAllProjectByUsrId($rvsUsrId=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
		$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
		$oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
		$oProject->joinAdd($oProjectInfo);
		$oProject->selectAdd();
		$oProject->selectAdd('project_id, project_name, last_update');
		$oProject->orderBy('project_name');

		if (!is_null($rvsUsrId)) {
			$oProject->rvs_usr_id = $rvsUsrId;
			$oProject->find();
		}
		$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[$oProject->project_id] = clone($oProject);
		}
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, 'getassoc');
    }

    public function findCustomLayerByProjectId($rvsProjectId=null, $layerId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oCustomLayer = DB_DataObject::factory($this->aConf['table']['rvs_custom_layer']);
        if (!is_null($rvsProjectId)) {
            $query = sprintf('
                SELECT
                   *
                FROM
                    %s
                WHERE
                	rvs_project_id = %s
                	%s
                ORDER BY
                    layer_id
            '
            , $this->aConf['table']['rvs_custom_layer']
            , RvsLibs_String::quoteSmart($rvsProjectId)
            , (is_null($layerId) === false) ? sprintf('AND layer_id = %s', RvsLibs_String::quoteSmart($layerId)) : ''
            );

            $oCustomLayer->query($query);
        }
        $aCloneData = array();
        while ($oCustomLayer->fetch()) {
            $aCloneData[$oCustomLayer->layer_id] = clone($oCustomLayer);
        }
        return DbWrapper::fetchDatas($oCustomLayer->_resultFields, $aCloneData, $fetchMode);
    }

    public function findAllProjectsPropByUsrId($rvsUsrId=null, $fetchMode = 'getassoc')
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel(0);
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
    	if (!is_null($rvsUsrId)) {
    		$query = sprintf('
                SELECT
                    p.project_id, p.project_name, p.project_footer, pi.last_update, pi.project_info_id
                    , CONCAT(pl.rvs_publish_protocal,"://",pl.rvs_publish_domain,pl.rvs_publish_path )as urlPublish
                    , pl.rvs_publish_path
                    , ti.*
                FROM
                    %s as p INNER JOIN
                    %s as pi ON p.project_info_id = pi.project_info_id LEFT OUTER JOIN
                    %s as pl ON pl.project_id = p.project_id LEFT OUTER JOIN
                    %s as ti ON ti.template_item_id = pi.template_item_id
                WHERE
                    rvs_usr_id = %s
                ORDER BY
                    pi.last_update DESC
            '
            , $this->aConf['table']['rvs_project']
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_publish']
            , $this->aConf['table']['rvs_template_item']
            , RvsLibs_String::quoteSmart($rvsUsrId)
            );

            $oProject->query($query);
    	}
    	$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[$oProject->project_id] = clone($oProject);
    	}
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
        * select  data table rvs_body_attribute By projectId projectPageId att_name
        * @author duangdao.k
        * @param string $projectId
        * @param string projectPageId
        * @param string $attName
        * @return array
     */
    public function findAttNameBodyAttributeByprojectIdAndProjectPageId($projectId, $projectPageId = null, $attName, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf("
                        SELECT
                            *
                        FROM
                            %s bx
                            , %s ba
                        WHERE
                            bx.project_id = %s
                            %s
                            AND bx.att_id = ba.att_id
                            AND ba.att_name = %s
                        "
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
                       , (is_null($projectPageId)) ? '' :  'AND bx.project_page_id = ' . RvsLibs_String::quoteSmart($projectPageId)
                       , RvsLibs_String::quoteSmart($attName)
                 );
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
        * find rvs_body_attribute_xref by projectId or pageId
        * @author witoon
        * @param string $projectId
        * @param string $projectPageId
        * @return mix return result by fetch mode
     */
    public function findBodyAttributeXref($projectId, $projectPageId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oBodyXref = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        SELECT
                            bx.*
                        FROM
                            %s as bx
                            , %s as bo
                        WHERE
                            bx.project_id = %s
                            %s
                            AND bx.att_id = bo.att_id
                        '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
                       , (!is_null($projectPageId)) ? ' AND bx.project_page_id=' . RvsLibs_String::quoteSmart($projectPageId) : ''
        );
        $oBodyXref->query($query);
        $aCloneData = array();
        while ($oBodyXref->fetch()) {
            $aCloneData[] = clone($oBodyXref);
        }
        return DbWrapper::fetchDatas($oBodyXref->_resultFields, $aCloneData, $fetchMode);
    }

    /**
        * find rvs_body_attribute_xref by projectId or pageId
        * @author witoon
        * @param string $projectId
        * @param string $projectPageId
        * @return mix return result by fetch mode
     */
    public function findBodyAttributeXrefdel($projectId, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oBodyXref = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        SELECT
                             *
                        FROM
                            %s as bx
                            , %s as bo
                        WHERE
                            bx.project_id = %s
                            AND bx.att_id = bo.att_id
                        '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
        );
        $oBodyXref->query($query);
        $aCloneData = array();
        while ($oBodyXref->fetch()) {
            $aCloneData[] = clone($oBodyXref);
        }
        return DbWrapper::fetchDatas($oBodyXref->_resultFields, $aCloneData, $fetchMode);
    }

    public function findBodyAttributeXrefDelByPageId($projectPageId=null, $fetchMode = 'getAll')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oBodyXref = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        SELECT
                             *
                        FROM
                            %s as bx
                            , %s as bo
                        WHERE
                            bx.project_page_id = %s
                            AND bx.att_id = bo.att_id
                        '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectPageId)
        );
        $oBodyXref->query($query);
        $aCloneData = array();
        while ($oBodyXref->fetch()) {
            $aCloneData[] = clone($oBodyXref);
        }
        return DbWrapper::fetchDatas($oBodyXref->_resultFields, $aCloneData, $fetchMode);
    }

    public function findBodyAttributeXrefDelByProjectId($projectId=null, $fetchMode = 'getAll')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oBodyXref = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        SELECT
                             *
                        FROM
                            %s as bx
                            , %s as bo
                        WHERE
                            bx.project_id = %s
                            AND bx.att_id = bo.att_id
                        '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
        );
        $oBodyXref->query($query);
        $aCloneData = array();
        while ($oBodyXref->fetch()) {
            $aCloneData[] = clone($oBodyXref);
        }
        return DbWrapper::fetchDatas($oBodyXref->_resultFields, $aCloneData, $fetchMode);
    }


    /**
        * find rvs_body_attribute  By projectId or pageId
        * @author witoon
        * @param string $projectId
        * @param string $projectPageId
        * @return mix return result by fetch mode
     */
    public function findBodyAttributeData($projectId, $projectPageId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
        $query = sprintf("
                        SELECT
                        ba.att_id
                        , ba.att_name
                        , ba.att_value
                        FROM
                            %s as bx
                            , %s as ba
                        WHERE
                            bx.att_id = ba.att_id
                            AND bx.project_id = %s
                            %s
                        "
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
                       , (is_null($projectPageId) == false)
                       		? ' AND bx.project_page_id =' . RvsLibs_String::quoteSmart($projectPageId)
                       		: ''
                 );
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
        * select  data table rvs_body_attribute And rvs_body_attribute_xref By projectId
        * @author duangdao.k
        * @param string $projectId
        * @param string $projectPageId
        * @param string $attName
        * @return array
     */
    public function findDataBodyAttributeBodyAttributeXrefByprojectIdAndProjectPageId($projectId, $projectPageId = null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
        $query = sprintf("
                        SELECT
                            *
                        FROM
                            %s bx
                            , %s ba
                        WHERE
                            bx.project_id = %s
                            %s
                            AND bx.att_id = ba.att_id
                        "
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($projectId)
                       , (is_null($projectPageId)) ? '' : 'AND bx.project_page_id = ' . RvsLibs_String::quoteSmart($projectPageId)
                 );
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Find all projects_id  from table 'rvs_project'  by rvsUsrId
     * @access public
     * @author Witoon Jansri
     * @param string $rvsUsrId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     *
     * @return <array obj>
     */
    public function findProjectIdByUsrId($rvsUsrId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $oProject->selectAdd();
        $oProject->selectAdd('project_id');

        if (!is_null($rvsUsrId)) {
            $oProject->rvs_usr_id = $rvsUsrId;
            $oProject->find();
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Find all Data project info  from table 'rvs_project_info'  by template item id
     * Resulting SQL
     *      SELECT
     *           *
     *       FROM
     *           rvs_project_info
     *       WHERE
     *           template_item_id = {$templateItemId}
     * $res = $this->objDbh->getAssoc($query);
     *
     * @access public
     * @author Darawan Taorong
     * @param string $templateItemId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     *
     * @return <array obj>
     * @from file : TemplateList.php  Fn : isTemplateImportUsed
     */
    public function findDataProjectInfoByTemplateItemId($templateItemId = null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        //$oProject->selectAdd();
      //  $oProject->selectAdd('project_id');

        if (!is_null($templateItemId)) {
            $oProject->template_item_id = $templateItemId;
            $oProject->find();
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Find all projects data  from table 'rvs_project'
     * @access public
     * @author Witoon Jansri
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     *
     * @return <array obj>
     */
    public function findAllProjectsByAllUser($fetchMode = 'getassoc')
    {
        DB_DataObject::debugLevel();
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
		$oUsr = DB_DataObject::factory($this->aConf['table']['rvs_usr']);
		//$oProject->orderBy('rvs_usr_id');
		$oProject->joinAdd($oUsr);
		$oProject->find();
		$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[] = clone($oProject);
		}
        DB_DataObject::debugLevel();
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

	/**
     * Selete all project data from table 'rvs_project' and 'rvs_project_info' by project ID
     * Resulting SQL
     * 	SELECT
     * 		*
     * 	FROM
     * 		rvs_project p
     * 		, rvs_project_info i
     * 	WHERE
     * 		p.project_id = {$projectId}
     * 		AND i.project_info_id = p.project_info_id
     *
     * @access public
     * @author Parinya Chatpetch
     * @param string $projectId
     *
     * @return <array obj>
     */
    public function findAllProjectsByProjectId($projectId=null, $fetchMode = 'getassoc', $aResultFields = array())
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
		$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
		$oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
		$oProject->joinAdd($oProjectInfo);

		if (!is_null($projectId)) {
			$oProject->project_id = $projectId;
		    $oProject->find();
		}
		$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[$oProject->project_id] = clone($oProject);
		}
        $oProject = DbWrapper::buildResultFields($oProject, $aResultFields);
		return DbWrapper::fetchDatas($oProject, $aCloneData, $fetchMode);
    }

    public function findProjectByLikeProjectName($projectName, $fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        if (!is_null($projectName)) {
            $query = sprintf("
                        SELECT
                              project_id
                              , project_name
                        FROM
                              %s
                        WHERE project_name LIKE %s
                        "
                       , $this->aConf['table']['rvs_project']
                       , RvsLibs_String::quoteSmart($projectName. '%')
                 );

            $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

	/**
     * Selete all project data from table 'rvs_project' and 'rvs_project_info' by user ID and project name
     * @access public
     * @author Parinya Chatpetch
     * @param string $rvsUserId
     * @param srting $projectName
     *
     * @return <array obj>
     */
    public function findAllProjectsByUserIDAndProjectName($rvsUserId=null, $projectName=null, $fetchMode='getassoc')
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
		$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
		$oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
		$oProject->joinAdd($oProjectInfo);

		if (!is_null($rvsUserId) && !is_null($projectName)) {
			$oProject->rvs_usr_id = $rvsUserId;
			$oProject->project_name = $projectName;

			$oProject->find();
		}
		$aCloneData = array();
		while ($oProject->fetch()) {
    		$aCloneData[$oProject->project_id] = clone($oProject);
		}
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Select all prohect data by user id and project name
     *
     * @author Parinya Chaipetch
     * @param string $rvsUserId
     * @param string $projectId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array
     */
    public function findProjectsByUserIdAndProjectId($rvsUserId=null, $projectId=null, $fetchMode = 'getassoc')
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);

        if (!is_null($rvsUserId) && !is_null($projectId)) {
            $oProject->rvs_usr_id = $rvsUserId;
            $oProject->project_id = $projectId;
            $oProject->find();
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Select all publist data by user id and project id
     *
     * @author Darawan Taorong
     * @param string $rvsUserId
     * @param string $projectId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array
     */
    public function findPublishByUserIdAndProjectId($rvsUserId=null, $projectId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_publish']);

        if (!is_null($rvsUserId) && !is_null($projectId)) {
             $query = sprintf("
                        SELECT
                            *
                        FROM
                            %s pb
                            , %s p
                        WHERE
                            pb.project_id = p.project_id
                            AND  p.rvs_usr_id = %s
                            AND  pb.project_id = %s
                            AND  pb.rvs_publish_path != ''
                        "
                       , $this->aConf['table']['rvs_publish']
                       , $this->aConf['table']['rvs_project']
                       , RvsLibs_String::quoteSmart($rvsUserId)
                       , RvsLibs_String::quoteSmart($projectId)
                 );

            $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }
/**
     * Select publish data
     *
     * @author Witoon Jansri
     * @param string $projectId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array or obj
     */
    public function findPublishDataByProjectId($projectId=null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_publish']);

        if (!is_null($projectId) || $projectId) {
			$oProject->project_id = $projectId;
		}
 		$oProject->find();
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

     /** Select all project
     * Resulting SQL
     * 	SELECT
     * 		rvs_project
     * 		, rvs_project.project_name
     * 		, rvs_project_info.last_update
     * 	FROM
     * 		rvs_project
     * 		, rvs_project_info
     * 		, rvs_usr
     *  WHERE
     * 		rvs_project.rvs_usr_id = rvs_usr.rvs_usr_id
     * 		AND rvs_project.project_info_id = rvs_project_info.project_info_id
     * 	ORDER BY
     * 		rvs_usr.rvs_usr_id
     *  $aDBUserList = $this->dbh->getAll($query,DB_FETCHMODE_ASSOC);
     *
     * @author Darawan Taorong create date 24/04/2552
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array
     */
    public function findAllProject($fetchMode='getassoc')
    {
   	    SGL::logMessage(null, PEAR_LOG_DEBUG);
   	    DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf("
                       	SELECT
                            p.project_id
                            , p.project_name
                            , pi.last_update
                        FROM
                            %s p
                            , %s pi
                            , %s u
                        WHERE
                            p.rvs_usr_id = u.rvs_usr_id
                        AND
                            p.project_info_id = pi.project_info_id
                        ORDER BY
                            u.rvs_usr_id
                        "
                       	, $this->aConf['table']['rvs_project']
                       	, $this->aConf['table']['rvs_project_info']
                       	, $this->aConf['table']['rvs_usr']
                      	);
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        DB_DataObject::debugLevel(0);
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Select all prohect data by user id and project name
     *
     * Resulting SQL
     * 		SELECT
     *          rvs_project.project_id
     * 			, rvs_project.project_name
     * 			, rvs_project_info.last_update
     *      FROM
     *           rvs_project
     * 			, rvs_project_info
     * 			, rvs_usr
     *      WHERE
     *       	rvs_project.rvs_usr_id = rvs_usr.rvs_usr_id
     * 			AND rvs_project.project_info_id = rvs_project_info.project_info_id
     * 			AND rvs_usr.user_name = '{$username}'
     * 		ORDER
     * 			rvs_usr.rvs_usr_id
     *
     * @author Darawan Taorong
     * @param string $username
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array
     */
    public function findProjectByUsername($username=null,$fetchMode='getassoc')
    {
   	    SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        if (!is_null($username)) {
              $query = sprintf("
                        SELECT
                                  rvs_project.project_id
                                  , rvs_project.project_name
                                  , rvs_project_info.last_update
                        FROM
                                %s , %s , %s
                        WHERE
                                rvs_project.rvs_usr_id = rvs_usr.rvs_usr_id
                        AND
                                rvs_project.project_info_id = rvs_project_info.project_info_id
                       AND
                                rvs_usr.user_name = %s
                        ORDER BY
                                rvs_usr.rvs_usr_id
                       "
                       , $this->aConf['table']['rvs_project']
                       , $this->aConf['table']['rvs_project_info']
                       , $this->aConf['table']['rvs_usr']
                       , RvsLibs_String::quoteSmart($username)
                      );
                  $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    function findprojectDataByUserId($userId=null,$fetchMode='getassoc', $aResultFields =array())
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        if (!is_null($userId)) {
            $query = sprintf("
                        SELECT
                                   *
                        FROM
                                %s
                        WHERE
                                rvs_usr_id = %s
                    "
                    , $this->aConf['table']['rvs_project']
                    , RvsLibs_String::quoteSmart($userId)
                    );
            $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        $_aResultFields = DbWrapper::buildResultFields($oProject, $aResultFields);
        return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
    }

    function findProjectRefColorGroupNavigatorByProjectIdAndNavgiatorId($projectId=null, $navigatorId=null, $fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
            SELECT
                *
            FROM
                %s p
                , %s pf
                , %s n
                , %s nf
                , %s cgn
            WHERE
                p.project_id = %s
                AND n.navigator_id = %s
                AND p.project_info_id = pf.project_info_id
                AND pf.navigator_id = n.navigator_id
                AND n.navigator_id = nf.navigator_id
                AND nf.color_group_id = cgn.color_group_id
            '
            , $this->aConf['table']['rvs_project']
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_navigator']
            , $this->aConf['table']['rvs_navigator_color_xref']
            , $this->aConf['table']['rvs_color_group_name']
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($navigatorId)
        );
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Find category id by project id
     *
     * Resulting SQL
     *      SELECT
     *           xr.rvs_category_id
     * 			, pf.template_item_id
     * 			, pf.navigator_id
     *       FROM
     *          rvs_project p
     * 			rvs_project_info pf
     * 			rvs_template_item ti
     * 			rvs_template_categories_xref xr
     *       WHERE
     *          p.project_id = '$projectId'
     * 		    AND p.project_info_id = pf.project_info_id
     *          AND pf.template_item_id = ti.template_item_id
     *          AND ti.template_id = xr.template_id
     *          AND xr.rvs_category_id = pf.rvs_category_id
     *       ORDER BY
     *          xr.rvs_category_id
     * $this->objDbh->getRow($query,DB_FETCHMODE_ASSOC);
     *
     * @param string $projectId
     * @param string $fetchMode
     * @author Darawan Taorong
     * @access public
     * @return array
     * @from TemplateList.php    Fn : _getRefCategoryId
     */
    function findCategoryIdByProjectId($projectId=null, $fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
            SELECT
            	xr.rvs_category_id
            	, pf.template_item_id
            	, pf.navigator_id
            FROM
                %s p
                , %s pf
                , %s ti
                , %s xr
            WHERE
                p.project_id = %s
                AND p.project_info_id = pf.project_info_id
            	AND pf.template_item_id = ti.template_item_id
                AND ti.template_id = xr.template_id
                AND xr.rvs_category_id = pf.rvs_category_id
            ORDER BY
                xr.rvs_category_id
            '
            , $this->aConf['table']['rvs_project']
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_template_item']
            , $this->aConf['table']['rvs_template_categories_xref']
            , RvsLibs_String::quoteSmart($projectId)
        );
        $oProject->query($query);
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * find projectidfo data by projectid and usrid
     * @othor phatadol
     * @param <string> $projectId
     * @param <string> $rvsUsrId
     * @param <string> $fetchMode
     * @return array
     * form file common.php
     */
    public function findProjectInfoDataByProjectIdAndUsrId($projectId = null, $rvsUsrId = null, $fetchMode='getrow')
    {
        DB_DataObject::debugLevel();
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);

        if (!is_null($projectId)) {
            $query = sprintf("
                        SELECT
                        			pr.*,t.*,pi.*,it.*
                        FROM
                                    %s pr
                                    , %s pi
                                    , %s t
                                    , %s it
                        WHERE
                                    pr.project_id = %s
                                    AND pr.rvs_usr_id = %s
                                    AND pr.project_info_id = pi.project_info_id
                                    AND t.template_id = it.template_id
                                    AND pi.template_item_id = it.template_item_id
                        "
                        , $this->aConf['table']['rvs_project']
                        , $this->aConf['table']['rvs_project_info']
                        , $this->aConf['table']['rvs_template']
                        , $this->aConf['table']['rvs_template_item']
                        , RvsLibs_String::quoteSmart($projectId)
                        , RvsLibs_String::quoteSmart($rvsUsrId)
                        );
            $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $oProject->font_id = ($oProject->font_id == '0' || $oProject->font_id == '' || $oProject->font_id == null)?'1': $oProject->font_id;
            $aCloneData[] = clone($oProject);
        }
        DB_DataObject::debugLevel();
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }
    /**
     * select form rvs_project rvs_project_info rvs_template_item by  project_id color_id picture_id template_id
     *
     * @param unknown_type $projectId
     * @param unknown_type $rvsUsrId
     * @param unknown_type $fetchMode
     * @return unknown
     */
    public function findProjectInfoDataByProjectIdAndUsrIdWidthTemplateId($projectId=null, $colorId=null, $pictureId=null, $templateId=null, $fetchMode='getrow')
    {
        DB_DataObject::debugLevel();
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        if (!is_null($projectId) && !is_null($colorId) && !is_null($pictureId) && !is_null($templateId)) {
            $query = sprintf("
                            SELECT
                                    *
                            FROM
                                        %s p,
                                        %s pf,
                                        %s it
                            WHERE
                                        p.project_id = %s
                                        AND p.project_info_id = pf.project_info_id
                                        AND it.color_id = %s
                                        AND it.picture_id = %s
                                        AND it.template_id = %s
                    ",
                      $this->aConf['table']['rvs_project'],
                      $this->aConf['table']['rvs_project_info'],
                      $this->aConf['table']['rvs_template_item'],
                      RvsLibs_String::quoteSmart($projectId),
                      RvsLibs_String::quoteSmart($colorId),
                      RvsLibs_String::quoteSmart($pictureId),
                      RvsLibs_String::quoteSmart($templateId)
                                        );
            $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        DB_DataObject::debugLevel();
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }
     /**
     * Select project_id  by ProjectId
     *
     * Resulting SQL
     *      SELECT
     *           project_id
     *       FROM
     *           rvs_publish
     *       WHERE
     *           project_id = {$rvsProjectId}
     *
     * @author Darawan Taorong
     * @param string $rvsProjectId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @access public
     * @return array
     */
    public function findPublishProjectByProjectId($rvsProjectId=null,$fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_publish']);
        $oProject->selectAdd();
        $oProject->selectAdd('project_id');
        $oProject->orderBy('project_id');
        if (!is_null($rvsProjectId)) {
            $oProject->rvs_project_id = $rvsProjectId;
            $oProject->find();
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[$oProject->project_id] = clone($oProject);
        }
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

     /**
     * Select Project Data by $projectId
     * Resulting SQL
     * 	SELECT
     * 		i.project_title
     * 		, p.project_name
     * 		, i.project_domain
     * 	FROM
     * 		rvs_project p
     * 		, rvs_project_info i
     * 	WHERE
     * 		p.project_id = {$projectId}
     * 		AND i.project_info_id = p.project_info_id
     * $res = $this->dbh->getRow($query,DB_FETCHMODE_ASSOC);
     *
     * @author Pornthip Phothong
     * @param string $projectId
     * @param string $fetchMode; getassoc, getall, getrow, getarray
     * @return array
     */
    public function findProjectDataByPorjectId($projectId=null, $fetchMode='getassoc')
    {
        DB_DataObject::debugLevel();
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        if (!is_null($projectId)) {
           $query = sprintf('
                        SELECT
                                    i.project_title
                                    , p.project_name
                                    , i.project_domain
                        FROM
                                   %s   p
                                  , %s  i
                        WHERE
                                    p.project_id = %s
                                    AND i.project_info_id = p.project_info_id
                    '
                    , $this->aConf['table']['rvs_project']
                    , $this->aConf['table']['rvs_project_info']
                    , RvsLibs_String::quoteSmart($projectId)
                         );
             $oProject->query($query);
        }
        $aCloneData = array();
        while ($oProject->fetch()) {
            $aCloneData[] = clone($oProject);
        }
        DB_DataObject::debugLevel();
        return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
        }

        /**
         * Find Data from table rvs_project, rvs_project_info and rvs_charset by project_id, project_info_id and charset_id
         *
         * Resulting SQL
         * 		SELECT
         * 				 *
         * 		FROM
         * 				rvs_project p
         * 				 , rvs_project_info pf
         * 				 , rvs_charset cs
         * 		WHERE
         * 				p.project_id = {$projectId}
         * 		 AND
         * 				 p.project_info_id = pf.project_info_id
         * 		 AND
         * 				pf.charset_id = cs.charset_id
         *
         *
         * @author duangdao.k
         * @param string $projectId
         * @param string $fetchMode
         * @return arrayobj
         */
        public function findProjectInfoDataByProjectId($projectId = null, $fetchMode='getassoc')
        {
            DB_DataObject::debugLevel();
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
            if (!is_null($projectId)) {
                  $query = sprintf('
                         SELECT
                                 *
                          FROM
                                  %s p
                                  , %s pf
                                   , %s cs
                          WHERE
                                 p.project_id =%s
                          AND
                                 p.project_info_id = pf.project_info_id
                           AND
                                pf.charset_id = cs.charset_id
                           '
                           , $this->aConf['table']['rvs_project']
                           , $this->aConf['table']['rvs_project_info']
                           , $this->aConf['table']['rvs_charset']
                           , RvsLibs_String::quoteSmart($projectId)
                     );
                     $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
        }

        /**
         * Find Data from table rvs_project and rvs_project_info where project_id and project_info_id order by project_info_id
         *
         * Resulting SQL
         *   	SELECT
         * 					*
         * 		FROM
         * 				rvs_project p
         * 				, rvs_project_info i
         * 		WHERE
         * 				p.project_id = {$projectId}
         * 				AND i.project_info_id = p.project_info_id
         * 		ORDER BY
         * 				p.project_info_id
         *
         * @author duangdao.k
         * @param string $projectId
         * @param string $fetchMode
         * @return array
         */
        public function findProjectDataByProjectIdAndProjectInfoId($projectId = null, $fetchMode='getassoc', $aResultFields=array())
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
            if (!is_null($projectId)) {
               $query = sprintf("
                      SELECT
                            *
                       FROM
                             %s p
                             , %s i
                       WHERE
                              p.project_id = %s
                              AND i.project_info_id = p.project_info_id
                       ORDER BY
                               p.project_info_id"
                               , $this->aConf['table']['rvs_project']
                               , $this->aConf['table']['rvs_project_info']
                               , RvsLibs_String::quoteSmart($projectId)
                  );
                  $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            $_aResultFields = DbWrapper::buildResultFields($oProject, $aResultFields);
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
        }

        /**
         * Find project_keyword and project_description from table rvs_project and rvs_project_info where project_id and project_info_id
         *
         * Resulting SQL
         * 		SELECT
         * 			i.project_keyword
         * 			, i.project_description
         * 		FROM
         * 			rvs_project' p
         * 			 , rvs_project_info i
         * 		WHERE
         * 			p.project_id = {$projectId}
         * 			 AND i.project_info_id = p.project_info_id
         *
         *  @author duangdao.k
         * @param string $projectId
         * @param string $fetchMode
         * @return bool
         */
        public function findProjectKeywordAndProjectDescriptionByProjectId($projectId = null, $fetchMode='getassoc')
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
            if (!is_null($projectId)) {
                 $query = sprintf('
					 SELECT
                            i.project_keyword
                            , i.project_description
					  FROM
                            %s p
                            , %s i
                      WHERE
                            p.project_id = %s
                            AND i.project_info_id = p.project_info_id
                    '
                    , $this->aConf['table']['rvs_project']
                    , $this->aConf['table']['rvs_project_info']
                    , RvsLibs_String::quoteSmart($projectId)
                );
            $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
        }

        /**
         * Find ProjectTitle By ProjectID
         *
         * Resulting SQL
         * 		 SELECT
         * 				 i.project_title
         * 		 FROM
         * 				 rvs_project p
         * 				 , rvs_project_info i
         * 		 WHERE
         * 				 p.project_id ={$projectID}
         * 				 AND i.project_info_id = p.project_info_id
         *
         * @author duangdao.k
         * @param string $projectID
         * @param string $fetchMode
         * @return string
         */
        public function findProjectTitleByProjectID($projectID = null, $fetchMode='getassoc')
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
            if (!is_null($projectID)) {
                $query = sprintf('
                        SELECT
                                    i.project_title
                        FROM
                                    %s p
                                    , %s i
                        WHERE
                                    p.project_id = %s
                                    AND i.project_info_id = p.project_info_id
                    '
                    , $this->aConf['table']['rvs_project']
                    , $this->aConf['table']['rvs_project_info']
                    , RvsLibs_String::quoteSmart($projectID)
                  );
                     $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
        }
        /**
         * Find ProjectData And ProjectInfo By UsrId
         * Resulting SQL
         * 		SELECT
         * 	 		project_id
         *  		, rvs_usr_id
         * 			, project_name
         * 			 , last_update
         * 		FROM
         * 			rvs_project as a
         *    		 , rvs_project_info as b
         *		 WHERE
         * 			rvs_usr_id = {$rvsUsrId}
         *  		AND a.project_info_id = b.project_info_id
         * 			ORDER BY
         *  		project_name
         *
         *  @author duangdao.k
         * @param string $rvsUsrId
         * @param string $fetchMode
         * @return arrayobj
         */
        public function findProjectDataAndProjectInfoByUsrId($rvsUsrId = null, $fetchMode = 'getassoc')
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
            $query = sprintf('
				SELECT
                       project_id
                        , rvs_usr_id
                        , project_name
                        , last_update
				FROM
                        %s as a
                         , %s as b
				WHERE
                           rvs_usr_id = %s
                           AND a.project_info_id = b.project_info_id
				ORDER BY
                           project_name
                '
                 , $this->aConf['table']['rvs_project']
                 , $this->aConf['table']['rvs_project_info']
                 , RvsLibs_String::quoteSmart($rvsUsrId)
            );
            $oProject->query($query);
           $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
        }

        /**
         * Find ProjectAll Data By ProjectName And UserID
         *
         * @param string $projectname
         * @param string $userID
         * @param string $fetchMode
         * @param string $aResultFields
         */
        public function findProjectAllDataByProjectNameAndUserID($projectname = null, $userID = null, $fetchMode = 'getassoc', $aResultFields=array())
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
             $query = sprintf('
                SELECT
                    *
                FROM
                    %s
                WHERE
                    project_name = %s
                    AND rvs_usr_id = %s
                '
                , $this->aConf['table']['rvs_project']
                , RvsLibs_String::quoteSmart($projectname)
                , RvsLibs_String::quoteSmart($userID)
             );
             $oProject->query($query);
             $aCloneData = array();
             while ($oProject->fetch()) {
                 $aCloneData[] = clone($oProject);
             }
              $_aResultFields = DbWrapper::buildResultFields($oProject, $aResultFields);
             DB_DataObject::debugLevel();
             return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
        }
 /**
     * find ProjectId By PageData And UsrId from rvs_project_page and rvs_project_layout_page table
     *
     * @author Pornthip Phothong
     * @param  string $pageData
     * @param  string $usrId
     * @param  string $fetchMode
     /* $query = "
                        SELECT DISTINCT
                                    lp.project_id
                        FROM
                                     {$this->conf['table']['rvs_project_page']} pp
                                     , {$this->conf['table']['rvs_project_layout_page']} lp
                        WHERE
                                    pp.page_data LIKE '%$projectPageId%'
                                    AND rvs_usr_id = '$rvs_usr_id'
                                    AND pp.project_page_id = lp.project_page_id
                    ";

        $res = $this->dbh->getAll($query, DB_FETCHMODE_ASSOC);
       */
     public function findProjectIdByPageDataAndUsrId($pageData=null, $usrId=null, $fetchMode = 'getassoc')
     {
         //Fix loop in log
         //SGL::logMessage(null, PEAR_LOG_DEBUG);
         $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_page']);
         if (!is_null($usrId)) {
         $query = sprintf('
                        SELECT DISTINCT
                                    lp.project_id
                        FROM
                                     %s as pp
                                     , %s as lp
                        WHERE
                                    pp.page_data LIKE  %s
                                    AND rvs_usr_id = %s
                                    AND pp.project_page_id = lp.project_page_id
                    '
                    , $this->aConf['table']['rvs_project_page']
                    , $this->aConf['table']['rvs_project_layout_page']
                    , RvsLibs_String::quoteSmart('%' . $pageData . '%')
                    , RvsLibs_String::quoteSmart($usrId)
                    );
              $oProject->query($query);
     }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
     }

     /**
      * find ProjectId And ProjectInfoId By ProjectId from rvs_project and rvs_project_info
      * Resulting SQL
      *		SELECT
      * 		p.project_id
      * 		, p.project_info_id
      * 	FROM
      * 		rvs_project p
      * 		, rvs_project_info i
      * 	WHERE
      * 		p.project_id = {$projectId}
      * 		AND i.project_info_id = p.project_info_id
      * res = $this->dbh->getRow($query,DB_FETCHMODE_ASSOC);
      *
      * @author Pornthip Phothong
      * @param <string> $projectId
      * @param <string> $fetchMode
      * @return <array>
      * form file CreatePrljectMgr.php
      */
     public function findProjectIdAndProjectInfoIdByProjectId($projectId=null, $fetchMode = 'getassoc')
     {
         SGL::logMessage(null, PEAR_LOG_DEBUG);
         $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
         if (!is_null($projectId)) {
         $query = sprintf('
                                SELECT
                                            p.project_id
                                            , p.project_info_id
                                FROM
                                            %s as p
                                            , %s as i
                                WHERE
                                            p.project_id = %s
                                            AND i.project_info_id = p.project_info_id
                                '
                                , $this->aConf['table']['rvs_project']
                                , $this->aConf['table']['rvs_project_info']
                                , RvsLibs_String::quoteSmart($projectId)
                                );
              $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
     }

 /**
      * Find ProjectInfoData By ProjectId And ProjectInfoId
      *
      *  Resulting SQL
      * 		SELECT
      * 			 i.project_keyword
      * 			 , i.project_description
      * 			 , i.project_info_id
      * 	 	FROM
      * 			 rvs_project p
      * 			 , rvs_project_info  i
      * 		 WHERE
      * 				p.project_id ={$projectId}
      * 				AND i.project_info_id = p.project_info_id
      * 		ORDER BY
      * 				p.project_info_id
      *
      * @author duangdao.k
      * @param string $projectId
      * @param string $fetchMode
      * @return array
      */
     public function findProjectInfoDataByProjectIdAndProjectInfoId($projectId = null, $fetchMode = 'getassoc')
     {
         SGL::logMessage(null, PEAR_LOG_DEBUG);
         $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
         if (!is_null($projectId)) {
              $query =sprintf('
              		SELECT
                         i.project_keyword
                         , i.project_description
                          , i.project_info_id
                      FROM
                           %s p
                            , %s i
                      WHERE
                             p.project_id = %s
                             AND i.project_info_id = p.project_info_id
                      ORDER BY
                            p.project_info_id
                      '
                      , $this->aConf['table']['rvs_project']
                      , $this->aConf['table']['rvs_project_info']
                      , RvsLibs_String::quoteSmart($projectId)
                   );
                    $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
     }

     public function findPageStructureDataByProjectIdAndUsrId($projectId, $rvsUsrId, $mainPage, $fetchMode = 'getassoc')
     {
         SGL::logMessage(null, PEAR_LOG_DEBUG);
         $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
         if (!is_null($projectId) && !is_null($rvsUsrId) && !is_null($mainPage)) {
         $query = sprintf('
                                SELECT
                                            lp.project_page_id
                                            , lp.parent_project_page_id
                                            , lp.priority
                                            , pp.set_draft
                                            , pp.page_name
                                            , pp.custom_page_name
                                            , pp.rvs_component_id
                                            , pp.rvs_link_id
                                            , pp.target
                                            , pp.link_active
                                FROM
                                            %s  p
                                            , %s pf
                                            , %s  lp
                                            , %s  pp
                                WHERE
                                            p.project_id = lp.project_id
                                            AND lp.project_page_id = pp.project_page_id
                             				AND p.project_info_id = pf.project_info_id
                                            AND lp.project_id = %s
                                            AND pp.rvs_usr_id =   %s
                                            %s
                                ORDER BY
                             				lp.priority
                                            '
                                            , $this->aConf['table']['rvs_project']
                                            , $this->aConf['table']['rvs_project_info']
                                            , $this->aConf['table']['rvs_project_layout_page']
                                            , $this->aConf['table']['rvs_project_page']
                                            , RvsLibs_String::quoteSmart($projectId)
                                            , RvsLibs_String::quoteSmart($rvsUsrId)
                                            , ($mainPage == 1) ? " AND lp.parent_project_page_id = '0'"
                                            				: " AND lp.parent_project_page_id != '0'"
                                            );
               $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
     }

 /**
      * find ProjectName By ProjectName And  UsrId from rvs_project table
      * Resulting SQL
      * SELECT
      *       project_name
      *  FROM
      *       rvs_project
      *  WHERE
      *       project_name = {$projectName}
      *  if ({$action}== 'edit' && {$projectId} {
      *      $query .= "      AND project_id != {$projectId}
      *  }
      *  $query .= "         AND rvs_usr_id = {$usrId}
      *
      * @author Pornthip Phothong
      * @param <string> $projectName
      * @param <string> $action
      * @param <string> $projectId
      * @param <string> $usrId
      * @param <string> $fetchMode
      * @return array obj
      * @from CreateProjectMgr.php
      */

     public function findProjectNameByProjectNameAndUsrId($projectName=null, $action=null, $projectId=null, $usrId=null, $fetchMode = 'getassoc')
     {
         SGL::logMessage(null, PEAR_LOG_DEBUG);
         $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
         if (!is_null($projectId)) {
         $query = sprintf('
                        SELECT
                                    project_name
                        FROM
                                   %s
                        WHERE
                                    project_name = %s
                                    %s
                       				AND rvs_usr_id = %s
                       				'
           , $this->aConf['table']['rvs_project']
           , RvsLibs_String::quoteSmart($projectName)
           , ($action == 'edit' && $projectId)? sprintf('AND project_id != %s', RvsLibs_String::quoteSmart($projectId)) : ''
           , RvsLibs_String::quoteSmart($usrId)
           );
           $oProject->query($query);
            }
            $aCloneData = array();
            while ($oProject->fetch()) {
                $aCloneData[] = clone($oProject);
            }
            DB_DataObject::debugLevel();
            return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
     }

    function findProjectByProjectId($projectId, $fetchMode = 'getassoc')
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $oProject->project_id = $projectId;
        $oProject->find();
        $aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[] = clone($oProject);
		}
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    function findProjectInfoByProjectInfoId($projectInfoId, $fetchMode = 'getassoc')
    {
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $oProjectInfo->project_info_id = $projectInfoId;
        $oProjectInfo->find();
        $aCloneData = array();
        while ($oProjectInfo->fetch()) {
            $aCloneData[] = clone($oProjectInfo);
        }
        return DbWrapper::fetchDatas($oProjectInfo->_resultFields, $aCloneData, $fetchMode);
    }

    public function findProjectMetatagByProjectInfoId($projectInfoId = null, $fetchMode = 'getassoc', $aResultFields = array())
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfoMetatag = DB_DataObject::factory($this->aConf['table']['rvs_project_info_metatag']);
        /*
        $oProjectInfoMetatag->selectAdd();
        $oProjectInfoMetatag->selectAdd('project_info_metatag_id');

        $oProjectInfoMetatag->rvs_project_info_id = $projectInfoId;
        $oProjectInfoMetatag->find();
        */
        if (!is_null($projectInfoId)) {
        $query = sprintf('
        				SELECT
        					*
        				FROM
        					%s
        				WHERE
        					rvs_project_info_id = %s
        				'
                        , $this->aConf['table']['rvs_project_info_metatag']
                        , RvsLibs_String::quoteSmart($projectInfoId)
                        );
        $oProjectInfoMetatag->query($query);
        }
        $aCloneData = array();
        while ($oProjectInfoMetatag->fetch()) {
            $aCloneData[] = clone($oProjectInfoMetatag);
        }
        $_aResultFields = DbWrapper::buildResultFields($oProjectInfoMetatag, $aResultFields);
        return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
    }

    public function findProjectMetatagByProjectInfoMetatagId($projectInfoMetatagId = null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfoMetatag = DB_DataObject::factory($this->aConf['table']['rvs_project_info_metatag']);
        /*
        $oProjectInfoMetatag->project_info_metatag_id = $projectInfoMetatagId;
        $oProjectInfoMetatag->find();
        */
        if (!is_null($projectInfoMetatagId)) {
             $query = sprintf('
        				SELECT
        					*
        				FROM
        					%s
        				WHERE
        					project_info_metatag_id = %s
        				'
                        , $this->aConf['table']['rvs_project_info_metatag']
                        , RvsLibs_String::quoteSmart($projectInfoMetatagId)
                        );
        $oProjectInfoMetatag->query($query);
        }
        $aCloneData = array();
        while ($oProjectInfoMetatag->fetch()) {
            $aCloneData[] = clone($oProjectInfoMetatag);
        }
        return DbWrapper::fetchDatas($oProjectInfoMetatag->_resultFields, $aCloneData, $fetchMode);
    }

    public function findCustomMetatagByCustomMetatagId($customMetatagId = null, $fetchMode = 'getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oCustomMetatag = DB_DataObject::factory($this->aConf['table']['rvs_custom_metatag']);
        /*
        $oProjectInfoMetatag->rvs_custom_metatag_id = $customMetatagId;
        $oProjectInfoMetatag->find();
        */
        if (!is_null($customMetatagId)) {
        $query = sprintf('
        				SELECT
        					*
        				FROM
        					%s
        				WHERE
        					rvs_custom_metatag_id = %s
        				'
                        , $this->aConf['table']['rvs_custom_metatag']
                        , RvsLibs_String::quoteSmart($customMetatagId)
                        );
        $oCustomMetatag->query($query);
        }
        $aCloneData = array();

        while ($oCustomMetatag->fetch()) {
            $aCloneData[] = clone($oCustomMetatag);
        }
        return DbWrapper::fetchDatas($oCustomMetatag->_resultFields, $aCloneData, $fetchMode);
    }

    public function findProjectInfoIdByProjectId($projectId = null, $fetchMode = 'getassoc')
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $oProject->selectAdd();
        $oProject->selectAdd('project_info_id');
        if (!is_null($projectId)) {
        $oProject->project_id = $projectId;
        }
        $oProject->find();
        $aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[] = clone($oProject);
		}
		return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Select rvs_head (by project,by project page)
     * @author darawan
     * @param string $projectId
     * @param string $projectPageId
     * @return bool
     */
    public function findRvsHead($projectId, $projectPageId=null, $fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oRvsHead = DB_DataObject::factory($this->aConf['table']['rvs_head']);
        if (!is_null($projectId)) {
            $query = sprintf('
                SELECT
                    *
                FROM
                    %s
                WHERE
                    project_id = %s
                    %s
                '
                , $this->aConf['table']['rvs_head']
                , RvsLibs_String::quoteSmart($projectId)
                , ($projectPageId != null) ? ' AND project_page_id=' . RvsLibs_String::quoteSmart($projectPageId) : ''
            );
            $oRvsHead->query($query);
        }
        $aCloneData = array();
        while ($oRvsHead->fetch()) {
            $aCloneData[] = clone($oRvsHead);
        }
        return DbWrapper::fetchDatas($oRvsHead->_resultFields, $aCloneData, $fetchMode);
    }

    public function findRvsHeadByProjectId($projectId = null, $fetchMode='getassoc')
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel(0);
    	$oRvsHead = DB_DataObject::factory($this->aConf['table']['rvs_head']);
    	if (!is_null($projectId)) {
    		$query = sprintf('
                SELECT
                    *
                FROM
                    %s
                WHERE
                    project_id = %s
                '
                , $this->aConf['table']['rvs_head']
                , RvsLibs_String::quoteSmart($projectId)
                );
                $oRvsHead->query($query);
    	}
    	$aCloneData = array();
    	while ($oRvsHead->fetch()) {
    		$aCloneData[] = clone($oRvsHead);
    	}
    	return DbWrapper::fetchDatas($oRvsHead->_resultFields, $aCloneData, $fetchMode);
    }

	/**
	 * find Is MemberPage By ProjectInfoId
	 * @param string $projectInfoId
	 * @param string $isMember
	 * @param  $fetchMode
	 * @author duangdao.k
	 * @return unknown_type
	 */
    public function findIsMemberPageByProjectInfoId($projectInfoId = null, $isMember = 0, $fetchMode='getassoc')
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                SELECT
                    *
                FROM
                    %s
                WHERE
                    project_info_id = %s
                    AND is_member_page = %s
                '
                , $this->aConf['table']['rvs_project_info']
                , RvsLibs_String::quoteSmart($projectInfoId)
                , RvsLibs_String::quoteSmart($isMember)
               );
        $oProjectInfo->query($query);
        $aCloneData = array();
        while ($oProjectInfo->fetch()) {
            $aCloneData[] = clone($oProjectInfo);
        }
        return DbWrapper::fetchDatas($oProjectInfo->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Update rvs_css (by project,by project page
     * @author darawan
     * @param string $projectId
     * @param string $projectPageId
     * @param string $data
     * @return bool
     */
    public function findRvsCss($projectId, $projectPageId=null, $fetchMode='getassoc')
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel(0);
    	$oRvsCss = DB_DataObject::factory($this->aConf['table']['rvs_css']);
    	if (!is_null($projectId)) {
    		$query = sprintf('
                    SELECT
                        *
                    FROM
                        %s
                    WHERE
                        project_id = %s
                        %s
                    '
                    , $this->aConf['table']['rvs_css']
                    , RvsLibs_String::quoteSmart($projectId)
                    , (is_null($projectPageId) == false)
                    	? 'AND project_page_id = ' . RvsLibs_String::quoteSmart($projectPageId)
                    	: ''
                    );
            $oRvsCss->query($query);
    	}
    	$aCloneData = array();
    	while ($oRvsCss->fetch()) {
    		$aCloneData[] = clone($oRvsCss);
    	}
    	return DbWrapper::fetchDatas($oRvsCss->_resultFields, $aCloneData, $fetchMode);
    }

    /**
     * Find pathway By ProjectID
     *
     * Resulting SQL
     * 		 SELECT
     * 				 i.i_pathway
     * 		 FROM
     * 				 rvs_project p
     * 				 , rvs_project_info i
     * 		 WHERE
     * 				 p.project_id ={$projectID}
     * 				 AND i.project_info_id = p.project_info_id
     *
     * @author darawan
     * @param string $projectID
     * @param string $fetchMode
     * @return string
     */
    public function findPathwayByProjectID($projectID = null, $fetchMode='getrow')
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
    	if (!is_null($projectID)) {
    		$query = sprintf('
                        SELECT
                                    i.i_pathway
                        FROM
                                    %s p
                                    , %s i
                        WHERE
                                    p.project_id = %s
                                    AND i.project_info_id = p.project_info_id
                    '
                    , $this->aConf['table']['rvs_project']
                    , $this->aConf['table']['rvs_project_info']
                    , RvsLibs_String::quoteSmart($projectID)
                    );
                    $oProject->query($query);
    	}
    	$aCloneData = array();
    	while ($oProject->fetch()) {
    		$aCloneData[] = clone($oProject);
    	}
    	DB_DataObject::debugLevel();
    	return DbWrapper::fetchDatas($oProject->_resultFields, $aCloneData, $fetchMode);
    }
        //--------------------------------------------- Insert ---------------------------------------------------------------//

        /**
         * Insert ProjectData By ProjectId And ProjectInfoId And UserId And ProjectName
         *
         *  Resulting SQL
         * 		 INSERT INTO
         * 				rvs_project
         * 				 (
         * 					 project_id
         * 					 , project_info_id
         * 					 , rvs_usr_id
         * 					 , project_name
         * 				  )
         * 		VALUES
         * 				 (
         * 					 {$projectId}
         * 					  , {$projectInfoId}
         * 					  , {$userId}
         * 				      , {$projectName}
         * 				 )
         *
         * @author duangdao.k
         * @param string $projectId
         * @param string $projectInfoId
         * @param string $userId
         * @param string $projectName
         * @return bool
         */
        public function InsertProjectDataByProjectIdAndProjectInfoIdAndUserIdAndProjectName($projectId, $projectInfoId, $userId, $projectName, $utf8Format)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            DB_DataObject::debugLevel(0);
            $oProject =  DB_DataObject::factory($this->aConf['table']['rvs_project']);
             $query = sprintf("
                    INSERT INTO
                        %s
                        (
                            project_id
                            , project_info_id
                            , rvs_usr_id
                            , project_name
                            , utf8format
                        )
                    VALUES
                        (
                            %s
                            , %s
                            , %s
                            , %s
                            , %s
                        )
                    "
                    , $this->aConf['table']['rvs_project']
                    , RvsLibs_String::quoteSmart($projectId)
                    , RvsLibs_String::quoteSmart($projectInfoId)
                    , RvsLibs_String::quoteSmart($userId)
                    , RvsLibs_String::quoteSmart($projectName)
                    , RvsLibs_String::quoteSmart($utf8Format)
                );
                $res = $oProject->query($query);
                DB_DataObject::debugLevel();
                return (isset($res) && $res) ? true : false;
        }

        /**
         * Insert data table rvs_body_attribute_xref
         * @author duangdao.k
         * @param string $projectId
         * @param string $projectPageId
         * @param string $attId
         * @return bool
         */
        public function InsertDataBodyAttributeXref($projectId, $projectPageId, $attId)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            DB_DataObject::debugLevel(0);
            $oBodyAttAref =  DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
            $query = sprintf("
                    INSERT INTO
                        %s
                        (
                            project_id
                            , project_page_id
                            , att_id
                        )
                    VALUES
                        (
                            %s
                            , %s
                            , %s
                        )
                    "
                    , $this->aConf['table']['rvs_body_attribute_xref']
                    , RvsLibs_String::quoteSmart($projectId)
                    , RvsLibs_String::quoteSmart($projectPageId)
                    , RvsLibs_String::quoteSmart($attId)
                );
                $res = $oBodyAttAref->query($query);
                DB_DataObject::debugLevel();
                return (isset($res) && $res) ? true : false;
        }

        /**
         * Insert data table rvs_body_attribute
         * @author duangdao.k
         * @param string $attId
         * @param string $attName
         * @param string $attValue
         * @return bool
         */
        public function InsertDataBodyAttribute($attId, $attName, $attValue)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            DB_DataObject::debugLevel(0);
            $oBodyAttAref =  DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
            $query = sprintf("
                    INSERT INTO
                        %s
                        (
                            att_id
                            , att_name
                            , att_value
                        )
                    VALUES
                        (
                            %s
                            , %s
                            , %s
                        )
                    "
                    , $this->aConf['table']['rvs_body_attribute']
                    , RvsLibs_String::quoteSmart($attId)
                    , RvsLibs_String::quoteSmart($attName)
                    , RvsLibs_String::quoteSmart($attValue)
                );
                $res = $oBodyAttAref->query($query);
                DB_DataObject::debugLevel();
                return (isset($res) && $res) ? true : false;
        }

        /**
         * insert  Data from table rvs_project_info
         *
         * ///OPTIMIZE VARIABLE PASSING
         *
         * @param <Array> $aParamsInsertProject
         *                                                                    - 'projectInfoId' => project info id,
         *                                                                    - 'charset' => charset,
         *                                                                    - 'company' => company,
         *                                                                    - 'slogan' => slogan,
         *                                                                    - 'logoName' => logo name,
         *                                                                    - 'title' => title,
         *                                                                    - 'keyword' => keyword,
         *                                                                    - 'description' => description,
         *                                                                    - 'domain' => domain,
         *                                                                    - 'lastUpdate' => time last update
         * @return bool
         *
         */
        public function insertProjectInfoData($aParamsInsertProject)
        {
            SGL::logMessage(null, PEAR_LOG_DEBUG);
            DB_DataObject::debugLevel(0);
            $oProjectInFo =  DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
            $query = sprintf("
                INSERT INTO
                    %s
                    (
                        project_info_id
                        , charset_id
                        , project_company
                        , project_slogan
                        , project_logo
                        , project_title
                        , project_keyword
                        , project_description
                        , project_domain
                        , last_update
                        , check_step
                        , template_item_id
                    )
                VALUES
                    (
                        %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                        , %s
                    )
                "
                , $this->aConf['table']['rvs_project_info']
                , RvsLibs_String::quoteSmart($aParamsInsertProject['projectInfoId'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['charset'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['company'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['slogan'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['logoName'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['title'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['keyword'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['description'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['domain'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['lastUpdate'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['check_step'])
                , RvsLibs_String::quoteSmart($aParamsInsertProject['template_item_id'])
            );
            $res = $oProjectInFo->query($query);
            DB_DataObject::debugLevel();
            return $res;
        }

        /**
         * insert table rvs_custom_layer step 2 Header
         * @author nipaporn
         * @param unknown_type $layerId
         * @param unknown_type $rvsProjectId
         * @param unknown_type $layerdata
         * @param unknown_type $isImg
         * @param unknown_type $headerUrlLink
         * @param unknown_type $headerUrlTarget
         * @return unknown_type
         */
        public function insertCustomlayer($layerId, $rvsProjectId,$layerdata,$isImg, $headerUrlLink, $headerUrlTarget)
        {
        	SGL::logMessage(null, PEAR_LOG_DEBUG);
        	DB_DataObject::debugLevel(0);
        	$aLayerText =  DB_DataObject::factory($this->aConf['table']['rvs_custom_layer']);
        	$query = sprintf('
                        INSERT INTO
                                   %s
                                       ( layer_id
                                         , rvs_project_id
                                         , layer_data
                                         , is_image
                                         , layer_url
                                         , layer_target
                                          )
                        VALUES (
                                             %s
                                           , %s
                                           , %s
                                           , %s
                                           , %s
                                           , %s
                                           );

                    '
                    , $this->aConf['table']['rvs_custom_layer']
                    , RvsLibs_String::quoteSmart($layerId)
                    , RvsLibs_String::quoteSmart($rvsProjectId)
                    , RvsLibs_String::quoteSmart($layerdata)
                    , RvsLibs_String::quoteSmart($isImg)
                    , RvsLibs_String::quoteSmart($headerUrlLink)
                    , RvsLibs_String::quoteSmart($headerUrlTarget)
                    );
                    //SGL::logMessage('====>>>>add' . $query, PEAR_LOG_DEBUG);
                    $aLayerText->query($query);
    }
    /**
    * Insert rvs_head (by project,by project page
    * @author darawan
    * @param string $projectId
    * @param string $projectPageId
    * @param string $data
    * @return bool
    */
    public function insertRvsHead($projectId, $projectPageId, $data)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oRvsHead =  DB_DataObject::factory($this->aConf['table']['rvs_head']);
        $query = sprintf('
            INSERT INTO
                %s
            (
                project_id
                , project_page_id
                , head_tag_data
            )
            VALUES
            (
                %s
                , %s
                , %s
            )
            '
            , $this->aConf['table']['rvs_head']
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($projectPageId)
            , RvsLibs_String::quoteSmart($data)
            );
        $res = $oRvsHead->query($query);
        DB_DataObject::debugLevel();
        return (isset($res) && $res) ? true : false;
    }

    /**
    * Insert rvs_css (by project,by project page
    * @author darawan
    * @param string $projectId
    * @param string $projectPageId
    * @param string $data
    * @return bool
    */
    public function insertRvsCss($projectId, $projectPageId, $data)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oRvsCss =  DB_DataObject::factory($this->aConf['table']['rvs_css']);
        $query = sprintf('
            INSERT INTO
                %s
            (
                project_id
                , project_page_id
                , css_tag_data
            )
            VALUES
            (
                %s
                , %s
                , %s
            )
            '
            , $this->aConf['table']['rvs_css']
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($projectPageId)
            , RvsLibs_String::quoteSmart($data)
            );
        $res = $oRvsCss->query($query);
        DB_DataObject::debugLevel();
        return (isset($res) && $res) ? true : false;
    }
    //--------------------------Update---------------------------//

	/**
     * Modify last update project in database
     * @access public
     * @author Parinya Chatpetch
     * @param string $projectID
     * @param string $updatetime
     *
     * @return boolean
     */
    public function updateLastUpdateTimeByProjectID($projectID=null, $updateTime=null, $projectInfoId=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
		$oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
		$oProject->joinAdd($oProjectInfo);
		if (!is_null($projectID) && !is_null($updateTime)) {
			$oProject->get('project_id', $projectID);
			$projectInfoId = (!is_null($projectInfoId)) ? $projectInfoId : $oProject->project_info_id;
			$oProjectInfo->get('project_info_id', $projectInfoId);
			$oProjectInfo->last_update = $updateTime;
			$oProject->update();
			$oProjectInfo->update();
		}
		return 0;
    }
/**
     * Modify last update project in database
     * @access public
     * @author Parinya Chatpetch
     * @param string $projectID
     * @param string $updatetime
     *
     * @return boolean
     */
    public function updateProjectNameByProjectID($projectID=null, $projectName=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        if (!is_null($projectID) && !is_null($projectName)) {
            $oProject->get('project_id', $projectID);
            $oProject->project_name = $projectName;
            $oProject->update();
        }
        return 0;
    }
    /**
     * Update newNavigatorId and navigatorNameId from table rvs_project_info and rvs_project by project_info_id, project_id and rvs_usr_id
     *
     * Resulting SQ
     * 		UPDATE
     * 			rvs_project_info as pi
     * 			, rvs_project as pp
     * 		SET
     * 			pi.navigator_id = {$newNavigatorId}
     * 			, pi.navigator_name_id = {$navigatorNameId}
     * 		 WHERE
     * 			pp.project_info_id = pi.project_info_id
     * 			AND pp.project_id = {$projectId}
     * 			AND pp.rvs_usr_id = {$rvsUsrId}
     *
     * @author duangdao.k
     * @param string $newNavigatorId
     * @param string $navigatorNameId
     * @param string $projectId
     * @param string $rvsUsrId
     * @return bool
     */
    public function updateNavigatorDataByProjectIdAndUsrId($newNavigatorId = null, $navigatorNameId = null, $projectId = null, $rvsUsrId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
       $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
       $query = sprintf('
			UPDATE
                %s as pi
                , %s as pp
			SET
                pi.navigator_id = %s
                , pi.navigator_name_id = %s
			WHERE
                pp.project_info_id = pi.project_info_id
                AND pp.project_id = %s
                AND pp.rvs_usr_id = %s
            '
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($newNavigatorId)
            , RvsLibs_String::quoteSmart($navigatorNameId)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($rvsUsrId)
        );
        $res = $oProject->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

    /**
     * Update rvs_project_info specific = 999
     *
     * @param $projectId
     * @param $usrId
     * @param $navigatorName
     */
    public function updateNavigatorDataSpicific($projectId = null, $usrId = null, $navigatorName=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
            UPDATE
                  %s as pi
                   , %s as  pp
             SET
                   pi.navigator_name_id = %s
             WHERE
                   pi.project_info_id = pp.project_info_id
                   AND pp.project_id = %s
                   AND pp.rvs_usr_id = %s
             '
             , $this->aConf['table']['rvs_project_info']
             , $this->aConf['table']['rvs_project']
             , RvsLibs_String::quoteSmart($navigatorName)
             , RvsLibs_String::quoteSmart($projectId)
             , RvsLibs_String::quoteSmart($usrId)
        );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

    /**
     * Update project check step by project info id
     *
     * Resulting SQL
     *      UPDATE
     *           rvs_project_info as pi
     *           ,rvs_project as pp
     *       SET
     *           check_step = {$step}
     *       WHERE
     *           pp.project_id = {$projectId}
     *           AND pi.project_info_id = {$projectInfoId}
     *           AND pp.rvs_usr_id = {$usrId}
     *           AND pi.project_info_id = pp.project_info_id
     *
     * @param string $step
     * @param string $projectId
     * @param string $projectInfoId
     * @param string $usrId
     * @author Parinya Chaipetch
     * @access public
     * @return bool
     */
    public function updateProjectCheckStepByProjectInfoId($step, $projectId = null, $projectInfoId = null ,$usrId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
            UPDATE
                %s as pi
                ,%s as pp
            SET
                check_step = %s
            WHERE
                pp.project_id = %s
                AND pi.project_info_id = %s
                AND pp.rvs_usr_id = %s
                AND pi.project_info_id = pp.project_info_id
            '
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , $step
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($projectInfoId)
            , RvsLibs_String::quoteSmart($usrId)
        );
        $res = $oProject->query($query);
        DB_DataObject::debugLevel();
        return true;
    }

    /**
     * Update table rvs_project_info and rvs_project set project_keyword and project_description where project_id, rvs_usr_id and project_info_id
     *
     * Resulting SQL
     * 		UPDATE
     * 			rvs_project_info as i
     * 			 , rvs_project as p
     * 		SET
     * 			 i.project_keyword = {$projectKeyword}
     * 			, i.project_description = {$projectDescription}
     * 		WHERE
     * 			p.project_id = {$projectId}
     * 			AND p.rvs_usr_id ={$usrId}
     * 			AND i.project_info_id = p.project_info_id
     *
     *  @author duangdao.k
     * @param string $projectKeyword
     * @param string $projectDescription
     * @param string $projectId
     * @param string $usrId
     * @return bool
     */
    public function updateProjectKeywordAndProjectDescription($projectKeyword = null, $projectDescription = null, $projectId = null, $usrId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
               UPDATE
                       %s as i
                      , %s as p
                SET
                      i.project_keyword = %s
                      , i.project_description = %s
                WHERE
                       p.project_id = %s
                       AND p.rvs_usr_id = %s
                       AND i.project_info_id = p.project_info_id
                  '
                  , $this->aConf['table']['rvs_project_info']
                  , $this->aConf['table']['rvs_project']
                  , RvsLibs_String::quoteSmart($projectKeyword)
                  , RvsLibs_String::quoteSmart($projectDescription)
                  , RvsLibs_String::quoteSmart($projectId)
                  , RvsLibs_String::quoteSmart($usrId)
          );
        $res = $oProject->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

     /**
     * Update effect_site_enter and duration_site_enter by project_info_id, project_id, rvs_usr_id and project_info_id
     *
     * Resulting SQL
     *     	  UPDATE
     * 				rvs_project_info as pi
     * 				,rvs_project as  pp
     * 			SET
     * 				pi.effect_site_enter ={$effectSiteEnter}
     * 				 , pi.duration_site_enter = {$durationSiteEnter}
     * 			WHERE
     * 				 pi.project_info_id = pp.project_info_id
     * 				AND pp.project_id = {$projectId}
     * 				AND pp.rvs_usr_id = {$usrId}
     * 				AND pi.project_info_id = {$projectInfoId}
     *
     * @author duangdao.k
     * @param string $effectSiteEnter
     * @param string $durationSiteEnter
     * @param string $projectId
     * @param string $usrId
     * @param string $projectInfoId
     * @return bool
     */
    public function updateEffectSiteEnterAndDurationSiteEnterByProjectId($effectSiteEnter = null, $durationSiteEnter = null, $projectId = null, $usrId = null, $projectInfoId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
            UPDATE
                  %s as pi
                   , %s as  pp
             SET
                   pi.effect_site_enter = %s
                   , pi.duration_site_enter = %s
             WHERE
                   pi.project_info_id = pp.project_info_id
                   AND pp.project_id = %s
                   AND pp.rvs_usr_id = %s
                   AND pi.project_info_id = %s
             '
             , $this->aConf['table']['rvs_project_info']
             , $this->aConf['table']['rvs_project']
             , $effectSiteEnter
             , $durationSiteEnter
             , RvsLibs_String::quoteSmart($projectId)
             , RvsLibs_String::quoteSmart($usrId)
             , RvsLibs_String::quoteSmart($projectInfoId)
        );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

    /**
     * Update Icon ProjectInfo By ProjectInfoId And ProjectId And UsrId
     *
     * Resulting SQL
     * UPDATE
     * 		rvs_project_info as pi
     * 		rvs_project as pp
     * SET
     * 		pa.i_favorite = {$iconFavorite} *** (isset($iconFavorite) && $iconFavorite) ? $iconFavorite : 0
     * 		, pa.i_print = {$iconPrint} *** (isset($iconPrint) && $iconPrint) ? $iconPrint : 0
     * 		, pa.i_mail = {$iconMail} *** (isset($iconMail) && $iconMail) ? $iconMail : 0
     * 		, pa.i_pathway = {$iconPathway} ***(isset($iconPathway) && $iconPathway) ? $iconPathway : 0
     * WHERE
     * 		pa.rvs_usr_id = {$projectInFoId}
     * 		AND pp.project_id ={$projectId}
     * 		AND pa.project_page_id ={$usrId}
     *
     * @author duangdao.k
     * @param string $iconFavorite
     * @param string $iconPrint
     * @param string $iconMail
     * @param string $iconPathway
     * @param string $projectInFoId
     * @param string $projectId
     * @param string $usrId
     * @return obj
     */
    public function updateIconProjectInfoByProjectInfoIdAndProjectIdAndUsrId($iconFavorite, $iconPrint, $iconMail, $iconPathway, $projectInFoId, $projectId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
			UPDATE
					%s as pi
					, %s as pp
             SET
					pi.i_favorite = %s
					, pi.i_print =  %s
					, pi.i_mail = %s
					, pi.i_pathway = %s
			WHERE
					 pi.project_info_id = %s
					 AND pp.project_id = %s
					 AND pp.rvs_usr_id = %s
            '
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , (isset($iconFavorite) && $iconFavorite) ? $iconFavorite : 0
            , (isset($iconPrint) && $iconPrint) ? $iconPrint : 0
            , (isset($iconMail) && $iconMail) ? $iconMail : 0
             , (isset($iconPathway) && $iconPathway) ? $iconPathway : 0
             , RvsLibs_String::quoteSmart($projectInFoId)
             , RvsLibs_String::quoteSmart($projectId)
             , RvsLibs_String::quoteSmart($usrId)
         );
         $res = $oProjectInfo->query($query);
         DB_DataObject::debugLevel();
         return $res;
    }

    /**
     * update rvs_project_info rvs_project and  By $projectId And $usrId  and $projectInfoId
     *
     * Resulting SQL
     *  		UPDATE
     * 				rvs_project_info as pi
     * 				, rvs_project' as p
     * 			SET
     * 				 pi.template_item_id = '$input->template_item_id'
     * 				, pi.rvs_category_id = '$input->category_id'
     * 				, pi.navigator_id = '$input->navigator_id'
     * 			   ";
     * 			 if ({$checkStep} > 2) {
     * 					 $query .= " , pi.check_step = {$checkStep} ";
     * 				 } else {
     * 					 $query .= " , pi.check_step = '2' ";
     * 				 }
     * 			  if ( isset({$navigatorNameId}) ) {
     * 					$query .= " , pi.navigator_name_id = {$navigatorNameId} ";
     * 				 }
     * $query .= " WHERE
     * 				 pi.project_info_id = p.project_info_id
     * 				 AND p.project_id = {$projectId}
     * 				 AND p.rvs_usr_id = {$usrId}
     * 				  AND pi.project_info_id = {$projectInfoId}
     *
     * @author duangdao.k
     * @param string $templateItemId
     * @param string $categoryId
     * @param string $navigatorId
     * @param string $checkStep
     * @param string $navigatorNameId
     * @param string $projectId
     * @param string $usrId
     * @param string $projectInfoId
     * @return object
     */
    public function updateProjectInfoDataByTemplateItemIdAndCategoryId($templateItemId, $categoryId, $navigatorId, $checkStep, $navigatorNameId, $projectId, $usrId, $projectInfoId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
			UPDATE
				%s as pi
				 , %s as p
			SET
				pi.template_item_id = %s
				, pi.rvs_category_id = %s
				, pi.navigator_id = %s
                 %s
                 %s
			 WHERE
				 pi.project_info_id = p.project_info_id
				 AND p.project_id = %s
				 AND p.rvs_usr_id = %s
				 AND pi.project_info_id = %s
           '
           , $this->aConf['table']['rvs_project_info']
           , $this->aConf['table']['rvs_project']
           , RvsLibs_String::quoteSmart($templateItemId)
           , RvsLibs_String::quoteSmart($categoryId)
           , RvsLibs_String::quoteSmart($navigatorId)
           , ($checkStep > 2) ? sprintf(', pi.check_step = %s', RvsLibs_String::quoteSmart($checkStep)) : ", pi.check_step = '2'"
           , (isset($navigatorNameId) && $navigatorNameId) ? sprintf(', pi.navigator_name_id = %s', RvsLibs_String::quoteSmart($navigatorNameId)) : ''
           , RvsLibs_String::quoteSmart($projectId)
           , RvsLibs_String::quoteSmart($usrId)
           , RvsLibs_String::quoteSmart($projectInfoId)
           );
           $res = $oProjectInfo->query($query);
           DB_DataObject::debugLevel();
           return $res;
    }

    public function updateProjectTitleKeywordDescriptionByprojectIdUsrIdProjectInfoId($projectId, $UsrId, $projectInfoId, $project_title, $project_keyword, $project_description)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
        	UPDATE
				 %s as pi
				 , %s as p
			SET
                	pi.project_title = %s
                	, pi.project_keyword = %s
                	, pi.project_description= %s
            WHERE
					pi.project_info_id = p.project_info_id
					AND p.project_id = %s
					AND p.rvs_usr_id = %s
					AND pi.project_info_id = %s
            '
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($project_title)
            , RvsLibs_String::quoteSmart($project_keyword)
            , RvsLibs_String::quoteSmart($project_description)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($UsrId)
            , RvsLibs_String::quoteSmart($projectInfoId)
            );
            $res = $oProjectInfo->query($query);
            DB_DataObject::debugLevel();
            return $res;
    }

 /**
     * Update layout_template_id from table rvs_project_info where project_id, rvs_usr_id and project_info_id
     *
     *  Resulting SQL
     *          UPDATE
     *              rvs_project_info as pi
     *              , rvs_project' as p
     *          SET
     *              pi.layout_template_id = {$defaultLayoutId}
     *          WHERE
     *              pi.project_info_id = p.project_info_id
     *              AND p.project_id = {$projectId}
     *              AND p.rvs_usr_id = {$UsrId}
     *              AND pi.project_info_id = {$projectInfoId}
     *
     * @author duangdao.k
     * @param string $defaultLayoutId
     * @param string $projectId
     * @param string $UsrId
     * @param string $projectInfoId
     * @return object
     */
    public function updateLayoutTemplateId($defaultLayoutId, $projectId, $UsrId, $projectInfoId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
            UPDATE
                 %s as pi
                 , %s as p
            SET
                    pi.layout_template_id = %s
            WHERE
                    pi.project_info_id = p.project_info_id
                    AND p.project_id = %s
                    AND p.rvs_usr_id = %s
                    AND pi.project_info_id = %s
            '
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($defaultLayoutId)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($UsrId)
            , RvsLibs_String::quoteSmart($projectInfoId)
            );
            $res = $oProjectInfo->query($query);
            DB_DataObject::debugLevel();
            return $res;
    }

    /**
     * update LastUpdate ByProjectId And UsrId And ProjectInfoId
     *
     * Resulting SQL
     *  	 UPDATE
     * 				rvs_project_info as pi
     * 				rvs_project as p
     * 		  SET
     * 				pi.last_update = {$updatetime}
     * 		 WHERE
     * 				 p.project_id = {$projectID}
     * 				 AND p.rvs_usr_id = {$rvsUsrId}
     * 			     AND p.project_info_id = pi.project_info_id
     *
     * @author duangdao.k
     * @param string $updatetime
     * @param string $projectID
     * @param string $rvsUsrId
     * @return string
     */
    public function updateLastUpdateByProjectIdAndUsrIdAndProjectInfoId($updatetime, $projectID, $rvsUsrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf("
            UPDATE
                %s as pi
                , %s as p
            SET
                pi.last_update = %s
            WHERE
                p.project_id = %s
                AND p.rvs_usr_id = %s
                AND p.project_info_id = pi.project_info_id

            "
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($updatetime)
            , RvsLibs_String::quoteSmart($projectID)
            , RvsLibs_String::quoteSmart($rvsUsrId)
        );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

   /**
     * update data proect info By ProjectId And UsrId And ProjectInfoId
     *
     * Resulting SQL
     *  	 UPDATE
     * 				rvs_project_info as pi
     * 				rvs_project as pp
     * 		 SET
     * 				pi.i_favorite = {$favorite}
     * 				pi.i_print =  {$print}
     * 				pi.i_mail = {$mail}
     * 				pi.i_pathway = {$pathwqay}
     * 		 WHERE
     * 				 pi.project_info_id = pp.project_info_id
     * 				 AND pi.project_info_id = {$projectInfoId}
     * 			     AND pp.project_id = {$projectId}
     * 				 AND pp.rvs_usr_id = {$usrId}
     *
     * @author Darawan Taorong
     * @param string $favorite
     * @param string $print
     * @param string $mail
     * @param string $pathwqay
     * @param string $projectInfoId
     * @param string $projectId
     * @param string $usrId
     * @return string
     */
    public function updateDataProjectInfoByProjectInfoIdAndProjectIdAndUsrId($favorite = null, $print = null, $mail = null, $pathwqay = null, $projectInfoId = null, $projectId = null, $usrId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf("
            UPDATE
                %s as pi
                , %s as pp
            SET
            	pi.i_favorite = %s
            	, pi.i_print =  %s
            	, pi.i_mail = %s
            	, pi.i_pathway = %s
            WHERE
                pi.project_info_id = pp.project_info_id
                AND pi.project_info_id = %s
                AND pp.project_id = %s
                AND pp.rvs_usr_id = %s
            "
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($favorite)
            , RvsLibs_String::quoteSmart($print)
            , RvsLibs_String::quoteSmart($mail)
            , RvsLibs_String::quoteSmart($pathwqay)
            , RvsLibs_String::quoteSmart($projectInfoId)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($usrId)
        );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

   /**
     * update Projectinfo Set template_item_id,navigator_name_id,check_step,font_id by project_info_id
     * @author tanawat
     * @param <string> $templateItemId
     * @param <string> $navigatorNameId
     * @param <string> $checkStep
     * @param <string> $fontId
     * @param <string> $projectInfoId
     * @param <string> $projectId
     * @param <string> $rvsUsrId
     * @return bool
     */
 public function updateProjectinfoSetNavigatorIdAndFontIdByProjectInfoId($templateItemId=null, $navigatorNameId=null, $checkStep=null, $fontId=null, $projectInfoId=null, $projectId=null, $rvsUsrId=null)
    {
        $oProjectinfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
         $query = sprintf('
            UPDATE
                %s as pi
                ,%s as pp
            SET
                pi.template_item_id = %s
                %s
                %s
                ,pi.font_id = %s
            WHERE
                pp.project_id = %s
                AND pp.rvs_usr_id = %s
                AND pi.project_info_id = %s
                AND pi.project_info_id = pp.project_info_id
        '
        , $this->aConf['table']['rvs_project_info']
        , $this->aConf['table']['rvs_project']
        , RvsLibs_String::quoteSmart($templateItemId)
        , ($navigatorNameId)? ',pi.navigator_name_id = '. RvsLibs_String::quoteSmart($navigatorNameId):''
        , ($checkStep && $checkStep > 3)? ',pi.check_step = ' . RvsLibs_String::quoteSmart($checkStep):',pi.check_step = \'3\''
        , RvsLibs_String::quoteSmart($fontId)
        , RvsLibs_String::quoteSmart($projectId)
        , RvsLibs_String::quoteSmart($rvsUsrId)
        , RvsLibs_String::quoteSmart($projectInfoId)
        );
        $resultEdit = $oProjectinfo->query($query);
         DB_DataObject::debugLevel();
        return $resultEdit;
    }

    /**
     * Update ProjectLogo By ProjectId And ProjectInFoId And projectinfoID and rvsUsrId
     *
     * Resulting SQL
     * 		UPDATE
     * 		   rvs_project_info as pi
     * 			 , rvs_project as p
     * 		 SET
     * 			 pi.project_logo = {$logoName}
     * 		 WHERE
     * 			p.project_id = {$projectID}
     * 			 AND pi.project_info_id = {$projectinfoID}
     * 			AND p.rvs_usr_id = {}
     * 			 AND p.project_info_id = pi.project_info_id
     *
     * @author duangdao.k
     * @param string $logoName
     * @param string $projectID
     * @param string $projectinfoID
     * @param string $rvsUsrId
     * @return bool
     */
    public function updateProjectLogoByProjectIdAndProjectInFoId($logoName, $projectID, $projectinfoID, $rvsUsrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf("
            UPDATE
                %s as pi
                , %s as p
            SET
                pi.project_logo = %s
            WHERE
                p.project_id = %s
                AND pi.project_info_id = %s
                AND p.rvs_usr_id = %s
                AND p.project_info_id = pi.project_info_id

            "
            , $this->aConf['table']['rvs_project_info']
            , $this->aConf['table']['rvs_project']
            , RvsLibs_String::quoteSmart($logoName)
            , RvsLibs_String::quoteSmart($projectID)
            , RvsLibs_String::quoteSmart($projectinfoID)
            , RvsLibs_String::quoteSmart($rvsUsrId)
        );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

    /**
     * updata check step by usrid and porject id and project info id
     * @author pharadol
     * @param <string> $checkStep
     * @param <string> $projectId
     * @param <string> $projectPagrId
     * @param <string> $usrId
     * @return array
            /*
            $query = "
                               UPDATE
                                            {$this->conf['table']['rvs_project_info']} as pi
                                             , {$this->conf['table']['rvs_project']} as pp
                                SET
                                             pi.check_step = '4'

                                WHERE
                                             pi.project_info_id = pp.project_info_id
                                             AND pi.project_info_id = '" . $aProjectInfoId . "'
                                             AND pp.project_id = '$input->project_id'
                                             AND pp.rvs_usr_id = '$input->rvs_usr_id'
                       ";
            $res = $this->dbh->query($query);
            */
    public function updateChekStepByusrIdAndProjectIdAndProjectInfoId($checkStep, $projectId, $projectPagrId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProjectInfo = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                               UPDATE
                                            %s as pi
                                             , %s as pp
                                SET
                                             pi.check_step = %s

                                WHERE
                                             pi.project_info_id = pp.project_info_id
                                             AND pp.project_id = %s
                                             AND pp.project_info_id = %s
                                             AND pp.rvs_usr_id = %s
                                '
                                , $this->aConf['table']['rvs_project_info']
                                , $this->aConf['table']['rvs_project']
                                , RvsLibs_String::quoteSmart($checkStep)
                                , RvsLibs_String::quoteSmart($projectId)
                                , RvsLibs_String::quoteSmart($projectPagrId)
                                , RvsLibs_String::quoteSmart($usrId)
                                );
        $res = $oProjectInfo->query($query);
        DB_DataObject::debugLevel();
        return ($res) ? true : false;
    }

    public function updateProjectFooterByProjectId($projectFooter, $projectId, $usrId)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
    	$query = sprintf('
                                UPDATE
                                            %s
                                SET
                                            project_footer = %s
                                WHERE
                                            project_id = %s
                                            AND rvs_usr_id = %s
                             '
    			, $this->aConf['table']['rvs_project']
    			, RvsLibs_String::quoteSmart($projectFooter)
    			, RvsLibs_String::quoteSmart($projectId)
    			, RvsLibs_String::quoteSmart($usrId)
    	);
    	//SGL::logMessage('rvdebug: ===========' . $query);
    	$res = $oProject->query($query);
    	return $res;
    }

     /**
     *update ProjectName By ProjectId And UsrId in rvs_project table
     * Resulting SQL
     * 	UPDATE
     * 		rvs_project
     * 	SET
     * 		project_name = {$projectName}
     * 	WHERE
     * 		project_id = {$projectId}
     * 		AND rvs_usr_id = {$usrId}
     * $res = $this->dbh->query($query);
     *
     * @author Pornthip Phothong
     * @param <string> $projectName
     * @param <string> $projectId
     * @param <string> $usrId
     * form file CreateProjectMgr.php
     */
    public function updateProjectNameByProjectIdAndUsrId($projectName, $projectId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
                                UPDATE
                                            %s
                                SET
                                            project_name = %s
                                 WHERE
                                             project_id = %s
                                             AND rvs_usr_id = %s
                             '
                             , $this->aConf['table']['rvs_project']
                             , RvsLibs_String::quoteSmart($projectName)
                             , RvsLibs_String::quoteSmart($projectId)
                             , RvsLibs_String::quoteSmart($usrId)
                             );
                             $res = $oProject->query($query);
                             DB_DataObject::debugLevel();
                             return $res;
    }

    /**
     * update NoSlogan And NoCompanyName By ProjectInfoId And ProjectId And UsrId in rvs_project_info and rvs_project
     *
     * Resulting SQL
     *
     *  UPDATE
     *         rvs_project_info as pi
     *         , rvs_project as pp
     *  SET
     *         pi.no_slogan = {'$noSlogan'}
     *       , pi.no_company_name = {'$noCompanyName'}
     * WHERE
     *        pi.project_info_id = {$projectInfoId}
     *        AND pp.project_id = {$projectId}
     *        AND pp.rvs_usr_id = {$usrId}
     *
     * @author Pornthip Phothong
     * @param <string> $noSlogan
     * @param <string> $noCompanyName
     * @param <string> $projectInfoId
     * @param <string> $projectId
     * @param <string> $usrId
     * @from CreateProjectMgr.php
     */
    public function updateNoSloganAndNoCompanyName($noSlogan, $noCompanyName, $projectInfoId, $projectId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                        UPDATE
                                    %s as pi
                                     , %s as pp
                        SET
                                     pi.no_slogan = %s
                                     , pi.no_company_name = %s
                        WHERE
                                     pi.project_info_id = %s
                                     AND pp.project_id = %s
                                     AND pp.rvs_usr_id = %s
                    '
                    , $this->aConf['table']['rvs_project_info']
                    , $this->aConf['table']['rvs_project']
                    , RvsLibs_String::quoteSmart($noSlogan)
                    , RvsLibs_String::quoteSmart($noCompanyName)
                    , RvsLibs_String::quoteSmart($projectInfoId)
                    , RvsLibs_String::quoteSmart($projectId)
                    , RvsLibs_String::quoteSmart($usrId)
                    );
                    $res = $oProject->query($query);
                    DB_DataObject::debugLevel();
                    return $res;
    }

     /**
     * update font_id,page_title By ProjectInfoId And ProjectId And UsrId in rvs_project_info and rvs_project
     * @author darawan taorong
     * @param <string> $noSlogan, $noCompanyName, $fontId, $pageTitle, $metaKeyword, $metaDesc
     * @param <string> $projectInfoId
     * @param <string> $projectId
     * @param <string> $usrId
     * @from AdjustStyleAjaxMgr.php
     */
    public function updateProjectInfo($noSlogan, $noCompanyName, $fontId, $projectInfoId, $projectId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                        UPDATE
                                    %s as pi
                                     , %s as pp
                                     , %s as ppp
                        SET
                                      pi.no_slogan = %s
                                     , pi.no_company_name = %s
                                     , pi.font_id = %s
                        WHERE
                                     pi.project_info_id = %s
                                     AND pp.project_id = %s
                                     AND pp.rvs_usr_id = %s
                    '
                    , $this->aConf['table']['rvs_project_info']
                    , $this->aConf['table']['rvs_project']
                    , $this->aConf['table']['rvs_project_page']
                    , RvsLibs_String::quoteSmart($noSlogan)
                    , RvsLibs_String::quoteSmart($noCompanyName)
                    , ($fontId && $fontId != '') ? RvsLibs_String::quoteSmart($fontId) : '12'
                    , RvsLibs_String::quoteSmart($projectInfoId)
                    , RvsLibs_String::quoteSmart($projectId)
                    , RvsLibs_String::quoteSmart($usrId)
                    );
                    $res = $oProject->query($query);
                    DB_DataObject::debugLevel();
                    return $res;
    }

 	/**
     * update font_id,page_title By ProjectInfoId And ProjectId And UsrId in rvs_project_info and rvs_project
     * @author darawan taorong
     * @param <string> $noSlogan, $noCompanyName, $fontId, $pageTitle, $metaKeyword, $metaDesc
     * @param <string> $projectInfoId
     * @param <string> $projectId
     * @param <string> $usrId
     * @from AdjustStyleAjaxMgr.php
     */
    public function updatePathwayProjectInfo($pathway, $projectInfoId, $projectId, $usrId)
    {
        SGL::logMessage('*****update pathway to ====>' . $pathway, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
       	 $query = sprintf('
                        UPDATE
                                    %s as pi
                                     , %s as pp
                        SET
                                     pi.i_pathway = %s
                        WHERE
                                     pi.project_info_id = %s
                                     AND pp.project_id = %s
                                     AND pp.rvs_usr_id = %s
                    '
                    , $this->aConf['table']['rvs_project_info']
                    , $this->aConf['table']['rvs_project']
                    , ($pathway && $pathway != '') ? RvsLibs_String::quoteSmart($pathway) : '0'
                    , RvsLibs_String::quoteSmart($projectInfoId)
                    , RvsLibs_String::quoteSmart($projectId)
                    , RvsLibs_String::quoteSmart($usrId)
                    );
                    $res = $oProject->query($query);
                    DB_DataObject::debugLevel();
                    return $res;
    }
    /**
     *
     * update ProjectInfoData By ProjectInfoId And ProjectId And UsrId in rvs_project_info and rvs_project
     *
     * ///OPTIMIZE VARIABLE PASSING
     * @param <Array> $aParamsUpdateProject
     *                                                      array(
                                                                        'charsetId' => char set id
                                                                        'projectCompany' => project company name
                                                                        'projectSlogan' => slogan name
                                                                        'projectTitle' => title name
                                                                        'projectKeyword' => project keyword
                                                                        'projectDescription' => project description
                                                                        'projectDomain' => project domain
                                                                        'lastUpdate' => last update
                                                                        'projectInfoId' => project info id
                                                                        'projectId' => project id
                                                                        'rvsUsrId' => user id
                                                                    );
     *
     * @from CreateProjectMgr.php
     */
    public function updateProjectInfoDataByProjectInfoIdAndProjectIdAndUsrId($aParamsUpdateProject)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);

        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                                UPDATE
                                            %s as pi
                                            , %s as pp
                                SET
                                            pi.charset_id = %s
                                            , pi.project_company = %s
                                            , pi.project_slogan = %s
                            '
                            , $this->aConf['table']['rvs_project_info']
                            , $this->aConf['table']['rvs_project']
                            , RvsLibs_String::quoteSmart($aParamsUpdateProject['charsetId'])
                            , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectCompany'])
                            , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectSlogan'])
                              );

       $query .= sprintf('
                                            , pi.project_title = %s
                                            , pi.project_keyword = %s
                                            , pi.project_description = %s
                                            , pi.project_domain = %s
                                            , pi.last_update = %s
                                 WHERE
                                             pi.project_info_id = %s
                                             AND pp.project_id = %s
                                             AND pp.rvs_usr_id = %s
                                 '
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectTitle'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectKeyword'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectDescription'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectDomain'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['lastUpdate'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectInfoId'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['projectId'])
                                 , RvsLibs_String::quoteSmart($aParamsUpdateProject['rvsUsrId'])
                                 );

      $res = $oProject->query($query);
      DB_DataObject::debugLevel();
      return $res;
    }

    /**
     *
     * update Slogan,Company name projectProjectInfoData By ProjectInfoId And ProjectId And UsrId in rvs_project_info and rvs_project
     * var $aFieldUpdate = array('project_company'=>'name company aaaa','project_slogan'=>'name slogannnn');
     * @from AdjustStyleMgr.php
     */
    public function updateSloganCompanyByProjectInfoIdAndProjectIdAndUsrId($aFieldUpdate,$projectInfoId=nul,$projectId=null,$usrId=null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);

        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $dataUpdate = '';
        if(count($aFieldUpdate) != 0){
        	foreach($aFieldUpdate as $k=>$v){
        		$dataUpdate .= 'pi.'.$k.'='.RvsLibs_String::quoteSmart($v);
        	}
        }
        $query = sprintf('
                                UPDATE
                                            %s as pi
                                            , %s as pp
                                SET
                                            %s

                                WHERE
                                             pi.project_info_id = %s
                                             AND pp.project_id = %s
                                             AND pp.rvs_usr_id = %s
                            '
                            , $this->aConf['table']['rvs_project_info']
                            , $this->aConf['table']['rvs_project']
                            , $dataUpdate
                            , RvsLibs_String::quoteSmart($projectInfoId)
                            , RvsLibs_String::quoteSmart($projectId)
                            , RvsLibs_String::quoteSmart($usrId)
                              );
      $res = $oProject->query($query);
      DB_DataObject::debugLevel();
      return $res;
    }


 public function updateLastUpdateByProjectInfoIdAndProjectIdAndUsrId($LastUpdate=null,$projectId=null,$usrId=null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);

        DB_DataObject::debugLevel(0);
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        $query = sprintf('
                                UPDATE
                                            %s as pi
                                            , %s as pp
                                SET
                                            last_update = %s

                                WHERE
                                             pp.project_info_id = pi.project_info_id
                                             AND pp.project_id = %s
                                             AND pp.rvs_usr_id = %s
                            '
                            , $this->aConf['table']['rvs_project_info']
                            , $this->aConf['table']['rvs_project']
                            , RvsLibs_String::quoteSmart($LastUpdate)
                            , RvsLibs_String::quoteSmart($projectId)
                            , RvsLibs_String::quoteSmart($usrId)
                              );
      $res = $oProject->query($query);
      DB_DataObject::debugLevel();
      // pi.project_company = %s, pi.project_slogan = %s
      return $res;
    }

    // , ($checkStep && $checkStep > 3)? ',pi.check_step = ' . RvsLibs_String::quoteSmart($checkStep):',pi.check_step = \'3\''
     /**
     * Update charset utf8 format
     * @author  pharadol
     * @from ConvertProjectUTF8AjaxMgr.php
     **/
    public function updateCharsetUtf8Format($projectId)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
    	$query = sprintf('UPDATE
    	                                        %s
    	                                SET
    	                                        utf8format = 1
    	                           WHERE
    	                                        project_id = %s
    	                           '
    	                           , $this->aConf['table']['rvs_project']
    	                           , RvsLibs_String::quoteSmart($projectId)
    	                        );
        $res = $this->dbh->query($query);
    	if (SGL::isError($res)) {
           SGL::raiseError($res->getMessage());
        }
        return $res = isset($res) ? true : false;
    }
     /**
     * update new project name
     * @author pharadol/siwakorn
     * @param <string> $projectId
     * @param <string> $projectName
     * @return bool
     */
    public function updateProjectNameByProjectName($projectId, $projectName)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        $query = sprintf('
                                UPDATE
                                            %s
                                SET
                                            project_name = %s
                                 WHERE
                                             project_id = %s
                             '
                             , $this->aConf['table']['rvs_project']
                             , RvsLibs_String::quoteSmart($projectName)
                             , RvsLibs_String::quoteSmart($projectId)
                             );
                             $res = $oProject->query($query);
                             DB_DataObject::debugLevel();
                             return $res;
    }

    /**
     * update layer_data table rvs_custom_layer step 2 Header
     * @author nipaporn
     * @param unknown_type $layerId
     * @param unknown_type $projectId
     * @param unknown_type $layerdata
     * @param unknown_type $headerUrlLink
     * @param unknown_type $headerUrlTarget
     * @return unknown_type
     */
    public function updateCustomLayer($layerId,$projectId,$layerdata, $headerUrlLink, $headerUrlTarget)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oCustomLayer = DB_DataObject::factory($this->aConf['table']['rvs_custom_layer']);
    	$query = sprintf('
                            UPDATE
                                        %s
                            SET
                                        layer_data = %s
                                        , layer_url = %s
                                        , layer_target = %s
                            WHERE
                                        layer_id = %s
                                        AND rvs_project_id = %s
                         '
                         , $this->aConf['table']['rvs_custom_layer']
                         , RvsLibs_String::quoteSmart($layerdata)
                         , RvsLibs_String::quoteSmart($headerUrlLink)
                         , RvsLibs_String::quoteSmart($headerUrlTarget)
                         , RvsLibs_String::quoteSmart($layerId)
                         , RvsLibs_String::quoteSmart($projectId)
                         );
                         //SGL::logMessage('====>>>>' . $query, PEAR_LOG_DEBUG);
                         $res = $oCustomLayer->query($query);
    }


    /**
     * update attName AttValue table rvs_body_attribute
     * @author duangdao.k
     * @param <string> $projectId
     * @param <string> $projectPageId
     * @param <string> $attId
     * @param <string> $attName
     * @param <string> $attValue
     * @return bool
     */
    public function updateAttNameAttValueBodyAttributeByProjectIdAndAttId($projectId = null, $projectPageId = null, $attId = null, $attName = null, $attValue = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
            UPDATE
                %s as bx
                , %s as ba
            SET
                ba.att_name = %s
                , ba.att_value = %s
            WHERE
                bx.project_id = %s
                AND bx.att_id = %s
                %s
                AND bx.att_id = ba.att_id
            '
            , $this->aConf['table']['rvs_body_attribute_xref']
            , $this->aConf['table']['rvs_body_attribute']
            , RvsLibs_String::quoteSmart($attName)
            , RvsLibs_String::quoteSmart($attValue)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($attId)
            , (is_null($projectPageId)) ? '' : 'AND bx.project_page_id = ' . RvsLibs_String::quoteSmart($projectPageId)
            );
            $res = $oProject->query($query);
            DB_DataObject::debugLevel();
            return $res;
    }

    /**
     * Update rvs_head (by project,by project page
     * @author darawan
     * @param string $projectId
     * @param string $projectPageId
     * @param string $data
     * @return bool
     */
    public function updateRvsHead($projectId, $projectPageId, $data)
    {
    	
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oRvsHead = DB_DataObject::factory($this->aConf['table']['rvs_head']);
        $query = sprintf('
            UPDATE
                %s
            SET
                head_tag_data = %s
            WHERE
                project_id = %s
                AND project_page_id = %s
            '
            , $this->aConf['table']['rvs_head']
            , RvsLibs_String::quoteSmart($data)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($projectPageId)
            );
        
        
        SGL::logMessage($query, PEAR_LOG_DEBUG);
        
        $res = $oRvsHead->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }
    
    public function addRvsHead($projectId, $projectPageId, $data)
    {


    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oRvsHead = DB_DataObject::factory($this->aConf['table']['rvs_head']);
    	$query = sprintf('
            REPLACE INTO
                %s
    	   (project_id, project_page_id, head_tag_data) 
    			VALUES (%s 
    			,%s
    			,%s)
             
            '
    			, $this->aConf['table']['rvs_head']
    			, RvsLibs_String::quoteSmart($projectId)
    			, RvsLibs_String::quoteSmart($projectPageId)
    			, RvsLibs_String::quoteSmart($data)
    			);
    	
    	
    	SGL::logMessage($query, PEAR_LOG_DEBUG);
    	
    	$res = $oRvsHead->query($query);
    	DB_DataObject::debugLevel();
    	return $res;
    	
    	
    }

    /**
     * Update rvs_css (by project,by project page
     * @author darawan
     * @param string $projectId
     * @param string $projectPageId
     * @param string $data
     * @return bool
     */
    public function updateRvsCss($projectId, $projectPageId, $data)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oRvsCss = DB_DataObject::factory($this->aConf['table']['rvs_css']);
        $query = sprintf('
            UPDATE
                %s
            SET
                css_tag_data = %s
            WHERE
                project_id = %s
                AND project_page_id = %s
            '
            , $this->aConf['table']['rvs_css']
            , RvsLibs_String::quoteSmart($data)
            , RvsLibs_String::quoteSmart($projectId)
            , RvsLibs_String::quoteSmart($projectPageId)
            );
        $res = $oRvsCss->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }
    //--------------------------------------------Delete---------------------------------------------------------//
    /**
     * delete project info by projectid and usrid
     * $query = "
                        DELETE
                                    {$this->conf['table']['rvs_project_info']} as pi
                        FROM
                                    {$this->conf['table']['rvs_project_info']} as pi
                                    , {$this->conf['table']['rvs_project']} as p
                        WHERE
                                    pi.project_info_id = p.project_info_id
                                    AND p.project_id = '$input->project_id'
                                    AND p.rvs_usr_id = '$input->rvs_usr_id'
                    ";
     * @author pharadol
     * @param <string> $projectId
     * @param <string> $usrId
     * @return bool
     */
    public function deleteProjectInfoByProjectIdAndUsrId($projectInfoId = null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project_info']);
        if (!is_null($projectInfoId)) {
            /*
        	$query = sprintf('
                        DELETE
                                   %s as pi
                        FROM
                                    %s as pi
                                    , %s  as p
                        WHERE
                                    pi.project_info_id = p.project_info_id
                                    AND p.project_id = %s
                                    AND p.rvs_usr_id = %s
                       '
                       , $this->aConf['table']['rvs_project_info']
                       , $this->aConf['table']['rvs_project_info']
                       , $this->aConf['table']['rvs_project']
                       , RvsLibs_String::quoteSmart($projectId)
                       , RvsLibs_String::quoteSmart($usrId)
                        );
             */
        	       $query = sprintf('
                        DELETE

                        FROM
                                    %s
                        WHERE
                                    project_info_id = %s
                       '
                       , $this->aConf['table']['rvs_project_info']
                       , RvsLibs_String::quoteSmart($projectInfoId)
                        );

             $res = $oProject->query($query);
        }
		return ($res) ? true : false;
    }

    /**
     * delete project by projectid and usrid
        $query = "
                        DELETE
                                    {$this->conf['table']['rvs_project']}
                        FROM
                                    {$this->conf['table']['rvs_project']}
                        WHERE
                                    project_id = '$input->project_id'
                                    AND rvs_usr_id = '$input->rvs_usr_id'
                    ";
     * @author pharadol
     * @param <string> $projectId
     * @param <string> $usrId
     * @return bool
     * form file RemoveProjectMgr.php
     */
    public function deleteProjectByProjectIdAndUsrId($projectId, $usrId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_project']);
        /*
        $query = sprintf('
                        DELETE
                                    %s
                        FROM
                                    %s
                        WHERE
                                    project_id = %s
                                    AND rvs_usr_id = %s
                            '
                            , $this->aConf['table']['rvs_project']
                            , $this->aConf['table']['rvs_project']
                            , RvsLibs_String::quoteSmart($projectId)
                            , RvsLibs_String::quoteSmart($usrId)
                            );
         */
         $query = sprintf('
                        DELETE

                        FROM
                                    %s
                        WHERE
                                    project_id = %s

                            '
                            , $this->aConf['table']['rvs_project']
                            , RvsLibs_String::quoteSmart($projectId)
                            );

        $res = $oProject->query($query);
		return (isset($res) && $res) ? true : false;
    }

public function deleteProjectMetatagByProjectInfoId($projectInfoId)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);
        DB_DataObject::debugLevel();
        $oProjectInfoMetatag = DB_DataObject::factory($this->aConf['table']['rvs_project_info_metatag']);
        if (!is_null($projectInfoId)) {
        	/*
             $query = sprintf('
                            DELETE
                                        %s as pm
                                        , %s as cm
                            FROM
                                        %s as pm
                                        , %s as cm
                            WHERE
                                        pm.rvs_custom_metatag_id = cm.rvs_custom_metatag_id
                                        AND pm.rvs_project_info_id = %s
                                '
                                , $this->aConf['table']['rvs_project_info_metatag']
                                , $this->aConf['table']['rvs_custom_metatag']
                                , $this->aConf['table']['rvs_project_info_metatag']
                                , $this->aConf['table']['rvs_custom_metatag']
                                , RvsLibs_String::quoteSmart($projectInfoId)
                                );
             */

        	                $query = sprintf('
                            DELETE

                            FROM
                                        %s
                            WHERE
                                        rvs_project_info_id = %s
                                '
                                , $this->aConf['table']['rvs_project_info_metatag']
                                , RvsLibs_String::quoteSmart($projectInfoId)
                                );

            $res = $oProjectInfoMetatag->query($query);
        }
        return isset($res) && $res ? true : false;
    }

    /**
     * delete rvs_body_attribute_xref and rvs_body_attribute where project_id $projectPageId att_id
     * @author duangdao.k
     * @param <string> $projectId
     * @param <string> $projectPageId
     * @param <string> $attId
     * @return bool
     */
    public function deleteAttributeXrefAndBodyAttributeByProjectIdAndAttId($projectId, $projectPageId = null, $attId = null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
    	if (!is_null($attId)) {
    		$this->_deleteAttributeXrefAttribute($attId);
    		$this->_deleteAttributeXrefAttributeXref($attId);
    	} else if (!is_null($projectPageId)) {
	    	  $aRes = $this->findBodyAttributeXrefDelByPageId($projectPageId,'getAll');
	    	  foreach ($aRes as $key => $val) {
	    	      $this->deleteAttributeByPageAttribute($val->att_id);
	    	      $this->deleteAttributeByPageAttributeXref($val->att_id);
	    	  }
    	} else if (!is_null($projectId)) {
    		  $aRes = $this->findBodyAttributeXrefDelByProjectId($projectId,'getAll');
    		  foreach ($aRes as $key => $val) {
    		      $this->deleteAttributeByProjectAttribute($val->att_id);
                  $this->deleteAttributeByProjectAttributeXref($val->att_id);
    		  }
    	}

    }

    public function deleteAttributeByProjectAttribute($attId)
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
        $query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($attId)
                       );
                       $res = $oProject->query($query);
        return (isset($res) && $res) ? true : false;
    }

    public function deleteAttributeByProjectAttributeXref($attId)
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($attId)
                       );
                       $res = $oProject->query($query);
        return (isset($res) && $res) ? true : false;
    }



    public function deleteAttributeByPageAttribute($attId)
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
        $query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($attId)
                       );
                       $res = $oProject->query($query);
        return (isset($res) && $res) ? true : false;
    }


    public function deleteAttributeByPageAttributeXref($attId)
    {
        $oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
        $query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , RvsLibs_String::quoteSmart($attId)
                       );
                       $res = $oProject->query($query);
        return (isset($res) && $res) ? true : false;
    }

    public function _deleteAttributeXrefAttribute($attId)
    {
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute']);
    	$query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute']
                       , RvsLibs_String::quoteSmart($attId)
                       );
         $res = $oProject->query($query);

    }

    public function _deleteAttributeXrefAttributeXref($attId)
    {
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_body_attribute_xref']);
    	$query = sprintf('
                        DELETE

                        FROM
                                %s
                        WHERE
                                att_id = %s

                       '
                       , $this->aConf['table']['rvs_body_attribute_xref']
                       , RvsLibs_String::quoteSmart($attId)
                       );
         $res = $oProject->query($query);
    }



    /**
     * Delete rvs_css
     * Enter description here ...
     * @param $projectId string
     * @param $projectPageId string
     */
    public function deleteCustomCSS($projectId, $projectPageId=null)
    {
    	$oCss = DB_DataObject::factory($this->aConf['table']['rvs_css']);
    	$query = sprintf('
    		DELETE FROM
    			%s
    		WHERE
    			project_id = %s
    			%s
	    	'
	    	, $this->aConf['table']['rvs_css']
	    	, RvsLibs_String::quoteSmart($projectId)
	    	, (!is_null($projectPageId)) ? ' AND project_page_id=' . RvsLibs_String::quoteSmart($projectPageId) : ''
    	);
    	$res = $oCss->query($query);
        DB_DataObject::debugLevel();
        return $res;
    }

    /**
     * Delete rvs_head by project
     * Enter description here ...
     * @param $projectId string
     * @param $projectPageId string
     */
    public function deleteRvsHead($projectId, $projectPageId=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oRvsHead = DB_DataObject::factory($this->aConf['table']['rvs_head']);
    	$query = sprintf('
            DELETE FROM
                %s
            WHERE
	            project_id = %s
	            %s
            '
            , $this->aConf['table']['rvs_head']
            , RvsLibs_String::quoteSmart($projectId)
            , (!is_null($projectPageId)) ? ' AND project_page_id =' . RvsLibs_String::quoteSmart($projectPageId) : ''
            );
            $res = $oRvsHead->query($query);
            DB_DataObject::debugLevel();
            return $res;
    }

    /**
     * delect table rvs_custom_layer step 2 Header
     * @author nipaporn
     * @param unknown_type $projectId
     * @param unknown_type $layerId
     * @return unknown_type
     */
    public function deleteCustomLayer($projectId, $layerId=null)
    {
    	SGL::logMessage(null, PEAR_LOG_DEBUG);
    	DB_DataObject::debugLevel();
    	$oProject = DB_DataObject::factory($this->aConf['table']['rvs_custom_layer']);
    	$query = sprintf('
                        DELETE FROM
                                    %s
                        WHERE
                                    rvs_project_id = %s
                                    %s
                        '
                        , $this->aConf['table']['rvs_custom_layer']
                        , RvsLibs_String::quoteSmart($projectId)
                        , (!is_null($layerId)) ? ' AND layer_id=' . RvsLibs_String::quoteSmart($layerId) : ''
                    );
                    $res = $oProject->query($query);
                    return (isset($res) && $res) ? true : false;
    }

    public function backupsql($projectId, $usrId, $projectPageId=null)
    {
        /// Backup Table rvs_project
        $aCustomMetatagId = array();
        $aSQLData = array();

        $oHead = $this->findRvsHead($projectId, $projectPageId, 'getDataObject');
        foreach ($oHead as $k => $v) {
        	$aSQLData[] = DbWrapper::buildSQLFormat($v);
        }
        $oCss = $this->findRvsCss($projectId, $projectPageId, 'getDataObject');
        foreach ($oCss as $k => $v) {
        	$aSQLData[] = DbWrapper::buildSQLFormat($v);
        }
        $oAttBodyXref = $this->findBodyAttributeXref($projectId, $projectPageId, 'getDataObject');
        foreach ($oAttBodyXref as $k => $v) {
        	$aSQLData[] = DbWrapper::buildSQLFormat($v);
        }
        $oAttBody = $this->findBodyAttributeData($projectId, $projectPageId, 'getDataObject');
        foreach ($oAttBody as $k => $v) {
        	$aSQLData[] = DbWrapper::buildSQLFormat($v);
        }

        if (!is_null($projectPageId)) {
        	return $aSQLData;
        }

        $oProject = $this->findProjectByProjectId($projectId, 'getDataObject');
        foreach ($oProject as $k => $v) {
            $aProjectInfoId[] = $v->project_info_id;
            $aSQLData[] = DbWrapper::buildSQLFormat($v);
        }
        /// Backup Table rvs_project_info
        foreach ($aProjectInfoId as $projectInfoId) {
            $oProjectInfo = $this->findProjectInfoByProjectInfoId($projectInfoId, $fetchMode = 'getDataObject');
            foreach ($oProjectInfo as $k => $v) {
                $aSQLData[] = DbWrapper::buildSQLFormat($v);
            }
        }
        /// Backup Table rvs_project_info_metatag
        foreach ($aProjectInfoId as $projectInfoId) {
            $oProjectInfoMetatag = $this->findProjectMetatagByProjectInfoId($projectInfoId, 'getDataObject');
            foreach ($oProjectInfoMetatag as $k => $v) {
                $aCustomMetatagId[] = $v->rvs_custom_metatag_id;
                $aSQLData[] = DbWrapper::buildSQLFormat($v);
            }
        }
        /// Backup Table rvs_custom_metatag
        foreach ($aCustomMetatagId as $customMetatagId) {
            $oCustomMetatagId = $this->findCustomMetatagByCustomMetatagId($customMetatagId, $fetchMode = 'getDataObject');
            foreach ($oCustomMetatagId as $k => $v) {
                $aSQLData[] = DbWrapper::buildSQLFormat($v);
            }
        }
        /// Backup Custom Layer
        $oLayerData = $this->findCustomLayerByProjectId($projectId, null, 'getDataObject');
        foreach ($oLayerData as $k => $v) {
        	$aSQLData[] = DbWrapper::buildSQLFormat($v);
        }
        //echo $projectId;

        return $aSQLData;
    }

    public function deleteProjectOfUserId($projectId, $usrId, $aProjectPageId=array(), $projectPageId=null)
    {
        SGL::logMessage(null, PEAR_LOG_DEBUG);

        ///delete body
        $this->deleteAttributeXrefAndBodyAttributeByProjectIdAndAttId($projectId, $projectPageId);
        ///delete css
        $this->deleteCustomCSS($projectId, $projectPageId);
        ///delete head
        $this->deleteRvsHead($projectId, $projectPageId);

        if (!is_null($projectPageId)) {
        	return true;
        }

        $aResultFields = array(
        						'project_info_id'
        					);
        $aProjectInfo = $this->findAllProjectsByProjectId($projectId, $fetchMode = 'getall', $aResultFields);
        if (isset($aProjectInfo) && is_array($aProjectInfo)) {
            foreach ($aProjectInfo as $projectInfoId) {
                $this->deleteProjectMetatagByProjectInfoId($projectInfoId->project_info_id);
            }
        }
        $this->deleteProjectInfoByProjectIdAndUsrId($projectId, $usrId);
        $this->deleteProjectByProjectIdAndUsrId($projectId, $usrId);

        ///delete Custom Layer
        $this->deleteCustomLayer($projectId);

    }
}
?>

Copyright 2K16 - 2K18 Indonesian Hacker Rulez