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

(-)a/C4/Items.pm (-5 / +4 lines)
Lines 3006-3018 sub PrepareItemrecordDisplay { Link Here
3006
3006
3007
                        #----- itemtypes
3007
                        #----- itemtypes
3008
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
3008
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
3009
                        my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
3009
                        my $itemtypes = GetItemTypes( style => 'array' );
3010
                        $sth->execute;
3011
                        push @authorised_values, ""
3010
                        push @authorised_values, ""
3012
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
3011
                          unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
3013
                        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
3012
                        for my $itemtype ( @$itemtypes ) {
3014
                            push @authorised_values, $itemtype;
3013
                            push @authorised_values, $itemtype->{itemtype};
3015
                            $authorised_lib{$itemtype} = $description;
3014
                            $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
3016
                        }
3015
                        }
3017
                        #---- class_sources
3016
                        #---- class_sources
3018
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
3017
                    } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
(-)a/C4/Koha.pm (-9 / +40 lines)
Lines 254-268 sub GetItemTypes { Link Here
254
    my ( %params ) = @_;
254
    my ( %params ) = @_;
255
    my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash';
255
    my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash';
256
256
257
    my $language = C4::Languages::getlanguage();
257
    # returns a reference to a hash of references to itemtypes...
258
    # returns a reference to a hash of references to itemtypes...
258
    my %itemtypes;
259
    my %itemtypes;
259
    my $dbh   = C4::Context->dbh;
260
    my $dbh   = C4::Context->dbh;
260
    my $query = qq|
261
    my $query = q|
261
        SELECT *
262
        SELECT
263
               itemtypes.itemtype,
264
               itemtypes.description,
265
               itemtypes.rentalcharge,
266
               itemtypes.notforloan,
267
               itemtypes.imageurl,
268
               itemtypes.summary,
269
               itemtypes.checkinmsg,
270
               itemtypes.checkinmsgtype,
271
               itemtypes.sip_media_type,
272
               COALESCE( localization.translation, itemtypes.description ) AS translated_description
262
        FROM   itemtypes
273
        FROM   itemtypes
274
        LEFT JOIN localization ON itemtypes.itemtype = localization.code
275
            AND localization.entity = 'itemtypes'
276
            AND localization.lang = ?
277
        ORDER BY itemtype
263
    |;
278
    |;
264
    my $sth = $dbh->prepare($query);
279
    my $sth = $dbh->prepare($query);
265
    $sth->execute;
280
    $sth->execute( $language );
266
281
267
    if ( $style eq 'hash' ) {
282
    if ( $style eq 'hash' ) {
268
        while ( my $IT = $sth->fetchrow_hashref ) {
283
        while ( my $IT = $sth->fetchrow_hashref ) {
Lines 486-499 Defaults to intranet. Link Here
486
501
487
sub getitemtypeinfo {
502
sub getitemtypeinfo {
488
    my ($itemtype, $interface) = @_;
503
    my ($itemtype, $interface) = @_;
489
    my $dbh        = C4::Context->dbh;
504
    my $dbh      = C4::Context->dbh;
490
    my $sth        = $dbh->prepare("select * from itemtypes where itemtype=?");
505
    my $language = C4::Languages::getlanguage();
491
    $sth->execute($itemtype);
506
    my $it = $dbh->selectrow_hashref(q|
492
    my $res = $sth->fetchrow_hashref;
507
        SELECT
508
               itemtypes.itemtype,
509
               itemtypes.description,
510
               itemtypes.rentalcharge,
511
               itemtypes.notforloan,
512
               itemtypes.imageurl,
513
               itemtypes.summary,
514
               itemtypes.checkinmsg,
515
               itemtypes.checkinmsgtype,
516
               itemtypes.sip_media_type,
517
               COALESCE( localization.translation, itemtypes.description ) AS translated_description
518
        FROM   itemtypes
519
        LEFT JOIN localization ON itemtypes.itemtype = localization.code
520
            AND localization.entity = 'itemtypes'
521
            AND localization.lang = ?
522
        WHERE itemtypes.itemtype = ?
523
    |, undef, $language, $itemtype );
493
524
494
    $res->{imageurl} = getitemtypeimagelocation( ( ( defined $interface && $interface eq 'opac' ) ? 'opac' : 'intranet' ), $res->{imageurl} );
525
    $it->{imageurl} = getitemtypeimagelocation( ( ( defined $interface && $interface eq 'opac' ) ? 'opac' : 'intranet' ), $it->{imageurl} );
495
526
496
    return $res;
527
    return $it;
497
}
528
}
498
529
499
=head2 getitemtypeimagedir
530
=head2 getitemtypeimagedir
(-)a/C4/Search.pm (-9 / +3 lines)
Lines 1874-1888 sub searchResults { Link Here
1874
    #Build itemtype hash
1874
    #Build itemtype hash
1875
    #find itemtype & itemtype image
1875
    #find itemtype & itemtype image
1876
    my %itemtypes;
1876
    my %itemtypes;
1877
    $bsth =
1877
    my $itemtypes = GetItemTypes( style => 'array' );
1878
      $dbh->prepare(
1878
    for my $itemtype ( @$itemtypes ) {
1879
        "SELECT itemtype,description,imageurl,summary,notforloan FROM itemtypes"
1879
        $itemtypes{ $itemtype->{itemtype} } = $itemtype;
1880
      );
1881
    $bsth->execute();
1882
    while ( my $bdata = $bsth->fetchrow_hashref ) {
1883
		foreach (qw(description imageurl summary notforloan)) {
1884
        	$itemtypes{ $bdata->{'itemtype'} }->{$_} = $bdata->{$_};
1885
		}
1886
    }
1880
    }
1887
1881
1888
    #search item field code
1882
    #search item field code
(-)a/Koha/Localization.pm (+28 lines)
Line 0 Link Here
1
package Koha::Localization;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
22
use base qw(Koha::Object);
23
24
sub type {
25
    return 'Localization';
26
}
27
28
1;
(-)a/Koha/Localizations.pm (+34 lines)
Line 0 Link Here
1
package Koha::Localizations;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Koha::Database;
21
22
use Koha::Localization;
23
24
use base qw(Koha::Objects);
25
26
sub type {
27
    return 'Localization';
28
}
29
30
sub object_class {
31
    return 'Koha::Localization';
32
}
33
34
1;
(-)a/Koha/Template/Plugin/ItemTypes.pm (-5 / +2 lines)
Lines 27-37 use C4::Koha; Link Here
27
sub GetDescription {
27
sub GetDescription {
28
    my ( $self, $itemtype ) = @_;
28
    my ( $self, $itemtype ) = @_;
29
29
30
    my $query = "SELECT description FROM itemtypes WHERE itemtype = ?";
30
    my $itemtype = C4::Koha::getitemtypeinfo( $itemtype );
31
    my $sth   = C4::Context->dbh->prepare($query);
31
    return $itemtype->{translated_description};
32
    $sth->execute($itemtype);
33
    my $d = $sth->fetchrow_hashref();
34
    return $d->{description}
35
32
36
}
33
}
37
34
(-)a/admin/itemtypes.pl (-15 / +35 lines)
Lines 52-69 use C4::Context; Link Here
52
use C4::Auth;
52
use C4::Auth;
53
use C4::Output;
53
use C4::Output;
54
54
55
sub StringSearch {
55
use Koha::Localizations;
56
    my ( $searchstring, $type ) = @_;
57
    my $dbh = C4::Context->dbh;
58
    $searchstring =~ s/\'/\\\'/g;
59
    my @data = split( ' ', $searchstring );
60
    my $sth = $dbh->prepare(
61
        "SELECT * FROM itemtypes WHERE (description LIKE ?) ORDER BY itemtype"
62
	);
63
    $sth->execute("$data[0]%");
64
    return $sth->fetchall_arrayref({});		# return ref-to-array of ref-to-hashes
65
								# like [ fetchrow_hashref(), fetchrow_hashref() ... ]
66
}
67
56
68
my $input       = new CGI;
57
my $input       = new CGI;
69
my $searchfield = $input->param('description');
58
my $searchfield = $input->param('description');
Lines 99-106 if ( $op eq 'add_form' ) { Link Here
99
    #---- if primkey exists, it's a modify action, so read values to modify...
88
    #---- if primkey exists, it's a modify action, so read values to modify...
100
    my $data;
89
    my $data;
101
    if ($itemtype) {
90
    if ($itemtype) {
102
        my $sth = $dbh->prepare("select * from itemtypes where itemtype=?");
91
        my $sth = $dbh->prepare(q|
103
        $sth->execute($itemtype);
92
            SELECT
93
                   itemtypes.itemtype,
94
                   itemtypes.description,
95
                   itemtypes.rentalcharge,
96
                   itemtypes.notforloan,
97
                   itemtypes.imageurl,
98
                   itemtypes.summary,
99
                   itemtypes.checkinmsg,
100
                   itemtypes.checkinmsgtype,
101
                   itemtypes.sip_media_type,
102
                   COALESCE( localization.translation, itemtypes.description ) AS translated_description
103
            FROM   itemtypes
104
            LEFT JOIN localization ON itemtypes.itemtype = localization.code
105
                AND localization.entity='itemtypes'
106
                AND localization.lang = ?
107
            WHERE itemtype = ?
108
        |);
109
        my $language = C4::Languages::getlanguage();
110
        $sth->execute($language, $itemtype);
104
        $data = $sth->fetchrow_hashref;
111
        $data = $sth->fetchrow_hashref;
105
    }
112
    }
106
113
Lines 249-259 elsif ( $op eq 'delete_confirmed' ) { Link Here
249
}
256
}
250
257
251
if ( $op eq 'list' ) {
258
if ( $op eq 'list' ) {
252
    my ($results) = StringSearch( $searchfield, 'web' );
259
    my $results = C4::Koha::GetItemTypes( style => 'array' );
253
    my @loop;
260
    my @loop;
254
    foreach my $itemtype ( @{$results} ) {
261
    foreach my $itemtype ( @{$results} ) {
255
        $itemtype->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtype->{imageurl} );
262
        $itemtype->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtype->{imageurl} );
256
        $itemtype->{rentalcharge} = sprintf( '%.2f', $itemtype->{rentalcharge} );
263
        $itemtype->{rentalcharge} = sprintf( '%.2f', $itemtype->{rentalcharge} );
264
265
        my @translated_descriptions = Koha::Localizations->search(
266
            {   entity => 'itemtypes',
267
                code   => $itemtype->{itemtype},
268
            }
269
        );
270
        $itemtype->{translated_descriptions} = [ map {
271
            {
272
                lang => $_->lang,
273
                translation => $_->translation,
274
            }
275
        } @translated_descriptions ];
276
257
        push( @loop, $itemtype );
277
        push( @loop, $itemtype );
258
    }
278
    }
259
279
(-)a/admin/localization.pl (+64 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19
use Modern::Perl;
20
21
use C4::Auth;
22
use C4::Output;
23
24
use Koha::Localization;
25
use Koha::Localizations;
26
27
use CGI qw( -utf8 );
28
29
my $query = new CGI;
30
31
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
32
    {   template_name   => "admin/localization.tt",
33
        authnotrequired => 0,
34
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
35
        query           => $query,
36
        type            => "intranet",
37
        debug           => 1,
38
    }
39
);
40
41
my $entity = $query->param('entity');
42
my $code   = $query->param('code');
43
my $rs     = Koha::Localizations->search( { entity => $entity, code => $code } );
44
my @translations;
45
while ( my $s = $rs->next ) {
46
    push @translations,
47
      { id          => $s->localization_id,
48
        entity      => $s->entity,
49
        code        => $s->code,
50
        lang        => $s->lang,
51
        translation => $s->translation,
52
      };
53
}
54
55
my $translated_languages = C4::Languages::getTranslatedLanguages( 'intranet', C4::Context->preference('template') );
56
57
$template->param(
58
    translations => \@translations,
59
    languages    => $translated_languages,
60
    entity       => $entity,
61
    code         => $code,
62
);
63
64
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/authorities/authorities.pl (-11 / +5 lines)
Lines 83-105 sub build_authorized_values_list { Link Here
83
            push @authorised_values, $branchcode;
83
            push @authorised_values, $branchcode;
84
            $authorised_lib{$branchcode} = $branchname;
84
            $authorised_lib{$branchcode} = $branchname;
85
        }
85
        }
86
87
        #----- itemtypes
88
    }
86
    }
89
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
87
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
90
        my $sth =
91
        $dbh->prepare(
92
            "select itemtype,description from itemtypes order by description");
93
        $sth->execute;
94
        push @authorised_values, ""
88
        push @authorised_values, ""
95
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
89
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
96
            && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
90
            && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
97
        
91
98
        my $itemtype;
92
        my $itemtype;
99
        
93
        my $itemtypes = GetItemTypes( style => 'array' );
100
        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
94
        for my $itemtype ( @$itemtypes ) {
101
            push @authorised_values, $itemtype;
95
            push @authorised_values, $itemtype->{itemtype};
102
            $authorised_lib{$itemtype} = $description;
96
            $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
103
        }
97
        }
104
        $value = $itemtype unless ($value);
98
        $value = $itemtype unless ($value);
105
99
(-)a/catalogue/search.pl (-1 / +1 lines)
Lines 266-272 foreach my $advanced_srch_type (@advanced_search_types) { Link Here
266
	    my %row =(  number=>$cnt++,
266
	    my %row =(  number=>$cnt++,
267
		ccl => "$itype_or_itemtype,phr",
267
		ccl => "$itype_or_itemtype,phr",
268
                code => $thisitemtype,
268
                code => $thisitemtype,
269
                description => $itemtypes->{$thisitemtype}->{'description'},
269
                description => $itemtypes->{$thisitemtype}->{translated_description},
270
                imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ),
270
                imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ),
271
            );
271
            );
272
	    push @itypesloop, \%row;
272
	    push @itypesloop, \%row;
(-)a/cataloguing/addbiblio.pl (-12 / +5 lines)
Lines 184-209 sub build_authorized_values_list { Link Here
184
            $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
184
            $authorised_lib{$thisbranch} = $branches->{$thisbranch}->{'branchname'};
185
        }
185
        }
