package WebGUI::Inbox::Message; =head1 LEGAL ------------------------------------------------------------------- WebGUI is Copyright 2001-2008 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 WebGUI::Mail::Send; use WebGUI::International; =head1 NAME Package WebGUI::Inbox::Message; =head1 DESCRIPTION This package provides an API for working with inbox messages. =head1 SYNOPSIS use WebGUI::Inbox::Message; my $message = WebGUI::Inbox::Message->new($session, $messageId); =head1 METHODS These methods are available from this class: =cut #------------------------------------------------------------------- =head2 create ( session, properties ) Creates a new message. =head2 session A reference to the current session. =head3 properties A hash reference containing the properties to update. =head4 message The content of this message. =head4 subject The topic of this message. Defaults to 'Notification'. =head4 status May be "pending" or "completed". Defaults to "pending". You should set this to completed if this is a message without an action, such as a notification. =head4 userId A userId of a user attached to this message. =head4 groupId A groupId of a group attached to this message. =head4 sentBy A userId that created this message. Defaults to '3' (Admin). =head4 emailMessage Email message to use rather than inbox message contents. =head4 emailSubject Email subject to use rather than inbox message subject. =cut sub create { my $class = shift; my $session = shift; my $properties = shift; my $self = {}; $self->{_properties}{messageId} = "new"; $self->{_properties}{status} = $properties->{status} || "pending"; $self->{_properties}{subject} = $properties->{subject} || WebGUI::International->new($session)->get(523); $self->{_properties}{message} = $properties->{message}; $self->{_properties}{dateStamp} = time(); $self->{_properties}{userId} = $properties->{userId}; $self->{_properties}{groupId} = $properties->{groupId}; $self->{_properties}{sentBy} = $properties->{sentBy} || 3; if ($self->{_properties}{status} eq "completed") { $self->{_properties}{completedBy} = $session->user->userId; $self->{_properties}{completedOn} = time(); } $self->{_messageId} = $self->{_properties}{messageId} = $session->db->setRow("inbox","messageId",$self->{_properties}); my $subject = (defined $properties->{emailSubject}) ? $properties->{emailSubject} : $self->{_properties}{subject}; my $mail = WebGUI::Mail::Send->create($session, { toUser=>$self->{_properties}{userId}, toGroup=>$self->{_properties}{groupId}, subject=>$subject, }); if (defined $mail) { my $preface = ""; my $fromUser = WebGUI::User->new($session, $properties->{sentBy}); #Don't append prefaces to the visitor users or messages that don't specify a user (default case) unless ($fromUser->isVisitor || $fromUser->userId eq 3) { #Can't use isAdmin because it will not send prefaces from normal users who in the admin group my $i18n = WebGUI::International->new($session, 'Inbox_Message'); $preface = sprintf($i18n->get('from user preface'), $fromUser->username); } my $msg = (defined $properties->{emailMessage}) ? $properties->{emailMessage} : $self->{_properties}{message}; if ($msg =~ m/\<.*\>/) { $msg = '
' . $preface . '