D:\my docs\My Received Files\Yabb\Yabb\YaBB_2.5_AEB\cgi-bin\yabb2_old\Sources\ExtendedProfiles.pl D:\WEBSITES\testbed\cgi-bin\yabb252\Sources\ExtendedProfiles.pl
############################################################################### ###############################################################################
# ExtendedProfiles.pl                                                         # # ExtendedProfiles.pl                                                         #
############################################################################### ###############################################################################
# YaBB: Yet another Bulletin Board                                            # # YaBB: Yet another Bulletin Board                                            #
# Version:        YaBB 2.5 Anniversary Edition                                # # Version:        YaBB 2.5.2                                                  #
# Packaged:       July 04, 2010                                               # # Packaged:       September 30, 2012                                          #
# Distributed by: http://www.yabbforum.com                                    # # Distributed by: http://www.yabbforum.com                                    #
# =========================================================================== # # =========================================================================== #
# Copyright (c) 2000-2010 YaBB (www.yabbforum.com) - All Rights Reserved.     # # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved.     #
# Software by:  The YaBB Development Team                                     # # Software by:  The YaBB Development Team                                     #
#               with assistance from the YaBB community.                      # #               with assistance from the YaBB community.                      #
# Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com            #    
#               Your source for web hosting, web design, and domains.         #    
############################################################################### ###############################################################################
   
$extendedprofilesplver = 'YaBB 2.5 AE $Revision: 1.3 $'; $extendedprofilesplver = 'YaBB 2.5.2 $Revision: 1.1 $';
if ($action eq 'detailedversion') { return 1; } if ($action eq 'detailedversion') { return 1; }
   
############################################################################### ###############################################################################
# This file was part of the Extended Profiles Mod which has been created by   # # This file was part of the Extended Profiles Mod which has been created by   #
# Michael Prager. Last modification by him: 15.11.07                          # # Michael Prager. Last modification by him: 15.11.07                          #
# Added to the YaBB default code on 07. September 2008                        # # Added to the YaBB default code on 07. September 2008                        #
############################################################################### ###############################################################################
# file formats used by this code: # file formats used by this code:
# #
#  username.vars - contains the additional user profile information. Number is field-id #  username.vars - contains the additional user profile information. Number is field-id
#  ------------- #  -------------
#  ... #  ...
#  'ext_0',"value" #  'ext_0',"value"
#  'ext_1',"value" #  'ext_1',"value"
#  'ext_2',"value" #  'ext_2',"value"
#  ... #  ...
# #
#  @ext_prof_order - contains the order in which the fields will be displayed #  @ext_prof_order - contains the order in which the fields will be displayed
#  --------------------------- #  ---------------------------
#  ("name","name","name",....) #  ("name","name","name",....)
# #
#  extended_profiles_fields.txt - defines the new profile fields. Uses line number as field-id #  extended_profiles_fields.txt - defines the new profile fields. Uses line number as field-id
#  ---------------------------- #  ----------------------------
#  ("name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname",....) #  ("name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname","name|type|options|active|comment|required_on_reg|visible_in_viewprofile|v_users|v_groups|visible_in_posts|p_users|p_groups|p_displayfieldname|visible_in_memberlist|m_users|m_groups|editable_by_user|visible_in_posts_popup|pp_users|pp_groups|pp_displayfieldname",....)
# #
#  Here are all types with their possible type-specific options. If options contain multiple entries, seperated by ^ #  Here are all types with their possible type-specific options. If options contain multiple entries, separated by ^
#  - text       limit_len^width^is_numberic^default_value^allow_ubbc #  - text       limit_len^width^is_numberic^default_value^allow_ubbc
#  - text_multi     limit_len^rows^cols^allow_ubbc #  - text_multi     limit_len^rows^cols^allow_ubbc
#  - select     option1^option2^option3... (first option is default) #  - select     option1^option2^option3... (first option is default)
#  - radiobuttons   option1^option2^option3... (first option is default) #  - radiobuttons   option1^option2^option3... (first option is default)
#  - spacer     br_or_hr^visible_in_editprofile #  - spacer     br_or_hr^visible_in_editprofile
#  - checkbox       - #  - checkbox       -
#  - date       - #  - date       -
#  - emial      - #  - emial      -
#  - url        - #  - url        -
#  - image      width^height^allowed_extensions #  - image      width^height^allowed_extensions
# #
#  required_on_reg can have value 0 (disabled), 1 (required on registration) and 2 (not req. but display on reg. page anyway) #  required_on_reg can have value 0 (disabled), 1 (required on registration) and 2 (not req. but display on reg. page anyway)
#  editable_by_user can have value 0 (will only show on the "admin edits" page), 1 ("edit profile" page), 2 ("contact information" page), 3 ("Options" page) and 4 ("PM Preferences" page) #  editable_by_user can have value 0 (will only show on the "admin edits" page), 1 ("edit profile" page), 2 ("contact information" page), 3 ("Options" page) and 4 ("PM Preferences" page)
#  allowed_extensions is a space-seperated list of file extensions, example: "jpg jpeg gif bmp png" #  allowed_extensions is a space-seperated list of file extensions, example: "jpg jpeg gif bmp png"
#  v_groups, p_groups, m_groups, pp_groups format: "Administrator" or "Moderator" or "Global Moderator" or NoPost{...} or Post{...} #  v_groups, p_groups, m_groups, pp_groups format: "Administrator" or "Moderator" or "Global Moderator" or NoPost{...} or Post{...}
# #
# NOTE: use prefix "ext_" in sub-, variable- and formnames to prevent conflicts with other mods # NOTE: use prefix "ext_" in sub-, variable- and formnames to prevent conflicts with other mods
# #
# easy mod integration: use &ext_get($username,"fieldname") go get user's field value # easy mod integration: use &ext_get($username,"fieldname") go get user's field value
# #
############################################################################### ###############################################################################
   
&LoadLanguage("ExtendedProfiles"); &LoadLanguage("ExtendedProfiles");
   
$ext_spacer_hr = qq~<hr size="1" width="100%" class="hr" />~; $ext_spacer_hr = qq~<hr size="1" width="100%" class="hr" />~;
$ext_spacer_br = qq~<br />~; $ext_spacer_br = qq~<br />~;
$ext_max_email_length = 60; $ext_max_email_length = 60;
$ext_max_url_length = 100; $ext_max_url_length = 100;
$ext_max_image_length = 100; $ext_max_image_length = 100;
   
my %field; my %field;
   
# outputs the value of a user's extended profile field # outputs the value of a user's extended profile field
## USAGE: $value = ext_get("admin","my_custom_fieldname"); ## USAGE: $value = ext_get("admin","my_custom_fieldname");
##  or    $value_raw = ext_get("admin","my_custom_fieldname",1); ##  or    $value_raw = ext_get("admin","my_custom_fieldname",1);
## pass the third argument if you want to get the raw content e.g. an unformated date ## pass the third argument if you want to get the raw content e.g. an unformated date
sub ext_get { sub ext_get {
   my ($pusername, $fieldname, $no_parse, @ext_profile, @options, $id, $value, $width, $height, @allowed_extensions, $extension, $match) = (shift, shift, shift);    my ($pusername, $fieldname, $no_parse, @ext_profile, @options, $id, $value, $width, $height, @allowed_extensions, $extension, $match) = (shift, shift, shift);
   &ext_get_profile($pusername);    &ext_get_profile($pusername);
   $id = &ext_get_field_id($fieldname);    $id = &ext_get_field_id($fieldname);
   $value = ${$uid.$pusername}{'ext_'.$id};    $value = ${$uid.$pusername}{'ext_'.$id};
   if ($no_parse eq "" || $no_parse == 0) {    if ($no_parse eq "" || $no_parse == 0) {
       &ext_get_field($id);        &ext_get_field($id);
       if ($field{'type'} eq "text") {        if ($field{'type'} eq "text") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($options[3] ne "" && $value eq "") { $value = $options[3]; }            if ($options[3] ne "" && $value eq "") { $value = $options[3]; }
           if ($options[4] == 1) { $value = &ext_parse_ubbc($value, $pusername); }            if ($options[4] == 1) { $value = &ext_parse_ubbc($value, $pusername); }
   
       } elsif ($field{'type'} eq "text_multi" && $value ne "") {        } elsif ($field{'type'} eq "text_multi" && $value ne "") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($options[3] == 1) { $value = &ext_parse_ubbc($value, $pusername); }            if ($options[3] == 1) { $value = &ext_parse_ubbc($value, $pusername); }
   
       } elsif ($field{'type'} eq "select") {        } elsif ($field{'type'} eq "select") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($value > $#options || $value eq "") { $value = 0; }            if ($value > $#options || $value eq "") { $value = 0; }
           $value = $options[$value];            $value = $options[$value];
   
       } elsif ($field{'type'} eq "radiobuttons") {        } elsif ($field{'type'} eq "radiobuttons") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($value > $#options) { $value = 0; }            if ($value > $#options) { $value = 0; }
           if(!$field{'radiounselect'} && $value eq "") { $value = 0; }            if(!$field{'radiounselect'} && $value eq "") { $value = 0; }
           if($value ne "") { $value = $options[$value]; }            if($value ne "") { $value = $options[$value]; }
   
       } elsif ($field{'type'} eq "date" && $value ne "") {        } elsif ($field{'type'} eq "date" && $value ne "") {
           $value = &ext_timeformat($value);            $value = &ext_timeformat($value);
   
       } elsif ($field{'type'} eq "checkbox") {        } elsif ($field{'type'} eq "checkbox") {
           if ($value == 1) { $value = $lang_ext{'true'} }            if ($value == 1) { $value = $lang_ext{'true'} }
           else { $value = $lang_ext{'false'} }            else { $value = $lang_ext{'false'} }
   
       } elsif ($field{'type'} eq "spacer") {        } elsif ($field{'type'} eq "spacer") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($options[0] == 1) { $value = qq~$ext_spacer_br~; }            if ($options[0] == 1) { $value = qq~$ext_spacer_br~; }
           else { $value = qq~$ext_spacer_hr~; }            else { $value = qq~$ext_spacer_hr~; }
   
       } elsif ($field{'type'} eq "url" && $value ne "") {        } elsif ($field{'type'} eq "url" && $value ne "") {
           if ($value !~ m~\Ahttp://~) { $value = "http://$value"; }            if ($value !~ m~\Ahttp://~) { $value = "http://$value"; }
   
       } elsif ($field{'type'} eq "image" && $value ne "") {        } elsif ($field{'type'} eq "image" && $value ne "") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($options[2] ne "") {            if ($options[2] ne "") {
               @allowed_extensions = split(/ /,$options[2]);                @allowed_extensions = split(/ /,$options[2]);
               $match = 0;                $match = 0;
               foreach $extension (@allowed_extensions){                foreach $extension (@allowed_extensions){
                   if (grep /$extension$/i,$value) { $match = 1; last; }                    if (grep /$extension$/i,$value) { $match = 1; last; }
               }                }
               if ($match == 0) { return ""; }                if ($match == 0) { return ""; }
           }            }
           if ($options[0] ne "" && $options[0] != 0) { $width = " width=\"".($options[0]+0)."\""; } else { $width = ""; }            if ($options[0] ne "" && $options[0] != 0) { $width = " width=\"".($options[0]+0)."\""; } else { $width = ""; }
           if ($options[1] ne "" && $options[1] != 0) { $height = " height=\"".($options[1]+0)."\""; } else { $height = ""; }            if ($options[1] ne "" && $options[1] != 0) { $height = " height=\"".($options[1]+0)."\""; } else { $height = ""; }
           if ($value !~ m~\Ahttp://~) { $value = "http://$value"; }            if ($value !~ m~\Ahttp://~) { $value = "http://$value"; }
           $value = qq~<img src="$value" align="top"$width$height alt="" />~;            $value = qq~<img src="$value" align="top"$width$height alt="" />~;
       }        }
   }    }
   
   $value;    $value;
} }
   
