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

(-)a/admin/categorie.pl (-214 / +273 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){
64
    while ( my $data = $sth->fetchrow_hashref ) {
61
	push(@results,$data);
65
        push( @results, $data );
62
	}
66
    }
63
	#  $sth->execute;
67
    #  $sth->execute;
64
	$sth->finish;
68
    $sth->finish;
65
	return (scalar(@results),\@results);
69
    return ( scalar(@results), \@results );
66
}
70
}
67
71
68
my $input = new CGI;
72
my $input        = new CGI;
69
my $searchfield=$input->param('description');
73
my $searchfield  = $input->param('description');
70
my $script_name="/cgi-bin/koha/admin/categorie.pl";
74
my $script_name  = "/cgi-bin/koha/admin/categorie.pl";
71
my $categorycode=$input->param('categorycode');
75
my $categorycode = $input->param('categorycode');
72
my $op = $input->param('op') // '';
76
my $op           = $input->param('op') // '';
73
74
my ($template, $loggedinuser, $cookie)
75
    = get_template_and_user({template_name => "admin/categorie.tmpl",
76
			     query => $input,
77
			     type => "intranet",
78
			     authnotrequired => 0,
79
                 flagsrequired => {parameters => 'parameters_remaining_permissions'},
80
			     debug => 1,
81
			     });
82
77
78
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
79
    {
80
        template_name   => "admin/categorie.tmpl",
81
        query           => $input,
82
        type            => "intranet",
83
        authnotrequired => 0,
84
        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
85
        debug           => 1,
86
    }
87
);
83
88
84
$template->param(script_name => $script_name,
89
$template->param(
85
		 categorycode => $categorycode,
90
    script_name  => $script_name,
86
		 searchfield => $searchfield);
91
    categorycode => $categorycode,
87
92
    searchfield  => $searchfield
93
);
88
94
89
################## ADD_FORM ##################################
95
################## ADD_FORM ##################################
90
# called by default. Used to create form to add or  modify a record
96
# called by default. Used to create form to add or  modify a record
91
if ($op eq 'add_form') {
97
if ( $op eq 'add_form' ) {
92
	$template->param(add_form => 1);
98
    $template->param( add_form => 1 );
93
	
99
94
	#---- if primkey exists, it's a modify action, so read values to modify...
100
    #---- if primkey exists, it's a modify action, so read values to modify...
95
	my $data;
101
    my $data;
96
    my @selected_branches;
102
    my @selected_branches;
97
	if ($categorycode) {
103
    if ($categorycode) {
98
		my $dbh = C4::Context->dbh;
104
        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=?");
105
        my $sth = $dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
100
		$sth->execute($categorycode);
106
        $sth->execute($categorycode);
101
		$data=$sth->fetchrow_hashref;
107
        $data = $sth->fetchrow_hashref;
102
108
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 = ?");
109
        $sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?");
104
        $sth->execute( $categorycode );
110
        $sth->execute($categorycode);
105
        while ( my $branch = $sth->fetchrow_hashref ) {
111
        while ( my $branch = $sth->fetchrow_hashref ) {
106
            push @selected_branches, $branch;
112
            push @selected_branches, $branch;
107
        }
113
        }
108
        $sth->finish;
114
        $sth->finish;
109
    }
115
    }
110
116
111
    $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} && $data->{'enrolmentperioddate'} eq '0000-00-00');
117
    if ( $data->{'enrolmentperioddate'} &&
118
         $data->{'enrolmentperioddate'} eq '0000-00-00' ) {
119
        $data->{'enrolmentperioddate'} = undef;
120
    }
112
    $data->{'category_type'} //= '';
121
    $data->{'category_type'} //= '';
113
122
114
    my $branches = GetBranches;
123
    my $branches = GetBranches;
115
    my @branches_loop;
124
    my @branches_loop;
116
    foreach my $branch (sort keys %$branches) {
125
    foreach my $branch ( sort keys %$branches ) {
117
        my $selected = ( grep {$$_{branchcode} eq $branch} @selected_branches ) ? 1 : 0;
126
        my $selected =
118
        push @branches_loop, {
127
          ( grep { $$_{branchcode} eq $branch } @selected_branches ) ? 1 : 0;
128
        push @branches_loop,
129
          {
119
            branchcode => $$branches{$branch}{branchcode},
130
            branchcode => $$branches{$branch}{branchcode},
120
            branchname => $$branches{$branch}{branchname},
131
            branchname => $$branches{$branch}{branchname},
121
            selected => $selected,
132
            selected   => $selected,
122
        };
133
          };
123
    }
134
    }
