============================================================================================================================
Modification Name: Warning System

Version: 1.2

Last modified: 04/22/10

Description:
This modification gives the staff the power to give warnings to members who misbehave on their forum.
There is a limit of 5 warnings. When that limit is reached then the member is banned for 72 hours.
There is a page in your admin panel for a few settings, including an On/Off, Money Deduction, Display Warns in Posts and Who Can Warn.
There is a page in your admin panel where you can view all the live warnings out right now and you can see the post that the member got warned for and see if the warning was warranted.
You are asked to confirm if you want to warn a member, so there are no accidents. You can also delete warnings.

Compatibility: XMB 1.9.5 SP1

Original Code Developed By: Nickpledge, Scan and Battle Angle.

Updated Code Developed By: Area51mafia (1.9.1 Release).
                                               WormHole : http://www.xmbgarage.com (1.9.5 Release)
                                               Adam Clarke : http://www.xmbservices.com (1.9.5 - Fixed Member Status Check)

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

Notes:
Backup all affected files, templates & databases.
Affected Files (5): include/admin.user.inc.php, header.php, viewthread.php, member.php, & lang/English.lang.php.
Affected Templates (3): viewthread, viewthread_post, & member_profile.

Author Note:
You downloaded this modification from XMBGarage.com, the best 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  Submit Changes.

============================================================================================================================
=======
Step 2:
=======
===========================
Edit File: include/admin.user.inc.php
===========================
==========
Find Code:
==========

    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    <br />

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

    <!-- Warning System Mod Begin -->
    &raquo;&nbsp;<a href="warnings.php?action=settings"><?php echo $lang['warnsettings']?></a><br />
    <!-- Warning System Mod End -->

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

    &raquo;&nbsp;<a href="cp.php?action=rename"><?php echo $lang['admin_rename_txt']?></a><br />

===============
Add Code Below:
===============

    <!-- Warning System Mod Begin -->
    &raquo;&nbsp;<a href="warnings.php"><?php echo $lang['viewwarnings']?></a><br />
    <!-- Warninig System Mod End -->

============================================================================================================================
=======
Step 3:
=======
=================
Edit File: header.php
=================
==========
Find Code:
==========

// Get the user-vars, and make them semi-global
if (!isset($xmbuser)) {
    $xmbuser = '';
    $xmbpw = '';
    $self['status'] = '';
}

===============
Add Code Below:
===============

// Warning System Mod Begin
$query = $db->query("SELECT * FROM $table_warnings WHERE username='$xmbuser' AND status='live'");
$origwarnings = mysql_num_rows($query);
if ($origwarnings > 0) {
    $expiretime = $onlinetime - 259200;
    $query = $db->query("UPDATE $table_warnings SET status = 'exp' WHERE username='$xmbuser' AND dateline < $expiretime");
    $query = $db->query("SELECT * FROM $table_warnings WHERE username='$xmbuser' AND status='live'");
    $numwarnings = mysql_num_rows($query);

    if ($numwarnings < 5 && $origwarnings == 5) {
        $query = $db->query("UPDATE $table_members SET ban='' WHERE username='$xmbuser'");
        $u2umessage = "You currently have ".$numwarnings." warnings from forum staff. Your posting ban has been automatically lifted. Please respect our members and participate in discussions in a productive manner.";
        $query = $db->query("INSERT INTO $table_u2u VALUES('', '$xmbuser', 'FORUM STAFF', 'incoming', '$xmbuser', 'inbox', 'Posting Ban Lifted', '$u2umessage', $onlinetime, 'no', 'yes')");
    } 
    if ($numwarnings =! $origwarnings) {
        $u2umessage = "You currently have ".$numwarnings." warnings from forum staff. Please continue to respect our members and participate in discussions in a productive manner.";
        $query = $db->query("INSERT INTO $table_u2u VALUES('', '$xmbuser', 'FORUM STAFF', 'incoming', '$xmbuser', 'inbox', 'Warning Expiration', '$u2umessage', $onlinetime, 'no', 'yes')");
    }
}
// Warning System Mod End

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

'u2u','whosonline'

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

'u2u','warnings','whosonline'

============================================================================================================================
=======
Step 4:
=======
===================
Edit File: viewthread.php
===================
==========
Find Code:
==========

