<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<title>模块管理</title>
		<link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
		<link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
		<link rel="stylesheet" href="/static/web/css/admin.css">
		<script src="/static/web/js/jquery.min.js"></script>
		<script src="/static/web/js/bootstrap.min.js"></script>
		<script src="/static/web/js/webajax.js"></script>
		<script>
			function getmodule(action, hash) {
				fetch('module_main.php?action=download&hash=' + hash).then(resp => resp.text()).then((d) => {
					$DE('status_' + hash).innerHTML = d;
				});
				$DE('manager_' + hash).style.display = 'block';
			}
		</script>
	</head>
	<body>
		<form name="form1" action="plus_add.php" method="post">
			<input type="hidden" name="dopost" value="save">
			<table align="center" class="table maintable my-3">
				<tr>
					<td>
						<a class="btn btn-success btn-sm" href="module_main.php">全部</a>
						<a class="btn btn-success btn-sm" href="module_main.php?moduletype=soft">模块</a>
						<a class="btn btn-success btn-sm" href="module_main.php?moduletype=templets">模板</a>
						<a class="btn btn-success btn-sm" href="module_main.php?moduletype=plus">小插件</a>
						<a class="btn btn-success btn-sm" href="module_main.php?moduletype=patch">补丁</a>
						<a class="btn btn-success btn-sm" href="module_upload.php">上传</a>
					</td>
				</tr>
			</table>
			<table align="center" class="table maintable mb-3">
				<tr>
					<td bgcolor="#f8fafb" colspan="6">模块管理</td>
				</tr>
				<tr bgcolor="#f8f9fa" align="center">
					<td width="26%">模块名称</td>
					<td width="10%">发布时间</td>
					<td width="10%">编码</td>
					<td width="10%">类型</td>
					<td width="12%">模块状态</td>
					<td>操作</td>
				</tr>
				<?php if (count($modules) > 0) foreach($modules as $k => $v) {?>
				<tr align="center">
					<td><?php echo $v['name'];?></td>
					<td><?php echo $v['time'];?></td>
					<td>
						<?php
						if ($cfg_soft_lang != $v['lang']) echo $v['lang'];
						else  echo $v['lang'];
						?>
					</td>
					<td><?php echo $types[$v['moduletype']];?></td>
					<td>
						<?php
						$file = DEDEDATA."/module/{$v['hash']}.xml";
						if (file_exists($file)) {
							if (file_exists(DEDEDATA."/module/{$v['hash']}-readme.php")){
								echo "<span class='btn btn-success btn-sm'>已安装</span><a href='module_main.php?action=uninstall&hash={$v['hash']}' class='btn btn-outline-danger btn-sm'>卸载</a>";
							} else {
								echo "<span class='btn btn-warning btn-sm'>未安装</span><a href='module_main.php?action=setup&hash={$v['hash']}' class='btn btn-outline-success btn-sm'>安装</a>";
							}
						} else {
							echo "<div id=\"status_{$v['hash']}\"><a href=\"javascript:getmodule('download','{$v['hash']}')\" class=\"btn btn-outline-warning btn-sm\">下载</a></div>";
						}
						?>
					</td>
					<td>
						<div id="manager_<?php echo $v['hash'];?>" <?php if (!file_exists(DEDEDATA."/module/{$v['hash']}.xml")) echo "style='display:none'"?>>
							<a class="btn btn-light btn-sm" href="module_main.php?action=view_developoer&hash=<?php echo $v['hash'];?>"><i class="fa fa-user-circle"></i> 贡献者</a>
							<a class="btn btn-light btn-sm" href="module_main.php?action=view&hash=<?php echo $v['hash'];?>"><i class="fa fa-eye"></i> 查看</a>
							<a class="btn btn-light btn-sm" href="module_main.php?action=edit&hash=<?php echo $v['hash'];?>"><i class="fa fa-pencil-square"></i> 修改</a>
							<a class="btn btn-danger btn-sm" href="module_main.php?action=del&hash=<?php echo $v['hash'];?>"><i class="fa fa-trash"></i> 删除</a>
						</div>
					</td>
				</tr>
				<?php }?>
			</table>
		</form>
	</body>
</html>