/** * Get mobile format for matching purposes * * @param string $mobile * @return mixed */ function core_mobile_matcher_format($mobile) { // sanitize for mobile numbers only $c_mobile = sendsms_getvalidnumber($mobile); if (strlen($c_mobile) >= 6) { // remove + $c_mobile = str_replace('+', '', $c_mobile); // remove first 3 digits if phone number length more than 7 if (strlen($c_mobile) > 7) { $c_mobile = substr($c_mobile, 3); } $mobile = $c_mobile; } return $mobile; }
/** * 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); }
// $i = 0; foreach ($data as $d) { $name = trim($d[0]); $mobile = trim($d[1]); $email = trim($d[2]); if ($group_code = trim($d[3])) { $gpid = phonebook_groupcode2id($uid, $group_code); } $tags = phonebook_tags_clean($d[4]); if ($name && $mobile) { if ($c_pid = phonebook_number2id($uid, $mobile)) { if ($gpid) { $save_to_group = TRUE; } } else { $items = array('uid' => $uid, 'name' => $name, 'mobile' => sendsms_getvalidnumber($mobile), 'email' => $email, 'tags' => $tags); if ($c_pid = dba_add(_DB_PREF_ . '_featurePhonebook', $items)) { if ($gpid) { $save_to_group = TRUE; } else { _log('contact added pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } } else { _log('fail to add contact pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email . ' tags:[' . $tags . ']', 3, 'phonebook_add'); } } if ($save_to_group && $gpid) { $db_query = "SELECT id FROM " . _DB_PREF_ . "_featurePhonebook_group_contacts WHERE gpid='" . $gpid . "' AND pid='" . $c_pid . "' LIMIT 1"; if (dba_num_rows($db_query) > 0) { _log('contact already in the group gpid:' . $gpid . ' pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_add'); } else {
/** * 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, $counts) */ 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; $array_sms_to = array(); // get User ID $uid = user_username2uid($username); _log("start uid:" . $uid . " sender_id:[" . $sms_sender . "] smsc:[" . $smsc . "]", 2, "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])) { $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)) { $array_sms_to[] = $sms_to; $sms_count++; } } } _log("collect gpid:" . $c_gpid . " uid:" . $uid . " sender:[" . $sms_sender . "] count:" . $sms_count, 2, "sendsms_bc"); } } _log("send all uid:" . $uid . " sender:[" . $sms_sender . "] count:" . count($array_sms_to), 2, "sendsms_bc"); // sendsms if (is_array($array_sms_to) && $array_sms_to[0]) { list($ok, $to, $smslog_id, $queue, $counts, $error_strings) = sendsms($username, $array_sms_to, $message, $sms_type, $unicode, $smsc, $nofooter, $sms_footer, $sms_sender, $sms_schedule); } return array($ok, $to, $smslog_id, $queue, $counts, $error_strings); }
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; }
echo $content; break; case 'members_add_submit': $sid = $_REQUEST['sid']; $data = sms_survey_getdatabyid($sid); $keyword = $data['keyword']; if ($sid && $keyword) { $filename = $_FILES['fncsv']['name']; $fn = $_FILES['fncsv']['tmp_name']; $fs = $_FILES['fncsv']['size']; if ($fs == filesize($fn) && file_exists($fn)) { if (($fd = fopen($fn, 'r')) !== FALSE) { $_SESSION['error_string'] = ""; while (($data = fgetcsv($fd, $fs, ',')) !== FALSE) { $c_keyword = trim(strtoupper($data[0])); $c_mobile = sendsms_getvalidnumber(trim($data[1])); $c_name = htmlspecialchars(trim($data[2])); if ($keyword == $c_keyword && $c_keyword && $c_mobile) { if (sms_survey_membersadd($sid, $c_mobile, $c_name)) { $_SESSION['error_string'] .= _('Member has been added') . " (" . _('Keyword') . ": " . $c_keyword . ", " . _('mobile') . ": " . $c_mobile . ", " . _('name') . ": " . $c_name . " )<br />"; } else { $_SESSION['error_string'] .= _('Fail to add member') . " (" . _('Keyword') . ": " . $c_keyword . ", " . _('mobile') . ": " . $c_mobile . ", " . _('name') . ": " . $c_name . " )<br />"; } } else { if ($c_mobile) { $_SESSION['error_string'] .= _('Keyword does not match') . " (" . _('Keyword') . ": " . $c_keyword . ", " . _('mobile') . ": " . $c_mobile . ", " . _('name') . ": " . $c_name . " )<br />"; } else { if ($c_keyword) { $_SESSION['error_string'] .= _('Mobile number not exists') . " (" . _('Keyword') . ": " . $c_keyword . ", " . _('mobile') . ": " . $c_mobile . ", " . _('name') . ": " . $c_name . " )<br />"; } }
} $_SESSION['dialog']['info'][] = _('Contact has been added'); } else { $_SESSION['dialog']['danger'][] = _('You must fill required fields'); } header("Location: " . _u('index.php?app=main&inc=feature_phonebook&op=phonebook_add')); exit; break; case 'edit': $uid = $user_config['uid']; $c_pid = $_POST['pid']; $gpids = $_POST['gpids']; $maps = ''; $save_to_group = FALSE; $mobile = str_replace("\\'", "", $_POST['mobile']); $mobile = sendsms_getvalidnumber(str_replace("\"", "", $mobile)); $name = str_replace("\\'", "", $_POST['name']); $name = str_replace("\"", "", $name); $email = str_replace("\\'", "", $_POST['email']); $email = str_replace("\"", "", $email); $tags = phonebook_tags_clean($_POST['tags']); if ($c_pid && $mobile && $name) { $items = array('name' => $name, 'mobile' => $mobile, 'email' => $email, 'tags' => $tags); $conditions = array('id' => $c_pid, 'uid' => $uid); dba_update(_DB_PREF_ . '_featurePhonebook', $items, $conditions, 'AND'); _log('contact edited pid:' . $c_pid . ' m:' . $mobile . ' n:' . $name . ' e:' . $email, 3, 'phonebook_edit'); } else { $_SESSION['dialog']['info'][] = _('You must fill mandatory fields'); header("Location: " . _u('index.php?app=main&inc=feature_phonebook&op=phonebook_list')); exit; break;