============================================================================================================================
Modification Title: Username Change Request Form

Version: 1.0

Author: GuldantheWarlock

Updated by : Ahmad

Description:
This modification will add a form to the memcp area that will allow a user to fill out a form requesting a username change.
This modification will allow you to specify in Settings which Super Admins should recieve the request.

Compatability: XMB 1.9.5 SP1

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 v3. A copy is provided with this software package.

Author Note:
You downloaded this hack 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 provided file named "SQL.txt" and click "Submit Changes".

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

        $doubleeon = $doubleeoff = '';
        if ($SETTINGS['doublee'] == "on") {
            $doubleeon = $selHTML;
        } else {
            $doubleeoff = $selHTML;
        }
        
===============
Add Code Below:
===============

        // Username Change Request Form Mod Begin
        $ucrfon = $ucrfoff = '';
        switch ($SETTINGS['ucrfstatus']) {
            case 'on':
                $ucrfon = $selHTML;
                break;
            default:
                $ucrfoff = $selHTML;
                break;
        }
        // Username Change Request Form Mod End
        
==========
Find Code:
==========

        $SETTINGS['bbrulestxt'] = stripslashes($SETTINGS['bbrulestxt']);
        
===============
Add Code Below:
===============

        // Username Change Request Form Mod Begin
        $SETTINGS['ucrfcontact'] = stripslashes($SETTINGS['ucrfcontact']);
        // Username Change Request Form Mod End
        
==========
Find Code:
==========

        printsetting1($lang['doublee'], 'doubleenew', $doubleeon, $doubleeoff);
        
===============
Add Code Below:
===============

        // Username Change Request Form Mod Begin
        printsetting1($lang['ucrflang2'], 'ucrfstatusnew', $ucrfon, $ucrfoff);
        // Username Change Request Form Mod End
        
==========================
Find Code (Just Below That Line):
==========================

        ?>
        
===============
Add Code Below:
===============

        <!-- Username Change Request Form Mod Begin -->
        <tr class="tablerow">
        <td bgcolor="<?php echo $altbg1?>"><?php echo $lang['ucrflang3']?></td>
        <td bgcolor="<?php echo $altbg2?>"><textarea rows="5" name="ucrfcontactnew" cols="50"><?php echo $SETTINGS['ucrfcontact']?></textarea></td>
        </tr>
        <!-- Username Change Request Form Mod End -->
        
==========
Find Code:
==========

        $bbrulestxtnew = addslashes($bbrulestxtnew);
        
===============
Add Code Below:
===============

        // Username Change Request Form Mod Begin
        $ucrfcontactnew = addslashes($ucrfcontactnew);
        // Username Change Request Form Mod End

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

        $resetSigNew = ($resetSigNew == 'on') ? 'on' : 'off';

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

        // Username Change Request Form Mod Begin
        $ucrfstatusnew = ($ucrfstatusnew == 'on') ? 'on' : 'off';
        // Username Change Request Form Mod End
        
