Allow placeholders to be removed in signature templates, if the corresponding value is empty

tags/ipasserelle-base-0.2.65-1
Daniel Berteaud 11 years ago
parent ce9c471886
commit 343f38a889
  1. 68
      root/etc/e-smith/events/actions/generate-email-sign

@ -83,50 +83,64 @@ foreach my $user (@users){
my $first = $user->prop('FirstName') || '';
my $last = $user->prop('LastName') || '';
my $mail = $user->prop('PreferredEmail') || "$userName\@$domain";
my $tel = $user->prop('Phone') || $defTel;
my $tel = $user->prop('Phone') || '';
my $mob = $user->prop('Mobile') || '';
my $fax = $user->prop('Fax') || '';
my $func = $user->prop('Function1') || '';
my $func2 = $user->prop('Function2') || '';
my $func3 = $user->prop('Function3') || '';
my $func4 = $user->prop('Function4') || '';
my $comp = $user->prop('Company') || $defComp;
my $dep = $user->prop('Dept') || $defDep;
my $comp = $user->prop('Company') || '';
my $dep = $user->prop('Dept') || '';
my $postalcode = $user->prop('PostalCode') || '';
my $street = $user->prop('Street') || $defStreet;
my $city = $user->prop('City') || $defCity;
my $street = $user->prop('Street') || '';
my $city = $user->prop('City') || '';
my $url = $user->prop('Url') || '';
my $template = $user->prop('SignatureTemplate') || "email";
my $addr = "$street $postalcode $city";
$tel = ($tel eq '') ? '':"Tél.: $tel";
$mob = ($mob eq '') ? '':"Mobile: $mob";
$fax = ($fax eq '') ? '':"Fax: $fax";
$url = ($url eq '') ? '':"Web: $url";
foreach my $ext (qw/txt html/){
open(R, '<', "/home/e-smith/files/shares/tools/files/signatures/templates/$template.$ext") ||
next;
open(W, '>', "$dir/email.$ext") || die "Error opening output file $dir/email.$ext\n";
my $src = '';
$src .= $_ foreach (<R>);
# Delete if value is empty
$src =~ s/__START_NOM__.*__END_NOM__//smg if ($last eq '');
$src =~ s/__START_PRENOM__.*__END_PRENOM__//smg if ($first eq '');
$src =~ s/__START_EMAIL__.*__END_EMAIL__//smg if ($mail eq '');
$src =~ s/__START_TEL__.*__END_TEL__//smg if ($tel eq '');
$src =~ s/__START_MOBILE__.*__END_MOBILE__//smg if ($mob eq '');
$src =~ s/__START_FAX__.*__END_FAX__//smg if ($fax eq '');
$src =~ s/__START_FONCTION__.*__END_FONCTION__//smg if ($func eq '');
$src =~ s/__START_FONCTION2__.*__END_FONCTION2__//smg if ($func2 eq '');
$src =~ s/__START_FONCTION3__.*__END_FONCTION3__//smg if ($func3 eq '');
$src =~ s/__START_FONCTION4__.*__END_FONCTION4__//smg if ($func4 eq '');
$src =~ s/__START_ENTREPRISE__.*__END_ENTREPRISE__//smg if ($comp eq '');
$src =~ s/__START_ADRESSE__.*__END_ADRESSE__//smg if ($addr eq '');
$src =~ s/__START_URL__.*__END_URL__//smg if ($url eq '');
$src =~ s/__NOM__/$last/g;
$src =~ s/__PRENOM__/$first/g;
$src =~ s/__EMAIL__/$mail/g;
$src =~ s/__TEL__/$tel/g;
$src =~ s/__MOBILE__/$mob/g;
$src =~ s/__FAX__/$fax/g;
$src =~ s/__FONCTION__/$func/g;
$src =~ s/__FONCTION2__/$func2/g;
$src =~ s/__FONCTION3__/$func3/g;
$src =~ s/__FONCTION4__/$func4/g;
$src =~ s/__SERVICE__/$dep/g;
$src =~ s/__ENTREPRISE__/$comp/g;
$src =~ s/__ADRESSE__/$addr/g;
$src =~ s/__URL__/$url/g;
# Now remove any remaining __START_ and __END_ tags
$src =~ s/__(START|END)_\w+__//g;
print W $src;
foreach (<R>){
s/__NOM__/$last/g;
s/__PRENOM__/$first/g;
s/__EMAIL__/$mail/g;
s/__TEL__/$tel/g;
s/__MOBILE__/$mob/g;
s/__FAX__/$fax/g;
s/__FONCTION__/$func/g;
s/__FONCTION2__/$func2/g;
s/__FONCTION3__/$func3/g;
s/__FONCTION4__/$func4/g;
s/__SERVICE__/$dep/g;
s/__ENTREPRISE__/$comp/g;
s/__ADRESSE__/$addr/g;
s/__URL__/$url/g;
print W $_;
}
close R;
close W;
}

Loading…
Cancel
Save