<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <xi:include href="macros.html" />
<?python
 statusname = {0:"非公開", 1:"公開/受付中", 2:"終了"}
?>
  <head>
    <title>アンケート</title>
    <script type="text/javascript" src="js/util.js"/>
	<script type="text/javascript">
	function eventHandler(actionName,enquete_id) {
		f = document.forms['enquetelist'];
		document.getElementById('actionName').value = actionName;
		if(actionName == "add"){
			f.action = "${href.enquete()}";
		} else if(actionName == 'edit'){
			f.action = "${href.enquete('edit')}";
		} else if(actionName == 'delete'){
			if(!confirm('削除してもよろしいですか？')){
				return false;
			}
			f.action = "${href.enquete()}";
		} else if(actionName == 'open' || actionName == 'close' || actionName == 'expire'){
			f.action = "${href.enquete()}";
		} else if(actionName == 'answer' || actionName == 'count'){
			f.action = "${href.enquete('answer')}";
			if(enquete_id == undefined){
				document.getElementById('id').value = getRadioButtonValue(f.enquete_id);
			} else {
				document.getElementById('id').value = enquete_id;
			}
		}
		f.submit();
	}

	</script>




  </head>

  <body>
	<py:if test="error!=''">
		<div id="content" class="error">
			<h2>Error:</h2>
			<p class="message">${error}</p>
		</div>
	</py:if>
	<form name="enquetelist"  method="post">
	<py:if test="req.perm.has_permission('ENQUETE_EDIT')">
	<div>
		<fieldset>
			<legend>アンケートの追加</legend>
			<table>
			<tr><td>アンケートタイトル:</td><td><input type="text" name="newtitle" size="70" /></td></tr>
			<tr><td>回答期限:</td><td><div class="expire_text" id="expire_text"></div><input type="hidden" name="expire_date" /><div id="cal1Container"></div></td></tr>
			<tr><td>説明:</td><td><textarea rows="3"  cols="60" name="description"></textarea></td>
				<td><input type="button" name="add" value="アンケート追加"  onclick="eventHandler('add');" /></td></tr>
			</table>
		</fieldset>
		<input type="button" name="count" value="結果参照"  onclick="eventHandler('count');" />
		<input type="button" name="edit" value="編集"  onclick="eventHandler('edit');" />
		<input type="button" name="delete" value="削除"  onclick="eventHandler('delete');" />
		<input type="button" name="open" value="公開"  onclick="eventHandler('open');" />
		<input type="button" name="close" value="非公開"  onclick="eventHandler('close');" />
		<input type="button" name="expire" value="受付終了"  onclick="eventHandler('expire');" />
		<input type="hidden" id="idx"  name="idx"/>
	</div>
	</py:if>
	<input type="hidden" id="id"  name="id"/>
	<input type="hidden" id="actionName"  name="actionName"/>
	<div>
		<table width="90%"  class="list">
			<thead>
				<tr>
					<th>No.</th>
					<th>アンケートタイトル</th>
					<th>作成者</th>
					<th>更新日時</th>
					<th>公開日時</th>
					<th>回答期限</th>
					<th>回答日時</th>
					<th>説明</th>
					<th>回答者数</th>
					<th>ステータス</th>
				</tr>
			</thead>
			<tbody>
				<py:for each="idx, enquete in enumerate(enquete_list)">
<?python
mod = idx % 2
style = ''
if mod==0:
	style = 'even'
else:
	style = 'odd'
?>
					<tr class="${style}">
						<td width="40">
						<py:if test="req.perm.has_permission('ENQUETE_EDIT')">
						<input type="radio"  name="enquete_id" id="enquete_id" value="${enquete['enquete_id']}"  checked="${idx==0 or None}"/>
						</py:if>
						${idx+1}
						</td>
						<td><a href="javascript:eventHandler('answer','${enquete['enquete_id']}')">${enquete['title']}</a></td>
						<td width="70">${enquete['create_user']}</td>
						<td width="70">${enquete['update_date']}</td>
						<td width="70">${enquete['open_date']}</td>
						<td width="70">${enquete['expire_date']}</td>
						<td width="70">${enquete['answer_date']}</td>
						<td>${enquete['description']}</td>
						<td align="right" width="70">${enquete['count']}</td>
						<td width="80">
							<py:choose test="enquete['status']">
								<py:when test="2">
									<py:if test="enquete['status']==2"><a href="javascript:eventHandler('count','${enquete['enquete_id']}')">${statusname[enquete['status']]}</a></py:if>
								</py:when>
								<py:otherwise>
									${statusname[enquete['status']]}
								</py:otherwise>
							</py:choose>
						</td>
					</tr>
				</py:for>
			 </tbody>
		</table>
	</div>
	</form>

<script type="text/javascript">
	YAHOO.namespace("enquate.calendar");

	YAHOO.enquate.calendar.init = function() {

		function handleSelect(type,args,obj) {
			var dates = args[0];
			var date = dates[0];
			var year = date[0], month = date[1], day = date[2];

			var txtDate1 = document.getElementById("expire_date");
			var txtDate2 = document.getElementById("expire_text");
			if((""+day).length == 1){
				day = "0" + day;
			}
			txtDate1 = year + "/" + month + "/" + day ;
			if (typeof txtDate2.textContent != "undefined") {
				txtDate2.textContent = txtDate1;
			} else {
				txtDate2.innerText = txtDate1;
			}
			YAHOO.enquate.calendar.cal1.hide();
		}

		YAHOO.enquate.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { title:"回答期限:", close:true } );
		YAHOO.enquate.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.enquate.calendar.cal1, true);
		YAHOO.enquate.calendar.cal1.render();

		YAHOO.util.Event.addListener("expire_text", "click", YAHOO.enquate.calendar.cal1.show,YAHOO.enquate.calendar.cal1, true);
	}

	YAHOO.util.Event.onDOMReady(YAHOO.enquate.calendar.init);
</script>
  </body>
</html>