# loads the (extended) profile of a user # loads the (extended) profile of a user
sub ext_get_profile { sub ext_get_profile {
   &LoadUser(shift);    &LoadUser(shift);
} }
   
# returns an array of the form qw(ext_0 ext_1 ext_2 ...) # returns an array of the form qw(ext_0 ext_1 ext_2 ...)
sub ext_get_fields_array { sub ext_get_fields_array {
   my ($count, @result) = (0);    my ($count, @result) = (0);
   foreach (@ext_prof_fields) {    foreach (@ext_prof_fields) {
       push(@result, "ext_$count");        push(@result, "ext_$count");
       $count++;        $count++;
   }    }
   @result;    @result;
} }
   
# returns the id of a field through the fieldname # returns the id of a field through the fieldname
sub ext_get_field_id { sub ext_get_field_id {
   my ($fieldname, $count, $id, $current, $currentname, $dummy) = (shift, 0);    my ($fieldname, $count, $id, $current, $currentname, $dummy) = (shift, 0);
   foreach $current (@ext_prof_fields) {    foreach $current (@ext_prof_fields) {
       ($currentname, $dummy) = split(/\|/, $current);        ($currentname, $dummy) = split(/\|/, $current);
       if ($currentname eq $fieldname) { $id = $count; last; }        if ($currentname eq $fieldname) { $id = $count; last; }
       $count++;        $count++;
   }    }
   $id;    $id;
} }
   
# returns all settings of a specifig field # returns all settings of a specific field
sub ext_get_field { sub ext_get_field {
   $field{'id'} = shift;    $field{'id'} = shift;
   
   ($field{'name'},    ($field{'name'},
    $field{'type'},     $field{'type'},
    $field{'options'},     $field{'options'},
    $field{'active'},     $field{'active'},
    $field{'comment'},     $field{'comment'},
    $field{'required_on_reg'},     $field{'required_on_reg'},
    $field{'visible_in_viewprofile'},     $field{'visible_in_viewprofile'},
    $field{'v_users'},     $field{'v_users'},
    $field{'v_groups'},     $field{'v_groups'},
    $field{'visible_in_posts'},     $field{'visible_in_posts'},
    $field{'p_users'},     $field{'p_users'},
    $field{'p_groups'},     $field{'p_groups'},
    $field{'p_displayfieldname'},     $field{'p_displayfieldname'},
    $field{'visible_in_memberlist'},     $field{'visible_in_memberlist'},
    $field{'m_users'},     $field{'m_users'},
    $field{'m_groups'},     $field{'m_groups'},
    $field{'editable_by_user'},     $field{'editable_by_user'},
    $field{'visible_in_posts_popup'},     $field{'visible_in_posts_popup'},
    $field{'pp_users'},     $field{'pp_users'},
    $field{'pp_groups'},     $field{'pp_groups'},
    $field{'pp_displayfieldname'},     $field{'pp_displayfieldname'},
    $field{'radiounselect'},     $field{'radiounselect'},
    undef) = split(/\|/, $ext_prof_fields[$field{'id'}]);     undef) = split(/\|/, $ext_prof_fields[$field{'id'}]);
} }
   
# formats a MM/DD/YYYY string to the user's prefered format, ignores time completely! # formats a MM/DD/YYYY string to the user's prefered format, ignores time completely!
sub ext_timeformat { sub ext_timeformat {
   my ($mytimeselected,$oldformat,$newformat,$mytimeformat,$newday,$newday2,$newmonth,$newmonth2,$newyear,$newshortyear,$oldmonth,$oldday,$oldyear,$newweekday,$newyearday,$newweek,$dummy,$usefullmonth);    my ($mytimeselected,$oldformat,$newformat,$mytimeformat,$newday,$newday2,$newmonth,$newmonth2,$newyear,$newshortyear,$oldmonth,$oldday,$oldyear,$newweekday,$newyearday,$newweek,$dummy,$usefullmonth);
   
   if (${$uid.$username}{'timeselect'} > 0) { $mytimeselected = ${$uid.$username}{'timeselect'}; } else { $mytimeselected = $timeselected; }    if (${$uid.$username}{'timeselect'} > 0) { $mytimeselected = ${$uid.$username}{'timeselect'}; } else { $mytimeselected = $timeselected; }
   
   $oldformat = shift;    $oldformat = shift;
   if ($oldformat eq '' || $oldformat eq "\n") { return $oldformat; }    if ($oldformat eq '' || $oldformat eq "\n") { return $oldformat; }
   
   $oldmonth = substr($oldformat,0,2);    $oldmonth = substr($oldformat,0,2);
   $oldday = substr($oldformat,3,2);    $oldday = substr($oldformat,3,2);
   $oldyear = substr($oldformat,6,4);    $oldyear = substr($oldformat,6,4);
   
   if ($oldformat ne '') {    if ($oldformat ne '') {
       $newday = $oldday+0;        $newday = $oldday+0;
       $newmonth = $oldmonth+0;        $newmonth = $oldmonth+0;
       $newyear = $oldyear+0;        $newyear = $oldyear+0;
       $newshortyear = substr($newyear,2,2);        $newshortyear = substr($newyear,2,2);
       if ($newmonth < 10) { $newmonth = "0$newmonth"; }        if ($newmonth < 10) { $newmonth = "0$newmonth"; }
       if ($newday < 10 && $mytimeselected != 4) { $newday = "0$newday"; }        if ($newday < 10 && $mytimeselected != 4) { $newday = "0$newday"; }
   
       if ($mytimeselected == 1) {        if ($mytimeselected == 1) {
           qq~$newmonth/$newday/$newshortyear~;            qq~$newmonth/$newday/$newshortyear~;
   
       } elsif ($mytimeselected == 2) {        } elsif ($mytimeselected == 2) {
           qq~$newday.$newmonth.$newshortyear~;            qq~$newday.$newmonth.$newshortyear~;
   
       } elsif ($mytimeselected == 3) {        } elsif ($mytimeselected == 3) {
           qq~$newday.$newmonth.$newyear~;            qq~$newday.$newmonth.$newyear~;
   
       } elsif ($mytimeselected == 4) {        } elsif ($mytimeselected == 4) {
           $newmonth--;            $newmonth--;
           $newmonth2 = $months[$newmonth];            $newmonth2 = $months[$newmonth];
           if( $newday > 10 && $newday < 20 ) { $newday2 = "<sup>$timetxt{'4'}</sup>"; }            if( $newday > 10 && $newday < 20 ) { $newday2 = "<sup>$timetxt{'4'}</sup>"; }
           elsif( $newday % 10 == 1 ) { $newday2 = "<sup>$timetxt{'1'}</sup>"; }            elsif( $newday % 10 == 1 ) { $newday2 = "<sup>$timetxt{'1'}</sup>"; }
           elsif( $newday % 10 == 2 ) { $newday2 = "<sup>$timetxt{'2'}</sup>"; }            elsif( $newday % 10 == 2 ) { $newday2 = "<sup>$timetxt{'2'}</sup>"; }
           elsif( $newday % 10 == 3 ) { $newday2 = "<sup>$timetxt{'3'}</sup>"; }            elsif( $newday % 10 == 3 ) { $newday2 = "<sup>$timetxt{'3'}</sup>"; }
           else{ $newday2 = "<sup>$timetxt{'4'}</sup>"; }            else{ $newday2 = "<sup>$timetxt{'4'}</sup>"; }
           qq~$newmonth2 $newday$newday2, $newyear~;            qq~$newmonth2 $newday$newday2, $newyear~;
   
       } elsif ($mytimeselected == 5) {        } elsif ($mytimeselected == 5) {
           qq~$newmonth/$newday/$newshortyear~;            qq~$newmonth/$newday/$newshortyear~;
   
       } elsif ($mytimeselected == 6) {        } elsif ($mytimeselected == 6) {
           $newmonth2 = $months[$newmonth-1];            $newmonth2 = $months[$newmonth-1];
           qq~$newday. $newmonth2 $newyear~;            qq~$newday. $newmonth2 $newyear~;
   
       } elsif ($mytimeselected == 7) {        } elsif ($mytimeselected == 7) {
           ($dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$newweekday,$newyearday,$dummy) = gmtime($oldformat);            ($dummy,$dummy,$dummy,$dummy,$dummy,$dummy,$newweekday,$newyearday,$dummy) = gmtime($oldformat);
           $newweek = int(( $newyearday + 1 - $newweekday ) / 7 )+1;            $newweek = int(( $newyearday + 1 - $newweekday ) / 7 )+1;
   
           $mytimeformat = ${$uid.$username}{'timeformat'};            $mytimeformat = ${$uid.$username}{'timeformat'};
           if ($mytimeformat =~ m/MM/) {$usefullmonth = 1;}            if ($mytimeformat =~ m/MM/) {$usefullmonth = 1;}
           $mytimeformat =~ s/(?:\s)*\@(?:\s)*//g;            $mytimeformat =~ s/(?:\s)*\@(?:\s)*//g;
           $mytimeformat =~ s/HH(?:\s)?//g;            $mytimeformat =~ s/HH(?:\s)?//g;
           $mytimeformat =~ s/mm(?:\s)?//g;            $mytimeformat =~ s/mm(?:\s)?//g;
           $mytimeformat =~ s/ss(?:\s)?//g;            $mytimeformat =~ s/ss(?:\s)?//g;
           $mytimeformat =~ s/://g;            $mytimeformat =~ s/://g;
           $mytimeformat =~ s/ww(?:\s)?//g;            $mytimeformat =~ s/ww(?:\s)?//g;
           $mytimeformat =~ s/(.*?)(?:\s)*$/$1/g;            $mytimeformat =~ s/(.*?)(?:\s)*$/$1/g;
   
           if ($mytimeformat =~ m/\+/) {            if ($mytimeformat =~ m/\+/) {
               if( $newday > 10 && $newday < 20 ) { $dayext = "<sup>$timetxt{'4'}</sup>"; }                  if( $newday > 10 && $newday < 20 ) { $dayext = "<sup>$timetxt{'4'}</sup>"; }  
               elsif( $newday % 10 == 1 ) { $dayext = "<sup>$timetxt{'1'}</sup>"; }                elsif( $newday % 10 == 1 ) { $dayext = "<sup>$timetxt{'1'}</sup>"; }
               elsif( $newday % 10 == 2 ) { $dayext = "<sup>$timetxt{'2'}</sup>"; }                elsif( $newday % 10 == 2 ) { $dayext = "<sup>$timetxt{'2'}</sup>"; }
               elsif( $newday % 10 == 3 ) { $dayext = "<sup>$timetxt{'3'}</sup>"; }                elsif( $newday % 10 == 3 ) { $dayext = "<sup>$timetxt{'3'}</sup>"; }
               else { $dayext = "<sup>$timetxt{'4'}</sup>"; }                else { $dayext = "<sup>$timetxt{'4'}</sup>"; }
           }            }
           $mytimeformat =~ s/YYYY/$newyear/g;            $mytimeformat =~ s/YYYY/$newyear/g;
           $mytimeformat =~ s/YY/$newshortyear/g;            $mytimeformat =~ s/YY/$newshortyear/g;
           $mytimeformat =~ s/DD/$newday/g;            $mytimeformat =~ s/DD/$newday/g;
           $mytimeformat =~ s/D/$newday/g;            $mytimeformat =~ s/D/$newday/g;
           $mytimeformat =~ s/\+/$dayext/g;            $mytimeformat =~ s/\+/$dayext/g;
           if ($usefullmonth == 1){            if ($usefullmonth == 1){
               $mytimeformat =~ s/MM/$months[$newmonth-1]/g;                $mytimeformat =~ s/MM/$months[$newmonth-1]/g;
           } else {            } else {
               $mytimeformat =~ s/M/$newmonth/g;                $mytimeformat =~ s/M/$newmonth/g;
           }            }
   
           $mytimeformat =~ s/\*//g;            $mytimeformat =~ s/\*//g;
           $mytimeformat;            $mytimeformat;
       }        }
   } else { ''; }    } else { ''; }
} }
   
