<?php
if (basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../index.php\">";
exit();} 
?>
<?php
if (empty($_SESSION["valid_admin"])){
echo "<p align=center><br><br><br><br><br><br><font size=\"6\" color=\"#FF0000\">ILLEGAL ACCESS !!";
echo "<meta http-equiv=\"refresh\" content=\"2; url=../../index.php\">";
exit();}
?>
<?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> ] #######################
	*/
?>
<h1><img src="images/icon-48-user.png" width="48" height="48" align="absmiddle" /> Add Deposit</h1>
<script>
function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
</script>
 <?php
$act = $_GET['act'];
if($act == 1) { 
echo "<div class='alert-box successs'><span>Success : </span>Deposit berhasil di input!</div>";
}
?>
<form name="addepo" method="post" id="addepo" action="?go=addepo&page=submit">

  <table width="90%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#EEEEEE">
    <tr> 
      <td colspan="2" bgcolor="#E2E2E2"><div align="center"><strong><font size="2">INPUT 
          DEPOSIT</font></strong></div></td>
    </tr>
    <tr> 
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr> 
      <td width="47%" align="right" bgcolor="#FFFFFF">User ID
        : </td>
      <td width="53%" bgcolor="#FFFFFF"><label> 
        <select name="mid" onchange="value" class="form" required="required">
          <option value="" >-- Pilih username --</option>
         <?php
					$tanggal=date("Y-m-d");
					$sql=mysql_query("select username from member where status=1 order by username");
					while($sto=mysql_fetch_row($sql)) {
						if(isset($mid)&& $mid == $sto[0]) {
							$pilih = "selected";
						} else {	
							$pilih = "";
						}	
					?>
          <option value="<?php echo $sto[0]; ?>" <?php echo $pilih; ?>> 
          <?php echo $sto[0]; ?>
          <?php
					}
					?>
        </select>
        </label></td>
    </tr>
    <tr> 
      <td align="right" bgcolor="#FFFFFF">Pilih Deposit  :      </td>
      <td bgcolor="#FFFFFF">
	  <select name="produk" id="produk" style="width:220px" required="required">
              <option value="" selected="selected">[ Pilih Paket]</option>
	 <?php
	
	for($i=0;$i<$batas_paket;$i++) {	
	 $ic = $i;
	 $icc = $i+1;
	 $produke = $lead[$ic];
	 $byay = rupiah($by[$ic]);
	 $byay2 = rupiah($byx[$ic]);
	 
	 echo"<option value='".$icc."' ".$dss.">$produke - $byay</option>";
	 }
	 ?> 	  
		  </select> 
		 
        </td>
    </tr>
	 
    <tr> 
      <td align="right" bgcolor="#FFFFFF">Tanggal Deposit :</td>
      <?php  $tt = date('Y-m-d', strtotime($clientdate)); ?>
	  <td bgcolor="#FFFFFF">
	  <input name="tanggal" id="tanggal" size="20" maxlength="30" required="required"/>  &nbsp;<img src="../images/calendar_select_none.png" alt="Kalender" id="tanggal_trig" title="Date selector" align="absmiddle" width="24px"/>
					<script type="text/javascript">
            Calendar.setup({
                inputField : "tanggal",
                ifFormat : "%e-%m-%Y",
                button : "tanggal_trig",
                align : "Bl",
                singleClick : true
            });
           

            $("tanggal_trig").observe("click", showCalendar);

            function showCalendar(event){
                var element = event.element(event);
                var offset = $(element).viewportOffset();
                var scrollOffset = $(element).cumulativeScrollOffset();
                var dimensionsButton = $(element).getDimensions();
                var index = $("widget-chooser").getStyle("zIndex");

                $$("div.calendar").each(function(item){
                    if ($(item).visible()) {
                        var dimensionsCalendar = $(item).getDimensions();

                        $(item).setStyle({
                            "zIndex" : index + 1,
                            "left" : offset[0] + scrollOffset[0] - dimensionsCalendar.width + dimensionsButton.width + "px",
                            "top" : offset[1] + scrollOffset[1] + dimensionsButton.height + "px"
                        });
                    };
                });
            };
        </script>  
      </td>
    </tr>
	
    <tr>
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr> 
      <td align="right" bgcolor="#FFFFFF"><label></label></td>
      <td bgcolor="#FFFFFF">
	 
	  <input type="submit" name="Submit" value="Submit" class="submit"></td>
    </tr>
    <tr> 
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
  </table>

