<?php
/*
 * design/template/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(__FILE__)))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(__FILE__))
	.DIRECTORY_SEPARATOR.'DaoTemplate.class.php');
class design_template_Save extends system_login_ModuleBase {
	function design_template_Save() {
	}
	function execute( & $request ) {
		$agentType			= strtolower(trim(stripslashes($_POST['agent'])));
		$fileName			= strtolower(trim(stripslashes($_POST['file_name'])));
		$bodyStrings		= stripslashes($_POST['body_strings']);
		$bodyStrings		= mb_convert_kana($bodyStrings,'KV');
		if( strlen(trim($agentType)) == 0 ) {
			$agentType				= 'default';
		} else if( !array_key_exists( $agentType, $GLOBALS['SPIDER_USER_AGENT_CLASS_HASH'] ) ){
			$agentType				= 'default';
		}
		if( strlen(trim($fileName)) == 0 ) {
			$request->addError('テンプレートファイル名を指定してください');
		}
		
		if( !$request->isError() ) {
			$templateObject	= new design_DaoTemplate($fileName);
			$templateObject->loadInfo( $request );
			if( $templateObject->html_edit ) {
				$templateObject->saveBody( $request, $agentType, $bodyStrings );
				if( !$request->isError() ) {
					$templateObject->rebuild( $request, $agentType );
				}
			} else {
				$request->addError('このテンプレートのHTML編集は許可されていません。');
			}
		}
		$request->setAttribute('design.template.form.targetHhtml',$bodyStrings );
		$request->setAttribute('design.template.form.agentType',$agentType );
		$request->setAttribute('design.template.form.templateName',$fileName );
	}
}
?>