Changes to WebGUI for Private Messaging

This commit is contained in:
Frank Dillon 2007-06-14 20:10:33 +00:00
parent cc7687c877
commit 82e020dc4f
9 changed files with 562 additions and 44 deletions

View file

@ -33,6 +33,73 @@ Operations for viewing message logs and individual messages.
#-------------------------------------------------------------------
=head2 _appendPrivateMessageForm ( vars, userTo, subject )
appends the form variables for the private message form
=cut
sub _appendPrivateMessageForm {
my $session = shift;
my $vars = shift;
my $userTo = shift;
my $message = shift;
my $i18n = WebGUI::International->new($session);
my $form = $session->form;
my $user = $session->user;
$vars->{ message_from_label } = $i18n->get("private message from label");
$vars->{ message_from } = $user->username;
$vars->{ message_to_label } = $i18n->get("private message to label");
$vars->{ message_to } = $userTo->username;
$vars->{ message_to } .= WebGUI::Form::hidden($session, {
name=>"uid",
value=>$userTo->userId
});
my $subject = $form->get("subject") || "";
if($subject eq "" && defined $message) {
$subject = "Re: ".$message->get("subject");
}
$vars->{ subject_label } = $i18n->get("private message subject label");
$vars->{ subject } = WebGUI::Form::text($session, {
name=>"subject",
value=>$subject,
});
$vars->{ message_label } = $i18n->get("private message message label");
$vars->{ message_text } = WebGUI::Form::textarea($session, {
name=>"message",
value=>$form->get("message") || "",
});
$vars->{ message_rich } = WebGUI::Form::HTMLArea($session, {
name=>"message",
value=>$form->get("message") || "",
});
$vars->{ form_header } = WebGUI::Form::formHeader($session);
$vars->{ form_header } .= WebGUI::Form::hidden($session, {
name => "op",
value => "sendPrivateMessageSave"
});
$vars->{ form_header } .= WebGUI::Form::hidden($session, {
name => "messageId",
value => $form->get("messageId") || "",
});
$vars->{ submit_button } = WebGUI::Form::submit($session,{});
$vars->{ submit_label } = $i18n->get("private message submit label");
$vars->{ form_footer } = WebGUI::Form::formFooter($session, {});
}
#-------------------------------------------------------------------
=head2 _status ( )
returns a hashref with internationalized values for message status.
@ -42,9 +109,138 @@ returns a hashref with internationalized values for message status.
sub _status {
my $session = shift;
my $i18n = WebGUI::International->new($session);
return {"pending"=>$i18n->get(552),"completed"=>$i18n->get(350)};
return {
"pending" =>$i18n->get(552),
"completed" =>$i18n->get(350),
"unread" =>$i18n->get("private message status unread"),
"read" =>$i18n->get("private message status read"),
"replied" =>$i18n->get("private message status replied"),
};
}
#-------------------------------------------------------------------
=head2 www_sendPrivateMessage ( )
Form for sending private messages
=cut
sub www_sendPrivateMessage {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $i18n = WebGUI::International->new($session);
my $form = $session->form;
my $user = $session->user;
my $style = $session->style;
my $settings = $session->setting;
my $templateId = $settings->get("sendPrivateMessageTemplateId");
my $uid = $form->get("uid");
my $userTo = WebGUI::User->new($session,$uid);
my $vars = {};
$vars->{title} = $i18n->get('private message title');
if($uid eq "") {
$vars->{'error_msg'} = $i18n->get('private message no user');
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
elsif($uid eq $user->userId) {
$vars->{'error_msg'} = $i18n->get('private message no self error');
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
unless($userTo->profileField("allowPrivateMessages")) {
$vars->{'error_msg'} = $i18n->get('private message blocked error');
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
_appendPrivateMessageForm($session,$vars,$userTo);
$vars->{ accountOptions } = WebGUI::Operation::Shared::accountOptions($session);
return $style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
#-------------------------------------------------------------------
=head2 www_sendPrivateMessageSave ( )
Post process the form, check for required fields, handle inviting users who are already
members (determined by email address) and send the email.
=cut
sub www_sendPrivateMessageSave {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $i18n = WebGUI::International->new($session);
my $form = $session->form;
my $user = $session->user;
my $style = $session->style;
my $uid = $form->get("uid");
my $userTo = WebGUI::User->new($session,$uid);
if($uid eq "") {
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
$i18n->get('private message error'),
$i18n->get('private message no user'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $style->userStyle($output);
} elsif($uid eq $user->userId) {
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
$i18n->get('private message error'),
$i18n->get('private message no self error'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $style->userStyle($output);
}
my $isReply = 0;
if($form->get("messageId")) {
my $message = WebGUI::Inbox->new($session)->getMessage($form->get("messageId"));
# Ensure that the user sending the message was sent by the user being replied to
# and that the user reponding is the user the message was sent to
if($message->get("sentBy") eq $uid && $message->get("userId") eq $user->userId) {
$isReply = 1;
$message->setStatus("replied");
}
}
unless($isReply || $userTo->profileField("allowPrivateMessages")) {
my $output = sprintf qq|<h1>%s</h1>\n<p>%s</p><a href="%s">%s</a>|,
$i18n->get('private message error'),
$i18n->get('private message blocked error'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $style->userStyle($output);
}
WebGUI::Inbox->new($session)->addMessage({
message => $form->get("message"),
subject => $form->get("subject"),
userId => $uid,
status => 'unread',
sentBy => $user->userId
});
my $output = sprintf qq!<p>%s</p><a href="%s">%s</a>!,
$i18n->get('private message sent'),
$session->url->getBackToSiteURL(),
$i18n->get('493', 'WebGUI');
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_viewInbox ( )
@ -56,25 +252,61 @@ Templated display all messages for the current user.
sub www_viewInbox {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
my $i18n = WebGUI::International->new($session);
my $i18n = WebGUI::International->new($session);
my $vars = {};
my @msg = ();
$vars->{title} = $i18n->get(159);
$vars->{'subject.label'} = $i18n->get(351);
$vars->{'status.label'} = $i18n->get(553);
$vars->{'dateStamp.label'} = $i18n->get(352);
my $messages = WebGUI::Inbox->new($session)->getMessagesForUser($session->user);
my @msg = ();
my $pn = $session->form->get("pn") || 1;
my $rpp = 10;
$vars->{ title } = $i18n->get(159);
$vars->{'subject_label' } = $i18n->get(351);
$vars->{'status_label' } = $i18n->get(553);
$vars->{'from_label' } = $i18n->get("private message from label");
$vars->{'dateStamp_label'} = $i18n->get(352);
my $adminUser = WebGUI::User->new($session,3)->username;
my $messages = WebGUI::Inbox->new($session)->getMessagesForUser($session->user,$rpp,$pn);
foreach my $message (@$messages) {
my $hash = {};
$hash->{'subject'} = '<a href="'.$session->url->page('op=viewInboxMessage;messageId='.$message->getId).'">'.$message->get("subject").'</a>';
$hash->{status} = _status($session)->{$message->get("status")};
$hash->{'dateStamp'} =$session->datetime->epochToHuman($message->get("dateStamp"));
my $hash = {};
$hash->{ message_url } = $session->url->page('op=viewInboxMessage;messageId='.$message->getId);
$hash->{ subject } = $message->get("subject");
$hash->{ status_class } = $message->get("status");
$hash->{ status } = _status($session)->{$hash->{ status_class }};
#Get the username of the person who sent the message
my $sentBy = $message->get("sentBy");
#Assume it's the admin user for speed purposes - admin user is cached above the loop
my $from = $adminUser;
#If it wasn't the admin user, get the username of the person who sent it
if($sentBy ne "3") {
my $u = WebGUI::User->new($session,$sentBy);
#If the user that sent the message is valid, get the username
#This case would happen if the user was deleted after sending a private message
if($u->userId ne "1") {
$from = $u->username;
}
}
$hash->{ from } = $from;
$hash->{ dateStamp } = $session->datetime->epochToHuman($message->get("dateStamp"));
push(@msg,$hash);
}
$vars->{'messages'} = \@msg;
$vars->{'noresults'} = $i18n->get(353) unless (scalar(@$messages) > 0);
my $msgCount = scalar(@{$messages});
#Pagination has to exist on every page regardless if there are more messages or not.
if($pn > 1 ) {
$vars->{'prev_url' } = $session->url->page('op=viewInbox;pn='.($pn-1));
$vars->{'prev_label' } = $i18n->get("private message prev label");
}
$vars->{'next_url' } = $session->url->page('op=viewInbox;pn='.($pn+1));
$vars->{'next_label' } = $i18n->get("private message next label");
$vars->{'messages' } = \@msg;
$vars->{'noresults' } = $i18n->get(353) unless ($msgCount > 0);
$vars->{'accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
return $session->style->userStyle(WebGUI::Asset::Template->new($session,"PBtmpl0000000000000206")->process($vars));
my $templateId = $session->setting->get("viewInboxTemplateId");
return $session->style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
#-------------------------------------------------------------------
@ -88,24 +320,65 @@ Templated display of a single message for the user.
sub www_viewInboxMessage {
my $session = shift;
return $session->privilege->insufficient() unless ($session->user->isInGroup(2));
#Get the message
my $message = WebGUI::Inbox->new($session)->getMessage($session->form->param("messageId"));
#Make sure users can only read their own messages
my $userId = $message->get("userId");
my $groupId = $message->get("groupId");
return $session->privilege->insufficient() unless (
$session->user->userId eq $userId
|| (defined $groupId && $session->user->isInGroup($groupId))
);
my $i18n = WebGUI::International->new($session);
my $vars = {};
$vars->{title} = $i18n->get(159);
my $message = WebGUI::Inbox->new($session)->getMessage($session->form->param("messageId"));
if (defined $message) {
$vars->{'subject'} = $message->get("subject");
$vars->{ title } = $i18n->get("private message reply title");
$vars->{ from_label } = $i18n->get("private message from label");
$vars->{ date_label } = $i18n->get("private message date label");
if (defined $message) {
my $origStatus = $message->get("status");
$message->setStatus("read") if($origStatus eq "unread");
$vars->{'message_subject' } = $message->get("subject");
$vars->{'dateStamp'} =$session->datetime->epochToHuman($message->get("dateStamp"));
$vars->{'status'} = _status($session)->{$message->get("status")};
$vars->{message} = $message->get("message");
$vars->{'status' } = _status($session)->{$message->get("status")};
$vars->{ message } = $message->get("message");
unless ($vars->{message} =~ /\<a/ig) {
$vars->{message} =~ s/(http\S*)/\<a href=\"$1\"\>$1\<\/a\>/g;
}
unless ($vars->{message} =~ /\<div/ig || $vars->{message} =~ /\<br/ig || $vars->{message} =~ /\<p/ig) {
$vars->{message} =~ s/\n/\<br \/\>\n/g;
}
#Get the username of the person who sent the message
my $sentBy = $message->get("sentBy");
#Assume it's the admin user who sent the message
my $from = WebGUI::User->new($session,3)->username;
#If the user actually exists, get the username
if($sentBy ne "1" && $sentBy ne "3") {
$from = WebGUI::User->new($session,$sentBy)->username;
}
$vars->{ from } = $from;
#If the person didn't send the message to themselves (for admin only) and the user still exsists (check visitor case)
if($sentBy ne $session->user->userId &&
$sentBy ne "1" &&
$origStatus ne "pending" &&
$origStatus ne "completed") {
my $u = WebGUI::User->new($session,$sentBy);
$vars->{'canReply'} = "true";
_appendPrivateMessageForm($session,$vars,$u,$message);
}
}
$vars->{'accountOptions'} = WebGUI::Operation::Shared::accountOptions($session);
return $session->style->userStyle(WebGUI::Asset::Template->new($session,"PBtmpl0000000000000205")->process($vars));
my $templateId = $session->setting->get("viewInboxMessageTemplateId");
return $session->style->userStyle(WebGUI::Asset::Template->new($session,$templateId)->process($vars));
}
1;

View file

@ -222,6 +222,33 @@ sub definition {
namespace=>"AdminConsole",
defaultValue=>$session->setting->get("AdminConsoleTemplate")
});
push(@fields, {
tab=>"ui",
fieldType=>"template",
name=>"viewInboxTemplateId",
label=>$i18n->get('view inbox template'),
hoverHelp=>$i18n->get('view inbox template description'),
namespace=>"Inbox",
defaultValue=>$session->setting->get("viewInboxTemplateId"),
});
push(@fields, {
tab=>"ui",
fieldType=>"template",
name=>"viewInboxMessageTemplateId",
label=>$i18n->get('view inbox message template'),
hoverHelp=>$i18n->get('view inbox message template description'),
namespace=>"Inbox/Message",
defaultValue=>$session->setting->get("viewInboxMessageTemplateId"),
});
push(@fields, {
tab=>"ui",
fieldType=>"template",
name=>"sendPrivateMessageTemplateId",
label=>$i18n->get('send private message template'),
hoverHelp=>$i18n->get('send private message template description'),
namespace=>"Inbox/SendPrivateMessage",
defaultValue=>$session->setting->get("sendPrivateMessageTemplateId"),
});
# messaging settings
push(@fields, {
tab=>"messaging",

View file

@ -35,6 +35,8 @@ is in group Admin (3). Returns the user to the List Database Links screen.
my $session = shift;
my $i18n = WebGUI::International->new($session);
my @array;
my $op = $session->form->process("op");
if ($session->user->isInGroup(12)) {
my %hash;
if ($session->var->get("adminOn")) {
@ -44,29 +46,35 @@ is in group Admin (3). Returns the user to the List Database Links screen.
}
push(@array,\%hash);
}
unless ($session->form->process("op") eq "displayAccount"){
unless ($op eq "displayAccount"){
my %hash;
$hash{'options.display'} = '<a href="'.$session->url->page('op=auth;method=init').'">'.$i18n->get(342).'</a>';
push(@array,\%hash);
}
unless ($session->form->process("op") eq "editProfile"){
unless ($op eq "editProfile"){
my %hash;
$hash{'options.display'} = '<a href="'.$session->url->page('op=editProfile').'">'.$i18n->get(341).'</a>';
push(@array,\%hash);
}
unless ($session->form->process("op") eq "viewProfile"){
unless ($op eq "viewProfile"){
my %hash;
$hash{'options.display'} = '<a href="'.$session->url->page('op=viewProfile;uid='.$session->user->userId).'">'.$i18n->get(343).'</a>';
push(@array,\%hash);
}
unless ($session->form->process("op") eq "viewInbox"){
unless ($op eq "viewInbox"){
my %hash;
$hash{'options.display'} = '<a href="'.$session->url->page('op=viewInbox').'">'.$i18n->get(354).'</a>';
push(@array,\%hash);
}
unless ($session->form->process("op") eq "redeemSubscriptionCode") {
unless ($op eq "redeemSubscriptionCode") {
push(@array, {'options.display' => '<a href="'.$session->url->page('op=redeemSubscriptionCode').'">'.$i18n->get('redeem code', 'Subscription').'</a>'});
}
my $uid = $session->form->get("uid");
if($op eq "viewProfile" && $uid ne $session->user->userId) {
push(@array, {'options.display' => '<a href="'.$session->url->page('op=sendPrivateMessage;uid='.$uid).'">'.$i18n->get('send private message').'</a>'});
}
if ($session->setting->get('userInvitationsEnabled')) {
push @array, {