<?php include_once( "../../../spider.inc.php" ); ?>
{charset:UTF-8}
{template:admin_default.tpl}
{module:member.mail.reject.LoadList}
{module:member.mail.template.LoadList}
{module:member.mail.Confirm}
{preset:page_title MEMBER_PERSONAL_LABEL . '管理 > メール送信確認'}

	<div class="panc">
		<a href="../../">管理パネルトップ</a>
		&gt; <a href="../">{write:MEMBER_PERSONAL_LABEL}情報一覧</a>
		&gt; メール送信
	</div>

	<h1>{write:MEMBER_PERSONAL_LABEL}情報一覧 &gt; メール送信確認</h1>
	
{if:IS_ERROR}

	<ul class="error">
	{foreach:errors error}
		<li>{write:error}</li>
	{/foreach}
	</ul>

{else}

	<p style="margin:0 auto;width:100%;margin-top:1em;margin-bottom:1em;">
		以下の内容でメールを送信します。間違いなければ「送信準備を開始する」ボタンをクリックしてください。
	</p>
	
	<form name="sendform" action="./execute.php?stype={write:member.mail.mail_object->'select_type'}{if:member.mail.mail_object->'select_type'=='m'}{if:count(member.mail.mail_object->'member_id_object_hash')>0}{foreach:member.mail.mail_object::member_id_object_hash key member_object}&amp;mi[]={write:key}{/foreach}{/if}{/if}" method="post">
	<input type="hidden" name="select_type" value="{write:member.mail.mail_object->'select_type'}" />
	<input type="hidden" name="subject" value="{write:member.mail.mail_object->'subject'}" />
	<input type="hidden" name="body" value="{write:member.mail.mail_object->'body'}" />

	<h2 class="global">送信設定</h2>
	<table class="detail" style="width:96%;margin:0 auto;">
	<tbody>
	<tr>
		<th style="white-space:nowrap;">宛先</th>
		<td colspan="3">
			{if:count(member.mail.mail_object->'member_id_object_hash')>0}
			<table style="width:100%;margin:0 auto;">
			{foreach:member.mail.mail_object::member_id_object_hash key member_object}
			<tr>
				<td style="vertical-align:top;">{write:key}<input type="hidden" name="member_id[]" value="{write:key}" /></td>
				<td style="vertical-align:top;">{write:member_object->'view_name'}さん</td>
				{if:member.mail.mail_object->'target_type'=='m'}
				<td style="vertical-align:top;">携帯</td>
				<td style="vertical-align:top;text-align:right;">
					{if:strlen(member_object->'mb_mail')>0}{write:member_object->'mb_mail'}{else}登録なし{/if}
				</td>
				{else}
				<td style="vertical-align:top;">ＰＣ</td>
				<td style="vertical-align:top;text-align:right;">
					{if:strlen(member_object->'pc_mail')>0}{write:member_object->'pc_mail'}{else}登録なし{/if}
				</td>
				{/if}
			</tr>
			{/foreach}
			</table>
			{else}検索結果全て{/if}
		</td>
	</tr>
	<tr>
		<th style="white-space:nowrap;">配信予約日時</th>
		<td colspan="3">
			{write:member.mail.mail_object->'reserve_date_year'}年
			{write:member.mail.mail_object->'reserve_date_month'}月
			{write:member.mail.mail_object->'reserve_date_day'}日
			{write:member.mail.mail_object->'reserve_date_hour'}:{write:member.mail.mail_object->'reserve_date_min'}
		</td>
	</tr>
	<tr>
		<th style="white-space:nowrap;">テンプレート</th>
		<td>
			{if:strlen(member.mail.mail_object->'template_id')==0}
				テンプレート利用なし
			{else}
				{foreach:member.mail.template.data_array mail_template_object}
					{if:mail_template_object->'template_id'==member.mail.mail_object->'template_id'}{write:mail_template_object->'subject'}{/if}
				{/foreach}
			{/if}
		</td>
		<th style="white-space:nowrap;">メールマガジン種類</th>
		<td>
			{if:strlen(member.mail.mail_object->'list_id')==0}
				-
			{else}
			{foreach:member.mail.reject.data_array reject_list_object}
				{if:reject_list_object->'list_id'==member.mail.mail_object->'list_id'}{write:reject_list_object->'list_name'}{/if}
			{/foreach}
			{/if}
		</td>
	</tr>
	<tr>
		<th style="width:10em;">送信対象</th>
		<td>
			{if:member.mail.mail_object->'target_type'=='p'}PCメール{/if}
			{if:member.mail.mail_object->'target_type'=='m'}携帯メール{/if}
		</td>
		<th style="width:10em;white-space:nowrap;">メールタイプ</th>
		<td>
			{if:member.mail.mail_object->'mail_type'=='p'}テキスト{/if}
			{if:member.mail.mail_object->'mail_type'=='h'}HTML{/if}
		</td>
	</tr>
	</tbody>
	</table>
	<br />
	
	<h2 class="global">メールヘッダ</h2>
	<table class="detail" style="width:96%;margin:0 auto;">
	<tbody>
	<tr>
		<th style="width:10em;">件名</th>
		<td>
			{write-mpic:member.mail.mail_object::subject}
		</td>
	</tr>
	<tr>
		<th style="width:10em;white-space:nowrap;">送信者名</th>
		<td>
			{write:member.mail.mail_object->'mail_from_name'}
		</td>
	</tr>
	<tr>
		<th style="width:10em;white-space:nowrap;">送信元<br />メールアドレス</th>
		<td>
			{write:member.mail.mail_object->'mail_from_address'}
		</td>
	</tr>
	<tr>
		<th style="width:10em;white-space:nowrap;">返信先<br />メールアドレス</th>
		<td>
			{write:member.mail.mail_object->'mail_reply_address'}
		</td>
	</tr>
	<tr>
		<th style="width:10em;white-space:nowrap;">エラー戻り先<br />メールアドレス</th>
		<td>
			{write:member.mail.mail_object->'mail_return_path'}
		</td>
	</tr>
	<tbody>
	</table>
	<br />
	
	<h2 class="global">対応履歴への追記</h2>
	<table class="detail" style="width:96%;margin:0 auto;">
	<tbody>
	<tr>
		<th style="width:10em;white-space:nowrap;">追記</th>
		<td>
			{if:member.mail.mail_object->'add_correspond'==false}しない{/if}
			{if:member.mail.mail_object->'add_correspond'==true}する{/if}
		</td>
	</tr>
	{if:member.mail.mail_object->'add_correspond'==true}
	<tr>
		<th style="font-size:0.8em;width:14em;white-space: nowrap;">状態指定<span class="required">※</span></th>
		<td>
			{write:MEMBER_CORERSPOND_STATUS_HASH[member.mail.mail_object->'correspond_status']}
		</td>
	</tr>
	<tr>
		<th style="font-size:0.8em;width:14em;white-space: nowrap;">対応開始タイプ<span class="required">※</span></th>
		<td>
			{write:MEMBER_CORERSPOND_TYPE_HASH[member.mail.mail_object->'correspond_type']}
		</td>
	</tr>
	<tr>
		<th style="font-size:0.8em;width:14em;white-space: nowrap;">対応分類<span class="required">※</span></th>
		<td>
			{write:MEMBER_CORRESPOND_CATEGORIES[member.mail.mail_object->'correspond_category']}
		</td>
	</tr>
	{/if}
	</tbody>
	</table>

	<p style="text-align:center;">
		<input type="button" value="本文プレビュー" onclick="preview()" />
		<input type="button" value="テスト送信" onclick="membarMailSendTestViewPanel()" />
	</p>
	<p style="text-align:center;">
		<input type="button" value="編集画面に戻る"
			onclick="window.history.back();"
			onkeypress="window.history.back();"
		/><input type="button" value="送信準備を開始する"
			onclick="membarMailSendExecuteSave()"
			onkeypress="membarMailSendExecuteSave()"
		/>
	</p>
	<br />
	<br />
	</form>

	<form name="previewForm" action="./preview.php?stype={write:member.mail.mail_object->'select_type'}{if:member.mail.mail_object->'select_type'=='m'}{if:count(member.mail.mail_object->'member_id_object_hash')>0}{foreach:member.mail.mail_object::member_id_object_hash key member_object}&amp;mi[]={write:key}{/foreach}{/if}{/if}" method="post" target="">
	<input type="hidden" name="target_type" value="{write:member.mail.mail_object->'target_type'}" />
	<input type="hidden" name="mail_type" value="{write:member.mail.mail_object->'mail_type'}" />
	<input type="hidden" name="bgcolor" value="{write:member.mail.mail_object->'bgcolor'}" />
	<input type="hidden" name="subject" value="{write:member.mail.mail_object->'subject'}" />
	<input type="hidden" name="body" value="{write:member.mail.mail_object->'body'}" />
	</form>

