{include file="header.tpl" page_name=$page_name sys_name=$sys_name}
<div align="center">
	{$admin_nav}
    {if $do == 'list' || $do == ''}
    	<table width="98%" border="0" cellpadding="0" cellspacing="0" id="slide_table" class="tableborder tableborder_line">
        	{if $result}
            	<tr class="header">
                    <td>名称</td>
                    <td>说明</td>
                    <td>类型</td>
                    <td>选项个数</td>
                    <td>总投票数</td>
                    <td>操作</td>
            	</tr>
                {literal}
                	<script type="text/javascript">
						$(document).ready(function(){
							$(".poll_edit_a").click(function(){
								var key  = $.trim($(this).attr("href"));
								if(isNaN(key)){
									alert("请正确选择");
									return false;
								}
								key = parseInt(key);
								var poll_type = $(this).parent().prev().prev().prev();
								var poll_desc = poll_type.prev();
								var poll_name = poll_desc.prev();
								
								$("#poll_name").val(poll_name.text());
								$("#poll_desc").val(poll_desc.text());
								if(poll_type.text() == "多选"){
									$("#poll_type_checkbox").attr("checked" , true);
								}else{
									$("#poll_type_radio").attr("checked" , true);
								}
								
								
								$("#poll_id").val(key);
								return false;
							});
							$(".button_form").click(function(){
								var value = $("#poll_name").val();
								if(empty(value)){
									alert("评论标题不能为空");
									return false;
								}
								$("#poll_form_oper").attr("action", $(this).attr("id"));
								$("#poll_form_oper").submit();
							});
						});
                    </script>
                {/literal}
                {foreach from=$result.data item=item}
                	<tr>
                    	<td>{$item.poll_title}</td>
                        <td>{$item.poll_desc}</td>
                        <td style="text-align:center">{if $item.poll_type == 'checkbox'}多选{else}单选{/if}</td>
                        <td>{$item.count}</td>
                        <td>{$item.ticke_total}</td>
                        <td  style="text-align:center">
                        	<a href="?action=poll&do=detail&id={$item.poll_id}">详情</a>
                            |
                            <a href="{$item.poll_id}" class="poll_edit_a">修改</a>
                            |
                            <a onclick="return confirm('确认删除吗？此操作会把投票选项全部删除，数据不可恢复？')" href="?action=poll&do=poll_delete&id={$item.poll_id}">删除</a>
                        </td>
                    </tr>
                {/foreach}
                {if $result.page}
                	<tr>
                    	<td colspan="8" style="text-align:right">{$result.page}</td>
                    </tr>
                {/if}
            {else}
            	<tr>
                	<td><div class="showNotice">没有数据。</div></td>
            	</tr>
            {/if}
        </table>
        <form action="?action=poll&do=poll_add" method="post" autocomplete="off" id="poll_form_oper">
            <table width="98%" border="0" cellpadding="0" cellspacing="0" id="slide_table" class="tableborder" style="margin-top:10px">
            	<tr>
                	<td class="one">评论标题</td>
                    <td>
                    <input type="text" name="poll_name" id="poll_name"  maxlength="100" class="form_text" />
                    </td>
                </tr>
                <tr>
                	<td class="one">评论说明</td>
                    <td>
                    	<input type="text" value="" id="poll_desc" name="poll_desc" maxlength="200" class="form_text" style="width:400px" />
                    </td>
                </tr>
                <tr>
                	<td class="one">类型</td>
                    <td>
                    	<input type="radio" id="poll_type_radio" name="poll_type" value="radio" checked="checked"  />单选
                        <input type="radio" id="poll_type_checkbox" name="poll_type" value="checkbox"  />多选
                    </td>
                </tr>
                <tr>
                	<td style="text-align:center" colspan="2">
                    	<input type="button" class="button_form" value="保存" id="?action=poll&do=poll_add" />
                        <input type="button" class="button_form" value="修改" id="?action=poll&do=poll_edit" />
                    </td>
                </tr>
            </table>
            <input type="hidden" name="id" id="poll_id" />
        </form>
    {elseif $do == 'detail'}
        <table width="98%" border="0" cellpadding="0" cellspacing="0" id="slide_table" class="tableborder">
            <tr>
                <td class="one">评论标题</td>
                <td colspan="3">{$result.title}</td>
            </tr>
            <tr>
                <td class="one">类型</td>
                <td style="width:21%">{if $result.poll_type == 'checkbox'}多选{else}单选{/if}</td>
                <td class="one">总票数</td>
                <td>{$result.sum}</td>
            </tr>
        </table>
        {literal}
        	<script type="text/javascript">
				$(document).ready(function(){
					$("input[type='checkbox']").css("cursor","pointer");
					$(".button_click_form_sub").click(function(){
						var value = $("#option_name").val();
						if(empty(value)){
							alert("选项名称不能为空");
							return false;
						}
						$("#phpwms_form_oper").attr("action", $(this).attr("id"));
						$("#phpwms_form_oper").submit();
					});
					$(".option_edit_a").click(function(){
						var obj = $(this).parent().prev().prev().prev();
						$("#option_name").val(obj.text());
						$("#option_id").val($(this).attr("href"));
						return false;
					});
				});
				function phpwms_submit_delete(self){
					var flg = true;
					$(".form_checkbox").each(function(i){
						if($(this).attr("checked") == true){
							flg = false;
							return;
						}
					});
					if(flg){
						alert('请选择要操作的项');
						return false;
					}
					$("#phpwms_form_oper_delete").attr("action", $(self).attr("id"));
					$("#phpwms_form_oper_delete").submit();
				}
				function checkall(self){
					$(".form_checkbox").attr("checked", $(self).attr("checked"));
				}
            </script>
        {/literal}
        <form action="" method="post" id="phpwms_form_oper_delete">
            <table width="98%" border="0" cellpadding="0" cellspacing="0" id="slide_table" class="tableborder" style="margin-top:10px">
            	{if $result.data}
                    <tr class="header">
                        <td style="width:50px"><input type="checkbox" onclick="checkall(this)"  />全选</td>
                        <td>选项名称</td>
                        <td>票数</td>
                        <td>所占比例</td>
                        <td>操作</td>
                    </tr>
                    {foreach from=$result.data item=item}
                        <tr>
                            <td style="text-align:center"><input type="checkbox" value="{$item.option_id}" class="form_checkbox" name="id[]" /></td>
                            <td>{$item.option_name}</td>
                            <td>{$item.option_ticket}</td>
                            <td>{math equation="x / y * z" x=$item.option_ticket y=$result.sum z=100} %</td>
                            <td style="text-align:center">
                                <a href="{$item.option_id}" class="option_edit_a">修改</a>
                                |
                                <a href="?action=poll&do=option_delete&id={$item.option_id}&poll_id={$result.poll_id}">删除</a>
                            </td>
                        </tr>
                    {/foreach}
                    <tr>
                        <td colspan="6"><input id="?action=poll&do=option_delete&poll_id={$result.poll_id}" type="button" value="批量删除" onclick="phpwms_submit_delete(this)" /></td>
                    </tr>
                {else}
                	<tr>
                		<td><div class="showNotice">没有数据。</div></td>
            		</tr>
                {/if}
            </table>
        </form>
        <form action="" method="post" autocomplete="off" id="phpwms_form_oper">
        	<table width="98%" border="0" cellpadding="0" cellspacing="0" id="slide_table" class="tableborder" style="margin-top:10px">
            	<tr>
                	<td class="one">选项名称</td>
                    <td><input type="text" class="form_text" name="option_name" id="option_name" /></td>
                    <td>
                        <input type="button" value="返回" onclick="javascript:location.href='?action=poll&do=list'"  />
                        <input type="button"  class="button_click_form_sub" value="添加" id="?action=poll&do=option_add" />
                        <input type="button" class="button_click_form_sub" value="修改" id="?action=poll&do=option_edit" />
                    </td>
                </tr>
            </table>
            <input type="hidden" value="" id="option_id" name="option_id" />
            <input type="hidden" value="{$result.poll_id}" id="poll_id" name="poll_id" />
        </form>
    {/if}
</div>
{include file="footer.tpl"}