==========
Find Code:
==========

        $db->query("UPDATE $table_settings SET

======================
Find Code (At End Of Line):
======================

");   

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

, ucrfstatus='$ucrfstatusnew', ucrfcontact='$ucrfcontactnew'"); 

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

loadtemplates(

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

loadtemplates(
'memcp_changeusername',

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

    case "favorites":
        nav('<a href="memcp.php">'.$lang['textusercp'].'</a>');
        nav($lang['textfavorites']);
        break;
        
===============
Add Code Below:
===============

    // Username Change Request Form Mod Begin
    case "changeusername":
        nav('<a href="memcp.php">'.$lang['textusercp'].'</a>');
        nav($lang['ucrflang1']);
        break;
    // Username Change Request Form Mod End

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

    global $bordercolor, $tablewidth, $borderwidth, $tablespacing, $altbg1, $altbg2, $lang;
    
================
Replace Code With:
================

    global $bordercolor, $tablewidth, $borderwidth, $tablespacing, $altbg1, $altbg2, $lang, $SETTINGS;
        
==========
Find Code:
==========

    if ($current == "profile") {
        echo "<td bgcolor=\"$altbg1\" width=\"15%\" class=\"ctrtablerow\">" .$lang['texteditpro']. "</td>";
    } else {
        echo "<td bgcolor=\"$altbg2\" width=\"15%\" class=\"ctrtablerow\"><a href=\"memcp.php?action=profile\">" .$lang['texteditpro']. "</a></td>";
    }
    
===============
Add Code Below:
===============

    // Username Change Request Form Mod Begin
    if ($SETTINGS['ucrfstatus'] == "on") {
        if ($current == "changeusername") {
            echo "<td bgcolor=\"$altbg1\" width=\"15%\" class=\"ctrtablerow\">" .$lang['ucrflang1']. "</td>";
        } else {
            echo "<td bgcolor=\"$altbg2\" width=\"15%\" class=\"ctrtablerow\"><a href=\"memcp.php?action=changeusername\">" .$lang['ucrflang1']. "</a></td>";
        }
    }
    // Username Change Request Form Mod End
    
==========
Find Code:
==========

} elseif ($action == 'favorites') {

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

// Username Change Request Form Mod Begin
} elseif ($action == 'changeusername') {
    if ($SETTINGS['ucrfcontact'] != 'off') {
        if (isset($requestsubmit)) {
            eval('echo ("'.template('header').'");');
            makenav($action);
            $newname = trim($newname);
            $newnameok = true;
            
            $find = array('<', '>', '|', '"', '[', ']', '\\', ',', '@', '\'', ' '); 
            foreach ($find as $needle) { 
                if (false !== strpos($newname, $needle)) { 
                    $newnameok = false;
                }
            }
    
            $query = $db->query("SELECT * FROM $table_restricted");
            while ($restriction = $db->fetch_array($query)) {
                if ($restriction['case_sensitivity'] == 1) {
                    if ($restriction['partial'] == 1) {
                        if (strpos($newname, $restriction['name']) !== false) {
                            $newnameokay = false;
                        }
                    } else {
                        if ($newname == $restriction['name']) {
                            $newnameokay = false;
                        }
                    }
                } else {
                    $t_username = strtolower($newname);
                    $restriction['name'] = strtolower($restriction['name']);
    
                    if ($restriction['partial'] == 1) {
                        if (strpos($t_username, $restriction['name']) !== false) {
                            $newnameokay = false;
                        }
                    } else {
                        if ($t_username == $restriction['name']) {
                            $newnameokay = false;
                        }
                    }
                }
            }
            $db->free_result($query);
            
            if ($newnameok) {
                $olduser = trim($currentuser);
                $comment = addslashes($comment);
                $subject = str_replace('*USER*', $olduser, $lang['ucrflang9']);
                
                $message   = array();
                $message[] = str_replace('*OLDUSER*', $olduser, $lang['ucrflang10']);
                $message[] = "\n[b]".$lang['ucrflang6']."[/b] $olduser";
                $message[] = "\n[b]".$lang['ucrflang7']."[/b] $newname";
                $message[] = "\n[b]".$lang['ucrflang8']."[/b] $comment";
                $message   = implode("\n", $message);
                
                if (false === strpos($SETTINGS['ucrfcontact'], ",")) {
                    $admin = trim($SETTINGS['ucrfcontact']);
                    $db->query("INSERT INTO $table_u2u (u2uid, msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('', '$admin', '$olduser', 'incoming', '$admin', 'Inbox', '$subject', '$message', '" . time() . "', 'no', 'yes')");
                } else {
                    $admins = explode(',', $SETTINGS['ucrfcontact']);
                    foreach($admins as $admin) {
                        $admin = trim($admin);
                        $query = $db->query("SELECT uid FROM $table_members WHERE username='$admin'");
                        if ($db->num_rows($query) != 0) {
                            $db->query("INSERT INTO $table_u2u (u2uid, msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('', '$admin', '$olduser', 'incoming', '$admin', 'Inbox', '$subject', '$message', '" . time() . "', 'no', 'yes')");
                        }
                    }
                }         
                echo "<center><span class=\"mediumtxt \">" .$lang['ucrflang12']. "</span></center>";
                redirect('memcp.php', 2, X_REDIRECT_JS);
            } else {
                echo "<center><span class=\"mediumtxt \">" .$lang['restricted']. "</span></center>";
                redirect('memcp.php?action=changeusername', 2, X_REDIRECT_JS);
            }
        } else {
            eval('echo "'.template("header").'";');
            makenav($action);
            eval('echo stripslashes("'.template('memcp_changeusername').'");');
        }
    } else {
        error($lang['ucrflang11']);
    }
    // Username Change Request Form Mod End

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

// Username Change Request Form Mod Begin
$lang['ucrflang1'] = "Change Username";
$lang['ucrflang2'] = "Username Change Request Form Status:";
$lang['ucrflang3'] = "Usernames who the request form should be sent to:<br /><font class=\"smalltxt\">Separate Usernames with a comma.</font>";
$lang['ucrflang4'] = "Fill out the form below to request a username change:";
$lang['ucrflang5'] = "Submit Request";
$lang['ucrflang6'] = "Current Username:";
$lang['ucrflang7'] = "New Username:";
$lang['ucrflang8'] = "Comment:";
$lang['ucrflang9'] = "Username Change Request (*USER*)";
$lang['ucrflang10'] = "The User *OLDUSER* has requested a Username change. Here are the details that were submitted:";
$lang['ucrflang11'] = "Sorry! But Username Change Requests have been disabled. Please try again later.";
$lang['ucrflang12'] = "Thank you! Your Username Change Request has been received. You will be contacted by an Administrator about it soon.";
// Username Change Request Form Mod End

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

<form action="memcp.php?action=changeusername" method="POST">
<table cellspacing="0" cellpadding="0" border="0" width="550" align="center">
<tr>
<td bgcolor="$bordercolor">
<table border="0" cellspacing="$borderwidth" cellpadding="$tablespace" width="100%">
<tr>
<td class="category" colspan="2"><strong><font color="$cattext">$lang[ucrflang1]</font></strong></td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg2" colspan="2" align="center">$lang[ucrflang4]</td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[ucrflang6]</td>
<td bgcolor="$altbg2"><input type="hidden" name="currentuser" value="$xmbuser" />$xmbuser</td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[ucrflang7]</td>
<td bgcolor="$altbg2"><input type="text" name="newname" size="25" /></td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg1" width="22%">$lang[ucrflang8]</td>
<td bgcolor="$altbg2"><textarea rows="5" name="comment" cols="50"></textarea></td></td>
</tr>
<tr class="tablerow">
<td bgcolor="$altbg2" colspan="2" align="center"><input type="submit" class="submit" name="requestsubmit" value="$lang[ucrflang5]" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

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