<script language="JavaScript" type="text/javascript"><!--
function preview() {
	var targetType				= '{write:member.mail.mail_object->'target_type'}';
	var wWidth	= '420';
	if( 'm' == targetType ) {
		wWidth	= '160';
	}
	var childWindow	= window.open('./form.php','memberMailPreviewBodyTemp','width='+wWidth+',height=400,scrollbars=yes,resizable=no,location=no,toolbar=no');
	if( childWindow ) {
		childWindow.name			= 'memberMailPreviewBodyTemp';
		document.previewForm.target	= 'memberMailPreviewBodyTemp';
		document.previewForm.submit();
	}
}
/**
 * メール送信テスト関連関数
 */
var templateHttpObject;
function membarMailSendTestViewPanel() {
	templateHttpObject	= FormerCommon.createHttpRequest(membarMailSendTestViewPanelResult);
	if (templateHttpObject) {
		FormerCommon.displayGrayOut(9999);
		var url	= "./sendtest/form.php?stype={write:member.mail.mail_object->'select_type'}{if:member.mail.mail_object->'select_type'=='m'}{if:count(member.mail.mail_object->'member_id_object_hash')>0}{foreach:member.mail.mail_object::member_id_object_hash key member_object}&mi[]={write:key}{/foreach}{/if}{/if}";
		templateHttpObject.open("GET",url,true);
		templateHttpObject.send(null);
	} else {
		alert('サーバー通信に失敗しました!');
	}
}
function membarMailSendTestViewPanelResult() {
	if ((templateHttpObject.readyState == 4) && (templateHttpObject.status == 200)){
		var sentTestPanel	= document.createElement('div');
		sentTestPanel.innerHTML	= templateHttpObject.responseText;
		sentTestPanel.id	= 'member-mail-sendtest-panel';
		sentTestPanel.style.position	= 'absolute';
		sentTestPanel.style.zIndex		= '99999';
		var bodyTags 	= document.getElementsByTagName('body');
		if( bodyTags && bodyTags[0] ) {
			bodyTags[0].appendChild(sentTestPanel);
			if(window.attachEvent){
				window.attachEvent('onscroll',membarMailSendTestViewPanelResize);
				window.attachEvent('onresize',membarMailSendTestViewPanelResize);
			}else{
				window.addEventListener('scroll',membarMailSendTestViewPanelResize,false);
				window.addEventListener('resize',membarMailSendTestViewPanelResize,false);
			}
			membarMailSendTestViewPanelResize();
		} else {
			alert('bodyタグがありません。このページのHTMLが正しく記述されていない可能性があります。');
			setTimeout(FormerCommon.displayWhiteIn, 100);
		}
	} else if ((templateHttpObject.readyState == 4) && (templateHttpObject.status != 200)){
		alert('サーバーと通信できませんでした。');
		setTimeout(FormerCommon.displayWhiteIn, 100);
	}
}
function membarMailSendTestViewPanelResize( e ) {
	var sentTestPanel		= document.getElementById('member-mail-sendtest-panel');
	var wall		= document.getElementById('innerblock-wall');
	if( wall ) {
		wall.style.height	= '450px';
	}
	if( sentTestPanel ) {
		var marginTop			= 0;
		var marginLeft			= 0;
		var cWidth				= 800;
		var cHeight				= 498;
		if ( document.documentElement ) {
			marginLeft	= document.documentElement.scrollLeft + ( ( document.documentElement.clientWidth - cWidth ) / 2 );
			marginTop	= document.documentElement.scrollTop + ( (document.documentElement.clientHeight -cHeight) / 2 );
		} else {
			marginLeft	= document.body.scrollLeft + ( ( document.body.clientWidth - cWidth ) / 2 );
			marginTop	= document.body.scrollTop + ( ( document.body.clientHeight - cHeight ) / 2 );
		}
		sentTestPanel.style.width	= String(cWidth) + 'px';
		sentTestPanel.style.height	= String(cHeight) + 'px';
		sentTestPanel.style.left	= String(marginLeft) + 'px';
		sentTestPanel.style.top		= String(marginTop) + 'px';
	}
}
function membarMailSendTestClosePanel() {
	var sentTestPanel	= document.getElementById('member-mail-sendtest-panel');
	if( sentTestPanel ) {
		var bodyTags 	= document.getElementsByTagName('body');
		if( bodyTags && bodyTags[0] ) {
			bodyTags[0].removeChild(sentTestPanel);
		} else {
			alert('bodyタグがありません。このページのHTMLが正しく記述されていない可能性があります。');
		}
	}
	setTimeout(FormerCommon.displayWhiteIn, 100);
}
function membarMailSendTestExecute(formObject) {
	var sentTestPanel	= document.getElementById('member-mail-sendtest-panel');
	if( sentTestPanel ) {
		sentTestPanel.style.zIndex		= '50';
	}
	FormerCommon.executePostForm(formObject,membarMailSendTestExecuteOk,membarMailSendTestExecuteNg);
}
function membarMailSendTestExecuteOk() {
	alert('テストメールを送信しました。受信メールボックスを確認してください。');
	var sentTestPanel	= document.getElementById('member-mail-sendtest-panel');
	if( sentTestPanel ) {
		sentTestPanel.style.zIndex		= '99999';
	}
}
function membarMailSendTestExecuteNg() {
	var sentTestPanel	= document.getElementById('member-mail-sendtest-panel');
	if( sentTestPanel ) {
		sentTestPanel.style.zIndex		= '99999';
	}
}
/**
 * メール送信実行開始 関数
 */
