Beispiel #1
0
function webservices_bc($c_username, $c_gcode, $msg, $type = 'text', $unicode = 0)
{
    if (($c_uid = username2uid($c_username)) && $c_gcode && $msg) {
        $c_gpid = phonebook_groupcode2id($c_uid, $c_gcode);
        // sendsms_bc($c_username,$c_gpid,$message,$sms_type='text',$unicode=0)
        list($ok, $to, $smslog_id) = sendsms_bc($c_username, $c_gpid, $msg, $type, $unicode);
        if ($ok[0]) {
            $ret = "OK";
        } else {
            $ret = "ERR 300";
        }
    } else {
        $ret = "ERR 301";
    }
    return $ret;
}
Beispiel #2
0
     // New function introduce for long sms count and another field (SMS character) added to send sms broadcast
     if ($errid) {
         $err = logger_get_error_string($errid);
     }
     if ($err) {
         $content = "<div class=error_string>{$err}</div>";
     }
     $content .= "\n\t    <form name=\"fm_smstemplate\">\n\t    {$input_values}\n\t    </form>\n\n\t    <h2>" . _('Send broadcast SMS') . "</h2>\n\t    <p>\n\t    <form name=fm_sendsms id=fm_sendsms action=index.php?app=menu&inc=send_sms&op=sendsmstogr_yes method=POST>\n\t    <p>" . _('SMS Sender ID') . ": {$sms_from}\n\t    <p>" . _('SMS footer') . ": {$sms_footer} \n\t    <p>\n\t    <p>" . _('Send to group') . ": <select name=\"gpid\">{$list_of_group}</select>\n\t    <p>" . _('Or') . ": <input type=text size=20 maxlength=20 name=gp_code_text value=\"{$dst_gp_code}\"> (" . _('Group code') . ")\n\t    <p>" . _('Message template') . ": <select name=\"smstemplate\">{$option_values}</select>\n\t    <p><input type=\"button\" onClick=\"SetSmsTemplate();\" name=\"nb\" value=\"" . _('Use template') . "\" class=\"button\">\n\t    <p>" . _('Your message') . ":\n\t    <br><textarea cols=\"39\" rows=\"5\" onKeyUp=\"SmsSetCounter();\" onClick=\"SmsSetCounter();\" onblur=\"SmsSetCounter();\" onkeypress=\"SmsSetCounter();\" onKeyUp=\"SmsCountKeyUp({$max_length});\" onKeyDown=\"SmsCountKeyDown({$max_length});\" name=\"message\" id=\"ta_sms_content\">{$message}</textarea>\n\t    <br>" . _('SMS character') . ": <input type=\"text\"  style=\"font-weight:bold;\" name=\"txtcount\" value=\"0 char : 0 SMS\" size=\"17\" onFocus=\"document.frmSendSms.message.focus();\" readonly>\n            <input type=\"hidden\" value=\"153\" name=\"hiddcount\">\n\t    <p><input type=checkbox name=msg_flash> " . _('Send as flash message') . "\n\t    <p><input type=checkbox name=msg_unicode> " . _('Send as unicode message (http://www.unicode.org)') . "\n\t    <p><input type=submit class=button value='" . _('Send') . "' onClick=\"selectAllOptions(this.form[gp_code[]])\"> \n\t    </form>\n\t";
     echo $content;
     break;
 case "sendsmstogr_yes":
     $gpid = $_POST['gpid'];
     $gp_code = $_POST['gp_code_text'];
     if ($gp_code) {
         $uid = username2uid($username);
         $gpid = phonebook_groupcode2id($uid, $gp_code);
     }
     /*
     if (!$gpid[0]) {
     $gpid = $_POST['gpid_text'];
     }
     */
     $msg_flash = $_POST['msg_flash'];
     $msg_unicode = $_POST['msg_unicode'];
     $message = $_POST['message'];
     if ($gpid && $message) {
         $sms_type = "text";
         if ($msg_flash == "on") {
             $sms_type = "flash";
         }
         $unicode = "0";
Beispiel #3
0
/**
 * Send SMS helper
 *
 * @global array $core_config, $user_config
 * @param string $username        	
 * @param mixed $sms_to        	
 * @param string $message        	
 * @param string $sms_type        	
 * @param integer $unicode        	
 * @param string $smsc        	
 * @param boolean $nofooter        	
 * @param string $sms_footer        	
 * @param string $sms_sender        	
 * @param string $sms_schedule        	
 * @param string $reference_id        	
 * @return array array($status, $sms_to, $smslog_id, $queue, $counts, $sms_count, $sms_failed)
 */
function sendsms_helper($username, $sms_to, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '', $reference_id = '')
{
    global $core_config, $user_config;
    // get user data
    if ($username && $user_config['username'] != $username) {
        $user_config = user_getdatabyusername($username);
    }
    if (!is_array($sms_to)) {
        $sms_to = explode(',', $sms_to);
    }
    // get destinations
    for ($i = 0; $i < count($sms_to); $i++) {
        if (substr(trim($sms_to[$i]), 0, 1) == '#') {
            if ($c_group_code = substr(trim($sms_to[$i]), 1)) {
                $c_gpid = phonebook_groupcode2id($user_config['uid'], $c_group_code);
                $members = phonebook_getdatabyid($c_gpid);
                foreach ($members as $member) {
                    if (trim($member['p_num'])) {
                        $array_sms_to[] = trim($member['p_num']);
                    }
                }
            }
        } else {
            if (substr(trim($sms_to[$i]), 0, 1) == '@') {
                if ($c_username = substr(trim($sms_to[$i]), 1)) {
                    // reference self will be ignored
                    if ($c_username != $user_config['username']) {
                        $array_username[] = $c_username;
                    }
                }
            } else {
                $array_sms_to[] = trim($sms_to[$i]);
            }
        }
    }
    // remove duplicates destinations
    array_unique($array_sms_to);
    $sms_queued = 0;
    $sms_failed = 0;
    // sendsms
    if (is_array($array_sms_to) && $array_sms_to[0]) {
        list($ok, $to, $smslog_id, $queue, $counts) = sendsms($user_config['username'], $array_sms_to, $message, $sms_type, $unicode, $smsc, $nofooter, $sms_footer, $sms_sender, $sms_schedule);
    }
    // fixme anton - IMs doesn't count
    // count SMSes only
    for ($i = 0; $i < count($ok); $i++) {
        if ($ok[$i]) {
            $sms_count += $counts[$i];
        } else {
            $sms_failed += $counts[$i];
        }
    }
    // sendsms_im
    if (is_array($array_username) && $array_username[0]) {
        $im_sender = '@' . $user_config['username'];
        foreach ($array_username as $target_user) {
            $im_sender = '@' . $user_config['username'];
            if (recvsms_inbox_add(core_get_datetime(), $im_sender, $target_user, $message, '', $reference_id)) {
                $ok[] = '1';
                $to[] = '@' . $target_user;
                $queue[] = md5($target_user . microtime());
                $sms_count++;
            }
        }
    }
    return array($ok, $to, $smslog_id, $queue, $counts, $sms_count, $sms_failed);
}
Beispiel #4
0
function setsmsincomingaction($sms_datetime, $sms_sender, $message, $sms_receiver = "")
{
    global $gateway_module, $core_config;
    // make sure sms_datetime is in supported format and in GMT+0
    $sms_datetime = core_adjust_datetime($sms_datetime);
    // incoming sms will be handled by plugin/tools/* first
    $ret_intercept = interceptincomingsms($sms_datetime, $sms_sender, $message, $sms_receiver);
    if ($ret_intercept['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;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
    }
    // if hooked function returns cancel=true then stop the processing incoming sms, return false
    if ($ret_intercept['cancel']) {
        logger_print("cancelled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        return false;
    }
    $c_uid = 0;
    $c_feature = "";
    $ok = false;
    $array_target_keyword = explode(" ", $message);
    $target_keyword = strtoupper(trim($array_target_keyword[0]));
    $message_full = $message;
    $message = $array_target_keyword[1];
    for ($i = 2; $i < count($array_target_keyword); $i++) {
        $message .= " " . $array_target_keyword[$i];
    }
    switch ($target_keyword) {
        case "BC":
            $c_uid = mobile2uid($sms_sender);
            $c_username = uid2username($c_uid);
            $c_feature = 'core';
            $array_target_group = explode(" ", $message);
            $target_group = strtoupper(trim($array_target_group[0]));
            $c_gpid = phonebook_groupcode2id($c_uid, $target_group);
            $message = $array_target_group[1];
            for ($i = 2; $i < count($array_target_group); $i++) {
                $message .= " " . $array_target_group[$i];
            }
            logger_print("username:"******" gpid:" . $c_gpid . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction bc");
            list($ok, $to, $queue) = sendsms_bc($c_username, $c_gpid, $message);
            $ok = true;
            break;
        case "PV":
            $c_feature = 'core';
            $array_target_user = explode(" ", $message);
            $target_user = strtoupper(trim($array_target_user[0]));
            $c_uid = username2uid($target_user);
            $message = $array_target_user[1];
            for ($i = 2; $i < count($array_target_user); $i++) {
                $message .= " " . $array_target_user[$i];
            }
            logger_print("datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user . " message:" . $message, 3, "setsmsincomingaction pv");
            if (insertsmstoinbox($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver)) {
                $ok = true;
            }
            break;
        default:
            for ($c = 0; $c < count($core_config['featurelist']); $c++) {
                $c_feature = $core_config['featurelist'][$c];
                $ret = x_hook($c_feature, 'setsmsincomingaction', array($sms_datetime, $sms_sender, $target_keyword, $message, $sms_receiver));
                if ($ok = $ret['status']) {
                    $c_uid = $ret['uid'];
                    logger_print("feature:" . $c_feature . " datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " keyword:" . $target_keyword . " message:" . $message, 3, "setsmsincomingaction");
                    break;
                }
            }
    }
    $c_status = $ok ? 1 : 0;
    if ($c_status == 0) {
        $c_feature = '';
        $target_keyword = '';
        $message = $message_full;
        // from interceptincomingsms(), force status as 'handled'
        if ($ret_intercept['hooked']) {
            $c_status = 1;
            logger_print("intercepted datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        } else {
            logger_print("unhandled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        }
    }
    $db_query = "\n        INSERT INTO " . _DB_PREF_ . "_tblSMSIncoming \n        (in_uid,in_feature,in_gateway,in_sender,in_receiver,in_keyword,in_message,in_datetime,in_status)\n        VALUES\n        ('{$c_uid}','{$c_feature}','{$gateway_module}','{$sms_sender}','{$sms_receiver}','{$target_keyword}','{$message}','{$sms_datetime}','{$c_status}')\n    ";
    $db_result = dba_query($db_query);
    return $ok;
}
Beispiel #5
0
function setsmsincomingaction($sms_datetime, $sms_sender, $message, $sms_receiver = '', $smsc = '')
{
    global $core_config;
    // incoming sms will be handled by plugins first
    $ret_intercept = recvsms_intercept($sms_datetime, $sms_sender, $message, $sms_receiver, $smsc);
    if ($ret_intercept['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;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
        $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc;
    }
    // set active gateway module as default gateway
    // if (!$smsc) {
    // $smsc = core_smsc_get();
    // }
    // log it
    logger_print("dt:" . $sms_datetime . " sender:" . $sms_sender . " m:" . $message . " receiver:" . $sms_receiver . ' smsc:' . $smsc, 3, "setsmsincomingaction");
    // if hooked function returns cancel=true then stop the processing incoming sms, return false
    if ($ret_intercept['cancel']) {
        logger_print("cancelled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        return false;
    }
    $c_uid = 0;
    $c_feature = "";
    $ok = false;
    $array_target_keyword = explode(" ", $message);
    $target_keyword = strtoupper(trim($array_target_keyword[0]));
    $raw_message = $message;
    $message = $array_target_keyword[1];
    for ($i = 2; $i < count($array_target_keyword); $i++) {
        $message .= " " . $array_target_keyword[$i];
    }
    switch ($target_keyword) {
        case "BC":
            $c_uid = user_mobile2uid($sms_sender);
            $c_username = user_uid2username($c_uid);
            $c_feature = 'core';
            $array_target_group = explode(" ", $message);
            $target_group = strtoupper(trim($array_target_group[0]));
            $c_gpid = phonebook_groupcode2id($c_uid, $target_group);
            $message = $array_target_group[1];
            for ($i = 2; $i < count($array_target_group); $i++) {
                $message .= " " . $array_target_group[$i];
            }
            logger_print("username:"******" gpid:" . $c_gpid . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message . " raw:" . $raw_message, 3, "setsmsincomingaction bc");
            list($ok, $to, $smslog_id, $queue) = sendsms_bc($c_username, $c_gpid, $message);
            $ok = true;
            break;
        default:
            for ($c = 0; $c < count($core_config['featurelist']); $c++) {
                $c_feature = $core_config['featurelist'][$c];
                $ret = core_hook($c_feature, 'setsmsincomingaction', array($sms_datetime, $sms_sender, $target_keyword, $message, $sms_receiver, $smsc, $raw_message));
                if ($ok = $ret['status']) {
                    $c_uid = $ret['uid'];
                    logger_print("feature:" . $c_feature . " datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " keyword:" . $target_keyword . " message:" . $message . " raw:" . $raw_message . " smsc:" . $smsc, 3, "setsmsincomingaction");
                    break;
                }
            }
    }
    $c_status = $ok ? 1 : 0;
    if ($c_status == 0) {
        $c_feature = '';
        $target_keyword = '';
        $message = $raw_message;
        // from recvsms_intercept(), force status as 'handled'
        if ($ret_intercept['hooked']) {
            $c_status = 1;
            if ($ret_intercept['uid']) {
                $c_uid = $ret_intercept['uid'];
            }
            logger_print("intercepted datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        } else {
            logger_print("unhandled datetime:" . $sms_datetime . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " message:" . $message, 3, "setsmsincomingaction");
        }
    }
    // incoming sms intercept after
    unset($ret_intercept);
    $ret_intercept = recvsms_intercept_after($sms_datetime, $sms_sender, $message, $sms_receiver, $c_feature, $c_status, $c_uid, $smsc);
    if ($ret_intercept['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;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
        $c_feature = $ret_intercept['param']['feature'] ? $ret_intercept['param']['feature'] : $c_feature;
        $c_status = $ret_intercept['param']['status'] ? $ret_intercept['param']['status'] : $c_status;
        $c_uid = $ret_intercept['param']['uid'] ? $ret_intercept['param']['uid'] : $c_uid;
        $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc;
    }
    // fixme anton - all incoming messages set to user with uid=1 if no one owns it
    $c_uid = $c_uid ? $c_uid : 1;
    $db_query = "\n\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSIncoming \n\t\t(in_uid,in_feature,in_gateway,in_sender,in_receiver,in_keyword,in_message,in_datetime,in_status)\n\t\tVALUES\n\t\t('{$c_uid}','{$c_feature}','{$smsc}','{$sms_sender}','{$sms_receiver}','{$target_keyword}','{$message}','" . core_adjust_datetime($sms_datetime) . "','{$c_status}')";
    $db_result = dba_query($db_query);
    return $ok;
}
Beispiel #6
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;
}