# returns whenever the current user is allowed to view a field or not # returns whenever the current user is allowed to view a field or not
sub ext_has_access { sub ext_has_access {
   my ($allowed_users, $allowed_groups, $usergroup, $useraddgroup, $postcount, $groupid) = (shift, shift, 0, ${$uid.$username}{'position'}, ${$uid.$username}{'addgroups'}, ${$uid.$username}{'postcount'}, undef);    my ($allowed_users, $allowed_groups, $usergroup, $useraddgroup, $postcount, $groupid) = (shift, shift, 0, ${$uid.$username}{'position'}, ${$uid.$username}{'addgroups'}, ${$uid.$username}{'postcount'}, undef);
   
   if ($allowed_users ne "" || $allowed_groups ne "") {    if ($allowed_users ne "" || $allowed_groups ne "") {
       foreach (split(/,/, $allowed_users)) { return 1 if $_ eq $username; }        foreach (split(/,/, $allowed_users)) { return 1 if $_ eq $username; }
   
       # example list of allowed groups:        # example list of allowed groups:
       # ('Administrator', 'Moderator', 'Global Moderator', 'Post{-1}', 'NoPost{1}')        # ('Administrator', 'Moderator', 'Global Moderator', 'Post{-1}', 'NoPost{1}')
       foreach my $group (split(/\s*,\s*/, $allowed_groups)) {        foreach my $group (split(/\s*,\s*/, $allowed_groups)) {
           # check if user is in one of these groups            # check if user is in one of these groups
           if ($group eq "Administrator" || $group eq "Moderator" || $group eq "Global Moderator") {            if ($group eq "Administrator" || $group eq "Moderator" || $group eq "Global Moderator") {
               if ($usergroup eq $group) { return 1; }                if ($usergroup eq $group) { return 1; }
   
           # check if user is on a post-independend group            # check if user is on a post-independent group
           } elsif ($group =~ m~^NoPost{(\d+)}$~) {            } elsif ($group =~ m~^NoPost{(\d+)}$~) {
               $groupid = $1;                $groupid = $1;
               # check if group exists at all                # check if group exists at all
               if ($groupid ne "" && exists $NoPost{$groupid}) {                if ($groupid ne "" && exists $NoPost{$groupid}) {
                   # check if group id is in user position or addgroup field                    # check if group id is in user position or addgroup field
                   if ($usergroup eq $groupid) { return 1; }                    if ($usergroup eq $groupid) { return 1; }
                   foreach (split(/,/,$useraddgroup)) {                    foreach (split(/,/,$useraddgroup)) {
                       if ($_ eq $groupid) { return 1; }                        if ($_ eq $groupid) { return 1; }
                   }                    }
               }                }
   
           # check if user is in one of the post-depending groups...            # check if user is in one of the post-depending groups...
           } elsif ($group =~ m~^Post{(\d+)}$~) {            } elsif ($group =~ m~^Post{(\d+)}$~) {
               $groupid = $1;                $groupid = $1;
               foreach (sort { $b <=> $a } keys %Post) {                foreach (sort { $b <=> $a } keys %Post) {
                   if ($postcount > $_) {                    if ($postcount > $_) {
                       # found the group the user is in                        # found the group the user is in
                       if ($_ eq $groupid) { return 1; }                        if ($_ eq $groupid) { return 1; }
                   }                    }
               }                }
           }            }
       }        }
       return 0;        return 0;
   }    }
   return 1;    return 1;
} }
   
# applies UBBC code to a string # applies UBBC code to a string
sub ext_parse_ubbc { sub ext_parse_ubbc {
   my ($source, $temp);    my ($source, $temp);
   ($source, $displayname, $temp) = ($_[0], $_[1], $message);    ($source, $displayname, $temp) = ($_[0], $_[1], $message);
   $message = $source;    $message = $source;
   require "$sourcedir/YaBBC.pl";    require "$sourcedir/YaBBC.pl";
   &DoUBBC;    &DoUBBC;
   &ToChars($message);    &ToChars($message);
   $source = $message;    $source = $message;
   $message = $temp;    $message = $temp;
   $source;    $source;
} }
   
# returns the output for the viewprofile page # returns the output for the viewprofile page
sub ext_viewprofile { sub ext_viewprofile {
   my ($pusername, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $count, $last_field_id, $pre_output) = (shift);    my ($pusername, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $count, $last_field_id, $pre_output) = (shift);
   
   if ($#ext_prof_order > 0) { $last_field_id = &ext_get_field_id($ext_prof_order[$#ext_prof_order]); }    if ($#ext_prof_order > 0) { $last_field_id = &ext_get_field_id($ext_prof_order[$#ext_prof_order]); }
   
   foreach $fieldname (@ext_prof_order) {    foreach $fieldname (@ext_prof_order) {
       $id = &ext_get_field_id($fieldname);        $id = &ext_get_field_id($fieldname);
       &ext_get_field($id);        &ext_get_field($id);
       $value = &ext_get($pusername,$fieldname);        $value = &ext_get($pusername,$fieldname);
   
       # make sure the field is visible and the user allowed to view the current field        # make sure the field is visible and the user allowed to view the current field
       if ($field{'visible_in_viewprofile'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'v_users'},$field{'v_groups'})) {        if ($field{'visible_in_viewprofile'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'v_users'},$field{'v_groups'})) {
           if ($output eq "" && $previous ne 1) {            if ($output eq "" && $previous ne 1) {
               $pre_output = qq~                $pre_output = qq~
   <tr>    <tr>
       <td class="windowbg2" align="left" valign="top">~;        <td class="windowbg2" align="left" valign="top">~;
               $previous = 1;                $previous = 1;
           }            }
           # format the output dependend of the field type            # format the output dependend of the field type
           if (($field{'type'} eq "text" && $value ne "") ||            if (($field{'type'} eq "text" && $value ne "") ||
               ($field{'type'} eq "text_multi" && $value ne "") ||                ($field{'type'} eq "text_multi" && $value ne "") ||
               ($field{'type'} eq "select" && $value ne " ") ||                ($field{'type'} eq "select" && $value ne " ") ||
               ($field{'type'} eq "radiobuttons" && $value ne "") ||                ($field{'type'} eq "radiobuttons" && $value ne "") ||
               ($field{'type'} eq "date" && $value ne "") ||                ($field{'type'} eq "date" && $value ne "") ||
               $field{'type'} eq "checkbox") {                $field{'type'} eq "checkbox") {
               $output .= qq~                $output .= qq~
           <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">
           <b>$field{'name'}:</b>            <b>$field{'name'}:</b>
           </div>            </div>
           <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">
           $value&nbsp;            $value&nbsp;
           </div>~;            </div>~;
               $previous = 0;                $previous = 0;
   
           } elsif ($field{'type'} eq "spacer") {            } elsif ($field{'type'} eq "spacer") {
               # only print spacer if the previous entry was no spacer of the same type and if this is not the last entry                # only print spacer if the previous entry was no spacer of the same type and if this is not the last entry
               if (($previous eq 0 || $field{'comment'} ne "") && $id ne $last_field_id) {                if (($previous eq 0 || $field{'comment'} ne "") && $id ne $last_field_id) {
                   if ($value eq $ext_spacer_br) {                    if ($value eq $ext_spacer_br) {
                       $output .= qq~                        $output .= qq~
           <div style="float: left; width: 100%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 100%; padding-top: 5px;  padding-bottom: 5px;">
           $ext_spacer_br            $ext_spacer_br
           </div>~;            </div>~;
                       $previous = 0;                        $previous = 0;
                   } else {                    } else {
                       $output .= qq~                        $output .= qq~
       </td>        </td>
   </tr>    </tr>
   <tr>~;    <tr>~;
                       if ($field{'comment'} ne "") {                        if ($field{'comment'} ne "") {
                           $output .= qq~                            $output .= qq~
       <td class="catbg" align="left">        <td class="catbg" align="left">
           <img src="$imagesdir/profile.gif" alt="" border="0" style="vertical-align: middle;" />&nbsp;              <img src="$imagesdir/profile.gif" alt="" border="0" style="vertical-align: middle;" />&nbsp;  
           <span class="text1"><b>$field{'comment'}</b></span>            <span class="text1"><b>$field{'comment'}</b></span>
       </td>        </td>
   </tr>    </tr>
   <tr>    <tr>
       <td class="windowbg2" align="left" valign="top">~;        <td class="windowbg2" align="left" valign="top">~;
                       } else {                        } else {
                           $output .= qq~                            $output .= qq~
       <td class="windowbg2" align="left" valign="top">~;        <td class="windowbg2" align="left" valign="top">~;
                       }                        }
                       $previous = 1;                        $previous = 1;
                   }                    }
               }                }
   
           } elsif ($field{'type'} eq "email" && $value ne "") {            } elsif ($field{'type'} eq "email" && $value ne "") {
               $output .= qq~                $output .= qq~
           <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">
           <b>$field{'name'}:</b>            <b>$field{'name'}:</b>
           </div>            </div>
           <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">
           ~ . &enc_eMail($img_txt{'69'},$value,'','') . qq~            ~ . &enc_eMail($img_txt{'69'},$value,'','') . qq~
           </div>~;            </div>~;
               $previous = 0;                $previous = 0;
   
           } elsif ($field{'type'} eq "url" && $value ne "") {            } elsif ($field{'type'} eq "url" && $value ne "") {
               $output .= qq~                $output .= qq~
           <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">
           <b>$field{'name'}:</b>            <b>$field{'name'}:</b>
           </div>            </div>
           <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">
           <a href="$value" target="_blank">$value</a>            <a href="$value" target="_blank">$value</a>
           </div>~;            </div>~;
               $previous = 0;                $previous = 0;
   
           } elsif ($field{'type'} eq "image" && $value ne "") {            } elsif ($field{'type'} eq "image" && $value ne "") {
               $output .= qq~                $output .= qq~
           <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 30%; padding-top: 5px;  padding-bottom: 5px;">
           <b>$field{'name'}:</b>            <b>$field{'name'}:</b>
           </div>            </div>
           <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">            <div style="float: left; width: 70%; padding-top: 5px;  padding-bottom: 5px;">
           $value            $value
           </div>~;            </div>~;
               $previous = 0;                $previous = 0;
           }            }
       }        }
   }    }
   # only add spacer if there there is at least one field displayed    # only add spacer if there there is at least one field displayed
   if ($output ne "") {    if ($output ne "") {
       $output = $pre_output . $output . qq~        $output = $pre_output . $output . qq~
       </td>        </td>
   </tr>~;    </tr>~;
   }    }
   $output;    $output;
} }
   