var memberMailSendMailId	= '';
var membermailSendPanelId	= 'member-mail-send-panel';
function membarMailSendExecuteSave() {
	templateHttpObject	= FormerCommon.createHttpRequest(membarMailSendExecuteSaveResult);
	if( templateHttpObject ) {
		var contents	= FormerCommon.createFormContents(document.sendform);
		FormerCommon.displayGrayOut(9999);
		var url	= "./execute.php?stype={write:member.mail.mail_object->'select_type'}{if:member.mail.mail_object->'select_type'=='m'}{if:count(member.mail.mail_object->'member_id_object_hash')>0}{foreach:member.mail.mail_object::member_id_object_hash key member_object}&mi[]={write:key}{/foreach}{/if}{/if}";
		templateHttpObject.open("POST",url,true);
		templateHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		templateHttpObject.send(contents);
	} else {
		alert('サーバー通信を作成できませんでした。');
	}
}
function membarMailSendExecuteSaveResult() {
	if ((templateHttpObject.readyState == 4) && (templateHttpObject.status == 200)){
	    var lines	= templateHttpObject.responseText.cr2lf().split(LF);
	    var isError = false;
	    var errorMessage	= '';
	    for( var i=0; i<lines.length; i++ ){
			if( String(lines[i]).cr2lf().trim().length>0 ){
				var result	= String(lines[i]).cr2lf().trim();
				if( result == 'OK' ) {
					break;
				} else if( isError ) {
					errorMessage += result + "\n";
				} else {
					isError	= true;
				}
			}
		}
		if( isError ) {
			alert(errorMessage);
			setTimeout(FormerCommon.displayWhiteIn, 100);
		} else {
			memberMailSendMailId	= templateHttpObject.responseText.cr2lf().replace('OK','').trim();
			membarMailSendExecuteSaveOk();
		}
	} else if ((templateHttpObject.readyState == 4) && (templateHttpObject.status != 200)){
		alert('サーバーと通信できませんでした。');
		setTimeout(FormerCommon.displayWhiteIn, 100);
	}
}

