###########################################################
# RMDB4.LIB
# 
# RMDatabase - version 4.0a - Shared Routines File
#----------------------------------------------------------

&read_custom;

$color_list{ "MOD1_HEAD" } = $mod1_hd_color;
$color_list{ "MOD2_HEAD" } = $mod2_hd_color;
$color_list{ "MOD3_HEAD" } = $mod3_hd_color;
$color_list{ "MOD_BG1" }   = $mod_bg_color1;
$color_list{ "MOD_BG2" }   = $mod_bg_color2;
$color_list{ "MOD_BG3" }   = $mod_bg_color3;

$width_list{ "LG" }        = $lg_module_width;
$width_list{ "MD" }        = $md_module_width;
$width_list{ "SM" }        = $sm_module_width;

$path_list{ "IMAGE" }      = $images_dir;
$path_list{ "HOME" }       = $home_url;
$path_list{ "CSS" }        = $css_url;
$path_list{ "CGI" }        = $cgi_url;

@sort_opts = ( "1::Name", "2::Begin Service Date", "3::End Service Date",
               "4::Last Updated", "5::E-Mail Address", "6::Date Registered" );
               
@col_opts  = ( "1::Service Dates", "2::Mission", "3::Last Updated",
               "4::E-Mail Address", "5::Current Address", "6::Date Registered" );
               
@case_opts = ( "1::Mixed", "2::Upper", "3::Lower" );

$adm_img_rec_del = "del_rec.gif";
$adm_img_x_email = "bad_mail.gif";
$moddate = localtime( time );               
$rmdb_ver = "4.0a";


1;

###########################################################                   
# Generate the page
# NOTE:  Do NOT modify the copyright variable here.  By
# using these scripts, you have agreed to the terms listed
# in the header of the main script.
#----------------------------------------------------------
sub page_gen {

    my $pg_template = $_[0];
    my $adm_stat    = $_[1];
    my $copyrt      = "<span class=footnote><a href=\"http://www.hubernet.com/rmdb4\">RMdB Ver $rmdb_ver</a> - Copyright 2001 - <a href=\"http://www.hubernet.com/mld\">Moonlight Design</a>.  All Rights Reserved.</span>";
    my $util = 0;
    
    if ( ! $done_cgi_head ) {
        &cgi_header;
    }
    
    $pg_title = "RMdB $rmdb_ver - $mission_name" unless ( $pg_title );
    
    $values{ "BODY" } = $pg_body;
    $values{ "TITLE" } = $pg_title;
    $values{ "PAGEHEAD" } = $pg_head;
    $values{ "MAIN_REG" } = $pg_main_reg;
    $values{ "MAIN_LNG" } = $pg_main_lng;
    $values{ "MAIN_NEW" } = $pg_main_new;
    $values{ "ADM_MAILTO" } = "<a href=\"mailto:$admin_address\">$admin_name</a>";
    $values{ "MISSION" } = $mission_name;
    
    $t = "$template_dir/$pg_template";
    if ( -s $t ) {
        open( TPT, $t ) || &rm_err( "Unable to open template - $t." );
        
        print "\n";
        
        foreach $line ( <TPT> ) {
            if ( $line =~ /\[COPYRIGHT:\]/ ) {
                $util = 1;
            }
            while ( $line =~ s/\[([^:\n]+):([^\]\n]*)\]/&parse_markup($1, $2, $adm_stat, $copyrt)/e ) {}
            print $line;
        }
        
        if ( $util == 0 ) {
            print "<center><b>UNAUTHORIZED USE OF RMdB SCRIPT!</b><br>It is prohibited to use these scripts without including a copyright tag in your<br>template file.  You must include the tag - [COPYRIGHT:] - in all templates used.</center>";
        }
        
        close( TPT );
    }
    else {
        &rm_err( "Template file - $t - not found." );
    }
    
    exit;

}

###########################################################                   
# Parse Markup Tags in Template
#----------------------------------------------------------
sub parse_markup {

    my $tag_id   = $_[0];
    my $params   = $_[1];
    my $adm_stat = $_[2];
    my $cr_val   = $_[3];
    my $result = "";
    
    if ( $tag_id eq "NAVDROP" ) {
        $result = &pulldown_list( $params, $adm_stat );
    }
    elsif ( $tag_id eq "COLOR" ) {
        $result = $color_list{ $params };
    }
    elsif ( $tag_id eq "PATH" ) {
        $result = $path_list{ $params };
    }
    elsif ( $tag_id eq "COPYRIGHT" ) {
        $result = $cr_val;
    }
    elsif ( $tag_id eq "WIDTH" ) {
        $result = $width_list{ $params };
    }
    elsif ( $tag_id eq "ACTION" ) {
        $result = &action_gen( $params, $adm_stat );
    }
    elsif ( $tag_id eq "FIELD" ) {
        $result = &field_gen( $params );
    }
    elsif ( $tag_id eq "MODULE" ) {
        $result = &module_gen( $params, $adm_stat );
    }
    elsif ( $tag_id eq "INPUT" ) {
        $result = &input_gen( $params );
    }
    else {
        $result = $values{ $tag_id };
    }
    
    return $result;
}

###########################################################                   
# Generate a pulldown list of shortcuts.
#----------------------------------------------------------
sub pulldown_list {

    my $options  = $_[0];
    my $adm_stat = $_[1];
    my @action_list;
    my $result = "";
    
    if ( $adm_stat ) {
        @action_list = ( "logout::Logout", "view_all_pres::View Presidents" );
    }
    else {
        @action_list = ( "view_all_pres::View Presidents" );
    }
    
    $result .= "<OPTION SELECTED value=\"\">--Quicklinks--\n";
    foreach $elem (@action_list) {
        ( $act_name, $act_desc ) = split( "::", $elem );
        $result .= "<OPTION VALUE=\"$cgi_url?action=$act_name\">$act_desc\n";
    }
    
    return $result;
}

