Example #1
1
File: fn.php Project: pr4ka5a/telek
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');
                    }
                }
            }
        }
    }
}
Example #2
0
function telek_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver)
{
    //$ret = array();
    $ps = explode(" ", $message, 2);
    $ikut = strtoupper($ps[0]);
    //$pesan = '';
    $hooked = false;
    if ($ikut == 'DAFTAR') {
        $pecah = preg_split("/#/", $ps[1], null, PREG_SPLIT_NO_EMPTY);
        $c_uid = user_mobile2uid($sms_sender);
        $data = array();
        $data['name'] = trim($pecah[0]);
        $data['username'] = trim($pecah[1]);
        $data['mobile'] = $sms_sender;
        $data['email'] = $data['name'] . "@noreply.org";
        $data['parent_uid'] = 0;
        $data['status'] = 4;
    }
    if ($nama && $nohp && $pengguna) {
        logger_print("*******", 3, "telek");
        logger_print("sms_sender " . $sms_sender, 3, "telek");
        logger_print("message " . $message, 3, "telek");
        logger_print("new message " . $nama, 3, "telek");
        logger_print("sms target user" . $sms_receiver, 3, "telek");
        logger_print("*******", 3, "telek");
        if (($uid = user_mobile2uid($sms_sender)) && $nama) {
            _log("save in inbox u:" . $username . " uid:" . $uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $nohp . "]", 3, 'telek');
            //recvsms_inbox_add($sms_datetime, $sms_sender, $username, $nama, $sms_receiver);
            //$hooked = true;
            //$status = ($ok ? 'handled' : 'unhandled');
        }
    }
    ////	$ret['uid'] = user_mobile2uid($sms_sender);
    ////	$ret['status'] = TRUE;
    //	$ret['param']['message'] = $ikut . ' ' . $nama .' '. $nohp . ' ' . $pengguna;
    //       $ret['modified'] = TRUE;
    //        $ret['hooked'] = TRUE;
    $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;
        } else {
            logger_print('fail to add contact pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email . ' tags:[' . $tags . ']', 3, 'phonebook_add');
        }
    } else {
        echo "gagal";
    }
    return $ret;
}
Example #3
0
function recvsms_inbox_add($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver = "", $reference_id = '')
{
    global $core_config;
    // sms to inbox will be handled by plugins first
    $ret_intercept = recvsms_inbox_add_intercept($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver, $reference_id);
    if ($ret_intercept['param_modified']) {
        $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime;
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $target_user = $ret_intercept['param']['target_user'] ? $ret_intercept['param']['target_user'] : $target_user;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
        $reference_id = $ret_intercept['param']['reference_id'] ? $ret_intercept['param']['reference_id'] : $reference_id;
    }
    $ok = FALSE;
    if ($sms_sender && $target_user && $message) {
        $user = user_getdatabyusername($target_user);
        if ($uid = $user['uid']) {
            // discard if banned
            if (user_banned_get($uid)) {
                logger_print("user banned, message ignored uid:" . $uid, 2, "recvsms_inbox_add");
                return FALSE;
            }
            // get name from target_user's phonebook
            $c_name = '';
            if (substr($sms_sender, 0, 1) == '@') {
                $c_username = str_replace('@', '', $sms_sender);
                $c_name = user_getfieldbyusername($c_username, 'name');
            } else {
                $c_name = phonebook_number2name($uid, $sms_sender);
            }
            $sender = $c_name ? $c_name . ' (' . $sms_sender . ')' : $sms_sender;
            // forward to Inbox
            if ($fwd_to_inbox = $user['fwd_to_inbox']) {
                $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSInbox\n\t\t\t\t\t(in_sender,in_receiver,in_uid,in_msg,in_datetime,reference_id)\n\t\t\t\t\tVALUES ('{$sms_sender}','{$sms_receiver}','{$uid}','{$message}','" . core_adjust_datetime($sms_datetime) . "','{$reference_id}')\n\t\t\t\t";
                logger_print("saving sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user . " reference_id:" . $reference_id, 2, "recvsms_inbox_add");
                if ($inbox_id = @dba_insert_id($db_query)) {
                    logger_print("saved id:" . $inbox_id . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 2, "recvsms_inbox_add");
                    $ok = TRUE;
                }
            }
            // forward to email, consider site config too
            if ($parent_uid = user_getparentbyuid($uid)) {
                $site_config = site_config_get($parent_uid);
            }
            $web_title = $site_config['web_title'] ? $site_config['web_title'] : $core_config['main']['web_title'];
            $email_service = $site_config['email_service'] ? $site_config['email_service'] : $core_config['main']['email_service'];
            $email_footer = $site_config['email_footer'] ? $site_config['email_footer'] : $core_config['main']['email_footer'];
            $sms_receiver = $sms_receiver ? $sms_receiver : '-';
            if ($fwd_to_email = $user['fwd_to_email']) {
                if ($email = $user['email']) {
                    $subject = _('Message from') . " " . $sender;
                    $body = $web_title . "\n\n";
                    $body .= _('Message received at') . " " . $sms_receiver . " " . _('on') . " " . $sms_datetime . "\n\n";
                    $body .= _('From') . " " . $sender . "\n\n";
                    $body .= $message . "\n\n--\n";
                    $body .= $email_footer . "\n\n";
                    $body = stripslashes($body);
                    logger_print("send email from:" . $email_service . " to:" . $email . " message:[" . $message . "]", 3, "recvsms_inbox_add");
                    $data = array('mail_from_name' => $web_title, 'mail_from' => $email_service, 'mail_to' => $email, 'mail_subject' => $subject, 'mail_body' => $body);
                    sendmail($data);
                    logger_print("sent email from:" . $email_service . " to:" . $email, 3, "recvsms_inbox_add");
                }
            }
            // forward to mobile
            if ($fwd_to_mobile = $user['fwd_to_mobile']) {
                if ($mobile = $user['mobile']) {
                    // fixme anton
                    $c_message = $message . ' ' . $sender;
                    if ($sender_uid = user_mobile2uid($sms_sender)) {
                        if ($sender_username = user_uid2username($sender_uid)) {
                            $c_message = $message . ' ' . '@' . $sender_username;
                        }
                    }
                    $message = $c_message;
                    $unicode = core_detect_unicode($message);
                    $nofooter = TRUE;
                    logger_print("send to mobile:" . $mobile . " from:" . $sms_sender . " user:"******" message:" . $message, 3, "recvsms_inbox_add");
                    list($ok, $to, $smslog_id, $queue) = sendsms($target_user, $mobile, $message, 'text', $unicode, '', $nofooter);
                    if ($ok[0] == 1) {
                        logger_print("sent to mobile:" . $mobile . " from:" . $sms_sender . " user:"******"recvsms_inbox_add");
                    }
                }
            }
        }
    }
    return $ok;
}
Example #4
0
/**
 * Intercept on before-process stage for incoming SMS
 *
 * @param $sms_datetime incoming
 *        SMS date/time
 * @param $sms_sender incoming
 *        SMS sender
 * @param $message incoming
 *        SMS message before interepted
 * @param $sms_receiver receiver
 *        number that is receiving incoming SMS
 * @param $reference_id reference_id
 *        data
 * @return array $ret
 */
function incoming_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $reference_id)
{
    $ret = array();
    $found_bc = FALSE;
    $found_pv = FALSE;
    // continue only when keyword does not exists
    $m = explode(' ', $message);
    if (!keyword_isavail($m[0])) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $pre_rules = incoming_pre_rules_get();
    // scan for #<sender's phonebook group code> and @<username> according to pre rules
    $msg = explode(' ', $message);
    if (count($msg) > 0) {
        $bc = array();
        $pv = array();
        for ($i = 0; $i < count($msg); $i++) {
            $c_text = trim($msg[$i]);
            // scan message for @username
            if ($pre_rules['match_username']) {
                if (substr($c_text, 0, 1) === '@') {
                    $pv[] = strtolower(substr($c_text, 1));
                    $found_pv = TRUE;
                }
            }
            // scan message for #groupcode
            if ($pre_rules['match_groupcode']) {
                if (substr($c_text, 0, 1) === '#') {
                    $bc[] = strtoupper(substr($c_text, 1));
                    $found_bc = TRUE;
                }
            }
        }
    }
    if ($found_bc || $found_pv) {
        _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
    }
    if ($found_bc) {
        $groups = array_unique($bc);
        foreach ($groups as $key => $c_group_code) {
            $c_uid = user_mobile2uid($sms_sender);
            $list = phonebook_search_group($c_uid, $c_group_code, '', TRUE);
            $c_gpid = $list[0]['gpid'];
            if ($c_uid && $c_gpid) {
                $c_username = user_uid2username($c_uid);
                _log("bc g:" . phonebook_code_clean($c_group_code) . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                sendsms_bc($c_username, $c_gpid, $message);
                _log("bc end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    if ($found_pv) {
        $users = array_unique($pv);
        foreach ($users as $key => $c_username) {
            $c_username = core_sanitize_username($c_username);
            if ($c_uid = user_username2uid($c_username)) {
                _log("pv u:" . $c_username . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "] reference_id:" . $reference_id, 3, 'incoming recvsms_intercept');
                recvsms_inbox_add($sms_datetime, $sms_sender, $c_username, $message, $sms_receiver, $reference_id);
                _log("pv end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    return $ret;
}
Example #5
0
function user_mobile2username($mobile)
{
    if ($uid = user_mobile2uid($mobile)) {
        $username = user_uid2username($uid);
    }
    return $username;
}
Example #6
0
//defined('_SECURE_') or die('Forbidden');
/*
if(!auth_isvalid()){
auth_block();
}
*/
//echo "Halo duniahh";
switch (_OP_) {
    case "mulai":
        echo "Daftar dong ah";
        break;
    case "daftar":
        echo "mulai dong ah";
        break;
    case "gabung":
        echo "gabung dong ah";
        break;
}
$list = dba_search(_DB_PREF_ . '_featurePhonebook_group', 'id', array('uid' => 1, 'code' => 'IL'));
foreach ($list as $kkk) {
    foreach ($kkk as $key => $val) {
        echo $key . " => " . $val . "<br />";
    }
}
$mobile = '+628568218424';
$uid = user_mobile2uid('08568218424');
$list01 = dba_search(_DB_PREF_ . '_featurePhonebook', 'id', array('uid' => 1, 'mobile' => $mobile));
var_dump($list01[0]['id']);
logger_print($list[0]['id'], 4, 'test');
echo '<br />' . $mobile;
//empty
Example #7
0
function sms_subscribe_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver)
{
    $msg = explode(" ", $message);
    $bc = strtoupper($msg[0]);
    $keyword = '';
    $message = '';
    if ($bc == 'BC') {
        $keyword = strtoupper($msg[1]);
        for ($i = 2; $i < count($msg); $i++) {
            $message .= $msg[$i] . ' ';
        }
    } else {
        if (substr($bc, 0, 1) == '#') {
            $keyword = str_replace('#', '', $bc);
            for ($i = 1; $i < count($msg); $i++) {
                $message .= $msg[$i] . ' ';
            }
        }
    }
    $keyword = trim($keyword);
    $message = trim($message);
    $hooked = false;
    if ($keyword && $message) {
        _log("recvsms_intercept k:" . $keyword . " m:" . $message, 1, "sms_subscribe");
        // if not available then the keyword is exists
        if (!sms_subscribe_hook_keyword_isavail($keyword)) {
            $c_uid = user_mobile2uid($sms_sender);
            $c_username = user_uid2username($c_uid);
            if ($c_uid && $c_username) {
                $list = dba_search(_DB_PREF_ . '_featureSubscribe', 'subscribe_id, forward_param', array('uid' => $c_uid, 'subscribe_keyword' => $keyword));
                if ($list[0]['subscribe_id']) {
                    $forward_param = $list[0]['forward_param'] ? $list[0]['forward_param'] : 'BC';
                    $sms_datetime = core_display_datetime($sms_datetime);
                    _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " uid:" . $c_uid . " username:"******" bc:" . $bc . " keyword:" . $keyword . " message:" . $message . " fwd:" . $forward_param, 3, "sms_subscribe");
                    $hooked = true;
                }
            }
        }
    }
    $ret = array();
    if ($hooked) {
        $ret['modified'] = true;
        $ret['hooked'] = true;
        $ret['param']['message'] = $keyword . ' ' . $forward_param . ' ' . $message;
    }
    return $ret;
}
Example #8
0
/**
 * Intercept on before-process stage for incoming SMS
 *
 * @param $sms_datetime incoming
 *        	SMS date/time
 * @param $sms_sender incoming
 *        	SMS sender
 * @param $message incoming
 *        	SMS message before interepted
 * @param $sms_receiver receiver
 *        	number that is receiving incoming SMS
 * @param $reference_id reference_id
 *        	data
 * @return array $ret
 */
function incoming_hook_recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $reference_id)
{
    $ret = array();
    $found_bc = FALSE;
    $found_pv = FALSE;
    // continue only when keyword does not exists
    $m = explode(' ', $message);
    if (!checkavailablekeyword($m[0])) {
        return $ret;
    }
    // get settings
    $settings = incoming_settings_get();
    // get post rules
    $pre_rules = incoming_pre_rules_get();
    // scan for #<sender's phonebook group code> and @<username> according to pre rules
    $msg = explode(' ', $message);
    if (count($msg) > 0) {
        $bc = array();
        $pv = array();
        for ($i = 0; $i < count($msg); $i++) {
            $c_text = trim($msg[$i]);
            // scan message for @username
            if ($pre_rules['match_username']) {
                if (substr($c_text, 0, 1) === '@') {
                    $pv[] = strtolower(substr($c_text, 1));
                    $found_pv = TRUE;
                }
            }
            // scan message for #groupcode
            if ($pre_rules['match_groupcode']) {
                if (substr($c_text, 0, 1) === '#') {
                    $bc[] = strtoupper(substr($c_text, 1));
                    $found_bc = TRUE;
                }
            }
        }
    }
    if ($found_bc || $found_pv) {
        _log("recvsms_intercept dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
    }
    if ($found_bc) {
        $groups = array_unique($bc);
        foreach ($groups as $key => $c_group_code) {
            $c_group_code = strtoupper($c_group_code);
            $c_group_code = core_sanitize_alphanumeric($c_group_code);
            $c_uid = user_mobile2uid($sms_sender);
            if ($c_uid && ($c_gpid = phonebook_groupcode2id($c_uid, $c_group_code))) {
                $c_username = user_uid2username($c_uid);
                _log("bc g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                sendsms_bc($c_username, $c_gpid, $message);
                _log("bc end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            } else {
                // check the group_code for flag_sender<>0
                $db_query = "SELECT id,uid,flag_sender FROM " . _DB_PREF_ . "_featurePhonebook_group WHERE code='{$c_group_code}' AND flag_sender<>0";
                $db_result = dba_query($db_query);
                if ($db_row = dba_fetch_array($db_result)) {
                    $c_gpid = $db_row['id'];
                    $c_uid = $db_row['uid'];
                    $c_flag_sender = $db_row['flag_sender'];
                    if ($c_flag_sender == 2) {
                        $c_username = user_uid2username($c_uid);
                        _log("bc mobile flag_sender:" . $c_flag_sender . " username:"******" uid:" . $c_uid . " g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                        $sender = trim(phonebook_number2name($sms_sender, $c_username));
                        $sender = $sender ? $sender : $sms_sender;
                        sendsms_bc($c_username, $c_gpid, $sender . ":" . $message);
                        _log("bc mobile end", 3, 'incoming recvsms_intercept');
                        $ret['uid'] = $c_uid;
                        $ret['hooked'] = true;
                    } else {
                        if ($c_flag_sender == 1) {
                            // check whether sms_sender belongs to c_group_code
                            $db_query = "SELECT B.id AS id FROM " . _DB_PREF_ . "_featurePhonebook AS A\n\t\t\t\t\t\t\t\tLEFT JOIN playsms.playsms_featurePhonebook_group_contacts AS C ON A.id=C.pid\n\t\t\t\t\t\t\t\tLEFT JOIN playsms.playsms_featurePhonebook_group AS B ON B.id=C.gpid\n\t\t\t\t\t\t\t\tWHERE A.mobile LIKE '%" . substr($sms_sender, 3) . "' AND B.code='" . $c_group_code . "'";
                            $db_result = dba_query($db_query);
                            if ($db_row = dba_fetch_array($db_result)) {
                                $c_username = user_uid2username($c_uid);
                                _log("bc mobile flag_sender:" . $c_flag_sender . " username:"******" uid:" . $c_uid . " g:" . $c_group_code . " gpid:" . $c_gpid . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:" . $message, 3, 'incoming recvsms_intercept');
                                $sender = trim(phonebook_number2name($sms_sender, $c_username));
                                $sender = $sender ? $sender : $sms_sender;
                                sendsms_bc($c_username, $c_gpid, $sender . ":" . $message);
                                _log("bc mobile end", 3, 'incoming recvsms_intercept');
                                $ret['uid'] = $c_uid;
                                $ret['hooked'] = true;
                            }
                        }
                    }
                }
            }
        }
    }
    if ($found_pv) {
        $users = array_unique($pv);
        foreach ($users as $key => $c_username) {
            $c_username = core_sanitize_username($c_username);
            if ($c_uid = user_username2uid($c_username)) {
                _log("pv u:" . $c_username . " uid:" . $c_uid . " dt:" . $sms_datetime . " s:" . $sms_sender . " r:" . $sms_receiver . " m:[" . $message . "] reference_id:" . $reference_id, 3, 'incoming recvsms_intercept');
                recvsms_inbox_add($sms_datetime, $sms_sender, $c_username, $message, $sms_receiver, $reference_id);
                _log("pv end", 3, 'incoming recvsms_intercept');
                $ret['uid'] = $c_uid;
                $ret['hooked'] = true;
            }
        }
    }
    return $ret;
}