Modification Name: Advanced Debug System v1.0

Modification Author: Adam Clarke

Minor 1.9.3 Update by: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)
Minor 1.9.5 Update by: WormHole (XMB Garage)
Updated for 1.9.8 by: WormHole (XMB Garage)

Last Updated: July 25, 2009

Modification Description:
This modification will allow you to enable DEBUG mode via the Administration Panel.
This modification will also allow you specify which Member Status can see the debug messages.

Supported Version: XMB 1.9.8 SP3/SP4

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

Please backup your files before installing this modification. Neither XMBGarage nor the author can be held 
responsible if your board stops functioning properly due to you installing this modification.

=======================================================================================================
=======
Step 1:
=======
==================================
Go to Administration Panel -> Insert Raw SQL
==================================
==============================
Paste the following code and click submit
==============================

ALTER TABLE `$table_settings` ADD `debugstatus` int(1) NOT NULL default '0';

=======================================================================================================
=======
Step 2:
=======
=======================
Edit File: lang/English.lang.php
=======================
=======================
Add To End Of File Above ?>
=======================

// Advanced Debug System Mod Begin
$lang['admin_debug_settings'] = 'Debug Settings';
$lang['textdebugstatus'] = 'Enable Debuging For:';
$lang['textdebug1'] = 'Admins';
$lang['textdebug2'] = 'All Staff';
$lang['textdebug3'] = 'All Members';
$lang['textdebug4'] = 'Everyone';
// Advanced Debug System Mod End

=======================================================================================================
=======
Step 3:
=======
==============
Edit File: cp.php
==============
======
Find:
======

        $langfileselect = createLangFileSelect($SETTINGS['langfile']);
    
==========
Add Below:
==========

        // Advanced Debug System Mod Begin
        $debugchecked[0] = $debugchecked[1] = $debugchecked[2] = $debugchecked[3] = $debugchecked[4] = false;
        if ($SETTINGS['debugstatus'] == '1') {
            $debugchecked[1] = true;
        } elseif ($SETTINGS['debugstatus'] == '2') {
            $debugchecked[2] = true;
        } elseif ($SETTINGS['debugstatus'] == '3') {
            $debugchecked[3] = true;
        } elseif ($SETTINGS['debugstatus'] == '4') {
            $debugchecked[4] = true;
        } else {
            $debugchecked[0] = true;
        }
        // Advanced Debug System Mod End

=====
Find:
=====

        <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $tablespace?>" width="100%">
        <tr class="category">
        <td colspan="2"><strong><font color="<?php echo $cattext?>"><?php echo $lang['admin_main_settings1']?></font></strong></td>
        </tr>
        
=============
Replace With:
=============

        <!-- Advanced Debug System Mod Begin -->
        <table border="0" cellspacing="<?php echo $THEME['borderwidth']?>" cellpadding="<?php echo $THEME['tablespace']?>" width="100%">
        <tr class="category">
        <td colspan="2"><strong><font color="<?php echo $THEME['cattext']?>">&raquo;&nbsp;<?php echo $lang['admin_debug_settings']?></font></strong></td>
        </tr>
        <?php
        printsetting3($lang['textdebugstatus'], 'debugstatusnew', array($lang['textoff'], $lang['textdebug1'], $lang['textdebug2'], $lang['textdebug3'], $lang['textdebug4']), array('0', '1', '2', '3', '4'), $debugchecked, false);
        ?>
        <!-- Advanced Debug System Mod End -->
        <tr>
        <td class="tablerow" bgcolor="<?php echo $THEME['altbg2']?>" colspan="2">&nbsp;</td>
        </tr>
        <tr>
        <td bgcolor="<?php echo $THEME['altbg1']?>" colspan="2" class="category"><strong><font color="<?php echo $THEME['cattext']?>">&raquo;&nbsp;<?php echo $lang['admin_main_settings1']?></font></strong></td>
        </tr>

======
Find:
======

        $onlinetoday_statusnew = formOnOff('onlinetoday_statusnew');

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

        // Advanced Debug System Mod Begin
        $debugstatusnew = postedVar('debugstatusnew');
        // Advanced Debug System Mod End
        
======
Find:
======

        $db->query("UPDATE ".X_PREFIX."settings SET
        
============
Replace With:
============

        $db->query("UPDATE ".X_PREFIX."settings SET
            debugstatus='$debugstatusnew',

=======================================================================================================
=======
Step 4:
=======
================
Edit File: config.php:
================
=============
Find and Delete
=============

// Resolving serveral modes (currently, 2)
// Debug-mode
    /*
    / To turn on DEBUG mode (you can then see ALL queries done at the bottom of each screen (except buddy-list & u2u)
    / just uncomment this variable. These queries are ONLY visible to the user currently loading that page
    / and ONLY visible to Super Administrators
    /
    / SECURITY NOTICE: DO NOT COMMENT OUT UNLESS YOU KNOW WHAT YOU'RE DOING!
    */
    define('DEBUG', false);
    // define('DEBUG', true);
    //
    /*
    / Comment first line and uncomment second line to use debug mode (1.9+ only). Only one define can be
    / active as define is immutable once set.
    */

=======================================================================================================
=======
Step 5:
=======
=================
Edit File: header.php:
=================
=============
Find and Delete
=============

if (DEBUG) {
    error_reporting(E_ALL | E_STRICT | E_DEPRECATED);
}

=========================
Find and Delete (on 2 occasions)
=========================

.(DEBUG === true ? ' (Debug Mode)' : '')

======
Find:
======

if (file_exists(ROOT.'lang/'.$langfile.'.lang.php')) {
    require ROOT.'lang/'.$langfile.'.lang.php';
} else {
    require ROOT.'lang/English.lang.php';
}
    
==========
Add Above:
==========

// Advanced Debug System Mod Begin
if ((X_ADMIN && $SETTINGS['debugstatus'] == '1') || (X_STAFF && $SETTINGS['debugstatus'] == '2') || (X_MEMBER && $SETTINGS['debugstatus'] == '3') || $SETTINGS['debugstatus'] == '4') {
    error_reporting(E_ALL);
    define('DEBUG', true);
} else {
    define('DEBUG', false);
}
    
$versionlong = (DEBUG) ? $versionlong.' (Debug Mode)' : $versionlong;
// Advanced Debug System Mod End

=======================================================================================================
=======
Step 6:
=======
=========================
Edit File: include/functions.inc.php
=========================
==================
Find (On 3 Occasions)
==================

X_SADMIN && DEBUG

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

DEBUG

=======================================================================================================
=======
Step 7:
=======
==================
Edit File: db/mysql.php:
==================
======
Find:
======

        if (X_SADMIN && DEBUG) {

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

        // Advanced Debug System Mod Begin
        if (defined('DEBUG') && DEBUG) {
        // Advanced Debug System Mod End

======
Find:
======

            echo '<pre>The system has failed to process your request. If you\'re an administrator, please set the DEBUG flag to true in config.php.</pre>';

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

            // Advanced Debug System Mod Begin
            echo '<pre>The system has failed to process your request. If you\'re an administrator, please set the DEBUG flag to true in the Administration Panel.</pre>';
           // Advanced Debug System Mod End

=======================================================================================================
Enjoy