###########################################################                   
# Generate an Action Link from Parameter passed
#----------------------------------------------------------
sub action_gen {

    my $action   = $_[0];
    my $adm_stat = $_[1];
    my $result   = "";
    
    if ( $action eq "OPTIONS" ) {
        $result = "<table width=$sm_module_width cellpadding=2 cellspacing=0 border=0>\n";
        $result .= "<tr bgcolor=$mod2_hd_color><td align=center class=module2><b>Options</b></td></tr>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=center class=mbody>\n";
        
        $result .= "<a href=\"$cgi_url?action=change_form&entrynum=$num\">Update Info</a><br>\n";
        $result .= "<a href=\"$cgi_url?action=change_pass_form&entrynum=$num\">Change Password</a><br>\n";
        $result .= "<a href=\"$cgi_url?action=rqst_passwd&entrynum=$num\">Request Password</a><br>\n";
        $result .= "<a href=\"$cgi_url?action=up_lost_contacts&entrynum=$num\">Lost Contacts</a><br>\n";
        
        if ( $adm_stat ) {
            $result .= "<a href=\"$cgi_adm_url?action=delete_entry&entrynum=$num\">Delete!</a><br>";
            $result .= "<a href=\"$cgi_adm_url?action=mark_bad_email&entrynum=$num\">Mark E-Mail Bad!</a><br>";
        }
        $result .= "</td></tr></table>\n";
    }
    elsif ( $action eq "FORM_START" ) {
        $result = "<form method=post action=\"$cgi_url\">\n";
        if ( $up_mode eq "edit" ) {
            $result .= "<input type=hidden name=action value=change_entry>\n";
            $result .= "<input type=hidden name=entrynum value=$num>\n";
        }
        else {
            $result .= "<input type=hidden name=action value=add_entry>\n";
        }
    }
    elsif ( $action eq "FORM_SUBMIT" ) {
        if ( $up_mode eq "edit" ) {
            if ( $adm_stat == 0 ) {
                $result .= "Password:&nbsp;<input type=password name=password value=\"\" size=10>&nbsp;";
            }
            $result .= "<input type=submit value=\" Update Now! \">";
        }
        else {
            $result .= "Choose a password:&nbsp;<input name=password value=\"\" size=10><br>\n";
            $result .= "<input type=submit value=\" Add Now! \">";
        }
    }
    
    return $result;
}

###########################################################                   
# Generate a field value from database
#----------------------------------------------------------
sub field_gen {

    my $field_id = uc( $_[0] );
    my $result   = "";
    
    if ( $field_id eq "RECNO" ) { $result = "$num"; }
    elsif ( $field_id eq "MISSIONARY" ) { $result = "$mis_title $lastname"; }
    elsif ( $field_id eq "FULLNAME" ) { $result = "$firstname $last_now"; }
    elsif ( $field_id eq "SPOUSE" ) { $result = "$spouse"; }
    elsif ( $field_id eq "SERVETIME" ) { $result = "$served_first, $served_second to $served_third, $served_fourth"; }
    elsif ( $field_id eq "EMAIL" ) { 
        if ( $email gt "" ) {
            $result = "<a href=\"mailto:$email\">$email</a>";
            if ( uc( $eml_stat ) eq "B" ) {
                $result .= "<br><span class=merror>Bad Address - Admin</span>";
            }
        }
        else {
            $result = "None";
        }
    }
    elsif ( $field_id eq "HOMEPAGE" ) { 
        if ( $homepage gt "" ) {
            $result = "<a href=\"$homepage\">$homepage</a>"; 
        }
    }
    elsif ( $field_id eq "WORK" ) {
        if ( $work gt "" ) {
            if ( $workurl gt "" ) {
                $result = "<a href=\"$workurl\">$work</a>";
            }
            else {
                $result = "$work";
            }
        }
        else {
            $result = "N/A";
        }
    }
    elsif ( $field_id eq "CITIES" ) { $result = "$txt_cities"; }
    elsif ( $field_id eq "OTHER" ) { $result = "$txt_other"; }
    elsif ( $field_id eq "CURADD" ) { $result = "$c_first<br>$c_second, $c_third  $c_fourth &nbsp;$c_ctry"; }
    elsif ( $field_id eq "CURPHN" ) { $result = "$c_phone"; }
    elsif ( $field_id eq "PERMADD" ) {
        if ( $p_first gt "" ) {
            $result = "$p_first<br>$p_second, $p_third  $p_fourth &nbsp;$p_ctry";
        }
        else {
            $result = "N/A";
        }
    }
    elsif ( $field_id eq "PERMPHN" ) { $result = "$p_phone"; }
    elsif ( $field_id eq "PRES" ) {
        if ( $president_one gt "" ) {
            $result .= "$president_one<br>";
        }
        if ( $president_two gt "" ) {
            $result .= "$president_two<br>";
        }
        if ( $pres_three gt "" ) {
            $result .= "$pres_three<br>";
        }
        if ( $pres_four gt "" ) {
            $result .= "$pres_four<br>";
        }
    }
    elsif ( $field_id eq "CHILDREN" ) { $result = "$children"; }
    elsif ( $field_id eq "LASTUP" ) { $result = "$lastdate"; }
    elsif ( $field_id eq "MISSION" ) { $result = "$whichmis"; }
    elsif ( $field_id eq "OCCUPATION" ) { $result = "$occup"; }
    
    return $result;
    
}

