<?php

  include "../config.php";
  include "../fungsi.php";

  $url = mysqli_real_escape_string($con,$_GET['url']);
  
  $query = mysqli_query($con,"SELECT * FROM link WHERE link2='$url'");
  $check = mysqli_fetch_array($query,MYSQLI_NUM);
  
  if (isset($check[0])) {
      $link1 =$check[1];
      
	  mysqli_query($con,"UPDATE link SET klik=klik+1 WHERE link2 = '$url'");
	  
	  $pesan = 'Ada pengunjung yang mengklik link '.$link1.' :)';
      mysqli_query($con,"insert into pesan1 values(NULL, '$pesan','5', NOW())");
      
      $query = mysqli_query($con,"SELECT * FROM akunn WHERE id=1");
	  $check = mysqli_fetch_array($query,MYSQLI_NUM);
	  if (isset($check[0])) {
		  $urlhost =$check[4];
    	  $emailhost = $check[5];
    	  $passhost = $check[6];
    	  $pixel = $check[8];
    	  $hp = $check[7];
    	  $port = $check[11];
    	  $emailapi = $check[12];
    	  $keyapi = $check[13];
    	  $smsaktif = $check[14];
    	  $telegram_id = $check[16];
    	  $secret_token = $check[17];
	  }   
	        
      echo "<script>
            !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
            n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
            n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
            t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
            document,'script','https://connect.facebook.net/en_US/fbevents.js');
            fbq('init', $pixel); 
            fbq('track', 'PageView');
            </script>
            <noscript><img height='1' width='1' style='display:none'
            src='https://www.facebook.com/tr?id=$pixel&ev=PageView&noscript=1'
            /></noscript>
            ";
            
        $email_api	= urlencode($emailapi);
        $passkey_api	= urlencode($keyapi);
        $no_hp_tujuan	= urlencode($hp);
        $isi_pesan	= urlencode("Info Auto BiznisTop: Barusan ada pengunjung yang mengklik link anda.");
        
        $url	= "https://reguler.medansms.co.id/sms_api.php?action=kirim_sms&email=".$email_api."&passkey=".$passkey_api."&no_tujuan=".$no_hp_tujuan."&pesan=".$isi_pesan;
        
        If($smsaktif==1){
            $result	= SendAPI_SMS($url);
        }   
        
        
        $message_text = $pesan;
        sendMessage($telegram_id, $message_text, $secret_token);
            
            echo "<script language='JavaScript'>document.location='$link1'</script>";
            
  }else{
      echo "<h1>URL Tidak ditemukan :(</h1>";
  }          
            
     
	        
 