if ($user_edited['parent_uid'] == $user_config['uid']) { $is_parent = TRUE; } else { auth_block(); } } } $c_uid = user_username2uid($c_username); switch (_OP_) { case "user_config": if ($c_user = dba_search(_DB_PREF_ . '_tblUser', '*', array('flag_deleted' => 0, 'uid' => $c_uid))) { $token = $c_user[0]['token']; $webservices_ip = $c_user[0]['webservices_ip']; $enable_webservices = $c_user[0]['enable_webservices']; $sender = core_sanitize_sender($c_user[0]['sender']); $footer = core_sanitize_footer($c_user[0]['footer']); $datetime_timezone = core_get_timezone($c_username); $fwd_to_inbox = $c_user[0]['fwd_to_inbox']; $fwd_to_email = $c_user[0]['fwd_to_email']; $fwd_to_mobile = $c_user[0]['fwd_to_mobile']; $local_length = $c_user[0]['local_length']; $replace_zero = $c_user[0]['replace_zero']; $acl_id = (int) $c_user[0]['acl_id']; $credit = rate_getusercredit($c_username); } else { $_SESSION['dialog']['info'][] = _('User does not exist') . ' (' . _('username') . ': ' . $uname . ')'; header("Location: " . _u('index.php?app=main&inc=core_user&route=user_mgmnt&op=user_list&view=' . $view)); exit; } // select enable_webservices if ($enable_webservices) {
/** * 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); }
/** * 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); }
function user_edit_conf($uid, $data = array()) { global $user_config; $ret['status'] = FALSE; $ret['error_string'] = _('No changes made'); $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) { $up[$field] = trim($data[$field]); } $up['lastupdate_datetime'] = core_adjust_datetime(core_get_datetime()); if ($uid) { if ($up['new_token']) { $up['token'] = md5(mktime() . $uid . _PID_); } unset($up['new_token']); // if sender ID is sent then validate it if ($c_sender = core_sanitize_sender($up['sender'])) { $check_sender = sender_id_check($uid, $c_sender) ? TRUE : FALSE; } else { $check_sender = TRUE; } if ($check_sender) { $up['sender'] = $c_sender; $c_footer = core_sanitize_footer($up['footer']); $up['footer'] = strlen($c_footer) > 30 ? substr($c_footer, 0, 30) : $c_footer; // acl exception for admins $c_status = (int) user_getfieldbyuid($uid, 'status'); if ($c_status == 2) { $up['acl_id'] = 0; } // self edit can't save acl if ($uid == $user_config['uid']) { unset($up['acl_id']); } if (dba_update(_DB_PREF_ . '_tblUser', $up, array('flag_deleted' => 0, 'uid' => $uid))) { if ($up['token']) { $ret['error_string'] = _('User configuration has been saved and webservices token updated'); } else { $ret['error_string'] = _('User configuration has been saved'); } $ret['status'] = TRUE; } else { $ret['error_string'] = _('Fail to save configuration'); } } else { $ret['error_string'] = _('Invalid sender ID'); } } else { $ret['error_string'] = _('Unknown error'); } return $ret; }