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

(-)a/admin/categorie.pl (-215 / +289 lines)
Lines 6-40 Link Here
6
# ALGO :
6
# ALGO :
7
# this script use an $op to know what to do.
7
# this script use an $op to know what to do.
8
# if $op is empty or none of the above values,
8
# if $op is empty or none of the above values,
9
#	- the default screen is build (with all records, or filtered datas).
9
#    - the default screen is built
10
#	- the   user can clic on add, modify or delete record.
10
#       (with all records, or filtered datas).
11
#    - the user can click on add, modify or delete record.
11
# if $op=add_form
12
# if $op=add_form
12
#	- if primkey exists, this is a modification,so we read the $primkey record
13
#    - if primkey exists, this is a modification, so we read
13
#	- builds the add/modify form
14
#       the $primkey record
15
#    - builds the add/modify form
14
# if $op=add_validate
16
# if $op=add_validate
15
#	- the user has just send datas, so we create/modify the record
17
#    - the user has just send datas, so we create or modify
18
#       the record
16
# if $op=delete_form
19
# if $op=delete_form
17
#	- we show the record having primkey=$primkey and ask for deletion validation form
20
#    - we show the record having primkey=$primkey and ask for
21
#       deletion validation form
18
# if $op=delete_confirm
22
# if $op=delete_confirm
19
#	- we delete the record having primkey=$primkey
23
#    - we delete the record having primkey=$primkey
20
24
21
22
# Copyright 2000-2002 Katipo Communications
23
#
24
# This file is part of Koha.
25
# This file is part of Koha.
25
#
26
#
26
# Koha is free software; you can redistribute it and/or modify it under the
27
# Copyright 2000-2002 Katipo Communications
27
# terms of the GNU General Public License as published by the Free Software
28
# Copyright (C) 2014  Mark Tompsett
28
# Foundation; either version 2 of the License, or (at your option) any later
29
#
29
# version.
30
# Koha is free software; you can redistribute it and/or modify it
31
# under the terms of the GNU General Public License as published by
32
# the Free Software Foundation; either version 3 of the License, or
33
# (at your option) any later version.
30
#
34
#
31
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
35
# Koha is distributed in the hope that it will be useful, but
32
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
36
# WITHOUT ANY WARRANTY; without even the implied warranty of
33
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
37
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38
# GNU General Public License for more details.
34
#
39
#
35
# You should have received a copy of the GNU General Public License along
40
# You should have received a copy of the GNU General Public License
36
# with Koha; if not, write to the Free Software Foundation, Inc.,
41
# along with Koha; if not, see <http://www.gnu.org/licenses>.
37
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38
42
39
use Modern::Perl;
43
use Modern::Perl;
40
44
Lines 46-307 use C4::Output; Link Here
46
use C4::Dates;
50
use C4::Dates;
47
use C4::Form::MessagingPreferences;
51
use C4::Form::MessagingPreferences;
48
52
49
sub StringSearch  {
53
sub StringSearch {
50
	my ($searchstring,$type)=@_;
54
    my ( $searchstring, $type ) = @_;
51
	my $dbh = C4::Context->dbh;
55
    my $dbh = C4::Context->dbh;
52
        $searchstring //= '';
56
    $searchstring //= '';
53
	$searchstring=~ s/\'/\\\'/g;
57
    $searchstring =~ s/\'/\\\'/g;
54
	my @data=split(' ',$searchstring);
58
    my @data = split( ' ', $searchstring );
55
        push @data,q{} if $#data==-1;
59
    push @data, q{} if $#data == -1;
56
	my $count=@data;
60
    my $count = @data;
57
	my $sth=$dbh->prepare("Select * from categories where (description like ?) order by category_type,description,categorycode");
61
    my $sth   = $dbh->prepare("Select * from categories where (description like ?) order by category_type,description,categorycode");
58
	$sth->execute("$data[0]%");
62
    $sth->execute("$data[0]%");
59
	my @results;
63
    my @results;
60
	while (my $data=$sth->fetchrow_hashref){
61
	push(@results,$data);
62
	}
63
	#  $sth->execute;
64
	$sth->finish;
65
	return (scalar(@results),\@results);
66
}
67
64
68
my $input = new CGI;
65
    while ( my $data = $sth->fetchrow_hashref ) {
69
my $searchfield=$input->param('description');
66
        push( @results, $data );
70
my $script_name="/cgi-bin/koha/admin/categorie.pl";
67
    }
71
my $categorycode=$input->param('categorycode');
72
my $op = $input->param('op') // '';
73
68
74
my ($template, $loggedinuser, $cookie)
69
    #  $sth->execute;
75
    = get_template_and_user({template_name => "admin/categorie.tmpl",
70
    $sth->finish;
76
			     query => $input,
71
    return ( scalar(@results), \@results );
77
			     type => "intranet",
72
}
78
			     authnotrequired => 0,
79
                 flagsrequired => {parameters => 'parameters_remaining_permissions'},
80
			     debug => 1,
81
			     });