124
135
125
	$template->param(description        => $data->{'description'},
136
    $template->param(
126
				enrolmentperiod         => $data->{'enrolmentperiod'},
137
        description         => $data->{'description'},
127
				enrolmentperioddate     => $data->{'enrolmentperioddate'},
138
        enrolmentperiod     => $data->{'enrolmentperiod'},
128
				upperagelimit           => $data->{'upperagelimit'},
139
        enrolmentperioddate => $data->{'enrolmentperioddate'},
129
				dateofbirthrequired     => $data->{'dateofbirthrequired'},
140
        upperagelimit       => $data->{'upperagelimit'},
130
				enrolmentfee            => sprintf("%.2f",$data->{'enrolmentfee'} || 0),
141
        dateofbirthrequired => $data->{'dateofbirthrequired'},
131
				overduenoticerequired   => $data->{'overduenoticerequired'},
142
        enrolmentfee        => sprintf( "%.2f", $data->{'enrolmentfee'} || 0 ),
132
				issuelimit              => $data->{'issuelimit'},
143
        overduenoticerequired => $data->{'overduenoticerequired'},
133
				reservefee              => sprintf("%.2f",$data->{'reservefee'} || 0),
144
        issuelimit            => $data->{'issuelimit'},
134
                                hidelostitems           => $data->{'hidelostitems'},
145
        reservefee            => sprintf( "%.2f", $data->{'reservefee'} || 0 ),
135
				category_type           => $data->{'category_type'},
146
        hidelostitems         => $data->{'hidelostitems'},
136
                SMSSendDriver => C4::Context->preference("SMSSendDriver"),
147
        category_type         => $data->{'category_type'},
137
                TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"),
148
        SMSSendDriver         => C4::Context->preference("SMSSendDriver"),
138
				"type_".$data->{'category_type'} => 1,
149
        TalkingTechItivaPhone =>
139
                branches_loop           => \@branches_loop,
150
          C4::Context->preference("TalkingTechItivaPhoneNotification"),
140
				);
151
        "type_" . $data->{'category_type'} => 1,
141
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
152
        branches_loop                      => \@branches_loop,
142
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template);
153
    );
154
    if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
155
        C4::Form::MessagingPreferences::set_form_values(
156
            { categorycode => $categorycode }, $template );
143
    }
157
    }
144
													# END $OP eq ADD_FORM
158
159
# END $OP eq ADD_FORM
145
################## ADD_VALIDATE ##################################
160
################## ADD_VALIDATE ##################################
146
# called by add_form, used to insert/modify data in DB
161
# called by add_form, used to insert/modify data in DB
147
} elsif ($op eq 'add_validate') {
162
}
148
	$template->param(add_validate => 1);
