{include file="header.tpl" page_name=$page_name sys_name=$sys_name}
<div align="center">
	{$admin_nav}
    <table class="adminMenu g-margin" width="98%" cellspacing="0" cellpadding="0" border="0" align="center">
        <tr>
            <td>
            <b>管理菜单：</b>
                <a href="?action=ads&do=show">广告列表</a>
                  |
                <a href="?action=ads&do=add">添加广告</a>
            </td>
        </tr>
    </table>
    {if $do =='show' || $do == ''}
    	{literal}
        	<script type="text/javascript">
				function checkall(self){
					$(".form_checkbox").attr("checked", $(self).attr("checked"));
				}
				$(document).ready(function(){
					$("input[type='checkbox']").css("cursor","pointer");
				});
				function phpwms_submit(self){
					var flg = true;
					$(".form_checkbox").each(function(i){
						if($(this).attr("checked") == true){
							flg = false;
							return;
						}
					});
					if(flg){
						alert('请选择要操作的项');
						return false;
					}
					$("#phpwms_ads_delete_form").attr("action", $(self).attr("id"));
					$("#phpwms_ads_delete_form").submit();
				}
            </script>
        {/literal}
        <form action="" id="phpwms_ads_delete_form" method="post">
            <table width="98%" border="0" cellpadding="0" cellspacing="0" class="tableborder tableborder_line">
                {if $result}
                    <tr class="header">
                        <td width="50"><input type="checkbox" onclick="checkall(this)" />全选</td>
                        <td>广告名称</td>
                        <td>媒体类型</td>
                        <td>所属广告位</td>
                        <td>广告描述</td>
                        <td>起始时间</td>
                        <td>结束时间</td>
                        <td>是否显示</td>
                        <td>操作</td>
                        {foreach from = $result.data item = ads}
                            <tr>
                                <td align="center" style="text-align:center;"><input name="adsid[]" class="form_checkbox" type="checkbox" value="{$ads.ads_id}" /></td>
                                <td>{$ads.ads_name}</td>
                                <td>
                                	{if $ads.ads_type == 'image'}图片
                                    {elseif $ads.ads_type == 'flash'}Flash
                                    {elseif $ads.ads_type == 'text'}文本
                                    {elseif $ads.ads_type == 'a'}文字连接{/if}
                                </td>
                                <td>{$ads.place_name}</td>
                                <td>{$ads.ads_text.ads_desc}</td>
                                <td align="center" style="text-align:center">{if $curtime < $ads.ads_begintime }<span  class="red">{/if}{$ads.ads_begintime|date_format:"%Y-%m-%d"}{if $curtime < ads_endtime }</span>{/if}</td>
                                <td align="center" style="text-align:center">{if $curtime >= $ads.ads_endtime }<span class="red">{/if}{$ads.ads_endtime|date_format:"%Y-%m-%d"}{if $curtime >= ads_endtime }</span>{/if}</td>
                                <td align="center" style="text-align:center">{if $ads.ads_pass == '1'}<span class="red">是</span>{else}否{/if}</td>
                                <td align="center" style="text-align:center">
                                    <a href="?action=ads&do=edit&adsid={$ads.ads_id}&page={$result.curpage}">修改</a>
                                    |
                                    <a href="?action=ads&do=delete&adsid={$ads.ads_id}&page={$result.curpage}">删除</a>
                                    |
                                    <a target="_blank" href="?action=ads&do=detail&adsid={$ads.ads_id}">详情</a>
                                </td>
                            </tr>
                        {/foreach}
                    </tr>
                    <tr>
                        <td colspan="9">
                            <div style="float:left" id="?action=ads&do=delete&page={$result.curpage}" onclick="phpwms_submit(this)" class="block_button">批量删除</div>
                            <div style="float:right">{$result.page}</div>
                        </td>
                    </tr>
                {else}
                     <tr>
                        <td><div class="showNotice">没有数据，请您添加广告。</div></td>
                     </tr>
                {/if}
            </table>
        </form>
    {elseif $do == 'add' || $do == 'edit'}
    	<script type="text/javascript" language="JavaScript" src="../js/My97DatePicker/WdatePicker.js"></script>
    	{literal}
        	<script type="text/javascript">
				$(document).ready(function(){
					$("input[name='type']").click(function(){
						var divid = "#phpwms_ads_" + $(this).val();
						$(".type_div").css("display", 'none');
						$(divid).css("display", 'block');
					});
					$(".ads_btn_submit").click(function(){
						<!-- 验证 -->
						var value = $("#adsname").val();
						if(empty(value)){
							alert("广告名称不能为空");
							return false;
						}
						value = $("#placeid").val();
						if(value == '0'){
							alert("请选择广告位");
							return false;
						}
						var valuetype = $("input[name='type']:checked").val();
						var flg = false;
						switch(valuetype){
							case "image":
								value = $("#type_image").val();
								if(empty(value)){
									alert("图片地址不能为空");
									flg = true;
								}
								break;
							case "flash":
								value = $("#type_flash").val();
								if(empty(value)){
									alert("flash地址不能为空");
									flg = true;
								}
								break;
							case "text":
								value = $("#type_text").val();
								if(empty(value)){
									alert("文本内容不能为空");
									flg = true;
								}
								break;
							case "a":
								value = $("#type_a").val();
								if(empty(value)){
									alert("文字内容不能为空");
									flg = true;
									break;
								}
								value = $("#type_a_link").val();
								if(empty(value)){
									alert("链接地址不能为空");
									flg = true;
								}
								break;
						}
						if(flg){
							return false;
						}
						value = $("#adsbegingtime").val();
						if(empty(value)){
							alert("请选择广告开始时间");
							return false;
						}
						value = $("#adsendtime").val();
						if(empty(value)){
							alert("请选择结束时间");
							return false;
						}
						$("#phpwms_ads_form").attr("action", $(this).attr("id"));
						$("#phpwms_ads_form").submit();
					});
				});
            </script>
        {/literal}
    	<form action="" method="post" id="phpwms_ads_form" autocomplete="off" enctype="multipart/form-data" >
            <table width="98%" border="0" cellpadding="0" cellspacing="0" class="tableborder">
                <tr>
                    <td class="one">广告名称：</td>
                    <td>
                    	<input type="text" class="form_text" name="name" value="{$ads.ads_name}" maxlength="50" id="adsname"  />
                        <span class="red">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="one">广告描述：</td>
                    <td>
                    	<input type="text" class="form_text" value="{$ads.ads_text.ads_desc}" name="desc" maxlength="50" id="adsdesc" />
                    </td>
                </tr>
                <tr>
                    <td class="one">所属广告位：</td>
                    <td>
                    	<select name="place" id="placeid">
                        	<option value="0">---请选择广告位---</option>
                            {foreach from=$places item=place}
                            	<option value="{$place.place_id}" {if $ads.ads_place_id == $place.place_id} selected="selected" {/if}>{$place.place_name} --- [{$place.place_width} x {$place.place_height}]</option>
                            {/foreach}
                        </select>
                        <span class="red">* 广告位名称 [宽度 x 高度]</span>
                    </td>
                </tr>
                <tr>
                    <td class="one">媒体类型：</td>
                    <td>
                    	<input type="radio"  name="type" id="adstypeimage" value="image" {if $ads.ads_type == '' || $ads.ads_type == 'image'} checked="checked" {/if} />图片
                        <input type="radio"  name="type" id="adstypeflash" value="flash" {if $ads.ads_type == 'flash'} checked="checked" {/if} />Flash
                        <input type="radio"  name="type" id="adstypetext" value="text" {if $ads.ads_type == 'text'} checked="checked" {/if} />多文本
                        <input type="radio"  name="type" id="adstypea" value="a" {if $ads.ads_type == 'a'} checked="checked" {/if} />链接文字
                    </td>
                </tr>
                <tr>
                	<td class="one">广告内容：</td>
                    <td>
                    	<div id="phpwms_ads_image" class="type_div" {if $ads.ads_type == '' || $ads.ads_type == 'image'} style="display:block" checked="checked" {else} style="display:none" {/if}>                        	
                            <table class="tableborder"  style="width:500px"  cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width:100px;text-align:right;">图片地址：</td>
                                    <td>
                                    	<input  value="{$ads.ads_text.image_src}" type="text" name="image_text"  id="type_image" maxlength="200"  /><input type="button"  onclick="window.parent.show_window(document.getElementById('type_image'),'admincp.php?action=file&a=default&type=pic');" value="选择"/>
                                    </td>
                                </tr>
                                <tr>
                                	<td style="width:100px;text-align:right;">连接地址：</td>
                                    <td>
                                    	<input type="text" value="{$ads.ads_text.image_link}"  name="image_link" value="" class="form_text"  maxlength="100"  />
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div id="phpwms_ads_flash" class="type_div" {if $ads.ads_type == 'flash'} style="display:block" checked="checked" {else} style="display:none" {/if}>                        	
                            <table class="tableborder" style="width:500px"   cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width:100px;text-align:right;">Flash地址：</td>
                                    <td>
                                    	<input type="text"  value="{$ads.ads_text.flash_src}" name="flash_text" id="type_flash" />
                                    	<input type="button"  onclick="window.parent.show_window(document.getElementById('type_flash'),'admincp.php?action=file&a=default&type=flash');" value="选择"/>
                                    </td>
                                </tr>
                                <tr>
                                	<td style="width:100px;text-align:right;">连接地址：</td>
                                    <td>
                                    	<input type="text" value="{$ads.ads_text.flash_link}" name="flash_link" class="form_text"   />
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div id="phpwms_ads_text" class="type_div" {if $ads.ads_type == 'text'} style="display:block" checked="checked" {else} style="display:none" {/if}>
                            <table class="tableborder" style="width:500px"  cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width:100px;text-align:right;">文本内容：</td>
                                    <td>
                                    	<textarea name="text_text" id="type_text" style="width:200px; height:100px">{$ads.ads_text.text_text}</textarea>
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div id="phpwms_ads_a" class="type_div" {if $ads.ads_type == 'a'} style="display:block" checked="checked" {else} style="display:none" {/if}>
                            <table class="tableborder" style="width:500px"  cellspacing="0" cellpadding="0">
                                <tr>
                                    <td style="width:100px;text-align:right;" align="right">连接内容：</td>
                                    <td>
                                        <input type="text"  name="a_text" value="{$ads.ads_text.a_text}" maxlength="50" id="type_a" class="form_text" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width:100px;text-align:right;">连接地址：</td>
                                    <td>
                                        <input type="text" name="a_link" id="type_a_link" value="{$ads.ads_text.a_link}" class="form_text" />
                                        <span class="red">*</span>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="one">广告开始时间：</td>
                    <td>
                    	<input value="{$ads.ads_begintime|date_format:"%Y-%m-%d"}" type="text" class="form_text Wdate" name="begintime" maxlength="11" id="adsbegingtime" {literal} onClick="WdatePicker({minDate:'%y-%M-#{%d}',dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" {/literal} />
                        <span class="red">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="one">广告结束时间：</td>
                    <td>
                    	<input type="text" value="{$ads.ads_endtime|date_format:"%Y-%m-%d"}" class="form_text Wdate" name="endtime" maxlength="11" id="adsendtime"  {literal} onClick="WdatePicker({dateFmt:'yyyy-MM-dd',alwaysUseStartDate:true})" {/literal} />
                        <span class="red">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="one">是否通过：</td>
                    <td>
                    	<input type="radio" name="pass" value="1" {if $ads.ads_pass == '1' }checked="checked" {/if}/>是
                        <input type="radio" name="pass" value="0" {if $ads.ads_pass != '1' } checked="checked" {/if} />否
                    </td>
                </tr>
            </table>
            <input type="hidden" name="adsid" value="{$ads.ads_id}" />
            <div align="center" style="padding: 5px;"><input type="button" class="ads_btn_submit" id="?action=ads&do=oper&page={$curpage}" value="保存" /></div>
        </form>
    {/if}
</div>
{include file="footer.tpl"}