<?php
session_start();
include('../config.php');
include('../fungsi.php');

$pok = mysqli_real_escape_string($con,$_GET['p']);
$grup = $_SESSION["grup"];
$idref = $_SESSION["ref"];

$query = mysqli_query($con,"SELECT * FROM grup WHERE id='$grup'");
$check = mysqli_fetch_array($query,MYSQLI_NUM);
if (isset($check[0])) {
    $v1 =$check[15];
    $v2 =$check[16];
    $v3 =$check[17];
    $v4 =$check[18];
}

IF($pok=='ok'){

    $queryref = mysqli_query($con,"SELECT * FROM prospek WHERE ID='$idref'");
    $checkref = mysqli_fetch_array($queryref,MYSQLI_NUM);
    if (isset($checkref[0])) {
        $namar =$checkref[1];
        $emailr =$checkref[2];
        $hpr =$checkref[5];
    }	
                
    IF(!empty($idref) && isset($checkref[0])){
        $queryc = mysqli_query($con,"SELECT id FROM gtm WHERE id_member='$idref' AND id_grup='$grup'");
    	$checkc = mysqli_fetch_array($queryc,MYSQLI_NUM);

        if (!isset($checkc['id'])) { 
                        
    		$queryg = mysqli_query($con,"SELECT * FROM grup,champ WHERE grup.id='$grup' AND champ.grup='$grup' ORDER BY champ.sort asc LIMIT 0,1");
    		$grupdata = mysqli_fetch_array($queryg,MYSQLI_ASSOC);	
    		$judul = 'Trima kasih sudah membagikan informasi kami, ini bonus untuk anda';
    		$v1 = $grupdata['v1'];
    		$v2 = $grupdata['v2'];
    		$v3 = $grupdata['v3'];
    		$v4 = $grupdata['v4'];
                		
    		$v3 = str_replace('[nama]',$namar,$v3);
    		$v3 = str_replace('[email]',$emailr,$v3);
    		$v3 = str_replace('[hp]',$hpr,$v3);
                		
    		$query2 = mysqli_query($con,"SELECT * FROM akunn WHERE id=1");
    	    $check2 = mysqli_fetch_array($query2,MYSQLI_NUM);
    	    if (isset($check2[0])) {
    			$urlhost =$check2[4];
    	        $emailhost = $check2[5];
    	        $passhost = $check2[6];
    	        $thp = $check2[7];
    	        $twa = $check2[9];
                $namao = $check2[10];
                $port = $check2[11];
                $emailapi = $check2[12];
    	        $keyapi = $check2[13];
    	        $hpp = $check2[7];
    	        $smsaktif = $check2[14];
    	        $catkaki = $check2[15];
    	        $telegram_id = $check2[16];
    	        $secret_token = $check2[17];
    	        $emailto =$check2[21];
                $namato = $check2[20];
                $usersmtp = $check2[22];
    	    }
        	        
            $thp =substr($thp, 1,12);
            $thp = '62'.$thp;
            $tombolWA ='<a href="https://api.whatsapp.com/send?phone='.$thp.'&text=halo%20pak/ibu%20'.$namao.'%20saya%20mau%20konsultasi" target="_blank"><img src="'.$weburl.'/images/tanyaWA.png"></a>';
                	        
    	    $catkaki ='<font size="1">'.$catkaki.'</font>';
                	        
    	    If($twa==0){
              $isi = $v3 .'<br>'. $catkaki ;    
            }else{
              $isi = $v3 .'<br>'. $tombolWA .'<br>'. $catkaki ; 
            }
                	    
    	    If(empty($usersmtp)){
                $usersmtp = $emailhost;
            }else{    
                $usersmtp = $usersmtp;
            }
        
            //kirimemail
            echo "<font color ='white'>";
            include "../classes/class.phpmailer.php";
            $mail = new PHPMailer; 
            $mail->IsSMTP();
            $mail->SMTPSecure = 'ssl'; 
            $mail->Host = $urlhost; 
            $mail->SMTPDebug = 2;
            $mail->Port = $port; 
            $mail->SMTPAuth = true;
            $mail->Username = $usersmtp; 
            $mail->Password = $passhost;   
            $mail->AddReplyTo($emailto, $namato);
            $mail->SetFrom($emailhost,$namao); 
            $mail->Subject = $judul; 
            $mail->AddAddress($emailr,$namar);  
            $mail->MsgHTML($isi);
            $message_body = $isi .'<br><br>';
            $mail->Body = $message_body;
                            
            if($mail->Send()){ echo "Message has been sent";
                            
                $pesannn ='Anda sukses mengirimkan pesan bonus ke prospek yang mereferensikan produk anda.'; 
                mysqli_query($con,"insert into pesan1 values(NULL, '$pesannn', '1', '$nowtgl')");
                                
                $message_text = $pesannn;
                sendMessage($telegram_id, $message_text, $secret_token);
                            
            }else{ 
                $pesannn ='Anda gagal mengirimkan pesan bonus ke prospek yang mereferensikan produk anda.'; 
                mysqli_query($con,"insert into pesan1 values(NULL, '$pesannn', '2', '$nowtgl')");
                                
                $message_text = $pesannn;
                sendMessage($telegram_id, $message_text, $secret_token);
                        
                echo "Failed to sending message";
            }
            echo "</font>";
                		    
            //kirimemail
                		
            $notifwa=mysqli_fetch_row(mysqli_query($con,"select * from notifwa where id=1"));
            IF($notifwa[4]==1){
                If (strlen($hpr)>9){
                    $hp =substr($hpr, 1,12);
                    $hp = '+62'.$hp;
                    $pesan2 = $v3;
                    $img = $weburl.'/'.$notifwa[3];
                    $key = $notifwa[1];
                    sendWA($hp,$pesan2,$img, $key);
                }
            }
            IF($notifwa[8]==1){
                If (strlen($hpr)>9){
                    $appid = $notifwa[5];
                    $csid = $notifwa[6];
                    $pesan3 = $v3;
                    $hp =substr($hpr, 1,12);
                    $hp2 = '62'.$hp;
                    sendWoowandroid($appid, $csid, $pesan3, $hp2);
                }
            }    
                            
        }
    }    
    $urltrims = $weburl.'trims';
    echo "
        <script>
        location.assign('$urltrims');
        </script>
    ";            
}                
                
