<?php
/********************************************************/
/* NSN Your Account                                     */
/* By: NukeScripts Network (webmaster@nukescripts.fr)   */
/* http://www.nukescripts.fr                            */
/* Original Script www.nukescripst.net                  */
/* Copyright  2000-2005 by NukeScripts Network         */
/* ==================================================== */
/* Based from:                                          */
/* PHP-NUKE: Web Portal System                          */
/********************************************************/
if (!defined('IN_YA')) { die("You can't access this file directly."); }
if (!defined('MAXIMUS')) {
redirect_url("index.php");
  die();
}

        $result  = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_USERS."` WHERE `username`='$username'");
        $setinfo = $GLOBALS['db']->sql_fetchrow($result);
        $forward = ereg_replace("redirect=", "", "$redirect");
        if (ereg("privmsg", $forward)) { $pm_login = "active"; }
        if ($GLOBALS['db']->sql_numrows($result) == 0) {
            incoh();
            title(_USERREGLOGIN);
            Max_OpenTable();
            echo "<center><font class='title'>"._SORRYNOUSEREXIST."</font></center>\n";
            Max_CloseTable();
            br('1');
            incof();
        } elseif ($GLOBALS['db']->sql_numrows($result) == 1 AND $setinfo['user_id'] != 1 AND $setinfo['user_password'] != "" AND $setinfo['user_active'] > 0 AND $setinfo['user_level'] > 0) {
            $dbpass = $setinfo['user_password'];
            $non_crypt_pass = $user_password;
            $old_crypt_pass = crypt($user_password,substr($dbpass,0,2));
            $new_pass = md5($user_password);
            if (($dbpass == $non_crypt_pass) OR ($dbpass == $old_crypt_pass)) {
                $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `user_password`='$new_pass' WHERE `username`='$username'");
                $result = $GLOBALS['db']->sql_query("SELECT `user_password` FROM `".TABLE_USERS."` WHERE `username`='$username'");
                $raw    = $GLOBALS['db']->sql_fetchrow($result);
		$dbpass = stripslashes($raw['dbpass']);
            }
            if ($dbpass != $new_pass) {
                redirect_url("modules.php?name=Your_Account&stop=1");
                return;
            }
            $datekey = date("F j");
            $rcode   = hexdec(md5($_SERVER['HTTP_USER_AGENT'] . $sitekey . $random_num . $datekey));
	    $code    = substr($rcode, 2, 6);
            if (extension_loaded("gd") AND $code != $gfx_check AND ($ya_config['usegfxcheck'] == 2 OR $ya_config['usegfxcheck'] == 3)) {
                redirect_url("modules.php?name=Your_Account&stop=1");
                die();
            } else {
                yacookie($setinfo['user_id'], $setinfo['username'], $new_pass, $setinfo['storynum'], $setinfo['umode'], $setinfo['uorder'], $setinfo['thold'], $setinfo['noscore'], $setinfo['ublockon'], $setinfo['theme'], $setinfo['commentmax']);
                $uname = $_SERVER["REMOTE_ADDR"];
                $GLOBALS['db']->sql_query("DELETE FROM `".TABLE_SESSION."` WHERE `uname`='$uname' AND guest='1'");
	  $lastip = getenv("REMOTE_ADDR");
          if (strpos($lastip, ', ')) {
            $lastips = explode(', ', $lastip);
            if($lastips[0] != 'unknown' AND $lastips[0] != 'none' AND $lastips[0] != '127.0.0.1' AND $lastips[0] != '') {
              $lastip = $lastips[0];
            } else {
              $lastip = $lastips[1];
            }
            $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `last_ip`='$lastip' WHERE `user_id`='$uid'");
	    $GLOBALS['db']->sql_query("OPTIMIZE TABLE ".TABLE_USERS."");
	    $GLOBALS['db']->sql_query("OPTIMIZE TABLE ".TABLE_SESSIONS."");
          }
            }
            if ($pm_login != "") {
                redirect_url("modules.php?name=Private_Messages&file=index&folder=inbox");
            } elseif ($redirect == "" ) {
 		  $redirect = $_SERVER['HTTP_REFERER'];
	        redirect_url("$redirect");
            } else if ($mode == "") {
                redirect_url("modules.php?name=Forums&file=$forward");
            } elseif ($t !="")  {
                redirect_url("modules.php?name=Forums&file=$forward&mode=$mode&t=$t");
            } else {
                redirect_url("modules.php?name=Forums&file=$forward&mode=$mode&f=$f");
            }
        } elseif ($GLOBALS['db']->sql_numrows($result) == 1 AND ($setinfo['user_level'] < 1 OR $setinfo['user_active'] < 1)) {
            incoh();
            title(_USERREGLOGIN);
            Max_OpenTable();
            if ($setinfo['user_level'] == 0) {
                echo "<center><font class='title'><b>"._ACCSUSPENDED."</b></font></center>\n";
        mt_srand ((double)microtime()*1000000);
        $maxran = 1000000;
        $random_num = mt_rand(0, $maxran);
    echo "<table align='center' cellpadding='3' cellspacing='3' border='0'>\n";
    echo "<tr><td align='center' bgcolor='$bgcolor1' colspan='2'><b>"._REACTIVATEUSER."</b> ("._ALLREQUIRED.")</td></tr>\n";
    echo "<form action='modules.php?name=Your_Account' method='post'>\n";
    echo "<input type='hidden' name='uid' value='".$setinfo['user_id']."'>\n";
    echo "<tr><td bgcolor='$bgcolor2'>"._EMAIL.":</td><td bgcolor='$bgcolor1'><input type='text' name='user_email' size='30' maxlength='255'></td></tr>\n";
    echo "<tr><td bgcolor='$bgcolor2'>"._RETYPEEMAIL.":</td><td bgcolor='$bgcolor1'><input type='text' name='user_email2' size='30' maxlength='255'></td></tr>\n";
    if (extension_loaded("gd") AND ($ya_config['usegfxcheck'] == 1 OR $ya_config['usegfxcheck'] == 3)) {
        echo "<tr><td bgcolor='$bgcolor2'>"._SECURITYCODE.":</td><td bgcolor='$bgcolor1'><img src='modules.php?name=$module_name&op=gfx&random_num=$random_num' border='0' height='20' width='80' alt='"._SECURITYCODE."' title='"._SECURITYCODE."'></td></tr>\n";
        echo "<tr><td bgcolor='$bgcolor2'>"._TYPESECCODE.":</td><td bgcolor='$bgcolor1'><input type='text' name='gfx_check' size='10' maxlength='8'></td></tr>\n";
        echo "<input type='hidden' name='random_num' value='$random_num'>\n";
    }
    echo "<input type='hidden' name='op' value='reactivate_user'>\n";
    echo "<tr><td align='center' bgcolor='$bgcolor1' colspan='2'><input type='submit' value='"._REACTIVATE."' onclick=\"this.form.submit();this.disabled=true;this.value='"._WAITING."'\" /></td></tr>\n";
    echo "</form></table>\n";
            } elseif ($setinfo['user_level'] == -1) {
                echo "<center><font class='title'><b>"._ACCDELETED."</b></font></center>\n";
            } else {
                echo "<center><font class='title'><b>"._SORRYNOUSERINFO."</b> Error ".$setinfo['user_level']." </font></center>\n";
            }
            Max_CloseTable();
            incof();
        } else {
            redirect_url("modules.php?name=Your_Account&stop=1");
        }