163
elsif ( $op eq 'add_validate' ) {
149
	my $is_a_modif = $input->param("is_a_modif");
164
    $template->param( add_validate => 1 );
150
	my $dbh = C4::Context->dbh;
165
    my $is_a_modif = $input->param("is_a_modif");
151
	if($input->param('enrolmentperioddate')){
166
    my $dbh        = C4::Context->dbh;
152
	    $input->param('enrolmentperioddate' => C4::Dates::format_date_in_iso($input->param('enrolmentperioddate')) );
167
    if ( $input->param('enrolmentperioddate') ) {
153
	}
168
        $input->param(
154
	
169
            'enrolmentperioddate' => C4::Dates::format_date_in_iso(
155
	if ($is_a_modif) {
170
                $input->param('enrolmentperioddate')
156
            my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?");
171
            )
157
            $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode'));
172
        );
158
            my @branches = $input->param("branches");
173
    }
159
            if ( @branches ) {
174
160
                $sth = $dbh->prepare("DELETE FROM categories_branches WHERE categorycode = ?");
175
    if ($is_a_modif) {
161
                $sth->execute( $input->param( "categorycode" ) );
176
        my $sth = $dbh->prepare(
162
                $sth = $dbh->prepare(
177
"UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"
163
                    "INSERT INTO categories_branches
178
        );
179
        $sth->execute(
180
            map { $input->param($_) } (
181
                'description',           'enrolmentperiod',
182
                'enrolmentperioddate',   'upperagelimit',
183
                'dateofbirthrequired',   'enrolmentfee',
184
                'reservefee',            'hidelostitems',
185
                'overduenoticerequired', 'category_type',
186
                'categorycode'
187
            )
188
        );
189
        my @branches = $input->param("branches");
190
        if (@branches) {
191
            $sth = $dbh->prepare(
192
                "DELETE FROM categories_branches WHERE categorycode = ?");
193
            $sth->execute( $input->param("categorycode") );
194
            $sth = $dbh->prepare(
195
                "INSERT INTO categories_branches
164
                                ( categorycode, branchcode )
196
                                ( categorycode, branchcode )
165
                                VALUES ( ?, ? )"
197
                                VALUES ( ?, ? )"
166
                );
198
            );
167
                for my $branchcode ( @branches ) {
199
            for my $branchcode (@branches) {
168
                    next if not $branchcode;
200
                next if not $branchcode;
169
                    $sth->bind_param( 1, $input->param( "categorycode" ) );
201
                $sth->bind_param( 1, $input->param("categorycode") );
170
                    $sth->bind_param( 2, $branchcode );
202
                $sth->bind_param( 2, $branchcode );
171
                    $sth->execute;
203
                $sth->execute;
172
                }
173
            }
204
            }
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
        }
205
        }
180
    if (C4::Context->preference('EnhancedMessagingPreferences')) {
206
        $sth->finish;
181
        C4::Form::MessagingPreferences::handle_form_action($input, 
182
                                                           { categorycode => $input->param('categorycode') }, $template);
183
    }
207
    }
184
	print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
208
    else {
185
	exit;
209
        my $sth = $dbh->prepare(
210
"INSERT INTO categories  (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"
211
        );
212
        $sth->execute(
213
            map { $input->param($_) } (
214
                'categorycode',    'description',
215
                'enrolmentperiod', 'enrolmentperioddate',
216
                'upperagelimit',   'dateofbirthrequired',
217
                'enrolmentfee',    'reservefee',
218
                'hidelostitems',   'overduenoticerequired',
219
                'category_type'
220
            )
221
        );
222
        $sth->finish;
223
    }
224
    if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
225
        C4::Form::MessagingPreferences::handle_form_action( $input,
226
            { categorycode => $input->param('categorycode') }, $template );
227
    }
228
    print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
229
    exit;
186
230
187
													# END $OP eq ADD_VALIDATE
231
# END $OP eq ADD_VALIDATE
188
################## DELETE_CONFIRM ##################################
232
################## DELETE_CONFIRM ##################################
189
# called by default form, used to confirm deletion of data in DB
233
# called by default form, used to confirm deletion of data in DB
190
} elsif ($op eq 'delete_confirm') {
234
}
191
	$template->param(delete_confirm => 1);
235
elsif ( $op eq 'delete_confirm' ) {
236
    $template->param( delete_confirm => 1 );
237
238
    my $dbh = C4::Context->dbh;
239
    my $sth = $dbh->prepare("select count(*) as total from borrowers where categorycode=?");
240
    $sth->execute($categorycode);
241
    my $total = $sth->fetchrow_hashref;
242
    $sth->finish;
243
    $template->param( total => $total->{'total'} );
192
244
193
	my $dbh = C4::Context->dbh;
245
    my $sth2 = $dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?");
194
	my $sth=$dbh->prepare("select count(*) as total from borrowers where categorycode=?");
246
    $sth2->execute($categorycode);
195
	$sth->execute($categorycode);
247
    my $data = $sth2->fetchrow_hashref;
196
	my $total = $sth->fetchrow_hashref;
248
    $sth2->finish;
197
	$sth->finish;
249
    if ( $total->{'total'} > 0 ) {
198
	$template->param(total => $total->{'total'});
250
        $template->param( totalgtzero => 1 );
199
	
251
    }
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
    if ( $data->{'enrolmentperioddate'} &&
209
        $template->param(       description             => $data->{'description'},
254
         $data->{'enrolmentperioddate'} eq '0000-00-00' ) {
210
                                enrolmentperiod         => $data->{'enrolmentperiod'},
255
        $data->{'enrolmentperioddate'} = undef;
211
                                enrolmentperioddate     => $data->{'enrolmentperioddate'},
256
    }
212
                                upperagelimit           => $data->{'upperagelimit'},
257
    $template->param(
213
                                dateofbirthrequired     => $data->{'dateofbirthrequired'},
258
        description           => $data->{'description'},
214
                                enrolmentfee            =>  sprintf("%.2f",$data->{'enrolmentfee'}),
259
        enrolmentperiod       => $data->{'enrolmentperiod'},
215
                                overduenoticerequired   => $data->{'overduenoticerequired'},
260
        enrolmentperioddate   => $data->{'enrolmentperioddate'},
216
                                issuelimit              => $data->{'issuelimit'},
261
        upperagelimit         => $data->{'upperagelimit'},
217
                                reservefee              =>  sprintf("%.2f",$data->{'reservefee'}),
262
        dateofbirthrequired   => $data->{'dateofbirthrequired'},
218
                                hidelostitems           => $data->{'hidelostitems'},
263
        enrolmentfee          => sprintf( "%.2f", $data->{'enrolmentfee'} ),
219
                                category_type           => $data->{'category_type'},
264
        overduenoticerequired => $data->{'overduenoticerequired'},
220
                                );
265
        issuelimit            => $data->{'issuelimit'},
221
													# END $OP eq DELETE_CONFIRM
266
        reservefee            => sprintf( "%.2f", $data->{'reservefee'} ),
267
        hidelostitems         => $data->{'hidelostitems'},
268
        category_type         => $data->{'category_type'},
269
    );
270
271
# END $OP eq DELETE_CONFIRM
222
################## DELETE_CONFIRMED ##################################
272
################## DELETE_CONFIRMED ##################################
223
# called by delete_confirm, used to effectively confirm deletion of data in DB
273
# called by delete_confirm, used to effectively confirm deletion
224
} elsif ($op eq 'delete_confirmed') {
274
# of data in DB
225
	$template->param(delete_confirmed => 1);
275
}
226
	my $dbh = C4::Context->dbh;
