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

(-)a/Koha/AuthorisedValue.pm (+208 lines)
Line 0 Link Here
1
package Koha::AuthorisedValue;
2
3
use Modern::Perl;
4
use List::MoreUtils qw( any uniq );
5
6
use base qw(Class::Accessor);
7
8
use C4::Context;
9
use Koha::Database;
10
11
my $rs_av  = Koha::Database->new()->schema->resultset('AuthorisedValue');
12
my $rs_avb = Koha::Database->new()->schema->resultset('AuthorisedValuesBranch');
13
14
sub fetch {
15
    my ( $self ) = @_;
16
17
    my $av;
18
    if( $self->{id} ) {
19
        $av = $rs_av->find($self->{id});
20
    }
21
    else {
22
        $av = $rs_av->find({
23
            category => $self->{category},
24
            authorised_value => $self->{authorised_value},
25
        });
26
    }
27
    die unless $av;
28
29
    my %iv = $av->get_columns;
30
    my $data = \%iv;
31
32
    $self->{id} = $data->{id};
33
    $self->{category} = $data->{category};
34
    $self->{authorised_value} = $data->{authorised_value};
35
    $self->{lib} = $data->{lib};
36
    $self->{lib_opac} = $data->{lib_opac};
37
    $self->{imageurl} = $data->{imageurl};
38
    return $self;
39
}
40
41
sub update {
42
    my ( $self ) = @_;
43
    die "There is no id defined for this authorised value. I cannot update it" unless $self->{id};
44
45
    $rs_av->find($self->{id})->update({
46
        category         => $self->{category},
47
        authorised_value => $self->{authorised_value},
48
        lib              => $self->{lib},
49
        lib_opac         => $self->{lib_opac},
50
        imageurl         => $self->{imageurl},
51
    });
52
53
    $rs_avb->search({ av_id => $self->{id} })->delete;
54
    for my $branch ( @{ $self->{branches_limitations} } ) {
55
        next unless $branch->{branchcode};
56
        $rs_avb->create({
57
            av_id      => $self->{id},
58
            branchcode => $branch->{branchcode},
59
        });
60
    }
61
}
62
63
sub delete {
64
    my ( $self ) = @_;
65
    $rs_av->find( $self->{id} )->delete;
66
    return 1;
67
}
68
69
sub insert {
70
    my ( $self ) = @_;
71
    $self->{id} = $rs_av->create({
72
        category         => $self->{category},
73
        authorised_value => $self->{authorised_value},
74
        lib              => $self->{lib},
75
        lib_opac         => $self->{lib_opac},
76
        imageurl         => $self->{imageurl},
77
    })->id;
78
79
    for my $branch ( @{ $self->{branches_limitations} } ) {
80
        next unless $branch->{branchcode};
81
        $rs_avb->create({
82
            av_id      => $self->{id},
83
            branchcode => $branch->{branchcode},
84
        });
85
    }
86
}
87
88
sub all {
89
    my ( $self ) = @_;
90
    return $self->search();
91
}
92
93
sub search {
94
    my ( $self, $filters ) = @_;
95
96
    my $rs = $rs_av->search( $filters );
97
    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
98
    return wantarray ? ( $rs->all ) : [ $rs->all ];
99
}
100
101
sub categories {
102
    my ( $self ) = @_;
103
    my @avs = $self->all;
104
    my @categories = uniq map {
105
        $_->{category}
106
    } @avs;
107
108
    return wantarray ? @categories : \@categories;
109
}
110
111
sub branches_limitations {
112
    my ( $self, $limitations ) = @_;
113
    my $dbh = C4::Context->dbh;
114
    unless ( defined $limitations ) {
115
        my $rs = $rs_avb->search({
116
            av_id => $self->{id},
117
        },{
118
            join => 'branchcode',
119
        });
120
121
        my @limitations;
122
        while( my $avb = $rs->next ) {
123
            push @limitations, {
124
                branchcode => $avb->branchcode->branchcode,
125
                branchname => $avb->branchcode->branchname,
126
            }
127
        }
128
        $self->{branches_limitations} = \@limitations;
129
        return $self->{branches_limitations};
130
    } else {
131
        die "setter not implemented yet";
132
    }
133
}
134
135
1;
136
137
__END__
138
139
=head1 NAME
140
141
Koha::AuthorisedValue
142
143
=head1 SYNOPSIS
144
145
    use Koha::AuthorisedValue;