186
186
187
        #----- itemtypes
188
    }
187
    }
189
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
188
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
190
        my $sth =
191
          $dbh->prepare(
192
            "select itemtype,description from itemtypes order by description");
193
        $sth->execute;
194
        push @authorised_values, ""
189
        push @authorised_values, ""
195
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
190
          unless ( $tagslib->{$tag}->{$subfield}->{mandatory}
196
            && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
191
            && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) );
197
          
192
198
        my $itemtype;
193
        my $itemtype;
199
        
194
        my $itemtypes = GetItemTypes( style => 'array' );
200
        while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
195
        for my $itemtype ( @$itemtypes ) {
201
            push @authorised_values, $itemtype;
196
            push @authorised_values, $itemtype->{itemtype};
202
            $authorised_lib{$itemtype} = $description;
197
            $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
203
        }
198
        }
204
        $value = $itemtype unless ($value);
199
        $value = $itemtype unless ($value);
205
206
          #---- class_sources
207
    }
200
    }
208
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
201
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {
209
        push @authorised_values, ""
202
        push @authorised_values, ""
(-)a/cataloguing/additem.pl (-6 / +5 lines)
Lines 176-188 sub generate_subfield_form { Link Here
176
            }
176
            }
177
            elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
177
            elsif ( $subfieldlib->{authorised_value} eq "itemtypes" ) {
178
                  push @authorised_values, "" unless ( $subfieldlib->{mandatory} );
178
                  push @authorised_values, "" unless ( $subfieldlib->{mandatory} );
179
                  my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
179
                  my $itemtypes = GetItemTypes( style => 'array' );
180
                  $sth->execute;
180
                  for my $itemtype ( @$itemtypes ) {
181
                  while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
181
                      push @authorised_values, $itemtype->{itemtype};
182
                      push @authorised_values, $itemtype;
182
                      $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
183
                      $authorised_lib{$itemtype} = $description;
184
                  }
183
                  }