82
73
74
my $input        = new CGI;
75
my $searchfield  = $input->param('description');
76
my $script_name  = "/cgi-bin/koha/admin/categorie.pl";
77
my $categorycode = $input->param('categorycode');
78
my $op           = $input->param('op') // '';
83
79
84
$template->param(script_name => $script_name,
80
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85
		 categorycode => $categorycode,
81
    {
86
		 searchfield => $searchfield);
82
        template_name   => "admin/categorie.tmpl",
83
        query           => $input,
84
        type            => "intranet",
85
        authnotrequired => 0,
86
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
87
        debug           => 1,
88
    }
89
);
87
90
91
$template->param(
92
    script_name  => $script_name,
93
    categorycode => $categorycode,
94
    searchfield  => $searchfield
95
);
88
96
89
################## ADD_FORM ##################################
97
################## ADD_FORM ##################################
90
# called by default. Used to create form to add or  modify a record
98
# called by default. Used to create form to add or  modify a record
91
if ($op eq 'add_form') {
99
if ( $op eq 'add_form' ) {
92
	$template->param(add_form => 1);
100
    $template->param( add_form => 1 );
93
	
101
94
	#---- if primkey exists, it's a modify action, so read values to modify...
102
    #---- if primkey exists, it's a modify action, so read values to modify...
95
	my $data;
103
    my $data;
96
    my @selected_branches;
104
    my @selected_branches;
97
	if ($categorycode) {
105
    if ($categorycode) {
98
		my $dbh = C4::Context->dbh;
106
        my $dbh = C4::Context->dbh;
99
		my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
107
        my $sth = $dbh->prepare(
100
		$sth->execute($categorycode);
108
"select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"
101
		$data=$sth->fetchrow_hashref;
109
        );
110
        $sth->execute($categorycode);
111
        $data = $sth->fetchrow_hashref;
102
112
103
        $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?");
113
        $sth = $dbh->prepare(
104
        $sth->execute( $categorycode );
114
"SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?"
115
        );
116
        $sth->execute($categorycode);
105
        while ( my $branch = $sth->fetchrow_hashref ) {
117
        while ( my $branch = $sth->fetchrow_hashref ) {
106
            push @selected_branches, $branch;
118
            push @selected_branches, $branch;
107
        }
119
        }
108
        $sth->finish;
120
        $sth->finish;
109
    }
121
    }
110
122
111
    $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} && $data->{'enrolmentperioddate'} eq '0000-00-00');
123
    if ( $data->{'enrolmentperioddate'} &&
124
         $data->{'enrolmentperioddate'} eq '0000-00-00' ) {
125
        $data->{'enrolmentperioddate'} = undef;
126
    }
112
    $data->{'category_type'} //= '';
127
    $data->{'category_type'} //= '';
113
128
114
    my $branches = GetBranches;
129
    my $branches = GetBranches;
115
    my @branches_loop;
