<?php if(!defined('IN_SDCMS')) exit;?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>链接管理</title>
<link rel="stylesheet" href="{WEB_ROOT}public/css/ui.css">
<link rel="stylesheet" href="{WEB_ROOT}public/admin/css/layout.css">
<script src="{WEB_ROOT}public/js/jquery.js"></script>
<script src="{WEB_ROOT}public/js/ui.js"></script>
</head>

<body>
    <div class="position">当前位置：扩展管理 > <a href="{THIS_LOCAL}">链接管理</a></div>
    <div class="border">
        <!---->
        <div class="navbar">
            <div class="lefter">
                <a href="javascript:;" data-url="{U('add')}" class="add-iframe btn btn-info mr-sm">添加链接</a>
                <a href="javascript:;" class="btn btn-info dropdown-show mr-sm" data-target="#dropdown-1">批量操作</a>
                <a href="{U('config')}" class="btn btn-yellow mr-sm">链接配置</a>
                
                <div class="dropdown" id="dropdown-1">
                    <a href="javascript:;" class="dropdown-item btach" type="1">批量启用</a>
                    <a href="javascript:;" class="dropdown-item btach" type="2">批量锁定</a>
                    <a href="javascript:;" class="dropdown-item btach" type="3">批量删除</a>
                </div>
                <span class="btn-group btn-group-yellow btn-group-bg">
                    <a class="btn-group-item{if $type==0} active{/if}" href="{U('index','type=0')}">全部</a>
                    <a class="btn-group-item{if $type==1} active{/if}" href="{U('index','type=1')}">未审</a>
                    <a class="btn-group-item{if $type==2} active{/if}" href="{U('index','type=2')}">已审</a>
                    <a class="btn-group-item{if $type==3} active{/if}" href="{U('index','type=3')}">文字</a>
                    <a class="btn-group-item{if $type==4} active{/if}" href="{U('index','type=4')}">Logo</a>
                </span>
            </div>            
        </div>

        <form method="post" class="ui-form">
        <div class="table-wrap">
        <table class="table table-border table-hover table-striped mb mt">
            <thead class="thead-gray">
                <tr>
                	<th width="30" height="30"><label class="checkbox tips" data-align="right-top" data-title="全选/取消"><input type="checkbox" class="checkall" value=""><i></i></label></th>
                    <th width="80">排序</th>
                    <th width="80">ID</th>
                    <th>网站名称</th>
                    <th width="300">网址</th>
                    {if C('link_class')==1}<th width="130">分类</th>{/if}
                    <th width="80">状态</th>
                    <th width="150">操作</th>
                </tr>
            </thead>
            <tbody>
            {php $arr=explode("\r\n",C('link_class_data'))}
            {sdcms:rs pagesize="20" table="sd_link" where="$where" order="ordnum,id"}
            {rs:eof}
            <tr>
                <td colspan="{if C('link_class')==0}7{else}8{/if}">暂无资料</td>
            </tr>
            {/rs:eof}
            <tr>
            	<td><label class="checkbox"><input type="checkbox" name="id" value="{$rs[id]}"><i></i></label></td>
                <td><input type="hidden" name="mid[]" value="{$rs[id]}"><input type="text" class="form-ip" name="ordnum[]" id="ordnum_{$rs[id]}" value="{$rs[ordnum]}" data-rule="required;int;"></td>
                <td>{$rs[id]}</td>
                <td class="text-left">{$rs[webname]}</td>
                <td class="text-left"><a href="{$rs[weburl]}" target="_blank">{$rs[weburl]}</a></td>
                {if C('link_class')==1}<td>{foreach $arr as $key=>$val}{php list($a,$b)=explode('|',$val)}{if $b==$rs[classid]}{$a}{/if}{/foreach}</td>{/if}
                <td><label class="switch switch-info"><input type="checkbox" {if $rs[islock]==1} checked{/if} data-url="{U('switchs','id='.$rs[id].'')}"><span class="switch-checkbox switch-text"></span></label></td>
                <td><a href="javascript:;" data-url="{U('edit',"id=".$rs[id]."")}" class="edit-iframe"><span class="ui-icon-edit"></span> 编辑</a>　<a href="javascript:;" class="del" data-url="{U('del','id='.$rs[id].'')}"><span class="ui-icon-delete"></span> 删除</a></td>
            </tr>
            {/sdcms:rs}
            </tbody>
        </table>
        </div>
        {if $total_rs!=0}
        <div class="page page-right page-info">
            <div class="page-other"><button type="submit" class="btn btn-yellow">保存排序</button></div>
            <div class="page-list"><ul>{$showpage}</ul></div>
        </div>
        {/if}
        </form>
        <!---->
    </div>

<script>
$(function()
{
    $(".add-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"添加链接",
			'text':url,
			'width':'600px',
			'height':'360px',
			'type':3,
			'oktheme':'btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#sdcms-submit").click();
			}
		});
	});
	$(".edit-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"编辑链接",
			'text':url,
			'width':'600px',
			'height':'360px',
			'type':3,
			'oktheme':'btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#sdcms-submit").click();
			}
		});
	});
	$('.switch input[type=checkbox]').on('click',function()
	{
		var url=$(this).attr("data-url");
		var result=($(this).is(':checked'))?1:0;
		$.ajax(
		{
			url:url,
			type:"post",
			dataType:'json',
			data:"islock="+result,
			error:function(e){alert(e.responseText);},
			success:function(d)
			{
				if(d.state=='success')
				{
					sdcms.success(d.msg);
				}
				else
				{
					sdcms.error(d.msg);
				}
			}
		});
	});
	$(".btach").click(function()
	{
		var type=$(this).attr("type");
		var data=[];
		$(".ui-form").find("input[type=checkbox]:checked").each(function()
		{
			if($(this).attr("class")!='checkall' && !$(this).closest("label").hasClass("switch"))
			{
				data.push($(this).val());
			}
		});
        if(data.length==0)
        {
            sdcms.error('至少选择一条内容');
        }
        else
        {
            $.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{U("btach")}',
                data:'id='+data.join(",")+'&type='+type,
                error:function(e){alert(e.responseText);},
                success:function(d)
				{
                    if(d.state=='success')
                    {
                        sdcms.success(d.msg);
                        setTimeout(function(){location.href='{THIS_LOCAL}';},1500);
                    }
                    else
                    {
                        sdcms.error(d.msg);
                    }
                }
            });
        }
    });
	$(".ui-form").form(
	{
		type:2,
		result:function(form)
		{
			$.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{THIS_LOCAL}',
                data:$(form).serialize(),
                error:function(e){alert(e.responseText);},
                success:function(d)
                {
                    if(d.state=='success')
                    {
                        sdcms.success(d.msg);
                        setTimeout(function(){location.href='{THIS_LOCAL}';},1500);
                    }
                    else
                    {
                        sdcms.error(d.msg);
                    }
                }
            });
		}
	});
    $(".del").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialog(
		{
			'title':"操作提示",
			'text':"确定要删除？不可恢复！",
			'oktheme':'btn-info',
			'ok':function(e)
			{
				$.ajax(
				{
                    url:url,type:'post',dataType:'json',
					error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        e.close();
                        if(d.state=='success')
                        {
                            sdcms.success(d.msg);
                            setTimeout(function(){location.href='{THIS_LOCAL}';},1000);
                        }
                        else
                        {
                            sdcms.error(d.msg);
                        }
                    }
                });
			}
		});
    });
})
</script>
</body>
</html>