forked from kkprakasa/telek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfn.php-bakup-terbaru
312 lines (256 loc) · 13.5 KB
/
fn.php-bakup-terbaru
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
defined('_SECURE_') or die('Forbidden');
function teltree_hook_checkavailablekeyword($keywords){
$ok = true;
//$db_query = "SELECT subscribe_id FROM " . _DB_PREF_ . "_featureSubscribe WHERE subscribe_keyword='$keyword'";
$keyword = array($keywords);
//$teltree_keyword = array("GABUNG", "DAFTAR", "KELUAR");
$teltree_keyword = array("DAFTAR", "KELUAR");
if (count(array_intersect($keyword, $teltree_keyword)) !== 0) {
_log("teltree " . $keywords);
$ok = false;
}
return $ok;
}
/*
* intercept incoming sms and remove keyword
*
* @param $sms_datetime
* incoming SMS date/time
* @param $sms_sender
* incoming SMS sender
* @message
* incoming SMS message before interepted
* @param $sms_receiver
* receiver number that is receiving incoming SMS
* @return
* array $ret
*/
function teltree_hook_setsmsincomingaction($sms_datetime, $sms_sender, $teltree_keyword, $teltree_param = '' , $sms_receiver = '', $smsc = '', $raw_message = ''){
$ok = false;
$keyword = array($teltree_keyword);
//$kw = array("GABUNG", "DAFTAR", "KELUAR");
$kw = array("DAFTAR", "KELUAR");
if (count(array_intersect($keyword, $kw)) !== 0) {
//$username="admin"; //-----------ini variabel parent bisa diganti sesuai parent sub user
$smsc="gsm1"; //-----------------ini variabel tergantung SMSC yang dipake
$c_uid=user_mobile2uid($sms_sender);
if(teltree_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $teltree_keyword, $teltree_param, $smsc, $raw_message)){
_log('begin s:' . $sms_sender . ' m:' . $teltree_keyword, 2, 'teltree');
$ok = true;
}
$status = ($ok ? 'handled' : 'unhandled');
_log('end s:' . $sms_sender . ' m:' . $teltree_param . ' s:' . $status, 2, 'teltree');
}
$ret['status'] = $ok;
return $ret;
}
function teltree_handle($c_uid, $sms_datetime, $sms_sender, $sms_receiver, $teltree_keyword, $teltree_param = '', $smsc = '', $raw_message = ''){
$ps= explode(" ", $raw_message);
//$kk = strtoupper($ps[0]);
$kk = strtoupper(substr($raw_message,0,6));
$kodeGrup = strtoupper(substr($raw_message,0 - strlen(end($ps))));
$nama = substr($raw_message,7,0 - strlen(end($ps)));
$username="admin";
if($teltree_keyword == 'DAFTAR' && isset($kodeGrup)){
$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','id', array(
'uid' => 1,
'code' => $kodeGrup
));
// } //-- INI CLOSE DARI IF DIATAS
if ( sizeof($gpids) !== 0 ){
//$pecah= preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY );
$data = array();
$data['name'] = trim($nama);
$data['username'] = trim($nama);
$data['mobile'] = $sms_sender;
$data['email'] = str_replace(' ','',$data['name'])."@noreply.org";
$data['parent_uid'] = 1; //----- ini parentnya admin
$data['status'] = 4; //---ini artinya ditambahkan ke sub user
$ret = user_add($data);
$ok = ($ret['status'] ? TRUE : FALSE );
_log($data['name'] . " " . $data['username'] . " " . $data['mobile'] . " " . $data['email'] . " " . $data['parent_uid'] . " " . $data['status']);
//_log($ok);
if ($ok){
//echo "okee";
$items = array(
'uid' => 1,
'name' => $data['name'],
'mobile' => $data['mobile'],
'email' => $data['email'],
'tags' => $tags
);
if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) {
$save_to_group = TRUE;
_log( 'Success to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree');
} else {
_log('Fail to add contact pid:' . $c_pid . ' m:' . $data['mobile'] . ' n:' . $data['name'] . ' e:' . $data['email'] . ' tags:[' . $data['tags'] . ']', 2, 'teltree');
} //--end if
//$balasan = "Selamat anda telah terdaftar di Telephone Tree";
//$gagal = "Maaf Sistem sedang mengalami gangguan, silahkan coba beberapa saat lagi";
$balasan = "Congratulation you are registered on Telephone Tree system";
$gagal = "We are appologies because our system is on maintenance, please try again later";
if ($save_to_group) {
$unicode = core_detect_unicode($balasan);
$balasan = addslashes($balasan);
// $username = "admin";
//$smsc = "gsm1";
_log("returns:".$balasan, 2, "teltree");
sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc);
} else {
$unicode = core_detect_unicode($gagal);
$balasan = addslashes($gagal);
_log("returns:".$gagal, 2, "teltree");
sendsms_helper($username, $sms_sender, $balasan, 'text', $unicode, $smsc);
_log_print("returns empty", 2, "teltree");
} //--end if
//---proses gabung ke grup Rev 1.1
if($kodeGrup && $sms_sender ){
$c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array(
'uid' => 1,
'mobile' => $sms_sender
));
foreach($gpids as $gpid){
foreach($gpid as $key => $val){
$items = array(
'gpid' => $val,
'pid' => $c_pid[0]['id']
);
if(dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) {
if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) {
$__gpid = dba_search(_DB_PREF_ . '_featurePhonebook_group_contacts','gpid',array(
'pid' => $c_pid[0]['id']
));
$list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'code', array(
'uid' => 1, //---$uid
'id' => $__gpid[0]['gpid']
));
_log('contact added to group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit');
if($iid = $c_pid[0]['id']){
//$bal_grup = "selamat anda telah tergabung di grup".$list[$iid]['code'];
$bal_grup = 'Congratulation you are registered to the group ' . $list[0]['code'];
$unicode = core_detect_unicode($bal_grup);
$bal_grup = addslashes($bal_grup);
_log("returns:".$bal_grup, 2, "telek");
sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc);
_log("returns empty", 2, "sms custom");
}
} else {
_log('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit');
_log('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit');
_log('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'phonebook_edit');
}
}
}//-- end foreach
} //-- end foreach
} //--end if proses gabung
}else{
echo "gagal";
$bal_gagal = 'Failed to register, probably you already have registered to the system or contact administrator on +628568218424';
$unicode = core_detect_uncode($bal_gagal);
$bal_gagal = addslashes($bal_gagal);
_log("returns : " . $bal_gagal, 2, "telek");
sendsms_helper($username, $sms_sender, $bal_gagal, 'text', $unicode, $smsc);
_log("returns empty", 2, "sms custom:");
} //--- end if
}
return $ret;
//$ok = true;
} elseif ( $kk == 'KELUAR' ){
$uid = user_mobile2uid($sms_sender);
if($kodeGrup && $sms_sender){
// _log($sms_sender . ' '. $kodeGrup , 2 , 'test');
$c_pid = dba_search(_DB_PREF_ . '_featurePhonebook','id',array(
'uid' => 1,
'mobile' => $sms_sender
));
$__gpid = dba_search(_DB_PREF_ . '_featurePhonebook_group_contacts','gpid',array(
'pid' => $c_pid[0]['id']
));
$list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'code', array(
'uid' => 1, //---$uid
'id' => $__gpid[0]['gpid']
));
$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','id',array(
'uid' => 1,
'code' => $kodeGrup
));
if (dba_update(_DB_PREF_ . '_tblUser', array(
'c_timestamp' => mktime(),
'flag_deleted' => 1
), array(
'flag_deleted' => 0,
'uid' => $uid
))) {
user_banned_remove($uid);
_log('user removed u:' . $username . ' uid:' . $uid, 2, 'user_remove');
// $ret['error_string'] = _('Account has been removed') . " (" . _('username') . ": " . $username . ")";
// $ret['status'] = TRUE;
}
foreach($gpids as $gpid){
foreach($gpid as $key => $val){
$items = array(
'gpid' => $val,
'pid' => $c_pid[0]['id']
);
_log($sms_sender . ' '. $kodeGrup, 2 , 'test');
if(!dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')){
if(dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts',$items)){
dba_remove(_DB_PREF_ . '_featurePhonebook',array(
'uid' => 1,
'id' => $c_pid[0]['id']
));
if($iid = $c_pid[0]['id']){
//$bal_grup = "anda telah keluar dari grup".$list[$iid]['code'];
$bal_grup = "You're successfully exit from group " . $list[0]['code'];
$unicode = core_detect_unicode($bal_grup);
$bal_grup = addslashes($bal_grup);
_log("returns:".$bal_grup, 2, "telek");
sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc);
_log("returns empty", 2, "sms custom");
}
_log('contact removed from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit');
}else{
_log('contact fail to remove from group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 2, 'teltree_phonebook_edit');
}
}else{
_log('failed '.$val . ' '. $c_pid[0]['id'], 2 , 'test');
$bal_grup = "Unsuccessfull exit from group ". $kodeGrup . " ,Probably you're not registered in this group" ;
$unicode = core_detect_unicode($bal_grup);
$bal_grup = addslashes($bal_grup);
_log("returns:".$bal_grup, 2, "telek");
sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc);
}
}
}
} else {
_log('failed '.$val . ' '. $c_pid[0]['id'], 2 , 'test');
$bal_grup = "to Exit you have to Enter before :) " ;
$unicode = core_detect_unicode($bal_grup);
$bal_grup = addslashes($bal_grup);
_log("returns:".$bal_grup, 2, "telek");
sendsms_helper($username, $sms_sender, $bal_grup, 'text', $unicode, $smsc);
}
}
}
/*
function tt_validasi($data=array()){
global $core_config;
$ret['status'] = true;
if(is_array($data)){
foreach($data as $key => $val){
$data[$key] = trim($val);
}
if($data['name'] && dba_isexists(_DB_PREF_ . '_tblUser', array(
'flag_deleted' => 0,
'username' => $data['name']
), 'AND')) {
if(!$flag_edit){
$ret['error_string'] = "test";
$ret['status'] = false;
}
}
}
return $ret
}
*/