Exemplo n.º 1
0
function credit_hook_rate_addusercredit($uid, $amount)
{
    global $plugin_config;
    $db_table = $plugin_config['credit']['db_table'];
    $parent_uid = user_getparentbyuid($uid);
    $username = user_uid2username($uid);
    $status = user_getfieldbyuid($uid, 'status');
    $balance = (double) rate_getusercredit($username);
    $amount = (double) $amount;
    if (abs($amount) <= 0) {
        _log('amount cannot be zero. amount:[' . $amount . ']', 2, 'credit_hook_rate_addusercredit');
        return FALSE;
    }
    // add to balance
    $balance = $balance + $amount;
    // record it
    $id = dba_add($db_table, array('parent_uid' => $parent_uid, 'uid' => $uid, 'username' => $username, 'status' => $status, 'create_datetime' => core_get_datetime(), 'amount' => $amount, 'balance' => $balance, 'flag_deleted' => 0));
    // update user's credit
    if ($id) {
        _log('saved id:' . $id . ' parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add');
        if (rate_setusercredit($uid, $balance)) {
            _log('updated uid:' . $uid . ' credit:' . $balance, 3, 'credit_add');
            return TRUE;
        } else {
            _log('fail to update uid:' . $uid . ' credit:' . $balance, 3, 'credit_add');
            dba_remove($db_table, array('id' => $id));
            return FALSE;
        }
    } else {
        _log('fail to save parent_uid:' . $parent_uid . ' uid:' . $uid . ' username:'******' amount:' . $amount . ' balance:' . $balance, 3, 'credit_add');
        return FALSE;
    }
}
Exemplo n.º 2
0
function recvsms_inbox_add($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver = "", $reference_id = '')
{
    global $core_config;
    // sms to inbox will be handled by plugins first
    $ret_intercept = recvsms_inbox_add_intercept($sms_datetime, $sms_sender, $target_user, $message, $sms_receiver, $reference_id);
    if ($ret_intercept['param_modified']) {
        $sms_datetime = $ret_intercept['param']['sms_datetime'] ? $ret_intercept['param']['sms_datetime'] : $sms_datetime;
        $sms_sender = $ret_intercept['param']['sms_sender'] ? $ret_intercept['param']['sms_sender'] : $sms_sender;
        $target_user = $ret_intercept['param']['target_user'] ? $ret_intercept['param']['target_user'] : $target_user;
        $message = $ret_intercept['param']['message'] ? $ret_intercept['param']['message'] : $message;
        $sms_receiver = $ret_intercept['param']['sms_receiver'] ? $ret_intercept['param']['sms_receiver'] : $sms_receiver;
        $reference_id = $ret_intercept['param']['reference_id'] ? $ret_intercept['param']['reference_id'] : $reference_id;
    }
    $ok = FALSE;
    if ($sms_sender && $target_user && $message) {
        $user = user_getdatabyusername($target_user);
        if ($uid = $user['uid']) {
            // discard if banned
            if (user_banned_get($uid)) {
                logger_print("user banned, message ignored uid:" . $uid, 2, "recvsms_inbox_add");
                return FALSE;
            }
            // get name from target_user's phonebook
            $c_name = '';
            if (substr($sms_sender, 0, 1) == '@') {
                $c_username = str_replace('@', '', $sms_sender);
                $c_name = user_getfieldbyusername($c_username, 'name');
            } else {
                $c_name = phonebook_number2name($uid, $sms_sender);
            }
            $sender = $c_name ? $c_name . ' (' . $sms_sender . ')' : $sms_sender;
            // forward to Inbox
            if ($fwd_to_inbox = $user['fwd_to_inbox']) {
                $db_query = "\n\t\t\t\t\tINSERT INTO " . _DB_PREF_ . "_tblSMSInbox\n\t\t\t\t\t(in_sender,in_receiver,in_uid,in_msg,in_datetime,reference_id)\n\t\t\t\t\tVALUES ('{$sms_sender}','{$sms_receiver}','{$uid}','{$message}','" . core_adjust_datetime($sms_datetime) . "','{$reference_id}')\n\t\t\t\t";
                logger_print("saving sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user . " reference_id:" . $reference_id, 2, "recvsms_inbox_add");
                if ($inbox_id = @dba_insert_id($db_query)) {
                    logger_print("saved id:" . $inbox_id . " sender:" . $sms_sender . " receiver:" . $sms_receiver . " target:" . $target_user, 2, "recvsms_inbox_add");
                    $ok = TRUE;
                }
            }
            // forward to email, consider site config too
            if ($parent_uid = user_getparentbyuid($uid)) {
                $site_config = site_config_get($parent_uid);
            }
            $web_title = $site_config['web_title'] ? $site_config['web_title'] : $core_config['main']['web_title'];
            $email_service = $site_config['email_service'] ? $site_config['email_service'] : $core_config['main']['email_service'];
            $email_footer = $site_config['email_footer'] ? $site_config['email_footer'] : $core_config['main']['email_footer'];
            $sms_receiver = $sms_receiver ? $sms_receiver : '-';
            if ($fwd_to_email = $user['fwd_to_email']) {
                if ($email = $user['email']) {
                    $subject = _('Message from') . " " . $sender;
                    $body = $web_title . "\n\n";
                    $body .= _('Message received at') . " " . $sms_receiver . " " . _('on') . " " . $sms_datetime . "\n\n";
                    $body .= _('From') . " " . $sender . "\n\n";
                    $body .= $message . "\n\n--\n";
                    $body .= $email_footer . "\n\n";
                    $body = stripslashes($body);
                    logger_print("send email from:" . $email_service . " to:" . $email . " message:[" . $message . "]", 3, "recvsms_inbox_add");
                    $data = array('mail_from_name' => $web_title, 'mail_from' => $email_service, 'mail_to' => $email, 'mail_subject' => $subject, 'mail_body' => $body);
                    sendmail($data);
                    logger_print("sent email from:" . $email_service . " to:" . $email, 3, "recvsms_inbox_add");
                }
            }
            // forward to mobile
            if ($fwd_to_mobile = $user['fwd_to_mobile']) {
                if ($mobile = $user['mobile']) {
                    // fixme anton
                    $c_message = $message . ' ' . $sender;
                    if ($sender_uid = user_mobile2uid($sms_sender)) {
                        if ($sender_username = user_uid2username($sender_uid)) {
                            $c_message = $message . ' ' . '@' . $sender_username;
                        }
                    }
                    $message = $c_message;
                    $unicode = core_detect_unicode($message);
                    $nofooter = TRUE;
                    logger_print("send to mobile:" . $mobile . " from:" . $sms_sender . " user:"******" message:" . $message, 3, "recvsms_inbox_add");
                    list($ok, $to, $smslog_id, $queue) = sendsms($target_user, $mobile, $message, 'text', $unicode, '', $nofooter);
                    if ($ok[0] == 1) {
                        logger_print("sent to mobile:" . $mobile . " from:" . $sms_sender . " user:"******"recvsms_inbox_add");
                    }
                }
            }
        }
    }
    return $ok;
}
Exemplo n.º 3
0
/**
 * 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)
 */
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;
    // 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)) {
        logger_print("user banned, exit immediately uid:" . $uid, 2, "sendsms");
        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_id:[" . $sms_sender . "] smsc:[" . $smsc . "]", 2, "sendsms");
    // 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");
    // 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
        logger_print("fail to finalize queue creation, exit immediately", 2, "sendsms");
        return array(FALSE, '', '', '', '');
    }
    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);
    // 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(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;
    }
    // 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;
    }
    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($ok, $to, $smslog_id, $queue, $counts);
        }
    } 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($ok, $to, $smslog_id, $queue, $counts);
        }
    }
    $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];
        if ($smslog_id[$i] = sendsms_queue_push($queue_code, $c_sms_to)) {
            $ok[$i] = TRUE;
            $queue_count++;
            $sms_count = $sms_count + $count;
        } else {
            $ok[$i] = FALSE;
            $failed_queue_count++;
            $failed_sms_count++;
        }
        $to[$i] = $c_sms_to;
        $queue[$i] = $queue_code;
        $counts[$i] = $count;
    }
    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");
    } else {
        logger_print("fail to prepare queue, exit immediately queue_code:" . $queue_code, 2, "sendsms");
        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");
        list($ok, $to, $smslog_id, $queue, $counts) = sendsmsd($queue_code);
    }
    return array($ok, $to, $smslog_id, $queue, $counts);
}
Exemplo n.º 4
0
         $button_delete = "<input type=button class=button value='" . _('Delete') . "' onClick=\"javascript: ConfirmURL('" . _('Are you sure you want to delete user ?') . " (" . _('username') . ": " . $c_username . ")','index.php?app=main&inc=core_user&route=user_mgmnt&op=user_del" . $url_uname . "&view=" . $view . "')\">";
         $button_back = _back('index.php?app=main&inc=core_user&route=user_mgmnt&op=user_list&view=' . $view);
     }
 } else {
     $form_title = _('User configuration');
     // fixme anton - now disabled since plugin/feature/credit exists
     // $option_credit = "<tr><td>" . _('Credit') . "</td><td>$credit</td></tr>";
 }
 // get access control list
 $c_option_acl = array_flip(acl_getall());
 $option_acl = _input('text', '', acl_getname($acl_id), array('readonly'));
 if (auth_isadmin()) {
     $option_acl = _select('up_acl_id', $c_option_acl, $acl_id);
 }
 if ($user_edited['status'] == 4) {
     $parent_id = user_getparentbyuid($user_edited['uid']);
     if ($parent_id == $user_config['uid']) {
         $c_option_acl = array_flip(acl_getallbyuid($user_config['uid']));
         $option_acl = _select('up_acl_id', $c_option_acl, $acl_id);
     }
 }
 // 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
