<?php
/*
 * design/template/setting/Save.class.php
 * 
 * CopyRight(C) 2010 Shopformer Development Team. All Right Reserved
 * URL: http://sourceforge.jp/projects/shopformer/
 * 
 * 
 * Mail: m_nakashima@users.sourceforge.jp
 * Auther: Masanori Nakashima
 * Last Update: 2010-06-18
 */
require_once( dirname(dirname(dirname(dirname(__FILE__))))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'DaoTemplate.class.php');
class design_template_setting_Save extends system_login_ModuleBase {
	function design_template_setting_Save() {
	}
	function execute( & $request ) {
		$fileName			= strtolower(trim(stripslashes($_GET['fmt'])));
		if( strlen(trim($fileName)) == 0 ) {
			$request->addError('テンプレートファイル名を指定してください');
		}
		
		if( !$request->isError() ) {
			$templateObject			= new design_DaoTemplate($fileName);
			$variableKeyArray		= $request->getParam('variable_key','post','array');
			$variableNoteArray		= $request->getParam('variable_note','post','array');
			$variableValueArray		= $request->getParam('variable_value','post','array');
			if( is_array($variableKeyArray) ) {
				foreach( $variableKeyArray as $num => $key ) {
					$vNote	= '';
					$vValue	= '';
					if( is_array($variableNoteArray) && isset($variableNoteArray[$num]) ) {
						$vNote	= str_replace("\r","",$variableNoteArray[$num]);
						$vNote	= str_replace("\n","",$vNote);
					}
					if( is_array($variableValueArray) && isset($variableValueArray[$num]) ) {
						$vValue	= str_replace("\r\n","\n",$variableValueArray[$num]);
						$vValue	= str_replace("\r","\n",$vValue);
					}
					$templateObject->setLabel( $request, $key, $vNote);
					$templateObject->setValue( $request, $key, $vValue);
				}
			}
			$templateObject->saveSetting( $request );
			$templateObject->loadInfo( $request );
			$templateObject->view_name		= stripslashes($_POST['view_name']);
			$templateObject->saveInfo( $request );
			if( !$request->isError() ) {
				// エラーがないならテンプレートをリビルド
				foreach( $GLOBALS['SPIDER_USER_AGENT_CLASS_HASH'] as $aKey => $aName ) {
					$templateObject->rebuild( $request, $aKey );
				}
			}
		}
	}
}
?>