###########################################################                   
# Generate the specific module for the page
#----------------------------------------------------------
sub module_gen {

    my $mlist = uc( $_[0] );
    my $result   = "";
    my $mod_in;
    my $mod_width;
    
    ( $mod_in, $mod_width ) = split( ",", $mlist );
    
    if ( $mod_in eq "MAIN" ) {
        $result = "<span class=mbody>$lng_cnt_stat</span>\n";
    }
    elsif ( $mod_in eq "SRCH" ) {
        $result = "<form method=post action=\"$cgi_url\">\n";
        $result .= "<input type=hidden name=action value=search_any>\n";
        $result .= "<table width=$mod_width cellpadding=2 cellspacing=0 border=0>\n";
        $result .= "<tr bgcolor=$mod2_hd_color><td align=left class=module2 colspan=2><b>$lng_srch_head</b></td></tr>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=left valign=top class=instruct colspan=2>$lng_srch_instruct</td></tr>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=right valign=top class=mbody>$lng_srch_name</td>\n";
        $result .= "<td valign=top class=form><input name=name1 value=\"\" size=30></td></tr>\n";
        
        if ( $adm_stat ) {
            $result .= "<tr bgcolor=$mod_bg_color2><td align=right valign=top class=mbody>Enter E-mail (or partial) address:</td>\n";
            $result .= "<td valign=top class=form><input name=email1 value=\"\" size=30></td></tr>\n";
        }
        
        if ( $option{ "S_PRES" } ) {
            $result .= "<tr bgcolor=$mod_bg_color2><td align=right valign=top class=mbody>$lng_srch_pres</td>\n";
            $result .= "<td valign=top class=form><select name=pres1>\n";
            $result .= "<option selected value=\"\">$lng_choose_pres";
        
            foreach $prez (@presidents) {
                $result .= "<option value=\"$prez\">$prez";
            }
        
            $result .= "</select></td></tr>\n";
        }
        
        if ( $option{ "S_TIME" } ) {
            $result .= "<tr bgcolor=$mod_bg_color2><td align=right valign=top class=mbody>$lng_srch_date</td>\n";
            $result .= "<td valign=top class=form><select name=month1>\n";
            $result .= "<option selected value=\"\">$lng_choose_mn\n";
        
            foreach $month (@fullmonth) {
                $result .= "<OPTION VALUE=\"$month\">$month";
            }
        
            $result .= "</select>&nbsp;<select name=year1><option selected value=\"\">$lng_choose_yr\n";
        
            ( undef, undef, undef, undef, undef, $current_year, undef, undef, undef ) = localtime(time);
            for ($number = $mission_start_year; $number <= $current_year + 1900; $number++) {
                $result .= "<option value=\"$number\">$number";
            }
        
            $result .= "</select></td></tr>\n";
        }
        
        if ( $option{ "S_ADDR" } ) {
            $result .= "<tr bgcolor=$mod_bg_color2><td align=right valign=top class=mbody>$lng_srch_res_city</td>\n";
            $result .= "<td valign=top class=form>$lng_city <input name=add_city1 VALUE=\"\" size=15><br>$lng_state <input name=add_state1 value=\"\" size=2><br>$lng_ctry <input name=add_ctry1 value=\"\" size=10></td></tr>\n";
        }
        
        $result .= "<tr bgcolor=$mod_bg_color2><td align=center class=mbody>&nbsp;</td><td class=form><input type=submit value=\"$lng_go_button\">&nbsp;<input type=reset value=\"$lng_reset_button\"></td></tr>\n";
        $result .= "</table>\n";
        $result .= "</form>\n";
    
    }
    elsif ( $mod_in eq "LIST" ) {
        $result = "<table width=$mod_width cellpadding=2 cellspacing=0 border=0>\n";
        $result .= "<tr bgcolor=$mod2_hd_color><td align=left class=module2><b>$lng_sort_head</b></td></tr>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=left class=mbody>\n";
        $result .= "<ul>\n";
        
        if ( $option{ "L_NAME" } ) {
            $result .= "<li><a href=\"$cgi_url?action=view_all\"><b>$lng_view_all</b></a>\n";
        }
        if ( $option{ "L_BEG" } ) {
            $result .= "<li><a href=\"$cgi_url?action=view_by_startdate\"><b>$lng_view_start</b></a>\n";
        }
        if ( $option{ "L_END" } ) {
            $result .= "<li><a href=\"$cgi_url?action=view_by_enddate\"><b>$lng_view_end</b></a>\n";
        }
        if ( $option{ "L_PRES" } ) {
            $result .= "<li><a href=\"$cgi_url?action=view_all_pres\"><b>$lng_view_all_pres</b></a>\n";
        }
        if ( $option{ "L_LOST" } ) {
            $result .= "<li><a href=\"$cgi_url?action=list_lost\"><b>$lng_list_lost</b></a>\n";
        }
        
        $result .= "</ul></td></tr></table>\n";
    
    }
    elsif ( $mod_in eq "FOOT" ) {
        $result = "<table width=$mod_width cellpadding=2 cellspacing=0 border=0>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=center class=instruct>$lng_prob_foot <a href=\"mailto:$admin_address\">$admin_address</a></td></tr>\n";
        $result .= "</table>\n";
    }
    elsif ( $mod_in eq "ADM" ) {
        $result = "<table width=$mod_width cellpadding=2 cellspacing=0 border=0>\n";
        $result .= "<tr bgcolor=$mod2_hd_color><td align=center class=module2><b>Admin Options</b></td></tr>\n";
        $result .= "<tr bgcolor=$mod_bg_color2><td align=center class=mbody>\n";
        if ( $adm_stat ) {
            $result .= "<a href=\"$cgi_adm_url?action=admin_opts\">Customize Settings</a><br>\n";
            $result .= "<a href=\"$cgi_adm_url?action=pres_maint\">Mission Presidents</a><br>\n";
            $result .= "<a href=\"$cgi_adm_url?action=lang_maint\">Language Database</a><br>\n";
            $result .= "<a href=\"$cgi_adm_url?action=glob_email\">Mass E-Mail Messaging</a><br>\n";
            $result .= "<a href=\"$cgi_adm_url?action=export_db_form\">Database Export Options</a><br>\n";
            $result .= "<a href=\"$cgi_adm_url?action=log_maint\">Log File Maintenance</a><br><br>\n";
            $result .= "<a href=\"$cgi_url?action=admin_logout\">Admin Logout</a><br>\n";
        }
        else {
            $result .= "<a href=\"$cgi_url?action=admin_login\">Admin Login</a><br>\n";
        }
        
        $result .= "</td></tr></table>\n";
    
    }
    
    return $result;

}