# returns the output for the post page # returns the output for the post page
sub ext_viewinposts { sub ext_viewinposts {
   my ($pusername, $popup, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $pre_output, $visible, $users, $groups, $displayfieldname) = (shift, shift);    my ($pusername, $popup, @ext_profile, $id, $output, $fieldname, @options, $value, $previous, $pre_output, $visible, $users, $groups, $displayfieldname) = (shift, shift);
   
   if ($pusername ne 'Guest') {    if ($pusername ne 'Guest') {
       foreach $fieldname (@ext_prof_order) {        foreach $fieldname (@ext_prof_order) {
           $id = &ext_get_field_id($fieldname);            $id = &ext_get_field_id($fieldname);
           &ext_get_field($id);            &ext_get_field($id);
           $value = &ext_get($pusername,$fieldname);            $value = &ext_get($pusername,$fieldname);
   
           if ($popup ne "") {            if ($popup ne "") {
               $visible = $field{'visible_in_posts_popup'};                $visible = $field{'visible_in_posts_popup'};
               $users = $field{'pp_users'};                $users = $field{'pp_users'};
               $groups = $field{'pp_groups'};                $groups = $field{'pp_groups'};
               $displayfieldname = $field{'pp_displayfieldname'};                $displayfieldname = $field{'pp_displayfieldname'};
           } else {            } else {
               $visible = $field{'visible_in_posts'};                $visible = $field{'visible_in_posts'};
               $users = $field{'p_users'};                $users = $field{'p_users'};
               $groups = $field{'p_groups'};                $groups = $field{'p_groups'};
               $displayfieldname = $field{'p_displayfieldname'};                $displayfieldname = $field{'p_displayfieldname'};
           }            }
   
           # make sure the field is visible and the user allowed to view the current field            # make sure the field is visible and the user allowed to view the current field
           if ($visible == 1 && $field{'active'} == 1 && &ext_has_access($users,$groups)) {            if ($visible == 1 && $field{'active'} == 1 && &ext_has_access($users,$groups)) {
               if ($displayfieldname == 1) { $displayedfieldname = "$field{'name'}: "; } else { $displayedfieldname = ""; }                if ($displayfieldname == 1) { $displayedfieldname = "$field{'name'}: "; } else { $displayedfieldname = ""; }
               if ($output eq "") { $output = qq~$ext_spacer_br\n~; }                if ($output eq "") { $output = qq~$ext_spacer_br\n~; }
               # format the output dependend of the field type                # format the output dependend of the field type
               if (($field{'type'} eq "text" && $value ne "") ||                if (($field{'type'} eq "text" && $value ne "") ||
                   ($field{'type'} eq "text_multi" && $value ne "") ||                    ($field{'type'} eq "text_multi" && $value ne "") ||
                   ($field{'type'} eq "select" && $value ne " ") ||                    ($field{'type'} eq "select" && $value ne " ") ||
                   ($field{'type'} eq "radiobuttons" && $value ne "") ||                    ($field{'type'} eq "radiobuttons" && $value ne "") ||
                   ($field{'type'} eq "date" && $value ne "") ||                    ($field{'type'} eq "date" && $value ne "") ||
                   $field{'type'} eq "checkbox") {                    $field{'type'} eq "checkbox") {
                   $output .= qq~$displayedfieldname$value<br />\n~;                    $output .= qq~$displayedfieldname$value<br />\n~;
                   $previous = "";                    $previous = "";
               } elsif ($field{'type'} eq "spacer") {                } elsif ($field{'type'} eq "spacer") {
                   # those tags are required to keep the doc XHTML 1.0 valid                    # those tags are required to keep the doc XHTML 1.0 valid
                   if ($previous ne "</small>$value<small>") {                    if ($previous ne "</small>$value<small>") {
                       $previous = qq~</small>$value<small>~;                        $previous = qq~</small>$value<small>~;
                       $output .= $previous;                        $output .= $previous;
                   }                    }
               } elsif ($field{'type'} eq "email" && $value ne "") {                } elsif ($field{'type'} eq "email" && $value ne "") {
                   $output .= $displayedfieldname . &enc_eMail($img_txt{'69'},$value,'','') . qq~<br />\n~;                    $output .= $displayedfieldname . &enc_eMail($img_txt{'69'},$value,'','') . qq~<br />\n~;
                   $previous = "";                    $previous = "";
               } elsif ($field{'type'} eq "url" && $value ne "") {                } elsif ($field{'type'} eq "url" && $value ne "") {
                   $output .= qq~$displayedfieldname<a href="$value" target="_blank">$value</a><br />\n~;                    $output .= qq~$displayedfieldname<a href="$value" target="_blank">$value</a><br />\n~;
                   $previous = "";                    $previous = "";
               } elsif ($field{'type'} eq "image" && $value ne "") {                } elsif ($field{'type'} eq "image" && $value ne "") {
                   $output .= qq~$displayedfieldname$value<br />\n~;                    $output .= qq~$displayedfieldname$value<br />\n~;
                   $previous = "";                    $previous = "";
               }                }
           }            }
       }        }
   }    }
   # check if there we have any output (except spacers) at all. If so, return empty output    # check if there we have any output (except spacers) at all. If so, return empty output
   $pre_output = $output;    $pre_output = $output;
   $pre_output =~ s~(?:\</small>(?:(?:$ext_spacer_hr)|(?:$ext_spacer_br))<small>)|\n|(?:\<br(?: /)?>)~~ig;    $pre_output =~ s~(?:\</small>(?:(?:$ext_spacer_hr)|(?:$ext_spacer_br))<small>)|\n|(?:\<br(?: /)?>)~~ig;
   if ($pre_output eq "") { $output = ""; }    if ($pre_output eq "") { $output = ""; }
   
   $output;    $output;
} }
   
{ {
   # we need a "static" variable to produce unique element ids    # we need a "static" variable to produce unique element ids
   my $ext_usercount = 0;    my $ext_usercount = 0;
   # returns the output for the post page (popup box)    # returns the output for the post page (popup box)
   sub ext_viewinposts_popup {    sub ext_viewinposts_popup {
       my ($pusername,$link,$output) = (shift,shift);        my ($pusername,$link,$output) = (shift,shift);
       $output = &ext_viewinposts($pusername, "popup");        $output = &ext_viewinposts($pusername, "popup");
       $output =~ s~^$ext_spacer_br\n~~ig;        $output =~ s~^$ext_spacer_br\n~~ig;
       if ($output ne "") {        if ($output ne "") {
           $link =~ s~<a ~<a onmouseover="document.getElementById('ext_$ext_usercount').style.visibility = 'visible'" onmouseout="document.getElementById('ext_$ext_usercount').style.visibility = 'hidden'" ~ig;            $link =~ s~<a ~<a onmouseover="document.getElementById('ext_$ext_usercount').style.visibility = 'visible'" onmouseout="document.getElementById('ext_$ext_usercount').style.visibility = 'hidden'" ~ig;
           $output = qq~$link<div id="ext_$ext_usercount" class="code" style="visibility:hidden; position:absolute; z-index:1; width:auto;">$output</div>~;            $output = qq~$link<div id="ext_$ext_usercount" class="code" style="visibility:hidden; position:absolute; z-index:1; width:auto;">$output</div>~;
           $ext_usercount++;            $ext_usercount++;
       } else {        } else {
           $output = $link;            $output = $link;
       }        }
   
       $output;        $output;
   }    }
} }
   
