Title: U2U Status v1.0

Author: John Briggs

Description:
This modification will provide a new tool in admin panel to turn the U2U messenger on and off.
This modification will prevent members only when set to off and still allow staff to access it.

Copyright:  2009 John Briggs. All rights reserved.

Compatability: XMB 1.9.11

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

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

=======================================================================================================================================
=======
Step 1:
=======

========================================================
Go to admin panel -> insert raw sql -> submit code below
========================================================

ALTER TABLE `$table_settings` ADD `u2ustatus` set('on','off') NOT NULL default 'on';

=======================================================================================================================================
=======
Step 2:
=======

=================
Edit File: cp.php
=================

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

        $remoteimageson = $remoteimagesoff = '';
        settingHTML('attach_remote_images', $remoteimageson, $remoteimagesoff);

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

        // U2U Status Mod Begin
        $u2ustatuson = $u2ustatusoff = '';
        settingHTML('u2ustatus', $u2ustatuson, $u2ustatusoff);
        // U2U Status Mod End

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

        printsetting1($lang['textmemliststatus'], 'memliststatusnew', $memliston, $memlistoff);

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

        // U2U Status Mod Begin
        printsetting1($lang['u2ustatus'], 'u2ustatusnew', $u2ustatuson, $u2ustatusoff);
        // U2U Status Mod End

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

        $remoteimages = formOnOff('remoteimages');

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

        // U2U Status Mod Begin
        $u2ustatusnew = formOnOff('u2ustatusnew');
        // U2U Status Mod End

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

        $sql = "UPDATE ".X_PREFIX."settings SET

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

            u2ustatus='$u2ustatusnew',

=======================================================================================================================================
=======
Step 3:
=======

