Beispiel #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;
    }
}
Beispiel #2
0
function simplerate_hook_rate_refund($smslog_id)
{
    $ok = false;
    logger_print("start smslog_id:" . $smslog_id, 3, "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'];
        $uid = $db_row['uid'];
        if ($p_dst && $p_msg && $uid) {
            if (billing_rollback($smslog_id)) {
                $bill = billing_getdata($smslog_id);
                $rate = $bill['rate'];
                $status = $bill['status'];
                logger_print("rolling smslog_id:" . $smslog_id, 3, "simplerate refund");
                if ($status == '2') {
                    // here should be added a routine to check charset encoding
                    // utf8 devided by 140, ucs2 devided by 70
                    $count = ceil(strlen($p_msg) / 153);
                    $charge = $count * $rate;
                    $username = uid2username($uid);
                    $credit = rate_getusercredit($username);
                    $remaining = $credit + $charge;
                    if (rate_setusercredit($uid, $remaining)) {
                        logger_print("refund smslog_id:" . $smslog_id, 3, "simplerate refund");
                        $ok = true;
                    }
                }
            }
        }
    }
    return $ok;
}
Beispiel #3
0
        break;
    case "user_add_yes":
        $add_email = $_POST['add_email'];
        $add_username = $_POST['add_username'];
        $add_name = $_POST['add_name'];
        $add_mobile = $_POST['add_mobile'];
        $add_sender = $_POST['add_sender'];
        $add_footer = $_POST['add_footer'];
        $add_password = $_POST['add_password'];
        $add_credit = $_POST['add_credit'];
        $add_status = $_POST['add_status'];
        $add_timezone = $_POST['add_timezone'];
        $add_language_module = $_POST['add_language_module'];
        if (ereg("^(.+)(.+)\\.(.+)\$", $add_email, $arr) && $add_email && $add_username && $add_name && $add_password) {
            $db_query = "SELECT * FROM " . _DB_PREF_ . "_tblUser WHERE username='******'";
            $db_result = dba_query($db_query);
            if ($db_row = dba_fetch_array($db_result)) {
                $error_string = _('User is already exists') . " (" . _('username') . ": `" . $db_row['username'] . "`)";
            } else {
                $db_query = "\n\t\t    INSERT INTO " . _DB_PREF_ . "_tblUser (status,username,password,name,mobile,email,sender,footer,credit,datetime_timezone,language_module)\n\t\t    VALUES ('{$add_status}','{$add_username}','{$add_password}','{$add_name}','{$add_mobile}','{$add_email}','{$add_sender}','{$add_footer}','{$add_credit}','{$add_timezone}','{$add_language_module}')\n\t\t";
                if ($new_uid = @dba_insert_id($db_query)) {
                    rate_setusercredit($new_uid, $add_credit);
                    $error_string = _('User has been added') . " (" . _('username') . ": `{$add_username}`)";
                }
            }
        } else {
            $error_string = _('You must fill all fields');
        }
        header("Location: index.php?app=menu&inc=user_mgmnt&op=user_add&err=" . urlencode($error_string));
        break;
}
Beispiel #4
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;
}