function membarMailSendExecuteSaveOk() {
	var sendPanel				= document.createElement('div');
	sendPanel.innerHTML			= '';
	sendPanel.id				= membermailSendPanelId;
	sendPanel.style.position	= 'absolute';
	sendPanel.style.zIndex		= '99999';
	var bodyTags 	= document.getElementsByTagName('body');
	if( bodyTags && bodyTags[0] ) {
		bodyTags[0].appendChild(sendPanel);
		if(window.attachEvent){
			window.attachEvent('onscroll',memberMailSendPanelResize);
			window.attachEvent('onresize',memberMailSendPanelResize);
		}else{
			window.addEventListener('scroll',memberMailSendPanelResize,false);
			window.addEventListener('resize',memberMailSendPanelResize,false);
		}
		memberMailSendPanelResize();
		memberMailSendCreateListStart();
	} else {
		alert('bodyタグがありません。このページのHTMLが正しく記述されていない可能性があります。');
		setTimeout(FormerCommon.displayWhiteIn, 100);
	}
}
function membarMailSendExecuteSaveNg() {
}
function memberMailSendPanelResize() {
	var sendPanel	= document.getElementById(membermailSendPanelId);
	var wall		= document.getElementById('innerblock-wall');
	if( wall ) {
		wall.style.height	= '450px';
	}
	if( sendPanel ) {
		var marginTop			= 0;
		var marginLeft			= 0;
		var cWidth				= 800;
		var cHeight				= 498;
		if ( document.documentElement ) {
			marginLeft	= document.documentElement.scrollLeft + ( ( document.documentElement.clientWidth - cWidth ) / 2 );
			marginTop	= document.documentElement.scrollTop + ( (document.documentElement.clientHeight -cHeight) / 2 );
		} else {
			marginLeft	= document.body.scrollLeft + ( ( document.body.clientWidth - cWidth ) / 2 );
			marginTop	= document.body.scrollTop + ( ( document.body.clientHeight - cHeight ) / 2 );
		}
		sendPanel.style.width	= String(cWidth) + 'px';
		sendPanel.style.height	= String(cHeight) + 'px';
		sendPanel.style.left	= String(marginLeft) + 'px';
		sendPanel.style.top		= String(marginTop) + 'px';
	}
}
function membarMailSendPanelClose() {
	var sendPanel	= document.getElementById(membermailSendPanelId);
	if( sendPanel ) {
		var bodyTags 	= document.getElementsByTagName('body');
		if( bodyTags && bodyTags[0] ) {
			bodyTags[0].removeChild(sendPanel);
		} else {
			alert('bodyタグがありません。このページのHTMLが正しく記述されていない可能性があります。');
		}
	}
	setTimeout(FormerCommon.displayWhiteIn, 100);
}
/**
 * 送信リスト準備
 */
