forked from kkprakasa/telek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn.php
219 lines (186 loc) · 9.3 KB
/
fn.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
defined('_SECURE_') or die('Forbidden');
function teltree_hook_checkavailablekeyword($keyword){
$ok = true;
//$db_query = "SELECT subscribe_id FROM " . _DB_PREF_ . "_featureSubscribe WHERE subscribe_keyword='$keyword'";
$keyword = array($keyword);
$teltree_keyword = array("GABUNG", "DAFTAR", "KELUAR");
if (count(array_intersect($keyword, $teltree_keyword)) !== 0) {
_log($keyword);
$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");
if (count(array_intersect($keyword, $kw)) !== 0) {
//$username="admin"; //-----------ini variabel parent bisa diganti sesuai parent sub user
$smsc="dev"; //-----------------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,2);
$kk = strtoupper($ps[0]);
$username="admin";
if ( $teltree_keyword == 'DAFTAR' ){
$pecah= preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY );
$data = array();
$data['name'] = trim($pecah[0]);
$data['username'] = trim($pecah[0]);
$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 );
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');
}
$balasan = "Selamat anda telah terdaftar di Telephone Tree";
$gagal = "Maaf Sistem sedang mengalami gangguan, silahkan coba beberapa saat lagi";
if ($save_to_group) {
$unicode = core_detect_unicode($balasan);
$balasan = addslashes($balasan);
// $username = "admin";
//$smsc = "dev";
_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");
}
}else{
echo "gagal";
}
return $ret;
//$ok = true;
} elseif ( $kk == 'GABUNG' ){
/*$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','code',array(
));*/
$uid = user_mobile2uid($sms_sender);
$group_code = strtoupper($ps[1]);
$list = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array(
'uid' => 1,
'mobile' => $sms_sender
));
if($group_code && $sms_sender ){
/*--dummy code--*/
$c_pid = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array(
'uid' => 1,
'mobile' => $sms_sender
));
$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','id',array(
'uid' => 1,
'code' => $group_code
));
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)) {
$list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'code', array(
'uid' => 1 //---$uid
));
_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'];
$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');
}
}
}
}
}
//$ok = true;
} elseif ( $kk == 'KELUAR' ){
$uid = user_mobile2uid($sms_sender);
$group_code = strtoupper($ps[1]);
//_log($sms_sender . ' '. $group_code, 2 , 'test');
if($group_code && $sms_sender){
// _log($sms_sender . ' '. $group_code, 2 , 'test');
$c_pid = dba_search(_DB_PREF_ . '_featurePhonebook','id',array(
'uid' => 1,
'mobile' => $sms_sender
));
$gpids = dba_search(_DB_PREF_ . '_featurePhonebook_group','id',array(
'uid' => 1,
'code' => $group_code
));
foreach($gpids as $gpid){
foreach($gpid as $key => $val){
$items = array(
'gpid' => $val,
'pid' => $c_pid[0]['id']
);
// _log($sms_sender . ' '. $group_code, 2 , 'test');
if(!dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')){
if(dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts',$items)){
if($iid = $c_pid[0]['id']){
$bal_grup = "anda telah keluar dari grup".$list[$iid]['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');
}
}
}
}
}
}