146
    my $av1 = Koha::AuthorisedValue->new({id => $id});
147
    my $av2 = Koha::AuthorisedValue->new({av => $av});
148
    my $av3 = Koha::AuthorisedValue->new({category => $category, authorised_value => $authorised_value});
149
    $av1->fetch;
150
    $av2->delete;
151
152
=head1 DESCRIPTION
153
154
Class for managing an authorised value into Koha.
155
156
=head1 METHODS
157
158
=head2 new
159
160
Create a new Koha::AuthorisedValue object. No sql query is done in this method.
161
162
=head2 fetch
163
164
The information will be retrieved from the database.
165
166
=head2 update
167
168
If the AuthorisedValue object has been modified and the values have to be modified into the database, call this method.
169
170
=head2 delete
171
172
Remove a the record in the database using the id the object.
173
174
=head2 insert
175
176
Insert a new AuthorisedValue object into the database.
177
178
=head2 branches_limitations
179
180
In the interest of being pleasant with the performance, the branches limitations is not retrieve with the fetch method.
181
If they are required, you should call this method.
182
183
=head1 AUTHOR
184
185
Jonathan Druart <jonathan.druart at biblibre.com>
186
187
=head1 COPYRIGHT
188
189
Copyright 2013 BibLibre
190
191
=head1 LICENSE
192
193
This file is part of Koha.
194
195
Koha is free software; you can redistribute it and/or modify it under the
196
terms of the GNU General Public License as published by the Free Software
197
Foundation; either version 3 of the License, or (at your option) any later
198
version.
199
200
Koha is distributed in the hope that it will be useful, but WITHOUT ANY
201
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
202
A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
203
204
You should have received a copy of the GNU General Public License along
205
with Koha; if not, write to the Free Software Foundation, Inc.,
206
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
207
208
=cut
(-)a/admin/authorised_values.pl (-201 / +120 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
4
# Copyright 2013 BibLibre
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 17-24 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
20
use strict;
21
use Modern::Perl;
21
use warnings;
22
22
23
use CGI;
23
use CGI;
24
use C4::Auth;
24
use C4::Auth;
Lines 26-57 use C4::Branch; Link Here
26
use C4::Context;
26
use C4::Context;
27
use C4::Koha;
27
use C4::Koha;
28
use C4::Output;
28
use C4::Output;
29
use Koha::AuthorisedValue;
29
30
30
31
31
sub AuthorizedValuesForCategory {
32
    my ($searchstring) = shift or return;
33
    my $dbh = C4::Context->dbh;
34
    $searchstring=~ s/\'/\\\'/g;
35
    my @data=split(' ',$searchstring);
36
    my $sth=$dbh->prepare('
37
          SELECT  id, category, authorised_value, lib, lib_opac, imageurl
38
            FROM  authorised_values
39
           WHERE  (category = ?)
40
        ORDER BY  category, authorised_value
41
    ');
42
    $sth->execute("$data[0]");
43
    return $sth->fetchall_arrayref({});
44
}
45
46
my $input = new CGI;
32
my $input = new CGI;
47
my $id          = $input->param('id');
33
my $id          = $input->param('id');
48
my $op          = $input->param('op')     || '';
34
my $op          = $input->param('op') || 'list';
49
our $offset      = $input->param('offset') || 0;
35
my $searchfield = $input->param('searchfield');
50
our $searchfield = $input->param('searchfield');
51
$searchfield = '' unless defined $searchfield;
36
$searchfield = '' unless defined $searchfield;
52
$searchfield =~ s/\,//g;
37
$searchfield =~ s/\,//g;
53
our $script_name = "/cgi-bin/koha/admin/authorised_values.pl";
38
my @messages;
54
our $dbh = C4::Context->dbh;
55
39
56
our ($template, $borrowernumber, $cookie)= get_template_and_user({
40
our ($template, $borrowernumber, $cookie)= get_template_and_user({
57
    template_name => "admin/authorised_values.tt",
41
    template_name => "admin/authorised_values.tt",
Lines 62-92 our ($template, $borrowernumber, $cookie)= get_template_and_user({ Link Here
62
    debug => 1,
46
    debug => 1,
63
});
47
});
64
48
65
$template->param(  script_name => $script_name,
66
                 ($op||'else') => 1 );
67
################## ADD_FORM ##################################
49
################## ADD_FORM ##################################
68
# called by default. Used to create form to add or  modify a record
50
# called by default. Used to create form to add or  modify a record
69
if ($op eq 'add_form') {
51
if ($op eq 'add_form') {
70
	my $data;
52
    my ( $selected_branches, $category, $av );
71
    my @selected_branches;
53
    if ($id) {
72
	if ($id) {
54
        $av = Koha::AuthorisedValue->new( { id => $id } )->fetch;
73
		my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?");
55
        $selected_branches = $av->branches_limitations;
74
		$sth->execute($id);
56
    } else {
75
		$data=$sth->fetchrow_hashref;
57
        $category = $input->param('category');
76
        $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?;");
58
    }
77
        $sth->execute( $id );
78
        while ( my $branch = $sth->fetchrow_hashref ) {
79
            push @selected_branches, $branch;
80
        }
81
	} else {
82
		$data->{'category'} = $input->param('category');
83
	}
84
59
85
    my $branches = GetBranches;
60
    my $branches = GetBranches;
86
    my @branches_loop;
61
    my @branches_loop;
87
62
88
    foreach my $branch (sort keys %$branches) {
63
    foreach my $branch (sort keys %$branches) {
89
        my $selected = ( grep {$_->{branchcode} eq $branch} @selected_branches ) ? 1 : 0;
64
        my $selected = ( grep {$_->{branchcode} eq $branch} @$selected_branches ) ? 1 : 0;
90
        push @branches_loop, {
65
        push @branches_loop, {
91
            branchcode => $branches->{$branch}{branchcode},
66
            branchcode => $branches->{$branch}{branchcode},
92
            branchname => $branches->{$branch}{branchname},
67
            branchname => $branches->{$branch}{branchname},
Lines 96-247 if ($op eq 'add_form') { Link Here
96
71
97
	if ($id) {
72
	if ($id) {
98
		$template->param(action_modify => 1);
73
		$template->param(action_modify => 1);
99
		$template->param('heading_modify_authorized_value_p' => 1);
74
   } elsif ( ! $category ) {
100
	} elsif ( ! $data->{'category'} ) {
101
		$template->param(action_add_category => 1);
75
		$template->param(action_add_category => 1);
102
		$template->param('heading_add_new_category_p' => 1);
103
	} else {
76
	} else {
104
		$template->param(action_add_value => 1);
77
		$template->param(action_add_value => 1);
105
		$template->param('heading_add_authorized_value_p' => 1);
106
	}
78
	}
107
	$template->param('use_heading_flags_p' => 1);
79
108
	$template->param( category        => $data->{'category'},
80
    $template->param(
109
                         authorised_value => $data->{'authorised_value'},
81
        category => ( $av ? $av->{category} : $category ),
110
                         lib              => $data->{'lib'},
82
        authorised_value => $av->{authorised_value},
111
                         lib_opac         => $data->{'lib_opac'},
83
        lib              => $av->{lib},
112
                         id               => $data->{'id'},
84
        lib_opac         => $av->{lib_opac},
113
                         imagesets        => C4::Koha::getImageSets( checked => $data->{'imageurl'} ),
85
        id               => $av->{id},
114
                         offset           => $offset,
86
        imagesets        => C4::Koha::getImageSets( checked => $av->{imageurl} ),
115
                         branches_loop    => \@branches_loop,
87
        branches_loop    => \@branches_loop,
116
                     );
88
     );
117
                          
89
118
################## ADD_VALIDATE ##################################
90
} elsif ($op eq 'add') {
119
# called by add_form, used to insert/modify data in DB
120
} elsif ($op eq 'add_validate') {
121
    my $new_authorised_value = $input->param('authorised_value');
91
    my $new_authorised_value = $input->param('authorised_value');
122
    my $new_category = $input->param('category');
92
    my $new_category = $input->param('category');
123
    my $imageurl     = $input->param( 'imageurl' ) || '';
93
    my $imageurl     = $input->param( 'imageurl' ) || '';
124
	$imageurl = '' if $imageurl =~ /removeImage/;
94
    $imageurl = '' if $imageurl =~ /removeImage/;
125
    my $duplicate_entry = 0;
95
    my $duplicate_entry = 0;
126
    my @branches = $input->param('branches');
96
    my @branches = $input->param('branches');
127
97
128
    if ( $id ) { # Update
98
    if ( $id ) { # Update
129
        my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? ");
99
        my $av = Koha::AuthorisedValue->new( { id => $id } );
130
        $sth->execute($id);
100
131
        my ($category, $authorised_value) = $sth->fetchrow_array();
101
        # TODO in updatedatabase and kohastructure
132
        if ( $authorised_value ne $new_authorised_value ) {
102
        # Add a uniq key on auv.category and av.authorised_values
133
            my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
103
        #if ( $av->{authorised_value} ne $new_authorised_value ) {
134
                "WHERE category = ? AND authorised_value = ? and id <> ? ");
104
        #    my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
135
            $sth->execute($new_category, $new_authorised_value, $id);
105
        #        "WHERE category = ? AND authorised_value = ? and id <> ? ");
136
            ($duplicate_entry) = $sth->fetchrow_array();
106
        #    $sth->execute($new_category, $new_authorised_value, $id);
137
        }
107
        #    ($duplicate_entry) = $sth->fetchrow_array();
138
        unless ( $duplicate_entry ) {
108
        #}
139
            my $sth=$dbh->prepare( 'UPDATE authorised_values
109
        #unless ( $duplicate_entry ) {
140
                                      SET category         = ?,
110
            $av->{lib} = $input->param('lib') || undef;
141
                                          authorised_value = ?,
111
            $av->{lib_opac} = $input->param('lib_opac') || undef;
142
                                          lib              = ?,
112
            $av->{category} = $new_category;
143
                                          lib_opac         = ?,
113
            $av->{authorised_value} = $new_authorised_value;
144
                                          imageurl         = ?
114
            $av->{imageurl} = $imageurl;
145
                                      WHERE id=?' );
115
            $av->{id} = $id;
146
            my $lib = $input->param('lib');
116
            $av->{branches_limitations} = [
147
            my $lib_opac = $input->param('lib_opac');
117
                map { {branchcode => $_, branchname => undef} } @branches
148
            undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
118
            ];
149
            undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
119
            if ( $@ ) {
150
            $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);
120
                push @messages, {type => 'error', code => 'error_on_update' };
151
            if ( @branches ) {
121
            } else {
152
                $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?");
122
                push @messages, { type => 'message', code => 'success_on_update' };
153
                $sth->execute( $id );
154
                $sth = $dbh->prepare(
155
                    "INSERT INTO authorised_values_branches
156
                                ( av_id, branchcode )
157
                                VALUES ( ?, ? )"
158
                );
159
                for my $branchcode ( @branches ) {
160
                    next if not $branchcode;
161
                    $sth->execute($id, $branchcode);
162
                }
163
            }
123
            }
164
            $sth->finish;
124
            $av->update;
165
            print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$new_category."&offset=$offset\"></html>";
125
            $template->param( update_success => 1 );
166
            exit;
126
        #}
167
        }
168
    }
127
    }
169
    else { # Insert
128
    else { # Insert
170
        my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
129
        my $av = Koha::AuthorisedValue->new( {
171
            "WHERE category = ? AND authorised_value = ? ");
130
            category => $new_category,
172
        $sth->execute($new_category, $new_authorised_value);
131
            authorised_value => $new_authorised_value,
173
        ($duplicate_entry) = $sth->fetchrow_array();
132
            lib => $input->param('lib') || undef,
174
        unless ( $duplicate_entry ) {
133
            lib_opac => $input->param('lib_opac') || undef,
175
            my $sth=$dbh->prepare( 'INSERT INTO authorised_values
134
            imageurl => $imageurl,
176
                                    ( category, authorised_value, lib, lib_opac, imageurl )
135
            branches_limitations => [ map { {branchcode => $_, branchname => undef} } @branches ],
177
                                    values (?, ?, ?, ?, ?)' );
136
        } );
178
    	    my $lib = $input->param('lib');
137
        eval {$av->insert};
179
    	    my $lib_opac = $input->param('lib_opac');
138
        if ( $@ ) {
180
    	    undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
139
            push @messages, {type => 'error', code => 'error_on_insert' };
181
    	    undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
140
        } else {
182
            $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
141
            push @messages, { type => 'message', code => 'success_on_insert' };
183
            $id = $dbh->{'mysql_insertid'};
184
            if ( @branches ) {
185
                $sth = $dbh->prepare(
186
                    "INSERT INTO authorised_values_branches
187
                                ( av_id, branchcode )
188
                                VALUES ( ?, ? )"
189
                );
190
                for my $branchcode ( @branches ) {
191
                    next if not $branchcode;
192
                    $sth->execute($id, $branchcode);
193
                }
194
            }
195
    	    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=".$input->param('category')."&offset=$offset\"></html>";
196
    	    exit;
197
        }
142
        }
198
    }
143
    }
199
    if ( $duplicate_entry ) {       
144
    if ( $duplicate_entry ) {
200
        $template->param(duplicate_category => $new_category,
145
        $template->param(duplicate_category => $new_category,
201
                         duplicate_value =>  $new_authorised_value,
146
                         duplicate_value =>  $new_authorised_value);
202
                         else => 1);
147
    }
203
        default_form();
204
     }           
205
	
206
################## DELETE_CONFIRM ##################################
207
# called by default form, used to confirm deletion of data in DB
208
} elsif ($op eq 'delete_confirm') {
209
	my $sth=$dbh->prepare("select category,authorised_value,lib,lib_opac from authorised_values where id=?");
210
	$sth->execute($id);
211
	my $data=$sth->fetchrow_hashref;
212
	$id = $input->param('id') unless $id;
213
	$template->param(searchfield => $searchfield,
214
							Tlib => $data->{'lib'},
215
							Tlib_opac => $data->{'lib_opac'},
216
							Tvalue => $data->{'authorised_value'},
217
							id =>$id,
218
							);
219
148
220
													# END $OP eq DELETE_CONFIRM
149
    $op = 'list';
221
################## DELETE_CONFIRMED ##################################
150
    $searchfield = $new_category;
222
# called by delete_confirm, used to effectively confirm deletion of data in DB
151
} elsif ($op eq 'delete') {
223
} elsif ($op eq 'delete_confirmed') {
152
    my $av = Koha::AuthorisedValue->new( { id => $input->param('id') } );
224
	my $id = $input->param('id');
153
    eval {$av->delete};
225
	my $sth=$dbh->prepare("delete from authorised_values where id=?");
154
    if ( $@ ) {
226
	$sth->execute($id);
155
        push @messages, {type => 'error', code => 'error_on_delete' };
227
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authorised_values.pl?searchfield=$searchfield&offset=$offset\"></html>";
156
    } else {
228
	exit;
157
        push @messages, { type => 'message', code => 'success_on_delete' };
229
													# END $OP eq DELETE_CONFIRMED
158
    }
230
################## DEFAULT ##################################
159
231
} else { # DEFAULT
160
    $op = 'list';
232
    default_form();
161
    $template->param( delete_success => 1 );
233
} #---- END $OP eq DEFAULT
162
}
234
output_html_with_http_headers $input, $cookie, $template->output;
235
163
236
exit 0;
164
$template->param(
165
    op => $op,
166
    searchfield => $searchfield,
167
    messages => \@messages,
168
);
237
169
238
sub default_form {
170
if ( $op eq 'list' ) {
239
    # build categories list
171
    # build categories list
240
    my $sth = $dbh->prepare("select distinct category from authorised_values");
172
    my $avs = Koha::AuthorisedValue->new;
241
    $sth->execute;
242
    my @category_list;
173
    my @category_list;
243
    my %categories;    # a hash, to check that some hardcoded categories exist.
174
    my %categories;    # a hash, to check that some hardcoded categories exist.
244
    while ( my ($category) = $sth->fetchrow_array ) {
175
    for my $category ( $avs->categories ) {
245
        push( @category_list, $category );
176
        push( @category_list, $category );
246
        $categories{$category} = 1;
177
        $categories{$category} = 1;
247
    }
178
    }
Lines 251-294 sub default_form { Link Here
251
        push @category_list, $_ unless $categories{$_};
182
        push @category_list, $_ unless $categories{$_};
252
    }
183
    }
253
184
254
	#reorder the list
185
    #reorder the list
255
	@category_list = sort {$a cmp $b} @category_list;
186
    @category_list = sort {$a cmp $b} @category_list;
256
	my $tab_list = CGI::scrolling_list(-name=>'searchfield',
187
257
	        -id=>'searchfield',
188
    $searchfield ||= $category_list[0];
258
			-values=> \@category_list,
189
259
			-default=>"",
190
    my $avs_for_category = $avs->search( { category => $searchfield } );
260
			-size=>1,
191
    my @loop_data = ();
261
			-multiple=>0,
192
    # builds value list
262
			);
193
    for my $av ( @$avs_for_category ) {
263
	if (!$searchfield) {
194
        my $branches = Koha::AuthorisedValue->new($av)->branches_limitations;
264
		$searchfield=$category_list[0];
195
        my %row_data;  # get a fresh hash for the row data
265
	}
196
        $row_data{category}              = $av->{category};
266
    my ($results) = AuthorizedValuesForCategory($searchfield);
197
        $row_data{authorised_value}      = $av->{authorised_value};
267
    my $count = scalar(@$results);
198
        $row_data{lib}                   = $av->{lib};
268
	my @loop_data = ();
199
        $row_data{lib_opac}              = $av->{lib_opac};
269
	# builds value list
200
        $row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $av->{imageurl} );
270
    my $dbh = C4::Context->dbh;
201
        $row_data{branches}              = $branches;
271
    $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM authorised_values_branches AS avb, branches AS b WHERE avb.branchcode = b.branchcode AND avb.av_id = ?");
202
        $row_data{id}                    = $av->{id};
272
	for (my $i=0; $i < $count; $i++){
203
        push(@loop_data, \%row_data);
273
        $sth->execute( $results->[$i]{id} );
204
    }
274
        my @selected_branches;
275
        while ( my $branch = $sth->fetchrow_hashref ) {
276
            push @selected_branches, $branch;
277
        }
278
		my %row_data;  # get a fresh hash for the row data
279
		$row_data{category}              = $results->[$i]{'category'};
280
		$row_data{authorised_value}      = $results->[$i]{'authorised_value'};
281
		$row_data{lib}                   = $results->[$i]{'lib'};
282
		$row_data{lib_opac}              = $results->[$i]{'lib_opac'};
283
		$row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} );
284
		$row_data{edit}                  = "$script_name?op=add_form&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
285
		$row_data{delete}                = "$script_name?op=delete_confirm&amp;searchfield=$searchfield&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
286
        $row_data{branches}              = \@selected_branches;
287
		push(@loop_data, \%row_data);
288
	}
289
205
290
	$template->param( loop     => \@loop_data,
206
    $template->param(
291
                          tab_list => $tab_list,
207
        loop     => \@loop_data,
292
                          category => $searchfield );
208
        category => $searchfield,
293
}
209
        categories => \@category_list,
210
    );
294
211
212
}
213
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-48 / +54 lines)
Lines 1-9 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Administration &rsaquo; Authorized values [% IF ( add_form ) %] &rsaquo; [% IF ( action_modify ) %]Modify authorized value[% END %]
2
<title>Koha &rsaquo; Administration &rsaquo; Authorized values
3
	   [% IF ( action_add_value ) %] &rsaquo;  New authorized value[% END %]
3
[% IF op == 'add_form' %]
4
	   [% IF ( action_add_category ) %] &rsaquo; New category[% END %][% END %]
4
  [% IF ( action_modify ) %] &rsaquo; Modify authorized value[% END %]
5
[% IF ( delete_confirm ) %] &rsaquo; Confirm deletion[% END %]
5
  [% IF ( action_add_value ) %] &rsaquo;  New authorized value[% END %]
6
[% IF ( else ) %]Authorized values[% END %]</title>
6
  [% IF ( action_add_category ) %] &rsaquo; New category[% END %]
7
[% END %]
8
</title>
7
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'doc-head-close.inc' %]
8
10
9
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
11
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
Lines 23-33 Link Here
23
        $("#branches option:first").attr("selected", "selected");
25
        $("#branches option:first").attr("selected", "selected");
24
    }
26
    }