# returns the output for the table header in memberlist # returns the output for the table header in memberlist
sub ext_memberlist_tableheader { sub ext_memberlist_tableheader {
   my ($output, $fieldname);    my ($output, $fieldname);
   
   foreach $fieldname (@ext_prof_order) {    foreach $fieldname (@ext_prof_order) {
       &ext_get_field(&ext_get_field_id($fieldname));        &ext_get_field(&ext_get_field_id($fieldname));
   
       # make sure the field is visible and the user allowed to view the current field        # make sure the field is visible and the user allowed to view the current field
       if ($field{'visible_in_memberlist'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'m_users'},$field{'m_groups'})) {        if ($field{'visible_in_memberlist'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'m_users'},$field{'m_groups'})) {
           $output .= qq~<td class="catbg" align="center">$field{'name'}</td>\n~;            $output .= qq~<td class="catbg" align="center">$field{'name'}</td>\n~;
       }        }
   }    }
   
   $output;    $output;
} }
   
# returns the number of additional fields showed in memberlist # returns the number of additional fields showed in memberlist
sub ext_memberlist_get_headercount { # count the linebreaks to get the number of additional <td>s for the memberlist table sub ext_memberlist_get_headercount { # count the linebreaks to get the number of additional <td>s for the memberlist table
   my ($headers,$headercount) = (shift, 0);    my ($headers,$headercount) = (shift, 0);
   $headers =~ s~(\n)~ $headercount++ ~eg;    $headers =~ s~(\n)~ $headercount++ ~eg;
   $headercount;    $headercount;
} }
   
# returns the output for the table tds in memberlist # returns the output for the table tds in memberlist
sub ext_memberlist_tds { sub ext_memberlist_tds {
   my ($pusername, $usergroup, @ext_profile, $id, $output, $access, @users, $user, @groups, $group, $fieldname, @options, $count, $color, $value) = (shift, ${$uid.$username}{'position'});    my ($pusername, $usergroup, @ext_profile, $id, $output, $access, @users, $user, @groups, $group, $fieldname, @options, $count, $color, $value) = (shift, ${$uid.$username}{'position'});
   
   $count = 0;    $count = 0;
   foreach $fieldname (@ext_prof_order) {    foreach $fieldname (@ext_prof_order) {
       $id = &ext_get_field_id($fieldname);        $id = &ext_get_field_id($fieldname);
       &ext_get_field($id);        &ext_get_field($id);
       $value = &ext_get($pusername,$fieldname);        $value = &ext_get($pusername,$fieldname);
   
       # make sure the field is visible and the user allowed to view the current field        # make sure the field is visible and the user allowed to view the current field
       if ($field{'visible_in_memberlist'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'m_users'},$field{'m_groups'})) {        if ($field{'visible_in_memberlist'} == 1 && $field{'active'} == 1 && &ext_has_access($field{'m_users'},$field{'m_groups'})) {
           $color = $count % 2 == 1 ? "windowbg" : "windowbg2";            $color = $count % 2 == 1 ? "windowbg" : "windowbg2";
           #if ($using_yams5 eq "1") {            #if ($using_yams5 eq "1") {
           #   $td_attributs = qq~class="windowbg2" style="border-top: #6394BD 1px solid; border-right: #6394BD 1px solid; padding: 2px" bgcolor="#F8F8F8" align="center" valign="middle"~;            #   $td_attributs = qq~class="windowbg2" style="border-top: #6394BD 1px solid; border-right: #6394BD 1px solid; padding: 2px" bgcolor="#F8F8F8" align="center" valign="middle"~;
           #} else {            #} else {
               $td_attributs = qq~class="$color"~;                $td_attributs = qq~class="$color"~;
           #}            #}
           if ($field{'type'} eq "email") {            if ($field{'type'} eq "email") {
               if ($value ne "") { $value = &enc_eMail($img_txt{'69'},$value,'',''); }                if ($value ne "") { $value = &enc_eMail($img_txt{'69'},$value,'',''); }
           } elsif ($field{'type'} eq "url") {            } elsif ($field{'type'} eq "url") {
               if ($value ne "") { $value = qq~<a href="$value" target="_blank">$value</a>~; }                if ($value ne "") { $value = qq~<a href="$value" target="_blank">$value</a>~; }
           }            }
           if ($value eq "") { $value .= "&nbsp;"; }            if ($value eq "") { $value .= "&nbsp;"; }
           $output .= qq~<td $td_attributs>$value</td>\n~;            $output .= qq~<td $td_attributs>$value</td>\n~;
           $count++;            $count++;
       }        }
   }    }
   
   $output;    $output;
} }
   
