/**
 * start checkout process
 */
function StartCheckout(&$errorMessage)
{
    global $dir;
    global $memberID;
    // defined in checkout.inc.php
    global $collectDataArr;
    global $enable_recurring;
    global $en_credits;
    global $credit2money;
    // these globals for module require call
    global $site;
    global $providerConf;
    global $checkoutFilename;
    global $checkoutURL;
    global $debugFilename;
    // if buy for credits
    if ($_REQUEST['use_credits'] == 'on' && $en_credits) {
        $amount = sprintf('%.2f', (double) $collectDataArr['amount']);
        $creditsAmount = sprintf("%.2f", (double) ($collectDataArr['amount'] * $credit2money));
        $creditBalance = getProfileCredits($memberID);
        $result = 0;
        if ($collectDataArr['checkout_action'] == 'credits') {
            $errorMessage = 'Credits couldn\'t be bought by credits';
            return false;
        }
        if ($creditBalance < $creditsAmount) {
            $result = 1000;
        } else {
            $purchaseRes = performPurchase($memberID, $collectDataArr['checkout_action'], $collectDataArr['data'], $amount, $result);
            if ($purchaseRes) {
                decProfileCredits($memberID, $creditsAmount);
                $result = 1;
            } else {
                $result = -1;
            }
        }
        $returnURL = returnURLByAction($collectDataArr['checkout_action'], $collectDataArr['data']);
        processValidationResult($result, $errorMessage, 0, $returnURL);
    } else {
        $providerID = (int) $_REQUEST['prov_id'];
        $providerRes = db_res("SELECT `Name`, `CheckoutFilename` FROM `PaymentProviders` WHERE `ID` = {$providerID} AND `Active`");
        if (!$providerRes || mysql_num_rows($providerRes) == 0) {
            $errorMessage = 'Wrong payment provider specified';
            return false;
        }
        $providerArr = mysql_fetch_assoc($providerRes);
        if (strlen(trim($providerArr['CheckoutFilename']))) {
            $checkoutFilename = $providerArr['CheckoutFilename'];
        } else {
            $checkoutFilename = $dir['checkout'] . $providerArr['Name'] . '.php';
        }
        if (!file_exists($checkoutFilename)) {
            $errorMessage = 'Checkout file not found';
            return false;
        }
        require_once $checkoutFilename;
        $validateRes = moduleValidateConfiguration($errorMessage);
        if (!$validateRes) {
            return false;
        }
        $localTranID = initiateTransaction($collectDataArr, $memberID, $providerID);
        if ($localTranID === false) {
            $errorMessage = 'Transaction initiating error';
            return false;
        }
        $subscriptionalPayment = $enable_recurring && $collectDataArr['allow_subscribe'] == 'on' && $_REQUEST['prov_recurring'] == 'on';
        if ($subscriptionalPayment) {
            $subsRes = initiateSubscription($localTranID, $collectDataArr['subscribe_days']);
            if (!$subsRes) {
                $errorMessage = 'Subscription initiating error';
                return false;
            }
        }
        $startRes = moduleStartTransaction($localTranID, $subscriptionalPayment, $collectDataArr['subscribe_days']);
        if (!$startRes) {
            $errorMessage = 'Transaction starting error';
            return false;
        }
    }
    return true;
}
Exemplo n.º 2
0
/**
 * Send message
 */
function MemberSendMessage($member, $recipient, $must_use_credits = false)
{
    global $site;
    $en_dest_choice = getParam("enable_msg_dest_choice");
    $max_message_size = getParam("max_inbox_message_size");
    $max_messages = getParam("max_inbox_messages");
    // Check if recipient is active
    if ('Active' != $recipient['Status']) {
        return 10;
    }
    // Check if member is blocked
    if (db_arr("SELECT `ID`, `Profile` FROM `BlockList` WHERE `Profile` = {$member['ID']} AND `ID` = '{$recipient['ID']}';")) {
        return 5;
    }
    // If must use credits then check for enough amount
    if ($must_use_credits && getProfileCredits($member['ID']) < (double) $msg_credits) {
        return 21;
    }
    // antispam ))
    if (db_arr("SELECT `ID` FROM `Messages` WHERE `Sender` = {$member[ID]} AND date_add(`Date`, INTERVAL 1 MINUTE) > Now()")) {
        return 3;
    }
    // Get sender info
    $sender = getProfileInfo($member['ID']);
    $aPlus = array();
    $aPlus['ProfileReference'] = $sender ? '<a href="' . getProfileLink($member['ID']) . '">' . $sender['NickName'] . '</a> (' . getProfileLink($member['ID']) . ') ' : '<b>' . _t("_Visitor") . '</b>';
    // Don't send notification if message is sending to email
    if ($_POST['notify'] && !($_POST['sendto'] == "email" || $_POST['sendto'] == "both")) {
        $message_text = getParam("t_Compose");
        $subject = getParam('t_Compose_subject');
        $aPlus['senderNickName'] = $sender ? $sender['NickName'] : _t("_Visitor");
        $notify_res = sendMail($recipient['Email'], $subject, $message_text, $recipient['ID'], $aPlus);
        if (!$notify_res) {
            echo "<div class=\"err\">" . _t("_Notification send failed") . "</div><br />\n";
        }
    }
    // Send message to email
    if ($en_dest_choice && ($_POST['sendto'] == "email" || $_POST['sendto'] == "both")) {
        $message_text = getParam("t_Message");
        $subject = process_pass_data($_POST['mes_subject']);
        $aPlus['MessageText'] = strmaxtextlen(clear_xss(replace_full_uris(process_pass_data($_POST['text']))), $max_message_size);
        $result = sendMail($recipient['Email'], $subject, $message_text, $recipient['ID'], $aPlus);
    }
    // Send message to communicator
    if ($_POST['sendto'] == "lovemail" || $_POST['sendto'] == "both") {
        // Restrict with total messages count
        $messages_count = db_arr("SELECT COUNT(*) AS `mess_count` FROM `Messages` WHERE `Recipient` = '{$recipient['ID']}'");
        $messages_count = $messages_count['mess_count'];
        if ($messages_count - 1 > $max_messages) {
            $del_res = db_res("SELECT `ID` FROM `Messages` WHERE `Recipient` = '{$recipient['ID']}' ORDER BY `Date` ASC LIMIT " . ($messages_count - $max_messages + 1));
            while ($del_arr = mysql_fetch_array($del_res)) {
                db_res("DELETE FROM `Messages` WHERE `ID` = {$del_arr['ID']}");
            }
        }
        // Insert message into database
        $message_text = strmaxtextlen(addslashes(clear_xss(process_pass_data($_POST['text']))), $max_message_size);
        $message_subject = strmaxwordlen(process_db_input($_POST['mes_subject']), 30);
        $result = db_res("INSERT INTO `Messages` ( `Date`, `Sender`, `Recipient`, `Text`, `Subject`, `New` ) VALUES ( NOW(), {$member['ID']}, {$recipient['ID']}, '{$message_text}', '{$message_subject}', '1' )");
    }
    // If sending successful then mark as performed action
    if ($result) {
        checkAction($member['ID'], ACTION_ID_SEND_MESSAGE, true);
        if ($must_use_credits) {
            decProfileCredits($member['ID'], $msg_credits);
        }
    } else {
        return 1;
    }
    return 0;
}