###########################################################                   
# Generate an input (input, select, textarea, etc) tag from
# the database.
#----------------------------------------------------------
sub input_gen {

    my $flist = uc( $_[0] );
    my $result   = "";
    my $field_id;
    my $sz;
    my $elem;
    my $cur_year;
    my $numb;
    
    ( $field_id, $sz ) = split( ",", $flist );
    ( undef, undef, undef, undef, undef, $cur_year, undef, undef, undef) = localtime(time);
    
    
    if ( $field_id eq "LASTNAME" ) { 
        $sz = 20 unless ( $sz );
        $result = "<input name=lastname value=\"$lastname\" size=$sz>"; 
    }
    elsif ( $field_id eq "FIRSTNAME" ) { 
        $sz = 20 unless ( $sz );
        $result = "<input name=firstname value=\"$firstname\" size=$sz>";
    }
    elsif ( $field_id eq "SPOUSE" ) { 
        $sz = 20 unless ( $sz );
        $result = "<input name=spouse value=\"$spouse\" size=$sz>"; 
    }
    elsif ( $field_id eq "BEG_MONTH" ) { 
        $result = "<select name=served_first>"; 
        if ( $served_first eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @fullmonth ) {
            if ( $served_first eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "BEG_YEAR" ) {
        $result = "<select name=served_second>";
        if ( $served_second eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        for ( $numb = $mission_start_year; $numb <= $cur_year + 1900; $numb++ ) {
            if ( $served_second eq $numb ) {
                $result .= "<option selected value=\"$numb\">$numb";
            }
            else {
                $result .= "<option value=\"$numb\">$numb";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "END_MONTH" ) { 
        $result = "<select name=served_third>"; 
        if ( $served_third eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @fullmonth ) {
            if ( $served_third eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "END_YEAR" ) {
        $result = "<select name=served_fourth>";
        if ( $served_fourth eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        for ( $numb = $mission_start_year; $numb <= $cur_year + 1900; $numb++ ) {
            if ( $served_fourth eq $numb ) {
                $result .= "<option selected value=\"$numb\">$numb";
            }
            else {
                $result .= "<option value=\"$numb\">$numb";
            }
        }
        $result .= "</select>";
    }    
    elsif ( $field_id eq "EMAIL" ) { 
        $sz = 40 unless ( $sz );
        $result = "<input name=email value=\"$email\" size=$sz>"; 
    }
    elsif ( $field_id eq "HOMEPAGE" ) { 
        $sz = 40 unless ( $sz );
        $result = "<input name=homepage value=\"$homepage\" size=$sz>";
    }
    elsif ( $field_id eq "WORK" ) {
        $sz = 30 unless ( $sz );
        $result = "<input name=work value=\"$work\" size=$sz>";
    }
    elsif ( $field_id eq "WORKURL" ) {
        $sz = 40 unless ( $sz );
        $result = "<input name=workurl value=\"$workurl\" size=$sz>";
    }
    elsif ( $field_id eq "CITIES" ) { 
        $sz = 40 unless ( $sz );
        $result = "<textarea name=txt_cities cols=$sz rows=8 wrap>$txt_cities</textarea>"; 
    }
    elsif ( $field_id eq "OTHER" ) { 
        $sz = 40 unless ( $sz );
        $result = "<textarea name=txt_other cols=$sz rows=8 wrap>$txt_other</textarea>"; 
    }
    elsif ( $field_id eq "C_ADD" ) { 
        $sz = 40 unless ( $sz );
        $result = "<input name=c_first value=\"$c_first\" size=$sz>";
    }
    elsif ( $field_id eq "C_CITY" ) {
        $sz = 20 unless ( $sz );
        $result = "<input name=c_second value=\"$c_second\" size=$sz>";
    }
    elsif ( $field_id eq "C_STATE" ) {
        $sz = 3 unless ( $sz );
        $result = "<input name=c_third value=\"$c_third\" size=$sz>";
    }
    elsif ( $field_id eq "C_ZIP" ) {
        $sz = 10 unless ( $sz );
        $result = "<input name=c_fourth value=\"$c_fourth\" size=$sz>";
    }
    elsif ( $field_id eq "C_CTRY" ) {
        $sz = 20 unless ( $sz );
        $result = "<input name=c_ctry value=\"$c_ctry\" size=$sz>"; 
    }
    elsif ( $field_id eq "C_PHONE" ) {
        $sz = 15 unless ( $sz );
        $result = "<input name=c_phone value=\"$c_phone\" size=$sz>"; 
    }
    elsif ( $field_id eq "P_ADD" ) { 
        $sz = 40 unless ( $sz );
        $result = "<input name=p_first value=\"$p_first\" size=$sz>";
    }
    elsif ( $field_id eq "P_CITY" ) {
        $sz = 20 unless ( $sz );
        $result = "<input name=p_second value=\"$p_second\" size=$sz>";
    }
    elsif ( $field_id eq "P_STATE" ) {
        $sz = 3 unless ( $sz );
        $result = "<input name=p_third value=\"$p_third\" size=$sz>";
    }
    elsif ( $field_id eq "P_ZIP" ) {
        $sz = 10 unless ( $sz );
        $result = "<input name=p_fourth value=\"$p_fourth\" size=$sz>";
    }
    elsif ( $field_id eq "P_CTRY" ) {
        $sz = 20 unless ( $sz );
        $result = "<input name=p_ctry value=\"$p_ctry\" size=$sz>"; 
    }
    elsif ( $field_id eq "P_PHONE" ) {
        $sz = 15 unless ( $sz );
        $result = "<input name=p_phone value=\"$p_phone\" size=$sz>"; 
    }
    elsif ( $field_id eq "PRES1" ) {
        $result = "<select name=president_one>";
        if ( $president_one eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @presidents ) {
            if ( $president_one eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "PRES2" ) {
        $result = "<select name=president_two>";
        if ( $president_two eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @presidents ) {
            if ( $president_two eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "PRES3" ) {
        $result = "<select name=pres_three>";
        if ( $pres_three eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @presidents ) {
            if ( $pres_three eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "PRES4" ) {
        $result = "<select name=pres_four>";
        if ( $pres_four eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @presidents ) {
            if ( $pres_four eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "CHILDREN" ) { 
        $sz = 30 unless ( $sz );
        $result = "<input name=children value=\"$children\" size=$sz"; 
    }
    elsif ( $field_id eq "MISSION" ) { 
        $result = "<select name=whichmis>";
        if ( $whichmis eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @missions ) {
            if ( $whichmis eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "TITLE" ) { 
        $result = "<select name=mis_title>";
        if ( $mis_title eq "" ) {
            $result .= "<option selected value=\"\">";
        }
        else {
            $result .= "<option value=\"\">";
        }
        foreach $elem ( @mistitles ) {
            if ( $mis_title eq $elem ) {
                $result .= "<option selected value=\"$elem\">$elem";
            }
            else {
                $result .= "<option value=\"$elem\">$elem";
            }
        }
        $result .= "</select>";
    }
    elsif ( $field_id eq "OCCUPATION" ) { 
        $sz = 30 unless ( $sz );
        $result = "<input name=occup value=\"$occup\" size=$sz>"; 
    }
    elsif ( $field_id eq "LAST_NOW" ) {
        $sz = 20 unless ( $sz );
        $result = "<input name=last_now value=\"$last_now\" size=$sz>";
    }
    
    return $result;
    
}


############################################################
# RMdB Error Handler
#-----------------------------------------------------------
sub rm_err {
    
    $pg_body = $_[0];
    
    if ( ! $done_cgi_head ) {
        &cgi_header;
    }
    
    $adm_stat = &admin_check;
    
    $pg_title = "$mission_name - Error Report";
    $pg_head  = "ERROR REPORT";
    
    &page_gen( "error", $adm_stat );
    
    exit;
}

###########################################################
# Check for cookie and form value to see if user is
# administrator.
###########################################################
sub admin_check {

    my $up_pass;
    my $ret_val = 0;
    
    $up_pass = $FORM{adm_passwd};
    
    if ( $up_pass eq "" ) {
        if ( &GetCookies( "rmad_pw" ) ) {
            $up_pass = $Cookies{ "rmad_pw" };
        }
    }
    
    if ( $up_pass eq $admin_passwd ) {
        $ret_val = 1;
    }
    
    return $ret_val;
}

###########################################################
# Check for cookie and form value to see if user is
# administrator - Validate and display error if not.
###########################################################
sub validate_admin {

    my $up_pass;
    
    if ( &GetCookies( "rmad_pw" ) ) {
        $up_pass = $Cookies{ "rmad_pw" };
    }
    
    if ( $up_pass ne $admin_passwd ) {
        &rm_err( "ACCESS DENIED! - Administrator Password required.<br><br><a href=\"$cgi_url?action=admin_login\">Click Here</a> to try logging in again.\n" );
    }
}

###########################################################
# Fill the Mission Presidents Array with the names of all
# the Mission Presidents.
#----------------------------------------------------------
sub pop_presarray {

    open(PRESIDENTS,"$data_dir/$db_pres") || &error("sub pop_presarray cant' open database: $!");
    @TMP_PRES = <PRESIDENTS>;
    close(PRESIDENTS);
    
    foreach $line (@TMP_PRES) {
        &pop_pres_flds( $line );
                
        unshift(@PRECS,"$pres_year_st</:/>$pres_name");
    }
    
    @sorted = sort(@PRECS);
    
    foreach $line (@sorted) {
        ($pres_year_st,$pres_name) = split("</:/>", $line);
        
        unshift(@presidents, "$pres_name");
    }
    
}


###########################################################
# Populate fields from ALUMNI record
#----------------------------------------------------------
sub pop_alum_flds {

    my $alum_rec = $_[0];
    
    ($num,$lastname,$firstname,$spouse,$passwd,$served_first,$served_second,
     $served_third,$served_fourth,$email,$homepage,$work,$workurl,$txt_cities,
     $txt_other,$c_first,$c_second,$c_third,$c_fourth,$c_ctry,$c_phone,
     $p_first,$p_second,$p_third,$p_fourth,$p_ctry,$p_phone,$president_one,
     $president_two,$children,$lastdate,$mis_title,$whichmis,$occup,
     $last_now,$eml_stat,$modmon,$modday,$modyear,$add_date,$ver3chk,
     $pres_three,$pres_four,$filler1,$filler2,$filler3,$filler4,
     $filler5,$blank) = split("</:/>",$alum_rec);

}

###########################################################
# Populate fields from LOST CONTACT record
#----------------------------------------------------------
sub pop_lost_flds {

    my $lost_rec = $_[0];
    
    ( $lc_id, $lc_orignum, $lc_last, $lc_first, $lc_info, $lc_origlast,
      $lc_origfirst, $lc_origemail, undef ) = split( "</:/>", $lost_rec );

}


###########################################################
# Populate fields from PRESIDENTS record
#----------------------------------------------------------
sub pop_pres_flds {

    my $pres_rec = $_[0];
    
    ( $pres_id, $pres_name, $pres_mission, $pres_year_st, $pres_year_end,
      $pres_image, $pres_info, $pres_link, undef ) = split( "</:/>", $pres_rec );

}

###########################################################
# Create New Alumni Record from fields
#----------------------------------------------------------
sub create_alum_rec {

    my $write_type = $_[0];
    my $up_all_flds = 1;
    my $retval = "";
    
    if ( $write_type eq "new" ) {
        $passwd = $FORM{password};
        $add_date = $moddate;
        $ver3chk = "rdy30";
    }
    elsif ( $write_type eq "chang_pass" ) {
        $up_all_flds = 0;
        $passwd = $FORM{password};
    }
    elsif ( $write_type eq "mark_eml_stat" ) {
        $up_all_flds = 0;
        $eml_stat = "b";
    }
    elsif ( $write_type eq "db_check" ) {
        $up_all_flds = 0;
        $ver3chk = "rdy30";
        $pres_three = "";
        $pres_four = "";
        $filler1 = "";
        $filler2 = "";
        $filler3 = "";
        $filler4 = "";
        $filler5 = "";
        $blank = "blank";
    }

    if ( $up_all_flds == 1 ) {
        $retval = join("</:/>",$num,$FORM{lastname},$FORM{firstname},$FORM{spouse},
        $passwd,$FORM{served_first},$FORM{served_second},
        $FORM{served_third},$FORM{served_fourth},$FORM{email},
        $FORM{homepage},$FORM{work},$FORM{workurl},$FORM{txt_cities},
        $FORM{txt_other},$FORM{c_first},$FORM{c_second},$FORM{c_third},
        $FORM{c_fourth},$FORM{c_ctry},$FORM{c_phone},$FORM{p_first},
        $FORM{p_second},$FORM{p_third},$FORM{p_fourth},$FORM{p_ctry},
        $FORM{p_phone},$FORM{president_one},$FORM{president_two},
        $FORM{children},$moddate,$FORM{mis_title},$FORM{whichmis},
        $FORM{occup},$FORM{last_now},"a",$modmon,$modday,$modyear,
        $add_date,$ver3chk,$FORM{pres_three},$FORM{pres_four},
        $filler1,$filler2,$filler3,$filler4,$filler5,"blank");
    
    }        
    else {
    
        $retval = join("</:/>",$num,$lastname,$firstname,$spouse,
        $passwd,$served_first,$served_second,$served_third,
        $served_fourth,$email,$homepage,$work,$workurl,$txt_cities,$txt_other,
        $c_first,$c_second,$c_third,$c_fourth,$c_ctry,$c_phone,$p_first,
        $p_second,$p_third,$p_fourth,$p_ctry,$p_phone,$president_one,
        $president_two,$children,$lastdate,$mis_title,$whichmis,$occup,
        $last_now,$eml_stat,$modmon,$modday,$modyear,$add_date,$ver3chk,
        $pres_three,$pres_four,$filler1,$filler2,$filler3,$filler4,
        $filler5,$blank);
    }
    
    return $retval;
    
}

###########################################################
# Get the language variables
#----------------------------------------------------------
sub lng_init {

    $FORM{lid} = "1" unless ($FORM{lid});
    
    open(LNGRECS,"$data_dir/$db_lang") || &error( "sub lng_init can't open database: $!" );
    @LNGRECS = <LNGRECS>;
    close(LNGRECS);
    
    foreach $line (@LNGRECS) {
        ($lng_id,$lng_mis_title,$lng_db_title,$lng_scr_title,$lng_cnt_stat,
        $lng_sort_head,$lng_view_all,$lng_view_start,$lng_view_end,
        $lng_srch_head,$lng_srch_name,$lng_srch_pres,$lng_srch_date,
        $lng_srch_res_city,$lng_city,$lng_state,$lng_view_recent,
        $lng_reg_head,$lng_filler1,$lng_go_button,$lng_reset_button,
        $lng_filler2,
        $lng_filler3,$lng_prob_foot,$lng_view_all_pres,$lng_list_lost,
        $lng_ctry,$lng_srch_instruct,$lng_choose_pres,$lng_choose_mn,
        $lng_choose_yr,$lng_blank) = split("</:/>",$line);
        if ($lng_id eq $FORM{lid}) {
            $lang_id = $lng_id;
            last;
        }
    }
}

###########################################################
# Display Filtered/Sorted List
#----------------------------------------------------------
sub disp_alum_list {

    my $list_id   = $_[0];
    my $list_head = $_[1];
    my $filtered  = $_[2];
    my $list_cnt;
    my @TMPRECS;
    my @sorted;
    my $in_width;
    
    $pg_head = $list_head;
    
    $col_opts = $col_list{ $list_id };
    ( $cfg, $sort ) = split( ",", $col_opts );
    
    open(ADDRESSES,"$data_dir/$db_file") || &error( "sub disp_alum_list can't open database: $!" );
    @ADDRESSES = <ADDRESSES>;
    close(ADDRESSES);
    
    foreach $alum_rec ( @ADDRESSES ) {
        &pop_alum_flds( $alum_rec );
        $include = &filt_rec( $filtered );
        if ( $include == 1 ) {
            if ( $sort eq "1" ) {
                $sortfld = "$lastname$firstname";
                
            }
            elsif ( $sort eq "2" ) {
                $smnth = &convert_month( $served_first );
                $sortfld = "$served_second$smnth";
            }
            elsif ( $sort eq "3" ) {
                $smnth = &convert_month( $served_third );
                $sortfld = "$served_fourth$smnth";
            }
            elsif ( $sort eq "4" ) {
                $sortfld = "$modyear$modmon$modday";
            }
            elsif ( $sort eq "5" ) {
                $sortfld = "$email";
            }
            elsif ( $sort eq "6" ) {
                $sortfld = "$num";
            }
            
            $restflds = join( "</:/>", $lastname, $firstname, 
                          $served_first, $served_second, $served_third,
                          $served_fourth, $email, $c_second, $c_third,
                          $c_ctry, $whichmis, $lastdate, $num );
                          
            $newrec = "$sortfld</:/>$restflds";
                          
            push( @TMPRECS, "$newrec\n" );
        }
    }
        
    if ( $sort eq "6" ) {
        @sorted = reverse( sort( @TMPRECS ) );
    }
    else {
        @sorted = sort( @TMPRECS );
    }
    $list_cnt = @sorted;
    
    $col2_head = &get_col_head_name( $col2_def{ $cfg } );
    $col3_head = &get_col_head_name( $col3_def{ $cfg } );
    $col4_head = &get_col_head_name( $col4_def{ $cfg } );
    
    $pg_body = "<table border=0 cellpadding=3 cellspacing=0 width=$lg_module_width>\n";
    $pg_body .= "<tr><td class=mbody>Alumni Records Listed: $list_cnt</td></tr>\n";
    $pg_body .= "</table>\n";
    
    $pg_body .= "<table border=0 cellpadding=3 cellspacing=0 width=$lg_module_width>\n";
    $pg_body .= "<tr bgcolor=$mod_bg_color2><td>\n";
    
    $in_width = $lg_module_width - 6;
    
    $pg_body .= "<table border=0 cellpadding=2 cellspacing=0 width=$in_width>\n";
    $pg_body .= "<tr bgcolor=$mod3_hd_color><td class=colhead>Name</td>\n";
    
    if ( $col2_head gt "" ) {
        $pg_body .= "<td class=colhead>$col2_head</td>\n";
    }
    
    if ( $col3_head gt "" ) {
        $pg_body .= "<td class=colhead>$col3_head</td>\n";
    }
    
    if ( $col4_head gt "" ) {
        $pg_body .= "<td class=colhead>$col4_head</td>\n";
    }
     
    if ( $adm_stat ) {
        $pg_body .= "<td class=colhead>Admin</td>\n";
    }
    
    $pg_body .= "</tr>\n";   
    
    $row = 0;
    
    foreach $disp_rec ( @sorted ) {
        ( undef, $d_last_name, $d_first_name, $d_start_month, $d_start_year,
          $d_end_month, $d_end_year, $d_email, $d_city, $d_state, $d_country,
          $d_mission, $d_lastdate, $d_num ) = split( "</:/>", $disp_rec );
          
          
        if ( $row == 0 ) {
            $row = 1;
            $row_color = $mod_bg_color1;
        }
        else {
            $row = 0;
            $row_color = $mod_bg_color2;
        }
        
        $pg_body .= "<tr bgcolor=$row_color><td class=mbodybold>\n";
        $pg_body .= "<a href=\"$cgi_url?action=viewentry&entrynum=$d_num\"><b>$d_last_name, $d_first_name</b></a>";
        
        if ( $d_email gt "" ){
            $pg_body .= "&nbsp;<a href=\"mailto:$d_email\"><img src=\"$images_dir/$img_let_bullet\" border=0 alt=\"Send e-mail message to $d_first_name $d_last_name\"></a>";
        }
        $pg_body .= "</td>\n";
        
        if ( $col2_def{ $cfg } gt "" ) {
            $pg_body .= &pop_cell( $col2_def{ $cfg } );
        }
            
        if ( $col3_def{ $cfg } gt "" ) {
            $pg_body .= &pop_cell( $col3_def{ $cfg } );
        }
             
        if ( $col4_def{ $cfg } gt "" ) {
            $pg_body .= &pop_cell( $col4_def{ $cfg } );
        }
        
        if ( $adm_stat ) {
            $pg_body .= "<td class=mbody><a href=\"$cgi_adm_url?action=delete_entry&entrynum=$d_num\"><img src=\"$images_dir/$adm_img_rec_del\" border=0 alt=\"Delete $d_first_name $d_last_name\" width=20 height=10></a>";
            if ( $d_email gt "" ) {
                $pg_body .= "&nbsp;<a href=\"$cgi_adm_url?action=mark_bad_email&entrynum=$d_num\"><img src=\"$images_dir/$adm_img_x_email\" border=0 alt=\"Mark E-Mail Bad for $d_first_name $d_last_name\" width=20 height=10></a>";
            }
            $pg_body .= "</td>\n";
        }
        
        $pg_body .= "</tr>\n";
          
        
    }
        
    $pg_body .= "</table>\n";
    $pg_body .= "</td></tr>\n";
    $pg_body .= "</table>\n";
    
    
    &page_gen( "column", $adm_stat );
    exit;
        
}

###########################################################                   
# Filter records if needed
#----------------------------------------------------------
sub filt_rec {

    my $filtered = $_[0];
    my $result = 0;
    my $s_val;
    my $now = time;
    
    if ( $filtered ) {
        foreach $f_type ( sort keys( %srch_filt ) ) {
            $s_val = $srch_filt{ $f_type };
            if ( $f_type eq "N" ) {
                if ( uc( $lastname ) =~ /^$s_val/ ) {
                    $result = 1;
                }
                else {
                    $result = 0;
                }
            }
            if ( $f_type eq "P" ) {
                if (( uc( $president_one ) eq $s_val ) || 
                    ( uc( $president_two ) eq $s_val ) ||
                    ( uc( $pres_three ) eq $s_val ) || 
                    ( uc( $pres_four ) eq $s_val )) {
                    $result = 1;
                }
                else {
                    $result = 0;
                }
            }
            if ( $f_type eq "T" ) {
                ( $xm, $xy ) = split( ",", $s_val );
                
                $bm = &convert_month( $served_first );
                $em = &convert_month( $served_third );
                $by = $served_second;
                $ey = $served_fourth;
                
                if (( $by < $xy ) && ( $ey > $xy )) {
                    $result = 1;
                }
                elsif (( $by == $xy ) && ( $bm <= $xm )) {
                    $result = 1;
                }
                elsif (( $ey == $xy ) && ( $em >= $xm )) {
                    $result = 1;
                }
                else {
                    $result = 0;
                }
            }
            if ( $f_type eq "E" ) {
                if ( uc( $email ) =~ /^$s_val/ ) {
                    $result = 1;
                }
                else {
                    $result = 0;
                }
            }
            if ( $f_type eq "A" ) {
                ( $xc, $xs, $xt ) = split( ",", $s_val );
                
                if (( $xc gt "" ) && ( $xs gt "" )) {
                    if (( uc( $c_second ) eq uc( $xc )) && 
                        ( uc( $c_third ) eq uc( $xs ))) {
                        $result = 1;
                    }
                    else {
                        $result = 0;
                    }
                }
                elsif ( $xs gt "" ) {
                    if ( uc( $c_third ) eq uc( $xs ) ) {
                        $result = 1;
                    }
                    else {
                        $result = 0;
                    }
                }
                elsif ( $xt gt "" ) {
                    if ( uc( $c_ctry ) eq uc( $xt ) ) {
                        $result = 1;
                    }
                    else {
                        $result = 0;
                    }
                }
                else {
                    $result = 0;
                }
            }
            elsif ( $f_type eq "R" ) {
                $start_time = $now - 2592000;        # 30 Days Ago
                if ( $num > $start_time ) {
                    $result = 1;
                }
                else {
                    $result = 0;
                }
            }    
            
            if ( $result == 0 ) {
                last;
            }
        }
    }
    else {
        $result = 1;
    }
    
    return $result;
}

###########################################################                   
# Convert Month for Sorting
#----------------------------------------------------------
sub convert_month {

    my $in_val = $_[0];
    my $result = "";
    my $cnt = 0;
    
    if ( $in_val eq "" ) { $result = "a"; }
    if ( $result eq "" ) {
        for ( $cnt = 0; $cnt < 12; $cnt++ ) {
            if ( $in_val eq $fullmonth[ $cnt ] ) {
                $result = chr( 98 + $cnt );
                last;
            }
        }
    }
    
    return $result;
}

###########################################################                   
# Get Column Header Name
#----------------------------------------------------------
sub get_col_head_name {

    my $in_val = $_[0];
    my $result = "";
    my $elem;
    
    foreach $elem ( @col_opts ) {
        ( $n, $d ) = split( "::", $elem );
        if ( $in_val eq $n ) {
            $result = $d;
            last;
        }
    }
    
    return $result;
}


###########################################################                   
# Populate the Column value
#----------------------------------------------------------
sub pop_cell {

    my $in_val = $_[0];
    my $result = "";
    my $cell_val;
    
    $result = "<td class=mbody>";
    
    if ( $in_val eq "1" ) {
        $cell_val = "$d_start_year to $d_end_year";
    }
    elsif ( $in_val eq "2" ) {
        $cell_val = "$d_mission";
    }
    elsif ( $in_val eq "3" ) {
        $cell_val = "$d_lastdate";
    }
    elsif ( $in_val eq "4" ) {
        $cell_val = "$d_email";
    }
    elsif ( $in_val eq "5" ) {
        $cell_val = "$d_city, $d_state $d_country";
    }
    elsif ( $in_val eq "6" ) {
        $cell_val = localtime( $d_num );
    }
    
    if ( $cell_val gt "" ) {
        $result .= "$cell_val</td>";
    }
    else {
        $result .= "&nbsp;</td>";
    }
    
    return $result;
}

###########################################################                   
# Read custom values from settings table.
#----------------------------------------------------------
sub read_custom {

    open( CUSTOM, "$data_dir/$db_settings" ) || &error( "Unable to open $db_settings. $!" );
    $set_line = <CUSTOM>;
    close( CUSTOM );
    
    ( @set_vals ) = split( "</:/>", $set_line );
    $admin_name         = $set_vals[ 0 ];
    $admin_address      = $set_vals[ 1 ];
    $mission_name       = $set_vals[ 2 ];
    $home_url           = $set_vals[ 3 ];
    $custom_filler1     = $set_vals[ 4 ];
    $lang_desc_1        = $set_vals[ 5 ];
    $lang_desc_2        = $set_vals[ 6 ];
    $mission_start_year = $set_vals[ 7 ];
    $email_new_users    = $set_vals[ 8 ];
    $new_user_message   = $set_vals[ 9 ];
    $request_pass_msg   = $set_vals[ 10 ];
    $email_admin_on_chg = $set_vals[ 11 ];
    $img_let_bullet     = $set_vals[ 12 ];
    $multi_lang_stat    = $set_vals[ 13 ];
    $lg_module_width    = $set_vals[ 14 ];
    $md_module_width    = $set_vals[ 15 ];
    $sm_module_width    = $set_vals[ 16 ];
    $mod1_hd_color      = $set_vals[ 17 ];
    $mod2_hd_color      = $set_vals[ 18 ];
    $mod3_hd_color      = $set_vals[ 19 ];
    $mod_bg_color1      = $set_vals[ 20 ];
    $mod_bg_color2      = $set_vals[ 21 ];
    $mod_bg_color3      = $set_vals[ 22 ];
    $col2_def{ "1" }    = $set_vals[ 23 ];
    $col3_def{ "1" }    = $set_vals[ 24 ];
    $col4_def{ "1" }    = $set_vals[ 25 ];
    $col2_def{ "2" }    = $set_vals[ 26 ];
    $col3_def{ "2" }    = $set_vals[ 27 ];
    $col4_def{ "2" }    = $set_vals[ 28 ];
    $col2_def{ "3" }    = $set_vals[ 29 ];
    $col3_def{ "3" }    = $set_vals[ 30 ];
    $col4_def{ "3" }    = $set_vals[ 31 ];
    $col2_def{ "4" }    = $set_vals[ 32 ];
    $col3_def{ "4" }    = $set_vals[ 33 ];
    $col4_def{ "4" }    = $set_vals[ 34 ];
    $col_list{ "NAME" } = $set_vals[ 35 ];
    $col_list{ "PRES" } = $set_vals[ 36 ];
    $col_list{ "MAIL" } = $set_vals[ 37 ];
    $col_list{ "BEG" }  = $set_vals[ 38 ];
    $col_list{ "END" }  = $set_vals[ 39 ];
    $col_list{ "ADDR" } = $set_vals[ 40 ];
    $col_list{ "NEW" }  = $set_vals[ 41 ];
    $option{ "S_PRES" } = $set_vals[ 42 ];
    $option{ "S_TIME" } = $set_vals[ 43 ];
    $option{ "S_ADDR" } = $set_vals[ 44 ];
    $option{ "L_NAME" } = $set_vals[ 45 ];
    $option{ "L_BEG" }  = $set_vals[ 46 ];
    $option{ "L_END" }  = $set_vals[ 47 ];
    $option{ "L_PRES" } = $set_vals[ 48 ];
    $option{ "L_LOST" } = $set_vals[ 49 ];
    $admin_upcase       = $set_vals[ 50 ];
    $admin_format_check = $set_vals[ 51 ];
    $admin_force_lower  = $set_vals[ 52 ];
    
}

###########################################################                   
# Print Main Screen
#----------------------------------------------------------
sub print_main {

    $adm_stat = &admin_check;
    
    &pop_presarray;
    &lng_init;
    
    open(ADDRESSES,"$data_dir/$db_file") || &error( "sub print_main can't open database: $!" );
    @ADDRESSES = <ADDRESSES>;
    close(ADDRESSES);
    $num_entries = @ADDRESSES;
    
    $box_width = $lg_module_width / 2;

    $pat_tmp = "</N/>";
    $lng_cnt_stat =~ s/$pat_tmp/$num_entries/o;
    
    $pg_head = "$lng_scr_title";
    
    $pg_main_reg = "<b><a href=\"$cgi_url?action=add_entry_form\">$lng_reg_head</a></b>";

    if ($multi_lang_stat eq "on") {

        if ($FORM{lid} eq 2) {
            $ld = $lang_desc_1;
            $lid = 1;
        }
        else {
            $ld = $lang_desc_2;
            $lid = 2;
        }
        
        $pg_main_lng = "<b><a href=\"$cgi_url?action=print_main&lid=$lid\">$ld</a></b>";
    }
    
    $pg_main_new = "<b><a href=\"$cgi_url?action=search_any&new=1\">$lng_view_recent</a></b>\n";
   
    &page_gen( "home", $adm_stat );
        
}

############################################################
# View the Alumni Entry
#-----------------------------------------------------------
sub viewentry {

    $adm_stat = &admin_check;
    
    $alum_rec = &findentry;
    
    if ( $alum_rec ) {
    
        &pop_alum_flds( $alum_rec );
        
        &page_gen( "view", $adm_stat );
    
    }
    else {
        &rm_err( "Alumni Profile ID not found.  Contact system administrator." );
    }
}


###########################################################                   
# Extract a particular entry based on its record number
#----------------------------------------------------------
sub findentry {

    my $rec;
    my @parts;
    my $result = "";
    
    $FORM{ entrynum } = $num unless ( $FORM{ entrynum } );
    
    open( ADDRESSES, "$data_dir/$db_file") || &error( "sub findentry can't open database: $!" );
    @ADDRESSES = <ADDRESSES>;
    close( ADDRESSES );
    
    foreach $rec ( @ADDRESSES ) {
        ( @parts ) = split( "</:/>", $rec );
        if ( $parts[0] eq $FORM{ entrynum } ) {
            $result = $rec;
            last;
        }
    }
    
    return $result;
}

###########################################################                   
# Convert a string passed to mixed case
#----------------------------------------------------------
sub mc {

    my $retval = $_[0];
    $retval =~ s/(\w+)/\u\L$1/g;
    return $retval;
}

###########################################################                   
# Add Entry to log file
#----------------------------------------------------------
sub add_log {

    my $log_type = $_[0];
    my $log_msg  = $_[1];
    my $log_date = time;
    my $log_ref  = "$ENV{REMOTE_ADDR}";
    
    open( LOG, ">>$data_dir/$db_log" ) || &error( "Unable to open log file: $!" );
    print LOG "$log_date</:/>$log_ref</:/>$log_type</:/>$log_msg</:/>blank\n";
    close( LOG );
    
}

###########################################################                   
# Update Summary File
#----------------------------------------------------------
sub up_summary {

    my @ADDRESS;
    my $num_email = 0;
    my $alum_rec;
    my $num_listed;
    
    # Read the database in to do some housekeeping
    open(ADDRESS,"$data_dir/$db_file") || &error( "sub up_summary can't open database: $!" );
    @ADDRESS = <ADDRESS>;
    close(ADDRESS);

    # Parse the database looking for entries with email addresses
    foreach $alum_rec (@ADDRESS) {
        
        &pop_alum_flds( $alum_rec );
        
        if (($email gt "") && ($eml_stat ne "b")) {
            $num_email++;
        }
    }

    # Get the total number of listings
    $num_listed = @ADDRESS;
   
    # Create an html file showing statistics for the database
    open( SF,">$summary_file") || &error("sub up_summary can't open summary file: [$summary_file] - $!");
    print SF "<HTML>\n";
    print SF "<HEAD>\n";
    print SF "<TITLE>$mission_name Count</TITLE>\n";
    print SF "<BODY>\n";
    print SF "Mission: $mission_name<br>\n";
    print SF "Number of alumni listed: $num_listed<br>\n";
    print SF "Number of e-mail addresses: $num_email<br>\n";
    print SF "Date last amended: $moddate<br>\n";
    print SF "X-Public: YES<br>\n";
    print SF "</BODY>\n";
    print SF "</HTML>\n";
    close( SF );


}

###########################################################                   
# Get Bad IPs - populate the %BAD associative array.
#----------------------------------------------------------
sub pop_badips {
    
    my @BAD;
    my $bad_rec;
    my $ref;
    
    open( BAD, "$data_dir/$db_badips" ) || &error( "pop_badips unable to open bad IPs file: $!" );
    @BAD = <BAD>;
    close( BAD );
    foreach $bad_rec ( @BAD ) {
        ( $ref, undef ) = split( "</:/>", $bad_rec );
        $BAD{ $ref } = 1;
    }
    
}

