<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
$timezone = "Asia/Jakarta";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
if (!function_exists("saltEncoding")) {
	function saltEncoding($toencode, $times=8986) {
		#enchsetenev
		$salt='s+(_a*';
		for($zo=0; $zo<$times; $zo=$zo+1) {
			$toencode=hash('sha512', $salt.$toencode);
			$toencode=md5($toencode.$salt);
		}
		return $toencode;
	}
}
function cleanQuery($string) {
	$setup=cvdb();
	$con=mysql_connect($setup["dbs"], $setup["dbu"], $setup["dbp"]);
	if(! $con)
		showMySQLError("Function: cleanQuery", $string);
	if(get_magic_quotes_gpc())
		$string=stripslashes($string);
	$string=(phpversion()>="4.3.0")?mysql_real_escape_string($string):mysql_escape_string($string);
	return $string;
	if(! mysql_close($con))
		showMySQLError("Function: cleanQuery", $string);
}

function cekpost($pstr, $prep) {
	$returnValue=($pstr!="" && isset($pstr))?$pstr:$prep;
	return $returnValue;
}
function numberToRoman($num) {
	$n=intval($num);
	$result='';
	$lookup=array("M" => 1000, "CM" => 900, "D" => 500, "CD" => 400, "C" => 100, "XC" => 90, "L" => 50, "XL" => 40, "X" => 10, "IX" => 9, "V" => 5, "IV" => 4, "I" => 1);
	foreach($lookup as $roman => $value) {
		$matches=intval($n / $value);
		$result .= str_repeat($roman, $matches);
		$n=$n % $value;
	}
	return $result;
}
function cout($string, $specs=array()) {
	$specs = array('nl'=>'n');
	echo $string;
	if (isset($specs)) {
		if (isset($specs["nl"])) {
			if (strtolower($specs["nl"])=="b") echo "<br />";
			if (strtolower($specs["nl"])=="n") echo "\n";
		}
	}
}
function dateFormat($time=NULL, $format=NULL) {
	if (!isset($time)) $time = time();
	if (!isset($format)) $foramt = 0;
	$s = "";
	$year = date('o', $time);
	$week = date('W', $time);
	switch ($format) {
		case 0: { $s='l, jS M Y'; break; }
	}
	return date($s, $time);
}

function cleanURL($string) {
	$url=str_replace("'", '', $string);
	$url=str_replace('%20', ' ', $url);
	$url=preg_replace('~[^\\pL0-9_]+~u', '-', $url); // substitutes anything but letters, numbers and '_' with separator
	$url=trim($url, "-");
	$url=iconv("utf-8", "us-ascii//TRANSLIT", $url);  // you may opt for your own custom character map for encoding.
	$url=strtolower($url);
	$url=preg_replace('~[^-a-z0-9_]+~', '', $url); // keep only letters, numbers, '_' and separator
	return $url;
}
function adminSubMenu($parUrl, $parType, $parLabel) {
	$spanClass = "main";
	$hrefLabel = "Main";
	switch($parType) {
		case "add": { $spanClass = "add"; break; }
		case "edit": { $spanClass = "edit"; break; }
		case "delete": { $spanClass = "delete"; break; }
		case "image": { $spanClass = "image"; break; }
		case "back": { $spanClass = "back"; break; }
	}
	return '<a class="'.$spanClass.'" href="'.$parUrl.'"><span class="'.$spanClass.'"></span> '.$parLabel.'</a>';
}
function textSeparator($par=0) {
	if ($par==0) {
		return '&nbsp;&nbsp;';
	} else {
		return '&nbsp;|&nbsp;';
	}
}
function tdWidth($width=180, $useStyle=0) {
	if ($useStyle==0) {
		return ' width:'.$width.'px; ';
	} else {
		return ' style="width:'.$width.'px;"';
	}
}
function tRowOddEven(&$count) {
	$count = $count + 1;
	if ($count % 2 == 0) {
		return 'reve';
	} else {
		return 'rodd';
	}
}