130
    my @branches_loop;
116
    foreach my $branch (sort keys %$branches) {
131
    foreach my $branch ( sort keys %$branches ) {
117
        my $selected = ( grep {$$_{branchcode} eq $branch} @selected_branches ) ? 1 : 0;
132
        my $selected =
118
        push @branches_loop, {
133
          ( grep { $$_{branchcode} eq $branch } @selected_branches ) ? 1 : 0;
134
        push @branches_loop,
135
          {
119
            branchcode => $$branches{$branch}{branchcode},
136
            branchcode => $$branches{$branch}{branchcode},
120
            branchname => $$branches{$branch}{branchname},
137
            branchname => $$branches{$branch}{branchname},
121
            selected => $selected,
138
            selected   => $selected,
122
        };
139
          };
123
    }
140
    }
124
141
125
	$template->param(description        => $data->{'description'},
142
    $template->param(
126
				enrolmentperiod         => $data->{'enrolmentperiod'},
143
        description         => $data->{'description'},
127
				enrolmentperioddate     => $data->{'enrolmentperioddate'},
144
        enrolmentperiod     => $data->{'enrolmentperiod'},
128
				upperagelimit           => $data->{'upperagelimit'},
145
        enrolmentperioddate => $data->{'enrolmentperioddate'},
129
				dateofbirthrequired     => $data->{'dateofbirthrequired'},
146
        upperagelimit       => $data->{'upperagelimit'},
130
				enrolmentfee            => sprintf("%.2f",$data->{'enrolmentfee'} || 0),
147
        dateofbirthrequired => $data->{'dateofbirthrequired'},
131
				overduenoticerequired   => $data->{'overduenoticerequired'},
148
        enrolmentfee        => sprintf( "%.2f", $data->{'enrolmentfee'} || 0 ),
132
				issuelimit              => $data->{'issuelimit'},
149
        overduenoticerequired => $data->{'overduenoticerequired'},
133
				reservefee              => sprintf("%.2f",$data->{'reservefee'} || 0),
150
        issuelimit            => $data->{'issuelimit'},
134
                                hidelostitems           => $data->{'hidelostitems'},
151
        reservefee            => sprintf( "%.2f", $data->{'reservefee'} || 0 ),
135
				category_type           => $data->{'category_type'},
152
        hidelostitems         => $data->{'hidelostitems'},
136
                SMSSendDriver => C4::Context->preference("SMSSendDriver"),
153
        category_type         => $data->{'category_type'},
137
                TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"),
154
        SMSSendDriver         => C4::Context->preference("SMSSendDriver"),
138
				"type_".$data->{'category_type'} => 1,
155
        TalkingTechItivaPhone =>
139
                branches_loop           => \@branches_loop,
156
          C4::Context->preference("TalkingTechItivaPhoneNotification"),
140
				);
157
        "type_" . $data->{'category_type'} => 1,
141
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
158
        branches_loop                      => \@branches_loop,
142
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template);
159
    );
160
    if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
161
        C4::Form::MessagingPreferences::set_form_values(
162
            { categorycode => $categorycode }, $template );
143
    }
163
    }
144
													# END $OP eq ADD_FORM
164
165
# END $OP eq ADD_FORM
145
################## ADD_VALIDATE ##################################
166
################## ADD_VALIDATE ##################################
146
# called by add_form, used to insert/modify data in DB
167
# called by add_form, used to insert/modify data in DB
147
} elsif ($op eq 'add_validate') {
168
}
148
	$template->param(add_validate => 1);
