Пример #1
0
function getsmsstatus()
{
    $smsc = core_smsc_get();
    $smsc_data = gateway_get_smscbyname($smsc);
    $gateway = $smsc_data['gateway'];
    $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='0' AND p_gateway='{$smsc}'";
    $db_result = dba_query($db_query);
    while ($db_row = dba_fetch_array($db_result)) {
        $uid = $db_row['uid'];
        $smslog_id = $db_row['smslog_id'];
        $p_datetime = $db_row['p_datetime'];
        $p_update = $db_row['p_update'];
        $gpid = $db_row['p_gpid'];
        core_hook($gateway, 'getsmsstatus', array($gpid, $uid, $smslog_id, $p_datetime, $p_update));
    }
}
Пример #2
0
function sendsms_process($smslog_id, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid = 0, $sms_type = 'text', $unicode = 0, $queue_code = '', $smsc = '')
{
    global $user_config;
    $ok = false;
    $user = $user_config;
    if ($uid && $user['uid'] != $uid) {
        $user = user_getdatabyuid($uid);
    }
    $username = $user['username'];
    $sms_to = sendsms_getvalidnumber($sms_to);
    // now on sendsms()
    // $sms_to = sendsms_manipulate_prefix($sms_to, $user);
    $sms_datetime = core_get_datetime();
    // sent sms will be handled by plugins first
    $ret_intercept = sendsms_intercept($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode, $smsc);
    if ($ret_intercept['modified']) {
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $sms_footer = $ret_intercept['param']['sms_footer'] ? $ret_intercept['param']['sms_footer'] : $sms_footer;
        $sms_to = $ret_intercept['param']['sms_to'] ? $ret_intercept['param']['sms_to'] : $sms_to;
        $sms_msg = $ret_intercept['param']['sms_msg'] ? $ret_intercept['param']['sms_msg'] : $sms_msg;
        $uid = $ret_intercept['param']['uid'] ? $ret_intercept['param']['uid'] : $uid;
        $gpid = $ret_intercept['param']['gpid'] ? $ret_intercept['param']['gpid'] : $gpid;
        $sms_type = $ret_intercept['param']['sms_type'] ? $ret_intercept['param']['sms_type'] : $sms_type;
        $unicode = $ret_intercept['param']['unicode'] ? $ret_intercept['param']['unicode'] : $unicode;
        $smsc = $ret_intercept['param']['smsc'] ? $ret_intercept['param']['smsc'] : $smsc;
    }
    // if hooked function returns cancel=true then stop the sending, return false
    if ($ret_intercept['cancel']) {
        logger_print("end with cancelled smslog_id:" . $smslog_id . " uid:" . $uid . " gpid:" . $gpid . " smsc:" . $smsc . " s:" . $sms_sender . " to:" . $sms_to . " type:" . $sms_type . " unicode:" . $unicode, 2, "sendsms_process");
        $ret['status'] = false;
        return $ret;
    }
    // get active gateway module as default gateway
    if (!$smsc) {
        $smsc = core_smsc_get();
    }
    // set no gateway if no default gateway selected
    if (!$smsc) {
        $smsc = 'blocked';
    }
    // a hack to remove \r from \r\n
    // the issue begins with ENTER being \r\n and detected as 2 chars
    // and since the javascript message counter can't detect it as 2 chars
    // thus the message length counts is inaccurate
    $sms_msg = str_replace("\r\n", "\n", $sms_msg);
    // just to make sure its length, we need to stripslashes message before enter other procedures
    $sms_sender = stripslashes($sms_sender);
    $sms_msg = stripslashes($sms_msg);
    $sms_footer = stripslashes($sms_footer);
    // fixme anton - mobile number can be anything, screened by gateway
    // $sms_sender = sendsms_getvalidnumber($sms_sender);
    // fixme anton - add a space in front of $sms_footer
    if (trim($sms_footer)) {
        $sms_footer = ' ' . trim($sms_footer);
    }
    logger_print("start", 2, "sendsms_process");
    if (rate_cansend($username, strlen($sms_msg . $sms_footer), $unicode, $sms_to)) {
        $p_status = 0;
    } else {
        logger_print("end with fail not enough credit smslog_id:" . $smslog_id, 2, "sendsms_process");
        $ret['status'] = true;
        // set TRUE to stop queue
        $ret['to'] = $sms_to;
        $ret['smslog_id'] = $smslog_id;
        $ret['p_status'] = 2;
        // set failed
        return $ret;
    }
    // message entering this proc already stripslashed, we need to addslashes it before saving to db
    $sms_sender = addslashes($sms_sender);
    $sms_msg = addslashes($sms_msg);
    $sms_footer = addslashes($sms_footer);
    // we save all info first and then process with gateway module
    // the thing about this is that message saved may not be the same since gateway may not be able to process
    // message with that length or certain characters in the message are not supported by the gateway
    $db_query = "\n\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSOutgoing \n\t\t(smslog_id,uid,p_gpid,p_gateway,p_src,p_dst,p_footer,p_msg,p_datetime,p_status,p_sms_type,unicode,queue_code) \n\t\tVALUES ('{$smslog_id}','{$uid}','{$gpid}','{$smsc}','{$sms_sender}','{$sms_to}','{$sms_footer}','{$sms_msg}','{$sms_datetime}','{$p_status}','{$sms_type}','{$unicode}','{$queue_code}')";
    logger_print("saving smslog_id:" . $smslog_id . " u:" . $uid . " g:" . $gpid . " smsc:" . $smsc . " s:" . $sms_sender . " d:" . $sms_to . " type:" . $sms_type . " unicode:" . $unicode . " status:" . $p_status, 2, "sendsms");
    // continue to gateway only when save to db is true
    if ($id = @dba_insert_id($db_query)) {
        logger_print("saved smslog_id:" . $smslog_id . " id:" . $id, 2, "sendsms_process");
        if ($p_status == 0) {
            $smsc = gateway_get_smscbyname($smsc);
            logger_print("final smslog_id:" . $smslog_id . " gw:" . $smsc['gateway'] . " smsc:" . $smsc['name'] . " message:" . $sms_msg . $sms_footer . " len:" . strlen($sms_msg . $sms_footer), 3, "sendsms");
            if (core_hook($smsc['gateway'], 'sendsms', array($smsc['name'], $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $smslog_id, $sms_type, $unicode))) {
                // fixme anton - deduct user's credit as soon as gateway returns true
                rate_deduct($smslog_id);
                $ok = true;
            } else {
                logger_print("fail no hook for sendsms", 2, "sendsms_process");
            }
        }
    } else {
        logger_print("fail to save in db table smslog_id:" . $smslog_id, 2, "sendsms_process");
    }
    logger_print("end", 2, "sendsms_process");
    $ret['status'] = $ok;
    $ret['to'] = $sms_to;
    $ret['smslog_id'] = $smslog_id;
    $ret['p_status'] = $p_status;
    return $ret;
}
Пример #3
0
/**
 * Get default gateway based on default SMSC
 *
 * @global array $core_config
 * @return string
 */
function core_gateway_get()
{
    global $core_config;
    $ret = core_call_hook();
    if (!$ret) {
        $smsc = core_smsc_get();
        $smsc_data = gateway_get_smscbyname($smsc);
        $gateway = $smsc_data['gateway'];
        return $gateway;
    }
    return $ret;
}
Пример #4
0
function getsmsinbox()
{
    $smsc = core_smsc_get();
    $smsc_data = gateway_get_smscbyname($smsc);
    $gateway = $smsc_data['gateway'];
    core_hook($gateway, 'getsmsinbox');
}