corat-coret03

<html>
<head>
<meta http-equiv="refresh" content="7"
	url="<?php $_SERVER['PHP_SELF'];?>" />
</head>
<body>
<h1>SMS server running ...</h1>

<?php
include('database.func.php');
mysql_connect("localhost","root","");
mysql_select_db("sds");

$query = "SELECT * FROM inbox where processed = 'false'";
$hasil = mysql_query($query);

while($data = mysql_fetch_array($hasil)){
	$id = $data['ID'];
	$noPengirim = $data['SenderNumber'];
	$msg = strtoupper($data['TextDecoded']);
	$pecah = explode(" ",$msg);

	if($pecah[0] == "REG"){
		$nama = "$pecah[1] $pecah[2]";

		$cekNo = mysql_query("SELECT Number,Name from pbk where Number = '$noPengirim'");

		if(mysql_num_rows($cekNo) == 0){
			$query = "INSERT INTO pbk (GroupID, Name, Number) values (1,'$nama','$noPengirim');";
			$ok = mysql_query($query);
			//echo "query pendaftaran: $ok";
			$reply = "Terima kasih $nama, Nomer anda telah terdaftar. Ketik INFO utk Informasi Markaz. Ketik JADWAL utk Informasi Kajian.";
		}else{
			while($resCekNo = mysql_fetch_array($cekNo)){
				$replayganda = "No anda telah terdaftar dengan nama: ";
				if(mysql_num_rows($cekNo) == 1){
					$reply = $resCekNo['Name'];
				} else {
					$reply .= $resCekNo['Name']." dan ";
				}
			}
			$reply = $replayganda.$reply;
		}
	} elseif($pecah[0] == "INFO") {
		if($pecah[1] == "MARKAZ"){
			$infomarkaz = query("select name, kode from markaz");
			while($resInfoMarkaz = mysql_fetch_object($infomarkaz)){
				$reply .= "$resInfoMarkaz->name kode: $resInfoMarkaz->kode.\n";
			}
		}elseif($pecah[1] == "ALAMAT"){
			if($pecah[2] == ""){
				$alamatmarkaz = query("select name,alamat from markaz");
				$reply = "Daftar Alamat semua markaz Surabaya. ";
				while($resAlamatMarkaz = mysql_fetch_array($alamatmarkaz)){
					$reply .= "Alamat $resAlamatMarkaz->name: $resAlamatMarkaz->alamat.";
				}
			}else{
				$alamatmarkaz = find("select alamat,name from markaz where kode = $pecah[2]");
				$reply = "Alamat $alamatmarkaz->name: $alamatmarkaz->alamat.";
			}
		}elseif($pecah[1] == "TELPON"){
			if($pecah[2] == ""){
				$telponmarkaz = query("select name, telpon from markaz");
				$reply = "Daftar No. Telpon semua markaz Surabaya. ";
				while($resTelponMarkaz = mysql_fetch_array($telponmarkaz)){
					$reply .= "No Telpon $resTelponMarkaz->name: $resTelponMarkaz->alamat.";
				}
			}else{
				$TelponMarkaz = find("select telpon,name from markaz where kode = $pecah[2]");
				$reply = "No Telpon $TelponMarkaz->name: $TelponMarkaz->telpon.";
			}
		}else{
			$reply = "Info [nocode]: INFO MARKAZ. Alamat lengkap Markaz: INFO ALAMAT [nocode]. No Telpon Markaz: INFO TELPON [nocode].";
		}
	} else if($pecah[0] == "JADWAL"){
		if($pecah[1] == "RUTIN"){
			if($pecah[2] == ""){
				$reply = "Tidak ditemukan [nocode]. Ketik INFO MARKAZ untuk mengetahuinya.";
			}else{
				if(find("select name from markaz where kode = $pecah[2]") == null){
					$reply = "[nocode] tidak ada dalam BUKU kami. Ketik INFO MARKAZ untuk mengetahuinya.";
				}else{
					$listJadwal = query("select name, hari, mingguke, kitab, ustadz, waktu from jadwal jd
								join markaz mk on mk.kode = jd.kode where mk.kode = $pecah[2]");
					$countRow = mysql_num_rows($listJadwal);
					while($resListJadwal = mysql_fetch_object($listJadwal)){

						if($resListJadwal->mingguke == 'semua') $mingguke = '';
						else $mingguke = $resListJadwal->mingguke;
						$reply .= "$resListJadwal->name,hari:$resListJadwal->hari $mingguke waktu:$resListJadwal->waktu,kitab: $resListJadwal->kitab,Al Ustadz $resListJadwal->ustadz";
					}
				}
			}
		}elseif($pecah[1] == "DAUROH"){
			if(!is_null($pecah[2])){
				$cekkode = findValue("select kode from markaz where kode = $pecah[2]");
				if($cekkode == "") $reply = "Untuk mengetahui [nocode], ketik INFO MARKAZ.";
				else {
					$infoDaurohMarkaz = query("select tanggal,waktu,tempat,tema,kitab,ustadz,asal_ustadz from dauroh
							where tanggal > now() && kode = $pecah[2]");
					$no=0;
					while($resInfoDaurohMarkaz = mysql_fetch_object($infoDaurohMarkaz)){
						$no++;
						$tanggal = date("d-m-Y",strtotime($resInfoDaurohMarkaz->tanggal));
						$reply .= "$no) Tanggal: $tanggal, Waktu: $resInfoDaurohMarkaz->waktu, Tempat: $resInfoDaurohMarkaz->tempat, Tema: $resInfoDaurohMarkaz->tema, Kitab: $resInfoDaurohMarkaz->kitab, Ustadz: $resInfoDaurohMarkaz->ustadz, $resInfoDaurohMarkaz->asal_ustadz.";
					}
				}
			}else{
				$infoDaurohMarkaz = query("select tanggal,waktu,tempat,tema,kitab,ustadz,asal_ustadz from dauroh
							where tanggal > now()");
				$no=0;
				while($resInfoDaurohMarkaz = mysql_fetch_object($infoDaurohMarkaz)){
					$no++;
					$tanggal = date("d-m-Y",strtotime($resInfoDaurohMarkaz->tanggal));
					$reply .= "$no) Tanggal: $tanggal, Waktu: $resInfoDaurohMarkaz->waktu, Tempat: $resInfoDaurohMarkaz->tempat, Tema: $resInfoDaurohMarkaz->tema, Kitab: $resInfoDaurohMarkaz->kitab, Ustadz: $resInfoDaurohMarkaz->ustadz, $resInfoDaurohMarkaz->asal_ustadz.";
				}
			}
		}else{
			$reply = "Ketik JADWAL RUTIN [nocode] untuk Kajian Rutin. Ketik JADWAL DAUROH [nocode] untuk Kajian Dauroh. Ketik INFO MARKAZ untuk [nocode].";
		}
	} else {
		$cekNo = mysql_query("SELECT Number,Name from pbk where Number = '$noPengirim'");
		$reply = "Perintah-perintah SMS Dakwah Surabaya. INFO MARKAZ untuk Informasi [nocode] Markaz. JADWAL RUTIN atau JADWAL DAUROH untuk Informasi Jadwal kajian/dauroh. REG 'nama' untuk pendaftaran.";
	}

	$jumlahSMS = ceil(strlen($reply)/153);
	$bagiSMS = str_split($reply, 153);
	$query = "SHOW TABLE STATUS LIKE 'outbox'";
	$hasil = mysql_query($query);
	$data  = mysql_fetch_array($hasil);
	$newID = $data['Auto_increment'];

	for($i=1; $i<=$jumlahSMS; $i++){
		$udh = "050003A7".sprintf("%02s", $jumlahSMS).sprintf("%02s", $i);
		$msg = $bagiSMS[$i-1];
		if($i == 1){
			$query = "INSERT INTO outbox (DestinationNumber, UDH, TextDecoded, ID, MultiPart)
                VALUES ('$noPengirim', '$udh', '$msg', '$newID', 'true')";

		}else{
			$query = "INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
                VALUES ('$udh', '$msg', '$newID', '$i')";
		}
		echo "query: $msg";
		$end = mysql_query($query);
	}

	$query = "update inbox set Processed = 'true' where ID = '$id'";
	$end = mysql_query($query);
}
?>

</body>
</html>

 

</pre>
<?php
include('database.func.php');

mysql_connect("localhost","root","");
mysql_select_db("sds");

$reply = "Bismillah, Hari ini Tausyiah Ust. Syafruddin di Masjid Darul Arqom, waktu: ba'da Maghrib. Insya Allah.";

//$noPengirim = find("SELECT Number,Name from pbk where Number = '+6285731785962'");
$query1 = mysql_query("SELECT Number,Name from pbk");
//$hasil = mysql_query($query);
$log = "";

while($noPengirim = mysql_fetch_object($query1)){

$jumlahSMS = ceil(strlen($reply)/152);
$bagiSMS = str_split($reply, 152);
$query = "SHOW TABLE STATUS LIKE 'outbox'";
$hasil = mysql_query($query);
$data = mysql_fetch_array($hasil);
$newID = $data['Auto_increment'];

for($i=1; $i<=$jumlahSMS; $i++){
$udh = "050003A7".sprintf("%02s", $jumlahSMS).sprintf("%02s", $i);
$msg = $bagiSMS[$i-1];
$msg = mysql_real_escape_string($msg);
if($i == 1){
$query = "INSERT INTO outbox (DestinationNumber, UDH, TextDecoded, ID, MultiPart)
VALUES ('$noPengirim->Number', '$udh', '$msg', '$newID', 'true')";

}else{
$query = "INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
VALUES ('$udh', '$msg', '$newID', '$i')";
}
$log .= "query: $msg <br/> $query <br/>";
$end = mysql_query($query);
}
}
echo $log;
?>

<span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; font-size: 12px; line-height: 18px; white-space: pre;">

Silahkan Komentar ... !

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s