} } // additional user's config available on registry $data = registry_search($c_uid, 'core', 'user_config'); // credit unicodes messages as single message $option_enable_credit_unicode = _options(array(_('yes') => 1, _('no') => 0), $data['core']['user_config']['enable_credit_unicode']); if (auth_isadmin()) { $option_enable_credit_unicode = "<select name='edit_enable_credit_unicode'>" . $option_enable_credit_unicode . "</select>"; } else { $option_enable_credit_unicode = $user_config['opt']['enable_credit_unicode'] ? _('yes') : _('no'); } // error string if ($err = TRUE) { $error_content = _dialog(); } $tpl = array('name' => 'user_config', 'vars' => array('Application options' => _('Application options'), 'Username' => _('Username'), 'Access Control List' => _('Access Control List'), 'Effective SMS sender ID' => _('Effective SMS sender ID'), 'Default sender ID' => _('Default sender ID'), 'Default message footer' => _('Default message footer'), 'Webservices username' => _('Webservices username'), 'Webservices token' => _('Webservices token'), 'Renew webservices token' => _('Renew webservices token'), 'Enable webservices' => _('Enable webservices'), 'Webservices IP range' => _('Webservices IP range'), 'Active language' => _('Active language'), 'Timezone' => _('Timezone'), 'Credit' => _('Credit'), 'Enable credit unicode SMS as normal SMS' => _('Enable credit unicode SMS as normal SMS'), 'Forward message to inbox' => _('Forward message to inbox'), 'Forward message to email' => _('Forward message to email'), 'Forward message to mobile' => _('Forward message to mobile'), 'Local number length' => _('Local number length'), 'Prefix or country code' => _('Prefix or country code'), 'Always choose to send as unicode' => _('Always choose to send as unicode'), 'Save' => _('Save'), 'DIALOG_DISPLAY' => $error_content, 'FORM_TITLE' => $form_title, 'BUTTON_DELETE' => $button_delete, 'BUTTON_BACK' => $button_back, 'URL_UNAME' => $url_uname, 'VIEW' => $view, 'HINT_MAX_CHARS' => _hint(_('Max. 16 numeric or 11 alphanumeric characters')), 'HINT_MAX_ALPHANUMERIC' => _hint(_('Max. 30 alphanumeric characters')), 'HINT_COMMA_SEPARATED' => _hint(_('Comma separated')), 'HINT_TIMEZONE' => _hint(_('Eg: +0700 for Jakarta/Bangkok timezone')), 'HINT_LOCAL_LENGTH' => _hint(_('Min length to detect missing country code')), 'HINT_REPLACE_ZERO' => _hint(_('Replace prefix 0 or padding local numbers')), 'HINT_MANAGE_CREDIT' => _hint(_('Add or reduce credit from manage credit menu')), 'HINT_ACL' => _hint(_('ACL DEFAULT will not restrict access to menus')), 'option_new_token' => $option_new_token, 'option_enable_webservices' => $option_enable_webservices, 'option_language_module' => $option_language_module, 'option_fwd_to_inbox' => $option_fwd_to_inbox, 'option_fwd_to_email' => $option_fwd_to_email, 'option_fwd_to_mobile' => $option_fwd_to_mobile, 'option_acl' => $option_acl, 'option_sender_id' => $option_sender_id, 'c_username' => $c_username, 'effective_sender_id' => sendsms_get_sender($c_username), 'sender' => $sender, 'footer' => $footer, 'token' => $token, 'webservices_ip' => $webservices_ip, 'datetime_timezone' => $datetime_timezone, 'local_length' => $local_length, 'replace_zero' => $replace_zero, 'credit' => $credit, 'option_enable_credit_unicode' => $option_enable_credit_unicode)); _p(tpl_apply($tpl)); break; case "user_config_save": $fields = array('footer', 'datetime_timezone', 'language_module', 'fwd_to_inbox', 'fwd_to_email', 'fwd_to_mobile', 'local_length', 'replace_zero', 'new_token', 'enable_webservices', 'webservices_ip', 'sender', 'acl_id'); $up = array(); foreach ($fields as $field) { if (strlen($_POST['up_' . $field])) { $up[$field] = trim($_POST['up_' . $field]); } } $ret = user_edit_conf($c_uid, $up); $items['enable_credit_unicode'] = (int) $_POST['edit_enable_credit_unicode']; registry_update($c_uid, 'core', 'user_config', $items); $_SESSION['dialog']['info'][] = $ret['error_string']; _log('saving username:'******' error_string:[' . $ret['error_string'] . ']', 2, 'user_config');
case "sendsmstogr": $message = $_REQUEST['message']; $rows = phonebook_getgroupbyuid($uid, "gp_name"); foreach ($rows as $key => $db_row) { $c_count = phonebook_getmembercountbyid($db_row['gpid']); $list_of_group .= "<option value=\"" . $db_row['gpid'] . "\" {$selected}>" . $db_row['gp_name'] . " (" . $db_row['gp_code'] . ")(" . $c_count . ")</option>"; } // add shared group $rows = phonebook_getsharedgroup($uid); foreach ($rows as $key => $db_row) { $c_uid = $db_row['uid']; $c_username = uid2username($c_uid); $c_count = phonebook_getmembercountbyid($db_row['gpid']); $list_of_group .= "<option value=\"" . $db_row['gpid'] . "\" {$selected}>" . $db_row['gp_name'] . " (" . $db_row['gp_code'] . ")(" . $c_count . ") - " . _('shared by') . " " . $c_username . "</option>"; } $sms_from = sendsms_get_sender($username); $max_length = $core_config['smsmaxlength']; if ($sms_footer = username2footer($username)) { $max_length = $max_length - strlen($sms_footer); } else { $sms_footer = "<i>" . _('not set') . "</i>"; } // WWW $db_query2 = "SELECT * FROM " . _DB_PREF_ . "_tblSMSTemplate WHERE uid='{$uid}'"; $db_result2 = dba_query($db_query2); $j = 0; $option_values = "<option value=\"\" default>--" . _('Please select') . "--</option>"; while ($db_row = dba_fetch_array($db_result2)) { $j++; $option_values .= "<option value=\"" . $db_row['t_text'] . "\">" . $db_row['t_title'] . "</option>"; $input_values .= "<input type=\"hidden\" name=\"content_{$j}\" value=\"" . $db_row['t_text'] . "\">";
/** * Send SMS to phonebook group * * @global array $core_config * @param string $username * @param integer $gpid * @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 * @return array array($status, $sms_to, $smslog_id, $queue) */ function sendsms_bc($username, $gpid, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '') { global $core_config, $user_config; $user = $user_config; if ($username && $user['username'] != $username) { $user = user_getdatabyusername($username); } $uid = $user['uid']; // discard if banned if (user_banned_get($uid)) { logger_print("user banned, exit immediately uid:" . $uid, 2, "sendsms_bc"); return array(FALSE, '', '', '', ''); } // SMS sender ID $sms_sender = core_sanitize_sender($sms_sender); $sms_sender = $sms_sender && sender_id_isvalid($username, $sms_sender) ? $sms_sender : sendsms_get_sender($username); // SMS footer $sms_footer = core_sanitize_footer($sms_footer); $sms_footer = $sms_footer ? $sms_footer : $user['footer']; if ($nofooter) { $sms_footer = ''; } // 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 $message = str_replace("\r\n", "\n", $message); // just to make sure its length, we need to stripslashes message before enter other procedures $sms_sender = stripslashes($sms_sender); $message = stripslashes($message); $sms_footer = stripslashes($sms_footer); // fixme anton - fix #71 but not sure whats the correct solution for this // $max_length = ( $unicode ? $user['opt']['max_sms_length_unicode'] : $user['opt']['max_sms_length'] ); $max_length = $user['opt']['max_sms_length']; if (strlen($message) > $max_length) { $message = substr($message, 0, $max_length); } $sms_msg = $message; logger_print("start uid:" . $uid . " sender:" . $sms_sender, 2, "sendsms_bc"); // add a space infront of footer if exists $c_sms_footer = trim($sms_footer) ? ' ' . trim($sms_footer) : ''; logger_print("maxlen:" . $max_length . " footerlen:" . strlen($c_sms_footer) . " footer:[" . $c_sms_footer . "] msglen:" . strlen($sms_msg) . " message:[" . $sms_msg . "]", 3, "sendsms_bc"); // destination group should be an array, if single then make it array of 1 member if (is_array($gpid)) { $array_gpid = $gpid; } else { $array_gpid = explode(',', $gpid); } $j = 0; for ($i = 0; $i < count($array_gpid); $i++) { if ($c_gpid = trim($array_gpid[$i])) { logger_print("start gpid:" . $c_gpid . " uid:" . $uid . " sender:" . $sms_sender, 2, "sendsms_bc"); // create a queue $queue_code = sendsms_queue_create($sms_sender, $sms_footer, $sms_msg, $uid, $c_gpid, $sms_type, $unicode, $sms_schedule, $smsc); if (!$queue_code) { // when unable to create a queue then immediately returns FALSE, no point to continue logger_print("fail to finalize queue creation, exit immediately", 2, "sendsms_bc"); return array(FALSE, '', '', '', ''); } $queue_count = 0; $sms_count = 0; $failed_queue_count = 0; $failed_sms_count = 0; $rows = phonebook_getdatabyid($c_gpid); if (is_array($rows)) { foreach ($rows as $key => $db_row) { $p_num = trim($db_row['p_num']); if ($sms_to = sendsms_getvalidnumber($p_num)) { $sms_to = sendsms_manipulate_prefix($sms_to, $user); if ($smslog_id[$j] = sendsms_queue_push($queue_code, $sms_to)) { $ok[$j] = true; $queue_count++; $sms_count += $count; } else { $ok[$j] = FALSE; $failed_queue_count++; $failed_sms_count++; } $to[$j] = $sms_to; $queue[$j] = $queue_code; $counts[$j] = $count; $j++; } } } if (sendsms_queue_update($queue_code, array('flag' => '0', 'sms_count' => $sms_count))) { logger_print("end queue_code:" . $queue_code . " queue_count:" . $queue_count . " sms_count:" . $sms_count . " failed_queue:" . $failed_queue_count . " failed_sms:" . $failed_sms_count, 2, "sendsms_bc"); } else { logger_print("fail to prepare queue, exit immediately queue_code:" . $queue_code, 2, "sendsms_bc"); return array(FALSE, '', '', $queue_code, ''); } } } if (!$core_config['issendsmsd']) { unset($ok); unset($to); unset($queue); unset($counts); logger_print("sendsmsd off immediately process queue_code:" . $queue_code, 2, "sendsms_bc"); list($ok, $to, $smslog_id, $queue, $counts) = sendsmsd($queue_code); } return array($ok, $to, $smslog_id, $queue, $counts); }
* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with playSMS. If not, see <http://www.gnu.org/licenses/>. */ defined('_SECURE_') or die('Forbidden'); if (!auth_isvalid()) { auth_block(); } switch (_OP_) { case "sendsms": // get $to and $message from session or query string $to = stripslashes($_REQUEST['to']); $message = stripslashes($_REQUEST['message']) ? stripslashes($_REQUEST['message']) : trim(stripslashes($_SESSION['tmp']['message'])); // sender ID $sms_from = sendsms_get_sender($user_config['username']); $ismatched = FALSE; foreach (sender_id_getall($user_config['username']) as $sender_id) { $selected = ''; if (strtoupper($sms_from) == strtoupper($sender_id)) { $selected = 'selected'; $ismatched = TRUE; } $option_values .= "<option value=\"" . $sender_id . "\" title=\"" . $sender_id . "\" " . $selected . ">" . $sender_id . "</option>"; } $sms_sender_id = "<select name=sms_sender style='width: 100%'>" . $option_values . "</select>"; if (!$ismatched) { $sms_sender_id = "<input type='text' style='width: 100%' name='sms_sender' value='" . $sms_from . "' readonly>"; } // SMS footer $sms_footer = $user_config['footer'];
/** * Send SMS * * @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 * @return array array($status, $sms_to, $smslog_id, $queue, $counts, $error_strings) */ function sendsms($username, $sms_to, $message, $sms_type = 'text', $unicode = 0, $smsc = '', $nofooter = false, $sms_footer = '', $sms_sender = '', $sms_schedule = '') { global $core_config, $user_config; // htmlspecialchars_decode to message and footer $message = htmlspecialchars_decode($message); $sms_footer = htmlspecialchars_decode($sms_footer); // get user data $user = $user_config; if ($username && $user['username'] != $username) { $user = user_getdatabyusername($username); } if (!is_array($sms_to)) { $sms_to = explode(',', $sms_to); } $uid = $user['uid']; // discard if banned if (user_banned_get($uid)) { _log("user banned, exit immediately uid:" . $uid . ' username:'******'username'], 2, "sendsms"); return array(FALSE, '', '', '', '', sprintf(_('Account %s is currently banned to use services'), $username)); } // SMS sender ID $sms_sender = core_sanitize_sender($sms_sender); $sms_sender = $sms_sender && sender_id_isvalid($username, $sms_sender) ? $sms_sender : sendsms_get_sender($username); // SMS footer $sms_footer = core_sanitize_footer($sms_footer); $sms_footer = $sms_footer ? $sms_footer : $user['footer']; if ($nofooter) { $sms_footer = ''; } // 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 $message = str_replace("\r\n", "\n", $message); // just to make sure its length, we need to stripslashes message before enter other procedures $sms_sender = stripslashes($sms_sender); $message = stripslashes($message); $sms_footer = stripslashes($sms_footer); // fixme anton - fix #71 but not sure whats the correct solution for this // $max_length = ( $unicode ? $user['opt']['max_sms_length_unicode'] : $user['opt']['max_sms_length'] ); $max_length = $user['opt']['max_sms_length']; if (strlen($message) > $max_length) { $message = substr($message, 0, $max_length); } $sms_msg = $message; _log("start uid:" . $uid . " sender_id:[" . $sms_sender . "] smsc:[" . $smsc . "]", 2, "sendsms"); // add a space infront of footer if exists $c_sms_footer = trim($sms_footer) ? ' ' . trim($sms_footer) : ''; _log("maxlen:" . $max_length . " footerlen:" . strlen($c_sms_footer) . " footer:[" . $c_sms_footer . "] msglen:" . strlen($sms_msg) . " message:[" . $sms_msg . "]", 3, "sendsms"); // create a queue $queue_code = sendsms_queue_create($sms_sender, $sms_footer, $sms_msg, $uid, 0, $sms_type, $unicode, $sms_schedule, $smsc); if (!$queue_code) { // when unable to create a queue then immediately returns FALSE, no point to continue _log("fail to finalize queue creation, exit immediately", 2, "sendsms"); return array(FALSE, '', '', '', '', _('Send message failed due to unable to create queue')); } if (is_array($sms_to)) { $array_sms_to = $sms_to; } else { $array_sms_to = explode(',', $sms_to); } // get manipulated and valid destination numbers $all_sms_to = array(); for ($i = 0; $i < count($array_sms_to); $i++) { if ($c_sms_to = sendsms_getvalidnumber(trim($array_sms_to[$i]))) { $c_sms_to = sendsms_manipulate_prefix(trim($c_sms_to), $user); $all_sms_to[] = $c_sms_to; } } // remove double entries $all_sms_to = array_unique($all_sms_to, SORT_STRING); // calculate total sms and charges $total_count = 0; $total_charges = 0; foreach ($all_sms_to as $c_sms_to) { list($count, $rate, $charge) = rate_getcharges($uid, strlen($message . $c_sms_footer), $unicode, $c_sms_to); $total_count += $count; $total_charges += $charge; } _log('dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms'); // sender's $credit = rate_getusercredit($user['username']); $balance = $credit - $total_charges; // parent's when sender is a subuser $parent_uid = user_getparentbyuid($user['uid']); if ($parent_uid) { $username_parent = user_uid2username($parent_uid); $credit_parent = rate_getusercredit($username_parent); $balance_parent = $credit_parent - $total_charges; } if ($parent_uid) { if (!($balance_parent >= 0)) { _log('failed parent do not have enough credit. credit:' . $credit_parent . ' dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms'); return array(FALSE, '', '', '', '', _('Internal error please contact service provider')); } } else { if (!($balance >= 0)) { _log('failed user do not have enough credit. credit:' . $credit_parent . ' dst:' . count($all_sms_to) . ' sms_count:' . $total_count . ' total_charges:' . $total_charges, 2, 'sendsms'); return array(FALSE, '', '', '', '', _('Send message failed due to insufficient funds')); } } // default returns for ($i = 0; $i < count($all_sms_to); $i++) { $ok[$i] = FALSE; $to[$i] = $all_sms_to[$i]; $smslog_id[$i] = 0; $queue[$i] = $queue_code; $counts[$i] = $count; } $queue_count = 0; $sms_count = 0; $failed_queue_count = 0; $failed_sms_count = 0; for ($i = 0; $i < count($all_sms_to); $i++) { $c_sms_to = $all_sms_to[$i]; $continue = TRUE; if (blacklist_mobile_isexists(0, $c_sms_to)) { $continue = FALSE; _log("fail to send. mobile is in the blacklist mobile:" . $c_sms_to, 2, "sendsms"); } if ($continue && ($smslog_id[$i] = sendsms_queue_push($queue_code, $c_sms_to))) { $ok[$i] = TRUE; $queue_count++; $sms_count += $count; $error_strings[$i] = sprintf(_('Message %s has been delivered to queue'), $smslog_id[$i]); } else { $ok[$i] = FALSE; $failed_queue_count++; $failed_sms_count++; $error_strings[$i] = sprintf(_('Send message to %s in queue %s has failed'), $c_sms_to, $queue_code); } $to[$i] = $c_sms_to; $queue[$i] = $queue_code; $counts[$i] = $count; } if (sendsms_queue_update($queue_code, array('flag' => '0', 'queue_count' => $queue_count, 'sms_count' => $sms_count))) { _log("end queue_code:" . $queue_code . " queue_count:" . $queue_count . " sms_count:" . $sms_count . " failed_queue:" . $failed_queue_count . " failed_sms:" . $failed_sms_count, 2, "sendsms"); } else { _log("fail to prepare queue, exit immediately queue_code:" . $queue_code, 2, "sendsms"); return array(FALSE, '', '', $queue_code, '', sprintf(_('Send message failed due to unable to prepare queue %s'), $queue_code)); } if (!$core_config['issendsmsd']) { unset($ok); unset($to); unset($queue); unset($counts); _log("sendsmsd off immediately process queue_code:" . $queue_code, 2, "sendsms"); list($ok, $to, $smslog_id, $queue, $counts) = sendsmsd($queue_code); } return array($ok, $to, $smslog_id, $queue, $counts, $error_strings); }
function sendsms_bc($username, $gpid, $message, $sms_type = 'text', $unicode = 0) { global $apps_path, $core_config, $gateway_module; $uid = username2uid($username); $sms_sender = sendsms_get_sender($username); $max_length = $unicode ? $core_config['smsmaxlength_unicode'] : $core_config['smsmaxlength']; if ($sms_footer = username2footer($username)) { $max_length = $max_length - strlen($sms_footer) - 1; } if (strlen($message) > $max_length) { $message = substr($message, 0, $max_length); } $sms_msg = $message; // \r and \n is ok - http://smstools3.kekekasvi.com/topic.php?id=328 //$sms_msg = str_replace("\r","",$sms_msg); //$sms_msg = str_replace("\n","",$sms_msg); $sms_msg = str_replace("\"", "'", $sms_msg); // destination group should be an array, if single then make it array of 1 member if (is_array($gpid)) { $array_gpid = $gpid; } else { $array_gpid[0] = $gpid; } // create a queue $queue_code = sendsms_queue_create($sms_sender, $sms_footer, $sms_msg, $uid, $sms_type, $unicode); if (!$queue_code) { // when unable to create a queue then immediately returns FALSE, no point to continue return FALSE; } $j = 0; for ($i = 0; $i < count($array_gpid); $i++) { $c_gpid = strtoupper($array_gpid[$i]); $rows = phonebook_getdatabyid($c_gpid); foreach ($rows as $key => $db_row) { $p_num = $db_row['p_num']; $sms_to = $p_num; $sms_to = str_replace("\\'", "", $sms_to); $sms_to = str_replace("\"", "", $sms_to); $ok[$j] = 0; $to[$j] = $sms_to; $queue[$j] = $queue_code; // fill the queue with destination numbers if ($ret = sendsms_queue_push($queue_code, $sms_to)) { $ok[$j] = $ret['status']; } $j++; } } if (!$core_config['issendsmsd']) { sendsmsd($queue_code); } return array($ok, $to, $queue); }
function sendsms_bc($username, $gpid, $message, $sms_type = 'text', $unicode = 0) { global $apps_path, $core_config; global $datetime_now, $gateway_module; $uid = username2uid($username); $sms_sender = sendsms_get_sender($username); $max_length = $core_config['smsmaxlength']; if ($sms_footer = username2footer($username)) { $max_length = $max_length - strlen($sms_footer) - 1; } if (strlen($message) > $max_length) { $message = substr($message, 0, $max_length - 1); } $sms_msg = $message; // \r and \n is ok - http://smstools3.kekekasvi.com/topic.php?id=328 //$sms_msg = str_replace("\r","",$sms_msg); //$sms_msg = str_replace("\n","",$sms_msg); $sms_msg = str_replace("\"", "'", $sms_msg); // destination group should be an array, if single then make it array of 1 member if (is_array($gpid)) { $array_gpid = $gpid; } else { $array_gpid[0] = $gpid; } $j = 0; for ($i = 0; $i < count($array_gpid); $i++) { $c_gpid = strtoupper($array_gpid[$i]); $rows = phonebook_getdatabyid($c_gpid); foreach ($rows as $key => $db_row) { $p_num = $db_row['p_num']; $sms_to = $p_num; $sms_to = str_replace("\\'", "", $sms_to); $sms_to = str_replace("\"", "", $sms_to); $to[$j] = $sms_to; $ok[$j] = 0; if ($ret = sendsms($sms_sender, $sms_footer, $sms_to, $sms_msg, $uid, $c_gpid, $sms_type, $unicode)) { $ok[$j] = $ret['status']; $smslog_id[$i] = $ret['smslog_id']; } $j++; } } return array($ok, $to, $smslog_id); }