<!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
from enquete.OpenFlashChart import *
from genshi.core import *
from trac.core import *
from trac.util import escape, Markup
import urllib
from genshi.input import *

?>
<?python
	def isSelected(val1,val2):
		if val1 != None:
			if val1 == val2:
				return "selected"
			else:
				return None
		else:
			return None
?>

  <head>
    <title>アンケート集計</title>
    <script type="text/javascript" src="../js/swfobject.js"></script>
	<script type="text/javascript">
		function eventHandler(actionName) {
			f = document.forms['questionlist'];
			document.getElementById('actionName').value = actionName;
			if(actionName == "enquetelist"){
				location.href="${href.enquete()}";
				return;
			} else if(actionName == "group"){
				f.action="${href.enquete('answer')}";
			}
			f.submit();
		}
	</script>
  </head>
  <body>
	<form name="questionlist" action="" method="post">
	<div style="padding-left:40px">
		<B>タイトル：${title}</B><P/>
		<input type="hidden" name="idx"/>
		<input type="hidden" id="id"  name="id" value="${enquete_id}"/>
		<input type="hidden" id="actionName"  name="actionName"/>
	</div>
	<div style="padding-left:40px">
		<input type="button" name="enquetelist" value="戻る"  onclick="eventHandler('enquetelist');" />
		&nbsp;&nbsp;&nbsp;&nbsp;グルーピング：
	  	<select name="group_id" onchange="javascript:eventHandler('group');">
		  		<option value=""> </option>
		  	<py:for each="idx, question in enumerate(question_list)">
		  		<option py:if="int(question['type'])==1 or int(question['type'])==2" value="${question['question_id']}" selected="${isSelected(group_id,str(question['question_id']))}">${question['question_title']}</option>
		  	</py:for>
	  	</select>
<?python
g = graph_object()

if group_id == None:
	group_id = ''
?>

		<table class="list">
			<thead>
				<tr>
					<th>No.</th>
					<th>設問</th>
<py:choose test="group_id">
	<py:when test="''">
					<th colspan="2">結果</th>
	</py:when>
	<py:otherwise>
					<th>全体</th>
		<py:for each="idx2, answer in enumerate(answer_map[int(group_id)])">
					<th>${answer['answer']}</th>
		</py:for>
	</py:otherwise>
</py:choose>
				</tr>
			</thead>
			<tbody>
				<py:for each="idx, question in enumerate(question_list)">
<?python
mod = idx % 2
style = ''
if mod==0:
	style = 'even'
else:
	style = 'odd'
?>
					<tr class="${style}">
						<td width="40">${idx+1}</td>
						<td nowrap="true">${question['question_title']}</td>
<?python
if(question['question_id'] in chart_map):
	_url = ("""%s""") % (urllib.quote(chart_map[question['question_id']]))
else:
	_url = ''

if(question['type'] == 4 or question['type'] == 5):
	graph = False
else:
	graph = True

width = 400
height = 300
if group_id != '':
	width = 300
	height = 200
?>
<py:choose test="graph">
<py:when test="False">
						<td colspan="${len(question_list)+2}" align="left" nowrap="true">
							<table width="100%">
								<py:for each="idx2, answer in enumerate(answer_map[question['question_id']])">

								<tr py:if="question['question_id']==answer['question_id'] and answer['answer']!=''">
									<td align="left" nowrap="true"><pre>${answer['answer']}</pre></td>
								</tr>
								</py:for>
							</table>
						</td>
</py:when>
<py:otherwise>
<?python
	span = 1;
	if group_id !='' and group_id==str(question['question_id']):
		span = len(question_list) + 2
?>
						<td bgcolor="#F8F8D8" align="center" colspan="${span}" >
	<py:choose test="url">
		<py:when test="''">
			NO DATA
		</py:when>
		<py:otherwise>
${Markup(g.render(width,height,unescape(_url),'../chrome/enquete/swf/'))}
		</py:otherwise>
	</py:choose>
						</td>
	<py:choose test="group_id">
		<py:when test="''">
						<td>
							<table class="list" py:if="answer_map.has_key(question['question_id'])">
								<py:for each="idx2, answer in enumerate(answer_map[question['question_id']])">

								<tr py:if="question['question_id']==answer['question_id']">
									<td>${answer['answer']}</td>
									<td>${answer['count']}</td>
								</tr>
								</py:for>
							</table>
						</td>
		</py:when>
		<py:otherwise>
			<py:choose test="group_id">
				<py:when test="str(question['question_id'])"></py:when>
				<py:otherwise>
					<py:for each="idx2, answer in enumerate(answer_map[int(group_id)])">
						<td bgcolor="#F8F8D8" align="center">
<?python
url2 = ("""%s&answer=%s&group_id=%s""") % (chart_map[question['question_id']],urllib.quote(answer['answer'].encode('utf-8')) ,group_id)
?>
${Markup(g.render(width,height,urllib.quote(url2),'../chrome/enquete/swf/'))}
						</td>
					</py:for>
				</py:otherwise>
			</py:choose>
		</py:otherwise>
	</py:choose>
</py:otherwise>
</py:choose>
					</tr>
				</py:for>
			</tbody>
		</table>
	</div>
	</form>
  </body>
</html>
