<?php
defined("BASEPATH") or exit("No direct access allowed");
if (isset($_GET['hapus']) && is_numeric($_GET['hapus'])) {
		$hapus = $_GET['hapus'];
		mysqli_query($con,"DELETE FROM `link` WHERE `id`=$hapus");
		echo '
		<script>
        	swal("Good Job","berhasil dihapus","success");
        </script>

		';
}
?>

<div class="card-header">
          
          <nav aria-label="breadcrumb">
                      <ol class="breadcrumb bg-warning text-white-all">
                        <li class="breadcrumb-item"><a href="#"><i class="fas fa-tachometer-alt"></i> Home</a></li>
                        <li class="breadcrumb-item"><a href="#"><i class="far fa-file"></i> Link</a></li>
                        <li class="breadcrumb-item active" aria-current="page"><i class="fas fa-list"></i> Tracking</li>
                      </ol>
                    </nav>
</div> 
<div class="card-body">
            <div class="alert alert-primary alert-has-icon p-4">
            <div class="alert-icon"><i class="far fa-lightbulb"></i></div>
            <div class="alert-body">
            <div class="alert-title">Petunjuk:</div>
            1. Fitur ini untuk memendekan link. <br>
            2. Dapat ditracking jumlah klik.<br>
            3. Setiap kali buat pesan email, sisipkan link bisnis anda, agar dapat diketahui jumlah klik dalam email anda.
            </div>
            </div>
        </div> 
<div class="card-body">        
<?php
if (isset($_POST['link1']) && isset($_POST['link2'])) {
	$oldlink = mysqli_real_escape_string($con,$_POST['link1']);
	$newlink = mysqli_real_escape_string($con,$_POST['link2']);
    $newlink = str_replace(' ', '',$newlink);
    
	if (substr($oldlink, 0,4) != 'http') {
		$oldlink = 'http://'.$oldlink;
	}
	
	mysqli_query($con,"INSERT INTO link VALUES (NULL,'$oldlink','$newlink',NOW(),0)");
	
	echo '
		<div class="alert alert-success alert-dismissable" style="margin-top:20px">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon glyphicon glyphicon-remove"></i> Anda berhasil membuat link
            </div>
            
        <script>
        	swal("Good Job","berhasil membuat link","success");
        </script>

		';
}
?>

<form action="" method="post">
<h6>Add New Link</h6>
 <div class="form-group">
 <label for="tiga" class="col-sm-2 control-label">URL Lama</label>
 <div class="col-sm-10">
    <input type="text" class="form-control" name="link1" id="tiga" placeholder="https://biznis.top/" value="" required>
      </div>
  </div>
 
  <div class="form-group">
 <label for="tiga" class="col-sm-2 control-label">URL Baru</label>
 <div class="col-sm-10">
     <?php echo $weburl;?>/link/
    <input type="text" class="form-control" name="link2" id="tiga" placeholder="biznistop [jangan pake https://, .com. Cukup kalimat saja tanpa spasi]" value="" required>
      </div>
  </div>                       

   <div class="col-sm-10">
    <input type="submit" class="btn btn-success btn-lg" value="Create Link"/>
   </div>
</form>
<br><br>
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
    <td width="35%">Link Lama</td>
    <td width="35%">Link Baru</td>
    <td width="10%">klik</td>
    <td width="20%">Tgl.Dibuat</td>
    <td width="20%">Klik (Perbesar)</td>
</tr>
</thead>
<?php
$i=0;
$query = mysqli_query($con,"SELECT * FROM link");
if (mysqli_num_rows($query)) {
	while($link = mysqli_fetch_array($query,MYSQLI_ASSOC)) {
		echo '<tr>
		      <td>'.$link['link1'].'</td>
		      <td><a href="?page=newlink&hapus='.$link['id'].'"><img src="'.$weburl.'/images/email_delete.png" alt="Delete" title="Delete"/></a> <a href="'.$weburl.'/link/'.$link['link2'].'">'.$link['link2'].'</a>
		      <div class="fb-share-button" 
                data-href="'.$weburl.'/link/'.$link['link2'].'" 
                data-layout="button_count">
              </div>
		      </td>
		      <td>'.$link['klik'].'</td>
		      <td>'.$link['tgl'].'</td>
		      <td><!-- <a href=qrcode.php?view='.$weburl.'/link/'.$link['link2'].' target="_blank"><img src='.$weburl.'/images/qrcode.png" width="35"></a> --> 
		      <a href=qrcode.php?view='.$weburl.'/link/'.$link['link2'].' target="_blank"><img src="qrcode.php?view='.$weburl.'/link/'.$link['link2'].'" width="35"> </a>
		      </td>
		      </tr>';
		$i++;
	}

} else {
	echo '<tr><td colspan="4">Anda belum membuat link</td></tr>';
}
echo '</table></div>';
?>
</div></div>


