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