25
    $('#icons').tabs();
27
    $('#icons').tabs();
28
29
    $("a.delete").click(function(){
30
        return confirm(_("Are you sure you want to delete this authorised value?"));
31
    });
26
});
32
});
27
//]]>
33
//]]>
28
</script>
34
</script>
29
35
30
[% IF ( else ) %]
36
[% IF op == 'list' %]
31
<script type="text/javascript">
37
<script type="text/javascript">
32
//<![CDATA[
38
//<![CDATA[
33
$(document).ready(function() {
39
$(document).ready(function() {
Lines 50-60 $(document).ready(function() { Link Here
50
<body id="admin_authorised_values" class="admin">
56
<body id="admin_authorised_values" class="admin">
51
[% INCLUDE 'header.inc' %]
57
[% INCLUDE 'header.inc' %]
52
[% INCLUDE 'cat-search.inc' %]
58
[% INCLUDE 'cat-search.inc' %]
53
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; [% IF ( add_form ) %] <a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a> &rsaquo; [% IF ( action_modify ) %]Modify authorized value[% END %]
59
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; [% IF op == 'add_form' %] <a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a> &rsaquo; [% IF ( action_modify ) %]Modify authorized value[% END %]
54
	   [% IF ( action_add_value ) %]New authorized value[% END %]
60
	   [% IF ( action_add_value ) %]New authorized value[% END %]
55
	   [% IF ( action_add_category ) %]New category[% END %][% END %]
61
	   [% IF ( action_add_category ) %]New category[% END %][% END %]
56
[% IF ( delete_confirm ) %] <a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a> &rsaquo; Confirm deletion[% END %]
62
[% IF op == 'list' %]Authorized values[% END %]</div>
57
[% IF ( else ) %]Authorized values[% END %]</div>
58
63
59
<div id="doc3" class="yui-t2">
64
<div id="doc3" class="yui-t2">
60
   
65
   
Lines 62-68 $(document).ready(function() { Link Here
62
	<div id="yui-main">
67
	<div id="yui-main">
63
	<div class="yui-b">
68
	<div class="yui-b">
64
69
65
[% IF ( add_form ) %]
70
[% IF op == 'add_form' %]
66
	<h1>
71
	<h1>
67
	   [% IF ( action_modify ) %]Modify authorized value[% END %]
72
	   [% IF ( action_modify ) %]Modify authorized value[% END %]
68
	   [% IF ( action_add_value ) %]New authorized value[% END %]
73
	   [% IF ( action_add_value ) %]New authorized value[% END %]
Lines 71-79 $(document).ready(function() { Link Here
71
76
72
    [% IF ( action_modify ) %]<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>[% END %]
77
    [% IF ( action_modify ) %]<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>[% END %]
73
78
74
	<form action="[% script_name %]" name="Aform" method="post">
79
 <form action="/cgi-bin/koha/admin/authorised_values.pl" name="Aform" method="post">
75
	<input type="hidden" name="op" value="add_validate" />
80
    <input type="hidden" name="op" value="add" />
76
    <input type="hidden" name="offset" value="[% offset %]" />
77
        <fieldset class="rows"><ol>
81
        <fieldset class="rows"><ol>
78
        <li>
82
        <li>
79
        [% IF ( action_add_category ) %]<label for="category">Category: </label>
83
        [% IF ( action_add_category ) %]<label for="category">Category: </label>
Lines 155-186 $(document).ready(function() { Link Here
155
[% END %]
159
[% END %]
156
160
157
161
158
[% IF ( delete_confirm ) %]
162
[% IF op == 'list' %]
159
	<div class="dialog alert">
160
<h3>Confirm deletion</h3>
161
<table>
162
	<tr>
163
		<th>Category</th>
164
		<th>Value</th>
165
		<th>Description</th>
166
		<th>Description (OPAC)</th>
167
	</tr>
168
	<tr>
169
	    <td>[% searchfield %]</td>
170
	    <td>[% Tvalue %]</td>
171
	    <td>[% Tlib %]</td>
172
	    <td>[% Tlib_opac %]</td>
173
	</tr>
174
	</table>
175
	<form action="[% script_name %]" method="post">
176
		<input type="hidden" name="op" value="delete_confirmed" />
177
		<input type="hidden" name="id" value="[% id %]" />
178
        <input type="hidden" name="searchfield" value="[% searchfield %]" /><fieldset class="action"><input type="submit" value="Yes, delete" class="approve" /></form>
179
<form action="[% script_name %]" method="get"><input type="hidden" name="searchfield" value="[% searchfield %]" /><input type="submit" value="No, do not delete" class="deny" /></form>
180
</div>
181
[% END %]
182
183
[% IF ( else ) %]
184
163
185
<div id="toolbar" class="btn-toolbar">
164
<div id="toolbar" class="btn-toolbar">
186
    <a id="addauth" class="btn btn-small" href= "/cgi-bin/koha/admin/authorised_values.pl?op=add_form&amp;category=[% category %]">New authorized value for [% category %]</a>
165
    <a id="addauth" class="btn btn-small" href= "/cgi-bin/koha/admin/authorised_values.pl?op=add_form&amp;category=[% category %]">New authorized value for [% category %]</a>
Lines 190-200 $(document).ready(function() { Link Here
190
<h1>Authorized values</h1>
169
<h1>Authorized values</h1>
191
<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>
170
<div class="note"><strong>NOTE:</strong> If you change an authorized value, existing records using it won't be updated.</div>
192
171
193
[% IF ( duplicate_category ) %]
172
[% FOR m IN messages %]
194
<div class="dialog alert">Could not add value &quot;[% duplicate_value %]&quot; for category &quot;[% duplicate_category %]&quot; &mdash; value already present.
173
    <div class="dialog [% m.type %]">
195
</div>
174
        [% SWITCH m.code %]
175
        [% CASE 'error_on_update' %]
176
            An error occurred when updating this authorised values. Perhaps the value already exists.
177
        [% CASE 'error_on_insert' %]
178
            An error occurred when inserting this authorised values. Perhaps the value or the category already exists.
179
        [% CASE 'error_on_delete' %]
180
            An error occurred when deleteing this authorised values. Check the logs.
181
        [% CASE 'success_on_update' %]
182
            Authorised value updated with success.
183
        [% CASE 'success_on_insert' %]
184
            Authorised value inserted with success.
185
        [% CASE 'success_on_delete' %]
186
            Authorised value deleted with success.
187
        [% CASE %]
188
            [% m.code %]
189
        [% END %]
190
    </div>
196
[% END %]
191
[% END %]
197
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category"><label for="searchfield">Show category: </label>[% tab_list %] <input type="submit" value="Submit" /></form>
192
193
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category">
194
  <label for="searchfield">Show category: </label>
195
  <select id="searchfield" name="searchfield">
196
  [% FOR c IN categories %]
197
    [% IF c == searchfield %]
198
      <option value="[% c %]" selected="selected">[% c %]</option>
199
    [% ELSE %]
200
      <option value="[% c %]">[% c %]</option>
201
    [% END %]
202
  [% END %]
203
  <input type="submit" value="Submit" />
204
</form>
198
[% IF ( category == 'Bsort1' ) %]
205
[% IF ( category == 'Bsort1' ) %]
199
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
206
    <p>An authorized value attached to patrons, that can be used for stats purposes</p>
200
[% END %]
207
[% END %]
Lines 273-280 $(document).ready(function() { Link Here
273
            No limitation
280
            No limitation
274
        [% END %]
281
        [% END %]
275
    </td>
282
    </td>
276
	<td><a href="[% loo.edit %]">Edit</a></td>
283
    <td><a href="/cgi-bin/koha/admin/authorised_values.pl?op=add_form&amp;id=[% loo.id %]">Edit</a></td>
277
	<td><a href="[% loo.delete %]">Delete</a></td>
284
    <td><a class="delete" href="/cgi-bin/koha/admin/authorised_values.pl?op=delete&amp;searchfield=[% searchfield %]&amp;id=[% loo.id %]">Delete</a></td>
278
</tr>
285
</tr>
279
[% END %]
286
[% END %]
280
</tbody></table>[% ELSE %]
287
</tbody></table>[% ELSE %]
Lines 282-289 $(document).ready(function() { Link Here
282
[% END %]
289
[% END %]
283
290
284
[% IF ( isprevpage ) %]
291
[% IF ( isprevpage ) %]
285
<form class="inline" action="[% script_name %]" method="post">
292
<form class="inline" action="/cgi-bin/koha/admin/authorised_values.pl" method="post">
286
<input type="hidden" name="offset" value="[% prevpage %]" /><input type="hidden" name="searchfield" value="[% searchfield %]" />
293
<input type="hidden" name="searchfield" value="[% searchfield %]" />
287
	<input type="submit" value="&lt;&lt; Previous" /></form>
294
	<input type="submit" value="&lt;&lt; Previous" /></form>
288
[% END %] 
295
[% END %] 
289
296
290
- 

Return to bug 10363