<?php
date_default_timezone_set('Asia/Jakarta');

include("common.php");
include("classMySQL.php");
$db = new db_mysql($server_name, $userdb, $passdb, $databasename,"");
include("function.php");
require_once('class.phpmailer.php');
include("class.smtp.php");

mysql_connect($server_name, $userdb, $passdb) or die ("Could not connect to database");
mysql_select_db($databasename);
?>
<?php
date_default_timezone_set('Asia/Jakarta');
$today = date("Y-m-d H:i:s");


$queryvvv = "SELECT * FROM deposit WHERE status='1'"; 
	 
$resultvvv = mysql_query($queryvvv) or die(mysql_error());


while($rowvvv = mysql_fetch_array($resultvvv)){
 $usernameku = $rowvvv['username'];
  $kode = $rowvvv['kode'];
  $ends = $rowvvv['kontrak'];
  $planame = $rowvvv['planame'];
  $jumlah = rupiah($rowvvv['jml']);
  $jumlahs = $rowvvv['jml'];
  $status = $rowvvv['status'];
  $tgldepow = $rowvvv['tgldepo'];
  $tgldepo = formatglxy($rowvvv['tgldepo']);
  $jame = date("H:i:s",strtotime($rowvvv['tgldepo']));
  $nama = $db->dataku("nama", $usernameku);
  $email = $db->dataku("email", $usernameku);
  $hp = $db->dataku("hp", $usernameku);
  $clientdate = (date ("Y-m-d H:i:s"));
$tgl = formatglxy($clientdate);
$waktu = date("H:i:s");
$expireddd = date('Y-m-d', strtotime("+3 day"));


$qrycc = mysql_query("SELECT * from komisi where username='$usernameku' and jenis='komshare' and kode='$kode' ORDER BY username");
  $rrrcc=mysql_num_rows($qrycc);
 
 
 if($rrrcc == $ends){
$db->update("deposit", "status='0', gt='1'", "kode='$kode'");


$isimailexp="<a href='http://".$domain."'><img src='".$logoinvoice."' style='display:inline;outline-style:none;text-decoration:none;' /></a><br><br><br>
<p>Hello ".$nama." (".$usernameku."),</p>
<p>Your investment packages today has ended,</p>
<p><strong>No: ".$kode."<br>
Package: ".$planame."<br>
Amount: ".$jumlah."<br>
Date of Deposit: ".$tgldepo."<br>
</p>
<p><br><br><br>
Regards,<br>
<b>".$bisnisname."</b><br>
".$domain."<br>".$emailadmin."<br>".$hpadmin."</p>";
	   
	    $mail3a = new PHPMailer;
        $mail3a->setFrom($emailadmin, $bisnisname);
        $mail3a->addAddress($email, $nama);
	    $mail3a->IsHTML(true);       
        $mail3a->Subject = ''.$nama.', investment completed';
        $mail3a->msgHTML($isimailexp);
        $mail3a->send();




$isimailexp2="<a href='http://".$domain."'><img src='".$logoinvoice."' style='display:inline;outline-style:none;text-decoration:none;' /></a><br><br><br>
<p>Hello admins ".$bisnisname.",</p>
<p>Investments the following members has expired,</p>
<p><strong>No: ".$kode."<br>
Package: ".$planame."<br>
Amount: ".$jumlah."<br>
Date of Deposit: ".$tgldepo."<br>
</p>
<p><br><br><br>
Regards,<br>
<b>".$bisnisname."</b><br>
".$domain."<br>".$emailadmin."<br>".$hpadmin."</p>";
	   
	    $mail3b = new PHPMailer;
        $mail3b->setFrom($email, $nama);
        $mail3b->addAddress($emailadmin, $bisnisname);
	    $mail3b->IsHTML(true);       
        $mail3b->Subject = ''.$bisnisname.', Investments member '.$usernameku.' has expired';
        $mail3b->msgHTML($isimailexp2);
        $mail3b->send();


  
 
	
	 $isipesan = "".$nama.", Your investment package ".$planame.", No: ".$kode.", Amount: ".$jumlah." has expired.";
	mysql_query("insert into outbox values('', '', '$usernameku', '$hp', '$isipesan', '$clientdate', '1')") or die(mysql_error());
	if($smsgtw == 1 && $jsms == 1){
	$hpne = preg_replace('/\D+/', '', $hp);
	$sms = new smsreguler();
	$sms->username = $userkey;
		$sms->password = $passkey;
		$sms->apikey   = $apikey;
		$sms->setTo($hpne);
		$sms->setText($isipesan);
		$sms->smssend();
	}else if($smsgtw == 1 && $jsms == 2){
	$hpne = preg_replace('/\D+/', '', $hp);
	$sms = new smsmasking();
	$sms->username = $userkey;
		$sms->password = $passkey;
		$sms->apikey   = $apikey;
		$sms->setTo($hpne);
		$sms->setText($isipesan);
		$sms->smssend();
	}else if($smsgtw == 2){
	sendsms($hp, $isipesan) ;
	}else{}
	
}

}
 ?>