function genCustomerName($customerName, $firstName, $lastName) {
	if ($customerName!="") {
		$namacustomer = $customerName;
	} else {
		$namacustomer = '';
		if ($firstName!="" || $lastName!="") {
			$namacustomer .= ($namacustomer!=""?' ':'').($firstName!=""?$firstName:'');
			$namacustomer .= ($namacustomer!=""?' ':'').($lastName!=""?$lastName:'');
		} else {
			$namacustomer = '<em>No Name</em>';
		}
	}
	return trim($namacustomer);
}
function checkDateTime($data, $format) {
	if (date('Y-m-d H:i:s', strtotime($data)) == $data) {
		return true;
	} else {
		return false;
	}
}
function genTransactionNo($type, $time=null) {
	switch ($type) {
		case "pb": { $kode = "PB"; $table="purchases"; $field="nopb"; $fieldtgl="tglpb"; break; }
		case "pj": { $kode = "PJ"; $table="sells"; $field="nopj"; $fieldtgl="tglpj"; break; }
		default: { $kode = "AUTO"; }
	}
	$year = date('Y');
	$month = date('m');
	if (isset($time)) {
		$detime = date('Y-m-d H:i:s', strtotime($time));
		if (checkDateTime($detime, 'Y-m-d H:i:s')) {
			$year = date('Y', strtotime($time));
			$month = date('m', strtotime($time));
		}
	}
	$rsn=array();$qn="SELECT $field FROM $table WHERE MONTH(FROM_UNIXTIME($fieldtgl))=".$month." AND YEAR(FROM_UNIXTIME($fieldtgl))=".$year." ORDER BY $field DESC, $fieldtgl DESC LIMIT 0,1";
	
	callRS($rsn, $qn);
	if (count($rsn)!=0) {
		$test = explode("/", $rsn[0][$field]);
		$newTmpNo = intval($test[count($test)-1])+1;
	} else {
		$newTmpNo = 1;
	}
	$tmpNo = "";
	for ($n=5;$n>strlen($newTmpNo);$n--) {
		$tmpNo .= "0";
	}
	$tmpNo .= $newTmpNo;
	$theNumber = $kode."/".$year."/".$month."/".$tmpNo;
	return $theNumber;
	
}
function browseContents($id, $page, $defaultID="", $defaultValue="") {
	switch ($page) {
		case "purchases": {
			$ajaxURL="/_ajax/purchases.php";
			if ($id=="item_id") {
				$deQS="a=callitem&isactive=1";
			}
			if ($id=="customer_id") {
				$deQS="a=callcustomer&isactive=1";
			}
			
			break;
		}
		case "sells": {
			$ajaxURL="/_ajax/sells.php";
			if ($id=="item_id") {
				$deQS="a=callitem&isactive=1";
			}
			if ($id=="customer_id") {
				$deQS="a=callcustomer&isactive=1";
			}
			
			break;
		}
		case "items": {
			$ajaxURL="/_ajax/items.php";
			if ($id=="category_id") {
				$deQS="a=callcategory&isactive=1";
			}
			
			break;
		}
		case "customerprice": {
			$ajaxURL="/_ajax/customerprice.php";
			if ($id=="customer_id") {
				$deQS="a=callcustomer&isactive=1";
			}
			
			break;
		}
		default: { $ajaxURL=""; }
	}
	$str = '';
	if ($ajaxURL!="") {
		$str.= '<div style="float:left;">';
		$str.= '<input type="hidden" name="i'.$id.'" id="i'.$id.'" value="'.$defaultID.'" />';
		$str.= '<input type="text" name="v'.$id.'" id="v'.$id.'" value="'.$defaultValue.'" />';
		$str.= '</div>';
		$str.= '<div style="float:left;">';
		$str.= '<a class="browse" id="browse'.$id.'" href="#" onclick="browseContents(\''.$id.'\', \''.$page.'\');return false;"><img src="/img/book_icon.png" alt="Browse" /></a>';
		$str.= '<a class="clear" id="clear'.$id.'" href="#" onclick="clearContents(\''.$id.'\', \''.$page.'\');return false;"><img src="/img/edit_clear.png" alt="Clear" /></a>';
		$str.= '</div>';
		$str.= '
		<script type="text/javascript">
			$("#v'.$id.'").autocomplete({
				source: "'.$ajaxURL.'?'.$deQS.'",
				select: function(event, ui){
					$("#i'.$id.'").val(ui.item.id);
					$("#v'.$id.'").val(ui.item.value);
				}
			});
		</script>
		';
	}
	return $str;
}
function temporaryTransactionNumber($parType) {
	switch ($parType) {
		case "nopb": { $ajaxURL="/_ajax/purchases.php"; $deA="gettmpnopb"; $elemID="nopb"; $elemCont="exnopb"; break; }
		case "nopj": { $ajaxURL="/_ajax/sells.php"; $deA="gettmpnopj"; $elemID="nopj"; $elemCont="exnopj"; break; }
		default: { $ajaxURL=""; }
	}
	if ($ajaxURL!="") {
		$str = '';
		$str.= '<span id="'.$elemCont.'">Automatic</span>';
		$str.= '
		<script type="text/javascript">
			$.ajax({
				type: "GET",
				url: "'.$ajaxURL.'",
				data: "a='.$deA.'&flag=" + $("#'.$elemID.'").val(),
				success: function(resp) {
					$("#'.$elemCont.'").html(resp);
				}
			});
		</script>
		';
		return $str;
	}
		
}
function ShowFileExtension($filepath) {
	preg_match('/[^?]*/', $filepath, $matches);
	$string=$matches[0];
	$pattern=preg_split('/\./', $string, - 1, PREG_SPLIT_OFFSET_CAPTURE);
	# check if there is any extension
	if(count($pattern)==1) {
		return 'No File Extension Present';
		exit();
	}
	if(count($pattern) > 1) {
		$filenamepart=$pattern[count($pattern) - 1][0];
		preg_match('/[^?]*/', $filenamepart, $matches);
		return $matches[0];
	}
	return false;
}
function createDirectory2($sub_dir, $dir_name, $permisi=0777) {
	$thisdir=getcwd()."/";
	$tmp_dir = "";
	if(file_exists($sub_dir."/".$dir_name)) {
		$tmp_dir = $sub_dir."/".$dir_name;
		#return $sub_dir."/".$dir_name;
	} else {
		if(! mkdir($sub_dir."/".$dir_name, $permisi)) {
			die('Failed to create folders...');
		} else {
			$tmp_dir = $sub_dir."/".$dir_name;
			#return $sub_dir."/".$dir_name;
		}
	}
	if ($tmp_dir[strlen($tmp_dir)-1]!="/") $tmp_dir=$tmp_dir."/";
	return $tmp_dir;
}
function deleteDirectory($dir) {
	if(! file_exists($dir))
		return true;
	if(! is_dir($dir) || is_link($dir))
		return unlink($dir);
	foreach(scandir($dir) as $item) {
		if($item=='.' || $item=='..')
			continue;
		if(! deleteDirectory($dir."/".$item)) {
			chmod($dir."/".$item, 0777);
			if(! deleteDirectory($dir."/".$item))
				return false;
		}
		;
	}
	return rmdir($dir);
}
function smart_resize_image($file, $width=0, $height=0, $proportional=false, $output='file', $delete_original=true, $use_linux_commands=false, $posx=0, $posy=0) {
	if($height<=0 && $width<=0)
		return false;
	$info=getimagesize($file);
	$image='';
	$final_width=0;
	$final_height=0;
	list($width_old, $height_old)=$info;
	if($proportional) {
		if($width==0)
			$factor=$height / $height_old;
		elseif($height==0)
			$factor=$width / $width_old;
		else
			$factor=min($width / $width_old, $height / $height_old);
		
		$final_width=round($width_old * $factor);
		$final_height=round($height_old * $factor);
	} else {
		$final_width=($width<=0)?$width_old:$width;
		$final_height=($height<=0)?$height_old:$height;
	}
	
	switch($info[2]) {
		case IMAGETYPE_GIF:
			$image=imagecreatefromgif($file);
			break;
		case IMAGETYPE_JPEG:
			$image=imagecreatefromjpeg($file);
			break;
		case IMAGETYPE_PNG:
			$image=imagecreatefrompng($file);
			break;
		default:
			return false;
	}
	
	$image_resized=imagecreatetruecolor($final_width, $final_height);
	if(($info[2]==IMAGETYPE_GIF) ||($info[2]==IMAGETYPE_PNG)) {
		$trnprt_indx=imagecolortransparent($image);
		if($trnprt_indx>=0) {
			$trnprt_color=imagecolorsforindex($image, $trnprt_indx);
			$trnprt_indx=imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
			imagefill($image_resized, 0, 0, $trnprt_indx);
			imagecolortransparent($image_resized, $trnprt_indx);
		} elseif($info[2]==IMAGETYPE_PNG) {
			imagealphablending($image_resized, false);
			$color=imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
			imagefill($image_resized, 0, 0, $color);
			imagesavealpha($image_resized, true);
		}
	}
	
	imagecopyresampled($image_resized, $image, 0, 0, $posx, $posy, $final_width, $final_height, $width_old, $height_old);
	//imagecopyresampled($dst_image, $src_image, $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h)
	if($delete_original) {
		if($use_linux_commands)
			exec('rm '.$file);
		else
			@unlink($file);
	}
	
	switch(strtolower($output)) {
		case 'browser':
			$mime=image_type_to_mime_type($info[2]);
			header("Content-type: $mime");
			$output=NULL;
			break;
		case 'file':
			$output=$file;
			break;
		case 'return':
			return $image_resized;
			break;
		default:
			break;
	}
	
	switch($info[2]) {
		case IMAGETYPE_GIF:
			imagegif($image_resized, $output);
			break;
		case IMAGETYPE_JPEG:
			imagejpeg($image_resized, $output, 100);
			break;
		case IMAGETYPE_PNG:
			imagepng($image_resized, $output);
			break;
		default:
			return false;
	}
	return true;
}
function smartCopy($source, $dest, $folderPermission=0755, $filePermission=0644) {
	$result=false;
	if(is_file($source)) {
		if(is_dir($dest)) {
			if($dest[strlen($dest) - 1]!='/')
				$__dest=$dest."/";
			$__dest .= basename($source);
		} else {
			$__dest=$dest;
		}
		$result=copy($source, $__dest);
		chmod($__dest, $filePermission);
	} elseif(is_dir($source)) {
		if(! is_dir($dest)) {
			@mkdir($dest, $folderPermission);
			chmod($dest, $folderPermission);
		}
		if($source[strlen($source) - 1]!='/')
			$source=$source."/";
		if($dest[strlen($dest) - 1]!='/')
			$dest=$dest."/";
		
		$result=true;
		$dirHandle=opendir($source);
		while(($file=readdir($dirHandle))==true) {
			if($file!="." && $file!="..")
				$result=smartCopy($source.$file, $dest.$file, $folderPermission, $filePermission);
		}
		closedir($dirHandle);
	} else {
		$result=false;
	}
	return $result;
}
function convertSecToStr($secs){
	$output = '';
	if($secs >= 86400) {
		$days = floor($secs/86400);
		$secs = $secs%86400;
		$output = $days.' day';
		if($days != 1) $output .= 's';
		if($secs > 0) $output .= ', ';
	}
	if($secs>=3600){
		$hours = floor($secs/3600);
		$secs = $secs%3600;
		$output .= $hours.' hr';
		if($hours != 1) $output .= 's';
		if($secs > 0) $output .= ', ';
	}
	if($secs>=60){
		$minutes = floor($secs/60);
		$secs = $secs%60;
		$output .= $minutes.' min';
		if($minutes != 1) $output .= 's';
		if($secs > 0) $output .= ', ';
	}
	$output .= $secs.' sec';
	if($secs != 1) $output .= 's'; 
	return $output;
}
function redirect($to,$code=301)
{	$location = null;
	$sn = $_SERVER['SCRIPT_NAME'];
	$cp = dirname($sn);
	if (substr($to,0,4)=='http') $location = $to; // Absolute URL
	else
	{	$schema = $_SERVER['SERVER_PORT']=='443'?'https':'http';
		$host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];
		if (substr($to,0,1)=='/') $location = "$schema://$host$to";
		elseif (substr($to,0,1)=='.') // Relative Path
		{	$location = "$schema://$host/";
			$pu = parse_url($to);
			$cd = dirname($_SERVER['SCRIPT_FILENAME']).'/';
			$np = realpath($cd.$pu['path']);
			$np = str_replace($_SERVER['DOCUMENT_ROOT'],'',$np);
			$location.= $np;
			if ((isset($pu['query'])) && (strlen($pu['query'])>0)) $location.= '?'.$pu['query'];
		}
	}
	$hs = headers_sent();
	if ($hs==false)
	{	if ($code==301) header("301 Moved Permanently HTTP/1.1"); // Convert to GET
		elseif ($code==302) header("302 Found HTTP/1.1"); // Conform re-POST
		elseif ($code==303) header("303 See Other HTTP/1.1"); // dont cache, always use GET
		elseif ($code==304) header("304 Not Modified HTTP/1.1"); // use cache
		elseif ($code==305) header("305 Use Proxy HTTP/1.1");
		elseif ($code==306) header("306 Not Used HTTP/1.1");
		elseif ($code==307) header("307 Temporary Redirect HTTP/1.1");
		else trigger_error("Unhandled redirect() HTTP Code: $code",E_USER_ERROR);
		header("Location: $location");
		header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
	}
	elseif (($hs==true) || ($code==302) || ($code==303))
	{	// todo: draw some javascript to redirect
		$cover_div_style = 'background-color: #ccc; height: 100%; left: 0px; position: absolute; top: 0px; width: 100%;'; 
		echo "<div style='$cover_div_style'>\n";
		$link_div_style = 'background-color: #fff; border: 2px solid #f00; left: 0px; margin: 5px; padding: 3px; ';
		$link_div_style.= 'position: absolute; text-align: center; top: 0px; width: 95%; z-index: 99;';
		echo "<div style='$link_div_style'>\n";
		echo "<p>Please See: <a href='$to'>".htmlspecialchars($location)."</a></p>\n";
		echo "</div>\n</div>\n";
	}
	exit(0);
	// Do stuff here before sending headers
	//redirect('/')
	//redirect("/my/page")
	//redirect("http://www.foo.bar/page.htm",303)
	//redirect("./index.php",307)

}
function checkAuth($pid, $ids) {
	return true;
	if (in_array($pid, $ids)) {
		return true;
	} else {
		return false;
		#return true;
	}
}
function viewNoAuth() {
	cout('<div style="color:red;"><em>No authorization to access this page!</em></div>');
}
function check_email_address($email) {
	// First, we check that there's one @ symbol, 
	// and that the lengths are right. 
	if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
		// Email invalid because wrong number of characters 
		// in one section or wrong number of @ symbols.
		return false;
	}
	// Split it into sections to make life easier
	$email_array = explode("@", $email);
	$local_array = explode(".", $email_array[0]);
	for ($i = 0; $i < sizeof($local_array); $i++) {
		if
		(!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
		'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
		$local_array[$i])) {
			return false;
		}
	}
	// Check if domain is IP. If not, 
	// it should be valid domain name
	if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
		$domain_array = explode(".", $email_array[1]);
		if (sizeof($domain_array) < 2) {
			return false; // Not enough parts to domain
		}
		for ($i = 0; $i < sizeof($domain_array); $i++) {
			if
			(!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
			([A-Za-z0-9]+))$",
			$domain_array[$i])) {
				return false;
			}
		}
	}
	return true;
}

