###############################################################################
# UB_ModifyProfile.src                                                        #
###############################################################################
# UltraBoard 2000 by UltraScripts.com, Inc.                                   #
# Scripts written by Jacky Wing Wa Yung, WebMaster@UltraScripts.com           #
# Available from http://www.UltraBoard.org/                                   #
# =========================================================================== #
# COPYRIGHT NOTICE :                                                          #
#                                                                             #
# Copyright (c) 1999-2000 UltraScripts.com, Inc. All Rights Reserved.         #
#                                                                             #
# This program is being distributed as shareware. It may be used and modified #
# free for personal, government or non-profit. Any commercial use must be     #
# registered. However, modified versions cannot be sold or distributed. You   #
# cannot alter the copyright and "powered by" notices throughout the scripts. #
# These notices must be clearly visible to the end users.                     #
#                                                                             #
# WARRANTY DISCLAIMER:                                                        #
#                                                                             #
# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT #
# ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR       #
# FITNESS FOR A PARTICULAR PURPOSE.                                           #
###############################################################################

package Source;

use strict;

sub ModifyProfile {
  my ($ERROR) = @_;

  &Login unless ($UB::MEMBER{'LOGIN'} == 1);

  (
    my ($Profile) = &DB::BinarySelect (
      TABLE   => "Profiles",
      KEY     => $UB::MEMBER{'USERNAME'}
    )
  ) || &HTML::Error(MESSAGE => $DB::Error);

# =========================================================================== #
# Printing Modify Profile Form

  &Standard::Require("UB_Modify_Profile.src", "$UB::INTERFACES_PATH/$SYSTEM::DEFAULT_THEME/UB_Modify_Profile.src");

  my %FORM = (
    "CATEGORY.ID"     => $UB::QUERY{'CID'} || ""      ,
    "BOARD.ID"        => $UB::QUERY{'BID'} || ""      ,
    "TOPIC.ID"        => $UB::QUERY{'TID'} || ""      ,
    "POST.ID"         => $UB::QUERY{'PID'} || ""      ,
    "DAY_PRUNE"       => $UB::QUERY{'DayPrune'} || "" ,
    "PAGE"            => $UB::QUERY{'P'} || ""        ,

    "FORM.USERNAME"   => $UB::MEMBER{'USERNAME'}                                        ,
    "FORM.NICKNAME"   => $UB::QUERY{'FORM_NICKNAME'}   || $UB::MEMBER{'NICKNAME'}  ,
    "FORM.EMAIL"      => $UB::QUERY{'FORM_EMAIL'}      || $UB::MEMBER{'EMAIL'}      ,

    "FORM.HOMEPAGE"   => $UB::QUERY{'FORM_HOMEPAGE'}   || $Profile->{'HOMEPAGE'}    ,
    "FORM.LOCATION"   => $UB::QUERY{'FORM_LOCATION'}   || $Profile->{'LOCATION'}    ,
    "FORM.OCCUPATION" => $UB::QUERY{'FORM_OCCUPATION'} || $Profile->{'OCCUPATION'} ,
    "FORM.INTEREST"   => $UB::QUERY{'FORM_INTEREST'}   || $Profile->{'INTEREST'}    ,
    "FORM.ICQ"        => $UB::QUERY{'FORM_ICQ'}        || $Profile->{'ICQ'}       ,
    "FORM.AGE"        => $UB::QUERY{'FORM_AGE'}        || $Profile->{'AGE'}       ,
    "FORM.COMMENTS"   => $UB::QUERY{'FORM_COMMENTS'}   || $Profile->{'COMMENTS'}    ,
    "FORM.SIGNATURE"  => $UB::QUERY{'FORM_SIGNATURE'}  || $Profile->{'SIGNATURE'}  ,

    "FORM.PHOTO"      => $Profile->{'PHOTO'}                                            ,

    &Standard::ExtraVariables()
  );

  my $Remember = 0;
  if ($UB::CGI->cookie()) {
    # ( $UB::CGI->cookie('Username') ) &&
    # ( $UB::CGI->cookie('Password') )
    if (
      ( $UB::COOKIES{'Username'} ) &&
      ( $UB::COOKIES{'Password'} )
    ) {
      $Remember = 1;
    }
  }

  $FORM{'FORM.CHECKBOX.REMEMBER_PASSWORD'} = &HTML::Checkbox (
    NAME    => "FORM_REMEMBER_PASSWORD",
    VALUE   => "1"                     ,
    CHECKED => $Remember
  );
  $FORM{'FORM.CHECKBOX.HIDE_EMAIL'}        = &HTML::Checkbox (
    NAME    => "FORM_HIDE_EMAIL",
    VALUE   => "1"              ,
    CHECKED => $UB::QUERY{'FORM_HIDE_EMAIL'} || ""
  );

  $FORM{'FORM.CHECKBOX.PHOTO.KEEP'} = &HTML::Radio (
    NAME    => "FORM_PHOTO_ACTION",
    VALUE   => "KEEP"             ,
    CHECKED => $UB::QUERY{'FORM_PHOTO_ACTION'} || ($Profile->{'PHOTO'} ? "KEEP" : undef) || "UPLOAD"
  );
  $FORM{'FORM.CHECKBOX.PHOTO.REMOVE'} = &HTML::Radio (
    NAME    => "FORM_PHOTO_ACTION",
    VALUE   => "REMOVE"           ,
    CHECKED => $UB::QUERY{'FORM_PHOTO_ACTION'} || ($Profile->{'PHOTO'} ? "KEEP" : undef) || "UPLOAD"
  );
  $FORM{'FORM.CHECKBOX.PHOTO.UPLOAD'} = &HTML::Radio (
    NAME    => "FORM_PHOTO_ACTION",
    VALUE   => "UPLOAD"           ,
    CHECKED => $UB::QUERY{'FORM_PHOTO_ACTION'} || ($Profile->{'PHOTO'} ? "KEEP" : undef) || "UPLOAD"
  );

  if ($GENERAL::MAX_PHOTO_LENGTH > 0) {
    if ($ENV{'HTTP_USER_AGENT'} =~/Mozilla\/(\d+)/) {
      my $Version = $1;
      if ($Version >= 4) {
        $FORM{'PHOTO_ATTACH'} = 1;
      }
    }
  }

  $FORM{'ERROR.MESSAGE'}    = ($Modify_Profile::DYNAMIC{"LANGUAGE.".$ERROR}) ? $Modify_Profile::DYNAMIC{"LANGUAGE.".$ERROR} : $ERROR;

  &Standard::PrintHTMLHeader();
  print &Modify_Profile::Parse(\%FORM);
}

sub Login {
  print "Location: $SYSTEM::UB_URL/UltraBoard.$SYSTEM::EXT?action=Login&refer=ModifyProfile\n\n";
}

###############################################################################
1; # end of UB_ModifyProfile.src file
###############################################################################