コード例 #1
0
ファイル: fn.php プロジェクト: 10corp/playSMS
/**
 * hook_sendsms called by sendsms_process()
 *
 * @param string $smsc
 *        SMSC name
 * @param unknown $sms_sender
 *        Sender ID
 * @param string $sms_footer
 *        Message footer
 * @param string $sms_to
 *        Destination number
 * @param string $sms_msg
 *        Message
 * @param integer $uid
 *        User ID
 * @param integer $gpid
 *        Group ID
 * @param integer $smslog_id
 *        SMS Log ID
 * @param integer $sms_type
 *        Type of SMS
 * @param integer $unicode
 *        Unicode flag
 * @return boolean
 */
function uplink_hook_sendsms($smsc, $sms_sender, $sms_footer, $sms_to, $sms_msg, $uid = '', $gpid = 0, $smslog_id = 0, $sms_type = 'text', $unicode = 0)
{
    // global $plugin_config; // global all variables needed, eg: varibles from config.php
    // ...
    // ...
    // return true or false
    // return $ok;
    global $plugin_config;
    _log("enter smsc:" . $smsc . " smslog_id:" . $smslog_id . " uid:" . $uid . " to:" . $sms_to, 3, "uplink_hook_sendsms");
    // override plugin gateway configuration by smsc configuration
    $plugin_config = gateway_apply_smsc_config($smsc, $plugin_config);
    $sms_sender = stripslashes($sms_sender);
    if ($plugin_config['uplink']['module_sender']) {
        $sms_sender = $plugin_config['uplink']['module_sender'];
    }
    $sms_footer = $sms_footer ? $sms_footer : stripslashes($sms_footer);
    $sms_msg = stripslashes($sms_msg) . $sms_footer;
    $ok = FALSE;
    if ($sms_to && $sms_msg) {
        $unicode = trim($unicode) ? 1 : 0;
        $nofooter = $plugin_config['uplink']['try_disable_footer'] ? 1 : 0;
        $ws = new Playsms\Webservices();
        $ws->url = $plugin_config['uplink']['master'] . '/index.php?app=ws';
        $ws->username = $plugin_config['uplink']['username'];
        $ws->token = $plugin_config['uplink']['token'];
        $ws->to = $sms_to;
        $ws->from = $sms_sender;
        $ws->msg = $sms_msg;
        $ws->unicode = $unicode;
        $ws->nofooter = $nofooter;
        $ws->sendSms();
        _log('sendsms url:[' . $ws->getWebservicesUrl() . '] smsc:[' . $smsc . ']', 3, 'uplink_hook_sendsms');
        // in playsms-webservices 1.0.5 and above the data returns as an array, unless a failed response
        $response = $ws->getData();
        if (is_array($response->data)) {
            $data = $response->data[0];
        } else {
            $data = $response;
        }
        //_log('data:[' . print_r($data, 1) . ']', 3, 'uplink_hook_sendsms');
        if ($data->status == 'OK') {
            if ($data->smslog_id || $data->queue) {
                $db_query = "\n\t\t\t\tINSERT INTO " . _DB_PREF_ . "_gatewayUplink (up_local_smslog_id,up_remote_smslog_id,up_status,up_remote_queue_code,up_dst)\n\t\t\t\tVALUES ('{$smslog_id}','" . $data->smslog_id . "','0','" . $data->queue . "','{$sms_to}')";
                if ($up_id = @dba_insert_id($db_query)) {
                    $ok = TRUE;
                    _log('sendsms success. smslog_id:' . $smslog_id . ' remote_smslog_id:' . $data->smslog_id . ' remote_queue:' . $data->queue, 3, 'uplink_hook_sendsms');
                } else {
                    $ok = TRUE;
                    $p_status = 1;
                    // sent
                    dlr($smslog_id, $uid, $p_status);
                    _log('sendsms success but unable to save data', 3, 'uplink_hook_sendsms');
                    return $ok;
                }
            } else {
                _log('sendsms failed no smslog_id or queue', 3, 'uplink_hook_sendsms');
            }
        } else {
            _log('sendsms failed. error:' . $ws->getError() . ' error_string:' . $ws->getErrorString(), 3, 'uplink_hook_sendsms');
        }
    }
    if ($ok && ($data->smslog_id || $data->queue)) {
        $p_status = 0;
        // pending
    } else {
        $p_status = 2;
        // failed
    }
    dlr($smslog_id, $uid, $p_status);
    return $ok;
}