<?php
/**
 * $Source: /home/cvs/nukescripts/modules/Your_Account/public/saveuser.php,v $
 * $Revision: 3.3.1-1 $
 * $Author: cyril $
 * $Date: 2006/07/01 12:15:04 $
 * Fix champs perso ( Bug 127 )
 */
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* 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 saveuser MAXIMUS directly...');
defined('MAXIMUS') OR header("Location: index.php");

if (defined('USER_ALLOW')) {
    $stop = "";
    cookiedecode($user);
    $check  = $cookie[1];
    $check2 = $cookie[2];
    $result = $GLOBALS['db']->sql_query("SELECT `user_id`, `user_password`, `user_email` FROM `".TABLE_USERS."` WHERE `username`='$check'");
    $row    = $GLOBALS['db']->sql_fetchrow($result);
    $vuid   = intval($row['user_id']);
    $ccpass = stripslashes($row['user_password']);
    $tuemail         = strtolower($row['user_email']);
    $user_sig        = str_replace("<br />", "\r\n", $user_sig);
    $user_sig        = ya_fixtext($user_sig);
    $user_email      = strtolower($user_email);
    $user_email      = ya_fixtext($user_email);
    $femail          = ya_fixtext($femail);
    $user_website    = ya_fixtext($user_website);
    $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_from2      = ya_fixtext($user_from2);
    $user_from       = ya_fixtext($user_from);
    $user_interests  = ya_fixtext($user_interests);
    $realname        = ya_fixtext($realname);
    $user_dateformat = ya_fixtext($user_dateformat);
    $newsletter            = intval($newsletter);
    $user_viewemail        = intval($user_viewemail);
    $user_allow_viewonline = intval($user_allow_viewonline);
    $user_timezone         = intval($user_timezone);

    $xfield1  = htmlentities(addslashes($xfield1));
    $xfield2  = htmlentities(addslashes($xfield2));
    $xfield3  = htmlentities(addslashes($xfield3));
    $xfield4  = htmlentities(addslashes($xfield4));
    $xfield5  = htmlentities(addslashes($xfield5));
    $xfield6  = htmlentities(addslashes($xfield6));
    $xfield7  = htmlentities(addslashes($xfield7));
    $xfield8  = htmlentities(addslashes($xfield8));
    $xfield9  = htmlentities(addslashes($xfield9));
    $xfield10 = htmlentities(addslashes($xfield10));

    if ($ya_config['allowmailchange'] < 1) {
        if ($tuemail != $user_email) { ya_mailCheck($user_email); }
    }
    if ($user_password > "" OR $vpass > "") { ya_passCheck($user_password, $vpass); }

    if (($stop == "") AND ($user_id == $vuid) AND ($check2 == $ccpass)) {
        if (!eregi("http://", $user_website) AND $user_website != "") {
            $user_website = "http://$user_website";
        }
        if ($bio) { filter_text($bio); $bio = $EditedMessage; $bio = FixQuotes($bio); }
        if ($user_password != "") {
            cookiedecode($user);
            $GLOBALS['db']->sql_query("LOCK TABLES `".TABLE_USERS."` WRITE");
            $user_password = md5($user_password);
            $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `name`='$realname', `user_email`='$user_email', `femail`='$femail', `user_website`='$user_website', `user_password`='$user_password', `bio`='$bio', `user_icq`='$user_icq', `user_occ`='$user_occ', `user_from`='$user_from', `user_from2`='$user_from2', `user_interests`='$user_interests', `user_sig`='$user_sig', `user_aim`='$user_aim', `user_yim`='$user_yim', `user_msnm`='$user_msnm', `newsletter`='$newsletter', `user_viewemail`='$user_viewemail', `user_allow_viewonline`='$user_allow_viewonline', `user_notify`='$user_notify', `user_notify_pm`='$user_notify_pm', `user_popup_pm`='$user_popup_pm', `user_attachsig`='$user_attachsig', `user_allowbbcode`='$user_allowbbcode', `user_allowhtml`='$user_allowhtml', `user_allowsmile`='$user_allowsmile', `user_timezone`='$user_timezone', `user_dateformat`='$user_dateformat' WHERE `user_id`='$user_id'");
            $sql = "SELECT * FROM `".TABLE_USERS."` WHERE `username`='$username' AND `user_password`='$user_password'";


 $resultfield = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_NSNYA_USERSFIELDS."` WHERE `user_id`='$user_id' "));
if (!empty($resultfield)) {
$sq = $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNYA_USERSFIELDS."` SET `field1`='$xfield1', `field2`='$xfield2', field3='$xfield3', `field4`='$xfield4', `field5`='$xfield5', `field6`='$xfield6', `field7`='$xfield7', `field8`='$xfield8', `field9`='$xfield9', `field10`='$xfield10' WHERE `user_id`='$user_id' ");
} else {
$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_NSNYA_USERSFIELDS."` VALUES (NULL, '$user_id', '$xfield1', '$xfield2', '$xfield3', '$xfield4', '$xfield5', '$xfield6', '$xfield7', '$xfield8', '$xfield9', '$xfield10' )");
}


            $result = $GLOBALS['db']->sql_query($sql);
            if ($GLOBALS['db']->sql_numrows($result) == 1) {
                $userinfo = $GLOBALS['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']);
            } else {
                echo "<center>"._SOMETHINGWRONG."</center><br />";
            }
            $GLOBALS['db']->sql_query("UNLOCK TABLES");
        } else {
            $GLOBALS['db']->sql_query("LOCK TABLES `".TABLE_USERS."` WRITE");
            $GLOBALS['db']->sql_query("UPDATE `".TABLE_USERS."` SET `name`='$realname', `user_email`='$user_email', `femail`='$femail', `user_website`='$user_website', `bio`='$bio', `user_icq`='$user_icq', `user_occ`='$user_occ', `user_from`='$user_from', `user_from2`='$user_from2', `user_interests`='$user_interests', `user_sig`='$user_sig', `user_aim`='$user_aim', `user_yim`='$user_yim', `user_msnm`='$user_msnm', `newsletter`='$newsletter', `user_viewemail`='$user_viewemail', `user_allow_viewonline`='$user_allow_viewonline', `user_notify`='$user_notify', `user_notify_pm`='$user_notify_pm', `user_popup_pm`='$user_popup_pm', `user_attachsig`='$user_attachsig', `user_allowbbcode`='$user_allowbbcode', `user_allowhtml`='$user_allowhtml', `user_allowsmile`='$user_allowsmile', user_timezone='$user_timezone', `user_dateformat`='$user_dateformat' WHERE `user_id`='$user_id'");
            $GLOBALS['db']->sql_query("UNLOCK TABLES");



 $resultfield = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_NSNYA_USERSFIELDS."` WHERE `user_id`='$user_id' "));
