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 686-751 sub GetRecordValue { Link Here
686
    return \@result;
683
    return \@result;
687
}
684
}
688
685
689
=head2 SetFieldMapping
690
691
  SetFieldMapping($framework, $field, $fieldcode, $subfieldcode);
692
693
Set a Field to MARC mapping value, if it already exists we don't add a new one.
694
695
=cut
696
697
sub SetFieldMapping {
698
    my ( $framework, $field, $fieldcode, $subfieldcode ) = @_;
699
    my $dbh = C4::Context->dbh;
700
701
    my $sth = $dbh->prepare('SELECT * FROM fieldmapping WHERE fieldcode = ? AND subfieldcode = ? AND frameworkcode = ? AND field = ?');
702
    $sth->execute( $fieldcode, $subfieldcode, $framework, $field );
703
    if ( not $sth->fetchrow_hashref ) {
704
        my @args;
705
        $sth = $dbh->prepare('INSERT INTO fieldmapping (fieldcode, subfieldcode, frameworkcode, field) VALUES(?,?,?,?)');
706
707
        $sth->execute( $fieldcode, $subfieldcode, $framework, $field );
708
    }
709
}
710
711
=head2 DeleteFieldMapping
712
713
  DeleteFieldMapping($id);
714
715
Delete a field mapping from an $id.
716
717
=cut
718
719
sub DeleteFieldMapping {
720
    my ($id) = @_;
721
    my $dbh = C4::Context->dbh;
722
723
    my $sth = $dbh->prepare('DELETE FROM fieldmapping WHERE id = ?');
724
    $sth->execute($id);
725
}
726
727
=head2 GetFieldMapping
728
729
  GetFieldMapping($frameworkcode);
730
731
Get all field mappings for a specified frameworkcode
732
733
=cut
734
735
sub GetFieldMapping {
736
    my ($framework) = @_;
737
    my $dbh = C4::Context->dbh;
738
739
    my $sth = $dbh->prepare('SELECT * FROM fieldmapping where frameworkcode = ?');
740
    $sth->execute($framework);
741
742
    my @return;
743
    while ( my $row = $sth->fetchrow_hashref ) {
744
        push @return, $row;
745
    }
746
    return \@return;
747
}
748
749
=head2 GetBiblioData
686
=head2 GetBiblioData
750
687
751
  $data = &GetBiblioData($biblionumber);
688
  $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