<?php
/**
 * 代点列表
**/
include("../php/common.php");
$title='代点列表';
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <nav class="navbar navbar-fixed-top navbar-default">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
          <span class="sr-only">导航按钮</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="./">后台管理</a>
      </div><!-- /.navbar-header -->
      <div id="navbar" class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
          <li>
            <a href="./"><span class="glyphicon glyphicon-user"></span> 平台首页</a>
          </li>
		  <li class="active">
            <a href="./list.php"><span class="glyphicon glyphicon-list"></span> 代点列表</a>
          </li>
		  <li>
            <a href="./bllist.php"><span class="glyphicon glyphicon-calendar"></span> 补领列表</a>
          </li>
		  <li>
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cloud"></span> 卡密管理<b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="./kmlist.php">卡密列表</a></li>
			  <li><a href="./search.php">搜索卡密</a><li>
            </ul>
          </li>
		  <li><a href="./set.php"><span class="glyphicon glyphicon-cog"></span> 系统设置</a></li>
          <li><a href="./login.php?logout"><span class="glyphicon glyphicon-log-out"></span> 退出登陆</a></li>
        </ul>
      </div><!-- /.navbar-collapse -->
    </div><!-- /.container -->
  </nav><!-- /.navbar -->
  <div class="container" style="padding-top:70px;">
    <div class="col-sm-12 col-md-10 center-block" style="float: none;">
<?php

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='add')
{
echo '<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">添加代点任务</h3></div>';
echo '<div class="panel-body">';
echo '<form action="./list.php?my=add_submit" method="POST">
<div class="form-group">
<label>球球大作战账号ID:</label><br>
<input type="text" class="form-control" name="id" value="" required>
</div>
<div class="form-group">
<label>过期时间:</label><br>
<input type="text" id="d11" class="form-control Wdate" name="endtime" value="" onClick="WdatePicker({isShowClear:false})" autocomplete="off" required>
</div>
<input type="submit" class="btn btn-primary btn-block"
value="确定添加"></form>';
echo '<br/><a href="./list.php">>>返回任务列表</a>';
echo '</div></div>';
}
elseif($my=='edit')
{
$id=$_GET['id'];
$row=$DB->get_row("select * from qiu_job where jobid='$id' limit 1");
echo '<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">修改任务信息</h3></div>';
echo '<div class="panel-body">';
echo '<form action="./list.php?my=edit_submit&jobid='.$id.'" method="POST">
<div class="form-group">
<label>球球大作战账号ID:</label><br>
<input type="text" class="form-control" name="id" value="'.$row['id'].'" required>
<font color="green">绑定多个域名请用英文逗号,隔开！</font>
</div>
<div class="form-group">
<label>过期时间:</label><br>
<input type="text" id="d11" class="form-control Wdate" name="endtime" value="'.$row['endtime'].'" onClick="WdatePicker({isShowClear:false})" autocomplete="off" required>
</div>
<input type="submit" class="btn btn-primary btn-block"
value="确定修改"></form>
';
echo '<br/><a href="./list.php">>>返回任务列表</a>';
echo '</div></div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default"));
}
</script>';
}
elseif($my=='add_submit')
{
$id=$_POST['id'];
$endtime=$_POST['endtime'];
if($id==NULL or $endtime==NULL){
showmsg('保存错误,请确保加*项都不为空!',3);
} else {
if($DB->query("insert into `qiu_job` (`id`,`addtime`,`endtime`) values ('".$id."','".$date."','".$endtime."')")){
	showmsg('添加任务成功！<br/><br/><a href="./list.php">>>返回任务列表</a>',1);
}else
	showmsg('添加任务失败！'.$DB->error(),4);
}
}
elseif($my=='edit_submit')
{
$jobid=$_GET['jobid'];
$rows=$DB->get_row("select * from qiu_job where jobid='$jobid' limit 1");
if(!$rows)
	showmsg('当前记录不存在！',3);
$id=$_POST['id'];
$endtime=$_POST['endtime'];
if($id==NULL or $endtime==NULL){
showmsg('保存错误,请确保加*项都不为空!',3);
} else {
if($DB->query("update qiu_job set id='$id',endtime='$endtime' where jobid='{$jobid}'"))
	showmsg('修改任务成功！<br/><br/><a href="./list.php">>>返回任务列表</a>',1);
else
	showmsg('修改任务失败！'.$DB->error(),4);
}
}
elseif($my=='delete')
{
$id=$_GET['id'];
$sql="DELETE FROM qiu_job WHERE jobid='$id'";
if($DB->query($sql))
	showmsg('删除任务成功！<br/><br/><a href="./list.php">>>返回任务列表</a>',1);
else
	showmsg('删除任务失败！'.$DB->error(),4);
}
else
{

$numrows=$DB->count("SELECT count(*) from qiu_job");
$ondate=$DB->count("select count(*) from qiu_job where endtime>'$date'");
echo '<div class="alert alert-info">系统共有'.$numrows.'条代点任务，其中未过期的有'.$ondate.'个。<br/>
<a href="./list.php?my=add" class="btn btn-primary">添加一条任务</a>';
echo '</div>';

echo $con;
?>
      <div class="table-responsive">
        <table class="table table-striped">
          <thead><tr><th>球球ID</th><th>添加时间</th><th>结束时间</th><th>上次运行</th><th>操作</th></tr></thead>
          <tbody>
<?php
$pagesize=30;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{
 $pages++;
 }
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1;
}
$offset=$pagesize*($page - 1);

$rs=$DB->query("SELECT * FROM qiu_job WHERE 1 order by jobid desc limit $offset,$pagesize");
while($res = $DB->fetch($rs))
{
echo '<tr><td><b>'.$res['id'].'</b></td><td>'.$res['addtime'].'</td><td>'.$res['endtime'].'</td><td>'.($res['lasttime']?$res['lasttime']:'等待运行').'</td><td><a href="./list.php?my=edit&id='.$res['jobid'].'" class="btn btn-info btn-xs">编辑</a>&nbsp;<a href="./list.php?my=delete&id='.$res['jobid'].'" class="btn btn-xs btn-danger" onclick="return confirm(\'你确实要删除此任务吗？\');">删除</a></td></tr>';
}
?>
          </tbody>
        </table>
      </div>
<?php
echo'<ul class="pagination">';
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
if ($page>1)
{
echo '<li><a href="list.php?page='.$first.$link.'">首页</a></li>';
echo '<li><a href="list.php?page='.$prev.$link.'">&laquo;</a></li>';
} else {
echo '<li class="disabled"><a>首页</a></li>';
echo '<li class="disabled"><a>&laquo;</a></li>';
}
for ($i=1;$i<$page;$i++)
echo '<li><a href="list.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '<li class="disabled"><a>'.$page.'</a></li>';
for ($i=$page+1;$i<=$pages;$i++)
echo '<li><a href="list.php?page='.$i.$link.'">'.$i .'</a></li>';
echo '';
if ($page<$pages)
{
echo '<li><a href="list.php?page='.$next.$link.'">&raquo;</a></li>';
echo '<li><a href="list.php?page='.$last.$link.'">尾页</a></li>';
} else {
echo '<li class="disabled"><a>&raquo;</a></li>';
echo '<li class="disabled"><a>尾页</a></li>';
}
echo'</ul>';
#分页
}
?>
    </div>
  </div>
<script src="../assets/datepicker/WdatePicker.js"></script>