From e75988cd1fd7cff4697b47c0bf3c71a53e6f1ff5 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 13 Nov 2005 18:42:08 +0000 Subject: [PATCH] Colin: adding avatar to collaboration systems and refactoring some user profile stuff. Added photo and avatar fields to user profile. --- docs/upgrades/upgrade_6.7.8-6.8.0.pl | 32 +- lib/WebGUI/Asset/Wobject/Collaboration.pm | 22 ++ lib/WebGUI/Form/CheckList.pm | 20 ++ lib/WebGUI/Form/Checkbox.pm | 7 + lib/WebGUI/Form/Codearea.pm | 27 ++ lib/WebGUI/Form/Combo.pm | 27 ++ lib/WebGUI/Form/Control.pm | 147 ++++++-- lib/WebGUI/Form/Date.pm | 22 +- lib/WebGUI/Form/DateTime.pm | 9 +- lib/WebGUI/Form/Email.pm | 27 ++ lib/WebGUI/Form/File.pm | 102 ++++-- lib/WebGUI/Form/Float.pm | 9 +- lib/WebGUI/Form/Group.pm | 9 +- lib/WebGUI/Form/HTMLArea.pm | 9 +- lib/WebGUI/Form/Hidden.pm | 27 ++ lib/WebGUI/Form/HiddenList.pm | 9 +- lib/WebGUI/Form/Image.pm | 120 +++++++ lib/WebGUI/Form/Integer.pm | 9 +- lib/WebGUI/Form/Interval.pm | 9 +- lib/WebGUI/Form/Password.pm | 9 +- lib/WebGUI/Form/Phone.pm | 27 ++ lib/WebGUI/Form/Radio.pm | 9 +- lib/WebGUI/Form/RadioList.pm | 22 +- lib/WebGUI/Form/ReadOnly.pm | 27 ++ lib/WebGUI/Form/SelectList.pm | 22 +- lib/WebGUI/Form/Text.pm | 9 +- lib/WebGUI/Form/Textarea.pm | 9 +- lib/WebGUI/Form/TimeField.pm | 9 +- lib/WebGUI/Form/Url.pm | 9 +- lib/WebGUI/Form/YesNo.pm | 9 +- lib/WebGUI/Form/Zipcode.pm | 9 +- lib/WebGUI/Help/Asset_Collaboration.pm | 5 + lib/WebGUI/Operation/Profile.pm | 340 +++++++++--------- lib/WebGUI/Operation/ProfileSettings.pm | 21 +- lib/WebGUI/Operation/User.pm | 70 ++-- .../i18n/English/Asset_Collaboration.pm | 9 + lib/WebGUI/i18n/English/WebGUI.pm | 21 ++ 37 files changed, 1000 insertions(+), 279 deletions(-) create mode 100644 lib/WebGUI/Form/Image.pm diff --git a/docs/upgrades/upgrade_6.7.8-6.8.0.pl b/docs/upgrades/upgrade_6.7.8-6.8.0.pl index caa802ed9..dbb850e04 100644 --- a/docs/upgrades/upgrade_6.7.8-6.8.0.pl +++ b/docs/upgrades/upgrade_6.7.8-6.8.0.pl @@ -27,11 +27,15 @@ addTimeZonesToUserPreferences(); # up to 2^32 as SCALARs. :( removeUnneededFiles(); updateCollaboration(); +addPhotoField(); +addAvatarField(); +addEnableAvatarColumn(); finish(); #------------------------------------------------- sub updateCollaboration { print "\tAdding collaboration/rss template\n" unless ($quiet); +WebGUI::SQL->write("ALTER TABLE Collaboration ADD COLUMN rssTemplateId varchar(22) binary NOT NULL default 'PBtmpl0000000000000142' after notificationTemplateId"); my $template = < @@ -97,6 +101,33 @@ sub removeUnneededFiles { unlink("../../www/index.pl"); } +#------------------------------------------------- +sub addPhotoField { + ##Get profileCategoryId. + my ($categoryId) = WebGUI::SQL->quickArray(q!select profileCategoryId from userProfileCategory where categoryName='WebGUI::International::get(439,"WebGUI");'!); + ##Get last sequence number + my ($lastField) = WebGUI::SQL->buildArray(qq!select max(sequenceNumber) from userProfileField where profileCategoryId=$categoryId!); + ++ $lastField; + ##Insert Photo Field + WebGUI::SQL->write(sprintf q!insert into userProfileField values ('photo','WebGUI::International::get("photo","WebGUI");', 1, 0, 'Image', '', '', %d, %d, 1, 1)!, $lastField, $categoryId); +} + +#------------------------------------------------- +sub addAvatarField { + ##Get profileCategoryId. + my ($categoryId) = WebGUI::SQL->buildArray(q!select profileCategoryId from userProfileCategory where categoryName='WebGUI::International::get(449,"WebGUI");';!); + ##Get last sequence number + my ($lastField) = WebGUI::SQL->buildArray(qq!select max(sequenceNumber) from userProfileField where profileCategoryId=$categoryId!); + ++ $lastField; + ##Insert Photo Field + WebGUI::SQL->write( sprintf q!insert into userProfileField values('avatar','WebGUI::International::get("avatar","WebGUI");', 0, 0, 'Image', '', '', %d, %d, 1, 0)!, $lastField, $categoryId ); +} + +#------------------------------------------------- +sub addEnableAvatarColumn { + WebGUI::SQL->write('ALTER TABLE Collaboration ADD COLUMN avatarsEnabled int(11) NOT NULL DEFAULT 0'); +} + #--- DO NOT EDIT BELOW THIS LINE #------------------------------------------------- @@ -108,7 +139,6 @@ sub start { ); WebGUI::Session::open("../..",$configFile); WebGUI::Session::refreshUserInfo(3); - WebGUI::SQL->write("ALTER TABLE Collaboration ADD COLUMN rssTemplateId varchar(22) binary NOT NULL default 'PBtmpl0000000000000142' after notificationTemplateId"); WebGUI::SQL->write("insert into webguiVersion values (".quote($toVersion).",'upgrade',".time().")"); } diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 7d7c76a5b..6464ae5b0 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -82,6 +82,17 @@ sub appendPostListTemplateVars { } else { $url = $post->getUrl."#".$post->getId; } + my $avatarUrl; + if ($self->get('avatarsEnabled')) { + #ownerUserId from post + #Create user object. + my $user = WebGUI::User->new($post->get('ownerUserId')); + #Get avatar field, storage Id. + my $storageId = $user->get("avatar"); + my $avatar = WebGUI::Storage->get($storageId); + #Get url from storage object. + $avatarUrl = $avatar->getUrl; + } push(@{$var->{post_loop}}, { %{$post->get}, "id"=>$post->getId, @@ -105,6 +116,7 @@ sub appendPostListTemplateVars { "isFourth"=>(($i+1)%4==0), "isFifth"=>(($i+1)%5==0), "user.isPoster"=>$post->isPoster, + "avatar.url"=>$post->isPoster, %lastReply }); $i++; @@ -399,6 +411,10 @@ sub definition { fieldType=>"yesNo", defaultValue=>0 }, + avatarsEnabled =>{ + fieldType=>"yesNo", + defaultValue=>0 + }, moderateGroupId =>{ fieldType=>"group", defaultValue=>'4' @@ -616,6 +632,12 @@ sub getEditForm { -hoverHelp=>WebGUI::International::get('use preview description', 'Asset_Collaboration'), -value=>$self->getValue("usePreview") ); + $tabform->getTab("properties")->yesNo( + -name=>"avatarsEnabled", + -label=>WebGUI::International::get('enable avatars', 'Asset_Collaboration'), + -hoverHelp=>WebGUI::International::get('enable avatars description', 'Asset_Collaboration'), + -value=>$self->getValue("avatarsEnabled") + ); $tabform->getTab("security")->yesNo( -name=>"moderatePosts", -label=>WebGUI::International::get('moderate', 'Asset_Collaboration'), diff --git a/lib/WebGUI/Form/CheckList.pm b/lib/WebGUI/Form/CheckList.pm index 200fec142..8c63e03c9 100644 --- a/lib/WebGUI/Form/CheckList.pm +++ b/lib/WebGUI/Form/CheckList.pm @@ -61,6 +61,10 @@ An array reference of the items to be checked if no value is specified. Defaults Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -75,12 +79,28 @@ sub definition { }, vertical=>{ defaultValue=>0 + }, + profileEnabled=>{ + defaultValue=>1 } }); return $class->SUPER::definition($definition); } +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +Return the all options + +=cut + +sub displayValue { + my ($self) = @_; + return join ", ", @{ $self->{value} }; +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/Checkbox.pm b/lib/WebGUI/Form/Checkbox.pm index 32b49dbc1..8967fa908 100644 --- a/lib/WebGUI/Form/Checkbox.pm +++ b/lib/WebGUI/Form/Checkbox.pm @@ -55,6 +55,10 @@ Defaults to "0". Set to "1" if this field should be checked. The value returned by this field if it is checked and no value is specified. Defaults to "1". +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -65,6 +69,9 @@ sub definition { defaultValue=> 0 }, defaultValue=>{ + defaultValue=>1 + }, + profileEnabled=>{ defaultValue=>1 } }); diff --git a/lib/WebGUI/Form/Codearea.pm b/lib/WebGUI/Form/Codearea.pm index 2d76ce14b..0401da725 100644 --- a/lib/WebGUI/Form/Codearea.pm +++ b/lib/WebGUI/Form/Codearea.pm @@ -39,6 +39,33 @@ The following methods are specifically available from this class. Check the supe =cut +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/Combo.pm b/lib/WebGUI/Form/Combo.pm index 2b7d25a6e..5b15b15dd 100644 --- a/lib/WebGUI/Form/Combo.pm +++ b/lib/WebGUI/Form/Combo.pm @@ -39,6 +39,33 @@ The following methods are specifically available from this class. Check the supe =cut +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index 6f84aa84a..8c2428ee8 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -17,6 +17,7 @@ package WebGUI::Form::Control; use strict; use WebGUI::Grouping; use WebGUI::Session; +use WebGUI::Operation::Shared; =head1 NAME @@ -133,6 +134,10 @@ A stylesheet class assigned to each label/field pair. A text string that will pop up when the user hovers over the label when toHtmlWithWrapper() is called. This string should indicate how to use the field and is usually tied into the help system. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -183,13 +188,66 @@ sub definition { }, idPrefix=>{ defaultValue=>undef - } + }, + profileEnabled=>{ + defaultValue=>0 + }, }); return $definition; } #------------------------------------------------------------------- +=head2 displayForm ( ) + +This utility method is used to format values for the Profile system but can +be used in other areas as well. Most form elements will just return toHtml. + +=cut + +sub displayForm { + my ($self) = @_; + $self->toHtml; +} + +#------------------------------------------------------------------- + +=head2 displayFormWithWrapper ( ) + +This utility method is used to format values for the Profile system but can +be used in other areas as well. Most form elements will just return displayForm. + +=cut + +sub displayFormWithWrapper { + my $self = shift; + if ($self->passUiLevelCheck) { + my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper; + return ' + '.$self->{label}.' + '.$self->displayForm().$subtext." + \n"; + } else { + return $self->toHtmlAsHidden; + } +} + +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +This utility method is used to format values for the Profile system. Most +form elements will just return their value. + +=cut + +sub displayValue { + my ($self) = @_; + return $self->{value}; +} + +#------------------------------------------------------------------- + =head2 generateIdParameter ( name ) A class method that returns a value to be used as the autogenerated ID for this field instance. Unless overriden, it simply returns the name with "_formId" appended to it. @@ -375,6 +433,40 @@ sub new { $params{id} = $params{idPrefix}.$params{id}; bless \%params, $class; } +#------------------------------------------------------------------- + +=head2 prepareWrapper ( ) + +Common code for preparing wrappers for *WithWrapper + +=cut + +sub prepareWrapper { + my $self = shift; + my $rowClass = $self->{rowClass}; + $rowClass = qq| class="$rowClass" | if($self->{rowClass}); + my $labelClass = $self->{labelClass}; + $labelClass = qq| class="$labelClass" | if($self->{labelClass}); + my $fieldClass = $self->{fieldClass}; + $fieldClass = qq| class="$fieldClass" | if($self->{fieldClass}); + my $hoverHelp = $self->{hoverHelp}; + $hoverHelp =~ s/\r/ /g; + $hoverHelp =~ s/\n/ /g; + $hoverHelp =~ s/&/& amp;/g; + $hoverHelp =~ s/>/& gt;/g; + $hoverHelp =~ s/</& lt;/g; + $hoverHelp =~ s/&/&/g; + $hoverHelp =~ s/>/>/g; + $hoverHelp =~ s/{subtext}; + $subtext = qq| $subtext| if ($subtext); + return ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext); +} + #------------------------------------------------------------------- @@ -412,35 +504,8 @@ Renders the form field to HTML as a table row complete with labels, subtext, hov sub toHtmlWithWrapper { my $self = shift; - my $passUiLevelCheck = 0; - if ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}}) { # use override if it exists - $passUiLevelCheck = ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}} <= $session{user}{uiLevel}); - } else { # use programmed default - $passUiLevelCheck = ($self->{uiLevel} <= $session{user}{uiLevel}); - } - $passUiLevelCheck = WebGUI::Grouping::isInGroup(3) unless ($passUiLevelCheck); # override if in admins group - if ($passUiLevelCheck) { - my $rowClass = $self->{rowClass}; - $rowClass = qq| class="$rowClass" | if($self->{rowClass}); - my $labelClass = $self->{labelClass}; - $labelClass = qq| class="$labelClass" | if($self->{labelClass}); - my $fieldClass = $self->{fieldClass}; - $fieldClass = qq| class="$fieldClass" | if($self->{fieldClass}); - my $hoverHelp = $self->{hoverHelp}; - $hoverHelp =~ s/\r/ /g; - $hoverHelp =~ s/\n/ /g; - $hoverHelp =~ s/&/& amp;/g; - $hoverHelp =~ s/>/& gt;/g; - $hoverHelp =~ s/</& lt;/g; - $hoverHelp =~ s/&/&/g; - $hoverHelp =~ s/>/>/g; - $hoverHelp =~ s/{subtext}; - $subtext = qq| $subtext| if ($subtext); + if ($self->passUiLevelCheck) { + my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper; return ' '.$self->{label}.' '.$self->toHtml().$subtext." @@ -450,5 +515,27 @@ sub toHtmlWithWrapper { } } +#------------------------------------------------------------------- + +=head2 passUiLevelCheck ( ) + +Renders the form field to HTML as a table row complete with labels, subtext, hoverhelp, etc. + +=cut + +sub passUiLevelCheck { + my $self = shift; + my $passUiLevelCheck = 0; + if ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}}) { # use override if it exists + $passUiLevelCheck = ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}} <= $session{user}{uiLevel}); + } else { # use programmed default + $passUiLevelCheck = ($self->{uiLevel} <= $session{user}{uiLevel}); + } + $passUiLevelCheck = WebGUI::Grouping::isInGroup(3) unless ($passUiLevelCheck); # override if in admins group + return $passUiLevelCheck; +} + + + 1; diff --git a/lib/WebGUI/Form/Date.pm b/lib/WebGUI/Form/Date.pm index 7cea0ca46..e31cb3ca8 100644 --- a/lib/WebGUI/Form/Date.pm +++ b/lib/WebGUI/Form/Date.pm @@ -67,6 +67,10 @@ A default date is placed in the value field. Set this to "1" to leave it empty. If no value is specified, this will be used. Defaults to today and now. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -84,13 +88,29 @@ sub definition { }, noDate=>{ defaultValue=>0 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } #------------------------------------------------------------------- +=head2 displayValue ( ) + +Return the date in a human readable format for the Profile system. + +=cut + +sub displayValue { + my ($self) = @_; + return WebGUI::DateTime::epochToHuman($self->{value},"%z"); +} + +#------------------------------------------------------------------- + =head2 getName () Returns the human readable name or type of this form control. diff --git a/lib/WebGUI/Form/DateTime.pm b/lib/WebGUI/Form/DateTime.pm index f14b6a169..f8882975f 100644 --- a/lib/WebGUI/Form/DateTime.pm +++ b/lib/WebGUI/Form/DateTime.pm @@ -58,6 +58,10 @@ Defaults to 19. Determines the maximum number of characters allowed in this fiel Defaults to 19. The displayed size of the box for the date to be typed in. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =head4 defaultValue If no value is specified, this will be used. Defaults to today and now. @@ -76,7 +80,10 @@ sub definition { }, size=>{ defaultValue=> 19 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Email.pm b/lib/WebGUI/Form/Email.pm index c0cc473d9..0a831603a 100644 --- a/lib/WebGUI/Form/Email.pm +++ b/lib/WebGUI/Form/Email.pm @@ -40,6 +40,33 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + +#------------------------------------------------------------------- + =head2 getName () Returns the human readable name or type of this form control. diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index 2a94f385f..0dd15c7e9 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -57,6 +57,10 @@ If no name is specified a default name of "file" will be used. Defaults to 1. Determines how many files the user can upload with this form control. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -68,11 +72,61 @@ sub definition { }, maxAttachments=>{ defaultValue=>1 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } +#------------------------------------------------------------------- + +=head2 displayForm ( ) + +If an image is uploaded, then return the image and a control to +delete it. Otherwise, display a form element to upload a file. + +=cut + +sub displayForm { + my ($self) = @_; + return $self->toHtml unless $self->{value}; + ##There are files inside here, for each one, display the image + ##and another form control for deleting it. + my $location = WebGUI::Storage->get($self->{value}); + my $id = $location->getId; + my $fileForm = ''; + foreach my $file ( @{ $location->getFiles } ) { + $fileForm .= sprintf qq!
!, $location->getUrl($file); + my $action = join '_', '_', $self->{name}, 'delete'; + $fileForm .= WebGUI::International::get(392) + . " "x4 + . WebGUI::Form::YesNo->new({-name=>$action, -value=>0})->toHtml; + } + my $hid = $self->toHtmlAsHidden(); + $fileForm .= $hid; + return $fileForm; +} + +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +This utility method is used to format values for the Profile system. Most +form elements will just return their value. + +=cut + +sub displayValue { + my ($self) = @_; + return '' unless $self->{value}; + my $location = WebGUI::Storage->get($self->{value}); + local $_; + my @files = map { sprintf qq! %s!, $location->getFileIconUrl($_), $_; } @{ $location->getFiles }; + my $fileValue = join "
\n", @files; +return $fileValue; +} #------------------------------------------------------------------- @@ -92,20 +146,37 @@ sub getName { =head2 getValueFromPost ( ) -Returns the storageId for the storage location that the file(s) got uploaded to. Returns undef if no files were uploaded. +Returns the storageId for the storage location that the file(s) got +uploaded to. Returns undef if no files were uploaded. Also handles +deleting the file if it was specified. =cut sub getValueFromPost { my $self = shift; - my $storage = WebGUI::Storage->create; - $storage->addFileFromFormPost($self->{name}); - my @files = @{ $storage->getFiles }; - if (scalar(@files) < 1) { + my $value = $session{req}->param($self->{name}); + if ($session{req}->param(join '_', '_', $self->{name}, 'delete')) { + my $storage = WebGUI::Storage->get($value); $storage->delete; - return undef; - } else { - return $storage->getId; + return ''; + } + else { + my $storage; + if ($value) { + $storage = WebGUI::Storage::Image->get($value); + } + else { + $storage = WebGUI::Storage::Image->create; + } + $storage->addFileFromFormPost($self->{name}); + my @files = @{ $storage->getFiles }; + if (scalar(@files) < 1) { + $storage->delete; + return undef; + } else { + my $id = $storage->getId; + return $id; + } } } @@ -139,18 +210,5 @@ sub toHtml { return $uploadControl; } -#------------------------------------------------------------------- - -=head4 toHtmlAsHidden ( ) - -Returns undef. - -=cut - -sub toHtmlAsHidden { - return undef; -} - - 1; diff --git a/lib/WebGUI/Form/Float.pm b/lib/WebGUI/Form/Float.pm index ecd5f7165..0406386c1 100644 --- a/lib/WebGUI/Form/Float.pm +++ b/lib/WebGUI/Form/Float.pm @@ -60,6 +60,10 @@ Defaults to 0. Used if no value is specified. Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -74,7 +78,10 @@ sub definition { }, size=>{ defaultValue=>11 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Group.pm b/lib/WebGUI/Form/Group.pm index 8844f52db..a53a23b16 100644 --- a/lib/WebGUI/Form/Group.pm +++ b/lib/WebGUI/Form/Group.pm @@ -72,6 +72,10 @@ This will be used if no value is specified. Should be passed as an array referen A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -92,7 +96,10 @@ sub definition { }, excludeGroups=>{ defaultValue=>[] - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/HTMLArea.pm b/lib/WebGUI/Form/HTMLArea.pm index f38359385..7394a1985 100644 --- a/lib/WebGUI/Form/HTMLArea.pm +++ b/lib/WebGUI/Form/HTMLArea.pm @@ -63,6 +63,10 @@ The number of columns (in characters) wide the box should be. Defaults to the se The ID of the WebGUI::Asset::RichEdit object to load. Defaults to the richEditor setting or "PBrichedit000000000001" if that's not set. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -77,7 +81,10 @@ sub definition { }, richEditId=>{ defaultValue=>$session{setting}{richEditor} || "PBrichedit000000000001" - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Hidden.pm b/lib/WebGUI/Form/Hidden.pm index eea7800af..90aeee105 100644 --- a/lib/WebGUI/Form/Hidden.pm +++ b/lib/WebGUI/Form/Hidden.pm @@ -39,6 +39,33 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + +#------------------------------------------------------------------- + =head2 generateIdParameter ( ) A class method that returns a value to be used as the autogenerated ID for this field instance. Returns undef because this field type can have more than one with the same name, therefore autogenerated ID's aren't terribly useful. diff --git a/lib/WebGUI/Form/HiddenList.pm b/lib/WebGUI/Form/HiddenList.pm index 5ad545985..a34302cd6 100644 --- a/lib/WebGUI/Form/HiddenList.pm +++ b/lib/WebGUI/Form/HiddenList.pm @@ -55,6 +55,10 @@ A hash reference containing name value pairs. The name of each pair will be used value and defaultValue are array referneces containing the names from the options list that should be stored. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -66,7 +70,10 @@ sub definition { }, defaultValue=>{ defaultValue=>[] - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Image.pm b/lib/WebGUI/Form/Image.pm new file mode 100644 index 000000000..f9c5060bf --- /dev/null +++ b/lib/WebGUI/Form/Image.pm @@ -0,0 +1,120 @@ +package WebGUI::Form::Image; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2005 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::File'; +use WebGUI::International; +use WebGUI::Session; +use WebGUI::Storage; +use WebGUI::Style; +use WebGUI::Form::YesNo; +use WebGUI::Session; + +=head1 NAME + +Package WebGUI::Form::Image + +=head1 DESCRIPTION + +Creates a text input box form field. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::File, and thereform WebGUI::Form::Image. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclasses for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 name + +If no name is specified a default name of "file" will be used. + +=head4 maxAttachments + +Defaults to 1. Determines how many files the user can upload with this form control. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + name=>{ + defaultValue=>"file" + }, + maxAttachments=>{ + defaultValue=>1 + }, + profileEnabled=>{ + defaultValue=>1 + }, + }); + return $class->SUPER::definition($definition); +} + + +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +This utility method is used to format values for the Profile system. It +displays each image in the storage location that is the value of the +profile field. + +=cut + +sub displayValue { + my ($self) = @_; + return '' unless $self->{value}; + my $location = WebGUI::Storage->get($self->{value}); + local $_; + my @files = map { sprintf qq!!, $location->getUrl($_) } @{ $location->getFiles }; + my $fileValue = join "
\n", @files; + return $fileValue; + } + +#------------------------------------------------------------------- + +=head2 getName () + +Returns the human readable name or type of this form control. + +=cut + +sub getName { + return WebGUI::International::get("image","WebGUI"); +} + +1; + + diff --git a/lib/WebGUI/Form/Integer.pm b/lib/WebGUI/Form/Integer.pm index cfe9d7a5f..41745ba9f 100644 --- a/lib/WebGUI/Form/Integer.pm +++ b/lib/WebGUI/Form/Integer.pm @@ -60,6 +60,10 @@ Defaults to 0. Used if no value is specified. Defaults to 11. The number of characters that will be displayed at once in this field. Usually no need to override the default. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -74,7 +78,10 @@ sub definition { }, size=>{ defaultValue=>11 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Interval.pm b/lib/WebGUI/Form/Interval.pm index 73295724c..55714bb7a 100644 --- a/lib/WebGUI/Form/Interval.pm +++ b/lib/WebGUI/Form/Interval.pm @@ -57,6 +57,10 @@ The following additional parameters have been added via this sub class. A time interval in seconds that is used if value is not specified. Defaults to 1. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -65,7 +69,10 @@ sub definition { push(@{$definition}, { defaultValue=>{ defaultValue=>1, - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Password.pm b/lib/WebGUI/Form/Password.pm index 2fafaf3c3..cc3b126e7 100644 --- a/lib/WebGUI/Form/Password.pm +++ b/lib/WebGUI/Form/Password.pm @@ -55,6 +55,10 @@ Defaults to 35. Determines the maximum number of characters allowed in this fiel Defaults to 30. Specifies how big of a text box to display. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -66,7 +70,10 @@ sub definition { }, size=>{ defaultValue=>30 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Phone.pm b/lib/WebGUI/Form/Phone.pm index 7fd16cc4d..7c1ad8ecb 100644 --- a/lib/WebGUI/Form/Phone.pm +++ b/lib/WebGUI/Form/Phone.pm @@ -40,6 +40,33 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + +#------------------------------------------------------------------- + =head2 getName () Returns the human readable name or type of this form control. diff --git a/lib/WebGUI/Form/Radio.pm b/lib/WebGUI/Form/Radio.pm index 8d128348e..3bf67007d 100644 --- a/lib/WebGUI/Form/Radio.pm +++ b/lib/WebGUI/Form/Radio.pm @@ -51,6 +51,10 @@ The following additional parameters have been added via this sub class. Defaults to "0". Set to "1" if this field should be checked. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -59,7 +63,10 @@ sub definition { push(@{$definition}, { checked=>{ defaultValue=> 0 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/RadioList.pm b/lib/WebGUI/Form/RadioList.pm index 1262bb1c0..41c6974fb 100644 --- a/lib/WebGUI/Form/RadioList.pm +++ b/lib/WebGUI/Form/RadioList.pm @@ -56,6 +56,10 @@ A hash reference containing key values that will be returned with the form post Boolean representing whether the checklist should be represented vertically or horizontally. If set to "1" will be displayed vertically. Defaults to "0". +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -67,12 +71,28 @@ sub definition { }, vertical=>{ defaultValue=>0 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +Return the all options + +=cut + +sub displayValue { + my ($self) = @_; + return join ", ", @{ $self->{value} }; +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/ReadOnly.pm b/lib/WebGUI/Form/ReadOnly.pm index 8876eb951..97c14ad0b 100644 --- a/lib/WebGUI/Form/ReadOnly.pm +++ b/lib/WebGUI/Form/ReadOnly.pm @@ -38,6 +38,33 @@ The following methods are specifically available from this class. Check the supe =cut +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + +=cut + +sub definition { + my $class = shift; + my $definition = shift || []; + push(@{$definition}, { + profileEnabled=>{ + defaultValue=>1 + } + }); + return $class->SUPER::definition($definition); +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/SelectList.pm b/lib/WebGUI/Form/SelectList.pm index ff0289a6c..c75d0fb9e 100644 --- a/lib/WebGUI/Form/SelectList.pm +++ b/lib/WebGUI/Form/SelectList.pm @@ -68,6 +68,10 @@ Boolean indicating whether the user can select multiple items from this list lik A boolean value for whether or not the values in the options hash should be sorted. Defaults to "0". +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -88,12 +92,28 @@ sub definition { }, size=>{ defaultValue=>1 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } +#------------------------------------------------------------------- + +=head2 displayValue ( ) + +Return the all options + +=cut + +sub displayValue { + my ($self) = @_; + return join ", ", @{ $self->{value} }; +} + #------------------------------------------------------------------- =head2 getName () diff --git a/lib/WebGUI/Form/Text.pm b/lib/WebGUI/Form/Text.pm index 5a42198b3..d49964a9c 100644 --- a/lib/WebGUI/Form/Text.pm +++ b/lib/WebGUI/Form/Text.pm @@ -55,6 +55,10 @@ Defaults to 255. Determines the maximum number of characters allowed in this fie Defaults to the setting textBoxSize or 30 if that's not set. Specifies how big of a text box to display. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -66,7 +70,10 @@ sub definition { }, size=>{ defaultValue=>$session{setting}{textBoxSize} || 30 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Textarea.pm b/lib/WebGUI/Form/Textarea.pm index a531e6736..a298dffd4 100644 --- a/lib/WebGUI/Form/Textarea.pm +++ b/lib/WebGUI/Form/Textarea.pm @@ -59,6 +59,10 @@ The number of columns (in characters) wide the box should be. Defaults to the se The style of wrapping this form should use. Defaults to "virtual". Other possible values are "off" and "physical". +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -73,7 +77,10 @@ sub definition { }, wrap=>{ defaultValue=>"virtual" - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/TimeField.pm b/lib/WebGUI/Form/TimeField.pm index a733fc72f..bedbb3eb0 100644 --- a/lib/WebGUI/Form/TimeField.pm +++ b/lib/WebGUI/Form/TimeField.pm @@ -59,6 +59,10 @@ Defaults to 8. Determines the maximum number of characters allowed in this field Default to 8. Determines how many characters wide the field wlll be. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -70,7 +74,10 @@ sub definition { }, size=>{ defaultValue=>8 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Url.pm b/lib/WebGUI/Form/Url.pm index af86c439c..f7772994f 100644 --- a/lib/WebGUI/Form/Url.pm +++ b/lib/WebGUI/Form/Url.pm @@ -52,6 +52,10 @@ The following additional parameters have been added via this sub class. Defaults to 2048. Determines the maximum number of characters allowed in this field. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -60,7 +64,10 @@ sub definition { push(@{$definition}, { maxlength=>{ defaultValue=> 2048 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/YesNo.pm b/lib/WebGUI/Form/YesNo.pm index 1daf227d8..3c1d5a5d5 100644 --- a/lib/WebGUI/Form/YesNo.pm +++ b/lib/WebGUI/Form/YesNo.pm @@ -52,6 +52,10 @@ The following additional parameters have been added via this sub class. Can be a 1 or 0. Defaults to 0 if no value is specified. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -60,7 +64,10 @@ sub definition { push(@{$definition}, { defaultValue=>{ defaultValue=>0 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Form/Zipcode.pm b/lib/WebGUI/Form/Zipcode.pm index 2290eef11..26eb64750 100644 --- a/lib/WebGUI/Form/Zipcode.pm +++ b/lib/WebGUI/Form/Zipcode.pm @@ -52,6 +52,10 @@ The following additional parameters have been added via this sub class. Defaults to 10. Determines the maximum number of characters allowed in this field. +=head4 profileEnabled + +Flag that tells the User Profile system that this is a valid form element in a User Profile + =cut sub definition { @@ -60,7 +64,10 @@ sub definition { push(@{$definition}, { maxlength=>{ defaultValue=> 10 - } + }, + profileEnabled=>{ + defaultValue=>1 + }, }); return $class->SUPER::definition($definition); } diff --git a/lib/WebGUI/Help/Asset_Collaboration.pm b/lib/WebGUI/Help/Asset_Collaboration.pm index 72baa6eb2..51f2fda82 100644 --- a/lib/WebGUI/Help/Asset_Collaboration.pm +++ b/lib/WebGUI/Help/Asset_Collaboration.pm @@ -130,6 +130,11 @@ our $HELP = { description => 'use preview description', namespace => 'Asset_Collaboration', }, + { + title => 'enable avatars', + description => 'enable avatars description', + namespace => 'Asset_Collaboration', + }, { title => 'moderate', description => 'moderate description', diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm index 90306194c..226da36cf 100644 --- a/lib/WebGUI/Operation/Profile.pm +++ b/lib/WebGUI/Operation/Profile.pm @@ -17,6 +17,7 @@ use WebGUI::Operation::Auth; use WebGUI::DateTime; use WebGUI::ErrorHandler; use WebGUI::FormProcessor; +use WebGUI::Form::DynamicField; use WebGUI::Grouping; use WebGUI::HTML; use WebGUI::HTMLForm; @@ -36,47 +37,50 @@ use WebGUI::Operation::Shared; # Builds Extra form requirements for anonymous registration. sub getRequiredProfileFields { my ($f,$a,$method,$label,$default,$values,$data,@array); - + #$f = WebGUI::HTMLForm->new(); - + $a = WebGUI::SQL->read("select * from userProfileField, userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId and - userProfileField.required=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber",WebGUI::SQL->getSlave); - while($data = $a->hashRef) { - my %hash = (); - $method = $data->{dataType}; - $label = WebGUI::Operation::Shared::secureEval($data->{fieldLabel}); - $default = WebGUI::Operation::Shared::secureEval($data->{dataDefault}); - if ($method eq "selectList") { - $values = WebGUI::Operation::Shared::secureEval($data->{dataValues}); - # note: this big if statement doesn't look elegant, but doing regular ORs caused problems with the array reference. - if ($session{form}{$data->{fieldName}}) { - $default = [$session{form}{$data->{fieldName}}]; - } elsif ($session{user}{$data->{fieldName}}) { - $default = [$session{user}{$data->{fieldName}}]; - } - $hash{'profile.formElement'} = WebGUI::Form::selectList({ - "name"=>$data->{fieldName}, - "options"=>$values, - "value"=>$default - }); - } else { - if ($session{form}{$data->{fieldName}}) { - $default = $session{form}{$data->{fieldName}}; - } elsif (exists $session{user}{$data->{fieldName}}) { - $default = $session{user}{$data->{fieldName}}; - } else { - $default = $data->{dataDefault}; - } - - my $cmd = 'WebGUI::Form::'.$method.'({"name"=>$data->{fieldName},"value"=>$default})'; - $hash{'profile.formElement'} = eval($cmd); - - } - $hash{'profile.formElement.label'} = $label; - push(@array,\%hash) - } - $a->finish; - return \@array; + userProfileField.required=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber",WebGUI::SQL->getSlave); + while($data = $a->hashRef) { + my %hash = (); + $method = $data->{dataType}; + $label = WebGUI::Operation::Shared::secureEval($data->{fieldLabel}); + $default = WebGUI::Operation::Shared::secureEval($data->{dataDefault}); + if ($method eq "selectList") { + $values = WebGUI::Operation::Shared::secureEval($data->{dataValues}); + # note: this big if statement doesn't look elegant, but doing regular ORs caused problems with the array reference. + if ($session{form}{$data->{fieldName}}) { + $default = [$session{form}{$data->{fieldName}}]; + } + elsif ($session{user}{$data->{fieldName}}) { + $default = [$session{user}{$data->{fieldName}}]; + } + $hash{'profile.formElement'} = WebGUI::Form::selectList({ + "name"=>$data->{fieldName}, + "options"=>$values, + "value"=>$default + }); + } + else { + if ($session{form}{$data->{fieldName}}) { + $default = $session{form}{$data->{fieldName}}; + } + elsif (exists $session{user}{$data->{fieldName}}) { + $default = $session{user}{$data->{fieldName}}; + } + else { + $default = $data->{dataDefault}; + } + + my $cmd = 'WebGUI::Form::'.$method.'({"name"=>$data->{fieldName},"value"=>$default})'; + $hash{'profile.formElement'} = eval($cmd); + } + $hash{'profile.formElement.label'} = $label; + push(@array,\%hash) + } + $a->finish; + return \@array; } #------------------------------------------------------------------- @@ -109,105 +113,98 @@ sub saveProfileFields { #------------------------------------------------------------------- sub validateProfileData { - my (%data, $error, $a, %field, $warning); - tie %field, 'Tie::CPHash'; - $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId - and userProfileCategory.editable=1 and userProfileField.editable=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); - while (%field = $a->hash) { - my $fieldData = WebGUI::FormProcessor::process($field{fieldName},$field{dataType}, $field{dataDefault}); - WebGUI::Macro::negate(\$fieldData); - $data{$field{fieldName}} = $fieldData; - - if ($field{required} && $data{$field{fieldName}} eq "") { - $error .= '
  • '.(WebGUI::Operation::Shared::secureEval($field{fieldLabel})).' '.WebGUI::International::get(451).'
  • '; - }elsif($field{fieldName} eq "email" && isDuplicateEmail($data{$field{fieldName}})){ - $warning .= '
  • '.WebGUI::International::get(1072).'
  • '; - } - } - $a->finish; - return (\%data, $error, $warning); + my (%data, $error, $a, %field, $warning); + tie %field, 'Tie::CPHash'; + $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId + and userProfileCategory.editable=1 and userProfileField.editable=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); + while (%field = $a->hash) { + $data{$field{fieldName}} = WebGUI::Macro::negate(WebGUI::FormProcessor::process($field{fieldName},$field{dataType}, $field{dataDefault})); + if ($field{required} && $data{$field{fieldName}} eq "") { + $error .= '
  • '.(WebGUI::Operation::Shared::secureEval($field{fieldLabel})).' '.WebGUI::International::get(451).'
  • '; + } + elsif($field{fieldName} eq "email" && isDuplicateEmail($data{$field{fieldName}})){ + $warning .= '
  • '.WebGUI::International::get(1072).'
  • '; + } + } + $a->finish; + return (\%data, $error, $warning); } #------------------------------------------------------------------- sub www_editProfile { - my ($a, $data, $method, $values, $category, $label, $default, $previousCategory, $subtext, $vars, @profile, @array); - return WebGUI::Operation::Auth::www_auth("init") if($session{user}{userId} eq '1'); - - $vars->{displayTitle} .= '

    '.WebGUI::International::get(338).'

    '; - - $vars->{'profile.message'} = $_[0] if($_[0]); - $vars->{'profile.form.header'} = "\n\n".WebGUI::Form::formHeader({}); - $vars->{'profile.form.footer'} = WebGUI::Form::formFooter(); - - $vars->{'profile.form.hidden'} = WebGUI::Form::hidden({"name"=>"op","value"=>"editProfileSave"}); - $vars->{'profile.form.hidden'} .= WebGUI::Form::hidden({"name"=>"uid","value"=>$session{user}{userId}}); - - $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId - and userProfileCategory.editable=1 and userProfileField.editable=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); - my $counter = 0; - while($data = $a->hashRef) { - $counter++; - my %hash = (); - $category = WebGUI::Operation::Shared::secureEval($data->{categoryName}); - $method = $data->{dataType}; - $label = WebGUI::Operation::Shared::secureEval($data->{fieldLabel}); - $default = WebGUI::Operation::Shared::secureEval($data->{dataDefault}); - - if ($method eq "selectList" || $method eq "checkList" || $method eq "radioList") { - $values = WebGUI::Operation::Shared::secureEval($data->{dataValues}); - my $orderedValues = {}; - tie %{$orderedValues}, 'Tie::IxHash'; - foreach my $ov (sort keys %{$values}) { - $orderedValues->{$ov} = $values->{$ov}; - } - # note: this big if statement doesn't look elegant, but doing regular ORs caused problems with the array reference. - if ($session{form}{$data->{fieldName}}) { - $default = [$session{form}{$data->{fieldName}}]; - } elsif ($session{user}{$data->{fieldName}}) { - $default = [$session{user}{$data->{fieldName}}]; - } - $hash{'profile.form.element'} = WebGUI::Form::selectList({ - "name"=>$data->{fieldName}, - "options"=>$values, - "value"=>$default - }); - } else { - if ($session{form}{$data->{fieldName}}) { - $default = $session{form}{$data->{fieldName}}; - } elsif (exists $session{user}{$data->{fieldName}}) { - $default = $session{user}{$data->{fieldName}}; - } - my $cmd = 'WebGUI::Form::'.$method.'({"name"=>$data->{fieldName},"value"=>$default})'; - $hash{'profile.form.element'} = eval($cmd); - - } - $hash{'profile.form.element.label'} = $label; - if ($data->{required}) { - $hash{'profile.form.element.subtext'} = "*"; - } - push(@profile,\%hash); - if (($previousCategory && $category ne $previousCategory) || $counter eq $a->rows) { - my @temp = @profile; - my $hashRef; - $hashRef->{'profile.form.category'} = $previousCategory; - $hashRef->{'profile.form.category.loop'} = \@temp; - push(@array,$hashRef); - @profile = (); - } - $previousCategory = $category; - } - $a->finish; - + my ($a, $data, $previousCategory, $subtext, $vars, @profile, @array); + return WebGUI::Operation::Auth::www_auth("init") if($session{user}{userId} eq '1'); + + $vars->{displayTitle} .= '

    '.WebGUI::International::get(338).'

    '; + + $vars->{'profile.message'} = $_[0] if($_[0]); + $vars->{'profile.form.header'} = "\n\n".WebGUI::Form::formHeader({}); + $vars->{'profile.form.footer'} = WebGUI::Form::formFooter(); + + $vars->{'profile.form.hidden'} = WebGUI::Form::hidden({"name"=>"op","value"=>"editProfileSave"}); + $vars->{'profile.form.hidden'} .= WebGUI::Form::hidden({"name"=>"uid","value"=>$session{user}{userId}}); + + $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId + and userProfileCategory.editable=1 and userProfileField.editable=1 order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); + my $counter = 0; + while($data = $a->hashRef) { + $counter++; + my %hash = (); + my $category = WebGUI::Operation::Shared::secureEval($data->{categoryName}); + my $label = WebGUI::Operation::Shared::secureEval($data->{fieldLabel}); + my $values = WebGUI::Operation::Shared::secureEval($data->{dataValues}); + my $method = $data->{dataType}; + my $orderedValues = {}; + tie %{$orderedValues}, 'Tie::IxHash'; + foreach my $ov (sort keys %{$values}) { + $orderedValues->{$ov} = $values->{$ov}; + } + my $default; + if ($session{form}{$data->{fieldName}}) { + $default = $session{form}{$data->{fieldName}}; + } + elsif ($session{user}{$data->{fieldName}}) { + $default = $session{user}{$data->{fieldName}}; + } + else { + $default = WebGUI::Operation::Shared::secureEval($data->{dataDefault}); + } + my $form = WebGUI::Form::DynamicField->new( + name => $data->{fieldName}, + value => $default, + options => $orderedValues, + fieldType => $method, + ); + + $hash{'profile.form.element'} = $form->displayForm(); + $hash{'profile.form.element.label'} = $label; + + if ($data->{required}) { + $hash{'profile.form.element.subtext'} = "*"; + } + if (($previousCategory && $category ne $previousCategory) || $counter eq $a->rows) { + my @temp = @profile; + my $hashRef; + $hashRef->{'profile.form.category'} = $previousCategory; + $hashRef->{'profile.form.category.loop'} = \@temp; + push(@array,$hashRef); + @profile = (); + } + $previousCategory = $category; + push(@profile,\%hash); + } + $a->finish; + $vars->{'profile.form.elements'} = \@array; - $vars->{'profile.form.submit'} = WebGUI::Form::submit({}); - $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); + $vars->{'profile.form.submit'} = WebGUI::Form::submit({}); + $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new("PBtmpl0000000000000051")->process($vars)); } #------------------------------------------------------------------- sub www_editProfileSave { my ($profile, $fieldName, $error, $u, $warning); - return WebGUI::Operation::Auth::www_auth("init") if ($session{user}{userId} eq '1'); + return WebGUI::Operation::Auth::www_auth("init") if ($session{user}{userId} eq '1'); ($profile, $error, $warning) = validateProfileData(); $error .= $warning; @@ -215,8 +212,8 @@ sub www_editProfileSave { return www_editProfile('
      '.$error.'
    ') if($error ne ""); $u = WebGUI::User->new($session{user}{userId}); - foreach $fieldName (keys %{$profile}) { - $u->profileField($fieldName,WebGUI::HTML::filter(${$profile}{$fieldName},"javascript")); + foreach $fieldName (keys %{$profile}) { + $u->profileField($fieldName,WebGUI::HTML::filter(${$profile}{$fieldName},"javascript")); } WebGUI::Session::refreshUserInfo($session{user}{userId}); return WebGUI::Operation::Auth::www_auth(); @@ -224,48 +221,63 @@ sub www_editProfileSave { #------------------------------------------------------------------- sub www_viewProfile { - my ($a, %data, $category, $label, $value, $previousCategory, $u, %gender,$vars,@array); - %gender = ('neuter'=>WebGUI::International::get(403),'male'=>WebGUI::International::get(339),'female'=>WebGUI::International::get(340)); + my ($a, %data, $category, $label, $value, $previousCategory, $u, $vars, @array); $u = WebGUI::User->new($session{form}{uid}); - $vars->{displayTitle} = '

    '.WebGUI::International::get(347).' '.$u->username.'

    '; + $vars->{displayTitle} = '

    '.WebGUI::International::get(347).' '.$u->username.'

    '; + return WebGUI::Privilege::notMember() if($u->username eq ""); + return WebGUI::Operation::Shared::userStyle($vars->{displayTitle}.WebGUI::International::get(862)) if($u->profileField("publicProfile") < 1 && ($session{user}{userId} ne $session{form}{uid} || WebGUI::Grouping::isInGroup(3))); + return WebGUI::Privilege::insufficient() if(!WebGUI::Grouping::isInGroup(2)); - $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId + + $a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId and userProfileCategory.visible=1 and userProfileField.visible=1 order by userProfileCategory.sequenceNumber, userProfileField.sequenceNumber",WebGUI::SQL->getSlave); - while (%data = $a->hash) { - $category = WebGUI::Operation::Shared::secureEval($data{categoryName}); - if ($category ne $previousCategory) { - my $header; - $header->{'profile.category'} = $category; - push(@array,$header); - } - - $label = WebGUI::Operation::Shared::secureEval($data{fieldLabel}); - if ($data{dataValues}) { - $value = WebGUI::Operation::Shared::secureEval($data{dataValues}); - $value = ${$value}{$u->profileField($data{fieldName})}; - } else { - $value = $u->profileField($data{fieldName}); - } - if ($data{dataType} eq "date") { - $value = WebGUI::DateTime::epochToHuman($value,"%z"); - } - unless ($data{fieldName} eq "email" and $u->profileField("publicEmail") < 1) { - my $hash; - $hash->{'profile.label'} = $label; - $hash->{'profile.value'} = $value; - push(@array,$hash); - } - $previousCategory = $category; - } - $vars->{'profile.elements'} = \@array; - $a->finish; - if ($session{user}{userId} eq $session{form}{uid}) { - $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); + + while (%data = $a->hash) { + + $category = WebGUI::Operation::Shared::secureEval($data{categoryName}); + if ($category ne $previousCategory) { + my $header; + $header->{'profile.category'} = $category; + push(@array,$header); + $previousCategory = $category; + } + + next if ($data{fieldName} eq "email" and $u->profileField("publicEmail")); + + $label = WebGUI::Operation::Shared::secureEval($data{fieldLabel}); + + ##If the form field has multiple selections, only display the one the user + ##currently has selected. + if ($data{dataValues}) { + $value = WebGUI::Operation::Shared::secureEval($data{dataValues}); + $value = ${$value}{$u->profileField($data{fieldName})}; + } + else { + $value = $u->profileField($data{fieldName}); + } + + my $form = WebGUI::Form::DynamicField->new( + value => $value, + fieldType => $data{dataType}, + ); + + $value = $form->displayValue(); + + my $hash; + + $hash->{'profile.label'} = $label; + $hash->{'profile.value'} = $value; + push(@array,$hash); } - return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new("PBtmpl0000000000000052")->process($vars)); + $vars->{'profile.elements'} = \@array; + $a->finish; + if ($session{user}{userId} eq $session{form}{uid}) { + $vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions(); + } + return WebGUI::Operation::Shared::userStyle(WebGUI::Asset::Template->new("PBtmpl0000000000000052")->process($vars)); } 1; diff --git a/lib/WebGUI/Operation/ProfileSettings.pm b/lib/WebGUI/Operation/ProfileSettings.pm index cad0266d4..4fdc5f750 100644 --- a/lib/WebGUI/Operation/ProfileSettings.pm +++ b/lib/WebGUI/Operation/ProfileSettings.pm @@ -22,6 +22,7 @@ use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Operation::Shared; +use WebGUI::Form::FieldType; #------------------------------------------------------------------- sub _reorderCategories { @@ -212,14 +213,24 @@ sub www_editProfileField { -hoverHelp=>WebGUI::International::get('474 description',"WebGUIProfile"), -value=>$data{required} ); - $f->fieldType( + #WebGUI::ErrorHandler::warn("type=".$data{dataType}); + my $fieldType = WebGUI::Form::FieldType->new( -name=>"dataType", -label=>WebGUI::International::get(486,"WebGUIProfile"), -hoverHelp=>WebGUI::International::get('486 description',"WebGUIProfile"), - -value=>$data{dataType}, - -defaultValue=>"text", - -types=>[qw(dateTime timeZone TimeField float zipcode text textarea HTMLArea url date email phone integer yesNo selectList radioList checkList)] - ); + -value=>ucfirst $data{dataType}, + -defaultValue=>"Text", + ); + my @profileForms = (); + foreach my $form ( sort @{ $fieldType->{types} }) { + my $cmd = join '::', 'WebGUI::Form', $form; + eval "use $cmd"; + my $w = eval "$cmd->new();"; + push @profileForms, $form if $w->{profileEnabled}; + } + + $fieldType->{types} = \@profileForms; + $f->raw($fieldType->toHtmlWithWrapper()); $f->textarea( -name => "dataValues", -label => WebGUI::International::get(487,"WebGUIProfile"), diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm index a53518e90..46e2f3827 100644 --- a/lib/WebGUI/Operation/User.pm +++ b/lib/WebGUI/Operation/User.pm @@ -15,10 +15,11 @@ use Tie::CPHash; use Tie::IxHash; use WebGUI::AdminConsole; use WebGUI::DateTime; -use WebGUI::Form; use WebGUI::FormProcessor; use WebGUI::Group; use WebGUI::Grouping; +use WebGUI::Form; +use WebGUI::Form::DynamicField; use WebGUI::HTMLForm; use WebGUI::Icon; use WebGUI::International; @@ -278,48 +279,39 @@ sub www_editUser { where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber"); my $previousCategory; - while(my %data = $a->hash) { - my $category = WebGUI::Operation::Shared::secureEval($data{categoryName}); + while(my $data = $a->hashRef) { + my $category = WebGUI::Operation::Shared::secureEval($data->{categoryName}); if ($category ne $previousCategory) { $tabform->getTab("profile")->raw(''.$category.''); } - my $values = WebGUI::Operation::Shared::secureEval($data{dataValues}); - my $method = $data{dataType}; - my $label = WebGUI::Operation::Shared::secureEval($data{fieldLabel}); + my $values = WebGUI::Operation::Shared::secureEval($data->{dataValues}); + my $method = $data->{dataType}; + my $label = WebGUI::Operation::Shared::secureEval($data->{fieldLabel}); my $default; - if ($method eq "selectList" || $method eq "checkList" || $method eq "radioList") { - my $orderedValues = {}; - tie %{$orderedValues}, 'Tie::IxHash'; - foreach my $ov (sort keys %{$values}) { - $orderedValues->{$ov} = $values->{$ov}; - } - if ($session{form}{$data{fieldName}}) { - $default = [$session{form}{$data{fieldName}}]; - } elsif (defined $u->profileField($data{fieldName}) && (defined($values->{$u->profileField($data{fieldName})}))) { - $default = [$u->profileField($data{fieldName})]; - } else { - $default = WebGUI::Operation::Shared::secureEval($data{dataDefault}); - } - $tabform->getTab("profile")->$method( - -name=>$data{fieldName}, - -options=>$orderedValues, - -label=>$label, - -value=>$default - ); - } elsif ($method) { - if ($session{form}{$data{fieldName}}) { - $default = $session{form}{$data{fieldName}}; - } elsif (defined $u->profileField($data{fieldName})) { - $default = $u->profileField($data{fieldName}); - } else { - $default = WebGUI::Operation::Shared::secureEval($data{dataDefault}); - } - $tabform->getTab("profile")->$method( - -name=>$data{fieldName}, - -label=>$label, - -value=>$default - ); - } + my $orderedValues = {}; + tie %{$orderedValues}, 'Tie::IxHash'; + foreach my $ov (sort keys %{$values}) { + $orderedValues->{$ov} = $values->{$ov}; + } + if ($session{form}{$data->{fieldName}}) { + $default = $session{form}{$data->{fieldName}}; + } + elsif ($session{user}{$data->{fieldName}}) { + $default = $session{user}{$data->{fieldName}}; + } + else { + $default = WebGUI::Operation::Shared::secureEval($data->{dataDefault}); + } + + my $form = WebGUI::Form::DynamicField->new( + name => $data->{fieldName}, + label => $label, + value => $default, + options => $orderedValues, + fieldType => $method, + ); + + $tabform->getTab("profile")->raw($form->displayFormWithWrapper()); $previousCategory = $category; } $a->finish; diff --git a/lib/WebGUI/i18n/English/Asset_Collaboration.pm b/lib/WebGUI/i18n/English/Asset_Collaboration.pm index 216dc685b..2f6aba925 100644 --- a/lib/WebGUI/i18n/English/Asset_Collaboration.pm +++ b/lib/WebGUI/i18n/English/Asset_Collaboration.pm @@ -1266,6 +1266,15 @@ A URL for sorting and displaying the list of posts by their ratings. lastUpdated => 1114467741, }, + 'enable avatars' => { + message => q|Enable Avatars?|, + lastUpdated => 1131432414, + }, + + 'enable avatars description' => { + message => q|

    Select "Yes" to display Avatars for users in the Collaboration System. The Avatar field inthe User Profile has to be enabled, and users will need to upload an Avatar image to display.

    Using Avatars will slow down the performance of Collaboration Systems.

    |, + lastUpdated => 1131432717, + }, 'collaboration rss template title' => { message => q|Collaboration RSS Template|, diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 931766fa1..bfb94aa1b 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -367,6 +367,11 @@ Be aware that any database links you create here will be available to all conten lastUpdated => 1031514049 }, + '392' => { + message => q|Delete this file?|, + lastUpdated => 1131831533, + }, + '743' => { message => q|You must specify a valid email address in order to attempt to recover your password.|, lastUpdated => 1035246389 @@ -3248,6 +3253,12 @@ that Asset and all Assets below it.

    context => q|Field type name| }, + 'image' => { + message => q|Image|, + lastUpdated =>0, + context => q|Field type name| + }, + 'codearea' => { message => q|Code Area|, lastUpdated =>0, @@ -3803,6 +3814,16 @@ Message Boards hold forums for users. There are many different Wobjects in WebG lastUpdated => 1128919994, }, + 'photo' => { + message => q|Photo|, + lastUpdated => 1131246503, + }, + + 'avatar' => { + message => q|Avatar|, + lastUpdated => 1131246512, + }, + }; 1;