# returns the edit mask of a field (used on registration and edit profile page) # returns the edit mask of a field (used on registration and edit profile page)
sub ext_gen_editfield { sub ext_gen_editfield {
   my ($id, $pusername, @ext_profile, $output, @options, $selected, $count, $required_prefix, $dayormonth, $dayormonthd, $dayormonthm, $value, $template1, $template2) = (shift, shift);    my ($id, $pusername, @ext_profile, $output, @options, $selected, $count, $required_prefix, $dayormonth, $dayormonthd, $dayormonthm, $value, $template1, $template2) = (shift, shift);
   
   &LoadLanguage("Profile");    &LoadLanguage("Profile");
   
   &ext_get_field($id);    &ext_get_field($id);
   
   # if username is obmitted, we'll generate the code for the registration page    # if username is omitted, we'll generate the code for the registration page
   if ($pusername ne "") { $value = &ext_get($pusername,$field{'name'},1); }    if ($pusername ne "") { $value = &ext_get($pusername,$field{'name'},1); }
   
   &FromHTML($field{'comment'});    &FromHTML($field{'comment'});
   
   $template1 = qq~<tr class="windowbg"><td align="left" valign="top"><label for=""><b>$field{'name'}: </b><br /><span class="small">$field{'comment'}</span></label></td><td align="left">~;    $template1 = qq~<tr class="windowbg"><td align="left" valign="top"><label for=""><b>$field{'name'}: </b><br /><span class="small">$field{'comment'}</span></label></td><td align="left">~;
   if ($field{'required_on_reg'} == 1) { $template2 = " *"; }    if ($field{'required_on_reg'} == 1) { $template2 = " * "; }
   $template2 .= qq~</td></tr>\n~;    $template2 .= qq~</td></tr>\n~;
   
   # format the output dependend on field type    # format the output dependend on field type
   my $name_id = "ext_$id";    my $name_id = "ext_$id";
   if ($field{'type'} eq "text") {    if ($field{'type'} eq "text") {
       @options = split(/\^/,$field{'options'});        @options = split(/\^/,$field{'options'});
       if ($options[0] ne "") { $options[0] = qq~ maxlength="$options[0]"~; }        if ($options[0] ne "") { $options[0] = qq~ maxlength="$options[0]"~; }
       if ($options[1] ne "") { $options[1] = qq~ size="$options[1]"~; }        if ($options[1] ne "") { $options[1] = qq~ size="$options[1]"~; }
       if ($options[3] ne "" && $value eq "") { $options[3] = qq~ value="$options[3]"~; } else { $options[3] = qq~ value="$value"~; }        if ($options[3] ne "" && $value eq "") { $options[3] = qq~ value="$options[3]"~; } else { $options[3] = qq~ value="$value"~; }
       $output .= $template1 . qq~<input type="text"$options[0] name="ext_$id" id="ext_$id"$options[1] $options[3] />~ . $template2;        $output .= $template1 . qq~<input type="text"$options[0] name="ext_$id" id="ext_$id"$options[1] $options[3] />~ . $template2;
   
   } elsif ($field{'type'} eq "text_multi") {    } elsif ($field{'type'} eq "text_multi") {
       @options = split(/\^/,$field{'options'});        @options = split(/\^/,$field{'options'});
       if ($options[0]) {        if ($options[0]) {
           $field{'options'} = qq~            $field{'options'} = qq~
   <br /><span class="small">$lang_ext{'max_chars1'}$options[0]$lang_ext{'max_chars2'} <input value="$options[0]" size="~ . length($options[0]) . qq~" name="ext_$id\_msgCL" id="ext_$id\_msgCL" class="windowbg" style="border: 0px; padding: 1px; font-size: 11px;" readonly="readonly" /></span>    <br /><span class="small">$lang_ext{'max_chars1'}$options[0]$lang_ext{'max_chars2'} <input value="$options[0]" size="~ . length($options[0]) . qq~" name="ext_$id\_msgCL" id="ext_$id\_msgCL" class="windowbg" style="border: 0px; padding: 1px; font-size: 11px;" readonly="readonly" /></span>
   <script language="JavaScript" type="text/javascript">    <script language="JavaScript" type="text/javascript">
   <!--    <!--
   var ext_$id\_supportsKeys = false;    var ext_$id\_supportsKeys = false;
   function ext_$id\_tick() {    function ext_$id\_tick() {
       ext_$id\_calcCharLeft(document.forms[0]);        ext_$id\_calcCharLeft(document.forms[0]);
       if (!ext_$id\_supportsKeys) timerID = setTimeout("ext_$id\_tick()",$options[0]);        if (!ext_$id\_supportsKeys) timerID = setTimeout("ext_$id\_tick()",$options[0]);
   }    }
   
   function ext_$id\_calcCharLeft(sig) {    function ext_$id\_calcCharLeft(sig) {
       clipped = false;        clipped = false;
       maxLength = $options[0];        maxLength = $options[0];
       if (document.creator.ext_$id.value.length > maxLength) {        if (document.creator.ext_$id.value.length > maxLength) {
           document.creator.ext_$id.value = document.creator.ext_$id.value.substring(0,maxLength);            document.creator.ext_$id.value = document.creator.ext_$id.value.substring(0,maxLength);
           charleft = 0;            charleft = 0;
           clipped = true;            clipped = true;
       } else {        } else {
           charleft = maxLength - document.creator.ext_$id.value.length;            charleft = maxLength - document.creator.ext_$id.value.length;
       }        }
       document.creator.ext_$id\_msgCL.value = charleft;        document.creator.ext_$id\_msgCL.value = charleft;
       return clipped;        return clipped;
   }    }
   
   ext_$id\_tick();    ext_$id\_tick();
   //-->    //-->
   </script>~;    </script>~;
       } else { $field{'options'} = ""; }        } else { $field{'options'} = ""; }
       if ($options[1] ne "") { $options[1] = qq~ rows="$options[1]"~; } else { $options[1] = qq~ rows="4"~; }        if ($options[1] ne "") { $options[1] = qq~ rows="$options[1]"~; } else { $options[1] = qq~ rows="4"~; }
       if ($options[2] ne "") { $options[2] = qq~ cols="$options[2]"~; } else { $options[2] = qq~ cols="50"~; }        if ($options[2] ne "") { $options[2] = qq~ cols="$options[2]"~; } else { $options[2] = qq~ cols="50"~; }
       $value =~ s/<br(?: ?\/)?>/\n/g;        $value =~ s/<br(?: ?\/)?>/\n/g;
       $output .= $template1 . qq~<textarea name="ext_$id" id="ext_$id"$options[1]$options[2]>$value</textarea>$field{'options'}~ . $template2;        $output .= $template1 . qq~<textarea name="ext_$id" id="ext_$id"$options[1]$options[2]>$value</textarea>$field{'options'}~ . $template2;
   
   } elsif ($field{'type'} eq "select") {    } elsif ($field{'type'} eq "select") {
       $output .= $template1 . qq~<select name="ext_$id" id="ext_$id" size="1">\n~;        $output .= $template1 . qq~<select name="ext_$id" id="ext_$id" size="1">\n~;
       @options = split(/\^/,$field{'options'});        @options = split(/\^/,$field{'options'});
       if ($value > $#options || $value eq "") { $ext_profile[$id] = 0; }        if ($value > $#options || $value eq "") { $ext_profile[$id] = 0; }
       $count = 0;        $count = 0;
       foreach (@options) {        foreach (@options) {
           if ($count == $value) { $selected = " selected=\"selected\""; } else { $selected = ""; }            if ($count == $value) { $selected = " selected=\"selected\""; } else { $selected = ""; }
           $output .= qq~<option value="$count"$selected>$_</option>\n~;            $output .= qq~<option value="$count"$selected>$_</option>\n~;
           $count++;            $count++;
       }        }
       $output .= qq~</select>~ . $template2;        $output .= qq~</select>~ . $template2;
   
   } elsif ($field{'type'} eq "radiobuttons") {    } elsif ($field{'type'} eq "radiobuttons") {
       $output .= $template1;        $output .= $template1;
       @options = split(/\^/,$field{'options'});        @options = split(/\^/,$field{'options'});
       if ($value > $#options) { $value = 0; }        if ($value > $#options) { $value = 0; }
       if(!$field{'radiounselect'} && $value eq "") { $value = 0; }        if(!$field{'radiounselect'} && $value eq "") { $value = 0; }
       $count = 0;        $count = 0;
       foreach (@options) {        foreach (@options) {
           if ($value ne "" && $count == $value) { $selected = qq~ id="ext_$id" checked="checked"~; } else { $selected = ""; }            if ($value ne "" && $count == $value) { $selected = qq~ id="ext_$id" checked="checked"~; } else { $selected = ""; }
           $output .= qq~<input type="radio" name="ext_$id" value="$count"$selected />$_\n~;            $output .= qq~<input type="radio" name="ext_$id" value="$count"$selected />$_\n~;
           $count++;            $count++;
       }        }
       $output .= $template2;        $output .= $template2;
   
   } elsif ($field{'type'} eq "date") {    } elsif ($field{'type'} eq "date") {
       if ($value !~ /[0-9\/]/) { $value = ""; }        if ($value !~ /[0-9\/]/) { $value = ""; }
       @options = split(/\//,$value);        @options = split(/\//,$value);
       $dayormonthm = qq~ $profile_txt{'564'} <input type="text" name="ext_$id\_month" id="ext_$id\_month" size="2" maxlength="2" value="$options[0]" />~;        $dayormonthm = qq~ $profile_txt{'564'} <input type="text" name="ext_$id\_month" id="ext_$id\_month" size="2" maxlength="2" value="$options[0]" />~;
       $dayormonthd = qq~ $profile_txt{'565'} <input type="text" name="ext_$id\_day" id="ext_$id\_day" size="2" maxlength="2" value="$options[1]" />~;        $dayormonthd = qq~ $profile_txt{'565'} <input type="text" name="ext_$id\_day" id="ext_$id\_day" size="2" maxlength="2" value="$options[1]" />~;
       if ((${$uid.$pusername}{'timeselect'} == 2 || ${$uid.$pusername}{'timeselect'} == 3 || ${$uid.$pusername}{'timeselect'} == 6) || ($timeselected == 2 || $timeselected == 3 || $timeselected == 6)) {        if ((${$uid.$pusername}{'timeselect'} == 2 || ${$uid.$pusername}{'timeselect'} == 3 || ${$uid.$pusername}{'timeselect'} == 6) || ($timeselected == 2 || $timeselected == 3 || $timeselected == 6)) {
           $dayormonth=$dayormonthd.$dayormonthm;            $dayormonth=$dayormonthd.$dayormonthm;
           $name_id = "ext_$id\_day";            $name_id = "ext_$id\_day";
       } else {        } else {
           $dayormonth=$dayormonthm.$dayormonthd;            $dayormonth=$dayormonthm.$dayormonthd;
           $name_id = "ext_$id\_month";            $name_id = "ext_$id\_month";
       }        }
       $output .= $template1 . qq~<span class="small">$dayormonth $profile_txt{'566'} <input type="text" name="ext_$id\_year" size="4" maxlength="4" value="$options[2]" /></span>~ . $template2;        $output .= $template1 . qq~<span class="small">$dayormonth $profile_txt{'566'} <input type="text" name="ext_$id\_year" size="4" maxlength="4" value="$options[2]" /></span>~ . $template2;
   
   } elsif ($field{'type'} eq "checkbox") {    } elsif ($field{'type'} eq "checkbox") {
       if ($value == 1) { $value = " checked=\"checked\""; } else { $value = ""; }        if ($value == 1) { $value = " checked=\"checked\""; } else { $value = ""; }
       # we have to use a little trick here to get a value from a checkbox if it has been unchecked by adding a hidden <input value=""> before it        # we have to use a little trick here to get a value from a checkbox if it has been unchecked by adding a hidden <input value=""> before it
       $output .= $template1 . qq~<input type="hidden" name="ext_$id" value="" /><input type="checkbox" name="ext_$id" id="ext_$id"$value />~ . $template2;        $output .= $template1 . qq~<input type="hidden" name="ext_$id" value="" /><input type="checkbox" name="ext_$id" id="ext_$id"$value />~ . $template2;
   
   } elsif ($field{'type'} eq "spacer") {    } elsif ($field{'type'} eq "spacer") {
       @options = split(/\^/,$field{'options'});        @options = split(/\^/,$field{'options'});
       if ($options[1] == 1) {        if ($options[1] == 1) {
           #if ($options[0] == 1) { $output .= qq~<tr class="catbg"><td colspan=2><br /></td></tr>\n~; }            #if ($options[0] == 1) { $output .= qq~<tr class="catbg"><td colspan=2><br /></td></tr>\n~; }
           #else { $output .= qq~<tr class="catbg"><td colspan=2><hr width="100%" size="1" class="hr"></td></tr>\n~; }            #else { $output .= qq~<tr class="catbg"><td colspan=2><hr width="100%" size="1" class="hr"></td></tr>\n~; }
           $output .= qq~<tr><td class="catbg" colspan="2">$field{'comment'}&nbsp;</td></tr>\n~;            $output .= qq~<tr><td class="catbg" colspan="2">$field{'comment'}&nbsp;</td></tr>\n~;
       }        }
   
   } elsif ($field{'type'} eq "email") {    } elsif ($field{'type'} eq "email") {
       $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_email_length" size="30" value="$value" />~ . $template2;        $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_email_length" size="30" value="$value" />~ . $template2;
   
   } elsif ($field{'type'} eq "url") {    } elsif ($field{'type'} eq "url") {
       $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_url_length" size="50" value="$value" />~ . $template2;        $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_url_length" size="50" value="$value" />~ . $template2;
   
   } elsif ($field{'type'} eq "image") {    } elsif ($field{'type'} eq "image") {
       if ($value eq "") { $value = "http://"; }        if ($value eq "") { $value = "http://"; }
       $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_image_length" size="50" value="$value" />~ . $template2;        $output .= $template1 . qq~<input type="text" name="ext_$id" id="ext_$id" maxlength="$ext_max_image_length" size="50" value="$value" />~ . $template2;
   }    }
   $output =~ s/<label for="">/<label for="$name_id">/g;    $output =~ s/<label for="">/<label for="$name_id">/g;
   
   $output;    $output;
} }
   
# returns the output for the edit profile page # returns the output for the edit profile page
## USAGE: $value = ext_editprofile("admin","required"); ## USAGE: $value = ext_editprofile("admin","required");
sub ext_editprofile { sub ext_editprofile {
   my ($pusername, $part, $usergroup, $id, $output, $fieldname, @options, $selected, $count) = (shift, shift, ${$uid.$username}{'position'});    my ($pusername, $part, $usergroup, $id, $output, $fieldname, @options, $selected, $count) = (shift, shift, ${$uid.$username}{'position'});
   
   if (-e ("$vardir/gmodsettings.txt")) { require "$vardir/gmodsettings.txt"; }    if (-e ("$vardir/gmodsettings.txt")) { require "$vardir/gmodsettings.txt"; }
   
   foreach $fieldname (@ext_prof_order) {    foreach $fieldname (@ext_prof_order) {
       $id = &ext_get_field_id($fieldname);        $id = &ext_get_field_id($fieldname);
       &ext_get_field($id);        &ext_get_field($id);
   
       # make sure the field is visible, the user allowed to edit the current field and only the requested fields are returned        # make sure the field is visible, the user allowed to edit the current field and only the requested fields are returned
       if ($field{'active'} == 1 &&        if ($field{'active'} == 1 &&
           ($field{'editable_by_user'} != 0 || $iamadmin || $iamgmod && $allow_gmod_profile) &&            ($field{'editable_by_user'} != 0 || $iamadmin || $iamgmod && $allow_gmod_profile) &&
           (($part eq "required"   && $field{'required_on_reg'}  == 1) ||  # show all required fields            (($part eq "required"   && $field{'required_on_reg'}  == 1) ||  # show all required fields
            ($part eq "additional" && $field{'required_on_reg'}  != 1) ||  # show all additional fields             ($part eq "additional" && $field{'required_on_reg'}  != 1) ||  # show all additional fields
            ($part eq "admin"      && $field{'editable_by_user'} == 0) ||  # all fields for "admin edits" page             ($part eq "admin"      && $field{'editable_by_user'} == 0) ||  # all fields for "admin edits" page
            ($part eq "edit"       && $field{'editable_by_user'} == 1) ||  # all fields for "edit profile" page             ($part eq "edit"       && $field{'editable_by_user'} == 1) ||  # all fields for "edit profile" page
            ($part eq "contact"    && $field{'editable_by_user'} == 2) ||  # contact information page             ($part eq "contact"    && $field{'editable_by_user'} == 2) ||  # contact information page
            ($part eq "options"    && $field{'editable_by_user'} == 3) ||  # options page             ($part eq "options"    && $field{'editable_by_user'} == 3) ||  # options page
            ($part eq "im"         && $field{'editable_by_user'} == 4))) { # im prefs page             ($part eq "im"         && $field{'editable_by_user'} == 4))) { # im prefs page
           $output .= &ext_gen_editfield($id, $pusername);            $output .= &ext_gen_editfield($id, $pusername);
       }        }
   }    }
   
   $output;    $output;
} }
   
# returns the output for the registration page # returns the output for the registration page
sub ext_register { sub ext_register {
   my ($id, $output, $fieldname, @options, @selected);    my ($id, $output, $fieldname, @options, @selected);
   
   foreach $fieldname (@ext_prof_order) {    foreach $fieldname (@ext_prof_order) {
       $id = &ext_get_field_id($fieldname);        $id = &ext_get_field_id($fieldname);
       &ext_get_field($id);        &ext_get_field($id);
       if ($field{'active'} == 1 && $field{'required_on_reg'} != 0) {        if ($field{'active'} == 1 && $field{'required_on_reg'} != 0) {
           $output .= &ext_gen_editfield($id);            $output .= &ext_gen_editfield($id);
       }        }
   }    }
   
   $output;    $output;
} }
   
# returns if the submitted profile is valid, if not, return error messages # returns if the submitted profile is valid, if not, return error messages
sub ext_validate_submition { sub ext_validate_submition {
   my ($username, $pusername, $usergroup, %newprofile, @oldprofile, $output, $key, $value, $id, @options) = (shift, shift, ${$uid.$username}{'position'}, %FORM);    my ($username, $pusername, $usergroup, %newprofile, @oldprofile, $output, $key, $value, $id, @options) = (shift, shift, ${$uid.$username}{'position'}, %FORM);
   
   if (-e "$vardir/gmodsettings.txt") { require "$vardir/gmodsettings.txt"; }    if (-e "$vardir/gmodsettings.txt") { require "$vardir/gmodsettings.txt"; }
   
   while (($key,$value) = each(%newprofile)) {    while (($key,$value) = each(%newprofile)) {
       # only validate fields with prefix "ext_"        # only validate fields with prefix "ext_"
       if ($key =~ /^ext_(\d+)$/) {        if ($key =~ /^ext_(\d+)/) {
           $id = $1;            $id = $1;
           &ext_get_field($id);            &ext_get_field($id);
   
           if (!$field{'name'}) { $output .= $lang_ext{'field_not_existing1'}.$id.$lang_ext{'field_not_existing2'}."<br />\n"; }            if (!$field{'name'}) { $output .= $lang_ext{'field_not_existing1'}.$id.$lang_ext{'field_not_existing2'}."<br />\n"; }
   
           # check if user is allowed to modify this setting            # check if user is allowed to modify this setting
           if ($action eq "register2") {            if ($action eq "register2") {
               # if we're on registration page, igonre the 'editable_by_user' setting in case that 'required_on_reg' is set                # if we're on registration page, ignore the 'editable_by_user' setting in case that 'required_on_reg' is set
               if ($field{'editable_by_user'} == 0 && $field{'required_on_reg'} == 0) {                if ($field{'editable_by_user'} == 0 && $field{'required_on_reg'} == 0) {
                   $output .= $field{'name'}.": ".$lang_ext{'not_allowed_to_modify'}."<br />\n";                    $output .= $field{'name'}.": ".$lang_ext{'not_allowed_to_modify'}."<br />\n";
               }                }
           } elsif (($field{'editable_by_user'} == 0 || $username ne $pusername) && !$iamadmin && (!$iamgmod || !$allow_gmod_profile)) {            } elsif (($field{'editable_by_user'} == 0 || $username ne $pusername) && !$iamadmin && (!$iamgmod || !$allow_gmod_profile)) {
                   $output .= $field{'name'}.": ".$lang_ext{'not_allowed_to_modify'}."<br />\n";                    $output .= $field{'name'}.": ".$lang_ext{'not_allowed_to_modify'}."<br />\n";
           }            }
   
           # check if setting is valid            # check if setting is valid
           if ($field{'type'} ne "text_multi" && $value =~ /[\n\r]/) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }            if ($field{'type'} ne "text_multi" && $value =~ /[\n\r]/) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }
   
           if ($field{'type'} eq "text") {            if ($field{'type'} eq "text") {
               @options = split(/\^/,$field{'options'});                @options = split(/\^/,$field{'options'});
               # don't fill it with default value yet, it might be required on registration                # don't fill it with default value yet, it might be required on registration
               # if ($options[3] ne "" && $value eq "") { $value = $options[3]; $newprofile{'ext_'.$id} = $value; }                # if ($options[3] ne "" && $value eq "") { $value = $options[3]; $newprofile{'ext_'.$id} = $value; }
               if ($options[0]+0 > 0 && length($value) > $options[0]) { $output .= $field{'name'}.": ".$lang_ext{'too_long'}."<br />\n"; }                if ($options[0]+0 > 0 && length($value) > $options[0]) { $output .= $field{'name'}.": ".$lang_ext{'too_long'}."<br />\n"; }
               if ($options[2] == 1 && $value !~ /[0-9\.,]+/ && $value ne "") { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }                if ($options[2] == 1 && $value !~ /[0-9\.,]+/ && $value ne "") { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }
               &FromChars($value);                &FromChars($value);
               &ToHTML($value);                &ToHTML($value);
               &ToChars($value);                &ToChars($value);
   
           } elsif ($field{'type'} eq "text_multi") {            } elsif ($field{'type'} eq "text_multi") {
               @options = split(/\^/,$field{'options'});                @options = split(/\^/,$field{'options'});
               if ($options[0]+0 > 0 && length($value) > $options[0]) { $output .= $field{'name'}.": ".$lang_ext{'too_long'}."<br />\n"; }                if ($options[0]+0 > 0 && length($value) > $options[0]) { $output .= $field{'name'}.": ".$lang_ext{'too_long'}."<br />\n"; }
               &FromChars($value);                &FromChars($value);
               &ToHTML($value);                &ToHTML($value);
               &ToChars($value);                &ToChars($value);
               $value =~ s/\n/<br \/>/g;                $value =~ s/\n/<br \/>/g;
               $value =~ s/\r//g;                $value =~ s/\r//g;
   
           } elsif ($field{'type'} eq "select" || $field{'type'} eq "radiobuttons") {            } elsif ($field{'type'} eq "select" || $field{'type'} eq "radiobuttons") {
               @options = split(/\^/,$field{'options'});                @options = split(/\^/,$field{'options'});
               if ($value !~ /[0-9]/) { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }                if ($value !~ /[0-9]/) { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }
               if ($value < 0) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }                if ($value < 0) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }
               if ($value > $#options) { $output .= $field{'name'}.": ".$lang_ext{'option_does_not_exist'}."<br />\n"; }                if ($value > $#options) { $output .= $field{'name'}.": ".$lang_ext{'option_does_not_exist'}."<br />\n"; }
               next;                next;
   
           } elsif ($field{'type'} eq "date" && $value ne "") {            } elsif ($field{'type'} eq "date" && $value ne "") {
               if ($value !~ /[0-9]/) { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }                if ($value !~ /[0-9]/) { $output .= $field{'name'}.": ".$lang_ext{'not_numeric'}."<br />\n"; }
               if ($key eq "ext_".$id."_day") {                if ($key eq "ext_".$id."_day") {
                   if ($value < 1) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }                    if ($value < 1) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }
                   if ($value > 31) { $output .= $field{'name'}.": ".$lang_ext{'too_big'}."<br />\n"; }                    if ($value > 31) { $output .= $field{'name'}.": ".$lang_ext{'too_big'}."<br />\n"; }
                   if (length($value) == 1) { $newprofile{'ext_'.$id.'_day'} = "0".$value; }                    if (length($value) == 1) { $newprofile{'ext_'.$id.'_day'} = "0".$value; }
               }                }
               elsif ($key eq "ext_".$id."_month") {                elsif ($key eq "ext_".$id."_month") {
                   if ($value < 1) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }                    if ($value < 1) { $output .= $field{'name'}.": ".$lang_ext{'too_small'}."<br />\n"; }
                   if ($value > 12) { $output .= $field{'name'}.": ".$lang_ext{'too_big'}."<br />\n"; }                    if ($value > 12) { $output .= $field{'name'}.": ".$lang_ext{'too_big'}."<br />\n"; }
                   if (length($value) == 1) { $newprofile{'ext_'.$id.'_month'} = "0".$value; }                    if (length($value) == 1) { $newprofile{'ext_'.$id.'_month'} = "0".$value; }
               }                }
               elsif ($key eq "ext_".$id."_year") {                elsif ($key eq "ext_".$id."_year") {
                   if (length($value) != 4) { $output .= $field{'name'}.": ".$lang_ext{'invalid_year'}."<br />\n"; }                    if (length($value) != 4) { $output .= $field{'name'}.": ".$lang_ext{'invalid_year'}."<br />\n"; }
               }                }
               $newprofile{'ext_'.$id} = $newprofile{'ext_'.$id.'_month'} ."\/". $newprofile{'ext_'.$id.'_day'} ."\/". $newprofile{'ext_'.$id.'_year'};                $newprofile{'ext_'.$id} = $newprofile{'ext_'.$id.'_month'} ."\/". $newprofile{'ext_'.$id.'_day'} ."\/". $newprofile{'ext_'.$id.'_year'};
               if ($newprofile{'ext_'.$id} !~ /^\d\d\/\d\d\/\d\d\d\d$/) { $newprofile{'ext_'.$id} = ""; }                if ($newprofile{'ext_'.$id} !~ /^\d\d\/\d\d\/\d\d\d\d$/) { $newprofile{'ext_'.$id} = ""; }
               next;                next;
   
           } elsif ($field{'type'} eq "checkbox") {            } elsif ($field{'type'} eq "checkbox") {
               if ($value ne "") { $newprofile{'ext_'.$id} = 1; } else { $newprofile{'ext_'.$id} = 0; }                if ($value ne "") { $newprofile{'ext_'.$id} = 1; } else { $newprofile{'ext_'.$id} = 0; }
               next;                next;
   
           } elsif ($field{'type'} eq "email" && $value ne "") {            } elsif ($field{'type'} eq "email" && $value ne "") {
               $value = substr($value,0,$ext_max_email_length);                $value = substr($value,0,$ext_max_email_length);
               # uses the code from Profile.pl without further checking...                # uses the code from Profile.pl without further checking...
               if ($value !~ /[\w\-\.\+]+\@[\w\-\.\+]+\.(\w{2,4}$)/) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }                if ($value !~ /[\w\-\.\+]+\@[\w\-\.\+]+\.(\w{2,4}$)/) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }
               if (($value =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/) || ($value !~ /^.+@\[?(\w|[-.])+\.[a-zA-Z]{2,4}|[0-9]{1,4}\]?$/)) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }                if (($value =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/) || ($value !~ /^.+@\[?(\w|[-.])+\.[a-zA-Z]{2,4}|[0-9]{1,4}\]?$/)) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }
   
           } elsif ($field{'type'} eq "url" && $value ne "") {            } elsif ($field{'type'} eq "url" && $value ne "") {
               $value = substr($value,0,$ext_max_url_length);                $value = substr($value,0,$ext_max_url_length);
   
           } elsif ($field{'type'} eq "image" && $value ne "" && $value ne "http://") {            } elsif ($field{'type'} eq "image" && $value ne "" && $value ne "http://") {
               $value = substr($value,0,$ext_max_image_length);                $value = substr($value,0,$ext_max_image_length);
               @options = split(/\^/,$field{'options'});                @options = split(/\^/,$field{'options'});
               if ($options[2] ne "") {                if ($options[2] ne "") {
                   @allowed_extensions = split(/ /,$options[2]);                    @allowed_extensions = split(/ /,$options[2]);
                   $match = 0;                    $match = 0;
                   foreach $extension (@allowed_extensions){                    foreach $extension (@allowed_extensions){
                       if (grep /$extension$/i,$value) { $match = 1; last; }                        if (grep /$extension$/i,$value) { $match = 1; last; }
                   }                    }
                   if ($match == 0) { $output .= $field{'name'}.": ".$lang_ext{'invalid_extension'}."<br />\n"; }                    if ($match == 0) { $output .= $field{'name'}.": ".$lang_ext{'invalid_extension'}."<br />\n"; }
               }                }
               # filename check from profile.pl:                # filename check from profile.pl:
               if ($value !~ m^\A[0-9a-zA-Z_\.\#\%\-\:\+\?\$\&\~\.\,\@/]+\Z^) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }                if ($value !~ m^\A[0-9a-zA-Z_\.\#\%\-\:\+\?\$\&\~\.\,\@/]+\Z^) { $output .= $field{'name'}.": ".$lang_ext{'invalid_char'}."<br />\n"; }
           }            }
           $newprofile{'ext_'.$id} = $value;            $newprofile{'ext_'.$id} = $value;
       }        }
   }    }
   
   # check if required fields are filled and add missing fields to $newprofile, just to be on the saver side    # check if required fields are filled and add missing fields to $newprofile, just to be on the safe side
   $id = 0;    $id = 0;
   foreach (@ext_prof_fields) {    foreach (@ext_prof_fields) {
       &ext_get_field($id);        &ext_get_field($id);
       $value = &ext_get($pusername, $field{'name'}, 1);        $value = &ext_get($pusername, $field{'name'}, 1);
       if (defined $newprofile{'ext_'.$id} && ($field{'type'} eq "checkbox" || $field{'type'} eq "radiobuttons")) {        if (defined $newprofile{'ext_'.$id} && ($field{'type'} eq "checkbox" || $field{'type'} eq "radiobuttons")) {
           if ($newprofile{'ext_'.$id} eq "") { $newprofile{'ext_'.$id} = 0; }            if ($newprofile{'ext_'.$id} eq "") { $newprofile{'ext_'.$id} = 0; }
       }        }
       if (defined $newprofile{'ext_'.$id} && $field{'type'} eq "select") {        if (defined $newprofile{'ext_'.$id} && $field{'type'} eq "select") {
           if ($newprofile{'ext_'.$id} eq "") { $newprofile{'ext_'.$id} = 0; }            if ($newprofile{'ext_'.$id} eq "") { $newprofile{'ext_'.$id} = 0; }
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if($options[$newprofile{'ext_'.$id}] eq " ") { $newprofile{'ext_'.$id} = ""; }            if($options[$newprofile{'ext_'.$id}] eq " ") { $newprofile{'ext_'.$id} = ""; }
       }        }
       if (defined $newprofile{'ext_'.$id} && $field{'type'} eq "image") {        if (defined $newprofile{'ext_'.$id} && $field{'type'} eq "image") {
           if ($newprofile{'ext_'.$id} eq "http://") { $newprofile{'ext_'.$id} = ""; }            if ($newprofile{'ext_'.$id} eq "http://") { $newprofile{'ext_'.$id} = ""; }
       }        }
       # load old settings which where invisible/restricted        # load old settings which where invisible/restricted
       if ($action eq "register2") {        if ($action eq "register2") {
           if ($field{'editable_by_user'} == 0 && $field{'required_on_reg'} == 0) {            if ($field{'editable_by_user'} == 0 && $field{'required_on_reg'} == 0) {
               $newprofile{'ext_'.$id} = $value;                $newprofile{'ext_'.$id} = $value;
           }            }
       } else {          }  
         else {  
           if ($field{'editable_by_user'} == 0 && !$iamadmin && (!$iamgmod || !$allow_gmod_profile)) {            if ($field{'editable_by_user'} == 0 && !$iamadmin && (!$iamgmod || !$allow_gmod_profile)) {
               $newprofile{'ext_'.$id} = $value;                $newprofile{'ext_'.$id} = $value;
           }            }
       }        }
       # if setting didn't get submitted or field is disabled, load old value        # if setting didn't get submitted or field is disabled, load old value
       if (!defined $newprofile{'ext_'.$id} || $field{'active'} == 0) { $newprofile{'ext_'.$id} = $value; }        if (!defined $newprofile{'ext_'.$id} && $field{'active'} == 0 && $action eq "register2" ) { $newprofile{'ext_'.$id} = 0; }
       if ($field{'required_on_reg'} == 1 && $newprofile{'ext_'.$id} eq "") { $output .= $field{'name'}.": ".$lang_ext{'required'}."<br />\n"; }        elsif (!defined $newprofile{'ext_'.$id} || $field{'active'} == 0) { $newprofile{'ext_'.$id} = $value; }
   
  #       if (!defined $newprofile{'ext_'.$id} || $field{'active'} == 0) { $newprofile{'ext_'.$id} = $value; } 
         if ($field{'required_on_reg'} == 1 && $newprofile{'ext_'.$id} eq "" && $action eq "register2") { $output .= $field{'name'}.": ".$lang_ext{'required'}."<br />\n"; }  
       # only fill with default value AFTER check of requirement        # only fill with default value AFTER check of requirement
       if ($field{'type'} eq "text" && $newprofile{'ext_'.$id} eq "") {        if ($field{'type'} eq "text" && $newprofile{'ext_'.$id} eq "") {
           @options = split(/\^/,$field{'options'});            @options = split(/\^/,$field{'options'});
           if ($options[3] ne "") { $newprofile{'ext_'.$id} = $options[3] }            if ($options[3] ne "") { $newprofile{'ext_'.$id} = $options[3] }
       } elsif ($field{'type'} eq "spacer") {        } elsif ($field{'type'} eq "spacer") {
           $newprofile{'ext_'.$id} = "";            $newprofile{'ext_'.$id} = "";
       }        }
       elsif ($field{'type'} eq "select" && $newprofile{'ext_'.$id} eq "") {        elsif ($field{'type'} eq "select" && $newprofile{'ext_'.$id} eq "") {
           $newprofile{'ext_'.$id} = 0;            $newprofile{'ext_'.$id} = 0;
       }        }
       $id++;        $id++;
   }    }
   
   # write our now validated profile information back into the usually used variable    # write our now validated profile information back into the usually used variable
   %FORM = %newprofile;    %FORM = %newprofile;
   
   $output;    $output;
} }
   
