============================================================================================================================
Title: Registration Notification By Username

Author: John Briggs

Version: 1.0

Description:
This modification will replace the redundant notification tool that contacts all super admins on new reg notifications.
This modification will provide a new tool in Admin Panel --> Settings to choose what username(s) you want new registration notices sent to.
This modification will provide the option of assigning single or multiple usernames for notification.

Copyright:  2009 John Briggs. All rights reserved.

Compatibility: XMB 1.9.8 SP4

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

Author Note: This modification is developed and released for use with XMB 1.9.8 SP4 which is provided by XMBGarage.com.

============================================================================================================================
=======
Step 1:
=======
==============================
Go To Admin Panel --> Insert Raw SQL
==============================
=======================================
Copy & Paste Code Below & click "Submit Changes"
=======================================

ALTER TABLE `$table_settings` ADD `usernamenotify` text NOT NULL;

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

        $query = $db->query("SELECT fid, lastpost FROM ".X_PREFIX."forums WHERE lastpost LIKE '%$userfrom'");
        while($result = $db->fetch_array($query)) {
            list($posttime, $lastauthor, $lastpid) = explode("|", $result['lastpost']);
            if ($lastauthor == $userfrom) {
                $newlastpost = $posttime . '|' . $userto.'|'.$lastpid;
                $db->query("UPDATE ".X_PREFIX."forums SET lastpost='$newlastpost' WHERE fid='".$result['fid']."'");
            }
        }
        $db->free_result($query);

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

        // Registration Notification By Username Mod Begin
        $query = $db->query("SELECT usernamenotify FROM ".X_PREFIX."settings WHERE usernamenotify LIKE '%$userfrom%'");
        while($list = $db->fetch_array($query)) {
            $parts = explode(',', $list['usernamenotify']);
            for($i = 0; $i < count($parts); $i++) {
                if (trim($parts[$i]) == $userfrom) {
                    $parts[$i] = $userto;
                    break;
                }
            }
            $parts = implode(', ', $parts);
            $db->query("UPDATE ".X_PREFIX."settings SET usernamenotify='".$parts."' WHERE usernamenotify='".$list['usernamenotify']."'");
        }
        $db->free_result($query);
        // Registration Notification By Username Mod End

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

        printsetting3($lang['notifyonreg'], 'notifyonregnew', array($lang['textoff'], $lang['viau2u'], $lang['viaemail']), array('off', 'u2u', 'email'), $notifycheck, false);

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

        // Registration Notification By Username Mod Begin
        printsetting4($lang['notify'], 'usernamenotifynew', stripslashes($SETTINGS['usernamenotify']), 5, 50);
        // Registration Notification By Username Mod End

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

        $u2uattachstatusnew = formOnOff('u2uattachstatusnew');

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

        // Registration Notification By Username Mod Begin
        $usernamenotifynew = postedVar('usernamenotifynew');
        // Registration Notification By Username Mod End

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

        $db->query("UPDATE ".X_PREFIX."settings SET

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

            usernamenotify='$usernamenotifynew',

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

            if ($SETTINGS['notifyonreg'] != 'off') {
                $mailquery = $db->query("SELECT username, email, langfile FROM ".X_PREFIX."members WHERE status='Super Administrator'");
                while($admin = $db->fetch_array($mailquery)) {
                    if ($SETTINGS['notifyonreg'] == 'u2u') {
                        $db->query("INSERT INTO ".X_PREFIX."u2u (u2uid, msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('', '$admin[username]', '".$db->escape_var($bbname)."', 'incoming', '$admin[username]', 'Inbox', '$lang[textnewmember]', '$lang[textnewmember2]', '".$onlinetime."', 'no', 'yes')");
                    } else {
                        $rawuser = postedVar('username', '', FALSE, FALSE);
                        $headers = array();
                        $headers[] = "From: $bbname <$adminemail>";
                        $headers[] = 'X-Mailer: PHP';
                        $headers[] = 'X-AntiAbuse: Board servername - '.$cookiedomain;
                        $headers[] = 'X-AntiAbuse: Username - '.$rawuser;
                        $headers[] = 'Content-Type: text/plain; charset='.$charset;
                        $headers = implode("\r\n", $headers);
                        $adminemail = htmlspecialchars_decode($admin['email'], ENT_QUOTES);
                        altMail($adminemail, $lang['textnewmember'], $lang['textnewmember2']."\n\n$full_url", $headers);
                    }
                }
                $db->free_result($mailquery);
            }

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

            // Registration Notification By Username Mod Begin
            if ($SETTINGS['notifyonreg'] != 'off') {
                if ($SETTINGS['notifyonreg'] == 'u2u') {
                    if (!empty($SETTINGS['usernamenotify'])) {
                        $member = explode(',', $SETTINGS['usernamenotify']);
                        for($i = 0; $i < count($member); $i++) {
                            $member[$i] = trim($member[$i]);
                            $mailquery = $db->query("SELECT * FROM ".X_PREFIX."members WHERE username='$member[$i]'");
                            while($admin = $db->fetch_array($mailquery)) {
                                $usernameurl = '<a href="member.php?action=viewpro&amp;member='.recodeOut($username).'" target="_blank"><strong>'.$username.'</strong></a>';
                                $db->query("INSERT INTO ".X_PREFIX."u2u (u2uid, msgto, msgfrom, type, owner, folder, subject, message, dateline, readstatus, sentstatus) VALUES ('', '$admin[username]', '$admin[username]', 'incoming', '$admin[username]', 'Inbox', '".$lang['newmember']." ".$db->escape_var($bbname)."', '$lang[newmember2]\n\n$usernameurl', '".$onlinetime."', 'no', 'yes')");
                            }
                            $db->free_result($mailquery);
                        }
                    }
                } else {
                    if ($SETTINGS['notifyonreg'] == 'email') {
                        if (!empty($SETTINGS['usernamenotify'])) {
                            $member = explode(',', $SETTINGS['usernamenotify']);
                            for($i = 0; $i < count($member); $i++) {
                                $member[$i] = trim($member[$i]);
                                $rawuser = postedVar('username', '', FALSE, FALSE);
                                $headers = array();
                                $headers[] = "From: $SETTINGS[bbname] <$SETTINGS[adminemail]>";
                                $headers[] = 'X-Mailer: PHP';
                                $headers[] = 'X-AntiAbuse: Board servername - '.$cookiedomain;
                                $headers[] = 'X-AntiAbuse: Username - '.$rawuser;
                                $headers[] = 'Content-Type: text/plain; charset='.$charset;
                                $headers = implode("\r\n", $headers);
                                $mailquery = $db->query("SELECT * FROM ".X_PREFIX."members WHERE username='$member[$i]'");
                                while($notify = $db->fetch_array($mailquery)) {
                                    $notify['email'] = htmlspecialchars_decode($notify['email'], ENT_QUOTES);
                                    $usernameurl = $full_url."member.php?action=viewpro&member=$rawuser";
                                    altMail($notify['username'].'<'.$notify['email'].'>', $lang['newmember'].' '.$SETTINGS['bbname'], $lang['newmember2']."\n\n".$usernameurl, $headers);
                                }
                                $db->free_result($mailquery);
                            }
                        }
                    }
                }
            }
            // Registration Notification By Username Mod End

============================================================================================================================
=======
Step 5:
=======
=======================
Edit File: lang/English.lang.php
=======================
==========
Find Code:
==========

$lang['notifyonreg'] = 'Notify (Super-)Administrator on new registrations';

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

// Registration Notification By Username Mod Begin
$lang['notifyonreg'] = "New Member Registration Notification Status:";
// Registration Notification By Username Mod End

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

// Registration Notification By Username Mod Begin
$lang['newmember'] = "New member signed up at ";
$lang['newmember2'] = "This is an automatic email. To disable this option you must turn it to OFF in Settings Panel.\n\n The following new member has signed up:";
$lang['notify'] = "Email/U2U Notification List:<br /><small>Put the username(s) you want to receive Email/U2U notifications here.<br />Separate names with commas (i.e. 'Person 1, Person 2').<br />Names are also case sensitive.</small>";
// Registration Notification By Username Mod End

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