Here's you go. Crude, and should be cleaned up, but it works for my purposes.
I sure wish Calorie would update this mod. It's one of very few things holding me back from vB4
Here's what the output looks like:
Attachment 134403
Here's the script: (I put a link to this in the misc section of the UserCP sidebar.)
Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'ptpnt_stat');
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array('user');
// pre-cache templates used by all actions
$globaltemplates = array('USERCP_SHELL','usercp_nav_folderbit');
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// ######################## START MAIN SCRIPT ############################
if ($vbulletin->userinfo['userid'] == 0)
{
print_no_permission();
}
$userid = intval($vbulletin->userinfo['userid']);
$threadstatus = "";
$result=$db->query_read("SELECT f.title AS forum, sum(p.totalthreads) AS 'threads',
sum(p.totalpaid) AS cost, sum(p.livethreads) AS live FROM ptpnt_buythread p left join forum f
on p.forumid=f.forumid where p.userid=" . $userid . " GROUP BY f.forumid");
If (mysql_num_rows($result)){
while( $buy = $db->fetch_array( $result ) ) {
$threadstatus .= "<tr><td>$buy[forum]</td><td>$buy[threads]</td><td>$buy[cost]</td><td>$buy[live]</td></tr></tr>";
}
$result=$db->query_read("SELECT f.title AS forum, p.totalthreads AS 'threads',
p.totalpaid AS cost, From_Unixtime(p.dateline, '%b %d %Y %r') AS purchased
FROM ptpnt_buythread p left join forum f ON p.forumid=f.forumid
WHERE p.userid=" . $userid . " ORDER BY p.dateline desc");
$history = "";
while( $buy = $db->fetch_array( $result ) ) {
$history .= "<tr><td>$buy[forum]</td><td>$buy[threads]</td><td>$buy[cost]</td><td>$buy[purchased]</td></tr></tr>";
}
}
eval('$ptpnt_stat = "' . fetch_template('ptpnt_stat') . '";');
// start the navbar
$navbits = array('usercp.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['user_control_panel']);
$navbits['ptpnt_stat.php' . $vbulletin->session->vars['sessionurl_q']] = 'Purchased Thread Status';
$navbits[''] = 'Purchased Thread Status';
// build the cp nav
require_once(DIR . '/includes/functions_user.php');
construct_usercp_nav();
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// eval('$HTML = "' . fetch_template($ptpnt_stat) . '";');
$HTML = $ptpnt_stat;
eval('print_output("' . fetch_template('USERCP_SHELL') . '");');
?>
Here's the template:
Code:
<div align="center">
<if condition="$history">
<h2>Thread Credit Status</h2>
<table class='ptpnt'>
<tr>
<th>Forum</th>
<th>Total Credits</th>
<th>Total Cost</th>
<th>Balance</th>
</tr>
$threadstatus
</table>
<h3>Thread Credit Purchase History</h3>
<table class='ptpnt'>
<tr>
<th>Forum</th>
<th>Credits Purchased</th>
<th>Total Cost</th>
<th>Purchase Date</th>
</tr>
$history
</table>
<else />
<h3>You have not purchased any threads.</h3>
</if>
</div>
Here's the query I execute directly when I need to know monthly totals:
Code:
SELECT DISTINCT FROM_UNIXTIME(dateline,"%M, %Y")
AS month, sum(totalpaid) as TotalPaid
FROM ptpnt_buythread
GROUP BY month
ORDER BY dateline