<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'admin_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;}
#msg,#msg2{color: #f00;margin-top: 10px;}
</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">
                  <p><input type="text" class="form-control input-lg" name="url" placeholder="请输入 http:// 或 https:// 开头的网址" id="url"></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>
                <p id="msg"></p>
              </div>
            </div>
            </form>
          </div>
        
        <div class="col-lg-6">
            <form class="form-horizontal" id="form2">
            <div class="card">
              <div class="card-header"><h4>自定义后缀</h4></div>
              <div class="card-body">
                  <p><input type="text" class="form-control" name="url" placeholder="请输入 http:// 或 https:// 开头的网址" id="url"></p>
                  <p>

                      <div class="input-group" style="width: 100%">
                        <select class="form-control" name="domain" style="width: 15%;display: inline-block;">
                          <option value="0">普通跳转</option>
                          <option value="1">防红跳转</option>
                          <option value="2">强开直链</option>
                        </select>
                                <select class="form-control" name="domain" style="width: 40%;display: inline-block;">
                                  <?php
                                  if(strpos($C_dwzon,"-2")!==false){
                                    echo "<option value=\"".gethttp().$_SERVER["HTTP_HOST"]."\" >".gethttp().$_SERVER["HTTP_HOST"]."/</option>";
                                  }
                                  $sql="select * 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 "<option value=\"".$row["D_http"].$row["D_domain"]."\" >".$row["D_http"].$row["D_domain"]."/</option>";
                                    }
                                  }
                                  ?>

                                </select><input type="text"  name="attach" class="form-control" placeholder="自定义后缀（字母或数字）" style="width: 45%;display: inline-block;">
        </div>


                  </p>
                  <button type="button" onclick="creat(2)" class="btn btn-primary btn-block" >生成短链接</button>
                <p id="msg2"></p>
              </div>
            </div>
            </form>
          </div>

        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
          &times;
        </button>
        <h4 class="modal-title" id="myModalLabel">
          短网址生成
        </h4>
      </div>
      <div class="modal-body" style="text-align: center;" id="modal_body">
        <div id="billImage" style="width: 200px;display: inline-block;margin-bottom: 10px"></div>
        <p>
          <div class="input-group">
            <span class="input-group-addon">原网址</span>
                      <input type="text" class="form-control" id="long">
                      
                  </div>
                  <div id="copymsg" style="font-size: 12px;margin-top: 10px;color: #009900"></div>
              </p>
        <p>
          <div class="input-group">
            <span class="input-group-addon">短链接</span>
                      <input type="text" class="form-control" id="short">
                      <span class="input-group-btn">
                          <button class="btn btn-info" type="button" onclick="copy()">复制</button>
                      </span>
                  </div>
                  <div id="copymsg" style="font-size: 12px;margin-top: 10px;color: #009900"></div>
              </p>
      </div>
    </div>
  </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 src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript">
$(".d").find("label input:first").attr("checked","checked");


function creat(i){
  $("#copymsg").html("");
  $.ajax({
          type: "post",
          url: "../creat.php?from=admin&action=creat"+i,
          data: $("#form"+i).serialize(),
          success: function(data) {
            data=JSON.parse(data);
            data=data[0];
            if(data.code=="success"){
              $('#myModal').modal('show');
              $("#short").val(data.short);
              $("#long").val(data.long);
              $("#urlup").attr("href","?action=up&id="+data.id);


                    $("#billImage").html("<img src='../qrcode.php?url="+data.short+"' style='width:200px'>")


                    $("#msg"+i).html("");
                    if(data.vip==1){
                      $("#vip").hide();
                    }
            }else{
              $("#msg"+i).html(data.msg);
            }
          }
      })
}


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>