loadtemplates(

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

loadtemplates(
'viewthread_post_warn',

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

smcwcache();

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

// Warning System Mod Begin
$viewmessage = '';
if ($SETTINGS['warnstatus'] == 'on' && $warn && $pid > 0) {
    $liststatuses = array_map('trim', explode(',', $SETTINGS['warnstatuses']));
    $warnallow = in_array($self['status'], $liststatuses);
    if ($warnallow && !X_GUEST) {
        $thatime = time();
        $query = $db->query("SELECT * FROM $table_warnings WHERE username='$warn' AND status='live'");
        $numwarnings = mysql_num_rows($query);
        if ($numwarnings < 5) {
            $post = "viewthread.php?tid=$tid&page=$page#pid$pid";
            $query = $db->query("INSERT INTO $table_warnings VALUES('', '$warn', $thatime, 'live', '$post')");
					
            $query = $db->query("SELECT subject FROM $table_threads WHERE tid='$tid'");
            $subject = $db->fetch_array($query);
            $numwarnings = $numwarnings + 1;
            if ($numwarnings == 5) {
                $query = $db->query("UPDATE $table_members SET ban='posts' WHERE username='$warn'");
                $viewmessage = "<div align='center' class='mediumtxt'><strong>You have warned ".$warn." who is now banned from posting.</strong></div>";
                $u2umessage = "A member of the forum staff has sent you a warning regarding your activity on the thread titled, ".$subject[subject].". This is now your fifth warning and a temporary posting ban has been automatically applied. Warnings are recorded, and each individual warning expires in three days (72 hours). This means your warnings will decrease to 4 in approximately three days, and your ban will be automatically lifted. However, be aware that unless all your warnings were given today, you may still have warnings applied to your profile when the ban is lifted. Do not reply to this U2U.";
                $query = $db->query("INSERT INTO $table_u2u VALUES('', '$warn', 'FORUM STAFF', 'incoming', '$warn', 'inbox', 'Warning and Posting Ban', '$u2umessage', $thatime, 'no', 'yes')");
            } else {
                $viewmessage = "<div align='center' class='mediumtxt'><strong>You have warned ".$warn." who now has ".$numwarnings." warnings.</strong></div>";
                $u2umessage = "A member of the forum staff has sent you a warning regarding your activity on the thread titled, ".$subject[subject].". Your have been warned ".$numwarnings." times. Warnings are recorded, and each individual warning expires in three days (72 hours) from the time it was applied. If forum staff continue to warn you for your action, and you gain five or more warnings, a temporary posting ban will be enforced automatically. Do not reply to this U2U.";
                $query = $db->query("INSERT INTO $table_u2u VALUES('', '$warn', 'FORUM STAFF', 'incoming', '$warn', 'inbox', 'Warning', '$u2umessage', $thatime, 'no', 'yes')");
            }
            if ($SETTINGS['moneywarn'] != '0') {
                $query = $db->query("UPDATE $table_members SET money=money-'$SETTINGS[moneywarn]' WHERE username='$warn'");
            }
        } else {
            $viewmessage="<div align='center' class='mediumtxt'><strong>That member, ".$warn." has already been warned five times.</strong></div>";
        }
    } else {
        $viewmessage = "<div align='center' class='mediumtxt'><strong>$lang[notabletowarn]</strong></div>";
    }
}
// Warning System Mod End

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

        if ($post['icon'] != '' && file_exists($smdir.'/'.$post['icon'])) {
            $post['icon'] = '<img src="'.$smdir.'/'.$post['icon'].'" alt="'.$post['icon'].'" border="0" />';
        } else {
            $post['icon'] = '<img src="'.$imgdir.'/default_icon.gif" alt="[*]" border="0" />';
        }

===============
Add Code Below:
===============

        // Warning System Mod Begin
        $staffwarnings = $warninglink = '';
        if ($SETTINGS['warnstatus'] == 'on') {
            $liststatuses = array_map('trim', explode(',', $SETTINGS['warnstatuses']));
            $warnallow = in_array($self['status'], $liststatuses);
            $query = $db->query("SELECT post FROM $table_warnings WHERE username='$post[author]' AND status='live'");
            $numwarnings = mysql_num_rows($query);
            if ($post['status'] == "Member" && $warnallow && !X_GUEST) {
                eval('$warninglink = "'.template('viewthread_post_warn').'";');			
                if ($numwarnings > 0) {
                    $staffwarnings = "<br />$lang[staffwarns] <strong>".$numwarnings."</strong><br />";
                }
            }
            $warndisplay = '';
            if ($SETTINGS['displaywarns'] == 'on') {
                if ($numwarnings != 0) {
                    $warndisplay = "<div align=\"center\">$lang[warnings]<br /><a href=\"member.php?action=warns&member=$post[author]\"><img alt=\"$lang[viewwarnings2]\" src=\"$imgdir/warn".$numwarnings.".gif\" border=\"0\"></a></div>";
                } else {
                    $warndisplay = '';
                }
            }
        }
        // Warning System Mod End

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

            $location = '';
            $mood = '';

===============
Add Code Below:
===============

            // Warning System Mod Begin
            $staffwarnings = '';
            $warninglink = '';
            $warndisplay = '';
            // Warning System Mod End

============================================================================================================================
=======
Step 5:
=======
=================
Edit File: member.php
=================
==========
Find Code:
==========

loadtemplates(

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

loadtemplates(
'member_profile_warns',
'member_warns_rows',
'member_warns',
'member_warns_none',

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

    case 'coppa':
        nav($lang['textcoppa']);
        break;

===============
Add Code Below:
===============

    // Warning System Mod Begin
    case 'warns':
        nav($lang['evalmemswarns']);
        break;
    // Warning System Mod End

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

            if (X_SADMIN) {
                $admin_edit = "<br />$lang[adminoption] <a href=\"./editprofile.php?user=$encodeuser\">$lang[admin_edituseraccount]</a>";
            } else {
                $admin_edit = NULL;
            }

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

            // Warning System Mod Begin
            $warndisplay = '';
            if ($SETTINGS['warnstatus'] == 'on' && $SETTINGS['displaywarns'] == 'on') {
                $query = $db->query("SELECT post FROM $table_warnings WHERE username='$memberinfo[username]' AND status='live'");
                $numwarnings = mysql_num_rows($query);
                if ($numwarnings != 0) {
                    $warndisplay = "<a href=\"member.php?action=warns&member=$memberinfo[username]\"><img alt=\"$lang[viewwarnings2]\"src=\"$imgdir/warn".$numwarnings.".gif\" border=\"0\"></a>";
                    eval('$warnblock = "'.template('member_profile_warns').'";');
                }
            }
            // Warning System Mod End

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

} elseif ($action == "viewpro") {

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

// Warning System Mod Begin
} elseif ($action == 'warns') {
    if (!$member) {
        error($lang['nomember']);
    } else {
        if ($SETTINGS['warnstatus'] == 'off' || $SETTINGS['displaywarns'] == 'off') {
            error($lang['warningoff']);
        }
        eval('echo ("'.template('header').'");');
            $query = $db->query("SELECT * FROM $table_warnings WHERE status='live' AND username='$member' ORDER BY dateline DESC");
            $warningsnum = mysql_num_rows($query);
            if ($warningsnum < 1) {
                eval('$warns = "'.template('member_warns_none').'";');
            } 
            while ($warninfo = $db->fetch_array($query)) { 
                $date = gmdate($dateformat, $warninfo['dateline'] + ($timeoffset * 3600) + ($addtime * 3600));
                $time = gmdate($timecode, $warninfo['dateline'] + ($timeoffset * 3600) + ($addtime * 3600));
                $datetime = "$date at $time";
                $post =  "<a href=\"$warninfo[post]\">$lang[viewpost2]</a>";
                if ($warningsnum != 0) {
                    eval('$warns .= "'.template('member_warns_rows').'";');
                }
            }
        eval('echo ("'.template('member_warns').'");');
    }
// Warning System Mod End

============================================================================================================================
=======
Step 6:
=======
=======================
Edit File: lang/English.lang.php
=======================
=============================
Add Code To End Of File ABOVE  ?>
=============================

// Warning System Mod Begin
$lang['warnings'] = "Warnings:";
$lang['warning'] = "Warning";
$lang['deletewarn'] = "Delete Warning";
$lang['warndate'] = "Date of Warning:";
$lang['reviewwarn'] = "Review Warning";
$lang['reviewwarn2'] = "Review";
$lang['warnupdate'] = "Warnings updated successfully!";
$lang['warnupdate2'] = "Warning Settings updated successfully!";
$lang['warnsettings'] = "Warning Settings";
$lang['displaywarns'] = "Display Warnings Next to Posts:";
$lang['warnstatus'] = "Warning System Status:";
$lang['warnstatuses'] = "Input the User Status of Those Who Can Give Out Warnings, Separated By Commas:";
$lang['warnstatuses2'] = "(ie. Super Administrator,Administrator,Super Moderator,Moderator,Member)";
$lang['notabletowarn'] = "You Are Not Able to Warn Users.";
$lang['moneywarn'] = "Money Taken Away on Warning:";
$lang['moneywarn2'] = "(Only If You Have the Shop Installed; If You Don't, Just Keep This Set To 0)";
$lang['staffwarns'] = "Staff Warnings: ";
$lang['viewwarnings'] = "View Warnings";
$lang['nowarnings'] = "This Member Has No Warnings";
$lang['viewpost'] = "View Post They Got Warned For:";
$lang['viewpost2'] = "View Post";
$lang['viewwarnings2'] = "View This Member's Warnings";
$lang['evalmemswarns'] = '$lang["memswarns"] = "$member\'s Warnings"';
$lang['warningoff'] = "The Warning System is Currently Turned Off";
$lang['warnsure'] = "Are you sure you want to warn this member?";
// Warning System Mod End

============================================================================================================================
=======
Step 7:
=======
===============================
Go To Administration Panel --> Templates
===============================
====================
Edit Template: viewthread
====================
========================
Add Code To Top Of Template:
========================

$viewmessage

============================================================================================================================
=======
Step 8:
=======
===============================
Go To Administration Panel --> Templates
===============================
========================
Edit Template: viewthread_post
========================
==========
Find Code:
==========

$onlinenow
<br />

===============
Add Code Below:
===============

$staffwarnings
<br />
$warninglink
<br />

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

$mood

===============
Add Code Below:
===============

$warndisplay

============================================================================================================================
=======
Step 9:
=======
===============================
Go To Administration Panel --> Templates
===============================
==================================
Create New Template: viewthread_post_warn
==================================
========================
Add Code and Submit Changes:
========================

<script type="text/javascript">
<!--
function warn() {
    if(confirm("$lang[warnsure]?")) {
        return true;
    } else {
        return false;
    }
}
//-->
</script>
<div align="center"><a href="viewthread.php?tid=$tid&page=$page&warn=$post[author]&pid=$post[pid]" onclick="return warn()" class='smalltxt'><strong>[warn]</strong></a></div>

============================================================================================================================
========
Step 10:
========
===============================
Go To Administration Panel --> Templates
===============================
=======================
Edit Template: member_profile
=======================
==========
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:
===============

$warnblock

============================================================================================================================
========
Step 11:
========
===============================
Go To Administration Panel --> Templates
===============================
==================================
Create New Template: member_profile_warns
==================================
========================
Add Code and Submit Changes:
========================

<tr class="tablerow">
<td bgcolor="$altbg1">$lang[warnings]</td>
<td bgcolor="$altbg2">$warndisplay</a></td>
</tr>

============================================================================================================================
========
Step 12:
========
===============================
Go To Administration Panel --> Templates
===============================
=============================
Create New Template: member_warns
=============================
========================
Add Code and Submit Changes:
========================

<tr bgcolor="$altbg2">
<td>
<table cellspacing="0" cellpadding="0" border="0" width="500" align="center">
<tr>
<td bgcolor="$bordercolor">
<table border="0" cellspacing="$borderwidth" cellpadding="$tablespace" width="100%">
<tr class="category">
<td width="50%"><strong><font color="$cattext">$lang[warndate]</font></strong></td>
<td width="50%"><strong><font color="$cattext">$lang[viewpost]</font></strong></td>
</tr>
$warns
</table>
</td>
</tr>
</table>
<br />
</td>
</tr>

============================================================================================================================
========
Step 13:
========
===============================
Go To Administration Panel --> Templates
===============================
=================================
Create New Template: member_warns_rows
=================================
========================
Add Code and Submit Changes:
========================

<tr bgcolor="$altbg2" class="tablerow">
<td>
$datetime
</td>
<td>
$post
</td>
</tr>

============================================================================================================================
========
Step 14:
========
===============================
Go To Administration Panel --> Templates
===============================
=================================
Create New Template: member_warns_none
=================================
========================
Add Code and Submit Changes:
========================

<tr bgcolor="$altbg2" class="tablerow">
<td colspan="2">
$lang[nowarnings]
</td>
</tr>

============================================================================================================================
========
Step 15:
========

Upload 'warnings.php' to your forum directory.
Upload 'warn1.gif', 'warn2.gif', 'warn3.gif', 'warn4.gif', 'warn5.gif' to all theme directories.
Upload 'warn.gif' if needed to all theme directories.

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