Modification Title: Username/Email Check on Reg v1.0

Modification Author: Area51mafia

Last Updated: 05/05/09

Modification Description:
This modification will automatically check the username for prior existence upon registration.
This modification will automatically check the email for prior existence upon registration.

Supported Version: XMB 1.9.8 SP3

Updated for 1.9.8 by: WormHole @ XMB Garage

Installation 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 package.

=======================================================================================================================
=======
Step 1:
=======
=================
Edit File: member.php
=================

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

    case 'reg':
        if ($SETTINGS['pruneusers'] > 0) {

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

    // Check Username/Email on Reg. Mod Begin
    case 'checkname':
        header('Content-Type: text/xml');
        if (isset($_GET['username'])) {
            $nameinuse = nameInUse($_GET['username']);
        } else {
            $nameinuse = '0';
        }
        echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><result>' . $nameinuse . '</result></response>';
        exit;
        break;

    case 'checkemail':
        header('Content-Type: text/xml');
        if (isset($_GET['email'])) {
            $emailinuse = emailInUse($_GET['email']);
        } else {
            $emailinuse = '0';
        }
        echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><result>' . $emailinuse . '</result></response>';
        exit;
        break;
    // Check Username/Email on Reg. Mod End

=======================================================================================================================
=======
Step 2:
=======
=================
Edit File: header.php
=================

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

if ($action != 'attachment' && !($action == 'templates' && isset($download)) && !($action == 'themes' && isset($download))) {

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

if ($action != 'attachment' && !($action == 'templates' && isset($download)) && !($action == 'themes' && isset($download) && !($action == 'checkname') && !($action == 'checkemail'))) {


=======================================================================================================================
=======
Step 3:
=======
=======================
Edit File: include/functions.php
=======================
==========
Find Code:
==========

function validateTpp() {
    global $tpp, $topicperpage;

    if (!isset($tpp) || $tpp == '') {
        $tpp = $topicperpage;
    } else {
        $tpp = is_numeric($tpp) ? (int) $tpp : $topicperpage;
    }

    if ($tpp < 5) {
        $tpp = 30;
    }
}

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

// Check Username/Email on Reg. Mod Begin
function nameInUse($username) {
    global $db;
    if (isset($username)){
        $username = trim($username);
        $query = $db->query("SELECT count(username) FROM ".X_PREFIX."members WHERE username='$username'");
        if ($db->result($query, 0) == '1') {
            return '1';
        } else {
            return '0';
        }
    } else {
        return '0';
    }
}

function emailInUse($email) {
    global $db;
    if (isset($email)){
        $email = addslashes(trim($email));
        $query = $db->query("SELECT count(email) FROM ".X_PREFIX."members WHERE email='$email'");
        if ($db->result($query, 0) == '1') {
            return '1';
        } else {
            return '0';
        }
    } else {
        return '0';
    }
}
// Check Username/Email on Reg. Mod End

=======================================================================================================================
=======
Step 4:
=======
===================
Edit file English.lang.php:
===================

============================
Add Code To End Of File Above ?>
============================

// Check Username/Email on Reg. Mod Begin
$lang['ajaxreg_namefailed'] = "&nbsp;This name is in use. Please try another.";
$lang['ajaxreg_emailfailed'] = "&nbsp;This email is in use. Please try another.";
// Check Username/Email on Reg. Mod End

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

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

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

<td bgcolor="$altbg2"><input type="text" name="username" size="25" maxlength="25" /></td>

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

<td bgcolor="$THEME[altbg2]"><input type="text" id="username" name="username" onblur="checkName(this.value,'')" size="25" maxlength="25" /><span class="hidden" id="nameCheckFailed">$lang[ajaxreg_namefailed]</span></td>

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

<td bgcolor="$altbg2"><input type="text" name="email" size="25" /></td>

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

<td bgcolor="$THEME[altbg2]"><input type="text" id="email" name="email" onblur="checkEmail(this.value,'')" size="25" /><span class="hidden" id="emailCheckFailed">$lang[ajaxreg_emailfailed]</span></td>

=======================================================================================================================
=======
Step 6:
=======
=============================
Go to admin panel -> templates -> css
=============================
==========
Find Code:
==========

/*]]>*/
</style>
$cssInclude

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

span.hidden{
    display: none;
}

span.error{
    display: inline;
    color: $tabletext;
}

=======================================================================================================================
=======
Step 7:
=======
===============================
Go to admin panel -> templates -> header
===============================
============================
If this is the first AJAX hack installed:
============================
==========
Find Code:
==========

<script language="JavaScript" type="text/javascript" src="./js/u2uheader.js"></script>

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

<script language="JavaScript" type="text/javascript" src="./js/xmlhttprequest.js"></script>
<script language="JavaScript" type="text/javascript" src="./js/xmlhttprequest_checkreg.js"></script>

================================
If this IS NOT the first AJAX hack installed:
================================

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

<script language="JavaScript" type="text/javascript" src="./include/xmlhttprequest.js"></script>

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

<script language="JavaScript" type="text/javascript" src="./include/xmlhttprequest_checkreg.js"></script>

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

Upload provided file named "xmlhttprequest.js" to your forum "/js/" directory.
Upload provided file named "xmlhttprequest_checkreg.js" to your forum "/js/" directory.

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