<?

/* ------------------------------------------------------------------- */
/*

*************************************************
*			UWAGA! SKRYPT NIE JEST DARMOWY.			*
*		DALSZE ROZPOWSZECHNIANIE BEZ ZGODY 			*
*			FIRMY ArtGlobal JEST ZABRONIONE.			*
*************************************************

*************************************************
*	WWW.ArtGlobal.PL		PRODUCENT OPROGRAMOWANIA	*
*	NAZWA SKRYPTU:		NIERUCHOMOSCI 6.0			*
*	WERSJA FINALNA:	04.10.2010						*
*	KONTAKT:				kontakt@artglobal.pl			**
*************************************************

Copyright (c) 2010 ArtGlobal. Wszelkie prawa zastrzeżone.

*/
/* ------------------------------------------------------------------- */

class user
{
        function isEmpty ( $string )
        {
                if ( empty( $string ) )
                {
                        return false;
                }
                else
                {
                        return true;
                }
        }
        function check_login ( $userName, $userPass, $mysql )
        {
                $userPass = md5( $userPass );
                $sql = "SELECT userId FROM users WHERE userName = '$userName' AND userPass = '$userPass' AND userConfirm = '1'";
                if ( $mysql -> num( $sql ) == 1 )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function lost ( $login, $email, $mysql )
        {
                $sql = "SELECT userName, userEmail FROM users WHERE userName = '$login' AND userEmail = '$email'";
                if ( $mysql -> num( $sql ) == 1 )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function newPass ( $login, $email, $wwwS, $mysql, $sendPass )
        {
                $new_pass = substr( str_shuffle('1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'), 0, 8);
                $new_pass_md5 = md5( $new_pass );
                $sql = "UPDATE `users` SET `userPass` = '$new_pass_md5' WHERE userName = '$login' AND userEmail = '$email'";
                $mysql -> q( $sql );
                $temat = 'Wygenerowano nowe hasło [' . $wwwS . ']';
                $tresc = 'Twoje nowe hasło to: <b>' . $new_pass . '</b>';
                $sendPass -> mailer ( $email, $login, '', $temat, $tresc );
        }
        function checkUserPass ( $pass, $userId, $mysql )
        {
                $sql = "SELECT userPass FROM users WHERE userId = '$userId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                if ( $db[0] == md5( $pass ) )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function checkPass ( $pass_1, $pass_2 )
        {
                if ( $pass_1 == $pass_2 )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function changePass ( $pass, $userId, $mysql )
        {
                $sql = "UPDATE `users` SET `userPass` = '".md5( $pass )."' WHERE userId = '$userId'";
                $mysql -> q( $sql );
        }
        function checkUserEmail ( $userEmail, $userId, $mysql )
        {
                $sql = "SELECT userEmail FROM users WHERE userId = '$userId'";
                $q = $mysql -> q( $sql );
                $db = mysql_fetch_array( $q );
                if ( $db[0] == $userEmail )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function emailSql ( $email, $mysql )
        {
                $sql = "SELECT userId FROM users WHERE userEmail = '$email'";
                if ( $mysql -> num( $sql ) == 0 )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function checkEmail ( $email_1, $email_2 )
        {
                if ( $email_1 == $email_2 )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }
        function changeEmail ( $email, $userId, $mysql )
        {
                $sql = "UPDATE `users` SET `userEmail` = '$email' WHERE userId = '$userId'";
                $mysql -> q( $sql );
        }
        function confirm ( $confirm, $mysql )
        {
                $sql = "UPDATE `users` SET `userConfirm` = '1' WHERE userHash = '$confirm'";
                $mysql -> q( $sql );
        }
}
