<?php
/*
 * design/template/Form.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_Form extends system_login_ModuleBase {
	function design_template_Form() {
	}
	function execute( & $request ) {
		$agentType			= strtolower(trim(stripslashes($_GET['agent'])));
		$fileName			= strtolower(trim(stripslashes($_GET['fmt'])));
		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('テンプレートファイル名を指定してください');
		}
		
		$targetHtml				= '';
		if( !$request->isError() ) {
			$templateObject	= new design_DaoTemplate($fileName);
			$templateObject->loadInfo( $request );
			if( $templateObject->html_edit ) {
				$targetHtml		= $templateObject->getBody( $request, $agentType );
			} else {
				$request->addError('このテンプレートのHTML編集は許可されていません。');
			}
		}
		$request->setAttribute('design.template.form.targetHhtml',$targetHtml );
		$request->setAttribute('design.template.form.agentType',$agentType );
		$request->setAttribute('design.template.form.templateName',$fileName );
	}
}
?>