<?php $this->display(tpl('head')); ?>
<fieldset class="layui-elem-field layui-field-title">
  <legend>已安装插件管理</legend>
</fieldset>
<style>
	.my-tabel thead tr td,.my-tabel tbody tr td{
		text-align: center;
	}
	.layui-form-switch{
		margin-top: 0;
	}
</style>
  <table class="layui-table my-tabel layui-form" lay-filter="test3">
   	<thead>
    	<tr>
    		<td width="50">id</td>
    		<td>插件名称</td>
    		<td>表前戳</td>
    		<td>目录</td>
    		<td>是否在会员显示</td>
    		<td>状态</td>
    		<td>操作</td>
    	</tr>
    </thead>
		<tbody>
			<?php foreach((array)$Plugin as $row)	{ ?>
			<tr>
				<td><?php echo $row[id] ?></td>
    			<td onclick=" return edit_input(this,'模块名称','name')" id="name_<?php echo $row[id] ?>" iid="<?php echo $row[id] ?>"><?php echo $row[name] ?></td>
    			<td><?php echo $row[table] ?></td>
    			<td><?php echo $row[dir] ?></td>
    			<td>
    				<input type="checkbox" id="<?php echo $row[id] ?>" <?php if($row[user_show]) echo 'checked'?> name="user_show"  lay-filter="user_show" lay-skin="switch"  lay-text='开启|关闭'>
    			</td>
    			<td><input type="checkbox" id="<?php echo $row[id] ?>" <?php if($row[state]) echo 'checked'?> name="user_show"  lay-filter="state" lay-skin="switch"  lay-text='开启|关闭'></td>
    			<td>
    				<?php if(!$row[is_copy]){ ?>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/plugin/copy/id_<?php echo $row[id] ?>">复制</a>
    				<?php } ?>
    				<?php if(!$row[is_del]){ ?>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要卸载本模块？此方法不可逆')"  href="/admin/plugin/del/id_<?php echo $row[id] ?>">卸载</a>
    				<?php } ?>	
    			</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
<fieldset class="layui-elem-field layui-field-title">
  <legend>未安装插件管理</legend>
</fieldset>
	<table class="layui-table my-tabel layui-form" lay-filter="test3">
    	<thead>
    		<tr>
    			<td>插件名称</td>
    			<td>表前戳</td>
    			<td>目录</td>
    			<td>开发者信息</td>
    			<td>状态</td>
    			<td>版本</td>
    			<td>更新时间</td>
    			<td>操作</td>
    		</tr>
    	</thead>
		<tbody>
			<?php foreach((array)$install as $row)	{ ?>
			<tr>
    			<td><?php echo $row[plugin][name] ?></td>
    			<td><?php echo $row[plugin][table] ?></td>
    			<td><?php echo $row[path] ?></td>
    			<td>
    				<p>开发者:<?php echo $row[plugin][developer] ?></p>
    				<p>联系email:<?php echo $row[plugin][email] ?></p>
    				<p>开发公司：<?php echo $row[plugin][firm] ?></p>
    			</td>
    			<td>待安装</td>
    			<td><?php echo $row[plugin][version] ?></td>
    			<td><?php echo $row[plugin][update] ?></td>
    			<td>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/plugin/install/dir_<?php echo $row[dir] ?>">安装</a>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要卸载本模块？此方法不可逆')"  href="/admin/plugin/del/step_uninstall/dir_<?php echo $row[dir] ?>">删除</a>
    			</td>
			</tr>
			<?php } ?>
		</tbody>
	</table>
<script>
function edit_input(a,b,c){
	
	$('#'+a.id).removeAttr("onclick"); 
	var iid =$('#'+a.id).attr('iid');
	a.innerHTML='<input type="text"  class="layui-input"  name="name" id="name" value="'+a.innerHTML+'" />';
	$("#name").focus();
	$("#name").blur(function(){
		var value=$(this).attr("value");
		$.ajax({
			url:"/admin/plugin/edit/",
			type: 'POST',
			data:{'value':value,'id':iid,'step':c,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					layer.tips('当前'+b+'修改为：'+value,a);
					$('#'+a.id).attr("onclick"," return edit_input(this)");
					a.innerHTML=data.value;
				}else{
					a.innerHTML=data.value;
					$('#'+a.id).attr("onclick"," return edit_input(this)"); 
					layer.tips(data.text, a);
				}
			}	
		});
		layer.tips('当前模块名称修改为：'+value,a);
	});
}

layui.use(['form','table'], function(){
	var form = layui.form;
	var table = layui.table;
	form.on('switch(state)', function(obj){
	  	var state= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/Plugin/state/",
			type: 'POST',
			data:{'state':state,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					if(state==0){
						layer.tips("本模块已关闭", obj.othis);
					}else{
						layer.tips("本模块已开启", obj.othis);
				  	}
				}else{
					layer.tips(data.text, obj.othis);
				}
			}	
		});
	});
	form.on('switch(user_show)', function(obj){
	  var user_show= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/plugin/user_show/",
			type: 'POST',
			data:{'user_show':user_show,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				console.log(data);
				if(data.code=='0'){
					if(user_show==0){
						layer.tips("已关闭前台显示功能", obj.othis);
					}else{
						layer.tips("已开启前台显示功能", obj.othis);
				  }
				}else{
					layer.tips(data.text, obj.othis);
				}
			}	
		});
	});
});

</script>
<?php $this->display(tpl('foot')); ?>