169
elsif ( $op eq 'add_validate' ) {
149
	my $is_a_modif = $input->param("is_a_modif");
170
    $template->param( add_validate => 1 );
150
	my $dbh = C4::Context->dbh;
171
    my $is_a_modif = $input->param("is_a_modif");
151
	if($input->param('enrolmentperioddate')){
172
    my $dbh        = C4::Context->dbh;
152
	    $input->param('enrolmentperioddate' => C4::Dates::format_date_in_iso($input->param('enrolmentperioddate')) );
173
    if ( $input->param('enrolmentperioddate') ) {
153
	}
174
        $input->param(
154
	
175
            'enrolmentperioddate' => C4::Dates::format_date_in_iso(
155
	if ($is_a_modif) {
176
                $input->param('enrolmentperioddate')
156
            my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?");
177
            )
157
            $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode'));
178
        );
158
            my @branches = $input->param("branches");
179
    }
159
            if ( @branches ) {
180
160
                $sth = $dbh->prepare("DELETE FROM categories_branches WHERE categorycode = ?");
181
    if ($is_a_modif) {
161
                $sth->execute( $input->param( "categorycode" ) );
182
        my $sth = $dbh->prepare(
162
                $sth = $dbh->prepare(
183
"UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"
163
                    "INSERT INTO categories_branches
184
        );
185
        $sth->execute(
186
            map { $input->param($_) } (
187
                'description',           'enrolmentperiod',
188
                'enrolmentperioddate',   'upperagelimit',
189
                'dateofbirthrequired',   'enrolmentfee',
190
                'reservefee',            'hidelostitems',
191
                'overduenoticerequired', 'category_type',
192
                'categorycode'
193
            )
194
        );
195
        my @branches = $input->param("branches");
196
        if (@branches) {
197
            $sth = $dbh->prepare(
198
                "DELETE FROM categories_branches WHERE categorycode = ?");
199
            $sth->execute( $input->param("categorycode") );
200
            $sth = $dbh->prepare(
201
                "INSERT INTO categories_branches
164
                                ( categorycode, branchcode )
202
                                ( categorycode, branchcode )
165
                                VALUES ( ?, ? )"
203
                                VALUES ( ?, ? )"
166
                );
204
            );
167
                for my $branchcode ( @branches ) {
205
            for my $branchcode (@branches) {
168
                    next if not $branchcode;
206
                next if not $branchcode;
169
                    $sth->bind_param( 1, $input->param( "categorycode" ) );
207
                $sth->bind_param( 1, $input->param("categorycode") );
170
                    $sth->bind_param( 2, $branchcode );
208
                $sth->bind_param( 2, $branchcode );
171
                    $sth->execute;
209
                $sth->execute;
172
                }
173
            }
210
            }
174
            $sth->finish;
175
        } else {
176
            my $sth=$dbh->prepare("INSERT INTO categories  (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)");
177
            $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type'));
178
            $sth->finish;
179
        }
211
        }
180
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
212
        $sth->finish;
181
        C4::Form::MessagingPreferences::handle_form_action($input, 
213
    }
182
                                                           { categorycode => $input->param('categorycode') }, $template);
214
    else {
215
        my $sth = $dbh->prepare(
216
"INSERT INTO categories  (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"
217
        );
218
        $sth->execute(
219
            map { $input->param($_) } (
220
                'categorycode',    'description',
221
                'enrolmentperiod', 'enrolmentperioddate',
222
                'upperagelimit',   'dateofbirthrequired',
223
                'enrolmentfee',    'reservefee',
224
                'hidelostitems',   'overduenoticerequired',
225
                'category_type'
226
            )
227
        );
228
        $sth->finish;
229
    }
230
    if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
231
        C4::Form::MessagingPreferences::handle_form_action( $input,
232
            { categorycode => $input->param('categorycode') }, $template );
183
    }
233
    }
184
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
234
    print
185
	exit;
235
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
236
    exit;
186
237
187
													# END $OP eq ADD_VALIDATE
238
# END $OP eq ADD_VALIDATE
188
################## DELETE_CONFIRM ##################################
239
################## DELETE_CONFIRM ##################################
189
# called by default form, used to confirm deletion of data in DB
240
# called by default form, used to confirm deletion of data in DB
190
} elsif ($op eq 'delete_confirm') {
241
}
191
	$template->param(delete_confirm => 1);
