<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
function callBanks($forWhat, $bankType, $returnType=0) {
	# $returnType: 0 => return function as array
	# $returnType: 1 => return function as decorated text
	if (isset($forWhat) && trim($forWhat)!="" && isset($bankType) && trim($bankType)!="") {
		$forWhat = trim($forWhat);
		$bankType = trim($bankType);
		if ($bankType=="1" || strtolower($bankType)=="bca" || strtolower($bankType)=="bc" || strtolower($bankType)=="b") {
			$jenisBank = 1;
		} else
		if ($bankType=="2" || strtolower($bankType)=="man" || strtolower($bankType)=="mandiri" || strtolower($bankType)=="ma" || strtolower($bankType)=="m") {
			$jenisBank = 2;
		} else
		if ($bankType=="3" || strtolower($bankType)=="bni" || strtolower($bankType)=="bn" || strtolower($bankType)=="n") {
			$jenisBank = 3;
		} else
		if ($bankType=="4" || strtolower($bankType)=="bri" || strtolower($bankType)=="br" || strtolower($bankType)=="r") {
			$jenisBank = 4;
		}
		
		if (strtolower($forWhat)=="deposit" || strtolower($forWhat)=="depo" || strtolower($forWhat)=="dp" || strtolower($forWhat)=="d") {
			$gbank = array(
			1 => array("bank"=>"BCA", "src"=>''.$absDom.'/images/bca.png', "norek"=>"687 106 5311", "namarek"=>"Rokiyah"),
			2 => array("bank"=>"Mandiri", "src"=>''.$absDom.'/images/mandiri.png', "norek"=>"163 000 1115 552", "namarek"=>"Wanto"),
			3 => array("bank"=>"BNI", "src"=>''.$absDom.'/images/bni.jpg', "norek"=>"034 477 3796", "namarek"=>"Ugi Sugi Yarsih"),
			);
			if ($returnType==0) {
				return $gbank[$jenisBank];
			} else if ($returnType==1) {
				$strLempar  = '';
				$strLempar .= '<div style="width:210px;height:110px;border:2px #00aaff solid;border-radius:10px;margin:0 2px;text-align:center;">';
					$strLempar .= '<img style="text-align:center;width:200px;height:67px;" src="'.$gbank[$jenisBank]["src"].'" alt="'.$gbank[$jenisBank]["bank"].'" /><br/>';
					$strLempar .= ''.$gbank[$jenisBank]["namarek"].'<br/>';
					$strLempar .= ''.$gbank[$jenisBank]["norek"].'';
				$strLempar .= '</div>';
				return $strLempar;
			}
		}
		
		if (strtolower($forWhat)=="withdraw" || strtolower($forWhat)=="wd" || strtolower($forWhat)=="w") {
			return null;
		}
	}
}