var createListContinueFlag	= false;
function memberMailSendCreateListStart() {
	FormerCommon.displayGrayOut(9999);
	createListContinueFlag	= true;
	memberMailSendCreateList();
}
function memberMailSendCreateListEnd() {
	createListContinueFlag	= false;
}
function memberMailSendCreateList() {
	FormerCommon.displayGrayOut(9999);
	if( createListContinueFlag ) {
		templateHttpObject	= FormerCommon.createHttpRequest(memberMailSendCreateListResult);
		if (templateHttpObject) {
			FormerCommon.displayGrayOut(9999);
			var url	= "./createlist.php?magid="+memberMailSendMailId+"&sao=10";
			templateHttpObject.open("GET",url,true);
			templateHttpObject.send(null);
		}
	}
}
function memberMailSendCreateListResult() {
	if ((templateHttpObject.readyState == 4) && (templateHttpObject.status == 200)){
		var sendPanel	= document.getElementById(membermailSendPanelId);
		sendPanel.innerHTML	= templateHttpObject.responseText;
		if( createListContinueFlag ) {
			setTimeout(memberMailSendCreateList, 2000);
		}
	} else if ((templateHttpObject.readyState == 4) && (templateHttpObject.status != 200)){
		alert('サーバーと通信できませんでした。');
	}
}
/**
 * 送信処理
 */
var sendMailContinueFlag	= false;
function memberMailSendMailPostStart() {
	FormerCommon.displayGrayOut(9999);
	sendMailContinueFlag	= true;
	memberMailSendMailPost();
}
function memberMailSendMailPostEnd() {
	sendMailContinueFlag	= false;
}
function memberMailSendMailPost() {
	FormerCommon.displayGrayOut(9999);
	if( sendMailContinueFlag ) {
		templateHttpObject	= FormerCommon.createHttpRequest(memberMailSendMailPostResult);
		if (templateHttpObject) {
			FormerCommon.displayGrayOut(9999);
			var url	= "./send.php?magid="+memberMailSendMailId+"&sao=1";
			templateHttpObject.open("GET",url,true);
			templateHttpObject.send(null);
		}
	}
}
function memberMailSendMailPostResult() {
	if ((templateHttpObject.readyState == 4) && (templateHttpObject.status == 200)){
		var sendPanel	= document.getElementById(membermailSendPanelId);
		sendPanel.innerHTML	= templateHttpObject.responseText;
		if( sendMailContinueFlag ) {
			setTimeout(memberMailSendMailPost, 1000);
		}
	} else if ((templateHttpObject.readyState == 4) && (templateHttpObject.status != 200)){
		alert('サーバーと通信できませんでした。');
	}
}

//--></script>
{/if}