-
Notifications
You must be signed in to change notification settings - Fork 0
/
cekinfo.php
198 lines (181 loc) · 7.76 KB
/
cekinfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<title>Halaman serverSms</title>
<meta http-equiv="refresh" content="5;url=serverSms.php">
<h1>Server SMS Running..., jangan di tutup!</h1>
<?php
require_once "conf/connect.php";
//===menangambil data isi pesan,noPengirim, dari inbox dengan field Processed bernilai false, yang menandakan bahwa pesan masuk belum diproses====
$crud = new crud("localhost","root","","db_broadcast");
$pesan = $crud->fetch("inbox", " Processed = 'false' ");
$ide = "";
$replyPesan = "";
$pesanAwal = "";
$nomor = "";
if (count($pesan)>0) {
foreach ($pesan as $list) {
$SenderNumber = "0".substr($list['SenderNumber'],3);
if (is_numeric($SenderNumber)) {
$cek_nomor = $crud->num("tpengguna","telepon = '$SenderNumber'");
$jabatan = $crud->fetch("tpengguna", "telepon = '$SenderNumber'");
if ($cek_nomor>0) {
$isi = $list['TextDecoded'];
$bagi = explode("#", $isi);
if (count($bagi) == 6) {
$pin = $bagi[5];
if ($pin == $jabatan[0]['pin'] && $jabatan[0]['jabatan'] == "Dosen") {
if (strtolower($bagi[0]) == "ch") {
$kd_mk = $bagi[1]; //kode matkul
$kd_jurusan = substr($kd_mk, 0,2);
$kelas = strtoupper($bagi[2]); //kelas
$hari = strtolower($bagi[3]); //hari
$jam = $bagi[4]; //jam
$no_reg = $jabatan[0]['no_reg']; //Kode dosen
$dtmtkul=$crud->num("tdosenmatkul","no_reg='$no_reg' AND kd_matkul='$kd_mk'");
$kddm = "";
if ($dtmtkul>0) {
$kddm = $crud->fetch("tdosenmatkul","no_reg='$no_reg' AND kd_matkul='$kd_mk'");
}
$cek = $crud->fetch("tmatkul","kd_matkul='$kd_mk'");
$kd_dm = $kddm[0]['kd_dm'];
$semester = $cek[0]['semester'];
$cekjk = $crud->fetch("tjadwal", "hari = '$hari' AND jam = '$jam' AND kelas = '$kelas' AND semester = '$semester' AND jurusan = '$kd_jurusan'");
if (!$dtmtkul > 0) {
$replyPesan .= "Maaf kode mata kuliah yang anda masukkan salah";
$ide = $list['ID'];
}else{
if ($cekjk[0]['kd_dm'] == NULL) {
$crud->jadwal("tjadwal","kd_dm = '$kd_dm'", "hari = '$hari' AND jam = '$jam' AND kelas = '$kelas' AND semester = '$semester' AND jurusan = '$kd_jurusan'");
$data = $crud->fetch("tkrs tk LEFT JOIN tpengguna tp ON tk.no_reg = tp.no_reg","tk.kd_dm = '$kd_dm' AND tp.kelas = '$kelas' AND tp.semester = '$semester' AND tp.jurusan = '$jurusan'");
foreach ($data as $value) {
$pesan = "INFO smtr ".$semester." Kelas ".$kelas.": Utk Mata kuliah ".$cek[0]['nm_matkul']." telah dipindahkan ke hari ".$hari." jam ke-".$jam.". Ttd. ".$jabatan[0]['nama'];
$kirim = array('SenderNumber' => $value['telepon'], 'TextDecoded' => $pesan);
$crud->insert("outbox", $kirim);
}
$replyPesan .= "Jadwal berhasil diubah";
$ide = $list['ID'];
}else{
$replyPesan .= "Jam yang anda tuju telah terisi";
$ide = $list['ID'];
}
}
/*else{
$cekjk = $crud->fetch("tjadwal", "hari = '$hari' AND jam = '$jam' AND kelas = '$kelas' AND semester = '$semester' AND jurusan = '$jurusan'");
if (!$cekjk[0]['kd_dm'] == "") {
$hasil = $crud->jadwal("tjadwal","kd_dm = '$kd_dm'", "hari = '$hari' AND jam = '$jam' AND kelas = '$kelas' AND semester = '$semester' AND jurusan = '$jurusan'");
$replyPesan .= "Jadwal kuliah berhasil diubah";
$ide = $list['ID'];
}else{
$replyPesan .= "Maaf hari ".$hari." jam ke-".$jam." sudah terisi";
$ide = $list['ID'];
}
}*/
}
}else{
$replyPesan .= "Pin yang anda masukkan salah !";
$ide = $list['ID'];
}
} else {
if ($pin == $cek_nomor[0]['pin']) {
if (strtolower($bagi[0]) == "info") {
if (strtolower($bagi[1]) == "Dosen") {
# code...
}
}else{
$replyPesan .= "Format pesan yang anda masukkan salah";
}
}
}
}else{
$id = $list['ID'];
$crud->delete("inbox","ID = '$id'");
}
}else{
$id = $list['ID'];
$crud->delete("inbox","ID = '$id'");
}
$nomor = $SenderNumber;
}
}
if (!$ide == "" && !$replyPesan == "") {
$data = array('DestinationNumber' => $nomor, 'TextDecoded' => $replyPesan);
$crud->insert('outbox',$data);
$crud->jadwal("inbox", "Processed = 'true'", "ID = '$ide'");
}elseif(!$ide == "" && $replyPesan == ""){
$crud->jadwal("inbox", "Processed = 'true'", "ID = '$ide'");
}
/*/balas pesan secara otomatis;
$jumSms = ceil(strlen($replyPesan)/160);
if($jumSms == 1){
if(strtolower($pesanAwal) == "stmik"){
$query=mysqli_query($conn,"SELECT * FROM mahasiswa,krs WHERE mahasiswa.nim = krs.nim AND krs.kodeMatkul='$pes2' AND krs.tahunAkademik='$tahun'");
while ($rs=mysqli_fetch_array($query)) {
$relply = mysqli_query($conn,"INSERT INTO outbox(DestinationNumber,TextDecoded) VALUES('$rs[telepon]','$replyPesan')");
}
}else{
$relply = mysqli_query($conn,"INSERT INTO outbox(DestinationNumber,TextDecoded) VALUES('$noTeleponPengirim','$replyPesan')");
}
}elseif($jumSms>1){
if(strtolower($pesanAwal) == "stmik"){
$query=mysqli_query($conn,"SELECT * FROM mahasiswa,krs WHERE mahasiswa.nim = krs.nim AND krs.kodeMatkul='$pes2' AND krs.tahunAkademik='$tahun'");
while ($rs=mysqli_fetch_array($query)) {
// menghitung jumlah pecahan
$hitPecah = ceil(strlen($replyPesan)/153);
// memecah pesan asli
$pecah = str_split($replyPesan, 153);
// membuat nilai ID untuk di insert di outbox
$query = "SHOW TABLE STATUS LIKE 'outbox'";
$hasil = mysql_query($query);
$data = mysqli_fetch_array($hasil);
$newID = $data['Auto_increment'];
for ($i=1; $i<=$jumSms;$i++){
// membuat UDH untuk setiap pecahan, sesuai urutannya
$udh = "050003A7".sprintf("%02s", $hitPecah).sprintf("%02s", $i);
// membaca text setiap pecahan
$msg = $pecah[$i-1];
if ($i == 1){
// jika merupakan pecahan pertama, maka masukkan ke tabel OUTBOX
$query = "INSERT INTO outbox (DestinationNumber, UDH, TextDecoded, ID, MultiPart)
VALUES ('$noTeleponPengirim', '$udh', '$msg', '$newID', 'true')";
}else{
// jika bukan merupakan pecahan pertama, simpan ke tabel OUTBOX_MULTIPART
$query = "INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
VALUES ('$udh', '$msg', '$newID', '$i')";
}
// jalankan query
mysql_query($query);
}
}
}else{
// menghitung jumlah pecahan
$hitPecah = ceil(strlen($replyPesan)/153);
// memecah pesan asli
$pecah = str_split($replyPesan, 153);
// membuat nilai ID untuk di insert di outbox
$query = "SHOW TABLE STATUS LIKE 'outbox'";
$hasil = mysql_query($query);
$data = mysqli_fetch_array($hasil);
$newID = $data['Auto_increment'];
for ($i=1; $i<=$jumSms;$i++){
// membuat UDH untuk setiap pecahan, sesuai urutannya
$udh = "050003A7".sprintf("%02s", $hitPecah).sprintf("%02s", $i);
// membaca text setiap pecahan
$msg = $pecah[$i-1];
if ($i == 1){
// jika merupakan pecahan pertama, maka masukkan ke tabel OUTBOX
$query = "INSERT INTO outbox (DestinationNumber, UDH, TextDecoded, ID, MultiPart)
VALUES ('$noTeleponPengirim', '$udh', '$msg', '$newID', 'true')";
}else{
// jika bukan merupakan pecahan pertama, simpan ke tabel OUTBOX_MULTIPART
$query = "INSERT INTO outbox_multipart(UDH, TextDecoded, ID, SequencePosition)
VALUES ('$udh', '$msg', '$newID', '$i')";
}
// jalankan query
mysql_query($query);
}
}
}
//$relply = mysqli_query($conn,"INSERT INTO outbox(DestinationNumber,TextDecoded) VALUES('$noTeleponPengirim','$replyPesan')");
$crud->jadwal("inbox", "Processed = 'true'", "ID = '$ide'");
//UPDATE `akademik`.`inbox` SET `Processed` = 'true' WHERE `inbox`.`ID` =353 LIMIT 1 ;
//========akhir baris code untuk membalas sms secara otomatis dengan mengambil nilai dari variabel $replyPesan sebagai isi SMS=======
*/
?>