<?php include_once( "../../../../spider.inc.php" ); ?>
{charset:UTF-8}
{template:admin_default.tpl}
{module:system.login.Require}
{module:content.widget.setting.Load}
{preset:page_title 'コンテンツ管理 > HTMLパーツ編集 > HTMLパーツ設定'}

	<div class="panc">
		<a href="../../../" title="管理パネルのトップページを表示します">管理パネルトップ</a>
		&gt; <a href="../../" title="コンテンツ管理トップページを表示します">コンテンツ管理</a>
		&gt; <a href="../" title="コンテンツ管理HTMLパーツ一覧を表示します">HTMLパーツ一覧</a>
		&gt; HTMLパーツ設定
	</div>

	<h1>コンテンツ管理 &gt; HTMLパーツ編集 &gt; HTMLパーツ設定</h1>
	
	{if:IS_ERROR}
	<ul class="error">
	{foreach:errors error}
		<li>{write:error}</li>
	{/foreach}
	</ul>
	<p style="width:95%;margin-top:2em;text-align:right;">
		<a href="../">&gt;&gt; HTMLパーツ一覧に戻る</a>
	</p>
	{else}
	
	<form name="settingform" action="./confirm.php" method="post">
	
	<p>
		値を設定してページ下部の「変更を保存」ボタンをクリックしてください。
	</p>
	<table class="list" style="width:95%;margin:0 auto;">
	<tbody>
	<tr>
		<th>ファイル名</th>
		<td>
			{write:content.widget.widgetObject->'file_name'}
			<input type="hidden" size="80" name="file_name" value="{write:content.widget.widgetObject->'file_name'}" />
		</td>
	</tr>
	<tr>
		<th>HTMLパーツタイトル</th>
		<td><input type="text" size="80" name="widget_name" value="{write:content.widget.widgetObject->'widget_name'}" /></td>
	</tr>
	<tr>
		<th>概要</th>
		<td><input type="text" size="80" name="description" value="{write:content.widget.widgetObject->'description'}" /></td>
	</tr>
	</tbody>
	</table>
	<p style="text-align:center;">
		<img alt="変更を保存する" onclick="contentVariableSave()" onkeydown="contentVariableSave()" src="/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01.jpg" onmouseover="this.src='/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01_on.jpg'" onmouseout="this.src='/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01.jpg'" style="cursor:pointer;" />
	</p>
	<br />
	<h2>パーツ内で利用されているサイト固有値</h2>
	{set:variableHash content.widget.widgetObject->'variableHash'}
	{if:is_array(variableHash) && count(variableHash)>0}
	<table class="list" style="width:95%;margin:0 auto;">
	<thead>
	<tr>
		<th>変数名</th>
		<th>説明</th>
		<th>値</th>
	</tr>
	</thead>
	<tbody id="valiable-table-body">
	{foreach:variableHash variableKey variableHash}
	<tr id="valrow-{write:variableHash_loop_counter}">
		<td class="variable-cell-key">
			<input type="hidden" name="variable_key[]" id="valrow-{write:variableHash_loop_counter}-key" value="{write:variableKey}" />
			{write:variableKey}
		</td>
		<td class="variable-cell-name">
			<input type="hidden" name="variable_label[]" value="{write:variableHash['label']}" />
			{write:variableHash['label']}
		</td>
		<td class="variable-cell-value">
			<textarea name="variable_value[]" cols="30" rows="2" style="width:98%;"
				>{write:variableHash['value']}</textarea>
		</td>
	</tr>
	{/foreach}
	</tbody>
	</table>
	<p style="text-align:center;">
		<img alt="変更を保存する" onclick="contentVariableSave()" onkeydown="contentVariableSave()" src="/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01.jpg" onmouseover="this.src='/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01_on.jpg'" onmouseout="this.src='/<?php echo SYSTEM_DIR_NAME_ADMIN_PANEL; ?>/images/button/save_01.jpg'" style="cursor:pointer;" />
	</p>
	{else}
	<p>サイト固有値は利用されていません。</p>
	{/if}
	<br />

