2 # Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4::MarcModificationTemplates;
31 my $op = $cgi->param('op');
32 my $template_id = $cgi->param('template_id');
34 my ($template, $loggedinuser, $cookie)
35 = get_template_and_user({template_name => "tools/marc_modification_templates.tmpl",
39 flagsrequired => { tools => 'marc_modfication_templates' },
43 if ( $op eq "create_template" ) {
44 $template_id = '' unless $cgi->param('duplicate_current_template');
45 $template_id = AddModificationTemplate( $cgi->param('template_name'), $template_id );
47 } elsif ( $op eq "delete_template" ) {
49 DelModificationTemplate( $template_id );
52 } elsif ( $op eq "add_action" ) {
54 my $mmta_id = $cgi->param('mmta_id');
55 my $action = $cgi->param('action');
56 my $field_number = $cgi->param('field_number');
57 my $from_field = $cgi->param('from_field');
58 my $from_subfield = $cgi->param('from_subfield');
59 my $field_value = $cgi->param('field_value');
60 my $to_field = $cgi->param('to_field');
61 my $to_subfield = $cgi->param('to_subfield');
62 my $to_regex = $cgi->param('to_regex');
63 my $conditional = $cgi->param('conditional');
64 my $conditional_field = $cgi->param('conditional_field');
65 my $conditional_subfield = $cgi->param('conditional_subfield');
66 my $conditional_comparison = $cgi->param('conditional_comparison');
67 my $conditional_value = $cgi->param('conditional_value');
68 my $conditional_regex = $cgi->param('conditional_regex') eq 'on';
69 my $description = $cgi->param('description');
72 AddModificationTemplateAction(
84 $conditional_subfield,
85 $conditional_comparison,
91 ModModificationTemplateAction(
103 $conditional_subfield,
104 $conditional_comparison,
112 } elsif ( $op eq "delete_action" ) {
113 DelModificationTemplateAction( $cgi->param('mmta_id') );
115 } elsif ( $op eq "move_action" ) {
117 MoveModificationTemplateAction( $cgi->param('mmta_id'), $cgi->param('where') );
121 my @templates = GetModificationTemplates( $template_id );
123 unless ( $template_id ) {
124 $template_id = $templates[0]->{'template_id'};
125 @templates = GetModificationTemplates( $template_id );
128 my @actions = GetModificationTemplateActions( $template_id );
129 foreach my $action ( @actions ) {
130 $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
131 $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
132 $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
133 $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
135 $action->{'conditional_if'} = ( $action->{'conditional'} eq 'if' );
136 $action->{'conditional_unless'} = ( $action->{'conditional'} eq 'unless' );
138 $action->{'conditional_comparison_exists'} = ( $action->{'conditional_comparison'} eq 'exists' );
139 $action->{'conditional_comparison_not_exists'} = ( $action->{'conditional_comparison'} eq 'not_exists' );
140 $action->{'conditional_comparison_equals'} = ( $action->{'conditional_comparison'} eq 'equals' );
141 $action->{'conditional_comparison_not_equals'} = ( $action->{'conditional_comparison'} eq 'not_equals' );
145 TemplatesLoop => \@templates,
146 ActionsLoop => \@actions,
148 template_id => $template_id,
151 output_html_with_http_headers $cgi, $cookie, $template->output;