<?php
/*
 * system/tools/notify/mailbody/Execute.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.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(dirname(dirname(__FILE__))))
	.DIRECTORY_SEPARATOR.'define.inc.php');
require_once( dirname(dirname(dirname(dirname(__FILE__))))
	.DIRECTORY_SEPARATOR.'DataFileWriter.class.php');
/**
 * パスワードリマインダ文章変更モジュール
 * 
 * @package system
 * @subpackage tools
 * @category module
 * @version 1.2.00
 * @copyright Copyright(c)2011, Shopformer Development Team. <shopformer-dev@lists.sourceforge.jp>
 * @author Masanori Nakashima
 * @access public
 */
class system_tools_notify_mailbody_Execute extends system_login_ModuleBase {
	
	function system_tools_notify_mailbody_Execute(){
	}
	function execute( & $request ) {
		
		$agent					= trim(stripslashes( $_GET['agent'] ));		
		if( 'mobile' != $agent ) {
			$agent	= 'default';
		}
		$sessionObjectName		= 'system.tools.notify.mailbody.modify.object.'.$agent;
		$sessionConfirmName		= 'system.tools.notify.mailbody.modify.confirm.'.$agent;
		$mailHash				= $request->getSession($sessionObjectName);
		$resultConfirm			= $request->getSession($sessionConfirmName);

		if( 'OK' != $resultConfirm ) {
			$request->addLocaledError('system.error.common.session.timeout',SPIDER_LOG_LEVEL_ERROR,array());
		} else {
			// メール件名と本文を合体する
			$mailBody	= $mailHash['subject'] . "\n" . $mailHash['body'];
			// ファイルを保存する
			$fileName 		= 'mail.password.'.$agent.'.txt';
			$fileUri		= '/system/tools/notify/'.$fileName;
			$fileWriter		= new system_DataFileWriter();
			if( $fileWriter->open( $request, $fileUri, 'w' ) ) {
				$fileWriter->write($mailBody);
				$fileWriter->close( $request );
			}
		}
		$request->removeSession($sessionObjectName);
		$request->removeSession($sessionConfirmName);
		$request->setAttribute('system.tools.notify.mailbody.agent', $agent);
		$request->setAttribute('system.tools.notify.mailbody.mail_hash', $mailHash);
	}
}
?>