<?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 online form of RVSiteBuilder
*
* @package sitebuilder
* @author Pairote Manunphol <pairote@rvglobalsoft.com>
* @author Parinya <parinya@rvglobalsoft.com>
* @version $Revision$
* @since PHP 5.1
*/
class OnlineFormDao extends DbWrapper implements SitebuilderInf
{
function OnlineFormDao()
{
parent::DbWrapper();
}
/**
* Returns a singleton OnlineFormDao instance.
*
* @param bool $autoload
* @return obj
*/
public static function singleton($autoload=false)
{
static $instance;
// If the instance is not there, create one
if (!isset($instance) || $autoload) {
$class = __CLASS__;
$instance = new $class();
}
return $instance;
}
/**
* Find online form data by online id
*
* Resulting SQL
* SELECT
* *
* FROM
* rvs_online_form
* WHERE
* rvs_onlineform_id = {$onlineFormId}
*
* @param string $onlineId
* @param string $fetchMode
* @param array $aResultFields (online_form, button, mailaccount, maildomain, mailsubject, thankmsg, mailbanedlist)
* @author Parinya Chaipetch
* @access public
* @return array
*/
function findOnlineFormDataByOnlineId($onlineFormId = null, $fetchMode = 'getassoc', $aResultFields = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($onlineFormId)) {
$oOnlineForm->rvs_onlineform_id = $onlineFormId;
}
$oOnlineForm->find();
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
$_aResultFields = DbWrapper::buildResultFields($oOnlineForm, $aResultFields);
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
}
/**
* Find OnlineForm AllData
* Resulting SQL
* SELECT
* *
* FROM
* rvs_online_form
*
* @author duangdao.k
* @param strimg $fetchMode
* @param array $aResultFields
* @return arrayobj
*/
public function findOnlineFormAllData($fetchMode = 'getassoc', $aResultFields = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
SELECT
*
FROM
%s
'
, $this->aConf['table']['rvs_online_form']
);
$oOnlineForm->query($query);
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* fine Online Form by onlineformid
* @author pharadol
* @param <string> $onlineformId
* @param <string> $fetchMode
* @return <array>
* form file Online_formMgr.php
*/
public function fineOnlineFormByOnlineFormId($onlineformId, $fetchMode = 'getassoc', $aResultFields=array('rvs_onlineform_id', 'online_form', 'step2_field', 'button'))
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($onlineformId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($onlineformId)
);
$res = $oOnlineForm->query($query);
}
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
$_aResultFields = DbWrapper::buildResultFields($oOnlineForm, $aResultFields);
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($_aResultFields, $aCloneData, $fetchMode);
}
/**
* find form mail conf by onlline form id
* @author pharadol
* @param <string> $onlineformId
* @param <string> $fetchMode
* @return array
* form file Online_FormMgr.php
/*
$query = "
SELECT
rvs_onlineform_id
, mailaccount
, maildomain
, mailsubject
, thankmsg
, mailbanedlist
FROM
{$this->conf['table']['rvs_online_form']}
WHERE
rvs_onlineform_id = '$onlineformId'
";
$aOnlineform = $this->dbh->getRow($query,DB_FETCHMODE_ASSOC);
*/
public function findFormmailCONFByOnlineFormId($onlineformId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($onlineformId)) {
$query = sprintf('
SELECT
rvs_onlineform_id
, mailaccount
, maildomain
, mailsubject
, thankmsg
, mailbanedlist
FROM
%s
WHERE
rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($onlineformId)
);
$oOnlineForm->query($query);
}
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* find online form layer by onlieformid
* @author pharadol
* @param <string> $onlineFormId
* @param <string> $fetchMode
* @return array
* form file Online_FormMgr.php
/*
$query = "
SELECT
onlineform_layout
FROM
{$this->conf['table']['rvs_online_form']}
WHERE
rvs_onlineform_id = '$onlineFormId'
";
$req = $this->dbh->getRow($query,DB_FETCHMODE_ASSOC);
*/
public function findOnlineFormLayoutByOnlineFormId($onlineFormId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($onlineFormId)) {
$query = sprintf('
SELECT
onlineform_layout
FROM
%s
WHERE
rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($onlineFormId)
);
$oOnlineForm->query($query);
}
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* find MailDomain By OnlineFormId from rvs_online_form table
* Resulting SQL
* SELECT
* maildomain
* FROM
* rvs_online_form
* WHERE
* rvs_onlineform_id = {$onlineFormId}
*
* @author Pornthip Phothong
* @param <string> $onlineFormId
* @param <string> $fetchMode
* @return array
* form file CreateProjectMgr.php
*/
public function findMailDomainByOnlineFormId($onlineFormId=null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($onlineFormId)) {
$query = sprintf('
SELECT
maildomain
FROM
%s
WHERE
rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($onlineFormId)
);
$oOnlineForm->query($query);
}
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* finc Dump Form template by template id
* @othor pharadol
* @param <string> $formTemplateId
* @param <string> $fetchMode
* @return array
*/
public function findDumpFormTemplateByTemplateId($formTemplateId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form_template']);
/*
if (!is_null($formTemplateId)) {
$query = sprintf('
SELECT
*
FROM
%s
WHERE
rvs_onlineform_template_id = %s
'
, $this->aConf['table']['rvs_online_form_template']
, RvsLibs_String::quoteSmart($formTemplateId)
);
$oOnlineForm->query($query);
}
*/
if (!is_null($formTemplateId)) {
$oOnlineForm->rvs_onlineform_template_id = $formTemplateId;
}
$oOnlineForm->find();
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* find Data List Jot Form by username :: project id
* @othor darawan 25/02/53
* @param <string> $projectId
* @param <string> $fetchMode
* @return array
* not unit test
*/
public function findListJotFormByProjectId($projectId = null, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oJotForm = DB_DataObject::factory($this->aConf['table']['forms']);
if (!is_null($projectId)) {
$oJotForm->username = $projectId;
}
$oJotForm->find();
$aCloneData = array();
while ($oJotForm->fetch()) {
$aCloneData[] = clone($oJotForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oJotForm->_resultFields, $aCloneData, $fetchMode);
}
/** get one Data table questions by form_id max order
*
* @param $projectId
* @param $fetchMode
* @return unknown_type
*/
public function findJotFormQuestionsByFormIdMaxOrder($FormId, $fetchMode = 'getone')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oJotForm = DB_DataObject::factory($this->aConf['table']['questions']);
$query = sprintf('
SELECT
count(form_id)
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['questions']
, RvsLibs_String::quoteSmart($FormId)
);
$oJotForm->query($query);
$aCloneData = array();
while ($oJotForm->fetch()) {
$aCloneData[] = clone($oJotForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oJotForm->_resultFields, $aCloneData, $fetchMode);
}
/**
* find Data Online Form by project id
* @othor darawan
* @param <string> $projectId
* @param <string> $fetchMode
* @return array
* not unit test
*/
public function findOnlineFormIdAndUsrIdAndProjectIdByProjectId($projectId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oFormOnline = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$aCloneData = array();
$query = sprintf('
SELECT
o.rvs_onlineform_id
,o.rvs_usr_id
,p.project_id
FROM
%s as o
,%s as p
WHERE
p.project_id = %s
AND o.project_page_id = p.project_page_id
'
, $this->aConf['table']['rvs_online_form']
, $this->aConf['table']['rvs_project_layout_page']
, RvsLibs_String::quoteSmart($projectId)
);
$oFormOnline->query($query);
while ($oFormOnline->fetch()) {
$aCloneData[] = clone($oFormOnline);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oFormOnline->_resultFields, $aCloneData, $fetchMode);
}
/*
public function findOnlineFormIdAndUsrIdAndProjectIdByProjectId($projectPageId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oFormOnline = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$aCloneData = array();
$query = sprintf('
SELECT
o.rvs_onlineform_id
,o.rvs_usr_id
,p.project_id
FORM
%s as o
,%s as p
WHERE
p.project_id = %s
, AND o.project_page_id = p.project_page_id
'
,$this->aConf['table']['rvs_layout_template']
);
$oFormOnline->query($query);
$aCloneData = array();
while ($oFormOnline->fetch()) {
$aCloneData[] = clone($oFormOnline);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oFormOnline->_resultFields, $aCloneData, $fetchMode);
}
*/
/** findOnlineFormByProjectId
* @author pornthip phothong
* @param $projectId
* @param $fetchMode
* not unit test
*/
public function findOnlineFormByProjectId($projectId, $fetchMode='getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oFormOnline = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($projectId)) {
$query = sprintf('
SELECT DISTINCT
o.rvs_onlineform_id
,o.rvs_usr_id
,o.project_id
,o.project_page_id
FROM
%s o
, %s p
WHERE
p.project_id = %s
AND (
o.project_page_id = p.project_page_id
OR
o.project_id = %s
)
'
, $this->aConf['table']['rvs_online_form']
, $this->aConf['table']['rvs_project_layout_page']
, RvsLibs_String::quoteSmart($projectId)
, RvsLibs_String::quoteSmart($projectId)
);
$oFormOnline->query($query);
}
$aCloneData = array();
while ($oFormOnline->fetch()) {
$aCloneData[] = clone($oFormOnline);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oFormOnline->_resultFields, $aCloneData, $fetchMode);
}
/**
* find Data Online Form by project id
* @othor pharadol
* @param <string> $projectId
* @param <string> $fetchMode
* @return array
* not unit test
*/
public function findPageNameByPageData($onlineformId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oFormOnline = DB_DataObject::factory($this->aConf['table']['rvs_project_page']);
$aCloneData = array();
$query = sprintf('
SELECT
page_name
FROM
%s
WHERE
page_data LIKE %s
'
, $this->aConf['table']['rvs_project_page']
, RvsLibs_String::quoteSmart('%'.$onlineformId.'%')
);
$oFormOnline->query($query);
while ($oFormOnline->fetch()) {
$aCloneData[] = clone($oFormOnline);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oFormOnline->_resultFields, $aCloneData, $fetchMode);
}
public function findJotFormQuestionPropertiesByFormId($FormId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oJotForm = DB_DataObject::factory($this->aConf['table']['question_properties']);
$query = sprintf('
SELECT
*
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['question_properties']
, RvsLibs_String::quoteSmart($FormId)
);
$oJotForm->query($query);
$aCloneData = array();
while ($oJotForm->fetch()) {
$aCloneData[] = clone($oJotForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oJotForm->_resultFields, $aCloneData, $fetchMode);
}
public function findJotFormQuestionsByFormId($FormId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oJotForm = DB_DataObject::factory($this->aConf['table']['questions']);
$query = sprintf('
SELECT
*
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['questions']
, RvsLibs_String::quoteSmart($FormId)
);
$oJotForm->query($query);
$aCloneData = array();
while ($oJotForm->fetch()) {
$aCloneData[] = clone($oJotForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oJotForm->_resultFields, $aCloneData, $fetchMode);
}
public function findJotFormQuestionUtf8ByFormId($FormId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel(0);
$oJotForm = DB_DataObject::factory($this->aConf['table']['question_utf8']);
$query = sprintf('
SELECT
*
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['question_utf8']
, RvsLibs_String::quoteSmart($FormId)
);
$oJotForm->query($query);
$aCloneData = array();
while ($oJotForm->fetch()) {
$aCloneData[] = clone($oJotForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oJotForm->_resultFields, $aCloneData, $fetchMode);
}
//*************************************** INSERT ***********************************************
/**
* insert step2 field
* @author pharadol
* @param <string> $rvsOnlineformId
* @param <string> $rvsUsrId
* @param <string> $projectPageId
* @param <string> $step2field
* form file Online_FormMgr.php
/*
$query = "
INSERT INTO
{$this->conf['table']['rvs_online_form']} (
rvs_onlineform_id
, rvs_usr_id
, project_page_id
, step2_field
)
VALUES (
'$rvsOnlineformId'
, '$rvsUsrId'
, '$projectPageId'
, " . RvsLibs_String::quoteSmart($step2field) . "
)
";
$res = $this->dbh->query($query);
*/
public function insertStep2Field($rvsOnlineformId, $rvsUsrId, $projectPageId, $step2field)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
INSERT INTO
%s
(
rvs_onlineform_id
, rvs_usr_id
, project_page_id
, step2_field
)
VALUES (
%s
, %s
, %s
, %s
)
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($rvsOnlineformId)
, RvsLibs_String::quoteSmart($rvsUsrId)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($step2field)
);
$oOnlineForm->query($query);
}
/**
* insert Dump form template
* @othor pharadol
*
* ///OPTIMIZE VARIABLE PASSING
* @param Array $aOnlineFormData
* [rvs_onlineform_template_id] - template id
* [online_form] - online form
* [step2_field] - field step2
* [mailaccount] - mail account
* [mailsubject] - mail subject
* [thankmsg] - thank message
* [mailbanedlist] -
* [onlineform_layout] - online form layout
* [projectPageId] - project page id
* [rvsUsrId] - rvs user id
* [rvsOnlineformId] - online form id
* [projectId] - project id
*
*/
public function insertDumpFormTemplate($aOnlineFormData)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
INSERT INTO
%s
(
rvs_onlineform_id ,
rvs_usr_id ,
project_page_id ,
project_id,
online_form ,
step2_field ,
button ,
mailaccount ,
maildomain ,
mailsubject ,
thankmsg ,
mailbanedlist ,
onlineform_layout
)
VALUES (
%s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
, %s
)
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($aOnlineFormData['rvsOnlineformId'])
, RvsLibs_String::quoteSmart($aOnlineFormData['rvsUsrId'])
, RvsLibs_String::quoteSmart($aOnlineFormData['projectPageId'])
, RvsLibs_String::quoteSmart($aOnlineFormData['projectId'])
, RvsLibs_String::quoteSmart($aOnlineFormData['online_form'])
, RvsLibs_String::quoteSmart($aOnlineFormData['step2_field'])
, RvsLibs_String::quoteSmart($aOnlineFormData['button'])
, RvsLibs_String::quoteSmart($aOnlineFormData['mailaccount'])
, RvsLibs_String::quoteSmart($aOnlineFormData['maildomain'])
, RvsLibs_String::quoteSmart($aOnlineFormData['mailsubject'])
, RvsLibs_String::quoteSmart($aOnlineFormData['thankmsg'])
, RvsLibs_String::quoteSmart($aOnlineFormData['mailbanedlist'])
, RvsLibs_String::quoteSmart($aOnlineFormData['onlineform_layout'])
);
$oOnlineForm->query($query);
}
//*************************************** UPDATE **********************************************//
/**
* Update UsrId And ProjectPageId By rvs_project_page, rvs_usr_id, rvs_onlineform_id
* Resulting SQL
* $query = sprintf('
* UPDATE
* %s as olf
* , %s as pa
* SET
* olf.rvs_usr_id = %s
* , olf.project_page_id =%s
* WHERE
* pa.project_page_id = %s
* AND pa.rvs_usr_id = %s
* AND olf.rvs_onlineform_id = %s
* '
* , $this->aConf['table']['rvs_online_form']
* , $this->aConf['table']['rvs_project_page']
* , RvsLibs_String::quoteSmart($rvsUsrId)
* , RvsLibs_String::quoteSmart($projectPageId)
* , RvsLibs_String::quoteSmart($projectPageId)
* , RvsLibs_String::quoteSmart($rvsUsrId)
* , RvsLibs_String::quoteSmart($onlineformId)
* );
*
* @ @author duangdao.k
* @param string $rvsUsrId
* @param string $projectPageId
* @param string $onlineformId
* @return bool
*/
public function updateUsrIdAndProjectPageIdByProjectPageId($rvsUsrId = null, $projectPageId = null, $onlineformId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s as olf
, %s as pa
SET
olf.rvs_usr_id = %s
, olf.project_page_id =%s
WHERE
pa.project_page_id = %s
AND pa.rvs_usr_id = %s
AND olf.rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, $this->aConf['table']['rvs_project_page']
, RvsLibs_String::quoteSmart($rvsUsrId)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($rvsUsrId)
, RvsLibs_String::quoteSmart($onlineformId)
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return $res;
}
/**
* Update form mail by online form id and usrid
*
* @author pharadol
*
* ///OPTIMIZE VARIABLE PASSING
* @param array(
'rvsUsrId' => rvs user id
'onlineformId' => online form id
'step5MailBanlist' => mail banlist
'step5ThankMSG' => message thank
'step5MailSubject' => mail subject
'step5MailDomain' => mail domain
'step5MailAccount' => mail account
);
* @return bool
* form file Online_FormMgr.php
*/
public function updateFormmailByOnlineFormIdAndUsrId($aFormMailData)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s
SET
mailaccount = %s
, maildomain = %s
, mailsubject = %s
, thankmsg = %s
, mailbanedlist = %s
WHERE
rvs_onlineform_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($aFormMailData['step5MailAccount'])
, RvsLibs_String::quoteSmart($aFormMailData['step5MailDomain'])
, RvsLibs_String::quoteSmart($aFormMailData['step5MailSubject'])
, RvsLibs_String::quoteSmart($aFormMailData['step5ThankMSG'])
, RvsLibs_String::quoteSmart($aFormMailData['step5MailBanlist'])
, RvsLibs_String::quoteSmart($aFormMailData['onlineformId'])
, RvsLibs_String::quoteSmart($aFormMailData['rvsUsrId'])
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res) ? true : false;
}
/**
* Update onlineform by onlineformid and usrid
* @author pharadol
* @param <string> $rvsUsrId
* @param <string> $onlineformId
* @param <string> $projectPageId
* @param <string> $button
* @param <string> $form
* @return bool
* form file Onlie_FormMgr.php
/*
$query = "
UPDATE
{$this->conf['table']['rvs_online_form']}
SET
online_form = " . RvsLibs_String::quoteSmart($form) . "
, button = '$button'
, project_page_id = '" . SGL_Session::get('project_page_id') . "'
WHERE
rvs_onlineform_id = '$onlineformId'
AND rvs_usr_id = '$rvsUsrId'
";
$res = $this->dbh->query($query);
*/
public function updateOnlineFormByOnlineFormIdAndUsrId($rvsUsrId, $onlineformId, $projectPageId, $button, $form)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s
SET
online_form = %s
, button = %s
, project_page_id = %s
WHERE
rvs_onlineform_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($form)
, RvsLibs_String::quoteSmart($button)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($onlineformId)
, RvsLibs_String::quoteSmart($rvsUsrId)
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res)? true : false;
}
/**
* update step2 data by usrid and onlineform id
* @author pharadol
* @param <string> $rvsUsrId
* @param <string> $formId
* @param <string> $projectPageId
* @param <string> $step2field
* @return bool
* form file Online_FormMgr.php
*/
public function updateStep2DataByUsrIdAndOnlineFormId($rvsUsrId, $formId, $projectPageId, $step2field)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s
SET
step2_field = %s
, project_page_id = %s
WHERE
rvs_onlineform_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($step2field)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($formId)
, RvsLibs_String::quoteSmart($rvsUsrId)
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res)? true : false;
}
/**
* update Online Form layout by usrid and online form id
* @author pharadol
* @param <string> $rvsUsrId
* @param <string> $onlineFormId
* @param <string> $projectPageId
* @param <string> $onlineFormLayout
* @return bool
* form file Online_FormMgr.php
/*
$query = "
UPDATE
{$this->conf['table']['rvs_online_form']}
SET
onlineform_layout = " . RvsLibs_String::quoteSmart($onlineFormLayout) . "
, project_page_id = '" . SGL_Session::get('project_page_id') . "'
WHERE
rvs_onlineform_id = '$onlineFormId'
AND rvs_usr_id = '$rvsUsrId'
";
$res = $this->dbh->query($query);
*/
public function updateOnlineFormLayoutByUsrIdAndOnlineFormId($rvsUsrId, $onlineFormId, $projectPageId, $onlineFormLayout)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s
SET
onlineform_layout = %s
, project_page_id = %s
WHERE
rvs_onlineform_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($onlineFormLayout)
, RvsLibs_String::quoteSmart($projectPageId)
, RvsLibs_String::quoteSmart($onlineFormId)
, RvsLibs_String::quoteSmart($rvsUsrId)
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return (isset($res) && $res)? true : false;
}
/**
* update Mail Domain By OnlineFormId And UsrId in rvs_online_form table
* Resulting SQL
* UPDATE
* rvs_online_form
* SET
* maildomain = {$mailDomain}
* WHERE
* rvs_onlineform_id = {$onlineFormID}
* AND rvs_usr_id = {$userID}
* @author Pornthip Phothong
* @param <string> $mailDomain
* @param <string> $onlineFormID
* @param <string> $userID
* form file CreateProjectMgr.php
*/
public function updateMailDomainByOnlineFormIdAndUsrId($mailDomain, $onlineFormID, $userID)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
$query = sprintf('
UPDATE
%s
SET
maildomain = %s
WHERE
rvs_onlineform_id = %s
AND rvs_usr_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($mailDomain)
, RvsLibs_String::quoteSmart($onlineFormID)
, RvsLibs_String::quoteSmart($userID)
);
$res = $oOnlineForm->query($query);
DB_DataObject::debugLevel();
return $res;
}
//***************************************DELETE *******************************************
/**
* delete online form by userid and projectid
* $query = "
DELETE
{$this->conf['table']['rvs_online_form']} as olf
FROM
{$this->conf['table']['rvs_online_form']} as olf
, {$this->conf['table']['rvs_project_page']} as pa
, {$this->conf['table']['rvs_project_layout_page']} as pl
WHERE
pa.project_page_id = pl.project_page_id
AND olf.rvs_onlineform_id = '$rvsOnlineformId'
AND pa.project_page_id = '$pageId'
AND pa.rvs_usr_id = '$input->rvs_usr_id'
AND pl.project_id = '$input->project_id'
";
* @author Pharadol
* @param <string> $rvsOnlineformId
* @param <string> $pageId
* @param <string> $projectId
* @param <string> $usrId
* @return <array>
*/
public function deleteOnlineFormByUsrIdAndProjectId($rvsOnlineformId = null, $pageId = null, $projectId = null, $usrId = null)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($rvsOnlineformId) && !is_null($pageId) && !is_null($projectId) && !is_null($usrId)) {
/*
$query = sprintf('
DELETE
%s as olf
FROM
%s as olf
, %s as pa
, %s as pl
WHERE
pa.project_page_id = pl.project_page_id
AND pa.rvs_usr_id = %s
AND pl.project_id = %s
'
, $this->aConf['table']['rvs_online_form']
, $this->aConf['table']['rvs_online_form']
, $this->aConf['table']['rvs_project_page']
, $this->aConf['table']['rvs_project_layout_page']
, RvsLibs_String::quoteSmart($rvsOnlineformId)
, RvsLibs_String::quoteSmart($pageId)
, RvsLibs_String::quoteSmart($usrId)
, RvsLibs_String::quoteSmart($projectId)
);
*/
$query = sprintf('
DELETE
FROM
%s
WHERE
rvs_onlineform_id = %s
AND project_page_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($rvsOnlineformId)
, RvsLibs_String::quoteSmart($pageId)
);
$res = $oOnlineForm->query($query);
}
return (isset($res) && $res) ? true : false;
}
public function fineOnlineFormByProjectPageId($projectPageId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($projectPageId)) {
$oOnlineForm->project_page_id = $projectPageId;
}
$oOnlineForm->find();
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, $fetchMode);
}
public function findFormTemplateIdByProjectPageId($projectPageId, $fetchMode = 'getassoc')
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oProjectPage = DB_DataObject::factory($this->aConf['table']['rvs_project_page']);
$oProjectPage->selectAdd();
$oProjectPage->selectAdd('form_template_id');
if (!is_null($projectPageId)) {
$oProjectPage->project_page_id = $projectPageId;
$oProjectPage->find();
}
$aCloneData = array();
while ($oProjectPage->fetch()) {
$aCloneData[] = clone($oProjectPage);
}
DB_DataObject::debugLevel();
return DbWrapper::fetchDatas($oProjectPage->_resultFields, $aCloneData, $fetchMode);
}
/**
* find online form id in project
* @param $projectId
* @param $aProjectPageId
* @return array(0=>'formId1',1=>'formId2')
*/
private function findFormInProject($projectId, $aProjectPageId)
{
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
///Select form id by project_page_id
$strPageId = implode('\',\'', array_keys($aProjectPageId));
$sql = 'SELECT
rvs_onlineform_id
FROM '
. $this->aConf['table']['rvs_online_form'] . '
WHERE
project_page_id IN(\''. $strPageId .'\');';
$oOnlineForm->query($sql);
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
$res = DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, 'getassoc');
///Select form id by project_id
$sql = 'SELECT
rvs_onlineform_id
FROM '
. $this->aConf['table']['rvs_online_form'] . '
WHERE
project_id='. RvsLibs_String::quoteSmart($projectId) .';';
$oOnlineForm->query($sql);
$aCloneData = array();
while ($oOnlineForm->fetch()) {
$aCloneData[] = clone($oOnlineForm);
}
$res2 = DbWrapper::fetchDatas($oOnlineForm->_resultFields, $aCloneData, 'getassoc');
$res = array_merge($res, $res2);
return array_keys($res);
}
public function backupsql($projectId, $usrId, $aFormID=array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aSQLData = array();
if (count($aFormID) <= 0) {
/// Get $aProjectPageId From rvs_project_layout_page by project_id
$aProjectPageId = DaoFactory::ProjectLayoutPage()->findProjectLayoutPage($projectId, 'getassoc');
/// Get $aProjectPageId From internal page
$aInternalPage = DaoFactory::InternalPage()->findInternalProjectPageIdByProjectId($projectId, 'getassoc', $aResultFields = array('project_page_id'));
$aProjectPageId = array_merge($aProjectPageId, $aInternalPage);
$aFormID = $this->findFormInProject($projectId, $aProjectPageId);
}
/// Backup rvs_online_form by project_page_id
foreach ($aFormID as $key => $val) {
$oOnlineForm = $this->fineOnlineFormByOnlineFormId($val, 'getDataObject', array());
foreach ($oOnlineForm as $k => $v) {
$aSQLData[] = DbWrapper::buildSQLFormat($v);
}
}
/*
// backup jotform
$oJotform = DaoFactory::OnlineForm()->findListJotFormByProjectId($projectId, 'getDataObject');
foreach ($oJotform as $key => $value) {
$aSQLData[] = DbWrapper::buildSQLFormat($value);
$oSqlQuestions = DaoFactory::OnlineForm()->findJotFormQuestionsByFormId($value->id, 'getDataObject');
foreach ($oSqlQuestions as $keyQuestions => $valQuestions) {
$aSQLData[] = DbWrapper::buildSQLFormat($valQuestions);
}
$oSqlQuestionProperties = DaoFactory::OnlineForm()->findJotFormQuestionPropertiesByFormId($value->id, 'getDataObject');
foreach ($oSqlQuestionProperties as $keyProperties => $valProperties) {
$aSQLData[] = DbWrapper::buildSQLFormat($valProperties);
}
$oSqlQuestionUtf8 = DaoFactory::OnlineForm()->findJotFormQuestionUtf8ByFormId($value->id, 'getDataObject');
foreach ($oSqlQuestionUtf8 as $key => $val) {
$aSQLData[] = DbWrapper::buildSQLFormat($val);
}
}
*/
return $aSQLData;
}
public function deleteProjectOfUserId($projectId, $usrId, $aProjectPageId = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
///@TODO : delete online form
$oJotform = DaoFactory::OnlineForm()->findListJotFormByProjectId($projectId, 'getall');
foreach ($oJotform as $key => $value) {
// $aSQLData[] = DbWrapper::buildSQLFormat($value);
$delSqlQuestions = DaoFactory::OnlineForm()->deleteJotFormQuestionsByFormId($value->id);
$delSqlQuestionsProPer = DaoFactory::OnlineForm()->deleteJotFormQuestionsPropertiesByFormId($value->id);
}
$delSqlForms = DaoFactory::OnlineForm()->deleteJotFormByProjectId($projectId);
}
/**deleteOnlineFormDataByFormId
* @author Pornthip Phothong
* @param <string> $formId
* @return bool
* not unit test
*/
public function deleteOnlineFormDataByFormId($formId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oOnlineForm = DB_DataObject::factory($this->aConf['table']['rvs_online_form']);
if (!is_null($formId)) {
$query = sprintf('
DELETE
FROM
%s
WHERE
rvs_onlineform_id = %s
'
, $this->aConf['table']['rvs_online_form']
, RvsLibs_String::quoteSmart($formId)
);
$res = $oOnlineForm->query($query);
}
return (isset($res) && $res) ? true : false;
}
/**
*
* @param unknown_type $projectId
* @return unknown_type
*/
public function deleteJotFormByProjectId($projectId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oJotForm = DB_DataObject::factory($this->aConf['table']['forms']);
if (!is_null($projectId)) {
$query = sprintf('
DELETE
FROM
%s
WHERE
username = %s
'
, $this->aConf['table']['forms']
, RvsLibs_String::quoteSmart($projectId)
);
$res = $oJotForm->query($query);
}
return (isset($res) && $res) ? true : false;
}
/**
*
* @param $formId
* @return unknown_type
*/
public function deleteJotFormQuestionsByFormId($formId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oJotForm = DB_DataObject::factory($this->aConf['table']['questions']);
if (!is_null($formId)) {
$query = sprintf('
DELETE
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['questions']
, RvsLibs_String::quoteSmart($formId)
);
$res = $oJotForm->query($query);
}
return (isset($res) && $res) ? true : false;
}
/**
*
* @param $formId
* @return unknown_type
*/
public function deleteJotFormQuestionsPropertiesByFormId($formId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
DB_DataObject::debugLevel();
$oJotForm = DB_DataObject::factory($this->aConf['table']['question_properties']);
if (!is_null($formId)) {
$query = sprintf('
DELETE
FROM
%s
WHERE
form_id = %s
'
, $this->aConf['table']['question_properties']
, RvsLibs_String::quoteSmart($formId)
);
$res = $oJotForm->query($query);
}
return (isset($res) && $res) ? true : false;
}
}
?>
Copyright 2K16 - 2K18 Indonesian Hacker Rulez