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 = "******"; 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 = "******"; //$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)); _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'); } } } } } }
/** * Add country * @param string $name Country name * @param string $code Country code * @param string $prefix Country prefix * @return boolean */ function country_add($name, $code, $prefix = '') { $ret = FALSE; if (!$name) { return FALSE; } $code = substr(0, 2, core_sanitize_alpha(strtolower(trim($code)))); if (!$code) { return FALSE; } $prefix = trim($prefix) ? core_sanitize_numeric($prefix) : ''; $db_table = _DB_PREF_ . '_tblCountry'; if (dba_isavail($db_table, array('country_name' => $name, 'country_code' => $code))) { $items = array('name' => $name, 'code' => $code, 'prefix' => $prefix); if ($result = dba_add($db_table, $items)) { logger_print('id:' . $result . ' name:' . $name . ' code:' . $code . ' prefix:' . $prefix, 3, 'country_add'); $ret = TRUE; } } return $ret; }
} $r = $_REQUEST; $c_uid = $r['uid']; $list = registry_search($c_uid, 'feature', 'sms_sync'); $sms_sync_secret = $list['feature']['sms_sync']['secret']; $sms_sync_enable = $list['feature']['sms_sync']['enable']; $message_id = $r['message_id']; $sms_datetime = core_display_datetime(core_get_datetime()); $sms_sender = $r['from']; $message = $r['message']; $sms_receiver = $r['sent_to']; $ok = FALSE; if ($sms_sync_enable && $c_uid && $r['secret'] == $sms_sync_secret && $message_id && $sms_sender && $message) { $db_table = _DB_PREF_ . '_featureSmssysnc'; $conditions = array('uid' => $c_uid, 'message_id' => $message_id); if (dba_isavail($db_table, $conditions, 'AND')) { _log("saving uid:" . $c_uid . " dt:" . $sms_datetime . " ts:" . $r['sent_timestamp'] . " message_id:" . $message_id . " s:" . $sms_sender . " m:" . $message . " r:" . $sms_receiver, 3, "sms_sync sync"); // if keyword does not exists (checkavailablekeyword == TRUE) // then prefix the message with an @username so that it will be routed to $c_uid's inbox $m = explode(' ', $message); $c_m = str_replace('#', '', $m[0]); if (checkavailablekeyword($c_m)) { _log("forwarded to inbox uid:" . $c_uid . " message_id:" . $message_id, 3, "sms_sync sync"); $message = "@" . user_uid2username($c_uid) . " " . $message; } // route it if ($recvsms_id = recvsms($sms_datetime, $sms_sender, $message, $sms_receiver)) { $items = array('uid' => $c_uid, 'message_id' => $message_id, 'recvsms_id' => $recvsms_id); dba_add($db_table, $items); _log("saved uid:" . $c_uid . " message_id:" . $message_id . " recvsms_id:" . $recvsms_id, 3, "sms_sync sync"); $ret = array('payload' => array('success' => "true", 'error' => NULL));
function dba_isexists($db_table, $conditions = '', $operand = 'OR') { $ret = dba_isavail($db_table, $conditions, $operand) ? false : true; return $ret; }
} else { $_SESSION['error_string'] = _('You must fill mandatory fields'); header("Location: " . _u('index.php?app=main&inc=feature_phonebook&op=phonebook_list')); exit; break; } foreach ($gpids as $gpid) { $maps[][$c_pid] = $gpid; } dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts', array('pid' => $c_pid)); foreach ($maps as $map) { foreach ($map as $key => $val) { $gpid = $val; $c_pid = $key; $items = array('gpid' => $gpid, 'pid' => $c_pid); if (dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', $items, 'AND')) { if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $items)) { logger_print('contact added to group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_edit'); } else { logger_print('contact edited but fail to save in group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_edit'); } } } } $_SESSION['error_string'] = _('Contact has been edited'); header("Location: " . _u('index.php?app=main&inc=feature_phonebook&op=phonebook_list')); exit; break; } break; }
case 'delete': foreach ($items as $item) { if (dba_remove(_DB_PREF_ . '_featurePhonebook', array('uid' => $user_config['uid'], 'id' => $item))) { dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts', array('pid' => $item)); $_SESSION['dialog']['info'][] = _('Selected contact has been deleted'); } } break; } $gpid = 0; $ops = explode('_', _OP_); if ($ops[0] == 'move' && $ops[1]) { $gpid = $ops[1]; } if ($gpid && dba_valid(_DB_PREF_ . '_featurePhonebook_group', 'id', $gpid)) { foreach ($items as $item) { if (dba_valid(_DB_PREF_ . '_featurePhonebook', 'id', $item)) { if (dba_remove(_DB_PREF_ . '_featurePhonebook_group_contacts', array('pid' => $item)) or dba_isavail(_DB_PREF_ . '_featurePhonebook_group_contacts', array('pid' => $item))) { $data = array('pid' => $item, 'gpid' => $gpid); if (dba_add(_DB_PREF_ . '_featurePhonebook_group_contacts', $data)) { $_SESSION['dialog']['info'][] = _('Selected contact moved to new group'); } } } } } $search = themes_search_session(); $nav = themes_nav_session(); $ref = $search['url'] . '&search_keyword=' . $search['keyword'] . '&search_category=' . $search['category'] . '&page=' . $nav['page'] . '&nav=' . $nav['nav']; header("Location: " . _u($ref)); exit;