<?php
	/* 
	############################[  <about> ] #######################
		S Name   ::       Inv-X Primadesain
		Update   ::       2013 © Primadesain.Com
		Author   ::       Agus Susanto S.kom
		Website  ::		  http://primadesain.com
		Contact  ::		  <primapc57@gmail.com> // +62 85228657360
	
	Primadesain melayani pembuatan website MLM dan Investasi
	( dengan sistem binary, trinary atau matrix dan matahari )
	juga menerima pembuatan website Iklan Baris, Website Profile,
	Reseller, Hyip, dll.
	############################[ </about> ] #######################
	*/
?>
<?php
date_default_timezone_set('Asia/Jakarta');
?>
<?php

if($auto_profits == 1) {

$sqljam="SELECT * FROM deposit WHERE status=1"; 
$dtjam=mysql_query($sqljam);
//--------------------------------------tglend <= '$today'

if($dtjam === FALSE) {
    die(mysql_error()); // TODO: better error handling
}
 
 while($rowjam = mysql_fetch_array($dtjam)){
  $usernamekujam = $rowjam['username'];
  $profitjam = $rowjam['profit'];
  $jenisnye = $rowjam['planame'];
  $jumlahkujam = $rowjam['jml'];
  $nulkode = $rowjam['request'];
  $komisikujam = ($profitjam/100)*$jumlahkujam;
  $kodekujam = $rowjam['kode'];
  $tgldepo = $rowjam['tgldepo']; 
  $harine = $rowjam['dy']; 
  $siklus = $rowjam['sc']; 
  $tgldepoxx = date('Y-m-d', strtotime($tgldepo));
  $jamdepoxx = date('H', strtotime($tgldepo));
  $dydepoxx = date('d', strtotime($tgldepo));
  
  date_default_timezone_set('Asia/Jakarta');
  $tanggale=date("Y-m-d H:i:s");
  $tanggalexx = date ("Y-m-d");
  $daytanggalexx = date ("d");
  $times=date("H");
  $xx = ":00";
  $jam = $times."".$xx;
  $day1 = strtotime($tgldepoxx);
  $day2 = strtotime($tanggalexx);
  $interval = round(abs($day2 - $day1) / (60*60*24));
  
$datevs = strtotime($tgldepo);
$dateve = strtotime("+24 hours", $datevs);
$mulaiprofit = date('Y-m-d H:i:s', $dateve);	






$sponsorematch = $db->dataku("sponsor", $usernamekujam);
$sponsorematch2 = $db->dataku("sponsor", $sponsorematch);
$sponsorematch3 = $db->dataku("sponsor", $sponsorematch2);
$sponsorematch4 = $db->dataku("sponsor", $sponsorematch3);
$sponsorematch5 = $db->dataku("sponsor", $sponsorematch4);
$sponsorematch6 = $db->dataku("sponsor", $sponsorematch5);
$sponsorematch7 = $db->dataku("sponsor", $sponsorematch6);
$sponsorematch8 = $db->dataku("sponsor", $sponsorematch7);
$sponsorematch9 = $db->dataku("sponsor", $sponsorematch8);
$sponsorematch10 = $db->dataku("sponsor", $sponsorematch9);

$komatch = ($komatchroi/100)*$komisikujam;
if($sponsorematch && $komatch > 0) {
			//	$db->insert("komisi", "", "'', '$sponsorematch', '$komatch', '$tanggale', '0', '', 'matching', '$usernamekujam', '".$kodekujam."mch1', ''");
				//$db->insert("databwalet", "", "'', '".$kodekujam."mch1', 'administrator', '$komatch', 'Bonus Matching ROI Level 1 from $usernamekujam', '$sponsorematch', '$tanggale', '1', '$tanggale'");
				}



if($mulaiprofit <= $tanggale ){

  
if($siklus == "day"){
  $ix = $interval+1;
  $qryccv = mysql_query("SELECT * from komisi where username='$usernamekujam' and jenis='komshare' and kode='$kodekujam' ORDER BY username");
  $rrrccv=mysql_num_rows($qryccv);
  $sftrd = $rrrccv+1;
  $jenisejam = "Package $jenisnye profits day $sftrd";

$sqlo = mysql_query("SELECT * FROM komisi WHERE username='$usernamekujam' and jenis='komshare' and total='$ix' and kode='$kodekujam'") or die(mysql_error());
$numo = mysql_num_rows($sqlo);
if(!$numo) {

if(!empty($usernamekujam)){
mysql_query("insert into komisi values('','$usernamekujam', '$komisikujam', '$tanggale', 0, '$ix', 'komshare', '$jenisejam', '$kodekujam', '')") or die(mysql_error());
//$db->insert("databwalet", "", "'', '$kodekujam', 'admin', '$komisikujam', '$jenisejam', '$usernamekujam', '$tanggale', 1, '$tanggale'");
}
}
} else if($siklus == "week"){
  $harine2 = date("N");
  $ix = floor($interval/7);
  $qryccv = mysql_query("SELECT * from komisi where username='$usernamekujam' and jenis='komshare' and kode='$kodekujam' ORDER BY username");
  $rrrccv=mysql_num_rows($qryccv);
  $sftrd = $rrrccv+1;
  $jenisejam = "Package $jenisnye profits week $sftrd";

if($harine == $harine2 && $tanggalexx > $tgldepoxx){
$sqlo = mysql_query("SELECT * FROM komisi WHERE username='$usernamekujam' and jenis='komshare' and total='$ix' and kode='$kodekujam'") or die(mysql_error());
$numo = mysql_num_rows($sqlo);
if(!$numo) {

if(!empty($usernamekujam)){
mysql_query("insert into komisi values('','$usernamekujam', '$komisikujam', '$tanggale', 0, '$ix', 'komshare', '$jenisejam', '$kodekujam', '')") or die(mysql_error());
//$db->insert("databwalet", "", "'', '$kodekujam', 'admin', '$komisikujam', '$jenisejam', '$usernamekujam', '$tanggale', 1, '$tanggale'");

}
}
}
} else if($siklus == "month"){
  $ix = floor($interval/28);
  $qryccv = mysql_query("SELECT * from komisi where username='$usernamekujam' and jenis='komshare' and kode='$kodekujam' ORDER BY username");
  $rrrccv=mysql_num_rows($qryccv);
  $sftrd = $rrrccv+1;
  $jenisejam = "Package $jenisnye profits month $sftrd";

if($dydepoxx == $daytanggalexx && $tanggalexx > $tgldepoxx){
$sqlo = mysql_query("SELECT * FROM komisi WHERE username='$usernamekujam' and jenis='komshare' and total='$ix' and kode='$kodekujam'") or die(mysql_error());
$numo = mysql_num_rows($sqlo);
if(!$numo) {

if(!empty($usernamekujam)){
mysql_query("insert into komisi values('','$usernamekujam', '$komisikujam', '$tanggale', 0, '$ix', 'komshare', '$jenisejam', '$kodekujam', '')") or die(mysql_error());
//$db->insert("databwalet", "", "'', '$kodekujam', 'admin', '$komisikujam', '$jenisejam', '$usernamekujam', '$tanggale', 1, '$tanggale'");

}
}
}
}
}
	

}
}
?>
<?php
mysql_close();
?>