function sendMail($parKd) {
	$rsm=array();$qm="SELECT a.*, b.username, b.pass FROM members a 
		LEFT JOIN accounts b ON b.kdaccount=a.kdaccount
		WHERE a.kdmember='$parKd'";
	callRS($rsm, $qm);
	$email_target = $rsm[0]["email"];
	$topic = "Pendaftaran UserID ".$rsm[0]["username"]." dari AgenVIP88.com";
	##################################
	$cemail = "info.agenvip88@gmail.com";
	$cname = "AgenVIP88";
	$cc = "info.agenvip88@gmail.com";
	$to = "$email_target";
	$subject = $topic;
	$headers = "From: ".$cemail."\r\n";
	$headers .= "Reply-To: ".$cemail."\r\n";
	if ($cc!="") {
		#$to .= ", $cc";
		$headers .= "CC: ".$cc."\r\n";
	}
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	$message = '';
	$message .= '<div style="width:600px;border:1px blue solid;border-left:4px blue solid;border-bottom:4px blue solid;margin:10px;">';
		$message .= '<div style="width:580px;text-align:center;margin:10px;">';
			$message .= '<a href="http://www.agenvip88.com/"><img src="http://www.agenvip88.com/img/_logo.big.png" alt="www.agenvip88.com" /></a>';
		$message .= '</div>';
		$message .= '<div style="text-align:center;"><br/>SELAMAT, pendaftaran Anda telah berhasil!</div>';
		$gameURL = '';
		$message .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
			$message .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-right:0;border-bottom:0;">';
				$message .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">UserName</td>
					<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
					<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">'.$rsm[0]["username"].'</td>
				</tr>';
				$message .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">Password</td>
					<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
					<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">'.$rsm[0]["pass"].'</td>
				</tr>';
				$message .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">Game URL</td>
					<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
					<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;"><a href="'.$gameURL.'">'.$gameURL.'</a></td>
				</tr>';
			$message .= '</table>';
		$message .= '</div>';
		
		$message .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
			$message .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px #888 solid;border-right:0;border-bottom:0;">';
				$message .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">No. Rekening</td>
					<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
					<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["norek"].'</td>
				</tr>';
				$message .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">Nama Rekening</td>
					<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
					<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["namarek"].'</td>
				</tr>';
			$message .= '</table>';
		$message .= '</div>';
		
		$message .= '<div style="text-align:center;">Untuk memulai bermain, silahkan lakukan transfer deposit Anda dahulu.</div>';
		$message .= '<div style="text-align:center;">&nbsp;</div>';
		$message .= '<div style="text-align:center;">Setelah Anda men-transfer deposit,</div>';
		$message .= '<div style="text-align:center;">silahkan isi form deposit di: <a href="'.absDom.'/deposit/">'.absDom.'/deposit</a> dan tunggu 1-3 menit,</div>';
		$message .= '<div style="text-align:center;">maka kredit akan otomatis ditambahkan ke UserID Anda,</div>';
		$message .= '<div style="text-align:center;">dan Anda sudah bisa mulai bermain.</div>';
		$message .= '<div style="text-align:center;">&nbsp;</div>';
		$message .= '<div style="text-align:center;">Untuk informasi lebih lengkap,</div>';
		$message .= '<div style="text-align:center;">Silahkan menghubungi kami di:</div>';
		$message .= '<div style="text-align:center;">&nbsp;</div>';
		$message .= '<div style="text-align:center;"><a href="'.absDom.'">'.absDom.'</a></div>';
		$rsx=array();$qx="SELECT * FROM contact_cats WHERE isactive=1";
		callRS($rsx, $qx);
		$message .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
			$message .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-bottom:0;">';
				for ($x=0;$x<count($rsx);$x++) {
					$rsc=array();$qc="SELECT * FROM contacts WHERE isactive=1 AND kdcontact_cat='".$rsx[$x]["kdcontact_cat"]."'";
					callRS($rsc, $qc);
					for ($y=0;$y<count($rsc);$y++) {
						$message .= '<tr><td style="text-align:center;padding:5px;border-bottom:1px purple solid;">'.$rsx[$x]["nama"].'</td>
							<td style="width:3px;border-bottom:1px purple solid;">:</td>
							<td style="padding:5px;border-bottom:1px purple solid;"><strong>'.$rsc[$y]["info"].'</strong></td>
						</tr>';
					}
				}
			$message .= '</table>';
		$message .= '</div>';
		
		$message .= '<div style="text-align:center;">&nbsp;</div>';
		$message .= '<div style="text-align:center;"><img width="200" src="'.absDom.'/img/thanks.png" alt="Terima kasih" /></div>';
	$message .= '</div>';
	if (!mail($to, $subject, $message, $headers)) {
		return false;
		#echo 'error';
	} else {
		return true;
		#echo 'email oke';
	}
}