242
elsif ( $op eq 'delete_confirm' ) {
243
    $template->param( delete_confirm => 1 );
192
244
193
	my $dbh = C4::Context->dbh;
245
    my $dbh = C4::Context->dbh;
194
	my $sth=$dbh->prepare("select count(*) as total from borrowers where categorycode=?");
246
    my $sth = $dbh->prepare(
195
	$sth->execute($categorycode);
247
        "select count(*) as total from borrowers where categorycode=?");
196
	my $total = $sth->fetchrow_hashref;
248
    $sth->execute($categorycode);
197
	$sth->finish;
249
    my $total = $sth->fetchrow_hashref;
198
	$template->param(total => $total->{'total'});
250
    $sth->finish;
199
	
251
    $template->param( total => $total->{'total'} );
200
	my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
201
	$sth2->execute($categorycode);
202
	my $data=$sth2->fetchrow_hashref;
203
	$sth2->finish;
204
	if ($total->{'total'} >0) {
205
		$template->param(totalgtzero => 1);
206
	}
207
252
208
    $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} && $data->{'enrolmentperioddate'} eq '0000-00-00');
253
    my $sth2 = $dbh->prepare(
209
        $template->param(       description             => $data->{'description'},
254
"select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"
210
                                enrolmentperiod         => $data->{'enrolmentperiod'},
255
    );
211
                                enrolmentperioddate     => $data->{'enrolmentperioddate'},
256
    $sth2->execute($categorycode);
212
                                upperagelimit           => $data->{'upperagelimit'},
257
    my $data = $sth2->fetchrow_hashref;
213
                                dateofbirthrequired     => $data->{'dateofbirthrequired'},
258
    $sth2->finish;
214
                                enrolmentfee            =>  sprintf("%.2f",$data->{'enrolmentfee'}),
259
    if ( $total->{'total'} > 0 ) {
215
                                overduenoticerequired   => $data->{'overduenoticerequired'},
260
        $template->param( totalgtzero => 1 );
216
                                issuelimit              => $data->{'issuelimit'},
261
    }
217
                                reservefee              =>  sprintf("%.2f",$data->{'reservefee'}),
262
218
                                hidelostitems           => $data->{'hidelostitems'},
263
    if ( $data->{'enrolmentperioddate'} &&
219
                                category_type           => $data->{'category_type'},
264
         $data->{'enrolmentperioddate'} eq '0000-00-00' ) {
220
                                );
265
        $data->{'enrolmentperioddate'} = undef;
221
													# END $OP eq DELETE_CONFIRM
266
    }
267
    $template->param(
268
        description           => $data->{'description'},
269
        enrolmentperiod       => $data->{'enrolmentperiod'},
270
        enrolmentperioddate   => $data->{'enrolmentperioddate'},
271
        upperagelimit         => $data->{'upperagelimit'},
272
        dateofbirthrequired   => $data->{'dateofbirthrequired'},
273
        enrolmentfee          => sprintf( "%.2f", $data->{'enrolmentfee'} ),
274
        overduenoticerequired => $data->{'overduenoticerequired'},
275
        issuelimit            => $data->{'issuelimit'},
276
        reservefee            => sprintf( "%.2f", $data->{'reservefee'} ),
277
        hidelostitems         => $data->{'hidelostitems'},
278
        category_type         => $data->{'category_type'},
279
    );
280
281
# END $OP eq DELETE_CONFIRM
222
################## DELETE_CONFIRMED ##################################
282
################## DELETE_CONFIRMED ##################################
223
# called by delete_confirm, used to effectively confirm deletion of data in DB
283
# called by delete_confirm, used to effectively confirm deletion
224
} elsif ($op eq 'delete_confirmed') {
284
# of data in DB
225
	$template->param(delete_confirmed => 1);
285
}
226
	my $dbh = C4::Context->dbh;
