<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'member_check.php';
$_SESSION["ym"]=time();
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>批量生成 - 后台管理</title>
<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/ico">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<style type="text/css">
.showpic{height: 60px;border: solid 1px #DDDDDD;padding: 5px;}
</style>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-6">
            <form class="form-horizontal" id="form">
            <div class="card">
              <div class="card-header"><h4>批量生成短链</h4></div>
              <div class="card-body">
                <form id="form">
                  <p><textarea class="form-control" name="url" placeholder="请输入 http:// 或 https:// 开头的网址，每行一个" id="url" rows="15"></textarea></p>
                  <p class="d">
                    <select name="type" style="width: 100px;height: 30px">
                      <option value="0">普通跳转</option>
                      <option value="1">防红跳转</option>
                      <option value="2">强开直链</option>
                    </select>
                    <?php 
                    if(strpos($C_dwzon,"-2")!==false){echo "<label><input type=\"radio\" name=\"d\" value=\"-2\"> ".$_SERVER["HTTP_HOST"]."</label> ";}

                    $sql="select D_id,D_domain from sl_domain where D_show=1";
                    $result = mysqli_query($conn,  $sql);
                    if (mysqli_num_rows($result) > 0) {
                    while($row = mysqli_fetch_assoc($result)) {
                            echo "<label><input type=\"radio\" name=\"d\" value=\"".$row["D_id"]."\"> ".$row["D_domain"]."</label> ";
                        }
                    }
                    
                  if(strpos($C_extra,"1")!==false){echo "<label><input type=\"radio\" name=\"d\" value=\"-101\"> 微信随机通道</label> ";}
                  if(strpos($C_extra,"2")!==false){echo "<label><input type=\"radio\" name=\"d\" value=\"-102\"> QQ随机通道</label> ";}
                  ?>
                  </p>
                  
                  <button type="button" onclick="creat()" class="btn btn-primary btn-block" >生成短链接</button>
                </form>
                <span id="msg"></span>
              </div>
            </div>
            </form>
          </div>

          <div class="col-lg-6">
            <form class="form-horizontal" id="form">
            <div class="card">
              <div class="card-header"><h4>返回结果</h4></div>
              <div class="card-body" id="return">
                点击生成按钮后，显示返回结果
              </div>
            </div>
            </form>
          </div>
        </div>
      </div>
    </main>
  </div>
</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>

<script type="text/javascript">
$(".d").find("label input:first").attr("checked","checked");
function creat(){
	lightyear.loading('show');
  $("#return").html("");
  $.ajax({
          type: "post",
          url: "../creat.php?action=creat",
          data: $("#form").serialize(),
          success: function(data) {
          	lightyear.loading('hide');
            var $return="";
            data=JSON.parse(data);
            for($i=0;$i<data.length;$i++){
              if(data[$i].code=="success"){
                $return=$return+"<img src=\"../qrcode.php?url="+data[$i]["short"]+"\" style=\"width:70px;margin-right:10px\"><div style=\"display:inline-block;vertical-align: top\">短链接：<a href=\""+data[$i]["short"]+"\" target=\"_blank\">"+data[$i]["short"]+"</a> <a href=\"myurl.php?S_id="+data[$i]["id"]+"\" class=\"btn btn-info btn-xs\">编辑</a><br>指向网址：<a href=\""+data[$i]["long"]+"\" target=\"_blank\">"+data[$i]["long"]+"</a><br>生成时间："+data[$i]["time"]+"</div><hr>";
              }else{
                $return=$return+"<div id=\"qrcode"+$i+"\" style=\"display:inline-block;vertical-align: top;margin-right:20px;width:60px;height:60px;\"></div><div style=\"display:inline-block;vertical-align: top\">返回信息："+data[$i]["msg"]+"<br>指向网址："+data[$i]["long"]+"<br>"+data[$i]["time"]+"</div><hr>";
              }
            }
            $("#return").html($return);
          }
      })
}
function copy(){
    var e=document.getElementById("short");//对象是content 
        e.select(); //选择对象 
        document.execCommand("Copy"); //执行浏览器复制命令
        $("#copymsg").html("复制成功");
  }

  var path=window.location.pathname;
  $("a").each(function(){
    if(path.indexOf($(this).attr("href"))!=-1){
      console.log($(this).attr("href"));
      $(this).parent("li").addClass("active");
      $(this).parent("li").parent("ul").parent("li").addClass("open active");
    }
  });
</script>
</body>
</html>