function printR($parArr) {
	echo'<pre>';print_r($parArr);echo'</pre>';
}
function updateUserActivities($parKet) {
	if (isset($_SESSION["user"])) {
		$session_id = $_SESSION["user"]["session_id"];
		$_SESSION["user"]["last_click"] = time();
		$rscua = array(); $qcua = "SELECT * FROM _user_activities WHERE session_id='$session_id' AND kduser='".$_SESSION["user"]["kduser"]."'";
		callRSL($rscua, $qcua);
		#if (count($rscua)!=0) {
		#	$qua = "UPDATE _user_activities SET ket='$parKet', last_click='".time()."' WHERE session_id='$session_id' AND kduser = '".$_SESSION["user"]["kduser"]."'";
		#	execRS($qua);
		#} else {
			$kdcua = getIDL("_user_activities", "kd");
			$kduser = $_SESSION["user"]["kduser"];
			$username = $_SESSION["user"]["username"];
			$inisial = $_SESSION["user"]["inisial"];
			$login_time = $_SESSION["user"]["login_time"];
			$last_click = $_SESSION["user"]["last_click"];
			$qua = "INSERT INTO _user_activities (kd, kduser, username, inisial, login_time, last_click, session_id, ket) 
				VALUES ('$kdcua', '$kduser', '$username', '$inisial', '$login_time', '$last_click', '$session_id', '$parKet')";
			execRSL($qua);
		#}
	}
}
function XML2Array(SimpleXMLElement $parent) {
	$array = array();
	foreach ($parent as $name => $element) {
		($node = & $array[$name])
			&& (1 === count($node) ? $node = array($node) : 1)
			&& $node = & $node[];
		$node = $element->count() ? XML2Array($element) : trim($element);
	}
	return $array;
}
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 doSMS($tujuan, $tipe, $kdmember=NULL, $kdakun=NULL) {
	// Script http API SMS Reguler Zenziva
	#$userkeyanda = 'legrac'; // userkey lihat di zenziva
	#$passkeyanda = 'abcd@1234'; // set passkey di zenziva
	$userkeyanda = 'izygh3'; // userkey lihat di zenziva
	$passkeyanda = 'a9ssd9'; // set passkey di zenziva
	$executeSMS = 0;
	$nohptujuan = $tujuan;
	if ($tipe == "assign" && isset($kdmember) && isset($kdakun)) {
		$rsc=array(); $qc="SELECT * FROM members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$username = $rsc[0]["username"];
		$tlp = $rsc[0]["tlp"];
		$email = $rsc[0]["email"];
		
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$breakfor = 0;
		for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
			if (trim($game_urls[$g])!="") {
				$gurl = trim($game_urls[0]);
				$breakfor = 1;
			}
		}
		if ($breakfor==0) {
			$gurl = $rsp[0]["link"];
		}
		#$gurl = (count($game_urls)>0)?trim($game_urls[0]):$rsp[0]["link"];
		
		#$firstString = "Abc66";
		#$lastDigit = substr(trim($username), -1);
		#$oddEvenIndicator = (is_numeric($lastDigit) && intval($lastDigit)%2==0)?"n":"j";
		#$defPassword = "$firstString@".(intval($lastDigit)==0?'n':$lastDigit)."$oddEvenIndicator";
		
		$rsa=array(); $qa="SELECT * FROM akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		#$isipesan = "Selamat bergabung bersama Alphabet66. (userID:".$username.")(Password:".$defPassword.")(Link:".$gurl.") Silahkan Dicoba Bos :D";
		$isipesan = "UserID : ".$username." . Password : ".$defPassword." . Link : ".$gurl." . Selamat bergabung bersama BandarSport dengan Sistem Keamanan Transaksi Terbaik. :)";
		$executeSMS = 1;
	}
	if ($tipe == "assign2" && isset($kdmember) && isset($kdakun)) {
		$rsc=array(); $qc="SELECT * FROM members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		
		$kdproduct = $rsc[0]["kdproduct"];
		$username = $rsc[0]["username"];
		$tlp = $rsc[0]["tlp"];
		$email = $rsc[0]["email"];
		$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"),
		);
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$breakfor = 0;
		for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
			if (trim($game_urls[$g])!="") {
				$gurl = trim($game_urls[0]);
				$breakfor = 1;
			}
		}
		if ($breakfor==0) {
			$gurl = $rsp[0]["link"];
		}
		#$isipesan = "Selamat bergabung bersama Alphabet66. (userID:".$username.")(Password:".$defPassword.")(Link:".$gurl.") Silahkan Dicoba Bos :D";
		#$isipesan = "Silahkan transfer deposit Anda ke rekening: ".$gbank[$rsc[0]["kdbank"]]["bank"].":".$gbank[$rsc[0]["kdbank"]]["norek"]." a/n ".$gbank[$rsc[0]["kdbank"]]["namarek"].".Silahkan abaikan SMS ini jika sudah transfer";
		$isipesan = "Silahkan transfer deposit Anda ke rekening: ".$gbank[$rsc[0]["kdbank"]]["bank"].":".$gbank[$rsc[0]["kdbank"]]["norek"]." a/n ".$gbank[$rsc[0]["kdbank"]]["namarek"].". Lalu silahkan isi form deposit di web kami dan Anda dapat segera mulai bermain. www.bandarsport.com";
		$executeSMS = 1;
	}
	if ($tipe == "assignnew" && isset($kdmember) && isset($kdakun)) {
		$rsc=array(); $qc="SELECT * FROM members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$username = $rsc[0]["username"];
		$tlp = $rsc[0]["tlp"];
		$email = $rsc[0]["email"];
		
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$gurl = (count($game_urls)>0)?trim($game_urls[0]):$rsp[0]["link"];
		
		$firstString = "Abc66";
		$lastDigit = substr(trim($username), -1);
		$oddEvenIndicator = (is_numeric($lastDigit) && intval($lastDigit)%2==0)?"n":"j";
		$defPassword = "$firstString@".(intval($lastDigit)==0?'n':$lastDigit)."$oddEvenIndicator";
		
		$rsa=array(); $qa="SELECT * FROM akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		$isipesan = "Selamat bergabung bersama BandarSport. (userID:".$username.")(Password:".$defPassword.")(Link:".$gurl.") Silahkan Dicoba Bos :D";
		$isipesan = "Anda telah diberikan UserID baru dari BandarSport. (userID:".$username.")(Password:".$defPassword.")(Link:".$gurl.") Silahkan Dicoba Bos :D";
		$executeSMS = 1;
		/* begin sementara */
			#$executeSMS = 0;
			#return array( "response"=>array( "message"=>array( "to"=>$nohptujuan, "status"=>"", "text"=>"success2", "balance"=>"-", "pesan"=>$isipesan ) ) );
		/* end sementara */
	}
	if ($tipe == "assign-turney" && isset($kdmember) && isset($kdakun)) {
		$rsc=array(); $qc="SELECT * FROM tourney_members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$username = $rsc[0]["username"];
		$tlp = $rsc[0]["tlp"];
		$email = $rsc[0]["email"];
		$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"),
		);
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$breakfor = 0;
		for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
			if (trim($game_urls[$g])!="") {
				$gurl = trim($game_urls[0]);
				$breakfor = 1;
			}
		}
		if ($breakfor==0) {
			$gurl = $rsp[0]["link"];
		}
		#$gurl = (count($game_urls)>0)?trim($game_urls[0]):$rsp[0]["link"];
		
		$rsa=array(); $qa="SELECT * FROM tourney_akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		$isipesan = "Selamat! Anda baru saja bergabung di Tournament BandarSport. (userID:".$username.")(Password:".$defPassword.")(Link:".$gurl.") Silahkan dicoba ^.^";
		$executeSMS = 1;
	}
	
	if ($tipe == "assign-turney2" && isset($kdmember) && isset($kdakun)) {
		$rsc=array(); $qc="SELECT * FROM tourney_members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$username = $rsc[0]["username"];
		$tlp = $rsc[0]["tlp"];
		$email = $rsc[0]["email"];
		$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"),
		);
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$breakfor = 0;
		for ($g=0;$g<count($game_urls) && $breakfor==0;$g++) {
			if (trim($game_urls[$g])!="") {
				$gurl = trim($game_urls[0]);
				$breakfor = 1;
			}
		}
		if ($breakfor==0) {
			$gurl = $rsp[0]["link"];
		}
		#$gurl = (count($game_urls)>0)?trim($game_urls[0]):$rsp[0]["link"];
		
		$rsa=array(); $qa="SELECT * FROM tourney_akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		
		$isipesan = "Silahkan transfer senilai Rp.150,006 utk Pkt150 / Rp.100,006 utk Pkt100. ".$gbank[$rsc[0]["kdbank"]]["bank"].":".$gbank[$rsc[0]["kdbank"]]["norek"]." a/n ".$gbank[$rsc[0]["kdbank"]]["namarek"].".Silahkan abaikan SMS ini jika sudah transfer";
		$executeSMS = 1;
	}
	
	if ($executeSMS==1) {
		$url = "http://zenziva.com/apps/smsapi.php";
		$url = "http://reguler.zenziva.net/apps/smsapi.php";
		$url = "http://pinkitty.zenziva.com/apps/smsapi.php";
		#return $url.'?userkey='.$userkeyanda.'&passkey='.$passkeyanda.'&nohp='.$nohptujuan.'&pesan='.urlencode($isipesan);
		#exit;
		$curlHandle = curl_init();
		curl_setopt($curlHandle, CURLOPT_URL, $url);
		curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'userkey='.$userkeyanda.'&passkey='.$passkeyanda.'&nohp='.$nohptujuan.'&tipe=reguler&pesan='.urlencode($isipesan));
		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);
		return $array;
		
	}
}