=====================
Edit File: header.php
=====================

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

    $u2ulink = "<a href=\"u2u.php\" onclick=\"Popup(this.href, 'Window', 700, 450); return false;\">{$lang['banu2u']}</a> - ";

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

    // U2U Status Mod Begin
    $u2ulink = '';
    if (!($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member')) {
        $u2ulink = "<a href=\"u2u.php\" onclick=\"Popup(this.href, 'Window', 700, 450); return false;\">{$lang['banu2u']}</a> - ";
    }
    // U2U Status Mod End

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

    // check for new u2u's
    if (X_MEMBER) {

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

    // check for new u2u's
    if (X_MEMBER && !($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member')) {

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

/* Set Up HTML Templates and Themes */

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

// U2U Status Mod Begin
// Assert U2U Status Translation
if (!isset($lang['u2ustatus'])) {
    require_once(ROOT.'include/translation.inc.php');
    $phrases = array();
    $phrases['u2ustatus'] = "U2U Status:<br /><small>(Disabled for members only.)</small>";
    $phrases['u2ustatusdisabled'] = "Sorry, the board administrator has disabled the U2U messenger.";
    setManyLangValues($phrases, $langfile);
    loadLang($langfile);
}
// U2U Status Mod End

=======================================================================================================================================
=======
Step 4:
=======

====================
Edit File: index.php
====================

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

loadtemplates(

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

'index_welcome_member_u2u',

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

        eval('$welcome = "'.template('index_welcome_member').'";');

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

        // U2U Status Mod Begin
        $u2ublock = '';
        if (X_MEMBER && !($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member')) {
            eval('$u2ublock = "'.template('index_welcome_member_u2u').'";');
        }
        // U2U Status Mod End

=======================================================================================================================================
=======
Step 5:
=======

=====================
Edit File: member.php
=====================

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

        if (X_GUEST) {
            $memberlinks = '';
        } else {
            $memberlinks = " <small>(<a href=\"u2u.php?action=send&amp;username=$encodeuser\" onclick=\"Popup(this.href, 'Window', 700, 450); return false;\">{$lang['textu2u']}</a>)&nbsp;&nbsp;(<a href=\"buddy.php?action=add&amp;buddys=$encodeuser\" onclick=\"Popup(this.href, 'Window', 450, 400); return false;\">{$lang['addtobuddies']}</a>)</small>";
        }

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

        // U2U Status Mod Begin
        $u2ulink = '';
        if (X_MEMBER && !($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member')) {
            $u2ulink = "(<a href=\"u2u.php?action=send&amp;username=$encodeuser\" onclick=\"Popup(this.href, 'Window', 700, 450); return false;\">{$lang['textu2u']}</a>)&nbsp;&nbsp;";
        }

        if (X_GUEST) {
            $memberlinks = '';
        } else {
            $memberlinks = " <small>$u2ulink(<a href=\"buddy.php?action=add&amp;buddys=$encodeuser\" onclick=\"Popup(this.href, 'Window', 450, 400); return false;\">{$lang['addtobuddies']}</a>)</small>";
        }
        // U2U Status Mod End

=======================================================================================================================================
=======
Step 6:
=======

====================
Edit File: memcp.php
====================

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

loadtemplates(

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

'memcp_home_u2u',

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

    $u2uquery = $db->query("SELECT * FROM ".X_PREFIX."u2u WHERE owner='$xmbuser' AND folder='Inbox' ORDER BY dateline DESC LIMIT 0, 5");
    $u2unum = $db->num_rows($u2uquery);
    $messages = '';
    $tmOffset = ($timeoffset * 3600) + ($addtime * 3600);
    while($message = $db->fetch_array($u2uquery)) {
        $postdate = gmdate($dateformat, $message['dateline'] + $tmOffset);
        $posttime = gmdate($timecode, $message['dateline'] + $tmOffset);
        $senton = $postdate.' '.$lang['textat'].' '.$posttime;

        $message['subject'] = rawHTMLsubject(stripslashes($message['subject']));
        if ($message['subject'] == '') {
            $message['subject'] = '&laquo;'.$lang['textnosub'].'&raquo;';
        }

        if ($message['readstatus'] == 'yes') {
            $read = $lang['textread'];
        } else {
            $read = $lang['textunread'];
        }
        eval('$messages .= "'.template('memcp_home_u2u_row').'";');
    }

    if ($u2unum == 0) {
        eval('$messages = "'.template('memcp_home_u2u_none').'";');
    }
    $db->free_result($u2uquery);

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

    $u2ublock = '';
    if (!($SETTINGS['u2ustatus'] == 'off' && isset($self['status']) && $self['status'] == 'Member')) {
        $u2uquery = $db->query("SELECT * FROM ".X_PREFIX."u2u WHERE owner='$xmbuser' AND folder='Inbox' ORDER BY dateline DESC LIMIT 0, 5");
        $u2unum = $db->num_rows($u2uquery);
        $messages = '';
        $tmOffset = ($timeoffset * 3600) + ($addtime * 3600);
        while($message = $db->fetch_array($u2uquery)) {
            $postdate = gmdate($dateformat, $message['dateline'] + $tmOffset);
            $posttime = gmdate($timecode, $message['dateline'] + $tmOffset);
            $senton = $postdate.' '.$lang['textat'].' '.$posttime;

            $message['subject'] = rawHTMLsubject(stripslashes($message['subject']));
            if ($message['subject'] == '') {
                $message['subject'] = '&laquo;'.$lang['textnosub'].'&raquo;';
            }

            if ($message['readstatus'] == 'yes') {
                $read = $lang['textread'];
            } else {
                $read = $lang['textunread'];
            }
            eval('$messages .= "'.template('memcp_home_u2u_row').'";');
        }

        if ($u2unum == 0) {
            eval('$messages = "'.template('memcp_home_u2u_none').'";');
        }
        $db->free_result($u2uquery);
        eval('$u2ublock = "'.template('memcp_home_u2u').'";');
    }

=======================================================================================================================================
=======
Step 7:
=======

==================
Edit File: u2u.php
==================

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

if (X_GUEST) {
    redirect("{$full_url}misc.php?action=login", 0);
    exit;
}

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

// U2U Status Mod Begin
if ($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member') {
    error($lang['u2ustatusdisabled'], false, $u2uheader, $u2ufooter, false, true, false, false);
}
// U2U Status Mod End

=======================================================================================================================================
=======
Step 8:
=======

=========================
Edit File: viewthread.php
=========================

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

            if (X_GUEST) {
                $u2u = '';
            } else {
                eval('$u2u = "'.template('viewthread_post_u2u').'";');
            }

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

            // U2U Status Mod Begin
            $u2u = '';
            if (X_MEMBER && !($SETTINGS['u2ustatus'] == 'off' && $self['status'] == 'Member')) {
                eval('$u2u = "'.template('viewthread_post_u2u').'";');
            }
            // U2U Status Mod End

=======================================================================================================================================
=======
Step 9:
=======

======================================================
Go to admin panel -> templates -> index_welcome_member
======================================================

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

<td width="33%"><a href="u2u.php" onclick="Popup(this.href,'Window', 700, 450); return false;"><strong>{$lang['textu2umessenger']}</strong></a></td>

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

$u2ublock

=======================================================================================================================================
========
Step 11:
========

============================================
Go to admin panel -> templates -> memcp_home
============================================

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

<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
<tr>
<td bgcolor="$bordercolor">
<table border="0" cellspacing="{$THEME['borderwidth']}" cellpadding="$tablespace" width="100%">
<tr class="category">
<td colspan="4"><font color="$cattext"><strong>$lang[textlatestu2us]</strong></font></td>
</tr>
<tr class="header">
<td>$lang[textsubject]</td>
<td>$lang[textfrom]</td>
<td>$lang[textsent]</td>
<td>$lang[mcpread]</td>
</tr>
$messages
<tr>
<td colspan="4" class="header" valign="top"><a href="u2u.php" onclick="Popup(this.href,'Window', 700, 450); return false;">{$lang['viewcompleteinbox']}</a></td>
</tr>
</table>
</td>
</tr>
</table>

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

$u2ublock

=======================================================================================================================================
========
Step 12:
========

==========================================================
Go to admin panel -> templates -> create -> memcp_home_u2u
==========================================================

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

<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center">
<tr>
<td bgcolor="$THEME[bordercolor]">
<table border="0" cellspacing="{$THEME['borderwidth']}" cellpadding="$THEME[tablespace]" width="100%">
<tr class="category">
<td colspan="4"><font color="$THEME[cattext]"><strong>$lang[textlatestu2us]</strong></font></td>
</tr>
<tr class="header">
<td>$lang[textsubject]</td>
<td>$lang[textfrom]</td>
<td>$lang[textsent]</td>
<td>$lang[mcpread]</td>
</tr>
$messages
<tr>
<td colspan="4" class="header" valign="top"><a href="u2u.php" onclick="Popup(this.href,'Window', 700, 450); return false;">{$lang['viewcompleteinbox']}</a></td>
</tr>
</table>
</td>
</tr>
</table>

=======================================================================================================================================
========
Step 14:
========

====================================================================
Go to admin panel -> templates -> create -> index_welcome_member_u2u
====================================================================

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

<td width="33%"><a href="u2u.php" onclick="Popup(this.href,'Window', 700, 450); return false;"><strong>{$lang['textu2umessenger']}</strong></a></td>

=======================================================================================================================================================