File: //opt/cloudlinux/alt-php54/root/usr/share/pear/RVSeagullMod/modules/tryout/classes/TemplateList.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: Main.php,v 1.101 2006/04/25 10:35:39 thiraphat Exp $
// +---------------------------------------------------------------------------+
/**
* Type program description here...
*
* @package sitebuilder
* @author Charnchai <charnchai@rvglobalsoft.com>
* @version $Revision: 1.101 $
* @since PHP 4.1
*/
class TemplateList extends SGL_Manager
{
var $aConf;
var $objDbh;
function TemplateList()
{
parent::SGL_Manager();
$this->aConf = $this->conf;
$this->objDbh = $this->dbh;
}
function registRvsConf($conf = null, $dbh = null)
{
if ( $conf != null) {
$this->aConf = $conf;
}
if ( $dbh != null) {
$this->objDbh = $dbh;
}
}
public static function singleton($autoLoad = false, $oFreeze=null)
{
static $instance;
if (is_null($oFreeze) === false) {
$instance = $oFreeze;
}
if (!isset($instance) || $autoLoad) {
$class = __CLASS__;
$instance = new $class($autoLoad);
}
return $instance;
}
// select template id relation
function _getTemplate(&$input)
{
// picture_type = 0,1 category_id template_type_id
SGL::logMessage(null, PEAR_LOG_DEBUG);
$input->category_id = isset($input->category_id) ? $input->category_id : '';
$input->template_type_id = isset($input->template_type_id) ? $input->template_type_id : '';
if ((isset($input->import_template_style) && $input->import_template_style)) {
//เป็นการค้นหา ImportTemplate ทั้งหมด ซึ่งไม่รวมถึง DIY Template
$aTemplate = DaoFactory::TemplateImport()->findAllImportTemplate();
} else if ((isset($input->productIdSearch) && $input->productIdSearch != "")) {
//เป็นการค้นหา Template ทั้งหมด
$aTemplate = DaoFactory::TemplateImport()->findAllTemplate();
} else {
if (isset($input->aAllTemplate) && count($input->aAllTemplate) == 1) {
$strId = implode('', $input->aAllTemplate);
} elseif (isset($input->aAllTemplate) && count($input->aAllTemplate > 1)) {
$strId = implode("','", $input->aAllTemplate);
} else {
$strId = '';
}
//เป็นการค้นหา Template ทั้งหมด ตามประเภทของ Categories และ Templates
$aTemplate = DaoFactory::Template()->findDataTemplateByCategoryIdOrTemplateTypeId($input->category_id, $input->template_type_id, 'getassoc', $strId);
}
if ($aTemplate) {
return $aTemplate;
}
}
function _getCurrentTemplate(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aCurrentTemplate = array();
$this->registRvsConf($this->aConf, $this->objDbh);
if ($input->ref_category_id && $input->ref_template_item_id) {
$showTemplateItem = $this->_getRefTemplatesData($input);
$aTemplateData = RvsLibs_Template::getTemplatesData($input->project_id, true);
foreach ($showTemplateItem as $k=>$v) {
if (is_dir(RvsLibs_File::buildPath(array($aTemplateData->templatePath, $v->template_item_folder)))) {
$aProductsId = RvsLibs_String::dbeExplode('-', $v->products_id);
$aCurrentTemplate['products_id'] = $aProductsId[0] . '-' . $aProductsId[1];
$aCurrentTemplate['template_item_id'] = $v->template_item_id;
$aCurrentTemplate['template_id'] = $v->template_id;
$aCurrentTemplate['category_name'] = $v->category_name;
$aCurrentTemplate['color_name'] = $v->color_name;
$aCurrentTemplate['picture_name'] = RvsLibs_String::ucfirst($v->picture_name);
$aCurrentTemplate['category_sh_name'] = (isset($v->category_sh_name)) ? $v->category_sh_name : "";
$aCurrentTemplate['template_path'] = $aTemplateData->templatePath;
$aCurrentTemplate['template_url'] = $aTemplateData->templateUrl;
$aCurrentTemplate['template_item_folder'] = $v->template_item_folder;
$aCurrentTemplate['template_type_s_preview'] = $v->template_type_s_preview;
$aCurrentTemplate['pre_'] = 'cur_';
// set current object
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id] = new stdClass();
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->template_item_id = $v->template_item_id;
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->template_id = $aTemplateData->template_id;
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->template_item_folder = $v->template_item_folder;
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->template_type_s_preview = $v->template_type_s_preview;
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->products_id = $aProductsId[0] . '-' . $aProductsId[1];
$aCurrentTemplate['set_template_current'][$aTemplateData->template_id]->picture_id = $aTemplateData->picture_id;
}
// warning msg template_item_id case click editwebsite จาก step Home : nipaporn
if ($aTemplateData->template_item_id && $aTemplateData->templatePath && is_dir($aTemplateData->templatePath) === false) {
SGL::raiseMsg('Please choose template of step 1', true, SGL_MESSAGE_WARNING);
}
}
} else {
$aCurrentTemplate = $this->_getCategoryData($input, $this->objDbh);
}
return $aCurrentTemplate;
}
function _listTemplateType(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aTemplateType = $this->getListTemplateType();
$input->submitUserImport = isset($input->submitUserImport) ? $input->submitUserImport : false;
$aTemplateType = $this->getTranslation($aTemplateType);
if ($aTemplateType) {
$selectTemplateType = SGL_Output::generateSelect($aTemplateType, $input->template_type_id);
return $selectTemplateType;
}
}
/**
* unSetDownloadTemplate :: Witoon
*
* @param Array $aTemplateType
* @param Boolean $submitUserImport
* @return Array
*/
function unSetDownloadTemplate($aTemplateType, $submitUserImport)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
// download template not show template type DIY Template : ID = 10 ref_id table rvs_template_type
if (isset($submitUserImport) && $submitUserImport && isset($aTemplateType[10])) {
unset($aTemplateType[10]);
}
return $aTemplateType;
}
/**
* getListTemplateType :: Witoon
*
* @return Array
*/
function getListTemplateType()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//optimize : siwakorn
return DaoFactory::Template()->findTemplateTypeData('getassoc',array('template_type_id','template_type_name'));
}
function _listCategory($categoryId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aCategory = $this->getCategoryList();
$aCategory = $this->getTranslation($aCategory);
if ($aCategory) {
//optimize : siwakorn
return SGL_Output::generateSelect($aCategory, $categoryId);
}
}
/**
* Get Category list :: Witoon
*
* @return Array
*/
function getCategoryList()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//optimize : siwakorn
return DaoFactory::Category()->findAllCategoryData('getvalue');
}
function getUsrStatus()
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$rvsUsrId = RvsLibs_User::getUserId();
$rvsRootId = RvsLibs_User::getRootId();
if ($rvsUsrId == $rvsRootId) {
$rvsUsrStatus = RVS_ROOT_USER_NAME;
} elseif ((RVS_IS_RESELLER == '1') && ($rvsUsrId != $rvsRootId)) {
$rvsUsrStatus = 'reseller';
} else {
$rvsUsrStatus = 'user';
}
return $rvsUsrStatus;
}
function _newGenerateCodeHTMLCategory(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$this->registRvsConf($this->aConf, $this->objDbh);
$showData = $this->_newGetAllTemplateData($input,$this->objDbh);
$showData = isset($input->aTemplateDefault) ? $input->aTemplateDefault : $showData;
$templateTotalSelect = count($showData);
$input->aSafeTemplates = $showData;
// $this->_pager($input, $aErrors);
// $showData = $input->showData;
$decreaseTotal = 0;
// $showDataTem = array();
$aShowData = array();
$refTemplateItemId = (isset($input->ref_template_item_id)) ? $input->ref_template_item_id : null;
$input->noLink = isset($input->noLink) ? $input->noLink : '';
$input->ref_template_item_id = isset($input->ref_template_item_id) ? $input->ref_template_item_id : '';
// $showDataTem = $showData;
$showDataTem = $this->newSetTemplateOutput($showData, $refTemplateItemId, $input->noLink);
$decreaseTotal = $showDataTem[1];
$input->template_total_select = $templateTotalSelect - $decreaseTotal;
if(isset($input->managerName) && $input->managerName == 'rvscategory') {
$aCategoryData = $this->_getCurrentTemplate($input);
if (isset($aCategoryData['template_item_id']) && $aCategoryData['template_item_id'] != ''
&& isset($aCategoryData['template_id']) && $aCategoryData['template_id'] != '' ) {
$aCategoryData['is_current'] = true;
$aCategoryData['reuploadIcon'] = RvsLibs_Template::isAllowToReuploadTemplate($aCategoryData['template_item_folder']);
if (RvsLibs_Template::isDiyTemplate($aCategoryData['template_path'], $aCategoryData['template_item_folder'])) {
$aCategoryData['isDiyTemplate'] = true;
}
array_push($aShowData, $aCategoryData);
}
}
//optimize : siwakorn
return $showDataTem[0];//$this->newGenShowCorlum($showDataTem[0], $aShowData);
}
function _generateCodeHTMLCategory(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$this->registRvsConf($this->aConf, $this->objDbh);
$allTemplatePath = SGL_WEB_ROOT . '/' . RvsLibs_Project::getJsCssPathV5('js/rvsitebuilder/allTemplate.js');
$aAllTemplate = array();
$content = file_get_contents($allTemplatePath);
if (preg_match('/var\s*showDataTemplate\s*=\s*(\{[\d\D\b\B\w\W]*\});\s*$/ims', $content, $aMatch)) {
$aAllTemplate = json_decode($aMatch[1], true);
$aAllTemplate = array_keys($aAllTemplate);
}
$input->aAllTemplate = $aAllTemplate;
$showData = $this->_getAllTemplateData($input, $this->objDbh);
$showData = isset($input->aTemplateDefault) ? $input->aTemplateDefault : $showData;
$templateTotalSelect = count($showData);
$input->aSafeTemplates = $showData;
$this->_pager($input, $aErrors);
$showData = $input->showData;
$decreaseTotal = 0;
$showDataTem = array();
$aShowData = array();
$refTemplateItemId = (isset($input->ref_template_item_id)) ? $input->ref_template_item_id : null;
$input->noLink = isset($input->noLink) ? $input->noLink : '';
$input->ref_template_item_id = isset($input->ref_template_item_id) ? $input->ref_template_item_id : '';
$showDataTem = $this->setTemplateOutput($showData, $refTemplateItemId, $input->noLink);
$decreaseTotal = $showDataTem[1];
$input->template_total_select = $templateTotalSelect - $decreaseTotal;
if(isset($input->managerName) && $input->managerName == 'rvscategory') {
$aCategoryData = $this->_getCurrentTemplate($input);
if (isset($aCategoryData['template_item_id']) && $aCategoryData['template_item_id'] != ''
&& isset($aCategoryData['template_id']) && $aCategoryData['template_id'] != '' ) {
$aCategoryData['is_current'] = true;
$aCategoryData['reuploadIcon'] = RvsLibs_Template::isAllowToReuploadTemplate($aCategoryData['template_item_folder']);
//is Uikit
if (RvsLibs_Template::isUikitTemplate($aCategoryData['template_path'], $aCategoryData['template_item_folder'])) {
$aCategoryData['isUikit'] = true;
}
if (RvsLibs_Template::isDiyTemplate($aCategoryData['template_path'], $aCategoryData['template_item_folder'])) {
$aCategoryData['isDiyTemplate'] = true;
if (isset($aCategoryData['isUikit']) == true) {
$aCategoryData['isDiyTemplateUikit'] = true;
}
}
array_push($aShowData, $aCategoryData);
}
}
//optimize : siwakorn
return $this->genShowCorlum($showDataTem[0], $aShowData);
}
function newSetTemplateOutput($showData, $ref_template_item_id, $noLink)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aReturnData = array();
$aTemplate = array();
$aRow = array();
$aRow2 = array();
$decreaseTotal = 0;
$license = RvsLibs_License::getSitebuilderLicense();
SGL::logMessage('_listColor', PEAR_LOG_DEBUG);
if (count($showData)) {
foreach ($showData as $k=>$v) {
$rvsUsrId = (!isset($v->rvs_usr_id)) ? "" : $v->rvs_usr_id;
$aProductsId = RvsLibs_String::dbeExplode('-', $v->products_id);
$aProductsId[0] = isset($aProductsId[0]) ? $aProductsId[0] : '';
$aProductsId[1] = isset($aProductsId[1]) ? $aProductsId[1] : '';
$productId = $aProductsId[0] . '-' . $aProductsId[1];
//$aColorData = $this->_listColor($v->template_id, $v->picture_id,$this->objDbh);
$aColorData = $this->_newlistColor($v->template_id, $v->picture_id,$this->objDbh);
$aTemplatePathUrl = RvsLibs_Template::getTemplatePathUrl($rvsUsrId, $v->template_item_folder, $action = 'view');
// $aTemplateItem = DaoFactory::Template()->findTemplateItemFolderByTemplateId($v->template_id, 'getvalue');
if ($aTemplatePathUrl) {
$aTemplate = array(
//'is_current' => false,
'template_item_id' => $v->template_item_id,
'template_id' => $v->template_id,
'template_item_folder' => $v->template_item_folder,
'template_type_s_preview' => $v->template_type_s_preview,
'color_id' => $aColorData['color_id'],
'products_id' => $productId,
'total_pic' => $aColorData['total_pic'],
'template_type_id' => $v->template_type_id,
'menustyle_id' => $v->menustyle_id,
//'aTemplateFolder' =>$aTemplateItem
);
//show template import
if (RvsLibs_Template::isValidTemplate($rvsUsrId, $v->template_item_folder)) {
$aTemplate['isImport'] = true;
$isMyTemplateImport = RvsLibs_Template::isMyTemplateImport($v->template_item_folder);
SGL::logMessage('ajax $isMyTemplateImport:' . $isMyTemplateImport, PEAR_LOG_DEBUG);
//is delete icon
if (!$this->isTemplateImportUsed($v->template_item_id)
&& $isMyTemplateImport === true) {
$aTemplate['deleteIcon'] = true;
}
$aTemplate['reuploadIcon'] = RvsLibs_Template::isAllowToReuploadTemplate($v->template_item_folder);
//is Uikit
if (RvsLibs_Template::isUikitTemplate($aTemplatePathUrl['path'], $v->template_item_folder)) {
$aTemplate['isUikit'] = true;
}
//is DiyTemplate
if (RvsLibs_Template::isDiyTemplate($aTemplatePathUrl['path'], $v->template_item_folder)) {
$aTemplate['isDiyTemplate'] = true;
$aTemplate['reuploadIcon'] = false;
if (isset($aTemplate['isUikit']) == true) {
$aTemplate['isDiyTemplateUikit'] = true;
}
}
$aTemplate['template_path'] = $aTemplatePathUrl['path'];
$aTemplate['template_url'] = $aTemplatePathUrl['url'];
//check template import is responsive
$aTemplate['isResponsive'] = false;
if (RvsLibs_Template::isResponsiveTemplate($aTemplatePathUrl['path'] . '/' . $v->template_item_folder)) {
$aTemplate['isResponsive'] = true;
}
}
}
$aRow[$v->template_id] = $aTemplate;
//array_push($aRow, $aTemplate);
$aTemplate = array();
}//endforeac
}
$aReturnData[0] = $aRow;
$aReturnData[1] = $decreaseTotal;
return $aReturnData;
}
/**
* setTemplateOutput :: Witoon
*
* @param Array $showData
* @param String $ref_template_item_id
* @param String $ref_template_item_id
* @param Boolean $noLink
* @return Array
*/
function setTemplateOutput($showData, $ref_template_item_id, $noLink)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aReturnData = array();
$aTemplate = array();
$aRow = array();
$decreaseTotal = 0;
$license = RvsLibs_License::getSitebuilderLicense();
SGL::logMessage('_listColor', PEAR_LOG_DEBUG);
foreach ($showData as $k=>$v) {
$rvsUsrId = (!isset($v->rvs_usr_id)) ? "" : $v->rvs_usr_id;
$aProductsId = RvsLibs_String::dbeExplode('-', $v->products_id);
$aProductsId[0] = isset($aProductsId[0]) ? $aProductsId[0] : '';
$aProductsId[1] = isset($aProductsId[1]) ? $aProductsId[1] : '';
$productId = $aProductsId[0] . '-' . $aProductsId[1];
$aColorData = $this->_listColor($v->template_id, $v->picture_id,$this->objDbh);
$aTemplatePathUrl = RvsLibs_Template::getTemplatePathUrl($rvsUsrId, $v->template_item_folder, $action = 'view');
if ($aTemplatePathUrl) {
$aTemplate = array (
'is_current' => false,
'template_item_id' => $v->template_item_id,
'template_id' => $v->template_id,
'template_path' => $aTemplatePathUrl['path'],
'template_url' => $aTemplatePathUrl['url'],
'template_item_folder' => $v->template_item_folder,
'template_type_s_preview' => $v->template_type_s_preview,
'color_id' => $aColorData['color_id'],
'products_id' => $productId,
'total_pic' => $aColorData['total_pic'],
'template_type_id' => isset($v->template_type_id) ? $v->template_type_id :'',
'menustyle_id' => isset($v->menustyle_id) ? $v->menustyle_id : ''
);
// set default_color_id , set default_picture_id
foreach ($aTemplate['color_id'] as $v) {
if ($v->template_item_id == $v->template_item_id) {
$aTemplate['default_color_id'] = $v->color_id;
$aTemplate['default_picture_id'] = $v->picture_id;
}
}
//show template import
if (RvsLibs_Template::isValidTemplate($rvsUsrId, $v->template_item_folder)) {
SGL::logMessage('ajax ===== 00000', PEAR_LOG_DEBUG);
$aTemplate['isImport'] = true;
$isMyTemplateImport = RvsLibs_Template::isMyTemplateImport($v->template_item_folder);
//is delete icon
if (!$this->isTemplateImportUsed($v->template_item_id)
&& $isMyTemplateImport === true) {
$aTemplate['deleteIcon'] = true;
}
$aTemplate['reuploadIcon'] = RvsLibs_Template::isAllowToReuploadTemplate($v->template_item_folder);
///TODO :: ปรับการ load responsive template
//is DiyTemplate
if (file_exists(RvsLibs_File::buildPath(array($aTemplatePathUrl['path'], $v->template_item_folder, 'diyconf.ini.php')))) {
$aTemplate['isDiyTemplate'] = true;
}
}
}
array_push($aRow, $aTemplate);
$aTemplate = array();
}//endforeac
$aReturnData[0] = $aRow;
$aReturnData[1] = $decreaseTotal;
return $aReturnData;
}
/**
* genShowCorlum :: Witoon
*
* @param Array $aShowTemplateData
* @param Array $row
* @return Array
*/
function genShowCorlum($aShowTemplateData, $row = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aData = array();
$total = count($aShowTemplateData);
$intRow = count($aShowTemplateData) < 4 ? count($aShowTemplateData) : 4;
$i = 1;
foreach($aShowTemplateData as $key => $val) {
if ($val) {
array_push($row, $val);
if ($intRow < 4 && count($row) == ($intRow+1)) {
array_push($aData, $row);
$row = array();
} else {
if (count($row) == $intRow ) {
array_push($aData, $row);
$row = array();
}
//last row
if ($i == $total) {
array_push($aData, $row);
$row = array();
}
}
}
$i++;
}
return $aData;
}
function newGenShowCorlum($aShowTemplateData, $row = array())
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aData = array();
$total = count($aShowTemplateData);
$intRow = count($aShowTemplateData) < 4 ? count($aShowTemplateData) : 4;
$i = 1;
foreach($aShowTemplateData as $key => $val) {
if ($val) {
array_push($row, $val);
if ($intRow < 4 && count($row) == ($intRow+1)) {
array_push($aData, $row);
$row = array();
} else {
if (count($row) == $intRow ) {
array_push($aData, $row);
$row = array();
}
//last row
if ($i == $total) {
array_push($aData, $row);
$row = array();
}
}
}
$i++;
}
return $aData;
}
// select template data more detail
function _newGetAllTemplateData(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$req = SGL_Request::singleton();
$input->import_template_style = $req->get('import_template_style');
//defind array
$aTem1 = array();
$aTemplateDefault = array();
$aTotalTemplate = array();
$module = SGL_Request::singleton()->get('moduleName');
//_getTemplate()
if (isset($input->productIdSearch) && $input->productIdSearch != "" ) {
SGL::logMessage('L: ' . __LINE__ . 'RVS Search Product ID = ' . $input->productIdSearch, PEAR_LOG_DEBUG);
$joinProductIdSearch = join(RvsLibs_String::mb_split('[ ,#-]', $input->productIdSearch));
$joinProductIdSearch = ((RvsLibs_String::strlen($joinProductIdSearch) <= 0) || (RvsLibs_String::strlen($joinProductIdSearch) > 8))
? 'null' : $joinProductIdSearch;
$aTemplate = $this->_getTemplate($input, $this->objDbh);
$aTemplateDefault = DaoFactory::Template()->findTemplateByProductId($joinProductIdSearch,'getAssoc');
$aTemplateDefault = $this->_getImportTemplateData($aTemplate, $aTemplateDefault);
} elseif (isset($input->productIdSearch) && $input->productIdSearch == "") {
$aTemplateDefault = array();
} else {
$aTemplate = $this->_getTemplate($input, $this->objDbh);
if ($aTemplate) {
$selectCategoryId = $req->get('select_category_id');
if ($selectCategoryId == '0' || $selectCategoryId == 0) {
// หา all category ทั้งหมด ยกเว้น Diy and ImportTemplate
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdAllCategoryNoDiyImport($aTemplate, 'getAssoc');
} else if($selectCategoryId != 'DiyPicture') {
// หา category import template ไม่เอา diy
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdImport($selectCategoryId, $input->rvs_usr_id, $input->rvs_owner_usr_id,'getAssoc');
foreach ($aTemplateDefault as $k => $v) {
$aProduct = explode('-', $v->products_id);
if (RvsLibs_String::strlen($selectCategoryId) != 32) {
//case เป็น import จะไม่เอา custom
if (isset($aProduct[0]) && (RvsLibs_String::strlen($aProduct[0]) == 32)) {
unset($aTemplateDefault[$k]);
}
} else {
//case เป็น custom จะไม่เอา import
if (isset($aProduct[0]) && (RvsLibs_String::strlen($aProduct[0]) != 32)) {
unset($aTemplateDefault[$k]);
}
}
}
} else {
//หา เฉพราะ diy template
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdDiy($aTemplate, $selectCategoryId, 'getassoc');
}
$aTemplateDefault = $this->_getImportTemplateData($aTemplate, $aTemplateDefault);
}
}
if (count($aTemplateDefault)) {
$input->aTemplateDefault = $aTemplateDefault;
return $aTemplateDefault;
}
}
function getColorDBbyTemplateItem($aShowData)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//build colordb.ini.php by template_item_folder
$aTem['aColorData'] = array();
$aTem['aTemPro'] = array();
$aTem['aTemLite'] = array();
$aOldResTemplate = array();
$oldRestemplate = SGL_PATH . '/etc/oldResTemplate.txt';
if (is_file($oldRestemplate)) {
//file_get_contents($oldRestemplate);
$aOldResTemplate = json_decode(file_get_contents($oldRestemplate), true);
}
foreach ($aShowData as $templateId => $aValue) {
//split template / pro | lite
$aValue = is_object($aValue) ? (array)$aValue : $aValue;
$templateItemPath = TEMPLATE_PATH . '/' . $aValue['template_item_folder'];
/*
$aValue['isResponsive'] = RvsLibs_Template::isResponsiveTemplate($templateItemPath);
if ($aValue['isResponsive'] === false || in_array($aValue['template_item_folder'], $aOldResTemplate)) {
continue;
}*/
$aValue['isUikit'] = RvsLibs_Template::isUikitTemplate($templateItemPath);
if ($aValue['isUikit'] == false || in_array($aValue['template_item_folder'], $aOldResTemplate)) {
continue;
}
$aTem['aTemPro'][$templateId] = $aValue;
if (!preg_match('/^pro\_/',$aValue['template_item_folder'])) {
$aTem['aTemLite'][$templateId] = $aValue;
}
foreach ($aValue['color_id'] as $itemId => $obj) {
$path = TEMPLATE_PATH . '/' . $obj->template_item_folder . '/colordb.ini.php';
$aColor = self::getBgAndFontColorFromClassIndex(TEMPLATE_PATH, $obj->template_item_folder);
if (is_file($path)) {
$aTem['aColorData'][$obj->template_item_folder] = RvsLibs_Config::parse_ini_file($path, true);
}
$aTem['aColorData'][$obj->template_item_folder]['bodybgColor'] = $aColor['bodybgColor'];
$aTem['aColorData'][$obj->template_item_folder]['flash_img'] = $aColor['flash_img'];
}
}
if (count($aTem)) {
return $aTem;
}
}
function getBgAndFontColorFromClassIndex($templatePath, $templateItemFolder)
{
$aColor = array();
$aColor['flash_img'] = '';
$aColor['bodybgColor'] = '';
$path = $templatePath . '/' . $templateItemFolder . '/index.htm';
if (is_file($path) == true) {
$aPageCss = RvsLibs_File::file($templatePath . '/' . $templateItemFolder . '/index.htm');
$strPageCss = join("", $aPageCss);
if (preg_match("/bgcolor\s*=\s*[\"]?(.*?)[\"]/s",$strPageCss,$aTagBodyByClass)) {
$aColor['bodybgColor'] = $aTagBodyByClass[1];
}
if (preg_match_all("/value\s*=\s*\"images\/(.*?\.swf)/is",$strPageCss,$aFlash)) {
if(count($aFlash[1])) {
$aColor['flash_img'] = join(",", $aFlash[1]);
}
}
}
return $aColor;
}
// select template data more detail
function _getAllTemplateData(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$req = SGL_Request::singleton();
$input->import_template_style = $req->get('import_template_style');
//defind array
$aTem1 = array();
$aTemplateDefault = array();
$aTotalTemplate = array();
$module = SGL_Request::singleton()->get('moduleName');
//_getTemplate()
if (isset($input->productIdSearch) && $input->productIdSearch != "" ) {
SGL::logMessage('L: ' . __LINE__ . 'RVS Search Product ID = ' . $input->productIdSearch, PEAR_LOG_DEBUG);
$joinProductIdSearch = join(RvsLibs_String::mb_split('[ ,#-]', $input->productIdSearch));
$joinProductIdSearch = ((RvsLibs_String::strlen($joinProductIdSearch) <= 0) || (RvsLibs_String::strlen($joinProductIdSearch) > 8))
? 'null' : $joinProductIdSearch;
$aTemplate = $this->_getTemplate($input, $this->objDbh);
$aTemplateDefault = DaoFactory::Template()->findTemplateByProductId($joinProductIdSearch,'getAssoc');
$aTemplateDefault = $this->_getImportTemplateData($aTemplate, $aTemplateDefault);
} elseif (isset($input->productIdSearch) && $input->productIdSearch == "") {
$aTemplateDefault = array();
} else {
$aTemplate = $this->_getTemplate($input, $this->objDbh);
if ($aTemplate) {
$selectCategoryId = $req->get('select_category_id'); //SGL_Session::get('select_category_id');
if (empty($selectCategoryId)) {
SGL::logMessage('template_All category template', PEAR_LOG_DEBUG);
// All category template
$cache = &RvsLibs_File::rvsCache();
if ($data = $cache->get('findTemplateItemData', 'cachedata')) {
$aTemplateDefault = unserialize($data);
SGL::logMessage('=============== findTemplateItemData from cache', PEAR_LOG_DEBUG);
} else {
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdAllCategoryNoDiyImportReseller($aTemplate, 'getAssoc');
$aTemplateImport = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdImport('23', $input->rvs_usr_id, $input->rvs_owner_usr_id,'getAssoc');
foreach ($aTemplateImport as $k => $v) {
if (isset($aTemplateDefault[$k])) {
unset($aTemplateDefault[$k]);
}
}
$data = serialize($aTemplateDefault);
$cache->save($data, 'findTemplateItemData', 'cachedata');
SGL::logMessage('================ findTemplateItemData from db', PEAR_LOG_DEBUG);
}
} elseif ($selectCategoryId == 23) {
SGL::logMessage('template_category import template', PEAR_LOG_DEBUG);
// หา category import template
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdImport($selectCategoryId, $input->rvs_usr_id, $input->rvs_owner_usr_id,'getAssoc');
} else if($selectCategoryId != 'DiyPicture') {
SGL::logMessage('template_category', PEAR_LOG_DEBUG);
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateId($aTemplate, $selectCategoryId, 'getAssoc');
} else {
SGL::logMessage('template_diy template ', PEAR_LOG_DEBUG);
//หา เฉพราะ diy template
$aTemplateDefault = DaoFactory::Template()->findTemplateItemDataByGroupTemplateItemIdAndTemplateIdDiy($aTemplate, $selectCategoryId, 'getassoc');
}
foreach ($aTemplateDefault as $k => $v) {
$aProduct = explode('-', $v->products_id);
if (RvsLibs_String::strlen($selectCategoryId) != 32) {
//case เป็น import จะไม่เอา custom
if (isset($aProduct[0]) && (RvsLibs_String::strlen($aProduct[0]) == 32)) {
unset($aTemplateDefault[$k]);
}
} else {
//case เป็น custom จะไม่เอา import
if (isset($aProduct[0]) && (RvsLibs_String::strlen($aProduct[0]) != 32)) {
unset($aTemplateDefault[$k]);
}
}
//Unset from is not responsives in AllTemplate.js
if (isset($input->aAllTemplate) && !in_array($k, $input->aAllTemplate)) {
unset($aTemplateDefault[$k]);
}
}
}
$aTemplateDefault = $this->_getImportTemplateData($aTemplate, $aTemplateDefault);
}
if (count($aTemplateDefault)) {
$input->aTemplateDefault = $aTemplateDefault;
return $aTemplateDefault;
}
}
function _getImportTemplateData($aTemplate, $aTemplateDefault)
{
SGL::logMessage('_getImportTemplateData ------------->', PEAR_LOG_DEBUG);
$this->registRvsConf($this->aConf, $this->objDbh);
$aTem2 = DaoFactory::TemplateImport()->findTemplateImportByGroupTemplateId($aTemplate,'getAssoc');
$oCp = CpHandle::factory();
if (SGL::isError($oCp) === true) {
SGL_Error::pop();
return $aTemplateDefault;
}
foreach ($aTemplateDefault as $k=>$v) {
if (!isset($aTem2[$aTemplateDefault[$k]->template_id])) {
continue;
}
$module = SGL_Request::singleton()->get('moduleName');
$this->registRvsConf($this->aConf, $this->objDbh);
// validate tryout
if ($oCp->isVaildTemplatePrivate() && $module != 'rvuser' && isset($aTem2[$aTemplateDefault[$k]->template_id]->private)) {
if ( RvsLibs_String::trim($aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id) == RvsLibs_String::trim(RvsLibs_User::getUserId()) ) {
$aTemplateDefault[$k]->rvs_usr_id = $aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id;
$aTemplateDefault[$k]->private = $aTem2[$aTemplateDefault[$k]->template_id]->private;
} else {
unset($aTemplateDefault[$k]);
}
} elseif (isset($aTem2[$aTemplateDefault[$k]->template_id]) && $this->_privateTemplateFilter( $aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id, $aTem2[$aTemplateDefault[$k]->template_id]->private)) {
$aTemplateDefault[$k]->rvs_usr_id = $aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id;
} elseif ( $aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id != RvsLibs_User::getUserId() && $aTem2[$aTemplateDefault[$k]->template_id]->private) {
// if template is private other user cannot show
unset($aTemplateDefault[$k]);
} else {
$aTemplateDefault[$k]->rvs_usr_id = '';
$aTemplateDefault[$k]->private = '';
}
//START if url and template path missin unset array fix template exist
// $aTemplateDefault[$k]->rvs_usr_id = $aTem2[$aTemplateDefault[$k]->template_id]->rvs_usr_id;
if (isset($aTemplateDefault[$k])) {
$aTemplatePathUrl = RvsLibs_Template::getTemplatePathUrl($aTemplateDefault[$k]->rvs_usr_id, $aTemplateDefault[$k]->template_item_folder, $action = 'view');
}
if (isset($aTemplatePathUrl) && !$aTemplatePathUrl) {
unset($aTemplateDefault[$k]);
}
//END if url and template path missin unset array fix template exist
}
return $aTemplateDefault;
}
function _privateTemplateFilter($templateUsrId, $private)
{
$this->registRvsConf($this->aConf, $this->objDbh);
//optimize : siwakorn
return ($private && $templateUsrId != RvsLibs_User::getUserId()) ? false : true;
}
function _pager(&$input, &$aErrors)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
require_once(RvsLibs_File::buildPath(array(SGL_LIB_PEAR_DIR, 'Pager', 'Pager.php')));
$pagerUrl = (preg_match("/downloadtemplate/i", $input->pagerUrl))
? $input->pagerUrl
: SGL_BASE_URL .'/'. INDEX_PHPSU . '/sitebuilder/rvscategory';
$oCp = CpHandle::factory();
if (SGL::isError($oCp) === true) {
return SGL::raiseError(RvsLibs_String::translate('CpWaring %MESSAGE', 'vprintf', array('MESSAGE' => $oCp->getMessage())));
}
$pagerUrl = ($oCp->isNotTryout()) ? $pagerUrl : $input->pagerUrl;
$rvsSelectCategory = isset($input->select_category_id) ? $input->select_category_id : "0";
$rvsSelectTemplateTypeId = (!isset($input->template_type_id)) ? 0: $input->template_type_id;
$rvsSelectPictureStyle = (!isset($input->picture_style)) ? 0 : $input->picture_style;
$isUser = (!SGL_Output::isAdmin()) ? true : false;
$userImport = (isset($input->submitUserImport) && $input->submitUserImport && $isUser) ? 'submitUserImport' : '';
$importTemplate = (isset($input->import_template_style) && $input->import_template_style)
? RvsLibs_File::buildPath(array('import_template_style', $input->import_template_style))
: '';
// siwakorn add num page data //
$all = count($input->aSafeTemplates);
$input->getNumPage = (isset($input->getNumPage)) ? $input->getNumPage : "";
$num = ($input->getNumPage == 'all') ? $all : $input->getNumPage;
$num = ($num && $num != '') ? $num : 12;
//siwakorn add num page data //
$num_current = (isset($input->ref_template_item_id) && $input->ref_template_item_id != '') ? $num - 1 : $num;
//puttipong path pager
$fullPagerUrl = $pagerUrl;
if (isset($input->productIdSearch) && $input->productIdSearch != "") {
$fullPagerUrl .= '/productIdSearch/' . $input->productIdSearch . '/select_category_id/0/templatestyle/0';
} else {
$fullPagerUrl .= '/select_category_id/' . $rvsSelectCategory . '/templatestyle/' . $rvsSelectTemplateTypeId;
}
$fullPagerUrl .= '/picture_style/' . $rvsSelectPictureStyle . '/getNumPage/' . $num . $importTemplate . '/' . $userImport;
//ถ้า ใน pager use httpMethod = 'GET' จะต้อง detech phpsu :: ถ้า httpMethod = 'POST' ไม่ต้อง detech phpsu ก็ได้
$params = array(
'mode' => 'Jumping',
'lastPagePre' => '<span>' . RvsLibs_String::translate('Last') . ' </span>',
'firstPagePost' =>'<span> ' . RvsLibs_String::translate('First') . '</span>',
'perPage' => $num_current,
'delta' => 10,
'httpMethod' => 'POST',
'itemData' => $input->aSafeTemplates,
'prevImg' =>'<span>' . RvsLibs_String::translate('Previous') . '</span>',
'nextImg' =>'<span>' . RvsLibs_String::translate('Next') . '</span>',
'curPageLinkClassName' => 'current',
'linkClass' => ' onclick="Javascript:bSubmitted=true;"',
'path' => RvsLibs_String::preg_replace('/\/(&|\?)\/select_category_id/i', '/select_category_id', $fullPagerUrl)
);
$pager = & Pager::factory($params);
$input->showData = $pager->getPageData();
$pager->getLinks();
$input->showPager = $this->getUnVariableExceed($pager->links, $params['path']);
$input->totalItems = $pager->numItems();
$input->perPage = $params['perPage'];
//witoon show page in step2//
$input->totalPage = $pager->_totalPages;
$input->currentPage = $pager->_currentPage;
$input->path = $pager->_path;
//witoon show page in step2//
}
/**
* Un variable variable total name length limit exceeded
*
* @param <string> $dataPager - Data pager
* @param <string> $pathUrl - Path Url
* @return <string> Data pager
*/
function getUnVariableExceed($dataPager, $pathUrl)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//fix suhosin: ALERT - configured GET variable total name length limit exceeded
RvsLibs_String::preg_match('/form\.action(\s*)=(.*?)\"\;/', $dataPager, $aMatches);
if (isset($aMatches[0])) {
$pattern = RvsLibs_String::preg_replace('/\//', '\/', $aMatches[0]);
$pattern = RvsLibs_String::preg_replace('/\?/', '\?', $pattern);
return RvsLibs_String::preg_replace('/' .$pattern . '/', ' form.action ="' . $pathUrl . '";', $dataPager);
}
return $dataPager;
}
function _getRefTemplatesData(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
if (RvsLibs_String::strlen($input->ref_category_id) < 32) {
$arraydata = DaoFactory::Template()->findRefTemplateDataByCategoryIdAndTemplateItemId($input->ref_category_id, $input->ref_template_item_id, 'getall');
return $arraydata;
} else {
///case custom category
$arraydata = DaoFactory::Template()->findRefTemplateDataByCustomCategoryId($input->ref_category_id, $input->ref_template_item_id, 'getall');
if (isset($arraydata[0]->custom_category_name)) {
$arraydata[0]->category_name = $arraydata[0]->custom_category_name;
}
return $arraydata;
}
}
function _getCategoryData(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
//$selectCategoryId = $req->get('select_category_id'); //SGL_Session::get('select_category_id'); //$req->get('select_category_id');
$selectCategoryId = isset($input->select_category_id) ? $input->select_category_id : '';
$aData = array();
$aCategory = array ('rvs_category_id'=>'',
'category_name' => '',
'category_sh_name' => '',
'img_file' => '',
);
if ($input->category_id || $selectCategoryId) {
$aResultData = array(
'rvs_category_id'
, 'category_name'
, 'category_sh_name'
);
$aResultDatac = array(
'custom_category_id'
, 'custom_category_name'
, 'custom_category_sh'
);
$aCustomCateory = DaoFactory::Category()->findCategoryNameByCustomCategoryId($selectCategoryId, 'getrowobj', $aResultDatac); // echo"<pre>";
if (count($aCustomCateory) > 0) {
$aCategory['custom_category_id'] = $aCustomCateory->custom_category_id;
$aCategory['custom_category_name'] = $aCustomCateory->custom_category_name;
$aCategory['custom_category_sh'] = $aCustomCateory->custom_category_sh;
}
$aData = DaoFactory::Category()->findCategoryNameByCategoryId($input->category_id, 'getrowobj', $aResultData);
if (count($aData) > 0){
$aCategory['rvs_category_id'] = $aData->rvs_category_id;
$aCategory['category_name'] = $aData->category_name;
$aCategory['category_sh_name'] = $aData->category_sh_name;
$imageFile = 'cat_' . $aData->category_sh_name . '_';
$imageFile .= ($input->category_id < 10)? '0' . $input->category_id : $input->category_id;
$imageFile .= '.gif';
$aCategory['img_file'] = $imageFile;
}
$aData = DaoFactory::Category()->findCategoryNameByCategoryId($input->category_id);
} else {
$aCategory['rvs_category_id'] = $input->category_id;
$aCategory['category_name'] = 'All Categories';
$aCategory['category_sh_name'] = '';
$imageFile = 'mix.gif';
$aCategory['img_file'] = $imageFile;
}
$this->registRvsConf($this->aConf, $this->objDbh);
$aTemplatePathUrl = RvsLibs_Template::getTemplatePathUrl('','', $action = 'view');
$aCategory['template_path'] = $aTemplatePathUrl['path'];
$aCategory['template_url'] = $aTemplatePathUrl['url'];
return $aCategory;
}
function _getRefCategoryId($projectId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aCategoryId = array();
$aCategoryId = DaoFactory::Project()->findCategoryIdByProjectId($projectId, 'getrow');
//optimize : siwakorn
if (!isset($aCategoryId['template_item_id'])) {
$aTemplateData = RvsLibs_Template::getTemplatesData($projectId, true, false);
if (!count($aTemplateData)) {
return array();
}
$aCateId = (isset($aTemplateData->products_id)) ? explode('-', $aTemplateData->products_id) : 0;
$cateIdCurrent = (isset($aCateId[0])) ? $aCateId[0] : 0;
$aCategoryId['rvs_category_id'] = $cateIdCurrent;
$aCategoryId['template_item_id'] = (isset($aTemplateData->template_item_id)) ? $aTemplateData->template_item_id : '';
$aCategoryId['navigator_id'] = (isset($aTemplateData->navigator_id)) ? $aTemplateData->navigator_id : '';
}
return ($aCategoryId) ? $aCategoryId : array();
}
function _countTemplateColor($templateId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aData = DaoFactory::Template()->findColorIdByTemplateId($templateId,'getAssoc');
$value = array_keys($aData);
foreach ($value as $k=>$v) {
$count = ($v == 0) ? '-' : count($value);
}
//optimize : siwakorn
return ($count) ? $count : false;
}
function _countTemplatePicture($templateId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$aData = DaoFactory::Template()->findPictureIdByTemplateId($templateId,'getAssoc');
$value = array_keys($aData);
foreach ($value as $k=>$v) {
//optmize : siwakorn
$count = ($v == 0) ? '-' : count($value);
}
//optimize : siwakorn
return ($count) ? $count : false;
}
function _GetDefaultLayoutId($templateItemId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$res = DaoFactory::Template()->findTemplateItemByTemplateItemId($templateItemId, 'getrowobj', array('template_id'));
$templateId = $res->template_id;
$res = DaoFactory::Template()->findTemplateByTemplateId($templateId, 'getrowobj',array('default_layout_id'));
return $res->default_layout_id;
}
function _listColor($templateId, $pictureId)
{
$aColorId = array();
$aPicture = array();
$aColorId = DaoFactory::Template()->findListColorByTemplateIdAndPictureId($templateId, $pictureId , true , 'getassoc');
foreach ($aColorId as $colorId => $value) {
$res = DaoFactory::Color()->findColorDataByColorId($colorId, 'getrowobj');
$aColorId[$colorId]->color_name = (isset($res->color_name))? RvsLibs_String::strtolower($res->color_name) : '';
}
//print_r($aColorId); exit;
$aColorId2 = DaoFactory::Template()->findListColorByTemplateIdAndPictureId($templateId, $pictureId , false , 'getassoc');
foreach ($aColorId as $key => $val) {
array_push($aPicture, $aColorId[$key]->picture_id);
}
foreach ($aColorId2 as $key => $val) {
array_push($aPicture, $aColorId2[$key]->picture_id);
}
$totalPic = count(array_unique($aPicture));
if (count($aColorId2) > count($aColorId)) {
foreach ($aColorId2 as $colorId => $objArray) {
if (!isset($aColorId[$colorId])) {
$res = DaoFactory::Color()->findColorDataByColorId($colorId, 'getrowobj');
$objArray->color_name = (isset($res->color_name))? RvsLibs_String::strtolower($res->color_name) : '';
$aColorId[$colorId] = $objArray;
}
}
}
$aColorData['color_id'] = $aColorId;
$aColorData['total_pic'] = $totalPic;
return $aColorData;
}
function _newlistColor($templateId, $pictureId)
{
$aColorId = array();
$aPicture = array();
$aColorId = DaoFactory::Template()->findAllColorByTemplateId($templateId, 'getassoc');
foreach ($aColorId as $colorId => $value) {
//echo $value->color_id;
$res = DaoFactory::Color()->findColorDataByColorId($value->color_id, 'getrowobj');
$aColorId[$colorId]->color_name = (isset($res->color_name))? RvsLibs_String::strtolower($res->color_name) : '';
}
$aColorId2 = DaoFactory::Template()->findAllColorByTemplateId($templateId, 'getassoc');
foreach ($aColorId as $key => $val) {
array_push($aPicture, $aColorId[$key]->picture_id);
}
foreach ($aColorId2 as $key => $val) {
array_push($aPicture, $aColorId2[$key]->picture_id);
}
$totalPic = count(array_unique($aPicture));
if (count($aColorId2) > count($aColorId)) {
foreach ($aColorId2 as $templateItmId => $objArray) {
if (!isset($aColorId[$templateItmId])) {
$res = DaoFactory::Color()->findColorDataByColorId($objArray->color_id, 'getrowobj');
$objArray->color_name = (isset($res->color_name))? RvsLibs_String::strtolower($res->color_name) : '';
$aColorId[$templateItmId] = $objArray;
}
}
}
$aColorData['color_id'] = $aColorId;
$aColorData['total_pic'] = $totalPic;
return $aColorData;
}
function _getCategoryIdNavigatorId(&$input)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$this->registRvsConf($this->aConf, $this->objDbh);
$input->project_id = (!isset($input->project_id)) ? SGL_Session::get('rvs_project_id') : $input->project_id;
$resCustom = DaoFactory::Template()->findDataNavigatorColorByTemplateItemId($input->template_item_id, 'getrowobj');
// get rvs_category_id
$aTemplateCate = DaoFactory::Template()->findCategoryIdByTemplateItemId($input->template_item_id, 'getrowobj');
if(empty($aTemplateData)) {
$aTemplateData = new stdClass();
}
$aTemplateData->rvs_category_id = $aTemplateCate->rvs_category_id;
$aObject = DaoFactory::Template()->findMenuStyleIdNavigatorNameColorGroupIdByTemplateItemId($input->template_item_id, 'getrowobj');
// เธฒ๏ฟฝ?เธซ๏ฟฝ? color_group_id table rvs_template_item_navigator_color custom_color_group_id navigator_id
if ( $resCustom && $resCustom->custom_color_group_id) {
$colorGroupId = $resCustom->custom_color_group_id;
} else {
$colorGroupId = $aObject->color_group_id;
}
$resProject = RvsLibs_Project::getProjectInfoData($input->project_id);
// get navigator_id
$aObject->menustyle_id = (isset($aObject->menustyle_id)) ? $aObject->menustyle_id : null;
$aObject->navigator_name_id = (isset($aObject->navigator_name_id)) ? $aObject->navigator_name_id : null;
$res = DaoFactory::Navigator()->findNavigatorByNavigatorData(null, $aObject->navigator_name_id, $aObject->menustyle_id, $colorGroupId, 'getall');
if ( isset($resProject[0]->navigator_id) && isset($resProject[0]->template_item_id)
&& $resProject[0]->template_item_id == $input->template_item_id) {
$aTemplateData->navigator_id = $resProject[0]->navigator_id;
} else {
$aTemplateData->navigator_id = isset($res[0]->navigator_id) ? $res[0]->navigator_id : '';
}
return $aTemplateData;
}
// mod 1
function getTranslation($aData)
{
$incTranslation = array();
$aTranslation = $GLOBALS['_SGL']['TRANSLATION'];
$oCp = CpHandle::factory();
if(SGL::isError($oCp) === true) {
return SGL::raiseError(RvsLibs_String::translate('CpWaring %MESSAGE', 'vprintf', array('MESSAGE' => $oCp->getMessage())));
}
if ($oCp->isValidIncludeFileLang($this->aConf)) {
$subDomainPath = $this->aConf['tryoutlogin']['subdomain_path'];
//$langPath = $subDomainPath . '/../../.rvsitebuilder/lang/sitebuilder';
$langPath = RVS_USER_HOME . '/.rvsitebuilder/lang/sitebuilder';
$curLang = $_SESSION['aPrefs']['language'];
$langFileName = $GLOBALS['_SGL']['LANGUAGE'][$curLang][1] . '.php';
$curLangFile = RvsLibs_File::buildPath(array($langPath, $langFileName));
if (file_exists($curLangFile)) {
include $curLangFile;
$incTranslation = $words;
unset($words);
}
}
foreach ($aData as $key=>$value) {
if (isset($aTranslation[$value])) {
$aData[$key] = $aTranslation[$value];
} elseif (isset($incTranslation[$value])) {
$aData[$key] = $incTranslation[$value];
}
}
return $aData;
}
function isTemplateImportUsed($templateItemId)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$res = DaoFactory::Project()->findDataProjectInfoByTemplateItemId($templateItemId, 'getAssoc');
if (count($res)) {
return true;
}
}
/**
* Function listNum Page Category
* By : Siwakorn Induang
* create 21-03-2008
*
* @param input select current num $numSelectId
* @return $selectNumPage :: generateSelect
*/
function listNumPageCategory($path ,$numSelectId = false)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$isSubmitUserImport = (RvsLibs_String::preg_match_all('/^http(.*?)\/submitUserImport/', $path, $aR)) ? '/submitUserImport/1' : '';
RvsLibs_String::preg_match_all('/^http(.*?)\/getNumPage/', $path, $aMatch);
$path = $aMatch[0][0] . '/';
$numSelectId = ($numSelectId == false)
? $path . '12' . $isSubmitUserImport
: $path . $numSelectId . $isSubmitUserImport;
$aNumPage = array(
$path . '12' . $isSubmitUserImport => RvsLibs_String::translate('select num Page' , 'vprintf' ,array('num' =>'12')),
$path . '16' . $isSubmitUserImport => RvsLibs_String::translate('select num Page' , 'vprintf' ,array('num' =>'16')),
$path . '20' . $isSubmitUserImport => RvsLibs_String::translate('select num Page' , 'vprintf' ,array('num' =>'20')),
);
//optimize : siwakorn
return SGL_Output::generateSelect($aNumPage, $numSelectId);
}
}
?>