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; }
function sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid = 0, $sms_type = 'text', $unicode = 0) { global $core_config, $gateway_module; $user = user_getdatabyuid($uid); $username = $user['username']; $sms_to = sendsms_getvalidnumber($sms_to); $sms_to = sendsms_manipulate_prefix($sms_to, $user); // make sure sms_datetime is in supported format and in GMT+0 // timezone used for outgoing message is not module timezone, but default timezone // module gateway may have set already to +0000 (such kannel and clickatell) $sms_datetime = core_adjust_datetime($core_config['datetime']['now'], $core_config['main']['cfg_datetime_timezone']); // sent sms will be handled by plugin/tools/* first $ret_intercept = interceptsendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $gpid, $sms_type, $unicode); 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; } // if hooked function returns cancel=true then stop the sending, return false if ($ret_intercept['cancel']) { logger_print("cancelled:{$uid},{$gpid},{$gateway_module},{$sms_sender},{$sms_to},{$sms_type},{$unicode}", 3, "sendsms"); $ret['status'] = false; return $ret; } // fixme anton - mobile number can be anything, screened by gateway // $sms_sender = sendsms_getvalidnumber($sms_sender); $ok = false; logger_print("start", 3, "sendsms"); if (rate_cansend($username, $sms_to)) { // fixme anton - its a total mess ! need another DBA - we dont need this anymore //$sms_footer = addslashes(trim($sms_footer)); //$sms_msg = addslashes($sms_msg); // 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\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSOutgoing \n\t\t\t(uid,p_gpid,p_gateway,p_src,p_dst,p_footer,p_msg,p_datetime,p_sms_type,unicode) \n\t\t\tVALUES ('{$uid}','{$gpid}','{$gateway_module}','{$sms_sender}','{$sms_to}','{$sms_footer}','{$sms_msg}','{$sms_datetime}','{$sms_type}','{$unicode}')\n\t\t"; logger_print("saving:{$uid},{$gpid},{$gateway_module},{$sms_sender},{$sms_to},{$sms_type},{$unicode}", 3, "sendsms"); // continue to gateway only when save to db is true if ($smslog_id = @dba_insert_id($db_query)) { logger_print("smslog_id:" . $smslog_id . " saved", 3, "sendsms"); // fixme anton - another mess with slashes! also trim $sms_footer and prefix it with a space $sms_footer = ' ' . stripslashes(trim($sms_footer)); $sms_msg = stripslashes($sms_msg); if (x_hook($gateway_module, 'sendsms', array($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; } } } logger_print("end", 3, "sendsms"); $ret['status'] = $ok; $ret['smslog_id'] = $smslog_id; return $ret; }