286
elsif ( $op eq 'delete_confirmed' ) {
227
	my $categorycode=uc($input->param('categorycode'));
287
    $template->param( delete_confirmed => 1 );
228
	my $sth=$dbh->prepare("delete from categories where categorycode=?");
288
    my $dbh          = C4::Context->dbh;
229
	$sth->execute($categorycode);
289
    my $categorycode = uc( $input->param('categorycode') );
230
	$sth->finish;
290
    my $sth = $dbh->prepare("delete from categories where categorycode=?");
231
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
291
    $sth->execute($categorycode);
232
	exit;
292
    $sth->finish;
293
    print
294
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
295
    exit;
233
296
234
													# END $OP eq DELETE_CONFIRMED
297
# END $OP eq DELETE_CONFIRMED
235
} else { # DEFAULT
298
}
236
	$template->param(else => 1);
299
else {    # DEFAULT
237
	my @loop;
300
    $template->param( else => 1 );
238
	my ($count,$results)=StringSearch($searchfield,'web');
301
    my @loop;
302
    my ( $count, $results ) = StringSearch( $searchfield, 'web' );
239
    my $dbh = C4::Context->dbh;
303
    my $dbh = C4::Context->dbh;
240
    my $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?");
304
    my $sth = $dbh->prepare(
241
	for (my $i=0; $i < $count; $i++){
305
"SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?"
306
    );
307
    for ( my $i = 0 ; $i < $count ; $i++ ) {
242
        $sth->execute( $results->[$i]{'categorycode'} );
308
        $sth->execute( $results->[$i]{'categorycode'} );
243
        my @selected_branches;
309
        my @selected_branches;
244
        while ( my $branch = $sth->fetchrow_hashref ) {
310
        while ( my $branch = $sth->fetchrow_hashref ) {
245
            push @selected_branches, $branch;
311
            push @selected_branches, $branch;
246
        }
312
        }
247
        my $enrolmentperioddate = $results->[$i]{'enrolmentperioddate'};
313
        my $enrolmentperioddate = $results->[$i]{'enrolmentperioddate'};
248
        if (defined($enrolmentperioddate) && $enrolmentperioddate eq '0000-00-00') {
314
        if ( $enrolmentperioddate &&
315
             $enrolmentperioddate eq '0000-00-00' ) {
249
            $enrolmentperioddate = undef;
316
            $enrolmentperioddate = undef;
250
        }
317
        }
251
		my %row = (
318
        $results->[$i]{'category_type'} //= '';
252
		        categorycode            => $results->[$i]{'categorycode'},
319
        my %row = (
253
				description             => $results->[$i]{'description'},
320
            categorycode        => $results->[$i]{'categorycode'},
254
				enrolmentperiod         => $results->[$i]{'enrolmentperiod'},
321
            description         => $results->[$i]{'description'},
255
				enrolmentperioddate     => $enrolmentperioddate,
322
            enrolmentperiod     => $results->[$i]{'enrolmentperiod'},
256
				upperagelimit           => $results->[$i]{'upperagelimit'},
323
            enrolmentperioddate => $enrolmentperioddate,
257
				dateofbirthrequired     => $results->[$i]{'dateofbirthrequired'},
324
            upperagelimit       => $results->[$i]{'upperagelimit'},
258
				enrolmentfee            => sprintf("%.2f",$results->[$i]{'enrolmentfee'}),
325
            dateofbirthrequired => $results->[$i]{'dateofbirthrequired'},
259
				overduenoticerequired   => $results->[$i]{'overduenoticerequired'},
326
            enrolmentfee => sprintf( "%.2f", $results->[$i]{'enrolmentfee'} || 0),
260
				issuelimit              => $results->[$i]{'issuelimit'},
327
            overduenoticerequired => $results->[$i]{'overduenoticerequired'},
261
				reservefee              => sprintf("%.2f",$results->[$i]{'reservefee'}),
328
            issuelimit            => $results->[$i]{'issuelimit'},
262
                                hidelostitems           => $results->[$i]{'hidelostitems'},
329
            reservefee    => sprintf( "%.2f", $results->[$i]{'reservefee'} || 0),
263
				category_type           => $results->[$i]{'category_type'},
330
            hidelostitems => $results->[$i]{'hidelostitems'},
264
                "type_".$results->[$i]{'category_type'} => 1,
331
            category_type => $results->[$i]{'category_type'},
265
                branches                => \@selected_branches,
332
            "type_" . $results->[$i]{'category_type'} => 1,
333
            branches                                  => \@selected_branches,
266
        );
334
        );
267
        if (C4::Context->preference('EnhancedMessagingPreferences')) {
335
        if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
268
            my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'});
336
            my $brief_prefs =
337
              _get_brief_messaging_prefs( $results->[$i]{'categorycode'} );
269
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
338
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
270
        }
339
        }
271
		push @loop, \%row;
340
        push @loop, \%row;
272
	}
341
    }
