Name: Thread Totals

Version: 1.4

Last modified: 25/06/2009 @ 14:45 (GMT)

Description: This modification will show the number of threads started in the member profile.
                   This modification will show the last thread started in the member profile.
                   This modification will show percentage of threads and threads per day in member profile.
                   This modification will show the number of threads started in the posts.
                   This modification will show the number of threads started in the member list.
                   This modification will enable the thread total to be edited in the admin member tool.
                   This modification will have add a new repair tool in the admin panel for member thread totals.

Compatibility: XMB 1.9.8 SP3

Tested On: XMB 1.9.8 SP3

Code Developed By: Adam Clarke (http://www.xmbservices.com)

Updated For 1.9.8 By: WormHole @ XMB Garage

MOD History: V1.0 (30/05/2005 @ 19:15) - Initial Release.
             V1.1 (26/09/2005 @ 20:50) - Added code for 'misc_mlist_multipage' template.
             V1.2 (22/10/2005 @ 17:20) - Added code for 'misc_mlist_results_none' template.
             V1.3 (11/02/2006 @ 23:00) - Modified code to work with XMB version 1.9.3.
             V1.4 (29/05/2007 @ 21:15) - Modified code to adjust thread counts on thread deletion.

License Note: This modification is released under the GPL License. A copy is provided with this software package.

Note: Backup all affected files, templates & database's.

Affected Files (7): member.php, misc.php, cp.php, tools.php, topicadmin.php, include/admin.user.inc.php, lang/English.lang.php

Affected Templates (7): member_profile, viewthread_post, misc_mlist, misc_mlist_admin, misc_mlist_multipage, misc_mlist_row, misc_mlist_results_none

====================================================================================================
========
STEP 1:
========
====================================
Go To Administration Panel -->  Insert Raw SQL
====================================

Upload SQL.txt and click Submit Changes.

====================================================================================================
========
STEP 2:
========
==============
Edit File: cp.php
==============
==========
Find Code:
==========

            <td><strong><font color="<?php echo $cattext?>"><?php echo $lang['textposts']?></font></strong></td>

===============
Add Code Above:
===============

            <!-- Thread Totals Mod Begin -->
            <td><strong><font color="<?php echo $THEME['cattext']?>"><?php echo $lang['textthreads']?></font></strong></td>
            <!-- Thread Totals Mod End -->

==========
Find Code:
==========

                <td><input type="text" size="3" name="postnum<?php echo $member['uid']?>" value="<?php echo $member['postnum']?>"></td>

===============
Add Code Above:
===============

                <!-- Thread Totals Mod Begin -->
                <td><input type="text" size="3" name="threadnum<?php echo $member['uid']?>" value="<?php echo $member['threadnum']?>"></td>
                <!-- Thread Totals Mod End -->

==========
Find Code:
==========

            <td bgcolor="<?php echo $altbg2?>" class="ctrtablerow" colspan="7"><input type="submit" class="submit" name="membersubmit" value="<?php echo $lang['textsubmitchanges']?>" onclick="return confirmUserDel('<?php echo $lang['confirmDeleteUser']?>');" /><input type="hidden" name="srchmem" value="<?php echo $srchmem?>" /><input type="hidden" name="srchstatus" value="<?php echo $srchstatus?>" /></td>

================
Replace Code With:
================

            <td bgcolor="<?php echo $altbg2?>" class="ctrtablerow" colspan="8"><input type="submit" class="submit" name="membersubmit" value="<?php echo $lang['textsubmitchanges']?>" onclick="return confirmUserDel('<?php echo $lang['confirmDeleteUser']?>');" /><input type="hidden" name="srchmem" value="<?php echo $srchmem?>" /><input type="hidden" name="srchstatus" value="<?php echo $srchstatus?>" /></td>

==========
Find Code:
==========

            $postnum = "postnum".$mem['uid'];
            $postnum = isset($_POST[$postnum]) ? $_POST[$postnum] : '';

===============
Add Code Above:
===============

            // Thread Totals Mod Begin
            $threadnum = "threadnum".$mem['uid'];
            $threadnum = isset($_POST[$threadnum]) ? $_POST[$threadnum] : '';
            // Thread Totals Mod End

==========
Find Code:
==========

$db->query("UPDATE ".X_PREFIX."members SET ban='$banstatus', status='$to[status]'

================
Replace Code With:
================

$db->query("UPDATE ".X_PREFIX."members SET ban='$banstatus', status='$to[status]', threadnum='$threadnum'

====================================================================================================
========
STEP 3:
========
==================
Edit File: member.php
==================
=================
Find Code (2 Times):
=================

$db->query("INSERT INTO ".X_PREFIX."members (username, password, regdate

=======================
Replace Code With (2 Times):
=======================

$db->query("INSERT INTO $table_members (username, password, regdate, threadnum

=================
Find Code (2 Times):
=================

) VALUES ('$username', '$password', ".$db->time($onlinetime).", 0

=======================
Replace Code With (2 Times):
=======================

) VALUES ('$username', '$password', ".$db->time($onlinetime).", '0', '0'

==========
Find Code:
==========

                $daysreg = ($onlinetime - $memberinfo['regdate']) / (24*3600);
                if ($daysreg > 1 ) {
                    $ppd = $memberinfo['postnum'] / $daysreg;
                    $ppd = round($ppd, 2);
                } else {
                    $ppd = $memberinfo['postnum'];
                }

================
Replace Code With:
================

                // Thread Totals Mod Begin
                $daysreg = ($onlinetime - $memberinfo['regdate']) / (24*3600);
                if ($daysreg > 1 ) {
                    $tpd = $memberinfo['threadnum'] / $daysreg;
                    $tpd = round($tpd, 2);
                    $ppd = $memberinfo['postnum'] / $daysreg;
                    $ppd = round($ppd, 2);
                } else {
                    $tpd = $memberinfo['threadnum'];
                    $ppd = $memberinfo['postnum'];
                }
                // Thread Totals Mod End

==========
Find Code:
==========

                $query = $db->query("SELECT COUNT(pid) FROM ".X_PREFIX."posts");

===============
Add Code Above:
===============

                // Thread Totals Mod Begin
                $query = $db->query("SELECT COUNT(tid) FROM ".X_PREFIX."threads");
                $threads = $db->result($query, 0);
                $db->free_result($query);

                $threadtot = $threads;
                if ($threadtot == 0) {
                    $t_percent = "0";
                } else {
                    $t_percent = $memberinfo['threadnum']*100/$threadtot;
                    $t_percent = round($t_percent, 2);
                }
                // Thread Totals Mod End

==========
Find Code:
==========

                $query = $db->query("SELECT t.tid, t.subject, p.dateline, p.pid FROM (".X_PREFIX."posts p, ".X_PREFIX."threads t) LEFT JOIN ".X_PREFIX."forums f ON p.fid=f.fid WHERE $restrict AND p.author='$member' AND p.tid=t.tid ORDER BY p.dateline DESC LIMIT 1");

===============
Add Code Above:
===============

                // Thread Totals Mod Begin
                $query = $db->query("SELECT t.tid, t.subject, p.dateline FROM (".X_PREFIX."posts p, ".X_PREFIX."threads t, ".X_PREFIX."forums f) WHERE $restrict AND p.fid=f.fid AND t.author='$memberinfo[username]' AND p.tid=t.tid ORDER BY t.tid DESC LIMIT 1");
                if ($thread = $db->fetch_array($query)) {

                    $lastthreaddate = gmdate($dateformat, $thread['dateline'] + ($timeoffset * 3600) + ($SETTINGS['addtime'] * 3600));
                    $lastthreadtime = gmdate($timecode, $thread['dateline'] + ($timeoffset * 3600) + ($SETTINGS['addtime'] * 3600));
                    $lastthreadtext = "$lastthreaddate $lang[textat] $lastthreadtime";
                    $thread['subject'] = censor($thread['subject']);
                    $lastthread = "<a href=\"./viewthread.php?tid=$thread[tid]\">$thread[subject]</a> ($lastthreadtext)";
                } else {
                    $lastthread = $lang['textnothreadsyet'];
                }
                // Thread Totals Mod End

====================================================================================================
========
STEP 4:
========
===============
Edit File: misc.php
===============
==========
Find Code:
==========

        if ($order != 'username' && $order != 'postnum' && $order != 'status') {

================
Replace Code With:
================

        if ($order != 'username' && $order != 'threadnum' && $order != 'postnum' && $order != 'status') {

====================================================================================================
========
STEP 5:
========
===============
Edit File: post.php
===============
==========
Find Code:
==========

            $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum+1 WHERE username like '$username'");

================
Replace Code With:
================

            $db->query("UPDATE ".X_PREFIX."members SET threadnum=threadnum+1, postnum=postnum+1 WHERE username like '$username'");

===========================
Find Code (Second Instance Only):
===========================

                    $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum-1 WHERE username='$orig[author]'");

=================================
Replace Code With (Second Instance Only):
=================================

                    $db->query("UPDATE ".X_PREFIX."members SET threadnum=threadnum-1, postnum=postnum-1 WHERE username='$orig[author]'");

==========
Find Code:
==========

                            $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum-1 WHERE username='$result[author]'");

================
Replace Code With:
================

                            $db->query("UPDATE ".X_PREFIX."members SET threadnum=threadnum-1, postnum=postnum-1 WHERE username='$result[author]'");

====================================================================================================
========
STEP 6:
========
===============
Edit File: tools.php
===============
==========

Find Code:
==========

    case 'fixmposts':

===============
Add Code Above:
===============

    // Thread Totals Mod Begin
    case 'fixmthreads':
        $queryt = $db->query("SELECT username FROM ".X_PREFIX."members");
        while ($mem = $db->fetch_array($queryt)) {
            $mem['username'] = addslashes(stripslashes($mem['username']));

            $query = $db->query("SELECT COUNT(tid) FROM ".X_PREFIX."threads WHERE author='$mem[username]'");
            $threadsnum = $db->result($query, 0);
            $db->query("UPDATE ".X_PREFIX."members SET threadnum='$threadsnum' WHERE username='$mem[username]'");
        }
        // Thread Totals Mod End

====================================================================================================
========
STEP 7:
========
===================
Edit File: topicadmin.php
===================
==========
Find Code:
==========

                    $db->query("UPDATE ".X_PREFIX."members SET postnum=postnum-1 WHERE username='$result[author]'");

================
Replace Code With:
================

                    $db->query("UPDATE ".X_PREFIX."members SET threadnum=threadnum-1, postnum=postnum-1 WHERE username='$result[author]'");

====================================================================================================
========
STEP 8:
========
=======================
Edit File: include/admin.inc.php
=======================
==========
Find Code:
==========

    &raquo;&nbsp;<a href="tools.php?action=fixmposts"><?php echo $lang['textfixmemposts']?></a><br />

===============
Add Code Above:
===============

    <!-- Thread Totals Mod Begin -->
    &raquo;&nbsp;<a href="tools.php?action=fixmthreads"><?php echo $lang['textfixmemthreads']?></a><br />
    <!-- Thread Totals Mod End -->

====================================================================================================
========
STEP 9:
========
=======================
Edit File: lang/English.lang.php
=======================
============================
Add Code To End Of File Above ?>
============================

// Thread Totals Mod Begin
$lang['textnothreadsyet'] = "No threads made yet.";
$lang['textthreads'] = "Threads:";
$lang['textoftotthreads'] = "of total threads";
$lang['textproflastthread'] = "Last Thread:";
$lang['textthreadperday'] = "threads per day";
$lang['textthreadnum'] = "Thread Number";
$lang['tool_memthread'] = 'Fixed Member Thread Totals';
$lang['textfixmemthreads'] = "Fix Member Thread Totals";
// Thread Totals Mod End

====================================================================================================
=========
STEP 10
=========
==========================
Go To Admin Panel --> Templates
==========================
=======================
Edit Template: member_profile
=======================
==========
Find Code:
==========

<td bgcolor="$altbg2" class="tablerow">$memberinfo[regdate] ($ppd $lang[textmesperday])</td>

================
Replace Code With:
================

<td bgcolor="$THEME[altbg2]" class="tablerow">$memberinfo[regdate] ($tpd $lang[textthreadperday]) ($ppd $lang[textmesperday])</td>

==========
Find Code:
==========

<tr>
<td bgcolor="$altbg1" class="tablerow">$lang[textposts]</td>
<td bgcolor="$altbg2" class="tablerow">$memberinfo[postnum] ($percent% $lang[textoftotposts])</td>
</tr>

===============
Add Code Above:
===============

<tr class="tablerow">
<td bgcolor="$THEME[altbg1]">$lang[textthreads]</td>
<td bgcolor="$THEME[altbg2]">$memberinfo[threadnum] ($t_percent% $lang[textoftotthreads])</td>
</tr>

==========
Find Code:
==========

<tr>
<td bgcolor="$altbg1" valign="top"
class="tablerow">$lang[textproflastpost]</td>
<td bgcolor="$altbg2" class="tablerow">$lastpost</td>
</tr>

===============
Add Code Above:
===============

<tr class="tablerow">
<td bgcolor="$THEME[altbg1]" valign="top">$lang[textproflastthread]</td>
<td bgcolor="$THEME[altbg2]">$lastthread</td>
</tr>

====================================================================================================
=========
STEP 11:
=========
==========================
Go To Admin Panel --> Templates
==========================
========================
Edit Template: viewthread_post
========================
==========
Find Code:
==========

$lang[textposts] $post[postnum]

===============
Add Code Above:
===============

$lang[textthreads] $post[threadnum]
<br />

====================================================================================================
=========
STEP 12:
=========
==========================
Go To Admin Panel --> Templates
==========================
=====================================
Edit Templates: misc_mlist AND misc_mlist_admin
=====================================
==========
Find Code:
==========

<td colspan="5" class="category"><font color="$cattext"><strong>$lang[textsortby]</strong></font></td>

================
Replace Code With:
================

<td colspan="6" class="category"><font color="$THEME[cattext]"><strong>$lang[textsortby]</strong></font></td>

==========
Find Code:
==========

<td bgcolor="$altbg2" width="18%"><a href="misc.php?action=list&amp;order=postnum&amp;desc=desc"><strong>$lang[textpostnum]</strong></a></td>
<td bgcolor="$altbg2" width="18%"><a href="misc.php?action=list&amp;order=username"><strong>$lang[textalpha]</strong></a></td>
<td bgcolor="$altbg2" width="18%"><a href="misc.php?action=list"><strong>$lang[textregdate]</strong></a></td>
<td bgcolor="$altbg2" width="18%"><a href="misc.php?action=list&amp;order=status"><strong>$lang[status]</strong></a></td>

================
Replace Code With:
================

<td bgcolor="$THEME[altbg2]" width="15%"><a href="misc.php?action=list&amp;order=threadnum&amp;desc=desc"><strong>$lang[textthreadnum]</strong></a></td>
<td bgcolor="$THEME[altbg2]" width="15%"><a href="misc.php?action=list&amp;order=postnum&amp;desc=desc"><strong>$lang[textpostnum]</strong></a></td>
<td bgcolor="$THEME[altbg2]" width="15%"><a href="misc.php?action=list&amp;order=username"><strong>$lang[textalpha]</strong></a></td>
<td bgcolor="$THEME[altbg2]" width="15%"><a href="misc.php?action=list"><strong>$lang[textregdate]</strong></a></td>
<td bgcolor="$THEME[altbg2]" width="15%"><a href="misc.php?action=list&amp;order=status"><strong>$lang[status]</strong></a></td>

==========
Find Code:
==========

<td width="20%">$lang[textusername]</td>
<td width="16%">$lang[status]</td>
<td width="10%">$lang[textemail]:</td>
<td width="10%">$lang[textsite]</td>
<td width="19%">$lang[textlocation]</td>
<td width="19%">$lang[textregistered]</td>
<td width="5%">$lang[textposts]</td>

================
Replace Code With:
================

<td width="20%">$lang[textusername]</td>
<td width="16%">$lang[status]</td>
<td width="10%">$lang[textemail]:</td>
<td width="10%">$lang[textsite]</td>
<td width="19%">$lang[textlocation]</td>
<td width="19%">$lang[textregistered]</td>
<td width="5%">$lang[textthreads]</td>
<td width="5%">$lang[textposts]</td>

=================
Find Code (2 Times):
=================

colspan="7"

=======================
Replace Code With (2 times):
=======================

colspan="8"

====================================================================================================
=========
STEP 13:
=========
==========================
Go To Admin Panel --> Templates
==========================
===========================================================
Edit Templates: misc_mlist_multipage, misc_mlist_results_none, misc_mlist_separator
===========================================================
==========
Find Code:
==========

colspan="7"

================
Replace Code With:
================

colspan="8"

====================================================================================================
=========
STEP 14:
=========
==========================
Go To Admin Panel --> Templates
==========================
=======================
Edit Template: misc_mlist_row
=======================
==========
Find Code:
==========

<td bgcolor="$altbg1" class="ctrtablerow">$member[postnum]</td>

================
Replace Code With:
================

<td bgcolor="$THEME[altbg1]" class="ctrtablerow">$member[threadnum]</td>
<td bgcolor="$THEME[altbg2]" class="ctrtablerow">$member[postnum]</td>

====================================================================================================
Enjoy!