Exemplo n.º 5
0
            $fields[] = 'status';
        }
        if ($allow_edit_parent) {
            _log('saving username:'******' parent_uid:' . $_POST['up_parent_uid'], 3, 'user_pref');
            $fields[] = 'parent_uid';
        }
        for ($i = 0; $i < count($fields); $i++) {
            if ($c_data = trim($_POST['up_' . $fields[$i]])) {
                $up[$fields[$i]] = $c_data;
            }
        }
        // subuser's parent uid, by default its uid=1
        if ($_POST['up_parent_uid']) {
            $up['parent_uid'] = (int) ($user_edited['status'] == 4 ? $_POST['up_parent_uid'] : $core_config['main']['default_parent']);
        } else {
            $up['parent_uid'] = (int) user_getparentbyuid(user_username2uid($c_username));
        }
        if ($up['password'] && $up['password'] != $_POST['up_password_conf']) {
            $ret['error_string'] = _('Password does not match');
            $continue = false;
        }
        if ($continue) {
            $uid = user_username2uid($c_username);
            $ret = user_edit($uid, $up);
        }
        $_SESSION['dialog']['info'][] = $ret['error_string'];
        _log('saving username:'******' error_string:[' . $ret['error_string'] . ']', 2, 'user_pref');
        header("Location: " . _u('index.php?app=main&inc=core_user&route=user_pref&op=user_pref' . $url_uname . '&view=' . $view));
        exit;
        break;
}
Exemplo n.º 6
0
                 }
             } else {
                 $_SESSION['dialog']['info'][] .= _('Wrong amount or user does not exist') . ' (' . _('User ID') . ':' . $uid . ')';
             }
         }
     }
     header("Location: " . _u('index.php?app=main&inc=feature_credit&op=credit_add'));
     exit;
     break;
 case "reduce":
     $continue = FALSE;
     $uids = $_POST['uids'];
     if (is_array($uids)) {
         foreach ($uids as $uid) {
             if ($user_config['status'] == 3) {
                 $parent_uid = user_getparentbyuid($uid);
                 if ($parent_uid == $user_config['uid']) {
                     $continue = TRUE;
                 }
             }
             if (auth_isadmin()) {
                 $continue = TRUE;
             }
             $amount = -1 * abs($_POST['amount']);
             if ($continue && $amount < 0 && ($username = user_uid2username($uid))) {
                 if (credit_add($uid, $amount)) {
                     $current_balance = credit_getbalance($uid);
                     $_SESSION['dialog']['info'][] .= _('Credit has been reduced') . ' (' . _('user') . ':' . $username . ' ' . _('amount') . ':' . $amount . ' ' . _('balance') . ':' . $current_balance . ')';
                 } else {
                     $_SESSION['dialog']['info'][] .= _('Fail to reduce credit') . ' (' . _('user') . ':' . $username . ' ' . _('amount') . ':' . $amount . ')';
                 }
Exemplo n.º 7
0
function webservices_parent_get($uid)
{
    if ($parent_uid = user_getparentbyuid($uid)) {
        $json['status'] = 'OK';
        $json['error'] = '0';
        $json['parent_uid'] = $parent_uid;
        $json['parent'] = user_uid2username($parent_uid);
    } else {
        $json['status'] = 'ERR';
        $json['error'] = '610';
    }
    return $json;
}
Exemplo n.º 8
0
/**
 * Get user ban status
 *
 * @param integer $uid
 *        User ID
 * @return mixed Ban date/time or FALSE for non-banned user
 */
function user_banned_get($uid)
{
    $list = registry_search(1, 'auth', 'banned_users', $uid);
    if ($list['auth']['banned_users'][$uid]) {
        return $list['auth']['banned_users'][$uid];
    } else {
        // check if this user has parent then check the parent ban status
        if ($parent_uid = user_getparentbyuid($uid)) {
            if ($bantime = user_banned_get($parent_uid)) {
                return $bantime;
            } else {
                return FALSE;
            }
        }
    }
}
Exemplo n.º 9
0
function simplerate_hook_rate_refund($smslog_id)
{
    global $core_config;
    logger_print("start smslog_id:" . $smslog_id, 2, "simplerate refund");
    $db_query = "SELECT p_dst,p_msg,uid FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE p_status='2' AND smslog_id='{$smslog_id}'";
    $db_result = dba_query($db_query);
    if ($db_row = dba_fetch_array($db_result)) {
        $p_dst = $db_row['p_dst'];
        $p_msg = $db_row['p_msg'];
        $p_footer = $db_row['p_footer'];
        $uid = $db_row['uid'];
        $unicode = $db_row['unicode'];
        if ($p_dst && $p_msg && $uid) {
            if (billing_rollback($smslog_id)) {
                $bill = billing_getdata($smslog_id);
                $credit = $bill['credit'];
                $charge = $bill['charge'];
                $status = $bill['status'];
                logger_print("rolling smslog_id:" . $smslog_id, 2, "simplerate refund");
                if ($status == '2') {
                    // sender's
                    $username = user_uid2username($uid);
                    $credit = rate_getusercredit($username);
                    $balance = $credit + $charge;
                    // parent's when sender is a subuser
                    $parent_uid = user_getparentbyuid($uid);
                    if ($parent_uid) {
                        $username_parent = user_uid2username($parent_uid);
                        $credit_parent = rate_getusercredit($username_parent);
                        $balance_parent = $credit_parent + $charge;
                    }
                    // if sender have parent then deduct parent first
                    if ($parent_uid) {
                        if (!rate_setusercredit($parent_uid, $balance_parent)) {
                            return FALSE;
                        }
                        logger_print("parent uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " credit_parent:" . $credit_parent . " balance_parent:" . $balance_parent, 2, "simplerate refund");
                    }
                    if (rate_setusercredit($uid, $balance)) {
                        logger_print("user uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " credit:" . $credit . " balance:" . $balance, 2, "simplerate refund");
                        return TRUE;
                    }
                }
            }
        }
    }
    return FALSE;
}