<?php (!defined('IN_ADMIN') || !defined('IN_MUDDER')) && exit('Access Denied'); ?>
<script type="text/javascript">
var g;
function reload() {
    var obj = document.getElementById('reload');
    var btn = document.getElementById('switch');
    if(obj.innerHTML.match(/^<.+href=.+>/)) {
        g = obj.innerHTML;
        obj.innerHTML = '<input type="file" name="picture" size="50" class="upfile">';
        btn.innerHTML = '取消上传';
    } else {
        obj.innerHTML = g;
        btn.innerHTML = '重新上传';
    }
}

function searchname() {
    var kw = document.couponfrm.keyword.value;
    if(kw.length == 0) {
        alert('未填写商铺关键字');
        return;
    }
	$.get(
        "<?=$MOD['url']?>",
        { ac:"submit",op:"searchshop",keyword:kw },
        function(result) {
            if (result.match(/id="shoplist"/)) {
                myDialog('查找商铺', result, 400, 260);
            } else {
                myAlert(result);
            }
	    }
    );
}

function insertshop(shopid,shopname) {
    document.couponfrm.keyword.value = shopname;
    document.couponfrm.shopid.value = shopid;
    myDialogClose();
}
</script>
<div id="body">
<form method="post" name="couponfrm" enctype="multipart/form-data" action="admincp.php?action=<?=$action?>&file=edit&">
    <input type="hidden" name="couponid" value="<?=$couponid?>" />
    <div class="space">
        <div class="subtitle">编辑优惠券</div>
        <table class="maintable" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="60" class="altbg1">礼品名称：</td>
                <td><input type="text" name="coupon[subject]" value="<?=$subject?>" class="txtbox" /></td>
            </tr>
            <tr>
                <td class="altbg1">所属商铺：</td>
                <input type="hidden" name="shopid" value="<?=$shopid?>" />
                <td><input type="text" name="keyword" value="<?=$shop['shopname'].$shop['subname']?>" class="txtbox" />&nbsp;
                    <button type="button" onclick="searchname();" class="btn2">查找商铺</button></td>
            </tr>
            <tr>
                <td class="altbg1">优惠说明：</td>
                <td><input type="text" name="coupon[des]" value="<?=$des?>" class="txtbox" /></td>
            </tr>
            <tr>
                <td class="altbg1">有效期：</td>
                <td>
                    <input type="text" name="coupon[starttime]" value="<?=date('Y-m-d',$starttime)?>" class="txtbox4" />
                    至
                    <input type="text" name="coupon[endtime]" value="<?=date('Y-m-d',$endtime)?>" class="txtbox4" />
                </td>
            </tr>
            <tr>
                <td class="altbg1" valign="top">状态：</td>
                <td><select name="flag">
                    <option value="1"<?if($flag==1)echo' selected';?>>正常</option>
                    <option value="3"<?if($flag==3)echo' selected';?>>无效</option>
                </select></td>
            </tr>
            <tr>
                <td class="altbg1" valign="top">详细说明：</td>
                <td><textarea name="coupon[content]" rows="10" cols="50"><?=$content?></textarea></td>
            </tr>
            <tr>
                <td class="altbg1">图片：</td>
                <td>
                    <span id="reload"><a href="<?=$_config['siteurl']?>uploads<?=$picture?>" target="_blank"><?=$picture?></a></span>&nbsp;&nbsp;[<a href="javascript:reload();" id="switch">重新上传</a>]
                </td>
            </tr>
        </table>
        <center><input type="submit" name="dosubmit" value=" 提交 " class="btn" />&nbsp;&nbsp;<input type="button" value=" 返回 " onclick="history.go(-1);" class="btn" /></center></center>
    </div>
</form>
</div>