<?php include_once( "../../../spider.inc.php" ); ?>
{charset:UTF-8}
{template:admin_default.tpl}
{module:member.download.Confirm}
{preset:page_title MEMBER_PERSONAL_LABEL . '管理 > ＣＳＶデータダウンロード'}

	<div class="panc">
		<a href="../../">管理パネルトップ</a>
		&gt; <a href="../">{write:MEMBER_PERSONAL_LABEL}情報一覧</a>
		&gt; CSVデータダウンロード確認
	</div>

	<h1>
		{write:MEMBER_PERSONAL_LABEL}管理 &gt; CSVデータダウンロード確認
	</h1>
{if:IS_ERROR}
	<ul class="error">
	{foreach:errors error}
		<li>{write:error}</li>
	{/foreach}
	</ul>
	<p style="text-align:center;">
		<input type="button" value="戻る"
			onclick="window.history.back();"
		/>
	</p>
	<br />
{else}
	<p style="text-align:center;">
		検索結果{write:member.download.total_count}件のデータをダウンロードします。<br />
		[ダウンロードする]をクリックすると出力を開始します。
	</p>

	<div id="panel-barcontainer" style="text-align:left;border-style:solid;border-width:1px;width:60%;height:1em;margin:0 auto;"
		><div id="panel-bar" style="height:1em;background-color:#0000FF;width:0%;"></div>
	</div>
	<div id="message_panel" style="text-align:center;">
		0 / {write:member.download.total_count}
	</div>
	
	<p style="text-align:center;">
		<input type="button" value="戻る"
			onclick="window.history.back();"
		/><input type="button" value="ダウンロードする"
			id="dlbutton" onclick="requestCsvCreate()"
		/><br />
	</p>
	<br />
	<br />
	<br />

<script language="JavaScript" type="text/javascript"><!--
var getHttpObject;
function requestCsvCreate() {
	var button		= document.getElementById('dlbutton');
	var bar			= document.getElementById('panel-bar');
	if( button ) {
		button.disabled	= 'disabled';
	}

	{if:member.download.write_at_once>=member.download.total_count}
	bar.style.width	= '100%';
	window.location.href='./download.php?mc=1&stype={write:member.download.select_type}';

	{else}

	getHttpObject	= FormerCommon.createHttpRequest(requestCsvCreateResult);
	if( getHttpObject ) {
		var url			= './execute.php?mc=1&stype={write:member.download.select_type}';
		getHttpObject.open("GET",url,true);
		getHttpObject.send(null);
	} else {
		alert('通信の作成に失敗しました。');
	}

	{/if}
	
}
function requestCsvCreateResult() {
	if ((getHttpObject.readyState == 4) && (getHttpObject.status == 200)){
		var panel		= document.getElementById('message_panel');
		var bar			= document.getElementById('panel-bar');
		var response	= getHttpObject.responseText;
		var lines		= response.trim().split(LF);
		var result		= new String(lines.shift()).trim();
		if( result == 'OK' ) {
			var offset	= new String(lines.shift().trim());
			var once	= new String(lines.shift().trim());
			var total	= new String(lines.shift().trim());
			var iOffset	= parseInt(offset);
			var iOnce	= parseInt(once);
			var iTotal	= parseInt(total);
			if( iOffset + iOnce >= iTotal ) {
				// 次回で超えるならロケーション
				getHttpObject	= null;
				panel.innerHTML	= 'CSVデータ作成が完了しました<br />';
				panel.innerHTML	+= total + ' / ' + total;
				bar.style.width	= '100%';
				window.location.href='./download.php?mc=1';
			} else {
				panel.innerHTML	= 'CSVデータを作成中です<br />';
				panel.innerHTML	+= offset + ' / ' + total;
				var rate		= Math.floor((offset/total)*100);
				bar.style.width	= new String(rate) + '%';
				getHttpObject	= null;
				requestCsvCreate();
			}
		} else {
			getHttpObject	= null;
			alert(result);
		}
	} else if ((getHttpObject.readyState == 4) && (getHttpObject.status != 200)){
		alert('通信に失敗しました。');
		getHttpObject	= null;
	}
}
//--></script>
{/if}
	<hr style="width:96%;margin:0 auto;margin-top:1em;" />
	<div style="width:96%;margin:0 auto;text-align:right;">
		<a href="../">&gt;&gt; {write:MEMBER_PERSONAL_LABEL}一覧へ戻る</a>
	</div>