Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6e76fe01

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 6e76fe01035adec38bf4de0948af7bb267b5f1a3
  • Vorgänger 7ce99469

FU: Email bei neuen Wiedervorlagen

Unterschiede anzeigen:

SL/FU.pm
8 8
use SL::DBUtils;
9 9
use SL::DB;
10 10
use SL::DB::FollowUpCreatedForEmployee;
11
use SL::Mailer;
11 12
use SL::Notes;
13
use SL::Template;
14
use SL::Template::Simple;
12 15

  
13 16
use strict;
14 17

  
......
16 19
  my ($self, %params) = @_;
17 20
  $main::lxdebug->enter_sub();
18 21

  
22
  my $is_new   = !$params{id};
23

  
19 24
  my $rc = SL::DB->client->with_transaction(\&_save, $self, %params);
20 25

  
26
  FU->send_email_notification(%params) if ($is_new);
27

  
21 28
  $::lxdebug->leave_sub;
22 29
  return $rc;
23 30
}
......
545 552
  return $access;
546 553
}
547 554

  
555
sub send_email_notification {
556
  $main::lxdebug->enter_sub();
557
  my ($self, %params) = @_;
558

  
559
  my $notify_cfg = $main::lx_office_conf{follow_up_notify};
560
  if (!$notify_cfg
561
   || !$notify_cfg->{email_subject}
562
   || !$notify_cfg->{email_from}
563
   || !$notify_cfg->{email_template}) {
564
    $main::lxdebug->leave_sub();
565
    return;
566
  }
567

  
568
  my $employee = SL::DB::Manager::Employee->current;
569

  
570
  my @for_employees_ids = @{$params{created_for_employees}};
571

  
572
  my $placeholders = join ', ', map {'?'} @for_employees_ids;
573
  my $query = <<SQL;
574
  SELECT login
575
  FROM employee
576
  WHERE id in ($placeholders)
577
SQL
578

  
579
  my $dbh = $employee->dbh;
580
  my $hash_key = 'login';
581
  my $hashref = $dbh->selectall_hashref(
582
    $query, $hash_key, undef, @for_employees_ids
583
  );
584
  my @logins = keys %$hashref;
585

  
586
  foreach my $login (@logins) {
587
    my %recipient  = $main::auth->read_user(
588
      login => conv_i($login),
589
    );
590

  
591
    if (!$recipient{follow_up_notify_by_email} || !$recipient{email}) {
592
      next;
593
    }
594

  
595
    my %template_params = (
596
      follow_up_subject => $params{subject},
597
      follow_up_body    => $params{body},
598
      follow_up_date    => $params{follow_up_date},
599
      creator_name      => $employee->name  || $::form->{login},
600
      recipient_name    => $recipient{name} || $recipient{login},
601
    );
602

  
603
    my $template = Template->new({ENCODING    => 'utf8'});
604

  
605
    my $body_file = $notify_cfg->{email_template};
606
    my $content_type   = $body_file =~ m/.html$/ ? 'text/html' : 'text/plain';
607

  
608
    my $message;
609
    $template->process($body_file, \%template_params, \$message)
610
    || die $template->error;
611

  
612
    my $param_form = Form->new();
613
    $param_form->{$_} = $template_params{$_} for keys %template_params;
614

  
615
    my $mail              = Mailer->new();
616
    $mail->{from}         = $notify_cfg->{email_from};
617
    $mail->{to}           = $recipient{email};
618
    $mail->{subject}      = SL::Template::Simple->new(form => $param_form)
619
                              ->substitute_vars($notify_cfg->{email_subject});
620
    $mail->{content_type} = $content_type;
621
    $mail->{message}      = $message;
622
    $mail->{charset}      = 'UTF-8';
623

  
624
    $mail->send();
625
  }
626

  
627
  $main::lxdebug->leave_sub();
628
}
629

  
548 630
1;

Auch abrufbar als: Unified diff