<?php
    /* Page that makes a change to the user password
    */
    
    # $Id: password_CHANGE.php,v 1.3 2007/01/14 15:09:20 jarda Exp $
    
    require_once('simplePage.inc.php');

    class PageClass extends ChangeOwnPasswordSimplePage
    {
        function checkEnvironment()
        {
            if (!$_POST['currentPassword'] || !$_POST['newPassword'] || !$_POST['confirmPassword'])
                return False;

            return True;
        }


        function handleInvalidEnvironment()
        {
            header("Location: password_EDIT.php?reason=incomplete"); /* Redirect browser */ 
        }

        
        function createPage()
        {
            if (!$_POST['OK'])
            {
                header("Location: index.php"); /* Redirect browser */ 
                exit();
            }
            
            $userInfo = $this->getUserInfo();
            
            if ($_POST['currentPassword'] != $userInfo['password'])
            {
                header("Location: password_EDIT.php?reason=invalid"); /* Redirect browser */ 
                exit();
            }

            if ($_POST['newPassword'] != $_POST['confirmPassword'])
            {
                header("Location: password_EDIT.php?reason=different"); /* Redirect browser */ 
                exit();
            }

            $db = connect();

            $query = "UPDATE bdbUser SET password='$_POST[newPassword]' WHERE id=$userInfo[userid]";

            $db->Execute($query);

            header("Location: index.php"); /* Redirect browser */ 
        }
    }


    launchPage();


    # vim:enc=iso8859-2:fenc=iso8859-2:
?>
