View | Details | Raw Unified | Return to bug 18269
Collapse All | Expand All

(-)a/C4/Biblio.pm (-63 lines)
Lines 72-80 BEGIN { Link Here
72
      GetBiblionumberFromItemnumber
72
      GetBiblionumberFromItemnumber
73
73
74
      &GetRecordValue
74
      &GetRecordValue
75
      &GetFieldMapping
76
      &SetFieldMapping
77
      &DeleteFieldMapping
78
75
79
      &GetISBDView
76
      &GetISBDView
80
77
Lines 685-750 sub GetRecordValue { Link Here
685
    return \@result;
682
    return \@result;
686
}
683
}
687
684
688
=head2 SetFieldMapping
689
690
  SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
691
692
Set a Field to MARC mapping value, if it already exists we don't add a new one.
693
694
=cut
695
696
sub SetFieldMapping {
697
    my ( $framework, $field, $fieldcode, $subfieldcode ) = @_;
698
    my $dbh = C4::Context->dbh;
699
700
    my $sth = $dbh->prepare('SELECT * FROM fieldmapping WHERE fieldcode = ? AND subfieldcode = ? AND frameworkcode = ? AND field = ?');
701
    $sth->execute( $fieldcode, $subfieldcode, $framework, $field );
702
    if ( not $sth->fetchrow_hashref ) {
703
        my @args;
704
        $sth = $dbh->prepare('INSERT INTO fieldmapping (fieldcode, subfieldcode, frameworkcode, field) VALUES(?,?,?,?)');
705
706
        $sth->execute( $fieldcode, $subfieldcode, $framework, $field );
707
    }
708
}
709
710
=head2 DeleteFieldMapping
711
712
  DeleteFieldMapping($id);
713
714
Delete a field mapping from an $id.
715
716
=cut
717
718
sub DeleteFieldMapping {
719
    my ($id) = @_;
720
    my $dbh = C4::Context->dbh;
721
722
    my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?');
723
    $sth->execute($id);
724
}
725
726
=head2 GetFieldMapping
727
728
  GetFieldMapping($frameworkcode);
729
730
Get all field mappings for a specified frameworkcode
731
732
=cut
733
734
sub GetFieldMapping {
735
    my ($framework) = @_;
736
    my $dbh = C4::Context->dbh;
737
738
    my $sth = $dbh->prepare('SELECT * FROM fieldmapping where frameworkcode = ?');
739
    $sth->execute($framework);
740
741
    my @return;
742
    while ( my $row = $sth->fetchrow_hashref ) {
743
        push @return, $row;
744
    }
745
    return \@return;
746
}
747
748
=head2 GetBiblioData
685
=head2 GetBiblioData
749
686
750
  $data = &GetBiblioData($biblionumber);
687
  $data = &GetBiblioData($biblionumber);
(-)a/admin/fieldmapping.pl (-22 / +24 lines)
Lines 1-5 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
# Copyright 2009 SARL BibLibre
2
# Copyright 2009 SARL BibLibre
3
# Copyright 2017 Koha Development Team
3
#
4
#
4
# This file is part of Koha.
5
# This file is part of Koha.
5
#
6
#
Lines 16-30 Link Here
16
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
19
use strict;
20
use Modern::Perl;
20
use warnings;
21
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
22
use C4::Auth;
22
use C4::Auth;
23
use C4::Biblio;
23
use C4::Biblio;
24
use C4::Koha;
25
use C4::Output;
24
use C4::Output;
26
25
27
use Koha::BiblioFrameworks;
26
use Koha::BiblioFrameworks;
27
use Koha::FieldMappings;
28
28
29
my $query = new CGI;
29
my $query = new CGI;
30
30
Lines 35-68 my $subfieldcode = $query->param('marcsubfield'); Link Here
35
my $op            = $query->param('op') || q{};
35
my $op            = $query->param('op') || q{};
36
my $id            = $query->param('id');
36
my $id            = $query->param('id');
37
37
38
my ($template, $loggedinuser, $cookie)
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
    = get_template_and_user({template_name => "admin/fieldmapping.tt",
39
    {
40
			     query => $query,
40
        template_name   => "admin/fieldmapping.tt",
41
			     type => "intranet",
41
        query           => $query,
42
			     authnotrequired => 0,
42
        type            => "intranet",
43
                 flagsrequired => {parameters => 'parameters_remaining_permissions'},
43
        authnotrequired => 0,
44
			     debug => 1,
44
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
45
			     });
45
        debug           => 1,
46
46
    }
47
if($op eq "delete" and $id){
47
);
48
    DeleteFieldMapping($id);