273
	$template->param(loop => \@loop);
342
    $template->param( loop => \@loop );
274
	# check that I (institution) and C (child) exists. otherwise => warning to the user
275
    $sth=$dbh->prepare("select category_type from categories where category_type='C'");
276
	$sth->execute;
277
	my ($categoryChild) = $sth->fetchrow;
278
	$template->param(categoryChild => $categoryChild);
279
	$sth=$dbh->prepare("select category_type from categories where category_type='I'");
280
	$sth->execute;
281
	my ($categoryInstitution) = $sth->fetchrow;
282
	$template->param(categoryInstitution => $categoryInstitution);
283
	$sth->finish;
284
343
344
# check that I (institution) and C (child) exists. otherwise => warning to the user
345
    $sth = $dbh->prepare(
346
        "select category_type from categories where category_type='C'");
347
    $sth->execute;
348
    my ($categoryChild) = $sth->fetchrow;
349
    $template->param( categoryChild => $categoryChild );
350
    $sth = $dbh->prepare(
351
        "select category_type from categories where category_type='I'");
352
    $sth->execute;
353
    my ($categoryInstitution) = $sth->fetchrow;
354
    $template->param( categoryInstitution => $categoryInstitution );
355
    $sth->finish;
285
356
286
} #---- END $OP eq DEFAULT
357
}    #---- END $OP eq DEFAULT
287
output_html_with_http_headers $input, $cookie, $template->output;
358
output_html_with_http_headers $input, $cookie, $template->output;
288
359
289
exit 0;
360
exit 0;
290
361
291
sub _get_brief_messaging_prefs {
362
sub _get_brief_messaging_prefs {
292
    my $categorycode = shift;
363
    my $categorycode      = shift;
293
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
364
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
294
    my $results = [];
365
    my $results           = [];
295
    PREF: foreach my $option ( @$messaging_options ) {
366
    PREF: foreach my $option (@$messaging_options) {
296
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { categorycode => $categorycode,
367
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
297
                                                                    message_name       => $option->{'message_name'} } );
368
            {
298
        next unless  $pref->{'transports'};
369
                categorycode => $categorycode,
370
                message_name => $option->{'message_name'}
371
            }
372
        );
373
        next unless $pref->{'transports'};
299
        my $brief_pref = {
374
        my $brief_pref = {
300
            message_attribute_id    => $option->{'message_attribute_id'},
375
            message_attribute_id      => $option->{'message_attribute_id'},
301
            message_name            => $option->{'message_name'},
376
            message_name              => $option->{'message_name'},
302
            $option->{'message_name'} => 1
377
            $option->{'message_name'} => 1
303
        };
378
        };
304
        foreach my $transport ( keys %{$pref->{'transports'}} ) {
379
        foreach my $transport ( keys %{ $pref->{'transports'} } ) {
305
            push @{ $brief_pref->{'transports'} }, { transport => $transport };
380
            push @{ $brief_pref->{'transports'} }, { transport => $transport };
306
        }
381
        }
307
        push @$results, $brief_pref;
382
        push @$results, $brief_pref;
308
- 

Return to bug 11513