</form>
<script language="JavaScript" type="text/javascript">
 var frmvalidator = new Validator("addepo");
  frmvalidator.addValidation("mid","dontselect=000","Pilih Username");
   frmvalidator.addValidation("produk","dontselect=000","Pilih Deposit");
</script>

<p>

<?php
if (isset($_GET['page']) && $_GET['page'] == "submit") {

$mid = $_POST['mid'];
$produk = $_POST['produk'];
$tgladd = $_POST['tanggal'];

$ttadd = date('Y-m-d', strtotime($tgladd));

$cstime    = (date ("H:i:s"));
$activesdate = $ttadd." ".$cstime;

  
  
  
  
  $produk = anti_injection($_POST['produk']);
if($produk == 1){
$biaya = $biaya1;
$biayax = $biayax1;
$myproduk = $jenis1;
$profite = $invest_profits1;
$priode = $inv_kontrak1;
$siklus = $invest_priod1;
}else if($produk == 2){
$biaya = $biaya2;
$biayax = $biayax2;
$myproduk = $jenis2;
$profite = $invest_profits2;
$priode = $inv_kontrak2;
$siklus = $invest_priod2;
}else if($produk == 3){
$biaya = $biaya3;
$biayax = $biayax3;
$myproduk = $jenis3;
$profite = $invest_profits3;
$priode = $inv_kontrak3;
$siklus = $invest_priod3;
}else if($produk == 4){
$biaya = $biaya4;
$biayax = $biayax4;
$myproduk = $jenis4;
$profite = $invest_profits4;
$priode = $inv_kontrak4;
$siklus = $invest_priod4;
}else if($produk == 5){
$biaya = $biaya5;
$biayax = $biayax5;
$myproduk = $jenis5;
$profite = $invest_profits5;
$priode = $inv_kontrak5;
$siklus = $invest_priod5;
}else if($produk == 6){
$biaya = $biaya6;
$biayax = $biayax6;
$myproduk = $jenis6;
$profite = $invest_profits6;
$priode = $inv_kontrak6;
$siklus = $invest_priod6;
}else if($produk == 7){
$biaya = $biaya7;
$biayax = $biayax7;
$myproduk = $jenis7;
$profite = $invest_profits7;
$priode = $inv_kontrak7;
$siklus = $invest_priod7;
}else if($produk == 8){
$biaya = $biaya8;
$biayax = $biayax8;
$myproduk = $jenis8;
$profite = $invest_profits8;
$priode = $inv_kontrak8;
$siklus = $invest_priod8;
}else if($produk == 9){
$biaya = $biaya9;
$biayax = $biayax9;
$myproduk = $jenis9;
$profite = $invest_profits9;
$priode = $inv_kontrak9;
$siklus = $invest_priod9;
}else if($produk == 10){
$biaya = $biaya10;
$biayax = $biayax10;
$myproduk = $jenis10;
$profite = $invest_profits10;
$priode = $inv_kontrak10;
$siklus = $invest_priod10;
}else{
}

  
 $hrgn= $produk;
 $pringkate =$myproduk;
  
  
  


$angkaunik = substr(str_shuffle(str_repeat("12365478985823641257846982357418965", 24)), 0, 3);
//$amount = $biaya;

$amount = $biaya;

if($siklus == "day"){
       $harine = date("d");	
	}else if($siklus == "week"){
       $harine = date("N");	
	}else if($siklus == "month"){
       $harine = date("m");	
	}else{}


$jumlahdepone = rupiah($amount);
$prodd="".$myproduk."";

$datev = $activesdate;
$datevs = strtotime($datev);

	//if($siklus == "day"){
//$kontrad_dt = ($priode/5);
//$tmbahan_dt = ($kontrad_dt*2);
//$ttlkontrak = $priode+$tmbahan_dt;
//}else{
$ttlkontrak = $priode;
//}

$dateve = strtotime("+".$ttlkontrak." ".$siklus."", $datevs);
$expired = date('Y-m-d H:i:s', $dateve);	


$tkk = date('d-m-Y-H-i-s', strtotime($clientdate));
$tokens = md5(md5(date("Y-m-d H:i:s")));

$initiale = substr(str_shuffle(str_repeat("ABCEFGHIJKLMNPRSTUVWXYZ", 36)), 6, 2);
$stkode = strtotime(date("Y-m-d H:i:s"));
$stmpkode = $initiale."".$stkode;
$uraian = "add from admin";

$sess0 = substr(str_shuffle(str_repeat("WZTYG31113I3N16ZU3F4248V2JY1Q86NYRIL233V5JD3U356BG3Q182Y5I2J598C3VPJ8S213MI741UD84Z1Z", 125)), 34, 48);


$invc = "add_package_".$mid."_".$tkk."_".$sess0;
$inv = "http://".$domain."/invoice/".$invc.".pdf";

$spnex = $db->dataku("sponsor", $mid);

	
	
		
$db->insert("dataewalet3", "", "'', '$stmpkode', '$mid', '$amount', '', '$activesdate', '$activesdate', '1', '$produk', '$pringkate', '$profite', '$angkaunik', '$priode', '$siklus'");
		
		
		
			 
				$db->update("member", "harga='$produk', stage='$pringkate'", "username='$usere'");	
			
			$db->update("reinv", "status='1'", "username='$mid'");
			$cekadadepo = mysql_query("select * from deposit where kode='$stmpkode'");
$ada_deponec = mysql_num_rows($cekadadepo); 
if(!$ada_deponec) {
			$db->insert("deposit", "", "'', '$mid', '$stmpkode', '$amount', '1', '$datev', '$expired', '$produk', '$pringkate', '$profite', '$priode', '$harine', '$siklus', '', ''"); 
}
		  
            //$db->insert("invoice", "", "'', '$mid', '$stmpkode', '$invc', 'clientdate'"); 
			
			
			
			
			    $trans_code=$stmpkode;
				$jumlahe=$amount;
				$users=$mid;
				$plan=$produk;
				$usere=$mid;
				$jumlah=$amount;
				$username=$mid;
				$kode=$stmpkode;
				
							
							
							
					$sponsore = $db->dataku("sponsor", $usere);
			$sponsorelev2 = $db->dataku("sponsor", $sponsore);
			$sponsorelev3 = $db->dataku("sponsor", $sponsorelev2);
			$sponsorelev4 = $db->dataku("sponsor", $sponsorelev3);
			$sponsorelev5 = $db->dataku("sponsor", $sponsorelev4);
			$sponsorelev6 = $db->dataku("sponsor", $sponsorelev5);
			$sponsorelev7 = $db->dataku("sponsor", $sponsorelev6);
			$sponsorelev8 = $db->dataku("sponsor", $sponsorelev7);
			$sponsorelev9 = $db->dataku("sponsor", $sponsorelev8);
			$sponsorelev10 = $db->dataku("sponsor", $sponsorelev9);		
							
				$kmspons = explode("|", $db->config("komisi_sponsor"));	
			$komsponx = ($kmspons[0]/100)*$jumlah;
			$komsponx2 = ($kmspons[1]/100)*$jumlah;
			$komsponx3 = ($kmspons[2]/100)*$jumlah;
			$komsponx4 = ($kmspons[3]/100)*$jumlah;
			$komsponx5 = ($kmspons[4]/100)*$jumlah;
			$komsponx6 = ($kmspons[5]/100)*$jumlah;
			$komsponx7 = ($kmspons[6]/100)*$jumlah;
			$komsponx8 = ($kmspons[7]/100)*$jumlah;
			$komsponx9 = ($kmspons[8]/100)*$jumlah;
			$komsponx10 = ($kmspons[9]/100)*$jumlah;			
							
							
							
				if($sponsore && $komsponx > 0) {  
					$db->insert("komisi", "", "'', '$sponsore', '$komsponx', '$clientdate', '0', '', 'komsponsor', '$usere', '".$trans_code."sp', ''");
				}
			   
			    if($sponsorelev2 && $komsponx2 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev2', '$komsponx2', '$clientdate', '0', '', 'komsponsor2', '$usere', '".$trans_code."sp2', ''");
				}
				if($sponsorelev3 && $komsponx3 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev3', '$komsponx3', '$clientdate', '0', '', 'komsponsor3', '$usere', '".$trans_code."sp3', ''");
				}
				if($sponsorelev4 && $komsponx4 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev4', '$komsponx4', '$clientdate', '0', '', 'komsponsor4', '$usere', '".$trans_code."sp4', ''");
				}	
				if($sponsorelev5 && $komsponx5 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev5', '$komsponx5', '$clientdate', '0', '', 'komsponsor5', '$usere', '".$trans_code."sp5', ''");
				}
				if($sponsorelev6 && $komsponx6 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev6', '$komsponx6', '$clientdate', '0', '', 'komsponsor6', '$usere', '".$trans_code."sp6', ''");
				}
				if($sponsorelev7 && $komsponx7 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev7', '$komsponx7', '$clientdate', '0', '', 'komsponsor7', '$usere', '".$trans_code."sp7', ''");
				}
				if($sponsorelev8 && $komsponx8 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev8', '$komsponx8', '$clientdate', '0', '', 'komsponsor8', '$usere', '".$trans_code."sp8', ''");
				}
				if($sponsorelev9 && $komsponx9 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev9', '$komsponx9', '$clientdate', '0', '', 'komsponsor9', '$usere', '".$trans_code."sp9', ''");
				}
				if($sponsorelev10 && $komsponx10 > 0) {
					$db->insert("komisi", "", "'', '$sponsorelev10', '$komsponx10', '$clientdate', '0', '', 'komsponsor10', '$usere', '".$trans_code."sp10', ''");
				}			
							
							
							
				$jsp=$db->jumlahsp($sponsore);
					$db->update("upline", "sp='$jsp'", "username='$sponsore'");
				
			
				
				
					
			

	$tgwal = formatgl($datev);
$tgend = formatgl($expired);

	
    $nama = $db->dataku("nama", $mid);
    $hp = $db->dataku("hp", $mid);
		$email = $db->dataku("email", $mid);
		$jumlahdepone = rupiah($amount);
		$keterangan = $uraian;
		 $tgl = formatgl($clientdate);
		$waktu = date("H:i:s");
		$hostaddress = gethostbyaddr($_SERVER['REMOTE_ADDR']);	
	    $paketnv = $myproduk;
		$pf = $profit;
	
$tgl_inv = date('d-m-Y', strtotime($clientdate));
$waktu_inv = date('H:i', strtotime($clientdate));

if($hp){
$isipesan = "Helo ".$nama.", Your investment has been active, ".$prodd.", Amount ".$jumlahdepone.".";
	mysql_query("insert into outbox values('', '', '$mid', '$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{}
}

$isimail_e="<a href='http://".$domain."'><img src='".$logoinvoice."' style='display:inline;outline-style:none;text-decoration:none;' /></a><br><br><br>
<p>Helo ".$nama." (".$mid."),</p>
<p>Your Investment has been active.</p>
<p><strong>No: ".$stmpkode."</strong><br>
Package: ".$prodd."<br>
Amount: ".$jumlahdepone."<br>
Start day : ".$tgwal."<br>
End day : ".$tgend."<br>
</p>

<p><br><br><br>
Salam,<br>
<b>".$bisnisname."</b><br>
".$domain."<br>".$emailadmin."<br>".$hpadmin."</p>";
	   
	    $mail3b = new PHPMailer;
		if($smaile == 1){	
//$mail3b->IsSMTP(); // telling the class to use SMTP
$mail3b->Host       = $smtphost; // SMTP server
$mail3b->SMTPAuth   = true;                  // enable SMTP authentication
$mail3b->Host       = $smtphost; // sets the SMTP server
$mail3b->Port       = $smtport;                    // set the SMTP port for the GMAIL server
$mail3b->Username   = $smtpuser; // SMTP account username
$mail3b->Password   = $smtpass;        // SMTP account password
}
        $mail3b->setFrom($emailadmin, $bisnisname);
        $mail3b->addAddress($email, $nama);
	    $mail3b->IsHTML(true);       
        $mail3b->Subject = ''.$nama.', Your Investment has been active.';
        $mail3b->msgHTML($isimail_e);
	$mail3b->AddAttachment("../invoice/".$invc.".pdf");      // attachment
    $mail3b->send();	



		header("location: ?go=addepo&act=1");
		exit;
}

?>