185
        
184
186
                  unless ( $value ) {
185
                  unless ( $value ) {
187
                      my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
186
                      my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?");
188
                      $itype_sth->execute( $biblionumber );
187
                      $itype_sth->execute( $biblionumber );
(-)a/installer/data/mysql/atomicupdate/Bug_14100-add_table_localization.sql (+8 lines)
Line 0 Link Here
1
CREATE TABLE `localization` (
2
      localization_id int(11) NOT NULL AUTO_INCREMENT,
3
      entity varchar(16) COLLATE utf8_unicode_ci NOT NULL,
4
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
5
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL,
6
      translation text COLLATE utf8_unicode_ci,
7
      PRIMARY KEY (localization_id)
8
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
(-)a/installer/data/mysql/kohastructure.sql (+14 lines)
Lines 3536-3541 CREATE TABLE discharges ( Link Here
3536
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3536
  CONSTRAINT borrower_discharges_ibfk1 FOREIGN KEY (borrower) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
3537
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3537
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3538
3538
3539
--
3540
-- Table structure for table 'localization'
3541
--
3542
3543
DROP TABLE IF EXISTS localization;
3544
CREATE TABLE `localization` (
3545
      localization_id int(11) NOT NULL AUTO_INCREMENT,
3546
      entity varchar(16) COLLATE utf8_unicode_ci NOT NULL,
3547
      code varchar(64) COLLATE utf8_unicode_ci NOT NULL,
3548
      lang varchar(25) COLLATE utf8_unicode_ci NOT NULL, --could be a foreign key
3549
      translation text COLLATE utf8_unicode_ci,
3550
      PRIMARY KEY (localization_id)
3551
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
3552
3539
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3553
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3540
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3554
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3541
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3555
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt (-3 / +20 lines)
Lines 20-25 Data deleted Link Here
20
</title>
20
</title>
21
[% INCLUDE 'doc-head-close.inc' %]
21
[% INCLUDE 'doc-head-close.inc' %]
22
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
22
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
23
[% INCLUDE 'greybox.inc' %]
23
[% INCLUDE 'datatables.inc' %]
24
[% INCLUDE 'datatables.inc' %]
24
<script type="text/javascript">
25
<script type="text/javascript">
25
//<![CDATA[
26
//<![CDATA[
Lines 124-130 Item types administration Link Here
124
      </li>
125
      </li>
125
  [% END %]
126
  [% END %]
126
      <li>
127
      <li>
127
          <label for="description" class="required">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" required="required" /> <span class="required">Required</span></li>
128
          <label for="description" class="required">Description: </label><input type="text" id="description" name="description" size="48" value="[% description |html %]" required="required" /> <span class="required">Required</span>
129
          <a href="/cgi-bin/koha/admin/localization.pl?entity=itemtypes&code=[% itemtype %]" title="Translate" rel="gb_page_center[600,500]"><i class="icon-edit"></i> Translate for other languages</a>
130
      </li>
128
     [% IF ( noItemTypeImages ) %]
131
     [% IF ( noItemTypeImages ) %]
129
	 <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
132
	 <li><span class="label">Image: </span>Item type images are disabled. To enable them, turn off the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&amp;searchfield=noItemTypeImages">noItemTypeImages system preference</a></li></ol>
130
	 [% ELSE %]</ol>
133
	 [% ELSE %]</ol>
Lines 253-259 Item types administration Link Here
253
			<td>[% itemtype %]</td>
256
			<td>[% itemtype %]</td>
254
		</tr>
257
		</tr>
255
258
256
	<tr><th scope="row">Description</th><td>[% description %]</td></tr>
259
	<tr><th scope="row">Description</th><td>[% translated_description %]</td></tr>
257
	<tr><th scope="row">Loan length</th><td>[% loanlength %]</td></tr>
260
	<tr><th scope="row">Loan length</th><td>[% loanlength %]</td></tr>
258
<tr><th scope="row">Rental charge</th><td>[% rentalcharge %]</td></tr></table>
261
<tr><th scope="row">Rental charge</th><td>[% rentalcharge %]</td></tr></table>
259
		<form action="[% script_name %]" method="post">
262
		<form action="[% script_name %]" method="post">
Lines 289-295 Item types administration Link Here
289
        [% loo.itemtype %]
292
        [% loo.itemtype %]
290
      </a>
293
      </a>
291
    </td>
294
    </td>
292
    <td>[% loo.description %]</td>
295
    <td>
296
        [% IF loo.translated_descriptions.size %]
297
            [% loo.description %] (default)<br/>
298
            [% FOR description IN loo.translated_descriptions %]
299
                [% IF description.translation == loo.translated_description %]
300
                    <b>[% description.translation %]</b>
301
                [% ELSE %]
302
                    [% description.translation %] ([% description.lang %])
303
                [% END %]
304
                <br/>
305
            [% END %]
306
        [% ELSE %]
307
            [% loo.description %]
308
        [% END %]
309
    </td>
293
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
310
    <td>[% IF ( loo.notforloan ) %]Yes[% ELSE %]&nbsp;[% END %]</td>
294
    <td>
311
    <td>
295
    [% UNLESS ( loo.notforloan ) %]
312
    [% UNLESS ( loo.notforloan ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt (+212 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Localization</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
5
[% INCLUDE 'greybox.inc' %]
6
[% INCLUDE 'datatables.inc' %]
7
<script type="text/javascript">
8
//<![CDATA[
9
10
    function show_message( params ) {
11
        var type = params.type;
12
        var data = params.data;
13
        var messages = $("#messages");
14
        var message;
15
        if ( type == 'success_on_update' ) {
16
            message = $('<div class="dialog message"></div>');
17
            message.text("Entity %s (code %s) for lang %s has correctly been updated with '%s'".format(data.entity, data.code, data.lang, data.translation));
18
        } else if ( type == 'error_on_update' ) {
19
            message = $('<div class="dialog alert"></div>');
20
            message.text("An error occurred when updating this translation");
21
        } else if ( type == 'success_on_delete' ) {
22
            message = $('<div class="dialog message"></div>');
23
            message.text("The translation (id %s) has been removed successfully".format(data.id));
24
        } else if ( type == 'error_on_delete' ) {
25
            message = $('<div class="dialog alert"></div>');
26
            message.text("An error occurred when deleting this translation");
27
        } else if ( type == 'success_on_insert' ) {
28
            message = $('<div class="dialog message"></div>');
29
            message.text("Translation (id %s) has been added successfully".format(data.id));
30
        } else if ( type == 'error_on_insert' ) {
31
            message = $('<div class="dialog alert"></div>');
32
            message.text("An error occurred when adding this translation");
33
        }
34
35
        $(messages).append(message);
36
37
        setTimeout(function(){
38
            message.hide()
39
        }, 3000);
40
    }
41
42
    function send_update_request( data, cell ) {
43
        $.ajax({
44
            data: data,
45
            type: 'PUT',
46
            url: '/cgi-bin/koha/svc/localization',
47
            success: function (data) {
48
                if ( data.is_changed ) {
49
                    $(cell).css('background-color', '#00FF00');
50
                    show_message({ type: 'success_on_update', data: data });
51
                }
52
                if ( $(cell).hasClass('lang') ) {
53
                    $(cell).text(data.lang)
54
                } else if ( $(cell).hasClass('translation') ) {
55
                    $(cell).text(data.translation)
56
                }
57
            },
58
            error: function (data) {
59
                $(cell).css('background-color', '#FF0000');
60
                if ( $(cell).hasClass('lang') ) {
61
                    $(cell).text(data.lang)
62
                } else if ( $(cell).hasClass('translation') ) {
63
                    $(cell).text(data.translation)
64
                }
65
                show_message({ type: 'error_on_update', data: data });
66
            },
67
        });
68
    }
69
70
    function send_delete_request( id, cell ) {
71
        $.ajax({
72
            type: 'DELETE',
73
            url: '/cgi-bin/koha/svc/localization/?id='+id,
74
            success: function (data) {
75
                $("#localization").DataTable().row( '#row_id_' + id ).remove().draw();
76
                show_message({ type: 'success_on_delete', data: data });
77
            },
78
            error: function (data) {
79
                $(cell).css('background-color', '#FF0000');
80
                show_message({ type: 'error_on_delete', data: data });
81
            },
82
        });
83
    }
84
85
    $(document).ready(function() {
86
        $(".dialog").hide();
87
88
        var table = $("#localization").DataTable($.extend(true, {}, dataTablesDefaults, {
89
            'bPaginate': false,
90
        }));
91
92
        var languages_select = $('<select name="lang"></select>');
93
        [% FOR language IN languages %]
94
            var option = $('<option value="[% language.lang %]">[% language.description %]</option>');
95
            $(languages_select).append(option);
96
        [% END %]
97
98
        $("td.translation").on('focus', function(){
99
            $(this).css('background-color', '');
100
        });
101
        $("td.lang").on('click', function(){
102
            var td = this;
103
            var lang = $(td).text();
104
            $(td).css('background-color', '');
105
            var my_select = $(languages_select).clone();
106
            $(my_select).find('option[value="' + lang + '"]').attr('selected', 'selected');
107
            $(my_select).on('click', function(e){
108
                e.stopPropagation();
109
            });
110
            $(my_select).on('change', function(){
111
                var tr = $(this).parent().parent();
112
                var id = $(tr).data('id');
113
                var lang = $(this).find('option:selected').val();
114
                var data = "id=" + encodeURIComponent(id) + "&lang=" + encodeURIComponent(lang);
115
                send_update_request( data, td );
116
            });
117
            $(my_select).on('blur', function(){
118
                $(td).html(lang);
119
            });
120
            $(this).html(my_select);
121
        });
122
123
        $("td.translation").on('blur', function(){
124
            var tr = $(this).parent();
125
            var id = $(tr).data('id');
126
            var translation = $(this).text();
127
            var data = "id=" + encodeURIComponent(id) + "&translation=" + encodeURIComponent(translation);
128
            send_update_request( data, this );
129
        });
130
131
        $("a.delete").on('click', function(){
132
            if ( confirm(_("Are you sure you want to delete this translation?")) ) {
133
                var td = $(this).parent();
134
                var tr = $(td).parent();
135
                var id = $(tr).data('id');
136
                send_delete_request( id, td );
137
            }
138
        });
139
140
        $("#add_translation").on('submit', function(e){
141
            e.preventDefault();
142
            var entity = $(this).find('input[name="entity"]').val();
143
            var code = $(this).find('input[name="code"]').val();
144
            var lang = $(this).find('select[name="lang"] option:selected').val();
145
            var translation = $(this).find('input[name="translation"]').val();
146
            var data = "entity=" + encodeURIComponent(entity) + "&code=" + encodeURIComponent(code) + "&lang=" + encodeURIComponent(lang) + "&translation=" + encodeURIComponent(translation);
147
            $.ajax({
148
                data: data,
149
                type: 'POST',
150
                url: '/cgi-bin/koha/svc/localization',
151
                success: function (data) {
152
                    // FIXME Should append the delete link
153
                    table.row.add( [ data.id, data.entity, data.code, data.lang, data.translation, "" ] ).draw();
154
                    show_message({ type: 'success_on_insert', data: data });
155
                },
156
                error: function (data) {
157
                    show_message({ type: 'error_on_insert', data: data });
158
                },
159
            });
160
        });
161
162
     });
163
//]]>
164
</script>
165
</head>
166
<body id="admin_localization" class="admin">
167
<div id="main">
168
<table id="localization">
169
    <thead>
170
        <tr>
171
            <th>Id</th>
172
            <th>Entity</th>
173
            <th>Code</th>
174
            <th>Lang</th>
175
            <th>Translation</th>
176
            <th></th>
177
        </tr>
178
    </thead>
179
    <tbody>
180
        [% FOR t IN translations %]
181
        <tr id="row_id_[% t.id %]" data-id="[% t.id %]">
182
            <td>[% t.id %]</td>
183
            <td>[% t.entity %]</td>
184
            <td>[% t.code %]</td>
185
            <td class="lang">[% t.lang %]</td>
186
            <td class="translation" contenteditable="true">[% t.translation %]</td>
187
            <td><a class="delete" title="Delete this translation"><i class="icon-remove"></i></a</td>
188
        </tr>
189
        [% END %]
190
    </tbody>
191
</table>
192
<form id="add_translation" method="post">
193
    <input type="hidden" name="entity" value="[% entity %]" />
194
    <input type="hidden" name="code" value="[% code %]" />
195
    Lang: <select name="lang">
196
        [% FOR language IN languages %]
197
            [% FOR sublanguage IN language.sublanguages_loop %]
198
                [% IF language.plural %]
199
                    <option value="[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] [% sublanguage.region_description %] ([% sublanguage.rfc4646_subtag %])</option>
200
                [% ELSE %]
201
                    <option value="[% sublanguage.rfc4646_subtag %]">[% sublanguage.native_description %] ([% sublanguage.rfc4646_subtag %])</option>
202
                [% END %]
203
            [% END %]
204
        [% END %]
205
    </select>
206
    Translation: <input type="text" name="translation" />
207
    <input type="submit" value="Add" />
208
</form>
209
<div id="messages"></div>
210
</div>
211
</body>
212
</html>
(-)a/svc/checkouts (-5 / +2 lines)
Lines 83-91 my $sql = ' Link Here
83
        branchname,
83
        branchname,
84
84
85
        items.itype,
85
        items.itype,
86
        itemtype_item.description AS itype_description,
87
        biblioitems.itemtype,
86
        biblioitems.itemtype,
88
        itemtype_bib.description AS itemtype_description,
89
87
90
        borrowernumber,
88
        borrowernumber,
91
        surname,
89
        surname,
Lines 103-110 my $sql = ' Link Here
103
        LEFT JOIN biblioitems USING ( biblionumber )
101
        LEFT JOIN biblioitems USING ( biblionumber )
104
        LEFT JOIN borrowers USING ( borrowernumber )
102
        LEFT JOIN borrowers USING ( borrowernumber )
105
        LEFT JOIN branches ON ( issues.branchcode = branches.branchcode )
103
        LEFT JOIN branches ON ( issues.branchcode = branches.branchcode )
106
        LEFT JOIN itemtypes itemtype_bib ON ( biblioitems.itemtype = itemtype_bib.itemtype )
107
        LEFT JOIN itemtypes itemtype_item ON ( items.itype = itemtype_item.itemtype )
108
    WHERE borrowernumber
104
    WHERE borrowernumber
109
';
105
';
110
106
Lines 145-157 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
145
    my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
141
    my ( $renewals_count, $renewals_allowed, $renewals_remaining ) =
146
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
142
      GetRenewCount( $c->{borrowernumber}, $c->{itemnumber} );
147
143
144
    my $itemtype = C4::Koha::getitemtypeinfo( $item_level_itypes ? $c->{itype} : $c->{itemtype} );
148
    my $checkout = {
145
    my $checkout = {
149
        DT_RowId   => $c->{itemnumber} . '-' . $c->{borrowernumber},
146
        DT_RowId   => $c->{itemnumber} . '-' . $c->{borrowernumber},
150
        title      => $c->{title},
147
        title      => $c->{title},
151
        author     => $c->{author},
148
        author     => $c->{author},
152
        barcode    => $c->{barcode},
149
        barcode    => $c->{barcode},
153
        itemtype   => $item_level_itypes ? $c->{itype} : $c->{itemtype},
150
        itemtype   => $item_level_itypes ? $c->{itype} : $c->{itemtype},
154
        itemtype_description => $item_level_itypes ? $c->{itype_description} : $c->{itemtype_description},
151
        itemtype_description => $itemtype->{translated_description},
155
        location   => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
152
        location   => $c->{location} ? GetAuthorisedValueByCode( 'LOC', $c->{location} ) : q{},
156
        itemnotes  => $c->{itemnotes},
153
        itemnotes  => $c->{itemnotes},
157
        branchcode => $c->{branchcode},
154
        branchcode => $c->{branchcode},
(-)a/svc/localization (+92 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use C4::Service;
6
use Koha::Localizations;
7
8
our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' );
9
10
sub get_translations {
11
    my $rs = Koha::Localizations->search({ type => $query->param('type'), code => $query->param('code') });
12
    my @translations;
13
    while ( my $s = $rs->next ) {
14
        push @translations, {
15
            id => $s->localization_id,
16
            type => $s->type,
17
            code => $s->code,
18
            lang => $s->lang,
19
            translation => $s->translation,
20
        }
21
    }
22
    $response->param( translations => \@translations );
23
    C4::Service->return_success( $response );
24
}
25
26
sub update_translation {
27
    my $id = $query->param('id');
28
    my $translation = $query->param('translation');
29
    my $lang = $query->param('lang');
30
    my $localization = Koha::Localizations->find( $id );
31
32
    if ( defined $lang and $localization->lang ne $lang ) {
33
        $localization->lang( $lang )
34
    }
35
    if ( defined $translation and $localization->translation ne $translation ) {
36
        $localization->translation( $translation )
37
    }
38
    my $is_changed;
39
    if ( $localization->is_changed ) {
40
        $is_changed = 1;
41
        $localization->store;
42
    }
43
    $response->param(
44
        id          => $localization->localization_id,
45
        entity      => $localization->entity,
46
        code        => $localization->code,
47
        lang        => $localization->lang,
48
        translation => $localization->translation,
49
        is_changed  => $is_changed,
50
    );
51
    C4::Service->return_success( $response );
52
}
53
54
sub add_translation {
55
    my $entity = $query->param('entity');
56
    my $code = $query->param('code');
57
    my $lang = $query->param('lang');
58
    my $translation = $query->param('translation');
59
    my $localization = Koha::Localization->new(
60
        {
61
            entity => $entity,
62
            code => $code,
63
            lang => $lang,
64
            translation => $translation,
65
        }
66
    );
67
    $localization->store;
68
    $localization->localization_id;
69
    $response->param(
70
        id          => $localization->localization_id,
71
        entity      => $localization->entity,
72
        code        => $localization->code,
73
        lang        => $localization->lang,
74
        translation => $localization->translation,
75
    );
76
77
    C4::Service->return_success( $response );
78
}
79
80
sub delete_translation {
81
    my $id = $query->param('id');
82
    Koha::Localizations->find($id)->delete;
83
    $response->param( id => $id );
84
    C4::Service->return_success( $response );
85
}
86
87
C4::Service->dispatch(
88
    [ 'GET /', [ 'id' ], \&get_translations ],
89
    [ 'PUT /', [ 'id' ], \&update_translation ],
90
    [ 'POST /', [ 'entity', 'code', 'lang', 'translation' ], \&add_translation ],
91
    [ 'DELETE /', ['id'],  \&delete_translation ],
92
);
(-)a/tools/batchMod.pl (-9 / +7 lines)
Lines 354-367 foreach my $tag (sort keys %{$tagslib}) { Link Here
354
	    }
354
	    }
355
        $value = "";
355
        $value = "";
356
	}
356
	}
357
	elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
357
    elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
358
	    push @authorised_values, "";
358
        push @authorised_values, "";
359
	    my $sth = $dbh->prepare("select itemtype,description from itemtypes order by description");
359
        my $itemtypes = GetItemTypes( style => 'array' );
360
	    $sth->execute;
360
        for my $itemtype ( @$itemtypes ) {
361
	    while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
361
            push @authorised_values, $itemtype->{itemtype};
362
		push @authorised_values, $itemtype;
362
            $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
363
		$authorised_lib{$itemtype} = $description;
363
        }
364
	    }
365
        $value = "";
364
        $value = "";
366
365
367
          #---- class_sources
366
          #---- class_sources
368
- 

Return to bug 14100