if (!empty($resultfield)) {
$sq = $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNYA_USERSFIELDS."` SET `field1`='$xfield1', `field2`='$xfield2', `field3`='$xfield3', `field4`='$xfield4',`field5`='$xfield5', `field6`='$xfield6', `field7`='$xfield7', `field8`='$xfield8', `field9`='$xfield9', `field10`='$xfield10'  WHERE `user_id`='$user_id' ");
//die();
} else {
$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_NSNYA_USERSFIELDS."` VALUE (NULL, '$user_id', '$xfield1', '$xfield2', '$xfield3', '$xfield4', '$xfield5', '$xfield6', '$xfield7', '$xfield8', '$xfield9', '$xfield10' )");
//ECHO "`".TABLE_NSNYA_USERSFIELDS."` VALUE (NULL, '$user_id', '$xfield1', '$xfield2', '$xfield3', '$xfield4', '$xfield5', '$xfield6', '$xfield7', '$xfield8', '$xfield9', '$xfield10'";
//die();
}
        }
        redirect_url("modules.php?name=$module_name");
    } else {
        incoh();
        Max_OpenTable();
        echo "<center><font class='title'><b>"._ERRORREG."</b></font><br /><br />";
        echo "<font class='content'>$stop<br /><br />"._GOBACK."</font></center>";
        Max_CloseTable();
        incof();
    }

    } else {
	notuser();
}