function web_setup() {
	$rss=array(); $qs="SELECT * FROM s_website";
	callRS($rss, $qs);
	$setting = array();
	for ($i=0;$i<count($rss);$i++) {
		$setting[$rss[$i]["seksi"]] = $rss[$i]["isi"];
	}
	$website_email = $setting["website_email"];
	$website_name = $setting["website_name"];
	$website_url = $setting["website_url"];
	$website_auto_email = $setting["website_auto_email"];
	$website_auto_email_password = $setting["website_auto_email_password"];
	$website_tagline = $setting["website_tagline"];
	$website_gmail = $setting["website_gmail"];
	return array("web_mail"=>$website_email,
		"web_name"=>$website_name,
		"web_url"=>$website_url,
		"auto_mail"=>$website_auto_email,
		"auto_mail_pass"=>$website_auto_email_password,
		"web_tag"=>$website_tagline,
		"web_gmail"=>$website_gmail,
	);
}
function generateEmailContent($type, $parKD=NULL) {
	$web_setup = web_setup();
	$system_email = $web_setup["auto_mail"];
	$system_email_name = $web_setup["web_name"];
	## NEW ASSIGN MEMBERS ###########################################
	if ($type=="assign" || $type=="reassign" || $type=="assignr") {
		$rsm=array();$qm="SELECT a.*, b.username, b.pass FROM members a 
			LEFT JOIN accounts b ON b.kdaccount=a.kdaccount
			WHERE a.kdmember='$parKD'";
		callRS($rsm, $qm);
		## content email pertama
			$ccemail = '';
			$fromEmail = $web_setup["auto_mail"];
			$fromName = $web_setup["web_name"];
			$targetEmail = $rsm[0]["email"];
			$targetName = $rsm[0]["namarek"];
			
			if ($type=="assign" || $type=="assignr") {
				$subjek = 'Your Account has been assigned for ['.$targetName.']';
			}
			if ($type=="reassign") {
				$subjek = 'Your New Account has been re-assigned for ['.$targetName.']';
			}
			
			$rsg=array(); $qg = "SELECT * FROM games WHERE kdgame='".$rsm[0]["kdgame"]."'";
			callRS($rsg, $qg);
			$game_urls = explode(",", $rsg[0]["links"]);
			$gameURL = '';
			for ($g=0;$g<count($game_urls);$g++) {
				$tmp = str_replace("https://", "", $game_urls[$g]);
				$tmp = str_replace("http://", "", $tmp);
				$tmp = trim($tmp);
				$gameURL .= ($gameURL!=""?', ':'').'<a href="//'.$tmp.'">'.$tmp.'</a>';
			}
			
			$isi = '';
			$isi .= '<div style="width:600px;border:1px #999 solid;border-left:4px #999 solid;border-bottom:4px #999 solid;margin:10px;">';
				$isi .= '<div style="width:580px;text-align:center;margin:10px;">';
					$isi .= '<a href="'.absDom.'"><img src="'.absDom.'/img/_logo.png" alt="'.$web_setup["web_url"].'" /></a>';
				$isi .= '</div>';
				$isi .= '<div style="text-align:center;"><br/>SELAMAT, pendaftaran Anda telah berhasil!</div>';
				$isi .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
					$isi .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-right:0;border-bottom:0;">';
						$isi .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">UserName</td>
							<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
							<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">'.$rsm[0]["username"].'</td>
						</tr>';
						$isi .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">Password</td>
							<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
							<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">'.$rsm[0]["pass"].'</td>
						</tr>';
						$isi .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;">Game URL</td>
							<td style="width:3px;border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">:</td>
							<td style="border-right:1px purple solid;border-bottom:1px purple solid;padding:5px;">'.$gameURL.'</td>
						</tr>';
					$isi .= '</table>';
				$isi .= '</div>';
				
				$isi .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
					$isi .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px #888 solid;border-right:0;border-bottom:0;">';
						$isi .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">No. Rekening</td>
							<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
							<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["norek"].'</td>
						</tr>';
						$isi .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">Nama Rekening</td>
							<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
							<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["namarek"].'</td>
						</tr>';
					$isi .= '</table>';
				$isi .= '</div>';
				
				$isi .= '<div style="text-align:center;">Untuk memulai bermain, silahkan lakukan transfer deposit Anda dahulu.</div>';
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;">Setelah Anda men-transfer deposit,</div>';
				$isi .= '<div style="text-align:center;">silahkan isi form deposit di: <a href="'.absDom.'/deposit/">'.absDom.'/deposit</a> dan tunggu 1-3 menit,</div>';
				$isi .= '<div style="text-align:center;">maka kredit akan otomatis ditambahkan ke UserID Anda,</div>';
				$isi .= '<div style="text-align:center;">dan Anda sudah bisa mulai bermain.</div>';
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;">Untuk informasi lebih lengkap,</div>';
				$isi .= '<div style="text-align:center;">Silahkan menghubungi kami di:</div>';
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;"><a href="'.absDom.'">'.absDom.'</a></div>';
				
				$rsx=array();$qx="SELECT * FROM contact_cats WHERE isactive=1";
				callRS($rsx, $qx);
				$isi .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
					$isi .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-bottom:0;">';
						for ($x=0;$x<count($rsx);$x++) {
							$rsc=array();$qc="SELECT * FROM contacts WHERE isactive=1 AND kdcontact_cat='".$rsx[$x]["kdcontact_cat"]."'";
							callRS($rsc, $qc);
							for ($y=0;$y<count($rsc);$y++) {
								$isi .= '<tr><td style="text-align:center;padding:5px;border-bottom:1px purple solid;">'.$rsx[$x]["nama"].'</td>
									<td style="width:3px;border-bottom:1px purple solid;">:</td>
									<td style="padding:5px;border-bottom:1px purple solid;"><strong>'.$rsc[$y]["info"].'</strong></td>
								</tr>';
							}
						}
					$isi .= '</table>';
				$isi .= '</div>';
				
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;">Terima Kasih,</div>';
				$isi .= '<div style="text-align:center;">Management '.$web_setup["web_name"].'</div>';
			$isi .= '</div>';
			
			
			$plain_isi = 'Terima kasih sudah mendaftar.<br/>'."\n";
			$plain_isi .= 'UserID: '.$rsm[0]["username"].'<br/>'."\n";
			$plain_isi .= 'Password: '.$rsm[0]["pass"].'<br/>'."\n";
			$plain_isi .= 'Game Links: '.$gameURL.'<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Nomor Rekening: '.$rsm[0]["norek"].'<br/>'."\n";
			$plain_isi .= 'Nama Rekening: '.$rsm[0]["namarek"].'<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Silahkan Menghubungi Kami:<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			for ($x=0;$x<count($rsx);$x++) {
				$rsc=array();$qc="SELECT * FROM contacts WHERE isactive=1 AND kdcontact_cat='".$rsx[$x]["kdcontact_cat"]."'";
				callRS($rsc, $qc);
				$plain_isi .= ''.$rsx[$x]["nama"].': '.$rsc[$y]["info"].'<br/>'."\n";
			}
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Terima Kasih,<br/>'."\n";
			$plain_isi .= 'Management '.$web_setup["web_name"].'';
		## end content email pertama
		
		## content email kedua
			$ccemail2 = '';
			$fromEmail2 = $rsm[0]["email"];
			$fromName2 = $rsm[0]["namarek"];
			$targetEmail2 = $web_setup["web_mail"];
			$targetName2 = $web_setup["web_name"];
			
			if ($type=="assign" || $type=="assignr") {
				$subjek2 = 'Assignation New Member for ['.$fromName2.']';
			}
			if ($type=="reassign") {
				$subjek2 = 'Re-Assignation Account for Member ['.$fromName2.']';
			}
			$isi2 = '<div style="border:1px #999 solid;padding:10px;"><div>Pesan terkirim:</div><div style="border:1px #999 dashed;">'.$isi.'</div></div>';
			$plain_isi2 = 'Pesan terkirim:<br/>'."\n";
			$plain_isi2 .= $plain_isi;
		## end content email kedua
		
		
		$return_array=array(
			
			"subject"=>$subjek,
			"isi"=>$isi,
			"plain_isi"=>$plain_isi,
			"from"=>$system_email,
			"from_name"=>$system_email_name,
			"target"=>$targetEmail,
			"target_name"=>$targetName,
			"replyto"=>$fromEmail,
			"replyto_name"=>$fromName,
			"cc"=>$ccemail,
			"bcc"=>$bccemail,
			
			"subject2"=>$subjek2,
			"isi2"=>$isi2,
			"plain_isi2"=>$plain_isi2,
			"from2"=>$system_email,
			"from_name2"=>$system_email_name,
			"target2"=>$targetEmail2,
			"target_name2"=>$targetName2,
			"replyto2"=>$fromEmail2,
			"replyto_name2"=>$fromName2,
			"cc2"=>$ccemail2,
			"bcc2"=>$bccemail2,
		);
		return $return_array;
	}
	#### end NEW ASSIGN MEMBERS #####################################
	
	#### begin DEPOSIT / WITHDRAW ###################################
	if ($type=="deposit_clear" || $type=="withdraw_clear") {
		#echo $parKD."\n";
		$rsm=array();
		if ($type=="deposit_clear") {
			$qm = "SELECT a.*, b.email FROM deposits a 
				LEFT JOIN members b ON b.kdmember=a.kdmember
				WHERE a.kddeposit='$parKD'";
		} else if ($type=="withdraw_clear") {
			$qm = "SELECT a.*, b.email FROM withdraws a 
				LEFT JOIN members b ON b.kdmember=a.kdmember
				WHERE a.kdwithdraw='$parKD'";
		}
		callRS($rsm, $qm);
		#echo $qm."\n";
		$jumlah = number_format($rsm[0]["jumlah"]);
		$username = $rsm[0]["username"];
		## content email pertama
			$ccemail = '';
			$fromEmail = $web_setup["auto_mail"];
			$fromName = $web_setup["web_name"];
			$replyToEmail = $web_setup["web_gmail"];
			$replyToName = $web_setup["web_name"];
			$targetEmail = $rsm[0]["email"];
			$targetName = $rsm[0]["namarek"];
			if ($type=="deposit_clear") {
				$subjek = 'Deposit #'.$web_setup["web_name"].' ('.date('d/M/Y H:i:s', time()).') telah berhasil diproses';
			}
			if ($type=="withdraw_clear") {
				$subjek = 'Penarikan #'.$web_setup["web_name"].' ('.date('d/M/Y H:i:s', time()).') telah berhasil diproses';
			}
			$isi = '';
			$isi .= '<div style="width:600px;border:1px #999 solid;border-left:4px #999 solid;border-bottom:4px #999 solid;margin:10px;">';
				$isi .= '<div style="width:580px;text-align:center;margin:10px;">';
					$isi .= '<a href="'.absDom.'"><img src="'.absDom.'/img/_logo.png" alt="'.$web_setup["web_url"].'" /></a>';
				$isi .= '</div>';
				
				if ($type=="deposit_clear") {
					$isi .= '<div style="text-align:center;"><br/>Selamat, Deposit Anda senilai Rp '.$jumlah.',- untuk UserID: '.$username.' telah disetujui. Goodluck! '.$web_setup["web_url"].' '.$web_setup["web_tag"].'</div>';
				}
				if ($type=="withdraw_clear") {
					$isi .= '<div style="text-align:center;"><br/>Selamat, Penarikan Anda senilai Rp '.$jumlah.',- untuk UserID: '.$username.' telah disetujui. Goodluck! '.$web_setup["web_url"].' '.$web_setup["web_tag"].'</div>';
				}
				$isi .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
					$isi .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-right:0;border-bottom:0;">';
						if ($type=="deposit_clear") {
							$isi .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;" colspan="3"><strong>Informasi Depositor</strong></td></tr>';
						}
						if ($type=="withdraw_clear") {
							$isi .= '<tr><td style="border-right:1px purple solid;border-bottom:1px purple solid;text-align:right;padding:5px;" colspan="3"><strong>Informasi Penarik</strong></td></tr>';
						}
						$isi .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">No. Rekening</td>
							<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
							<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["norek"].'</td>
						</tr>';
						$isi .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">Nama Rekening</td>
							<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
							<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$rsm[0]["namarek"].'</td>
						</tr>';
						$isi .= '<tr><td style="border-right:1px #888 solid;border-bottom:1px #888 solid;text-align:right;padding:5px;">Nama Rekening</td>
							<td style="width:3px;border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">:</td>
							<td style="border-right:1px #888 solid;border-bottom:1px #888 solid;padding:5px;">'.$jumlah.'</td>
						</tr>';
						
					$isi .= '</table>';
				$isi .= '</div>';
				if ($type=="deposit") {
					$isi .= '<div style="text-align:center;">Pastikan Anda telah melakukan transfer deposit ke Rekening kami.</div>';
				}
				if ($type=="withdraw") {
					$isi .= '<div style="text-align:center;">Untuk melakukan deposit, Anda dapat melakukan transfer deposit Anda ke Rekening kami.</div>';
				}
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;">Untuk informasi lebih lengkap,</div>';
				$isi .= '<div style="text-align:center;">Silahkan menghubungi kami di:</div>';
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;"><a href="'.absDom.'">'.absDom.'</a></div>';
				
				$rsx=array();$qx="SELECT * FROM contact_cats WHERE isactive=1";
				callRS($rsx, $qx);
				$isi .= '<div style="display:inline-block;width:400px;margin:20px 100px;font-size:120%;">';
					$isi .= '<table border="0" cellpadding="0" cellspacing="0" style="width:100%;border:1px purple solid;border-bottom:0;">';
						for ($x=0;$x<count($rsx);$x++) {
							$rsc=array();$qc="SELECT * FROM contacts WHERE isactive=1 AND kdcontact_cat='".$rsx[$x]["kdcontact_cat"]."'";
							callRS($rsc, $qc);
							for ($y=0;$y<count($rsc);$y++) {
								$isi .= '<tr><td style="text-align:center;padding:5px;border-bottom:1px purple solid;">'.$rsx[$x]["nama"].'</td>
									<td style="width:3px;border-bottom:1px purple solid;">:</td>
									<td style="padding:5px;border-bottom:1px purple solid;"><strong>'.$rsc[$y]["info"].'</strong></td>
								</tr>';
							}
						}
					$isi .= '</table>';
				$isi .= '</div>';
				
				$isi .= '<div style="text-align:center;">&nbsp;</div>';
				$isi .= '<div style="text-align:center;">Terima Kasih,</div>';
				$isi .= '<div style="text-align:center;">Management '.$web_setup["web_name"].'</div>';
			$isi .= '</div>';
			
			if ($type=="deposit_clear") {
				$plain_isi = 'Deposit Anda sudah diproses.<br/>'."\n";
			}
			if ($type=="withdraw_clear") {
				$plain_isi = 'Penarikan Anda sudah diproses.<br/>'."\n";
			}
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Nomor Rekening: '.$rsm[0]["norek"].'<br/>'."\n";
			$plain_isi .= 'Nama Rekening: '.$rsm[0]["namarek"].'<br/>'."\n";
			$plain_isi .= 'Nilai: '.$jumlah.'<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Silahkan Menghubungi Kami:<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			for ($x=0;$x<count($rsx);$x++) {
				$rsc=array();$qc="SELECT * FROM contacts WHERE isactive=1 AND kdcontact_cat='".$rsx[$x]["kdcontact_cat"]."'";
				callRS($rsc, $qc);
				$plain_isi .= ''.$rsx[$x]["nama"].': '.$rsc[$y]["info"].'<br/>'."\n";
			}
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= '<br/>'."\n";
			$plain_isi .= 'Terima Kasih,<br/>'."\n";
			$plain_isi .= 'Management '.$web_setup["web_name"].'';
		## end content email pertama
		
		## content email kedua
			$ccemail2 = '';
			$fromEmail2 = $rsm[0]["email"];
			$fromName2 = $rsm[0]["namarek"];
			$targetEmail2 = $web_setup["web_gmail"];
			$targetName2 = $web_setup["web_name"];
			
			$subjek2 = $subjek.' for Member ['.$username.']';
			
			$isi2 = '<div style="border:1px #999 solid;padding:10px;"><div>Pesan terkirim:</div><div style="border:1px #999 dashed;">'.$isi.'</div></div>';
			$plain_isi2 = 'Pesan terkirim:<br/>'."\n";
			$plain_isi2 .= $plain_isi;
		## end content email kedua
		
		$return_array=array(
			
			"subject"=>$subjek,
			"isi"=>$isi,
			"plain_isi"=>$plain_isi,
			"from"=>$system_email,
			"from_name"=>$system_email_name,
			"target"=>$targetEmail,
			"target_name"=>$targetName,
			"replyto"=>$replyToEmail,
			"replyto_name"=>$replyToName,
			"cc"=>$ccemail,
			"bcc"=>$bccemail,
			
			"subject2"=>$subjek2,
			"isi2"=>$isi2,
			"plain_isi2"=>$plain_isi2,
			"from2"=>$system_email,
			"from_name2"=>$system_email_name,
			"target2"=>$targetEmail2,
			"target_name2"=>$targetName2,
			"replyto2"=>$fromEmail2,
			"replyto_name2"=>$fromName2,
			"cc2"=>$ccemail2,
			"bcc2"=>$bccemail2,
		);
		return $return_array;
	}
	#### end DEPOSIT / WITHDRAW #####################################
}
function newSendMail($type, $parKD=NULL) {
	$web_setup = web_setup();
	$mail_settings = generateEmailContent($type, $parKD);
	#echo $type;
	#echo $parKD;
	#printR($web_setup);
	#printR($mail_settings);
	
	$SMTPDebug = 2;
	$mail = new PHPMailer;
	//$mail->SMTPDebug = $SMTPDebug;
	$mail->isSMTP();
	$mail->Host = 'localhost';
	$mail->SMTPAuth = true;
	$mail->Username = $web_setup["auto_mail"];
	$mail->Password = $web_setup["auto_mail_pass"];
	$mail->SMTPSecure = 'tls';
	$mail->Port = 587;
	$mail->setFrom($mail_settings["from"], $mail_settings["from_name"]);
	$mail->addAddress($mail_settings["target"], $mail_settings["target_name"]);
	$mail->addReplyTo($mail_settings["replyto"], $mail_settings["replyto_name"]);
	if (trim($mail_settings["cc"])!="") {
		$mail->addCC($mail_settings["cc"]);
	}
	if (trim($mail_settings["bcc"])!="") {
		$mail->addBCC($mail_settings["bcc"]);
	}
	$mail->isHTML(true);
	$mail->Subject = $mail_settings["subject"];
	$mail->Body    = $mail_settings["isi"];
	$mail->AltBody = $mail_settings["plain_isi"];
	
	if(!$mail->send()) {
		#echo 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
	} else {
		$terkirim = 1;
		#echo 'Message has been sent';
	}
	
	$mail2 = new PHPMailer;
	//$mail2->SMTPDebug = $SMTPDebug;
	$mail2->isSMTP();
	$mail2->Host = 'localhost';
	$mail2->SMTPAuth = true;
	$mail2->Username = $web_setup["auto_mail"];
	$mail2->Password = $web_setup["auto_mail_pass"];
	$mail2->SMTPSecure = 'tls';
	$mail2->Port = 587;
	$mail2->setFrom($mail_settings["from2"], $mail_settings["from_name2"]);
	$mail2->addAddress($mail_settings["target2"], $mail_settings["target_name2"]);
	$mail2->addReplyTo($mail_settings["replyto2"], $mail_settings["replyto_name2"]);
	if (trim($mail_settings["cc2"])!="") {
		$mail->addCC($mail_settings["cc2"]);
	}
	if (trim($mail_settings["bcc2"])!="") {
		$mail->addBCC($mail_settings["bcc2"]);
	}
	$mail2->isHTML(true);
	$mail2->Subject = $mail_settings["subject2"];
	$mail2->Body    = $mail_settings["isi2"];
	$mail2->AltBody = $mail_settings["plain_isi2"];
	
	if(!$mail2->send()) {
		#echo 'Message 2 could not be sent. Mailer Error: ' . $mail2->ErrorInfo;
	} else {
		$terkirim = 1;
		#echo 'Message 2 has been sent';
	}
}
function getSMSAuth() {
	$rss=array(); $qs="SELECT * FROM s_website";
	callRS($rss, $qs);
	$setting = array();
	for ($i=0;$i<count($rss);$i++) {
		$setting[$rss[$i]["seksi"]] = $rss[$i]["isi"];
	}
	$website_zenziva_userid = $setting["website_zenziva_userid"];
	$website_zenziva_userpass = $setting["website_zenziva_userpass"];
	$userkeyanda = $website_zenziva_userid; // userkey lihat di zenziva
	$passkeyanda = $website_zenziva_userpass; // set passkey di zenziva
	return array("userkeyanda"=>$userkeyanda, "passkeyanda"=>$passkeyanda);
}
function getSMSCredit() {
	$sms_auth = getSMSAuth();
	$userkeyanda = $sms_auth["userkeyanda"]; // userkey lihat di zenziva
	$passkeyanda = $sms_auth["passkeyanda"]; // set passkey di zenziva
	if ($userkeyanda=="" || $passkeyanda=="") {
		return;
	}
	$url = "https://reguler.zenziva.net/apps/smsapibalance.php";
	$url = "https://reguler.zsms.us/apps/smsapibalance.php";
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'userkey='.$userkeyanda.'&passkey='.$passkeyanda.'');
	curl_setopt($curlHandle, CURLOPT_HEADER, 0);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlHandle, CURLOPT_TIMEOUT,30);
	curl_setopt($curlHandle, CURLOPT_POST, 1);
	$results = curl_exec($curlHandle);
	curl_close($curlHandle);
	print_r($results);
	$xml   = simplexml_load_string($results);
	$array = XML2Array($xml);
	return $array;
	$array = array($xml->getName() => $array);
	return $array;
}
function getSMSCreditCP() {
	$sms_auth = getSMSAuth();
	$userkeyanda = $sms_auth["userkeyanda"]; // userkey lihat di zenziva
	$passkeyanda = $sms_auth["passkeyanda"]; // set passkey di zenziva
	if ((!isset($userkeyanda) && $userkeyanda=="") || (!isset($passkeyanda) && $passkeyanda=="")) {
		return false;
	}
	#$url = "https://reguler.zenziva.net/apps/smsapibalance.php";
	$url = "https://reguler.zsms.us/apps/smsapibalance.php";
	$url = "http://cp.charycannia.com/bacasms/index.php";
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'userkey='.$userkeyanda.'&passkey='.$passkeyanda.'');
	curl_setopt($curlHandle, CURLOPT_HEADER, 0);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlHandle, CURLOPT_TIMEOUT,30);
	curl_setopt($curlHandle, CURLOPT_POST, 1);
	$results = curl_exec($curlHandle);
	curl_close($curlHandle);
	return $results;
	print_r($results);
	$xml   = simplexml_load_string($results);
	$array = XML2Array($xml);
	return $array;
	$array = array($xml->getName() => $array);
	return $array;
}
function sendSMS($type, $parKD=NULL) {
	$web_setup = web_setup();
	$system_email = $web_setup["auto_mail"];
	$system_email_name = $web_setup["web_name"];
	$sms_auth = getSMSAuth();
	$userkeyanda = $sms_auth["userkeyanda"]; // userkey lihat di zenziva
	$passkeyanda = $sms_auth["passkeyanda"]; // set passkey di zenziva
	if ((!isset($userkeyanda) && $userkeyanda=="") || (!isset($passkeyanda) && $passkeyanda=="")) {
		return false;
	}
	if ($type=="deposit_clear") {
		$rsm=array();$qm="SELECT a.*, b.telp FROM deposits a LEFT JOIN members b ON b.kdmember = a.kdmember WHERE isclear=1 AND kddeposit = '$parKD'";
	} else if ($type=="withdraw_clear") {
		$rsm=array();$qm="SELECT a.*, b.telp FROM withdraws a LEFT JOIN members b ON b.kdmember = a.kdmember WHERE isclear=1 AND kdwithdraw = '$parKD'";
	} else if ($type=="assign" || $type=="reassign" || $type=="assignr") {
		$rsm=array();$qm="SELECT a.*, b.username, b.pass FROM members a 
			LEFT JOIN accounts b ON b.kdaccount=a.kdaccount
			WHERE a.kdmember='$parKD'";
	}
	callRS($rsm, $qm);
	#echo $qm."\n";
	$username = $rsm[0]["username"];
	$defPassword = $rsm[0]["pass"];
	$nohptujuan = $rsm[0]["telp"];
	$jumlah = $rsm[0]["jumlah"];
	$jumlah2 = number_format($jumlah);
	$norek = $rsm[0]["norek"];
	$namarek = $rsm[0]["namarek"];
	$rsg=array(); $qg = "SELECT * FROM games WHERE kdgame='".$rsm[0]["kdgame"]."'";
	callRS($rsg, $qg);
	$game_urls = explode(",", $rsg[0]["links"]);
	$breakfor = 0;
	$gurl = '';
	for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
		$tmp = str_replace("https://", "", $game_urls[$g]);
		$tmp = str_replace("http://", "", $tmp);
		$tmp = trim($tmp);
		if ($tmp!="") { $gurl = $tmp; $breakfor = 1; }
	}
	#echo $nohptujuan."--- nohptujuan\n";
	
	if ($type=="assign" || $type=="reassign" || $type=="assignr") {
		$isipesan = "UserID : ".$username." . Password : ".$defPassword." . Link : ".$gurl." . Selamat bergabung bersama ".$web_setup["web_name"]." ".$web_setup["web_tag"]."  :)";
	}
	if ($type=="deposit_clear") {
		$isipesan = "Deposit Anda Rp ".$jumlah2." u/ USERNAME: ".$username." telah BERHASIL. Thanks. ".$web_setup["web_url"]." ".$web_setup["web_tag"]." :)";
		$isipesan = substr($isipesan, 0, 150);
	}
	if ($type=="withdraw_clear") {
		$isipesan = "Withdraw Anda ke Rek#".$norek." a/n ".$namarek." Rp ".$jumlah2." telah BERHASIL. Thanks. ".$web_setup["web_url"]." ".$web_setup["web_tag"]." :)";
		$isipesan = substr($isipesan, 0, 150);
	}
	#echo $isipesan."--- isipesan\n";
	#$url = "http://fastwash.zenziva.com/apps/smsapi.php"; #banned
	#$url = "https://reguler.zenziva.net/apps/smsapi.php";
	$url = "https://reguler.zsms.us/apps/smsapi.php";
	$url_data = 'userkey='.$userkeyanda.'&passkey='.$passkeyanda.'&nohp='.$nohptujuan.'&pesan='.urlencode($isipesan).'';
	#echo $url.'?'.$url_data."\n";
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $url_data);
	curl_setopt($curlHandle, CURLOPT_HEADER, 0);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlHandle, CURLOPT_TIMEOUT,30);
	curl_setopt($curlHandle, CURLOPT_POST, 1);
	$results = curl_exec($curlHandle);
	curl_close($curlHandle);
	
	/* 
	$xml   = simplexml_load_string($results);
	$array = XML2Array($xml);
	$array = array($xml->getName() => $array);
	 */
	#printR($array);
}
function sendSMSCP($type, $parKD=NULL) {
	$web_setup = web_setup();
	$system_email = $web_setup["auto_mail"];
	$system_email_name = $web_setup["web_name"];
	$sms_auth = getSMSAuth();
	$userkeyanda = $sms_auth["userkeyanda"]; // userkey lihat di zenziva
	$passkeyanda = $sms_auth["passkeyanda"]; // set passkey di zenziva
	
	if ($type=="deposit_clear") {
		$rsm=array();$qm="SELECT a.*, b.telp FROM deposits a LEFT JOIN members b ON b.kdmember = a.kdmember WHERE isclear=1 AND kddeposit = '$parKD'";
	} else if ($type=="withdraw_clear") {
		$rsm=array();$qm="SELECT a.*, b.telp FROM withdraws a LEFT JOIN members b ON b.kdmember = a.kdmember WHERE isclear=1 AND kdwithdraw = '$parKD'";
	} else if ($type=="assign" || $type=="reassign" || $type=="assignr") {
		$rsm=array();$qm="SELECT a.*, b.username, b.pass FROM members a 
			LEFT JOIN accounts b ON b.kdaccount=a.kdaccount
			WHERE a.kdmember='$parKD'";
	}
	callRS($rsm, $qm);
	#echo $qm."\n";
	$username = $rsm[0]["username"];
	$defPassword = $rsm[0]["pass"];
	$nohptujuan = $rsm[0]["telp"];
	$jumlah = $rsm[0]["jumlah"];
	$jumlah2 = number_format($jumlah);
	$norek = $rsm[0]["norek"];
	$namarek = $rsm[0]["namarek"];
	$rsg=array(); $qg = "SELECT * FROM games WHERE kdgame='".$rsm[0]["kdgame"]."'";
	callRS($rsg, $qg);
	$game_urls = explode(",", $rsg[0]["links"]);
	$breakfor = 0;
	$gurl = '';
	for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
		$tmp = str_replace("https://", "", $game_urls[$g]);
		$tmp = str_replace("http://", "", $tmp);
		$tmp = str_replace("www.", "", $tmp);
		$tmp = trim($tmp);
		if ($tmp!="") { $gurl = $tmp; $breakfor = 1; }
	}
	#echo $nohptujuan."--- nohptujuan\n";
	
	if ($type=="assign" || $type=="reassign" || $type=="assignr") {
		#$isipesan = "Penarikan saldo ke Rek#".$norek." a/n ".$namarek." sebesar Rp ".$jumlah2." telah BERHASIL. Terima kasih. www.bandarsport.com Easy deposit and fast payout :)";
		$isipesan = "UserID : ".$username." . Password : ".$defPassword." . Link : ".$gurl." . Selamat bergabung bersama ".str_replace("www.", "", $web_setup["web_name"])." ".$web_setup["web_tag"]."  :)";
	}
	if ($type=="deposit_clear") {
		#$isipesan = "AGENVIP88.COM - AMAN DAN TERPERCAYA. Bonus 50% member baru, Bonus cashback 5% bola dan number game, Bonus komisi 1% livecasino, DP/WD Tdk smpai 5Menit!";
		$isipesan = "Deposit Anda Rp ".$jumlah2." u/ USERNAME: ".$username." telah BERHASIL. Thanks. ".str_replace("www.", "", $web_setup["web_url"])." ".$web_setup["web_tag"]." :)";
		$isipesan = substr($isipesan, 0, 150);
	}
	if ($type=="withdraw_clear") {
		#$isipesan = "Penarikan saldo ke Rek#".$norek." a/n ".$namarek." sebesar Rp ".$jumlah2." telah BERHASIL. Terima kasih. www.bandarsport.com Easy deposit and fast payout :)";
		$isipesan = "Withdraw Anda ke Rek#".$norek." a/n ".$namarek." Rp ".$jumlah2." telah BERHASIL. Thanks. ".str_replace("www.", "", $web_setup["web_url"])." ".$web_setup["web_tag"]." :)";
		$isipesan = substr($isipesan, 0, 150);
	}
	#echo $isipesan."--- isipesan\n";
	#$url = "http://fastwash.zenziva.com/apps/smsapi.php"; #banned
	#$url = "https://reguler.zenziva.net/apps/smsapi.php";
	$url = "https://reguler.zsms.us/apps/smsapi.php";
	$url = "http://cp.charycannia.com/bacasms/index.php";
	$url_data = 'kirim=1&userkey='.$userkeyanda.'&passkey='.$passkeyanda.'&nohp='.$nohptujuan.'&pesan='.urlencode($isipesan).'';
	#echo $url.'?'.$url_data."\n";
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $url_data);
	curl_setopt($curlHandle, CURLOPT_HEADER, 0);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curlHandle, CURLOPT_TIMEOUT,30);
	curl_setopt($curlHandle, CURLOPT_POST, 1);
	$results = curl_exec($curlHandle);
	curl_close($curlHandle);
	
	/* 
	$xml   = simplexml_load_string($results);
	$array = XML2Array($xml);
	$array = array($xml->getName() => $array);
	 */
	#printR($array);
}
?>