276
elsif ( $op eq 'delete_confirmed' ) {
227
	my $categorycode=uc($input->param('categorycode'));
277
    $template->param( delete_confirmed => 1 );
228
	my $sth=$dbh->prepare("delete from categories where categorycode=?");
278
    my $dbh          = C4::Context->dbh;
229
	$sth->execute($categorycode);
279
    my $categorycode = uc( $input->param('categorycode') );
230
	$sth->finish;
280
    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>";
281
    $sth->execute($categorycode);
232
	exit;
282
    $sth->finish;
283
    print
284
"Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=categorie.pl\"></html>";
285
    exit;
233
286
234
													# END $OP eq DELETE_CONFIRMED
287
# END $OP eq DELETE_CONFIRMED
235
} else { # DEFAULT
288
}
236
	$template->param(else => 1);
289
else {    # DEFAULT
237
	my @loop;
290
    $template->param( else => 1 );
238
	my ($count,$results)=StringSearch($searchfield,'web');
291
    my @loop;
292
    my ( $count, $results ) = StringSearch( $searchfield, 'web' );
239
    my $dbh = C4::Context->dbh;
293
    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 = ?");
294
    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 = ?");
241
	for (my $i=0; $i < $count; $i++){
295
    for ( my $i = 0 ; $i < $count ; $i++ ) {
242
        $sth->execute( $results->[$i]{'categorycode'} );
296
        $sth->execute( $results->[$i]{'categorycode'} );
243
        my @selected_branches;
297
        my @selected_branches;
244
        while ( my $branch = $sth->fetchrow_hashref ) {
298
        while ( my $branch = $sth->fetchrow_hashref ) {
245
            push @selected_branches, $branch;
299
            push @selected_branches, $branch;
246
        }
300
        }
247
        my $enrolmentperioddate = $results->[$i]{'enrolmentperioddate'};
301
        my $enrolmentperioddate = $results->[$i]{'enrolmentperioddate'};
248
        if (defined($enrolmentperioddate) && $enrolmentperioddate eq '0000-00-00') {
302
        if ( $enrolmentperioddate &&
303
             $enrolmentperioddate eq '0000-00-00' ) {
249
            $enrolmentperioddate = undef;
304
            $enrolmentperioddate = undef;
250
        }
305
        }
251
		my %row = (
306
        $results->[$i]{'category_type'} //= '';
252
		        categorycode            => $results->[$i]{'categorycode'},
307
        my %row = (
253
				description             => $results->[$i]{'description'},
308
            categorycode        => $results->[$i]{'categorycode'},
254
				enrolmentperiod         => $results->[$i]{'enrolmentperiod'},
309
            description         => $results->[$i]{'description'},
255
				enrolmentperioddate     => $enrolmentperioddate,
310
            enrolmentperiod     => $results->[$i]{'enrolmentperiod'},
256
				upperagelimit           => $results->[$i]{'upperagelimit'},
311
            enrolmentperioddate => $enrolmentperioddate,
257
				dateofbirthrequired     => $results->[$i]{'dateofbirthrequired'},
312
            upperagelimit       => $results->[$i]{'upperagelimit'},
258
				enrolmentfee            => sprintf("%.2f",$results->[$i]{'enrolmentfee'}),
313
            dateofbirthrequired => $results->[$i]{'dateofbirthrequired'},
259
				overduenoticerequired   => $results->[$i]{'overduenoticerequired'},
314
            enrolmentfee => sprintf( "%.2f", $results->[$i]{'enrolmentfee'} || 0),
260
				issuelimit              => $results->[$i]{'issuelimit'},
315
            overduenoticerequired => $results->[$i]{'overduenoticerequired'},
261
				reservefee              => sprintf("%.2f",$results->[$i]{'reservefee'}),
316
            issuelimit            => $results->[$i]{'issuelimit'},
262
                                hidelostitems           => $results->[$i]{'hidelostitems'},
317
            reservefee    => sprintf( "%.2f", $results->[$i]{'reservefee'} || 0),
263
				category_type           => $results->[$i]{'category_type'},
318
            hidelostitems => $results->[$i]{'hidelostitems'},
264
                "type_".$results->[$i]{'category_type'} => 1,
319
            category_type => $results->[$i]{'category_type'},
265
                branches                => \@selected_branches,
320
            "type_" . $results->[$i]{'category_type'} => 1,
321
            branches                                  => \@selected_branches,
266
        );
322
        );
267
        if (C4::Context->preference('EnhancedMessagingPreferences')) {
323
        if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
268
            my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'});
324
            my $brief_prefs = _get_brief_messaging_prefs( $results->[$i]{'categorycode'} );
269
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
325
            $row{messaging_prefs} = $brief_prefs if @$brief_prefs;
270
        }
326
        }
271
		push @loop, \%row;
327
        push @loop, \%row;
272
	}
328
    }
