1 package SL::Controller::EmailJournal;
5 use parent qw(SL::Controller::Base);
7 use SL::Controller::Helper::GetModels;
9 use SL::DB::EmailJournal;
10 use SL::DB::EmailJournalAttachment;
11 use SL::Helper::Flash;
12 use SL::Locale::String;
13 use SL::System::TaskServer;
15 use Rose::Object::MakeMethods::Generic
17 scalar => [ qw(entry) ],
18 'scalar --get_set_init' => [ qw(models can_view_all filter_summary) ],
21 __PACKAGE__->run_before('add_stylesheet');
30 if ( $::instance_conf->get_email_journal == 0 ) {
31 flash('info', $::locale->text('Storing the emails in the journal is currently disabled in the client configuration.'));
33 $self->render('email_journal/list',
34 title => $::locale->text('Email journal'),
35 ENTRIES => $self->models->get,
36 MODELS => $self->models);
42 my $back_to = $::form->{back_to} || $self->url_for(action => 'list');
44 $self->entry(SL::DB::EmailJournal->new(id => $::form->{id})->load);
46 if (!$self->can_view_all && ($self->entry->sender_id != SL::DB::Manager::Employee->current->id)) {
47 $::form->error(t8('You do not have permission to access this entry.'));
50 $self->render('email_journal/show',
51 title => $::locale->text('View sent email'),
55 sub action_download_attachment {
58 my $attachment = SL::DB::EmailJournalAttachment->new(id => $::form->{id})->load;
60 if (!$self->can_view_all && ($attachment->email_journal->sender_id != SL::DB::Manager::Employee->current->id)) {
61 $::form->error(t8('You do not have permission to access this entry.'));
64 $self->send_file(\$attachment->content, name => $attachment->name, type => $attachment->mime_type);
72 $::request->{layout}->use_stylesheet('email_journal.css');
79 sub init_can_view_all { $::auth->assert('admin', 1) }
85 push @where, (sender_id => SL::DB::Manager::Employee->current->id) if !$self->can_view_all;
87 SL::Controller::Helper::GetModels->new(
90 with_objects => [ 'sender' ],
92 sender => t8('Sender'),
94 recipients => t8('Recipients'),
95 subject => t8('Subject'),
96 sent_on => t8('Sent on'),
97 status => t8('Status'),
98 extended_status => t8('Extended status'),
103 sub init_filter_summary {
106 my $filter = $::form->{filter} || {};
108 [ "from:substr::ilike", $::locale->text('From') ],
109 [ "recipients:substr::ilike", $::locale->text('Recipients') ],
110 [ "sent_on:date::ge", $::locale->text('Sent on') . " " . $::locale->text('From Date') ],
111 [ "sent_on:date::le", $::locale->text('Sent on') . " " . $::locale->text('To Date') ],
114 my @filter_strings = grep { $_ }
115 map { $filter->{ $_->[0] } ? $_->[1] . ' ' . $filter->{ $_->[0] } : undef }
119 failed => $::locale->text('failed'),
120 ok => $::locale->text('succeeded'),
122 push @filter_strings, $status{ $filter->{'status:eq_ignore_empty'} } if $filter->{'status:eq_ignore_empty'};
124 return join ', ', @filter_strings;