<script language="JavaScript" type="text/javascript"><!--
var contentWidgetSettingHttpObject;
function contentVariableSave() {
	var postContents	= 'command=0'
	postContents		+= FormerCommon.createFormContents(document.settingform);
	contentWidgetSettingHttpObject	= FormerCommon.createHttpRequest(contentVariableSaveResult);
	if (contentWidgetSettingHttpObject) {
		FormerCommon.displayGrayOut(9999);
		contentWidgetSettingHttpObject.open("POST",'../../variable/save.php',true);
		contentWidgetSettingHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		contentWidgetSettingHttpObject.send(postContents);
	} else {
		alert('サーバーへの接続作成に失敗しました。');
	}
}
function contentVariableSaveResult() {
	if ((contentWidgetSettingHttpObject.readyState == 4) && (contentWidgetSettingHttpObject.status == 200)){
	    var lines	= contentWidgetSettingHttpObject.responseText.cr2lf().split(LF);
	    var isError = false;
	    var error_message	= '';
	    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 ) {
					error_message += result + "\n";
				} else {
					isError	= true;
				}
			}
		}
		if( isError ) {
			alert('保存に失敗しました!\n'+error_message);
			setTimeout(FormerCommon.displayWhiteIn, 500);
		} else {
			contentWidgetSettingSave();
		}
	} else if ((contentWidgetSettingHttpObject.readyState == 4) && (contentWidgetSettingHttpObject.status != 200)){
		alert('適用時にサーバー通信でエラーが発生しました。');
		setTimeout(FormerCommon.displayWhiteIn, 500);
	} else {
	}
}
function contentWidgetSettingSave() {
	var postContents	= 'command=0'
	postContents		+= FormerCommon.createFormContents(document.settingform);
	contentWidgetSettingHttpObject	= FormerCommon.createHttpRequest(contentWidgetSettingSaveResult);
	if (contentWidgetSettingHttpObject) {
		FormerCommon.displayGrayOut(9999);
		contentWidgetSettingHttpObject.open("POST",'./save.php?wfile='+encodeURIComponent('{write:content.widget.widgetObject->'file_name'}'),true);
		contentWidgetSettingHttpObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		contentWidgetSettingHttpObject.send(postContents);
	} else {
		alert('サーバーへの接続作成に失敗しました。');
	}
}
function contentWidgetSettingSaveResult() {
	if ((contentWidgetSettingHttpObject.readyState == 4) && (contentWidgetSettingHttpObject.status == 200)){
	    var lines	= contentWidgetSettingHttpObject.responseText.cr2lf().split(LF);
	    var isError = false;
	    var error_message	= '';
	    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 ) {
					error_message += result + "\n";
				} else {
					isError	= true;
				}
			}
		}
		if( isError ) {
			alert('保存に失敗しました!\n'+error_message);
			setTimeout(FormerCommon.displayWhiteIn, 500);
		} else {
			alert('保存が完了しました')
			setTimeout(FormerCommon.displayWhiteIn, 500);;
		}
	} else if ((contentWidgetSettingHttpObject.readyState == 4) && (contentWidgetSettingHttpObject.status != 200)){
		alert('適用時にサーバー通信でエラーが発生しました。');
		setTimeout(FormerCommon.displayWhiteIn, 500);
	} else {
	}
}

function contentWidgetSettingViewModule() {
	var elmButton = document.getElementById('content-widget-modules-button');
	var elmPanel = document.getElementById('content-widget-modules-panel');
	if( elmButton && elmPanel ) {
		if( elmButton.style.visibility == 'hidden' ) {
			elmButton.style.display	= 'block';
			elmButton.style.visibility	= 'visible';
			elmButton.style.position	= 'static';
			elmPanel.style.display	= 'none';
			elmPanel.style.visibility	= 'hidden';
			elmPanel.style.position		= 'absolute';
		} else {
			elmButton.style.display	= 'none';
			elmButton.style.visibility	= 'hidden';
			elmButton.style.position	= 'absolute';
			elmPanel.style.display	= 'block';
			elmPanel.style.visibility	= 'visible';
			elmPanel.style.position		= 'static';
		}
	}
}
//--></script>
	<hr style="width:96%;margin:0 auto;margin-top:1em;" />
	<div style="width:96%;margin:0 auto;text-align:right;">
		{if:!is_null(content.widget.widgetObject)}
		&gt;&gt; <a href="../html/form.php?wfile={write:urlencode(content.widget.widgetObject->'file_name')}">{write:content.widget.widgetObject->'file_name'}のHTML編集</a>
		&nbsp;
		{/if}
		&gt;&gt; <a href="../">HTMLパーツ一覧に戻る</a>
	</div>
	{/if}