function send_pm($privmsg_id, $from_userdata, &$to_user_ids, $subject, $message, $icon, $html_on = '?', $bbcode_on = '?', $smiley_on = '?', $attach_sig = '?')
{
    global $userdata, $user_ip;
    global $lang, $board_config, $db, $phpbb_root_path, $phpEx, $bbcode_parse;
    global $folders;
    global $s_unread;
    // get some constants
    $time = time();
    $sql_priority = SQL_LAYER == 'mysql' ? 'LOW_PRIORITY' : '';
    $q = "'";
    // lists of impacted users
    $recips = array();
    // fix some parameters
    $privmsg_id = intval(trim($privmsg_id));
    $subject = trim($subject);
    $message = trim($message);
    $icon = intval($icon);
    $privmsg_ip = $user_ip;
    // recipient is not an array, so make one
    if (!is_array($to_user_ids) && !empty($to_user_ids)) {
        $to_user_ids = array(intval($to_user_ids));
    }
    // check if recipients
    if (empty($to_user_ids)) {
        return 'No_to_user';
    }
    $s_to_user_ids = implode(', ', $to_user_ids);
    // deleted recip
    $s_new_delete = '';
    $s_unread_delete = '';
    $s_new_add = '';
    $s_unread_add = '';
    $s_read_add = '';
    // check we have a message and a subject
    if (empty($subject)) {
        return 'Empty_subject';
    }
    if (empty($message)) {
        return 'Empty_message';
    }
    // from_user_id can be 0 for sys message (sent by the board)
    if (empty($from_userdata)) {
        $from_userdata['user_id'] = 0;
        $from_userdata['username'] = $board_config['sitename'];
        $from_userdata['user_allowhtml'] = $board_config['allow_html'];
        $from_userdata['user_allowbbcode'] = $board_config['allow_bbcode'];
        $from_userdata['user_allowsmile'] = $board_config['allow_smilies'];
        $from_userdata['user_attachsig'] = $board_config['allow_sig'];
    }
    $from_user_id = intval($from_userdata['user_id']);
    // init message row
    $bbcode_uid = '';
    $html_on = !$board_config['allow_html'] ? false : $html_on == '?' ? intval($from_userdata['user_allowhtml']) : intval($html_on);
    $bbcode_on = !$board_config['allow_bbcode'] ? false : $bbcode_on == '?' ? intval($from_userdata['user_allowbbcode']) : intval($bbcode_on);
    $smiley_on = !$board_config['allow_smilies'] ? false : $smiley_on == '?' ? intval($from_userdata['user_allowsmile']) : intval($smiley_on);
    $attach_sig = !$board_config['allow_sig'] ? false : $attach_sig == '?' ? intval($from_userdata['user_attachsig']) : intval($attach_sig);
    $create = true;
    if (!empty($privmsg_id)) {
        $create = false;
    }
    //------------------------------
    // edit a message : read the pm and take care of recipients that are no more recipients
    //------------------------------
    if (!$create) {
        //-------------------------------
        // read the pm and check if ok to edit by the user (it has to belong to him)
        //-------------------------------
        $sql = "SELECT p.*, pr.*\n                    FROM " . PRIVMSGA_TABLE . " p, " . PRIVMSGA_RECIPS_TABLE . " pr\n                    WHERE p.privmsg_id = {$privmsg_id}\n                        AND pr.privmsg_id = p.privmsg_id\n                        AND pr.privmsg_user_id = {$from_user_id}\n                        AND pr.privmsg_direct = 0\n                        AND pr.privmsg_status = " . STS_TRANSIT;
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not read message to duplicate', '', __LINE__, __FILE__, $sql);
        }
        if (!($privmsg = $db->sql_fetchrow($result))) {
            return 'No_such_post';
        }
        // get some values from the original message
        $privmsg_ip = $privmsg['privmsg_ip'];
        //-------------------------------
        // manage recipients that are no more
        //-------------------------------
        // get users that are no more recipients and haven't read their pms
        $sql = "SELECT privmsg_user_id\n                    FROM " . PRIVMSGA_RECIPS_TABLE . "\n                    WHERE privmsg_user_id NOT IN ({$s_to_user_ids})\n                        AND privmsg_direct = 1\n                        AND privmsg_id = {$privmsg_id}\n                        AND privmsg_status = " . STS_TRANSIT . "\n                        AND privmsg_read IN ({$s_unread})";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not read users no more recipients having not yet readen the message', '', __LINE__, __FILE__, $sql);
        }
        while ($row = $db->sql_fetchrow($result)) {
            if ($row['privmsg_read'] == NEW_MAIL) {
                $s_new_delete .= (empty($s_new_delete) ? '' : ', ') . $row['privmsg_user_ids'];
            } else {
                $s_unread_delete .= (empty($s_unread_delete) ? '' : ', ') . $row['privmsg_user_ids'];
            }
        }
        // delete recipients for users who have deleted the message or not yet read and are no more recipients
        $sql = "DELETE {$sql_priority}\n                    FROM " . PRIVMSGA_RECIPS_TABLE . "\n                    WHERE privmsg_user_id NOT IN ({$s_to_user_ids})\n                        AND privmsg_direct = 1\n                        AND privmsg_id = {$privmsg_id}\n                        AND ( privmsg_read IN ({$s_unread}) OR privmsg_status = " . STS_DELETED . " )";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not delete users no more recipients having deleted or not yet readen the message', '', __LINE__, __FILE__, $sql);
        }
        // verify recipients that are no more but have read the pm
        $sql = "SELECT *\n                    FROM " . PRIVMSGA_RECIPS_TABLE . "\n                    WHERE privmsg_user_id NOT IN ({$s_to_user_ids})\n                        AND privmsg_direct = 1\n                        AND privmsg_id = {$privmsg_id}\n                        AND privmsg_read = " . READ_MAIL . "\n                        AND privmsg_status <> " . STS_DELETED . "\n                    LIMIT 0, 1";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not check if copy required', '', __LINE__, __FILE__, $sql);
        }
        // if some, duplicate the message and attach them to it
        if ($db->sql_numrows($result) > 0) {
            // message
            $fields = array();
            $fields['privmsg_subject'] = $q . str_replace("\\'", "''", str_replace('\\"', '"', addslashes(stripslashes($privmsg['privmsg_subject'])))) . $q;
            $fields['privmsg_text'] = $q . str_replace("\\'", "''", str_replace('\\"', '"', addslashes(stripslashes($privmsg['privmsg_text'])))) . $q;
            $fields['privmsg_bbcode_uid'] = $q . $privmsg['privmsg_bbcode_uid'] . $q;
            $fields['privmsg_time'] = intval($privmsg['privmsg_time']);
            $fields['privmsg_enable_bbcode'] = intval($privmsg['privmsg_enable_bbcode']);
            $fields['privmsg_enable_html'] = intval($privmsg['privmsg_enable_html']);
            $fields['privmsg_enable_smilies'] = intval($privmsg['privmsg_enable_smilies']);
            $fields['privmsg_attach_sig'] = intval($privmsg['privmsg_attach_sig']);
            $fields['privmsg_icon'] = intval($privmsg['privmsg_icon']);
            // generate a copy of the pm for recipients that are no more but have readen the pm, and mark it as deleted for the author
            _sql_statements($fields, $sql_fields, $sql_values, $sql_update);
            $sql = "INSERT {$sql_priority}\n                        INTO " . PRIVMSGA_TABLE . "\n                        ({$sql_fields})\n                        VALUES({$sql_values})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not generate a copy of original pm', '', __LINE__, __FILE__, $sql);
            }
            // get the copy id
            $privmsg_copy_id = $db->sql_nextid();
            // author
            $fields_recip = array();
            $fields_recip['privmsg_id'] = $privmsg_copy_id;
            $fields_recip['privmsg_direct'] = 0;
            $fields_recip['privmsg_user_id'] = intval($privmsg['privmsg_user_id']);
            $fields_recip['privmsg_ip'] = $q . $privmsg['privmsg_ip'] . $q;
            $fields_recip['privmsg_folder_id'] = intval($privmsg['privmsg_folder_id']);
            $fields_recip['privmsg_status'] = STS_DELETED;
            $fields_recip['privmsg_read'] = READ_PM;
            $fields_recip['privmsg_distrib'] = 1;
            // generate the author info
            _sql_statements($fields_recip, $sql_fields, $sql_values, $sql_update);
            $sql = "INSERT {$sql_priority}\n                        INTO " . PRIVMSGA_RECIPS_TABLE . "\n                        ({$sql_fields})\n                        VALUES({$sql_values})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not generate a copy of original pm author', '', __LINE__, __FILE__, $sql);
            }
            // attach to the copy recipients that are no more but have readed the pm
            $sql = "UPDATE {$sql_priority} " . PRIVMSGA_RECIPS_TABLE . "\n                        SET privmsg_id = {$privmsg_copy_id}, privmsg_distrib = 1\n                        WHERE privmsg_user_id NOT IN ({$s_to_user_ids})\n                            AND privmsg_direct = 1\n                            AND privmsg_id = {$privmsg_id}\n                            AND privmsg_read = " . READ_MAIL;
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not attach recips to the copied pm', '', __LINE__, __FILE__, $sql);
            }
        }
        //-------------------------------
        // get the existing recips list
        //-------------------------------
        $sql = "SELECT pr.privmsg_user_id, pr.privmsg_read\n                    FROM " . PRIVMSGA_RECIPS_TABLE . " pr\n                    WHERE pr.privmsg_id = {$privmsg_id}\n                        AND pr.privmsg_direct = 1";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not read recipients', '', __LINE__, __FILE__, $sql);
        }
        while ($row = $db->sql_fetchrow($result)) {
            $recips[$row['privmsg_user_id']] = $row['privmsg_read'];
        }
    }
    //----------------------------
    // create or update the message
    //----------------------------
    // get a bbcode uid
    $bbcode_uid = $bbcode_on ? $bbcode_parse->make_bbcode_uid() : '';
    // prepare the message and add bbcode uid to the bbcodes
    $message = prepare_message($message, $html_on, $bbcode_on, $smiley_on, $bbcode_uid);
    // message
    $fields = array();
    $fields['privmsg_subject'] = $q . str_replace("\\'", "''", str_replace('\\"', '"', addslashes(stripslashes($subject)))) . $q;
    $fields['privmsg_text'] = $q . str_replace("\\'", "''", str_replace('\\"', '"', addslashes(stripslashes($message)))) . $q;
    $fields['privmsg_bbcode_uid'] = $q . $bbcode_uid . $q;
    $fields['privmsg_time'] = $time;
    $fields['privmsg_enable_bbcode'] = $bbcode_on;
    $fields['privmsg_enable_html'] = $html_on;
    $fields['privmsg_enable_smilies'] = $smiley_on;
    $fields['privmsg_attach_sig'] = $attach_sig;
    $fields['privmsg_icon'] = $icon;
    // process
    if ($create) {
        // message
        _sql_statements($fields, $sql_fields, $sql_values, $sql_update);
        $sql = "INSERT {$sql_priority}\n                    INTO " . PRIVMSGA_TABLE . "\n                    ({$sql_fields})\n                    VALUES({$sql_values})";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not create pm', '', __LINE__, __FILE__, $sql);
        }
        // store the new privmsg_id
        $privmsg_id = $db->sql_nextid();
        // author
        $fields_recip = array();
        $fields_recip['privmsg_id'] = $privmsg_id;
        $fields_recip['privmsg_ip'] = $q . $privmsg_ip . $q;
        $fields_recip['privmsg_status'] = STS_TRANSIT;
        $fields_recip['privmsg_read'] = NEW_MAIL;
        $fields_recip['privmsg_distrib'] = 0;
        $fields_recip['privmsg_folder_id'] = OUTBOX;
        $fields_recip['privmsg_direct'] = 0;
        $fields_recip['privmsg_user_id'] = $from_user_id;
        _sql_statements($fields_recip, $sql_fields, $sql_values, $sql_update);
        $sql = "INSERT {$sql_priority}\n                    INTO " . PRIVMSGA_RECIPS_TABLE . "\n                    ({$sql_fields})\n                    VALUES({$sql_values})";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not create pm author', '', __LINE__, __FILE__, $sql);
        }
        // recipients
        $fields_recip['privmsg_direct'] = 1;
        $fields_recip['privmsg_folder_id'] = INBOX;
        _sql_statements($fields_recip, $sql_fields, $sql_values, $sql_update, 'privmsg_user_id');
        for ($i = 0; $i < count($to_user_ids); $i++) {
            $privmsg_to_user_id = intval($to_user_ids[$i]);
            if (!empty($privmsg_to_user_id)) {
                $sql = "INSERT {$sql_priority}\n                            INTO " . PRIVMSGA_RECIPS_TABLE . "\n                            ({$sql_fields}, privmsg_user_id)\n                            VALUES({$sql_values}, {$privmsg_to_user_id})";
                if (!$db->sql_query($sql)) {
                    message_die(GENERAL_ERROR, 'Could not create pm recipient', '', __LINE__, __FILE__, $sql);
                }
                $s_new_add .= (empty($s_new_add) ? '' : ', ') . $privmsg_to_user_id;
            }
        }
    } else {
        // message
        _sql_statements($fields, $sql_fields, $sql_values, $sql_update);
        $sql = "UPDATE {$sql_priority} " . PRIVMSGA_TABLE . "\n                    SET {$sql_update}\n                    WHERE privmsg_id = {$privmsg_id}";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not update pm', '', __LINE__, __FILE__, $sql);
        }
        // author
        $fields_recip = array();
        $fields_recip['privmsg_id'] = $privmsg_id;
        $fields_recip['privmsg_ip'] = $q . $privmsg_ip . $q;
        $fields_recip['privmsg_status'] = STS_TRANSIT;
        $fields_recip['privmsg_read'] = NEW_MAIL;
        $fields_recip['privmsg_distrib'] = 0;
        $fields_recip['privmsg_folder_id'] = OUTBOX;
        $fields_recip['privmsg_direct'] = 0;
        $fields_recip['privmsg_user_id'] = $from_user_id;
        _sql_statements($fields_recip, $sql_fields, $sql_values, $sql_update);
        $sql = "UPDATE {$sql_priority} " . PRIVMSGA_RECIPS_TABLE . "\n                    SET {$sql_update}\n                    WHERE privmsg_id = {$privmsg_id}\n                        AND privmsg_direct = 0";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not update pm', '', __LINE__, __FILE__, $sql);
        }
        // recipients
        $fields_recip['privmsg_direct'] = 1;
        $fields_recip['privmsg_folder_id'] = INBOX;
        _sql_statements($fields_recip, $sql_fields, $sql_values, $sql_update, 'privmsg_user_id');
        for ($i = 0; $i < count($to_user_ids); $i++) {
            $privmsg_to_user_id = intval($to_user_ids[$i]);
            if (!empty($privmsg_to_user_id)) {
                if (!isset($recips[$privmsg_to_user_id])) {
                    // create a new recip
                    $sql = "INSERT {$sql_priority}\n                                INTO " . PRIVMSGA_RECIPS_TABLE . "\n                                ({$sql_fields}, privmsg_user_id)\n                                VALUES({$sql_values}, {$privmsg_to_user_id})";
                    if (!$db->sql_query($sql)) {
                        message_die(GENERAL_ERROR, 'Could not create pm recipient', '', __LINE__, __FILE__, $sql);
                    }
                    $s_new_add .= (empty($s_new_add) ? '' : ', ') . $privmsg_to_user_id;
                } else {
                    // update an existing recip
                    $sql = "UPDATE {$sql_priority} " . PRIVMSGA_RECIPS_TABLE . "\n                                SET {$sql_update}\n                                WHERE privmsg_id = {$privmsg_id}\n                                    AND privmsg_user_id = {$privmsg_to_user_id}\n                                    AND privmsg_direct = 1";
                    if (!$db->sql_query($sql)) {
                        message_die(GENERAL_ERROR, 'Could not update pm recipient', '', __LINE__, __FILE__, $sql);
                    }
                    switch ($recips[$privmsg_to_user_id]) {
                        case READ_MAIL:
                            $s_read_add .= (empty($s_read_add) ? '' : ', ') . $privmsg_to_user_id;
                            break;
                        case UNREAD_MAIL:
                            $s_unread_add .= (empty($s_unread_add) ? '' : ', ') . $privmsg_to_user_id;
                            break;
                        case NEW_MAIL:
                            $s_new_add .= (empty($s_new_add) ? '' : ', ') . $privmsg_to_user_id;
                            break;
                    }
                }
            }
        }
    }
    //----------------------------
    // adjust the impacted users box
    //----------------------------
    if (!empty($s_new_delete)) {
        $sql = "UPDATE " . USERS_TABLE . "\n                    SET user_new_privmsg = user_new_privmsg-1\n                    WHERE user_id IN ({$s_new_delete})";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not update users counter - deleted new private messages', '', __LINE__, __FILE__, $sql);
        }
    }
    if (!empty($s_unread_delete) || !empty($s_unread_add)) {
        $semicol = empty($s_unread_delete) || empty($s_unread_add) ? '' : ',';
        $sql = "UPDATE " . USERS_TABLE . "\n                    SET user_unread_privmsg = user_unread_privmsg-1\n                    WHERE user_id IN ({$s_unread_delete} {$semicol} {$s_unread_add})";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not update users counter - deleted unread private messages', '', __LINE__, __FILE__, $sql);
        }
    }
    if (!empty($s_read_add) || !empty($s_new_add)) {
        $semicol = empty($s_read_add) || empty($s_new_add) ? '' : ',';
        $sql = "UPDATE " . USERS_TABLE . "\n                    SET user_new_privmsg = user_new_privmsg+1,\n                        user_last_privmsg = {$time}\n                    WHERE user_id IN ({$s_read_add} {$semicol} {$s_new_add})";
        if (!$db->sql_query($sql)) {
            message_die(GENERAL_ERROR, 'Could not update users counter - deleted new private messages', '', __LINE__, __FILE__, $sql);
        }
    }
    // notifications
    $date = $privmsg['privmsg_time'];
    $copy = false;
    // server values
    $server_name = trim($board_config['server_name']);
    $server_protocol = $board_config['cookie_secure'] ? 'https://' : 'http://';
    $server_port = $board_config['server_port'] != 80 ? ':' . trim($board_config['server_port']) . '/' : '/';
    // sender script
    $script_name = preg_replace('/^\\/?(.*?)\\/?$/', '\\1', trim($board_config['script_path']));
    $script_name = !empty($script_name) ? $script_name . '/privmsga.' . $phpEx : 'privmsga.' . $phpEx;
    // specific data
    $parsed_values = array('U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=' . INBOX);
    $recips = array();
    send_mail('privmsg_notify', $from_userdata, $to_user_ids, $recips, $subject, $message, $time, $copy, $parsed_values);
    if (defined('IN_CASHMOD')) {
        $pmer = new cash_user($userdata['user_id'], $userdata);
        $pmer->give_pm_amount();
    }
    return '';
}
Esempio n. 2
0
 // Output page header
 //
 $page_title = $lang['Exchange'];
 include $phpbb_root_path . 'includes/page_header.' . $phpEx;
 $sql = "SELECT * FROM " . CASH_EXCHANGE_TABLE;
 if (!($result = $db->sql_query($sql))) {
     message_die(GENERAL_ERROR, "Could not obtain exchange information", '', __LINE__, __FILE__, $sql);
 }
 if (!($row = $db->sql_fetchrow($result))) {
     message_die(GENERAL_MESSAGE, $lang['Exchange_lack_of_currencies']);
 }
 $exchange_data = array();
 do {
     $exchange_data[$row['ex_cash_id1']][$row['ex_cash_id2']] = 1;
 } while ($row = $db->sql_fetchrow($result));
 $exchanger = new cash_user($userdata['user_id'], $userdata);
 if (isset($HTTP_POST_VARS['exchange']) && isset($HTTP_POST_VARS['from_id']) && is_numeric($HTTP_POST_VARS['from_id']) && isset($HTTP_POST_VARS['to_id']) && is_numeric($HTTP_POST_VARS['to_id']) && isset($HTTP_POST_VARS['convert_amount']) && is_numeric($HTTP_POST_VARS['convert_amount'])) {
     $from_id = intval($HTTP_POST_VARS['from_id']);
     $to_id = intval($HTTP_POST_VARS['to_id']);
     $convert_amount = cash_floatval($HTTP_POST_VARS['convert_amount']);
     if ($convert_amount < 0) {
         qs($from_id, $to_id);
         $convert_amount = -$convert_amount;
     }
     if ($to_id != $from_id && $cash->currency_exists($to_id) && $cash->currency_exists($from_id) && isset($exchange_data[$from_id]) && is_array($exchange_data[$from_id]) && isset($exchange_data[$from_id][$to_id]) && $cash->currencies[$from_id]->mask(CURRENCY_ENABLED | CURRENCY_EXCHANGEABLE) && $cash->currencies[$to_id]->mask(CURRENCY_ENABLED | CURRENCY_EXCHANGEABLE)) {
         $c_cur_from = $cash->currency($from_id);
         $c_cur_to = $cash->currency($to_id);
         if ($exchanger->has($c_cur_from->id(), $convert_amount)) {
             $converted_amount = $convert_amount / $c_cur_from->data('cash_exchange') * $c_cur_to->data('cash_exchange');
             $exchanger->remove_by_id_array(array($c_cur_from->id() => $convert_amount));
             $exchanger->give_by_id_array(array($c_cur_to->id() => $converted_amount));
Esempio n. 3
0
                 $server_name = trim($board_config['server_name']);
                 $server_protocol = $board_config['cookie_secure'] ? 'https://' : 'http://';
                 $server_port = $board_config['server_port'] != 80 ? ':' . trim($board_config['server_port']) . '/' : '/';
                 $emailer = new emailer($board_config['smtp_delivery']);
                 $emailer->from($board_config['board_email']);
                 $emailer->replyto($board_config['board_email']);
                 $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
                 $emailer->email_address($to_userdata['user_email']);
                 $emailer->set_subject($lang['Notification_subject']);
                 $emailer->assign_vars(array('USERNAME' => stripslashes($to_username), 'SITENAME' => $board_config['sitename'], 'EMAIL_SIG' => !empty($board_config['board_email_sig']) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '', 'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox'));
                 if (!($emailer_result = $emailer->send(1))) {
                     message_die(GENERAL_ERROR, 'Failed sending email :: ' . $emailer_result, '', __LINE__, __FILE__);
                 }
                 $emailer->reset();
             }
             $pmer = new cash_user($userdata['user_id'], $userdata);
             $pmer->give_pm_amount();
         }
     }
     $template->assign_vars(array('META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("privmsg.{$phpEx}?folder=inbox") . '">'));
     $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . append_sid("privmsg.{$phpEx}?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.{$phpEx}") . '">', '</a>');
     message_die(GENERAL_MESSAGE, $msg);
 } else {
     if ($preview || $refresh || $error) {
         //
         // If we're previewing or refreshing then obtain the data
         // passed to the script, process it a little, do some checks
         // where neccessary, etc.
         //
         $to_username = isset($HTTP_POST_VARS['username']) ? trim(htmlspecialchars(stripslashes($HTTP_POST_VARS['username']))) : '';
         $privmsg_subject = isset($HTTP_POST_VARS['subject']) ? trim(htmlspecialchars(stripslashes($HTTP_POST_VARS['subject']))) : '';
Esempio n. 4
0
 function cash_update($mode, $poster_id, $first_post, &$old_message, &$new_message, $forum_id, $topic_id, $post_id, $new_bbcode, $topic_starter, $old_bbcode)
 {
     global $board_config, $lang, $db, $phpbb_root_path, $phpEx, $userdata, $cash;
     if ($mode == 'reply' && $poster_id != $topic_starter && ($topic_userdata = get_userdata($topic_starter))) {
         $topic_creator = new cash_user($topic_starter, $topic_userdata);
         $topic_creator->give_bonus($topic_id);
     }
     if ($poster_id == ANONYMOUS) {
         return;
     }
     if ($userdata['user_id'] == $poster_id) {
         $posting_user = new cash_user($userdata['user_id'], $userdata);
     } else {
         $posting_user = new cash_user($poster_id);
     }
     $all_active = true;
     $forumcount = array();
     $forumlist = array();
     if (($mode == 'newtopic' || $mode == 'reply') && intval($board_config['cash_disable_spam_num']) > 0) {
         $all_active = false;
         $interval = time() - 3600 * intval($board_config['cash_disable_spam_time']);
         $sum = 0;
         $sql = "SELECT forum_id, count(post_id) as postcount\n\t\t\t\t\tFROM " . POSTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$poster_id}\n\t\t\t\t\t\tAND post_time > {$interval}\n\t\t\t\t\tGROUP BY forum_id";
         if (!($result = $db->sql_query($sql))) {
             message_die(GENERAL_ERROR, 'Error retrieving post data', '', __LINE__, __FILE__, $sql);
         }
         while ($row = $db->sql_fetchrow($result)) {
             $forumlist[] = $row['forum_id'];
             $forumcount[$row['forum_id']] = $row['postcount'];
             $sum += $row['postcount'];
         }
         if ($sum < $board_config['cash_disable_spam_num']) {
             $all_active = true;
         }
     }
     $new_len = array(strlen($new_message), cash_quotematch($new_message, $new_bbcode));
     $old_len = array(strlen($old_message), cash_quotematch($old_message, $old_bbcode));
     $sql_clause = array();
     $message_clause = array();
     $reply_bonus = array();
     $all_spam = !$all_active;
     while ($c_cur =& $cash->currency_next($cm_i, CURRENCY_ENABLED, $forum_id)) {
         $this_enabled = $all_active;
         if (!$all_active) {
             $sum = 0;
             for ($i = 0; $i < count($forumlist); $i++) {
                 if ($c_cur->forum_active($forumlist[$i])) {
                     $sum += $forumcount[$forumlist[$i]];
                 }
             }
             if ($sum < $board_config['cash_disable_spam_num']) {
                 $this_enabled = true;
                 $all_spam = false;
             }
         }
         if ($this_enabled) {
             $base = $first_post ? $posting_user->get_setting($c_cur->id(), 'cash_perpost') : $posting_user->get_setting($c_cur->id(), 'cash_perreply');
             $perchar = $posting_user->get_setting($c_cur->id(), 'cash_perchar', PERCHAR_DEC_BONUS);
             $max = $posting_user->get_setting($c_cur->id(), 'cash_maxearn');
             $quotes = $c_cur->mask(CURRENCY_INCLUDEQUOTES) ? 0 : 1;
             $total_added = $mode != 'delete' ? min($max, $base + $perchar * $new_len[$quotes]) : 0;
             $total_removed = $mode != 'newtopic' && $mode != 'reply' ? min($max, $base + $perchar * $old_len[$quotes]) : 0;
             $total_change = $total_added - $total_removed;
             if ($total_change != 0) {
                 $change_sign = $total_change > 0;
                 $change_amount = $change_sign ? $total_change : -$total_change;
                 $change_sign = $change_sign ? " + " : " - ";
                 $sql_clause[] = $c_cur->db() . " = " . $c_cur->db() . $change_sign . $change_amount;
                 $message_clause[] = $c_cur->display($change_amount);
             }
         }
     }
     if ($all_spam) {
         return $board_config['cash_disable_spam_message'];
     }
     if (count($sql_clause) > 0) {
         $sql = "UPDATE " . USERS_TABLE . " \n\t\t\t\t\tSET " . implode(', ', $sql_clause) . "\n\t\t\t\t\tWHERE user_id = " . $poster_id;
         if (!$db->sql_query($sql)) {
             message_die(GENERAL_ERROR, 'Error in updating cash', '', __LINE__, __FILE__, $sql);
         }
     }
     return $userdata['user_id'] == $poster_id && $board_config['cash_display_after_posts'] == 1 ? sprintf($board_config['cash_post_message'], implode(', ', $message_clause)) : '';
 }
Esempio n. 5
0
     if ($max_user < intval($row['user_id'])) {
         $max_user = intval($row['user_id']);
     }
 }
 define('CASH_POSTS', 0);
 define('CASH_BONUS', 1);
 define('CASH_REPLIES', 2);
 define('FLUSH', '                                                                                                                                                                                                                                                                ');
 $cm_groups->load(true, true);
 $sql = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('cash_resetting','-1,{$max_user}')";
 if (!$db->sql_query($sql)) {
     message_die(GENERAL_ERROR, 'Error setting config data', '', __LINE__, __FILE__, $sql);
 }
 for ($i = 0; $i < count($userlist); $i++) {
     if ($userlist['user_id'] != ANONYMOUS) {
         $c_user = new cash_user($userlist[$i]['user_id'], $userlist[$i]);
         $sql = "SELECT t.forum_id, t.topic_id, t.topic_poster, t.topic_replies, count( p.post_id ) AS user_replies\n\t\t\t\t\tFROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p \n\t\t\t\t\tWHERE t.topic_id = p.topic_id AND p.poster_id = " . $c_user->id() . "\n\t\t\t\t\tGROUP BY t.topic_id";
         if (!($result = $db->sql_query($sql))) {
             message_die(GENERAL_ERROR, 'Error retrieving data', '', __LINE__, __FILE__, $sql);
         }
         $forums = array();
         $forum_list = array(CASH_POSTS => 0, CASH_BONUS => 0, CASH_REPLIES => 0);
         //
         // $forums is an array of arrays. the first index is the forum_id. the remainder are a count of
         //  [0] => topics started
         //  [1] => bonus earned on those topics
         //  [2] => replies
         //
         while ($row = $db->sql_fetchrow($result)) {
             $forum_id = intval($row['forum_id']);
             $topic_poster = intval($row['topic_poster']);
Esempio n. 6
0
 function cash_update_thanks($poster_id)
 {
     global $config, $lang, $db, $user, $cash;
     $posting_user = new cash_user($poster_id);
     $sql_clause = array();
     $message_clause = array();
     while ($c_cur =& $cash->currency_next($cm_i, CURRENCY_ENABLED, $forum_id)) {
         $perthanks = $posting_user->get_setting($c_cur->id(), 'cash_perthanks');
         $sql_clause[] = $c_cur->db() . ' = ' . $c_cur->db() . ' + ' . $perthanks;
         $message_clause[] = $c_cur->display($perthanks);
     }
     if (sizeof($sql_clause) > 0) {
         $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\tSET " . implode(', ', $sql_clause) . "\n\t\t\t\t\tWHERE user_id = " . $poster_id;
         $db->sql_query($sql);
         // Mighty Gorgon: to be fixed because it returns ARRAY
         //return $message_clause;
         return '';
     }
 }