<?php
/**
 * $Source: /home/cvs/nukescripts/modules/Your_Account/public/saveactivate.php,v $
 * $Revision: 1.1.0a $
 * $Author: cyril $
 * $Date: 2007/01/16 12:07:34 $
 * Fix Toumilovitch MP du 16 janvier 2007
 *
 */
/********************************************************/
/* NSN Your Account                                     */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.fr                            */
/* Original Script www.nukescripst.net                  */
/* Copyright  2000-2005 by NukeScripts Network         */
/* ==================================================== */
/* Based from:                                          */
/* PHP-NUKE: Web Portal System                          */
/********************************************************/
defined('IN_YA') OR die ('Access denied saveactivate MAXIMUS directly...');
defined('MAXIMUS') OR header("Location: index.php");

    $username  = trim($username);
    $check_num = trim($check_num);
    $time      = $db->XMFnum($time);
    $username  = addslashes( $username );
    $result = $db->sql_query("SELECT * FROM `".TABLE_USERS_TEMP."` WHERE `username`='$username' AND `check_num`='$check_num' AND `time`='$time'");
    if ($db->sql_numrows($result) == 1) {
        $row = $db->sql_fetchrow($result);
        $username      = stripslashes($row['username']);
        $user_email    = stripslashes($row['user_email']);
        $user_regdate  = stripslashes($row['user_regdate']);
        $user_password = stripslashes($row['user_password']);
        $realname = ya_fixtext($realname);
        if($realname == "") { $realname = $row['username']; }
        $user_sig   = str_replace("<br />", "\r\n", $user_sig);
        $user_sig   = ya_fixtext($user_sig);
        $user_email = ya_fixtext($user_email);
        $femail     = ya_fixtext($femail);
        $user_website = ya_fixtext($user_website);
        if (!eregi("http://", $user_website) AND $user_website != "") { $user_website = "http://$user_website"; }
        $bio = str_replace("<br />", "\r\n", $bio);
        $bio = ya_fixtext($bio);
        $user_icq = ya_fixtext($user_icq);
        $user_aim = ya_fixtext($user_aim);
        $user_yim = ya_fixtext($user_yim);
        $user_msnm = ya_fixtext($user_msnm);
        $user_occ = ya_fixtext($user_occ);
        $user_from = ya_fixtext($user_from);
        $user_interests = ya_fixtext($user_interests);
        $user_dateformat = ya_fixtext($user_dateformat);
        $newsletter = $db->XMFnum($newsletter);
        $user_viewemail = $db->XMFnum($user_viewemail);
        $user_allow_viewonline = $db->XMFnum($user_allow_viewonline);
        $user_timezone = $db->XMFnum($user_timezone);
        $raw = $db->sql_fetchrow($db->sql_query("SELECT max(user_id) AS latest_uid FROM `".TABLE_USERS."`"));
	$latest_uid = $db->XMFnum($raw['latest_uid']);
        if ($latest_uid == "-1") { $new_uid = 1; } else { $new_uid = $latest_uid+1; }
        $lv = time();
        $db->sql_query("LOCK TABLES `".TABLE_USERS."` WRITE");
        $db->sql_query("INSERT INTO `".TABLE_USERS."` (user_id, user_avatar, user_avatar_type, user_lang, user_lastvisit, umode) VALUES ($new_uid, 'gallery/blank.gif', '3', '$language', '$lv', 'nested')");
        $db->sql_query("UPDATE `".TABLE_USERS."` SET `username`='$username', `name`='$realname', `user_email`='$user_email', `femail`='$femail', `user_website`='$user_website', `user_icq`='$user_icq', `user_aim`='$user_aim', `user_yim`='$user_yim', `user_msnm`='$user_msnm', `user_from`='$user_from', `user_occ`='$user_occ', `user_interests`='$user_interests', `newsletter`='$newsletter', `user_viewemail`='$user_viewemail', `user_allow_viewonline`='$user_allow_viewonline', `user_timezone`='$user_timezone', `user_dateformat`='$user_dateformat', `user_sig`='$user_sig', `bio`='$bio', `user_password`='$user_password', `user_regdate`='$user_regdate' WHERE `user_id`='$new_uid'");
        $db->sql_query("UNLOCK TABLES");
        $db->sql_query("DELETE FROM `".TABLE_USERS_TEMP."` WHERE `username`='$username'");
        $db->sql_query("OPTIMIZE TABLE `".TABLE_USERS_TEMP."`");
        incoh();
        title(""._ACTIVATIONYES."");
        Max_OpenTable();
        $result = $db->sql_query("SELECT * FROM `".TABLE_USERS."` WHERE `username`='$username' AND `user_password`='$user_password'");
        if ($db->sql_numrows($result) == 1) {
            $userinfo = $db->sql_fetchrow($result);
            yacookie($userinfo['user_id'],$userinfo['username'],$userinfo['user_password'],$userinfo['storynum'],$userinfo['umode'],$userinfo['uorder'],$userinfo['thold'],$userinfo['noscore'],$userinfo['ublockon'],$userinfo['theme'],$userinfo['commentmax']);
            echo "<meta http-equiv=\"refresh\" content=\"2;URL=$nukeurl\">";
            echo "<center><b>$row[username]:</b> "._ACTMSG2."</center>";


      $register_pm_subject  = _REGISTER_PM_SUBJECT;
      $register_pm          = _REGISTER_PM;
      $privmsgs_date        = date("U");

      $sql = "UPDATE `".TABLE_USERS."` SET `user_new_privmsg`='1', `user_last_privmsg`='65534', `user_unread_privmsg`='1', `user_popup_pm`='1', `user_notify`='1', `user_notify_pm`='1' WHERE `user_id`='".$userinfo['user_id']."'";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
	{ query_die(MODULE_ERROR, 'Could not SELECT _user', '', __LINE__, __FILE__, $sql);
         Max_CloseTable();
         incof();
      }
      $sql = "INSERT INTO `".$user_prefix."_bbprivmsgs` (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig) VALUES ('5', '" . str_replace("\'", "''", addslashes(sprintf($register_pm_subject,$sitename))) . "', '2', '".$userinfo['user_id']."', '$privmsgs_date', '0', '1', '1', '0')";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
	{ query_die(MODULE_ERROR, 'Could not SELECT _bbprivmsgs', '', __LINE__, __FILE__, $sql);
         Max_CloseTable();
         incof();
      }
      $privmsgs_text = $register_pm_subject;
      $privmsg_sent_id = $db->sql_nextid();
      $sql = "INSERT INTO `".$user_prefix."_bbprivmsgs_text` (privmsgs_text_id, privmsgs_text) VALUES ($privmsg_sent_id, '" . str_replace("\'", "''", addslashes(sprintf($register_pm,$username,$sitename,$sitename))) . "')";
	if ( !($result = $GLOBALS['db']->sql_query($sql)) )
	{ query_die(MODULE_ERROR, 'Could not SELECT _bbprivmsgs_text', '', __LINE__, __FILE__, $sql);
         Max_CloseTable();
         incof();
      }

        } else {
            echo "<center>"._SOMETHINGWRONG."</center><br />";
        }
        Max_CloseTable();
        incof();
        die();
    } else {
        incoh();
        title(""._ACTIVATIONERROR."");
        Max_OpenTable();
        echo "<center>"._ACTERROR."</center>";
        Max_CloseTable();
        incof();
        die();
    }