49
    print $query->redirect("/cgi-bin/koha/admin/fieldmapping.pl?framework=".$frameworkcode);
50
    exit;
51
}
52
48
53
# insert operation
49
# FIXME Add exceptions
54
if($field and $fieldcode){
50
if ( $op eq "delete" and $id ) {
55
    SetFieldMapping($frameworkcode, $field, $fieldcode, $subfieldcode);
51
    Koha::FieldMappings->find($id)->delete;
52
} elsif ( $field and $fieldcode ) {
53
    my $params = { frameworkcode => $frameworkcode, field => $field, fieldcode => $fieldcode, subfieldcode => $subfieldcode };
54
    my $exists = Koha::FieldMappings->search( $params )->count;;
55
    unless ( $exists ) {
56
        Koha::FieldMapping->new( $params )->store;
57
    }
56
}
58
}
57
59
58
my $fieldloop = GetFieldMapping($frameworkcode);
60
my $fields = Koha::FieldMappings->search({ frameworkcode => $frameworkcode });
59
61
60
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
62
my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
61
my $framework  = $frameworks->search( { frameworkcode => $frameworkcode } )->next;
63
my $framework  = $frameworks->search( { frameworkcode => $frameworkcode } )->next;
62
$template->param(
64
$template->param(
63
    frameworks => $frameworks,
65
    frameworks => $frameworks,
64
    framework  => $framework,
66
    framework  => $framework,
65
    fields     => $fieldloop,
67
    fields     => $fields,
66
);
68
);
67
69
68
output_html_with_http_headers $query, $cookie, $template->output;
70
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/fieldmapping.tt (-5 / +6 lines)
Lines 24-32 $(document).ready(function() { Link Here
24
	<div id="yui-main">
24
	<div id="yui-main">
25
		<div class="yui-b">
25
		<div class="yui-b">
26
            <h2>Keyword to MARC mapping</h2>
26
            <h2>Keyword to MARC mapping</h2>
27
			[% UNLESS ( fields ) %]
27
            [% UNLESS ( fields.count ) %]
28
            <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div>
28
                <div class="dialog message"><p>There are no mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework. </p></div>
29
			[% END %]
29
            [% END %]
30
			<form method="get" action="/cgi-bin/koha/admin/fieldmapping.pl" id="selectframework">
30
			<form method="get" action="/cgi-bin/koha/admin/fieldmapping.pl" id="selectframework">
31
				<label for="framework">Framework:</label>
31
				<label for="framework">Framework:</label>
32
                <select name="framework" id="framework" style="width:20em;">
32
                <select name="framework" id="framework" style="width:20em;">
Lines 58-64 $(document).ready(function() { Link Here
58
				</fieldset>
58
				</fieldset>
59
			</form>
59
			</form>
60
60
61
				[% IF ( fields ) %]<table>
61
                [% IF ( fields.count ) %]
62
                    <table>
62
                    <caption>Mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework</caption>
63
                    <caption>Mappings for the [% IF framework.frameworktext %]<em>[% framework.frameworktext %]</em>[% ELSE %]default[% END %] framework</caption>
63
									<tr>
64
									<tr>
64
										<th>Field</th>
65
										<th>Field</th>
Lines 71-77 $(document).ready(function() { Link Here
71
										<td>[% field.field %]</td>
72
										<td>[% field.field %]</td>
72
										<td>[% field.fieldcode %]</td>
73
										<td>[% field.fieldcode %]</td>
73
										<td>[% field.subfieldcode %]</td>
74
										<td>[% field.subfieldcode %]</td>
74
                                        <td><a class="btn btn-default btn-xs" href="?op=delete&amp;id=[% field.id %]&amp;framework=[% field.framework %]"><i class="fa fa-trash"></i> Delete</a></td>
75
                                        <td><a class="btn btn-default btn-xs" href="?op=delete&amp;id=[% field.id %]&amp;framework=[% field.frameworkcode %]"><i class="fa fa-trash"></i> Delete</a></td>
75
									</tr>
76
									</tr>
76
									[% END %]
77
									[% END %]
77
								</table>[% END %]
78
								</table>[% END %]
(-)a/t/db_dependent/Charset.t (-2 / +1 lines)
Lines 2-8 use Modern::Perl; Link Here
2
use Test::More tests => 4;
2
use Test::More tests => 4;
3
use MARC::Record;
3
use MARC::Record;
4
4
5
use C4::Biblio qw( AddBiblio SetFieldMapping GetMarcFromKohaField );
5
use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
6
use C4::Context;
6
use C4::Context;
7
use C4::Charset qw( SanitizeRecord );
7
use C4::Charset qw( SanitizeRecord );
8
8
9
- 

Return to bug 18269