Lines 36-46
Link Here
|
36 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
36 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
37 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
37 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
38 |
|
38 |
|
39 |
use strict; |
39 |
use Modern::Perl; |
40 |
#use warnings; FIXME - Bug 2505 |
40 |
|
41 |
use CGI; |
41 |
use CGI; |
42 |
use C4::Context; |
42 |
use C4::Context; |
43 |
use C4::Auth; |
43 |
use C4::Auth; |
|
|
44 |
use C4::Branch; |
44 |
use C4::Output; |
45 |
use C4::Output; |
45 |
use C4::Dates; |
46 |
use C4::Dates; |
46 |
use C4::Form::MessagingPreferences; |
47 |
use C4::Form::MessagingPreferences; |
Lines 90-105
if ($op eq 'add_form') {
Link Here
|
90 |
|
91 |
|
91 |
#---- if primkey exists, it's a modify action, so read values to modify... |
92 |
#---- if primkey exists, it's a modify action, so read values to modify... |
92 |
my $data; |
93 |
my $data; |
|
|
94 |
my @selected_branches; |
93 |
if ($categorycode) { |
95 |
if ($categorycode) { |
94 |
my $dbh = C4::Context->dbh; |
96 |
my $dbh = C4::Context->dbh; |
95 |
my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); |
97 |
my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,hidelostitems,overduenoticerequired,category_type from categories where categorycode=?"); |
96 |
$sth->execute($categorycode); |
98 |
$sth->execute($categorycode); |
97 |
$data=$sth->fetchrow_hashref; |
99 |
$data=$sth->fetchrow_hashref; |
98 |
$sth->finish; |
100 |
|
99 |
} |
101 |
$sth = $dbh->prepare("SELECT b.branchcode, b.branchname FROM categories_branches AS cb, branches AS b WHERE cb.branchcode = b.branchcode AND cb.categorycode = ?"); |
|
|
102 |
$sth->execute( $categorycode ); |
103 |
while ( my $branch = $sth->fetchrow_hashref ) { |
104 |
push @selected_branches, $branch; |
105 |
} |
106 |
$sth->finish; |
107 |
} |
100 |
|
108 |
|
101 |
$data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00'); |
109 |
$data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00'); |
102 |
|
110 |
|
|
|
111 |
my $branches = GetBranches; |
112 |
my @branches_loop; |
113 |
foreach my $branch (sort keys %$branches) { |
114 |
my $selected = ( grep {$$_{branchcode} eq $branch} @selected_branches ) ? 1 : 0; |
115 |
push @branches_loop, { |
116 |
branchcode => $$branches{$branch}{branchcode}, |
117 |
branchname => $$branches{$branch}{branchname}, |
118 |
selected => $selected, |
119 |
}; |
120 |
} |
121 |
|
103 |
$template->param(description => $data->{'description'}, |
122 |
$template->param(description => $data->{'description'}, |
104 |
enrolmentperiod => $data->{'enrolmentperiod'}, |
123 |
enrolmentperiod => $data->{'enrolmentperiod'}, |
105 |
enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), |
124 |
enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), |
Lines 115-120
if ($op eq 'add_form') {
Link Here
|
115 |
SMSSendDriver => C4::Context->preference("SMSSendDriver"), |
134 |
SMSSendDriver => C4::Context->preference("SMSSendDriver"), |
116 |
TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"), |
135 |
TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"), |
117 |
"type_".$data->{'category_type'} => 1, |
136 |
"type_".$data->{'category_type'} => 1, |
|
|
137 |
branches_loop => \@branches_loop, |
118 |
); |
138 |
); |
119 |
if (C4::Context->preference('EnhancedMessagingPreferences')) { |
139 |
if (C4::Context->preference('EnhancedMessagingPreferences')) { |
120 |
C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template); |
140 |
C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode } , $template); |
Lines 133-138
if ($op eq 'add_form') {
Link Here
|
133 |
if ($is_a_modif) { |
153 |
if ($is_a_modif) { |
134 |
my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); |
154 |
my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,hidelostitems=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); |
135 |
$sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode')); |
155 |
$sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','hidelostitems','overduenoticerequired','category_type','categorycode')); |
|
|
156 |
my @branches = $input->param("branches"); |
157 |
if ( @branches ) { |
158 |
$sth = $dbh->prepare("DELETE FROM categories_branches WHERE categorycode = ?"); |
159 |
$sth->execute( $input->param( "categorycode" ) ); |
160 |
$sth = $dbh->prepare( |
161 |
"INSERT INTO categories_branches |
162 |
( categorycode, branchcode ) |
163 |
VALUES ( ?, ? )" |
164 |
); |
165 |
for my $branchcode ( @branches ) { |
166 |
next if not $branchcode; |
167 |
$sth->bind_param( 1, $input->param( "categorycode" ) ); |
168 |
$sth->bind_param( 2, $branchcode ); |
169 |
$sth->execute; |
170 |
} |
171 |
} |
136 |
$sth->finish; |
172 |
$sth->finish; |
137 |
} else { |
173 |
} else { |
138 |
my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"); |
174 |
my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,hidelostitems,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?,?)"); |
Lines 197-203
if ($op eq 'add_form') {
Link Here
|
197 |
$template->param(else => 1); |
233 |
$template->param(else => 1); |
198 |
my @loop; |
234 |
my @loop; |
199 |
my ($count,$results)=StringSearch($searchfield,'web'); |
235 |
my ($count,$results)=StringSearch($searchfield,'web'); |
|
|
236 |
my $dbh = C4::Context->dbh; |
237 |
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 = ?"); |
200 |
for (my $i=0; $i < $count; $i++){ |
238 |
for (my $i=0; $i < $count; $i++){ |
|
|
239 |
$sth->execute( $results->[$i]{'categorycode'} ); |
240 |
my @selected_branches; |
241 |
while ( my $branch = $sth->fetchrow_hashref ) { |
242 |
push @selected_branches, $branch; |
243 |
} |
201 |
my %row = ( |
244 |
my %row = ( |
202 |
categorycode => $results->[$i]{'categorycode'}, |
245 |
categorycode => $results->[$i]{'categorycode'}, |
203 |
description => $results->[$i]{'description'}, |
246 |
description => $results->[$i]{'description'}, |
Lines 211-217
if ($op eq 'add_form') {
Link Here
|
211 |
reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), |
254 |
reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), |
212 |
hidelostitems => $results->[$i]{'hidelostitems'}, |
255 |
hidelostitems => $results->[$i]{'hidelostitems'}, |
213 |
category_type => $results->[$i]{'category_type'}, |
256 |
category_type => $results->[$i]{'category_type'}, |
214 |
"type_".$results->[$i]{'category_type'} => 1); |
257 |
"type_".$results->[$i]{'category_type'} => 1, |
|
|
258 |
branches => \@selected_branches, |
259 |
); |
215 |
if (C4::Context->preference('EnhancedMessagingPreferences')) { |
260 |
if (C4::Context->preference('EnhancedMessagingPreferences')) { |
216 |
my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'}); |
261 |
my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'}); |
217 |
$row{messaging_prefs} = $brief_prefs if @$brief_prefs; |
262 |
$row{messaging_prefs} = $brief_prefs if @$brief_prefs; |
Lines 220-227
if ($op eq 'add_form') {
Link Here
|
220 |
} |
265 |
} |
221 |
$template->param(loop => \@loop); |
266 |
$template->param(loop => \@loop); |
222 |
# check that I (institution) and C (child) exists. otherwise => warning to the user |
267 |
# check that I (institution) and C (child) exists. otherwise => warning to the user |
223 |
my $dbh = C4::Context->dbh; |
268 |
$sth=$dbh->prepare("select category_type from categories where category_type='C'"); |
224 |
my $sth=$dbh->prepare("select category_type from categories where category_type='C'"); |
|
|
225 |
$sth->execute; |
269 |
$sth->execute; |
226 |
my ($categoryChild) = $sth->fetchrow; |
270 |
my ($categoryChild) = $sth->fetchrow; |
227 |
$template->param(categoryChild => $categoryChild); |
271 |
$template->param(categoryChild => $categoryChild); |