+ if (($::form->{use_templates} eq 'existing') && ($self->defaults->templates !~ m:^templates/[^/]+$:)) {
+ push @errors, t8('You must select existing print templates or create a new set.');
+
+ } elsif ($::form->{use_templates} eq 'new') {
+ if (!$::form->{new_templates}) {
+ push @errors, t8('You must enter a name for your new print templates.');
+ } elsif (-d "templates/" . $::form->{new_templates}) {
+ push @errors, t8('A directory with the name for the new print templates exists already.');
+ } elsif (! -d "templates/print/" . $::form->{new_master_templates}) {
+ push @errors, t8('The master templates where not found.');
+ }
+ }
+
+ # Show form again if there were any errors. Nothing's been changed
+ # yet in the database.
+ if (@errors) {
+ flash('error', @errors);
+ return $self->edit_form;
+ }
+
+ # Save currencies. As the names must be unique we cannot simply save
+ # them as they are -- the user might want to swap to names. So make
+ # them unique first and assign the actual names in a second step.
+ my %currency_names_by_id = map { ($_->id => $_->name) } @{ $self->all_currencies };
+ $_->update_attributes(name => '__039519735__' . $_->{id}) for @{ $self->all_currencies };
+ $_->update_attributes(name => $currency_names_by_id{ $_->{id} }) for @{ $self->all_currencies };
+
+ # Create new currency if required
+ my $new_currency;
+ if ($::form->{new_currency}) {
+ $new_currency = SL::DB::Currency->new(name => $::form->{new_currency});
+ $new_currency->save;
+ }