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

(-)a/Koha/AuthorisedValues.pm (-14 / +26 lines)
Lines 23-29 use Carp; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::Borrower;
26
use Koha::AuthorisedValue;
27
27
28
use base qw(Koha::Objects);
28
use base qw(Koha::Objects);
29
29
Lines 46-72 my @objects = Koha::AuthorisedValues->search($params); Link Here
46
sub search {
46
sub search {
47
    my ( $self, $params ) = @_;
47
    my ( $self, $params ) = @_;
48
48
49
    carp("No branchcode passed in for authorised values search!")
50
      unless $params->{branchcode};
51
52
    my $branchcode = $params->{branchcode};
49
    my $branchcode = $params->{branchcode};
53
    delete( $params->{branchcode} );
50
    delete( $params->{branchcode} );
54
51
55
    my $rs = $self->_resultset()->search(
52
    my $or =
56
        {
53
      $branchcode
57
            %$params,
54
      ? {
58
            -or => [
55
        '-or' => [
59
                'authorised_values_branches.branchcode' => undef,
56
            'authorised_values_branches.branchcode' => undef,
60
                'authorised_values_branches.branchcode' => $branchcode,
57
            'authorised_values_branches.branchcode' => $branchcode,
61
            ],
58
        ]
62
        },
59
      }
63
        { join => 'authorised_values_branches' }
60
      : {};
64
    );
61
    my $join = $branchcode ? { join => 'authorised_values_branches' } : {};
62
    my $rs = $self->_resultset()
63
      ->search( { %$params, %$or, }, $join );
65
64
66
    my $class = ref($self);
65
    my $class = ref($self);
67
    return wantarray ? $self->_wrap( $rs->all() ) : $class->new_from_dbic($rs);
66
    return wantarray ? $self->_wrap( $rs->all() ) : $class->new_from_dbic($rs);
68
}
67
}
69
68
69
sub categories {
70
    my ( $self ) = @_;
71
    my $rs = $self->_resultset->search(
72
        undef,
73
        {
74
            select => ['category'],
75
            distinct => 1,
76
            order_by => 'category',
77
        },
78
    );
79
    return map $_->get_column('category'), $rs->all;
80
}
81
70
=head3 type
82
=head3 type
71
83
72
=cut
84
=cut
(-)a/admin/authorised_values.pl (-199 / +114 lines)
Lines 17-24 Link Here
17
# 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
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use strict;
20
use Modern::Perl;
21
use warnings;
22
21
23
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
24
use C4::Auth;
23
use C4::Auth;
Lines 27-57 use C4::Context; Link Here
27
use C4::Koha;
26
use C4::Koha;
28
use C4::Output;
27
use C4::Output;
29
28
30
29
use Koha::AuthorisedValues;
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
30
46
my $input = new CGI;
31
my $input = new CGI;
47
my $id          = $input->param('id');
32
my $id          = $input->param('id');
48
my $op          = $input->param('op')     || '';
33
my $op          = $input->param('op') || 'list';
49
our $offset      = $input->param('offset') || 0;
34
my $searchfield = $input->param('searchfield');
50
our $searchfield = $input->param('searchfield');
51
$searchfield = '' unless defined $searchfield;
35
$searchfield = '' unless defined $searchfield;
52
$searchfield =~ s/\,//g;
36
$searchfield =~ s/\,//g;
53
our $script_name = "/cgi-bin/koha/admin/authorised_values.pl";
37
my @messages;
54
our $dbh = C4::Context->dbh;
55
38
56
our ($template, $borrowernumber, $cookie)= get_template_and_user({
39
our ($template, $borrowernumber, $cookie)= get_template_and_user({
57
    template_name => "admin/authorised_values.tt",
40
    template_name => "admin/authorised_values.tt",
Lines 62-92 our ($template, $borrowernumber, $cookie)= get_template_and_user({ Link Here
62
    debug => 1,
45
    debug => 1,
63
});
46
});
64
47
65
$template->param(  script_name => $script_name,
66
                 ($op||'else') => 1 );
67
################## ADD_FORM ##################################
48
################## ADD_FORM ##################################
68
# called by default. Used to create form to add or  modify a record
49
# called by default. Used to create form to add or  modify a record
69
if ($op eq 'add_form') {
50
if ($op eq 'add_form') {
70
	my $data;
51
    my ( $selected_branches, $category, $av );
71
    my @selected_branches;
52
    if ($id) {
72
	if ($id) {
53
        $av = Koha::AuthorisedValues->new->find( $id );
73
		my $sth=$dbh->prepare("select id, category, authorised_value, lib, lib_opac, imageurl from authorised_values where id=?");
54
        $selected_branches = $av->branch_limitations;
74
		$sth->execute($id);
55
    } else {
75
		$data=$sth->fetchrow_hashref;
56
        $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 = ?;");
57
    }
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
58
85
    my $branches = GetBranches;
59
    my $branches = GetBranches;
86
    my @branches_loop;
60
    my @branches_loop;
87
61
88
    foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
62
    foreach my $branchcode ( sort { uc($branches->{$a}->{branchname}) cmp uc($branches->{$b}->{branchname}) } keys %$branches ) {
89
        my $selected = ( grep {$_->{branchcode} eq $branchcode} @selected_branches ) ? 1 : 0;
63
        my $selected = ( grep {$_->{branchcode} eq $branchcode} @$selected_branches ) ? 1 : 0;
90
        push @branches_loop, {
64
        push @branches_loop, {
91
            branchcode => $branchcode,
65
            branchcode => $branchcode,
92
            branchname => $branches->{$branchcode}->{branchname},
66
            branchname => $branches->{$branchcode}->{branchname},
Lines 96-247 if ($op eq 'add_form') { Link Here
96
70
97
	if ($id) {
71
	if ($id) {
98
		$template->param(action_modify => 1);
72
		$template->param(action_modify => 1);
99
		$template->param('heading_modify_authorized_value_p' => 1);
73
   } elsif ( ! $category ) {
100
	} elsif ( ! $data->{'category'} ) {
101
		$template->param(action_add_category => 1);
74
		$template->param(action_add_category => 1);
102
		$template->param('heading_add_new_category_p' => 1);
103
	} else {
75
	} else {
104
		$template->param(action_add_value => 1);
76
		$template->param(action_add_value => 1);
105
		$template->param('heading_add_authorized_value_p' => 1);
106
	}
77
	}
107
	$template->param('use_heading_flags_p' => 1);
78
108
	$template->param( category        => $data->{'category'},
79
    if ( $av ) {
109
                         authorised_value => $data->{'authorised_value'},
80
        $template->param(
110
                         lib              => $data->{'lib'},
81
            category => $av->category,
111
                         lib_opac         => $data->{'lib_opac'},
82
            authorised_value => $av->authorised_value,
112
                         id               => $data->{'id'},
83
            lib              => $av->lib,
113
                         imagesets        => C4::Koha::getImageSets( checked => $data->{'imageurl'} ),
84
            lib_opac         => $av->lib_opac,
114
                         offset           => $offset,
85
            id               => $av->id,
115
                         branches_loop    => \@branches_loop,
86
            imagesets        => C4::Koha::getImageSets( checked => $av->imageurl ),
116
                     );
87
        );
117
                          
88
    } else {
118
################## ADD_VALIDATE ##################################
89
        $template->param(
119
# called by add_form, used to insert/modify data in DB
90
            category  => $category,
120
} elsif ($op eq 'add_validate') {
91
            imagesets => C4::Koha::getImageSets(),
92
        );
93
    }
94
    $template->param(
95
        branches_loop    => \@branches_loop,
96
    );
97
98
} elsif ($op eq 'add') {
121
    my $new_authorised_value = $input->param('authorised_value');
99
    my $new_authorised_value = $input->param('authorised_value');
122
    my $new_category = $input->param('category');
100
    my $new_category = $input->param('category');
123
    my $imageurl     = $input->param( 'imageurl' ) || '';
101
    my $imageurl     = $input->param( 'imageurl' ) || '';
124
	$imageurl = '' if $imageurl =~ /removeImage/;
102
    $imageurl = '' if $imageurl =~ /removeImage/;
125
    my $duplicate_entry = 0;
103
    my $duplicate_entry = 0;
126
    my @branches = $input->param('branches');
104
    my @branches = $input->param('branches');
127
105
128
    if ( $id ) { # Update
106
    if ( $id ) { # Update
129
        my $sth = $dbh->prepare( "SELECT category, authorised_value FROM authorised_values WHERE id = ? ");
107
        my $av = Koha::AuthorisedValues->new->find( $id );
130
        $sth->execute($id);
108
131
        my ($category, $authorised_value) = $sth->fetchrow_array();
109
        $av->lib( $input->param('lib') || undef );
132
        if ( $authorised_value ne $new_authorised_value ) {
110
        $av->lib_opac( $input->param('lib_opac') || undef );
133
            my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
111
        $av->category( $new_category );
134
                "WHERE category = ? AND authorised_value = ? and id <> ? ");
112
        $av->authorised_value( $new_authorised_value );
135
            $sth->execute($new_category, $new_authorised_value, $id);
113
        $av->imageurl( $imageurl );
136
            ($duplicate_entry) = $sth->fetchrow_array();
114
        eval{
137
        }
115
            $av->store;
138
        unless ( $duplicate_entry ) {
116
            $av->branch_limitations( \@branches );
139
            my $sth=$dbh->prepare( 'UPDATE authorised_values
117
        };
140
                                      SET category         = ?,
118
        if ( $@ ) {
141
                                          authorised_value = ?,
119
            push @messages, {type => 'error', code => 'error_on_update' };
142
                                          lib              = ?,
120
        } else {
143
                                          lib_opac         = ?,
121
            push @messages, { type => 'message', code => 'success_on_update' };
144
                                          imageurl         = ?
145
                                      WHERE id=?' );
146
            my $lib = $input->param('lib');
147
            my $lib_opac = $input->param('lib_opac');
148
            undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
149
            undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
150
            $sth->execute($new_category, $new_authorised_value, $lib, $lib_opac, $imageurl, $id);
151
            if ( @branches ) {
152
                $sth = $dbh->prepare("DELETE FROM authorised_values_branches WHERE av_id = ?");
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
            }
164
            $sth->finish;
165
            print $input->redirect("/cgi-bin/koha/admin/authorised_values.pl?searchfield=$new_category&amp;offset=$offset");
166
            exit;
167
        }
122
        }
168
    }
123
    }
169
    else { # Insert
124
    else { # Insert
170
        my $sth = $dbh->prepare_cached( "SELECT COUNT(*) FROM authorised_values " .
125
        my $av = Koha::AuthorisedValue->new( {
171
            "WHERE category = ? AND authorised_value = ? ");
126
            category => $new_category,
172
        $sth->execute($new_category, $new_authorised_value);
127
            authorised_value => $new_authorised_value,
173
        ($duplicate_entry) = $sth->fetchrow_array();
128
            lib => $input->param('lib') || undef,
174
        unless ( $duplicate_entry ) {
129
            lib_opac => $input->param('lib_opac') || undef,
175
            my $sth=$dbh->prepare( 'INSERT INTO authorised_values
130
            imageurl => $imageurl,
176
                                    ( category, authorised_value, lib, lib_opac, imageurl )
131
        } );
177
                                    values (?, ?, ?, ?, ?)' );
132
        eval {
178
    	    my $lib = $input->param('lib');
133
            $av->store;
179
    	    my $lib_opac = $input->param('lib_opac');
134
            $av->branch_limitations( \@branches );
180
    	    undef $lib if ($lib eq ""); # to insert NULL instead of a blank string
135
        };
181
    	    undef $lib_opac if ($lib_opac eq ""); # to insert NULL instead of a blank string
136
        if ( $@ ) {
182
            $sth->execute( $new_category, $new_authorised_value, $lib, $lib_opac, $imageurl );
137
            push @messages, {type => 'error', code => 'error_on_insert' };
183
            $id = $dbh->{'mysql_insertid'};
138
        } else {
184
            if ( @branches ) {
139
            push @messages, { type => 'message', code => 'success_on_insert' };
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
            my $category = $input->param('category');
196
            print $input->redirect("/cgi-bin/koha/admin/authorised_values.pl?searchfield=$category&amp;offset=$offset");
197
            exit;
198
        }
140
        }
199
    }
141
    }
200
    if ( $duplicate_entry ) {       
201
        $template->param(duplicate_category => $new_category,
202
                         duplicate_value =>  $new_authorised_value,
203
                         else => 1);
204
        default_form();
205
     }           
206
	
207
################## DELETE_CONFIRM ##################################
208
# called by default form, used to confirm deletion of data in DB
209
} elsif ($op eq 'delete_confirm') {
210
	my $sth=$dbh->prepare("select category,authorised_value,lib,lib_opac from authorised_values where id=?");
211
	$sth->execute($id);
212
	my $data=$sth->fetchrow_hashref;
213
	$id = $input->param('id') unless $id;
214
	$template->param(searchfield => $searchfield,
215
							Tlib => $data->{'lib'},
216
							Tlib_opac => $data->{'lib_opac'},
217
							Tvalue => $data->{'authorised_value'},
218
							id =>$id,
219
							);
220
142
221
													# END $OP eq DELETE_CONFIRM
143
    $op = 'list';
222
################## DELETE_CONFIRMED ##################################
144
    $searchfield = $new_category;
223
# called by delete_confirm, used to effectively confirm deletion of data in DB
145
} elsif ($op eq 'delete') {
224
} elsif ($op eq 'delete_confirmed') {
146
    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
225
	my $id = $input->param('id');
147
    my $deleted = eval {$av->delete};
226
	my $sth=$dbh->prepare("delete from authorised_values where id=?");
148
    if ( $@ or not $deleted ) {
227
	$sth->execute($id);
149
        push @messages, {type => 'error', code => 'error_on_delete' };
228
    print $input->redirect("/cgi-bin/koha/admin/authorised_values.pl?searchfield=$searchfield&amp;offset=$offset");
150
    } else {
229
    exit;
151
        push @messages, { type => 'message', code => 'success_on_delete' };
230
													# END $OP eq DELETE_CONFIRMED
152
    }
231
################## DEFAULT ##################################
232
} else { # DEFAULT
233
    default_form();
234
} #---- END $OP eq DEFAULT
235
output_html_with_http_headers $input, $cookie, $template->output;
236
153
237
exit 0;
154
    $op = 'list';
155
    $template->param( delete_success => 1 );
156
}
157
158
$template->param(
159
    op => $op,
160
    searchfield => $searchfield,
161
    messages => \@messages,
162
);
238
163
239
sub default_form {
164
if ( $op eq 'list' ) {
240
    # build categories list
165
    # build categories list
241
    my $category_list = C4::Koha::GetAuthorisedValueCategories();
166
    my @categories = Koha::AuthorisedValues->new->categories;
242
    my @category_list = @{$category_list};
167
    my @category_list;
243
    my %categories;    # a hash, to check that some hardcoded categories exist.
168
    my %categories;    # a hash, to check that some hardcoded categories exist.
244
    for my $category ( @category_list ) {
169
    for my $category ( @categories ) {
170
        push( @category_list, $category );
245
        $categories{$category} = 1;
171
        $categories{$category} = 1;
246
    }
172
    }
247
173
Lines 250-291 sub default_form { Link Here
250
        push @category_list, $_ unless $categories{$_};
176
        push @category_list, $_ unless $categories{$_};
251
    }
177
    }
252
178
253
	#reorder the list
179
    #reorder the list
254
    @category_list = sort {lc($a) cmp lc($b)} @category_list;
180
    @category_list = sort {$a cmp $b} @category_list;
255
	if (!$searchfield) {
181
256
		$searchfield=$category_list[0];
182
    $searchfield ||= $category_list[0];
257
	}
183
258
    my $tab_list = {
184
    my @avs_by_category = Koha::AuthorisedValues->new->search( { category => $searchfield } );
259
        values  => \@category_list,
185
    my @loop_data = ();
260
        default => $searchfield,
186
    # builds value list
261
    };
187
    for my $av ( @avs_by_category ) {
262
    my ($results) = AuthorizedValuesForCategory($searchfield);
188
        my %row_data;  # get a fresh hash for the row data
263
    my $count = scalar(@$results);
189
        $row_data{category}              = $av->category;
264
	my @loop_data = ();
190
        $row_data{authorised_value}      = $av->authorised_value;
265
	# builds value list
191
        $row_data{lib}                   = $av->lib;
266
    my $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 = ?");
192
        $row_data{lib_opac}              = $av->lib_opac;
267
	for (my $i=0; $i < $count; $i++){
193
        $row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $av->imageurl );
268
        $sth->execute( $results->[$i]{id} );
194
        $row_data{branches}              = $av->branch_limitations;
269
        my @selected_branches;
195
        $row_data{id}                    = $av->id;
270
        while ( my $branch = $sth->fetchrow_hashref ) {
196
        push(@loop_data, \%row_data);
271
            push @selected_branches, $branch;
197
    }
272
        }
273
		my %row_data;  # get a fresh hash for the row data
274
		$row_data{category}              = $results->[$i]{'category'};
275
		$row_data{authorised_value}      = $results->[$i]{'authorised_value'};
276
		$row_data{lib}                   = $results->[$i]{'lib'};
277
		$row_data{lib_opac}              = $results->[$i]{'lib_opac'};
278
		$row_data{imageurl}              = getitemtypeimagelocation( 'intranet', $results->[$i]{'imageurl'} );
279
		$row_data{edit}                  = "$script_name?op=add_form&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
280
		$row_data{delete}                = "$script_name?op=delete_confirm&amp;searchfield=$searchfield&amp;id=".$results->[$i]{'id'}."&amp;offset=$offset";
281
        $row_data{branches}              = \@selected_branches;
282
		push(@loop_data, \%row_data);
283
	}
284
198
285
    $template->param(
199
    $template->param(
286
            loop     => \@loop_data,
200
        loop     => \@loop_data,
287
            tab_list => $tab_list,
201
        category => $searchfield,
288
            category => $searchfield,
202
        categories => \@category_list,
289
    );
203
    );
290
}
291
204
205
}
206
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt (-55 / +50 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 code, existing records using it won't be updated. Changes to value descriptions will show immediately.</div>[% END %]
77
    [% IF ( action_modify ) %]<div class="note"><strong>NOTE:</strong> If you change an authorized value code, existing records using it won't be updated. Changes to value descriptions will show immediately.</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 %]"><i class="icon-plus"> </i> 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 %]"><i class="icon-plus"> </i> New authorized value for [% category %]</a>
Lines 190-211 $(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 code, existing records using it won't be updated. Changes to value descriptions will show immediately.</div>
170
<div class="note"><strong>NOTE:</strong> If you change an authorized value code, existing records using it won't be updated. Changes to value descriptions will show immediately.</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 %]
192
197
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category">
193
<form action="/cgi-bin/koha/admin/authorised_values.pl" method="post" id="category">
198
    <label for="searchfield">Show category: </label>
194
  <label for="searchfield">Show category: </label>
199
    <select name="searchfield" id="searchfield" size="1">
195
  <select name="searchfield" id="searchfield" size="1">
200
    [% FOREACH value IN tab_list.values %]
196
  [% FOR c IN categories %]
201
    [% IF ( value == tab_list.default ) %]
197
    [% IF c == searchfield %]
202
        <option value="[% value %]" selected="selected">[% value %]</option>
198
      <option value="[% c %]" selected="selected">[% c %]</option>
203
    [% ELSE %]
199
    [% ELSE %]
204
        <option value="[% value %]">[% value %]</option>
200
      <option value="[% c %]">[% c %]</option>
205
    [% END %]
206
    [% END %]
201
    [% END %]
207
    </select>
202
  [% END %]
208
    <input type="submit" value="Submit" />
203
  <input type="submit" value="Submit" />
209
</form>
204
</form>
210
[% IF ( category == 'Bsort1' ) %]
205
[% IF ( category == 'Bsort1' ) %]
211
    <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>
Lines 285-292 $(document).ready(function() { Link Here
285
            No limitation
280
            No limitation
286
        [% END %]
281
        [% END %]
287
    </td>
282
    </td>
288
	<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>
289
	<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>
290
</tr>
285
</tr>
291
[% END %]
286
[% END %]
292
</tbody></table>[% ELSE %]
287
</tbody></table>[% ELSE %]
Lines 294-301 $(document).ready(function() { Link Here
294
[% END %]
289
[% END %]
295
290
296
[% IF ( isprevpage ) %]
291
[% IF ( isprevpage ) %]
297
<form class="inline" action="[% script_name %]" method="post">
292
<form class="inline" action="/cgi-bin/koha/admin/authorised_values.pl" method="post">
298
<input type="hidden" name="offset" value="[% prevpage %]" /><input type="hidden" name="searchfield" value="[% searchfield %]" />
293
<input type="hidden" name="searchfield" value="[% searchfield %]" />
299
	<input type="submit" value="&lt;&lt; Previous" /></form>
294
	<input type="submit" value="&lt;&lt; Previous" /></form>
300
[% END %] 
295
[% END %] 
301
296
(-)a/t/db_dependent/AuthorisedValues.t (-3 / +16 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More;    # tests => 25;
4
use Test::More tests => 14;
5
5
6
use C4::Context;
6
use C4::Context;
7
use Koha::AuthorisedValue;
7
use Koha::AuthorisedValue;
Lines 44-52 my $av3 = Koha::AuthorisedValue->new( Link Here
44
    }
44
    }
45
)->store();
45
)->store();
46
46
47
my $av4 = Koha::AuthorisedValue->new(
48
    {
49
        category         => 'aaav_for_testing',
50
        authorised_value => 'value 4',
51
        lib              => 'display value 4',
52
        lib_opac         => 'opac display value 4',
53
        imageurl         => 'image4.png',
54
    }
55
)->store();
56
47
ok( $av1->id(), 'AV 1 is inserted' );
57
ok( $av1->id(), 'AV 1 is inserted' );
48
ok( $av2->id(), 'AV 2 is inserted' );
58
ok( $av2->id(), 'AV 2 is inserted' );
49
ok( $av3->id(), 'AV 3 is inserted' );
59
ok( $av3->id(), 'AV 3 is inserted' );
60
ok( $av4->id(), 'AV 4 is inserted' );
50
61
51
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
62
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
52
$av3->lib_opac('');
63
$av3->lib_opac('');
Lines 80-83 $av1->branch_limitations( [ $branchcode1, $branchcode2 ] ); Link Here
80
my $limits = $av1->branch_limitations;
91
my $limits = $av1->branch_limitations;
81
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
92
is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
82
93
83
done_testing;
94
my @categories = Koha::AuthorisedValues->new->categories;
95
is( @categories, 2, 'There should have 2 categories inserted' );
96
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' );
97
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );
84
- 

Return to bug 10363