273
	$template->param(loop => \@loop);
329
    $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
330
331
# check that I (institution) and C (child) exists. otherwise => warning to the user
332
    $sth = $dbh->prepare("select category_type from categories where category_type='C'");
333
    $sth->execute;
334
    my ($categoryChild) = $sth->fetchrow;
335
    $template->param( categoryChild => $categoryChild );
336
    $sth = $dbh->prepare("select category_type from categories where category_type='I'");
337
    $sth->execute;
338
    my ($categoryInstitution) = $sth->fetchrow;
339
    $template->param( categoryInstitution => $categoryInstitution );
340
    $sth->finish;
285
341
286
} #---- END $OP eq DEFAULT
342
}    #---- END $OP eq DEFAULT
287
output_html_with_http_headers $input, $cookie, $template->output;
343
output_html_with_http_headers $input, $cookie, $template->output;
288
344
289
exit 0;
345
exit 0;
290
346
291
sub _get_brief_messaging_prefs {
347
sub _get_brief_messaging_prefs {
292
    my $categorycode = shift;
348
    my $categorycode      = shift;
293
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
349
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
294
    my $results = [];
350
    my $results           = [];
295
    PREF: foreach my $option ( @$messaging_options ) {
351
    PREF: foreach my $option (@$messaging_options) {
296
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { categorycode => $categorycode,
352
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
297
                                                                    message_name       => $option->{'message_name'} } );
353
            {
298
        next unless  $pref->{'transports'};
354
                categorycode => $categorycode,
355
                message_name => $option->{'message_name'}
356
            }
357
        );
358
        next unless $pref->{'transports'};
299
        my $brief_pref = {
359
        my $brief_pref = {
300
            message_attribute_id    => $option->{'message_attribute_id'},
360
            message_attribute_id      => $option->{'message_attribute_id'},
301
            message_name            => $option->{'message_name'},
361
            message_name              => $option->{'message_name'},
302
            $option->{'message_name'} => 1
362
            $option->{'message_name'} => 1
303
        };
363
        };
304
        foreach my $transport ( keys %{$pref->{'transports'}} ) {
364
        foreach my $transport ( keys %{ $pref->{'transports'} } ) {
305
            push @{ $brief_pref->{'transports'} }, { transport => $transport };
365
            push @{ $brief_pref->{'transports'} }, { transport => $transport };
306
        }
366
        }
307
        push @$results, $brief_pref;
367
        push @$results, $brief_pref;
308
- 

Return to bug 11513