============================================================================================================================
Modification Name: Thread Totals v1.4

Last modified: 04/08/2010

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.5 SP1

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

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.

Install Note: Before adding this mod to your forum, you should back up all files related to this mod.

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

Author Note:
You downloaded this modification from XMBGarage.com, the #1 source for XMB related downloads.
Please visit http://www.xmbgarage.com/ for support.
============================================================================================================================
========
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 $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="tablerow" align="center" colspan="7"><input type="submit" class="submit" name="membersubmit" value="<?php echo $lang['textsubmitchanges']?>" /><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="tablerow" align="center" colspan="8"><input type="submit" class="submit" name="membersubmit" value="<?php echo $lang['textsubmitchanges']?>" /><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 $table_members SET ban='$banstatus', status='$to[status]'

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

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

============================================================================================================================
========
STEP 3:
========
=================
Edit File: member.php
=================
==========
Find Code:
==========

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

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

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

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

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

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

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

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

            if ($daysreg > 1 ) {
                $ppd = $memberinfo['postnum'] / $daysreg;
                $ppd = round($ppd, 2);
            } else {
                $ppd = $memberinfo['postnum'];
            }

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

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

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

            $query = $db->query("SELECT COUNT(pid) FROM $table_posts");

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

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

            $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 ($table_posts p, $table_threads t) LEFT JOIN $table_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 $table_posts p, $table_threads t, $table_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) + ($addtime * 3600));
                $lastthreadtime = gmdate("$timecode", $thread['dateline'] + ($timeoffset * 3600) + ($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 (!isset($order) || ($order != "username" && $order != "postnum"

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

            if (!isset($order) || ($order != "username" && $order != "threadnum" && $order != "postnum"

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

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

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

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

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

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

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

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

Find Code:
----------------------------------------------------------------------------------------------------
        $db->query("UPDATE $table_members SET postnum=postnum-1 WHERE username='$result[author]'");
----------------------------------------------------------------------------------------------------

Replace Code With:
----------------------------------------------------------------------------------------------------
        $db->query("UPDATE $table_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 $table_members");
        while ($mem = $db->fetch_array($queryt)) {
            $mem['username'] = addslashes(stripslashes($mem['username']));

            $query = $db->query("SELECT COUNT(tid) FROM $table_threads WHERE author='$mem[username]'");
            $threadsnum = $db->result($query, 0);
            $db->query("UPDATE $table_members SET threadnum='$threadsnum' WHERE username='$mem[username]'");
        }

        nav($lang['tools']);
        echo "<tr bgcolor=\"$altbg2\" class=\"ctrtablerow\"><td>$lang[tool_completed] - $lang[tool_memthread]</td></tr></table></table>";
        end_time();
        eval("echo (\"".template('footer')."\");");
        exit;
        break;
    // Thread Totals Mod End

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

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

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

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

============================================================================================================================
========
STEP 8:
========
===========================
Edit File: include/admin.user.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-numbers';
$lang['textfixmemthreads'] = "Fix Member thread-totals";
// Thread Totals Mod End

============================================================================================================================
=========
STEP 10:
=========
=======================
Edit Template: member_profile
=======================
==========
Find Code:
==========

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

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

<td bgcolor="$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="$altbg1">$lang[textthreads]</td>
<td bgcolor="$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="$altbg1" valign="top">$lang[textproflastthread]</td>
<td bgcolor="$altbg2">$lastthread</td>
</tr>

============================================================================================================================
=========
STEP 11:
=========
===============================
Go To Administration Panel --> Templates
===============================
========================
Edit Template: viewthread_post
========================
==========
Find Code:
==========
$lang[textposts] $post[postnum]
<br />

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

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

============================================================================================================================
=========
STEP 12:
=========
===============================
Go To Administration Panel --> Templates
===============================
====================
Edit Template: misc_mlist
====================
==========
Find Code:
==========

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

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

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

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

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

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

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

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

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

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

<td width="5%" class="header" align="center">$lang[mcpuid]</td>
<td width="20%" class="header">$lang[textusername]</td>
<td width="15%" class="header" align="center">$lang[status]</td>
<td width="10%" class="header" align="center">$lang[textemail]:</td>
<td width="10%" class="header" align="center">$lang[textsite]</td>
<td class="header" width="15%">$lang[textlocation]</td>
<td class="header" align="center" width="15%">$lang[textregistered]</td>
<td class="header" align="center" width="5%">$lang[textthreads]</td>
<td class="header" align="center" width="5%">$lang[textposts]</td>

============================================================================================================================
=========
STEP 13:
=========
===============================
Go To Administration Panel --> Templates
===============================
=========================
Edit Template: misc_mlist_admin
=========================
==========
Find Code:
==========

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

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

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

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

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

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

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

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

<td width="3%" class="header" align="center">$lang[mcpuid]</td>
<td width="19%" class="header">$lang[textusername]</td>
<td width="16%" class="header" align="center">$lang[status]</td>
<td width="10%" class="header" align="center">$lang[textemail]:</td>
<td width="10%" class="header" align="center">$lang[textsite]</td>
<td class="header" width="19%">$lang[textlocation]</td>
<td class="header" align="center" width="19%">$lang[textregistered]</td>
<td class="header" align="center" width="5%">$lang[textposts]</td>

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

<td width="5%" class="header" align="center">$lang[mcpuid]</td>
<td width="20%" class="header">$lang[textusername]</td>
<td width="15%" class="header" align="center">$lang[status]</td>
<td width="10%" class="header" align="center">$lang[textemail]:</td>
<td width="10%" class="header" align="center">$lang[textsite]</td>
<td class="header" width="15%">$lang[textlocation]</td>
<td class="header" align="center" width="15%">$lang[textregistered]</td>
<td class="header" align="center" width="5%">$lang[textthreads]</td>
<td class="header" align="center" width="5%">$lang[textposts]</td>

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

<td bgcolor="$altbg2" colspan="8" align="left"  class="multi">&nbsp;$multipage</td>

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

<td bgcolor="$altbg2" colspan="9" align="left"  class="multi">&nbsp;$multipage</td>

============================================================================================================================
=========
STEP 15:
===============================
Go To Administration Panel --> Templates
===============================
=======================
Edit Template: misc_mlist_row
=======================
==========
Find Code:
==========

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

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

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

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