#! /srvtools/http/bin/perl
#############################################################################
#  
#   File:          Change.pl 
#
#   Author:        Jungmin Kim
#
#   Created:       3/30/95
#   Modified:      
#   Version: 
#
#   Input:         subject, user information
#   Output:        HTML text
#
#   Description:   This program is to modify password file or conferences
#           
#               
#   Usage:         All arguments are passed through 'PATH_INFO'
#                  and 'POST' method.
#
#     example:     http://.../Change.pl/adduser:user
#                                    Add a new user 
#                                    and current user information is 'user'
#              Format of 'user' is "username:email_address"
#              Space characters should be replaced with '+' characters.
#
#############################################################################

require "Global.pl";	      # sets global variables
require "ParseArg.pl";	      # Parse arguments passed by http server
require "CheckPasswd.pl";     # funtions for password file
require "UserName.pl";	      # funtions to change password file
require "Conference.pl";      # functions to change conference file
require "PreviewConf.pl";     # Preview the edited message
require "Preferences.pl";     # Modify the preferences 

# ***********************************************************************
#
#   MAIN FUNCTION
#
# ***********************************************************************


&Global();
%in = ();
&ParseArg(*in);			# parse arguments passed by http server
&GetPath(*in);			# parse arguments passed by 'PATH_INFO'
&ReadOptions();


if($in{'subject'} eq "adduser") {
    #### add a new user name
    &EnterUser(-1, $in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "addconf") {
    #### add a new conference
    &AddConference("","","","", $in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "retryuser") {
    #### retry to confirm the new user name
    &RetryUser($in{'newuser'}, $in{'newpasswd'}, 
	       $in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "equal") {
    #### compaire the first password and the second one
    if ($in{'newuser'} eq $in{'newuser2'} &&
	$in{'newpasswd'} eq $in{'newpasswd2'}) {

	#### get name and email address
	&NameEmail($in{'newuser'}, $in{'newpasswd'}, 
		   $in{'user'}, $in{'subdir'});
    }
    else {
	#### failed
	&RetryNewPasswd($in{'user'}, $in{'subdir'});
    }
}
elsif($in{'subject'} eq "deluser") {
    #### delete a user name from password file
    &DeleteUser($in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "delconf") {
    #### delete a conference
    &DeleteConference($in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "saveuser") {
    $usr = &SaveName($in{'newuser'}, $in{'newpasswd'},
		      $in{'name'}, $in{'email'});
    &EnterUser($usr,$in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "saveconf") {
    #### current message should be edited
    if($in{'edit'} eq  "yes") {
	&AddConference($in{'newconf'}, $in{'newdir'},
		       $in{'title'}, $in{'message'}, 
		       $in{'user'}, $in{'subdir'});
    }
    #### generate a conference
    else {
	&SaveConference($in{'newconf'}, $in{'newdir'},
			$in{'title'}, $in{'message'}, 
			$in{'subdir'}, $in{'user'});
	&AddConference("","","","",$in{'user'}, $in{'subdir'});
    }
}
elsif($in{'subject'} eq "removeuser") {
    &RemoveName($in{'deluser'});
    &DeleteUser($in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "removeconf") {
    &RemoveConf($in{'delconf'});
    &DeleteConference($in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "preview") {
    &PreviewConf($in{'newconf'}, $in{'newdir'},
		 $in{'title'}, $in{'message'}, $in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "option") {
    &ChangeOptions($in{'user'}, $in{'subdir'});
}
elsif($in{'subject'} eq "changeopt") {
    &SaveOptions($in{'user'}, $in{'subdir'});
    
}


##########################################################################
#
#  GetPath
#
#  INPUT:    void
#  OUTPUT:   void
#
#  FUNCTION: Parses extended path information.
#            format of 'PATH_INFO' is /subject:user.
#
##########################################################################

sub GetPath{
    local(*in) = @_;

    $ENV{'PATH_INFO'} =~ /\/([^:]*):([^:]*):(.*)$/;
    $in{'subdir'} = $1;
    $in{'subject'} = $2 if $in{'subject'} eq "";
    $in{'user'} = $3;

    if ($in{'subdir'} ne "") {
	$fconffile = "$in{'subdir'}\/$conffile";
	$fcheckfile = "$in{'subdir'}\/$checkfile";
    }
    else {
	$fconffile = $conffile;
	$fcheckfile = $checkfile;
    }
    $fconffile = "$webboardhome\/$fconffile";
    $fcheckfile = "$webboardhome\/$fcheckfile";
}
1;

