@@ -, +, @@ --- .../intranet-tmpl/prog/en/modules/tools/letter.tt | 50 ++++++++++---- tools/letter.pl | 72 +++++++++++--------- 2 files changed, 77 insertions(+), 45 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt @@ -1,5 +1,5 @@ [% INCLUDE 'doc-head-open.inc' %] -Koha › Tools › Notices[% IF ( add_form ) %][% IF ( modify ) %] › Modify notice[% ELSE %] › Add notice[% END %][% END %][% IF ( add_validate ) %] › Notice added[% END %][% IF ( delete_confirm ) %] › Confirm deletion[% END %] +Koha › Tools › Notices[% IF ( add_form or copy_form ) %][% IF ( modify ) %] › Modify notice[% ELSE %] › Add notice[% END %][% END %][% IF ( add_validate or copy_validate) %] › Notice added[% END %][% IF ( delete_confirm ) %] › Confirm deletion[% END %] [% INCLUDE 'doc-head-close.inc' %] [% INCLUDE 'datatables.inc' %] @@ -24,7 +24,7 @@ $(document).ready(function() { }); [% END %] }); -[% IF ( add_form ) %] +[% IF add_form or copy_form %] function cancel(f) { $('#op').val(""); @@ -112,14 +112,18 @@ $(document).ready(function() { [% INCLUDE 'header.inc' %] [% INCLUDE 'letters-search.inc' %] - + -[% IF ( add_form ) %]
[% ELSE %]
[% END %] +[% IF add_form or copy_form %]
[% ELSE %]
[% END %]
+ [% IF already_exists %] +
This code already exists. Please change it.
+ [% END %] + [% IF ( no_op_set ) %]

Notices and Slips

@@ -180,7 +184,7 @@ $(document).ready(function() { [% IF !independant_branch || !lette.branchcode %] - + @@ -219,10 +223,15 @@ $(document).ready(function() { [% END %] -[% IF ( add_form ) %] +[% IF add_form or copy_form %]

[% IF ( modify ) %]Modify notice[% ELSE %]Add notice[% END %]

- + [% IF add_form %] + + [% ELSE %] + + [% END %] + [% IF ( modify ) %] @@ -230,7 +239,7 @@ $(document).ready(function() { [% END %]
- + [% IF independant_branch %] [% ELSE %] @@ -248,7 +257,11 @@ $(document).ready(function() {
  • - [% IF ( modify ) %][% END %] + [% IF adding %] + + [% END %] [% IF ( catalogue ) %] [% ELSE %] @@ -291,9 +304,18 @@ $(document).ready(function() { [% END %]
  • -
  • - Code:[% IF ( adding ) %][% ELSE %][% code %][% END %] -
  • +
  • + Code: + [% IF adding or copying %] + + [% IF copying %] + You must change this code to reflect the copy. + [% END %] + [% ELSE %] + [% code %] + [% END %] + +
  • @@ -328,7 +350,7 @@ $(document).ready(function() { [% END %] -[% IF ( add_validate ) %] +[% IF ( add_validate or copy_validate) %] Data recorded
    @@ -377,7 +399,7 @@ $(document).ready(function() {
    -[% UNLESS ( add_form ) %] +[% UNLESS add_form or copy_form %]
    [% INCLUDE 'tools-menu.inc' %]
    --- a/tools/letter.pl +++ a/tools/letter.pl @@ -76,7 +76,12 @@ sub letter_exists { my $letter = $dbh->selectrow_hashref("SELECT * $sql", undef, @$args); return $letter; } - +sub lettercode_exists { + my ( $letter_code ) = @_; + my $dbh = C4::Context->dbh; + my ( $exist ) = $dbh->selectrow_array("SELECT count(*) FROM letter where code=?", undef, $letter_code); + return $exist; +} # $protected_letters = protected_letters() # - return a hashref of letter_codes representing letters that should never be deleted sub protected_letters { @@ -119,17 +124,37 @@ $template->param( action => $script_name ); -if ($op eq 'copy') { - add_copy(); - $op = 'add_form'; +if ( $op eq 'add_validate' or $op eq 'copy_validate' ) { + my $added = add_validate(); + unless ( $added ) { + if ( $op eq 'add_validate' ) { + $op = 'add_form'; + } else { + $op = 'copy_form'; + $code = $input->param('oldcode'); + } + $template->param( already_exists => 1 ); + } + else { + $op = q{}; # next operation is to return to default screen + } } - -if ($op eq 'add_form') { - add_form($branchcode, $module, $code); +if ($op eq 'copy_form') { + my $oldbranchcode = $input->param('oldbranchcode') || q||; + my $branchcode = $input->param('branchcode') || q||; + my $oldcode = $input->param('oldcode') || $input->param('code'); + add_form($oldbranchcode, $module, $code); + $template->param( + oldbranchcode => $oldbranchcode, + branchcode => $branchcode, + branchloop => _branchloop($branchcode), + oldcode => $oldcode, + copying => 1, + modify => 0, + ); } -elsif ( $op eq 'add_validate' ) { - add_validate(); - $op = q{}; # next operation is to return to default screen +elsif ( $op eq 'add_form' ) { + add_form($branchcode, $module, $code); } elsif ( $op eq 'delete_confirm' ) { delete_confirm($branchcode, $module, $code); @@ -227,7 +252,6 @@ sub add_form { sub add_validate { my $dbh = C4::Context->dbh; - my $oldbranchcode = $input->param('oldbranchcode'); my $branchcode = $input->param('branchcode') || ''; my $module = $input->param('module'); my $oldmodule = $input->param('oldmodule'); @@ -236,12 +260,15 @@ sub add_validate { my $is_html = $input->param('is_html'); my $title = $input->param('title'); my $content = $input->param('content'); - if (letter_exists($oldbranchcode,$oldmodule, $code)) { + if ( lettercode_exists( $code ) ) { + return 0; + } + elsif (letter_exists($branchcode,$oldmodule, $code)) { $dbh->do( q{UPDATE letter SET branchcode = ?, module = ?, name = ?, is_html = ?, title = ?, content = ? WHERE branchcode = ? AND module = ? AND code = ?}, undef, $branchcode, $module, $name, $is_html || 0, $title, $content, - $oldbranchcode, $oldmodule, $code + $branchcode, $oldmodule, $code ); } else { $dbh->do( @@ -252,24 +279,7 @@ sub add_validate { } # set up default display default_display($branchcode); -} - -sub add_copy { - my $dbh = C4::Context->dbh; - my $oldbranchcode = $input->param('oldbranchcode'); - my $branchcode = $input->param('branchcode'); - my $module = $input->param('module'); - my $code = $input->param('code'); - - return if letter_exists($branchcode,$module, $code); - - my $old_letter = letter_exists($oldbranchcode,$module, $code); - - $dbh->do( - q{INSERT INTO letter (branchcode,module,code,name,is_html,title,content) VALUES (?,?,?,?,?,?,?)}, - undef, - $branchcode, $module, $code, $old_letter->{name}, $old_letter->{is_html}, $old_letter->{title}, $old_letter->{content} - ); + return 1; } sub delete_confirm { --