function doEMail($tipe, $kdmember=NULL, $kdakun=NULL) {
	$executeEMail = 0;
	if ($tipe=="assign" && isset($kdmember)) {
		$rsc=array(); $qc="SELECT * FROM members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$kdbank = $rsc[0]["kdbank"];
		$username = $rsc[0]["username"];
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$nama_product = $rsp[0]["nama"];
		$game_urls = explode(",", $rsp[0]["link"]);
		$gurl = '';
		for ($u=0;$u<count($game_urls);$u++) {
			$durl = trim($game_urls[$u]);
			if ($durl!="") { $gurl .= ($gurl!=''?'&nbsp;|&nbsp;':'').'<a href="//'.$durl.'" target="_blank">'.$durl.'</a>'; }
		}
		
		#$firstString = "Abc66";
		#$lastDigit = substr(trim($username), -1);
		#$oddEvenIndicator = (is_numeric($lastDigit) && intval($lastDigit)%2==0)?"n":"j";
		#$defPassword = "$firstString@".(intval($lastDigit)==0?'n':$lastDigit)."$oddEvenIndicator";
		
		$rsa=array(); $qa="SELECT * FROM akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		#$csubject = "Pendaftaran UserID dari Alphabet66 (".date('d/M/Y H:i:s', time()).")";
		$csubject = "Pendaftaran UserID dari BandarSport";
		
		$cmessage = '';
		$cmessage .= '<div><strong>Informasi UserID Anda</strong></div>';
		$cmessage .= '<table border="1" cellpadding="1" cellspacing="0">';
			$cmessage .= '<tr><td>UserID</td><td>:</td><td>'.$username.'</td></tr>';
			$cmessage .= '<tr><td>Password</td><td>:</td><td>'.$defPassword.'</td></tr>';
			$cmessage .= '<tr><td>Link URL</td><td>:</td><td>'.$gurl.'</td></tr>';
		$cmessage .= '</table>';
		#$cmessage .= '<div>Terima kasih sudah bermain bersama <a href="http://www.alphabet66.com/">Alphabet66</a>.</div>';
		#$cmessage .= '<div>&nbsp;</div>';
		#$cmessage .= '<div>&nbsp;</div>';
		#$cmessage .= '<div>Untuk Informasi lebih lanjut, silahkan menghubungi kami di <a href="mailto:info@alphabet66.com">info@alphabet66.com</a></div>';
		#$cmessage .= '<div>Atau bisa langsung berbicara dengan operator kami melalui LiveChat dalam website kami (<a href="//www.alphabet66.com/">Alphabet66</a>)</div>';
		#$cmessage .= '<div>Selamat Bermain!</div>';
		
		$cemail = "info@bandarsport.com";
		$cname = "bandarsport";
		$cc = "info@bandarsport.com";
		$to = $rsc[0]["email"].", ".$cc;
		$subject = $csubject;
		$headers = "From: ".$cemail."\r\n";
		$headers .= "Reply-To: ".$cemail."\r\n";
		if ($cc!="") {
			$headers .= "CC: ".$cc."\r\n";
		}
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
		
		$logo = '<img src="http://www.bandarsport.com/images/logo.png" width="100" alt="BandarSport :: Master Agen Bola dan Casino Terpercaya" />';
		
		$message = '';
		#$message = '<html><body>';
		#$message .= '<div style="background:#dfdfdf;margin:5px;padding:5px 10px;">'.$logo.'</div>';
		$message .= '<div style="width:650px;">';
			$message .= '<div style="margin:5px;padding:5px 10px;text-align:center;">'.$logo.'</div>';
			$message .= '<div style="text-align:center;">Pendaftaran Anda berhasil..!!</div>';
			$message .= '<div style="text-align:center;">Selamat bergabung bersama BandarSport dengan  Sistem Keamanan Transaksi Terbaik,</div>';
			$message .= '<div style="text-align:center;">dan nikmatilah servis 24 jam non-stop dari kami.</div>';
				
				$cmessage = str_replace("\\r\\n", "<br/>", $cmessage);
				$message .= '<div style="background:#fff;margin:5px;padding:5px 10px;">'.$cmessage.'</div>';
			
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">Untuk memulai bermain, silahkan lakukan transfer deposit Anda ke rekening : </div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;width:210px;margin:0 auto;">'.callBanks('d', $kdbank, 1).'</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">Setelah Anda men-transfer deposit, silahkan isi form <a href="'.absDom.'/index.php?r=deposits/create">deposit</a> dan tunggu 1-3 menit,</div>';
			$message .= '<div style="text-align:center;">maka kredit akan otomatis ditambahkan ke UserID '.$nama_product.' 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;">Alternatif link untuk '.$nama_product.' :</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">'.$gurl.'</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 style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			
			$message .= '<div>BandarSport | Agen Taruhan Bola Terbaik dan Terpercaya | <a href="'.absDom.'">www.BandarSport.com</a></div>';
			$message .= '<div>| SBObet | IBCbet | SBOcasino | CBO855 | Klik 4D | Maxbet | KlubTangkas |  IONcasino |</div>';
			$message .= '<div>&nbsp;</div>';
			$message .= '<div>YM: CS01.BANDARSPORT@yahoo.com</div>';
			$message .= '<div>BBM: 7DDC0C08</div>';
			$message .= '<div>WA: +85517394816</div>';
			
		$message .= '</div>';
		
		#$message .= "</body></html>";
		#echo str_replace("\r\n", "<br/>", $headers).$subject.$message;
		$executeEMail = 1;
	}
	
	if ($tipe=="assignnew" && isset($kdmember)) {
		$rsc=array(); $qc="SELECT * FROM members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$kdbank = $rsc[0]["kdbank"];
		$username = $rsc[0]["username"];
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$nama_product = $rsp[0]["nama"];
		$game_urls = explode(",", $rsp[0]["link"]);
		$gurl = '';
		for ($u=0;$u<count($game_urls);$u++) {
			$durl = trim($game_urls[$u]);
			if ($durl!="") { $gurl .= ($gurl!=''?'&nbsp;|&nbsp;':'').'<a href="//'.$durl.'" target="_blank">'.$durl.'</a>'; }
		}
		
		#$firstString = "Abc66";
		#$lastDigit = substr(trim($username), -1);
		#$oddEvenIndicator = (is_numeric($lastDigit) && intval($lastDigit)%2==0)?"n":"j";
		#$defPassword = "$firstString@".(intval($lastDigit)==0?'n':$lastDigit)."$oddEvenIndicator";
		
		$rsa=array(); $qa="SELECT * FROM akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		#$csubject = "Penggantian UserID Alphabet66 (".date('d/M/Y H:i:s', time()).")";
		$csubject = "Penggantian UserID BandarSport";
		$cmessage = '';
		$cmessage .= '<div><strong>Informasi UserID Baru Anda</strong></div>';
		$cmessage .= '<table border="1" cellpadding="1" cellspacing="0">';
			$cmessage .= '<tr><td>UserID</td><td>:</td><td>'.$username.'</td></tr>';
			$cmessage .= '<tr><td>Password</td><td>:</td><td>'.$defPassword.'</td></tr>';
			$cmessage .= '<tr><td>Link URL</td><td>:</td><td>'.$rsp[0]["link"].'</td></tr>';
		$cmessage .= '</table>';
		
		#$cmessage .= '<div>Terima kasih sudah bermain bersama <a href="http://www.alphabet66.com/">Alphabet66</a>.</div>';
		#$cmessage .= '<div>&nbsp;</div>';
		#$cmessage .= '<div>&nbsp;</div>';
		#$cmessage .= '<div>Untuk Informasi lebih lanjut, silahkan menghubungi kami di <a href="mailto:info@alphabet66.com">info@alphabet66.com</a></div>';
		#$cmessage .= '<div>Atau bisa langsung berbicara dengan operator kami melalui LiveChat dalam website kami (<a href="//alphabet66.com/">Alphabet66</a>)</div>';
		#$cmessage .= '<div>Selamat Bermain dan Semoga Beruntung!';
		
		$cemail = "info@bandarsport.com";
		$cname = "BandarSport";
		$cc = "info@BandarSport.com";
		$to = $rsc[0]["email"].", ".$cc;
		$subject = $csubject;
		$headers = "From: ".$cemail."\r\n";
		$headers .= "Reply-To: ".$cemail."\r\n";
		if ($cc!="") {
			$headers .= "CC: ".$cc."\r\n";
		}
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
		
		$logo = '<img src="http://www.bandarsport.com/img/logo_trans.png" width="100" alt="BandarSport :: Master Agen Bola dan Casino Terpercaya" />';
		#$message = '<html><body>';
		$message = '';
		#$message .= '<div style="background:#dfdfdf;margin:5px;padding:5px 10px;">'.$logo.'</div>';
		$message .= '<div style="width:650px;">';
			$message .= '<div style="margin:5px;padding:5px 10px;text-align:center;">'.$logo.'</div>';
			$message .= '<div style="text-align:center;">Penggantian UserID baru Anda berhasil..!!</div>';
			$message .= '<div style="text-align:center;">Selamat bermain kembali bersama BandarSport dengan Sistem Keamanan Transaksi Terbaik,</div>';
			$message .= '<div style="text-align:center;">dan nikmatilah servis 24 jam non-stop dari kami.</div>';
				
				$cmessage = str_replace("\\r\\n", "<br/>", $cmessage);
				$message .= '<div style="background:#fff;margin:5px;padding:5px 10px;">'.$cmessage.'</div>';
				
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">Untuk memulai bermain, silahkan lakukan transfer deposit Anda ke rekening : </div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;width:210px;margin:0 auto;">'.callBanks('d', $kdbank, 1).'</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">Setelah Anda men-transfer deposit, silahkan isi form <a href="'.absDom.'/index.php?r=deposits/create">deposit</a> dan tunggu 1-3 menit,</div>';
			$message .= '<div style="text-align:center;">maka kredit akan otomatis ditambahkan ke UserID '.$nama_product.' 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;">Alternatif link untuk '.$nama_product.' :</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">'.$gurl.'</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 style="text-align:center;">&nbsp;</div>';
			$message .= '<div style="text-align:center;">&nbsp;</div>';
			
			$message .= '<div>BandarSport | Agen Taruhan Bola Terbaik dan Terpercaya | <a href="'.absDom.'">www.BandarSport.com</a></div>';
			$message .= '<div>| SBObet | IBCbet | SBOcasino | CBO855 | Klik 4D | Maxbet | KlubTangkas |  IONcasino |</div>';
			$message .= '<div>&nbsp;</div>';
			$message .= '<div>YM: CS01.BANDARSPORT@yahoo.com</div>';
			$message .= '<div>BBM: 7DDC0C08</div>';
			$message .= '<div>WA: +85517394816</div>';
			
			
		$message .= '</div>';
		
		
		
		
		#$message .= "</body></html>";
		#echo str_replace("\r\n", "<br/>", $headers).$subject.$message;
		$executeEMail = 1;
	}
	if ($tipe=="assign-turney" && isset($kdmember)) {
		$rsc=array(); $qc="SELECT * FROM tourney_members WHERE kdmember='$kdmember'";
		callRS($rsc, $qc);
		$kdproduct = $rsc[0]["kdproduct"];
		$absDom = "http://www.bandarsport.com";
		$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"),
		);
		$username = $rsc[0]["username"];
		$rsp=array(); $qp="SELECT * FROM products WHERE kdproduct='$kdproduct'";
		callRS($rsp, $qp);
		$game_urls = explode(",", $rsp[0]["link"]);
		$gurl = '';
		for ($u=0;$u<count($game_urls);$u++) {
			$durl = trim($game_urls[$u]);
			if ($durl!="") { $gurl .= ($gurl!=''?'&nbsp;|&nbsp;':'').'<a href="//'.$durl.'" target="_blank">'.$durl.'</a>'; }
		}
		
		$firstString = "Abc66";
		$lastDigit = substr(trim($username), -1);
		$oddEvenIndicator = (is_numeric($lastDigit) && intval($lastDigit)%2==0)?"n":"j";
		$defPassword = "$firstString@".(intval($lastDigit)==0?'n':$lastDigit)."$oddEvenIndicator";
		
		$rsa=array(); $qa="SELECT * FROM tourney_akuns WHERE kdakun='$kdakun'";
		callRS($rsa, $qa);
		$defPassword = $rsa[0]["pass"];
		
		$csubject = "Pendaftaran UserID Tournament BandarSport (".date('d/M/Y H:i:s', time()).")";
		$cmessage = '';
		$cmessage .= '<div>UserID Anda:</div>';
		$cmessage .= '<table border="1" cellpadding="1" cellspacing="0">';
			$cmessage .= '<tr><td>UserID</td><td>:</td><td>'.$username.'</td></tr>';
			$cmessage .= '<tr><td>Password</td><td>:</td><td>'.$defPassword.'</td></tr>';
			$cmessage .= '<tr><td>Link URL</td><td>:</td><td>'.$gurl.'</td></tr>';
		$cmessage .= '</table>';
		$cmessage .= '<div>Terima kasih sudah mendaftar untuk <a href="http://www.bandarsport.com/tournament/">Tournament BandarSport</a>.</div>';
		$cmessage .= '<div>&nbsp;</div>';
		$cmessage .= '<div>
			Silahkan melakukan transfer sejumlah:<br/>
			<strong>Rp. 150,006</strong> untuk <strong>paket 150</strong><br/>
			atau<br/>
			<strong>Rp. 100,006</strong> untuk <strong>paket 100</strong>
			<br/>
			<strong>paket 100</strong>:<br/>
			<ul>
				<li>Biaya daftar Rp. 100,006.</li>
				<li>Saldo tidak bisa ditarik pada akhir Tournament.</li>
			</ul>
			<br/>
			<strong>paket 150</strong>:<br/>
			<ul>
				<li>Biaya daftar Rp. 150,006.</li>
				<li>Saldo kemenangan <span style="font-size:120%;"><strong>bisa</strong></span> ditarik pada akhir Tournament.</li>
			</ul>
			<br/>Semua paket mempunyai biaya isi ulang Rp. 100,006.
			<br/>User ID akan mendapatkan Credit 100 pada awal start Tournament.
		</div>';
		
		$cmessage .= '<div>
			<div style="float:left;width:210px;height:110px;border:2px #00aaff solid;border-radius:10px;margin:0 2px;">
				<img src="'.$gbank[$rsc[0]["kdbank"]]["src"].'" alt="" /><br/>
				'.$gbank[$rsc[0]["kdbank"]]["bank"].':<br/>
				'.$gbank[$rsc[0]["kdbank"]]["norek"].'<br/>
				'.$gbank[$rsc[0]["kdbank"]]["namarek"].'
			</div>
		</div>';
		$cmessage .= '<div>Untuk Informasi lebih lanjut, silahkan menghubungi kami di <a href="mailto:info@badarsport.com">info@bandarsport.com</a></div>';
		$cmessage .= '<div>Atau bisa langsung berbicara dengan operator kami melalui LiveChat dalam website kami (<a href="http://www.bandarsport.com/">BandarSport</a>)</div>';
		$cmessage .= '<div>Selamat Bermain!</div>';
		
		$cemail = "info@bandarsport.com";
		$cname = "BandarSport";
		$cc = "info@bandarsport.com";
		$to = $rsc[0]["email"].", ".$cc;
		$subject = $csubject;
		$headers = "From: ".$cemail."\r\n";
		$headers .= "Reply-To: ".$cemail."\r\n";
		if ($cc!="") {
			$headers .= "CC: ".$cc."\r\n";
		}
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
		
		$logo = '<img src="http://www.bandarsport.com/images/logo.png" width="100" alt="BandarSport :: Master Agen Bola dan Casino Terpercaya" />';
		
		#$message = '<html><body>';
		$message = '';
		$message .= '<div style="background:#dfdfdf;margin:5px;padding:5px 10px;">'.$logo.'</div>';
		
		$cmessage = str_replace("\\r\\n", "<br/>", $cmessage);
		$message .= '<div style="background:#fff;margin:5px;padding:5px 10px;">'.$cmessage.'</div>';
		#$message .= "</body></html>";
		#echo str_replace("\r\n", "<br/>", $headers).$subject.$message;
		$executeEMail = 1;
	}
	if ($executeEMail==1) {
		if (!mail($to, $subject, $message, $headers)) {
			return false;
			#echo 'error';
		} else {
			return true;
			#echo 'email oke';
		}
	}
	
	
	
	
}

function getSmsBalance() {
	$userkey = "izygh3";
	$passkey = "a9ssd9";
	$url = "http://pinkitty.zsms.us/api/credit.php";
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'userkey='.$userkey.'&passkey='.$passkey);
	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);
	$sms = array($xml->getName() => $array);
	return $sms["response"]["credit"]["value"];
}

?>