?>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Trima kasih, bantu Viralkan ya</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" type="image/png" href="../form/images/icons/favicon.ico"/>
	<link rel="stylesheet" type="text/css" href="../form/vendor/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../form/fonts/font-awesome-4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="../form/vendor/animate/animate.css">
	<link rel="stylesheet" type="text/css" href="../form/vendor/css-hamburgers/hamburgers.min.css">
	<link rel="stylesheet" type="text/css" href="../form/vendor/select2/select2.min.css">
	<link rel="stylesheet" type="text/css" href="../form/css/util.css">
	<link rel="stylesheet" type="text/css" href="../form/css/main.css">
	<link href="sit.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    
    <style> form {width:500px; margin:50px auto;}.search {padding:8px 15px;  background: #f0f8ff; border:2px solid #008080;              } 
.button {position:relative; left:-4px; padding:10px 15px;   border:0px solid #008080; background-color: #6B8E23; color:#fafafa; font-weight:bold;}              .button:hover {background: #008080;color:#fafafa;}          .button:active {background:#9ACD32;}         
    </style>   
</head>
<body>

    <?php
        $grup = md5($grup);
        $id = md5($_SESSION["idprosfek"]);
    ?>
                
	<div class="contact1">
		<div class="container-contact1">
			<!-- <div class="contact1-pic js-tilt" data-tilt> 
				<p align ="center"></p><img src="../form/images/share.png" alt="IMG" width="25%"> </p> 
			</div> -->
			
			<?php
				$link = $weburl.'v/ref.php?g='.$grup.'&r='.$id;
				$link =createIsgd($link);
				
				echo '<figure><img src="'.$weburl.'qrcode.php?view='.$link.'" width="50%"/>
				    <figcaption>QRCode Link Share Anda</figcaption></figure>
				    ';
				?>
                
				<!-- <span class="contact1-form-title"> </span> -->
					
				
                
				<div class="wrap-input1 validate-input" data-validate = "Name is required">
				    <p><?php echo $v4 ?></p> 
				    <br>
				    <center>Ini adalah Link Share Anda ke media sosial</center>
				    
					<b><input id="myInput" class="input1" type="text" name="name" placeholder="Name" value="<?php echo $weburl ?>v/ref.php?g=<?php echo $grup ?>&r=<?php echo $id ?>" readonly></b>
					<button type="submit" onclick="myFunction()" class="btn btn-primary">Copy</button>
					<!-- <b><input id="myInput2" class="input1" type="text" name="name" placeholder="Name" value="<?php echo $link ?>" readonly></b>
					<button type="submit" onclick="myFunction2()" class="btn btn-primary">Copy</button>
					<span class="shadow-input1"></span> -->
				</div>

                <!-- <p>
                    <a class="post-share facebook" href="http://www.facebook.com/plugins/like.php?href=<?php echo $weburl ?>v/ref.php?g=<?php echo $grup ?>&r=<?php echo $id ?>&width&layout=standard&action=like&show_faces=true&share=true&height=80&appId=#################" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=100,width=200');return false;">Facebook<span></span></a>
                    <a class="post-share twitter" href="https://twitter.com/share?url=<?php echo $weburl ?>v/ref.php?g=<?php echo $grup ?>&r=<?php echo $id ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">Twitter<span></span></a>
                    <a class="post-share gplus" href="https://plus.google.com/share?url=<?php echo $weburl ?>v/ref.php?g=<?php echo $grup ?>&r=<?php echo $id ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">Google Plus<span></span></a>
                    <a class="post-share stumble" href="http://www.stumbleupon.com/submit?url=<?php echo $weburl ?>v/ref.php?g=<?php echo $grup ?>&r=<?php echo $id ?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=800');return false;">Stumbleupon<span></span></a>
                </p> -->
				
			
		</div>
	</div>

    <script type="text/javascript">
        $(document).ready(function(){
                get_social_counts();
                //maybe_some_other_functions_too();
            });
    </script>
    
    <script type="text/javascript">
        function get_social_counts() {
        var thisUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
        $.ajax({
            type: "GET",
            url: '<?php echo $weburl ?>/trims/count.php?thisurl='+thisUrl,
            dataType: "json",
            success: function (data){
                $('a.post-share.twitter span').html(data.twitter);
                $('a.post-share.facebook span').html(data.facebook);
                $('a.post-share.gplus span').html(data.gplus);
                $('a.post-share.stumble span').html(data.stumble);
            }
        });
        }
    </script>
    
     <script type="text/javascript">
        function myFunction() {
          var copyText = document.getElementById("myInput");
          copyText.select();
          copyText.setSelectionRange(0, 99999); 
          document.execCommand("copy");
        
          alert("url: " + copyText.value + " sudah dicopy. Paste di medsos anda");
        }
        function myFunction2() {
          var copyText = document.getElementById("myInput2");
          copyText.select();
          copyText.setSelectionRange(0, 99999); 
          document.execCommand("copy");
        
          alert("url: " + copyText.value + " sudah dicopy. Paste di medsos anda");
        }
     </script>     
</body>
</html>