# stores the submitted profile on disk # stores the submitted profile on disk
sub ext_saveprofile { sub ext_saveprofile {
   my ($pusername, $id, %newprofile, @fields) = (shift, 0, %FORM);    my ($pusername, $id, %newprofile, @fields) = (shift, 0, %FORM);
   
   # note: we expect the new profile to be complete and validated already    # note: we expect the new profile to be complete and validated already
   
   foreach (@ext_prof_fields) {    foreach (@ext_prof_fields) {
       ${$uid.$pusername}{'ext_'.$id} = $newprofile{"ext_".$id};        ${$uid.$pusername}{'ext_'.$id} = $newprofile{"ext_".$id};
       $id++;        $id++;
   }    }
} }
   
# here we define us some ready-to-use html samples to design the input forms for the admin area # here we define us some ready-to-use html samples to design the input forms for the admin area
# this makes it easier to modify the html code afterwards # this makes it easier to modify the html code afterwards
sub ext_admin_htmlreq { sub ext_admin_htmlreq {
   $ext_template_blockstart = qq~    $ext_template_blockstart = qq~
<div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;"> <div class="bordercolor" style="padding: 0px; width: 99%; margin-left: 0px; margin-right: auto;">
 <table cellpadding="4" cellspacing="1" width="100%">  <table cellpadding="4" cellspacing="1" width="100%">
   <tbody>    <tbody>
~; ~;
   $ext_template_headerstart = qq~    $ext_template_headerstart = qq~
   <tr valign="middle"><td class="titlebg" align="left">    <tr valign="middle"><td class="titlebg" align="left">
     <img src="$imagesdir/profile.gif" alt="" border="0" /><b>~;      <img src="$imagesdir/profile.gif" alt="" border="0" /><b>~;
   $ext_template_headerstop = qq~    $ext_template_headerstop = qq~
     </b>      </b>
   </td></tr>~;    </td></tr>~;
   $ext_template_commentstart = qq~    $ext_template_commentstart = qq~
   <tr align="center" valign="middle"><td class="catbg" align="left">    <tr align="center" valign="middle"><td class="catbg" align="left">
     <span class="small">~;      <span class="small">~;
   $ext_template_commentstop = qq~    $ext_template_commentstop = qq~
     </span></td>      </span></td>
   </tr>~;    </tr>~;
   $ext_template_contentstart = qq~    $ext_template_contentstart = qq~
   <tr valign="middle"><td class="windowbg2" align="left">~;    <tr valign="middle"><td class="windowbg2" align="left">~;
   $ext_template_contentstop = qq~    $ext_template_contentstop = qq~
   </td></tr>~;    </td></tr>~;
   $ext_template_blockstop = qq~    $ext_template_blockstop = qq~
 </tbody></table>  </tbody></table>
</div> </div>
~; ~;
   $ext_template_option_part1 = qq~    $ext_template_option_part1 = qq~
     <tr>      <tr>
       <td align="left" valign="top"><b>~;        <td align="left" valign="top"><b>~;
   $ext_template_option_part2 = qq~: </b><br /><span class="small">~;    $ext_template_option_part2 = qq~: </b><br /><span class="small">~;
   $ext_template_option_part3 = qq~</span></td>    $ext_template_option_part3 =