Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
#Recommended pragmas |
3 |
|
4 |
# This file is part of Koha. |
5 |
# # |
6 |
# # Copyright (C) YEAR YOURNAME-OR-YOUREMPLOYER |
7 |
# # |
8 |
# # Koha is free software; you can redistribute it and/or modify it |
9 |
# # under the terms of the GNU General Public License as published by |
10 |
# # the Free Software Foundation; either version 3 of the License, or |
11 |
# # (at your option) any later version. |
12 |
# # |
13 |
# # Koha is distributed in the hope that it will be useful, but |
14 |
# # WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
# # GNU General Public License for more details. |
17 |
# # |
18 |
# # You should have received a copy of the GNU General Public License |
19 |
# # along with Koha; if not, see <http://www.gnu.org/licenses>. |
20 |
|
21 |
use strict; |
22 |
use warnings; |
23 |
use diagnostics; |
24 |
|
25 |
use Modern::Perl; |
26 |
use C4::InstallAuth; |
27 |
use CGI qw ( -utf8 ); |
28 |
use List::MoreUtils qw/uniq/; |
29 |
use Digest::MD5 qw(md5_base64); |
30 |
use Encode qw( encode ); |
31 |
use C4::Koha; |
32 |
use C4::Auth; |
33 |
use C4::Context; |
34 |
use C4::Output; |
35 |
use C4::Form::MessagingPreferences; |
36 |
use C4::Members; |
37 |
use C4::Members::Attributes; |
38 |
use C4::Members::AttributeTypes; |
39 |
use C4::Log; |
40 |
use C4::Letters; |
41 |
use C4::Form::MessagingPreferences; |
42 |
use Koha::AuthorisedValues; |
43 |
use Koha::Patron::Debarments; |
44 |
use Koha::Cities; |
45 |
use Koha::Patrons; |
46 |
use Koha::Items; |
47 |
use Koha::Libraries; |
48 |
use Koha::LibraryCategories; |
49 |
use Koha::Database; |
50 |
use Koha::DateUtils; |
51 |
use Koha::Patron::Categories; |
52 |
use Koha::Patron::HouseboundRole; |
53 |
use Koha::Patron::HouseboundRoles; |
54 |
use Koha::Token; |
55 |
use Email::Valid; |
56 |
use Module::Load; |
57 |
use Koha::ItemTypes; |
58 |
use Koha::IssuingRule; |
59 |
use Koha::IssuingRules; |
60 |
|
61 |
#Setting variables |
62 |
my $input = new CGI; |
63 |
my $query = new CGI; |
64 |
my $step = $query->param('step'); |
65 |
|
66 |
#Getting the appropriate template to display to the user |
67 |
my ( $template, $loggedinuser, $cookie) = C4::InstallAuth::get_template_and_user( |
68 |
{ |
69 |
template_name => "/onboarding/onboardingstep" . ( $step ? $step : 0 ) . ".tt", |
70 |
query => $query, |
71 |
type => "intranet", |
72 |
authnotrequired => 0, |
73 |
debug => 1, |
74 |
} |
75 |
); |
76 |
|
77 |
#Check database connection |
78 |
my %info; |
79 |
$info{'dbname'} = C4::Context->config("database"); |
80 |
$info{'dbms'} = |
81 |
( C4::Context->config("db_scheme") |
82 |
? C4::Context->config("db_scheme") |
83 |
: "mysql" ); |
84 |
|
85 |
$info{'hostname'} = C4::Context->config("hostname"); |
86 |
$info{'port'} = C4::Context->config("port"); |
87 |
$info{'user'} = C4::Context->config("user"); |
88 |
$info{'password'} = C4::Context->config("pass"); |
89 |
my $dbh = DBI->connect( |
90 |
"DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}" |
91 |
. ( $info{port} ? ";port=$info{port}" : "" ), |
92 |
$info{'user'}, $info{'password'} |
93 |
); |
94 |
|
95 |
|
96 |
#Store the value of the template input name='op' in the variable $op so we can check if the user has pressed the button with the name="op" and value="finish" meaning the user has finished the onboarding tool. |
97 |
my $op = $query->param('op'); |
98 |
$template->param('op'=>$op); |
99 |
if ( $op && $op eq 'finish' ) { #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl |
100 |
print $query->redirect("/cgi-bin/koha/mainpage.pl"); |
101 |
exit; |
102 |
} |
103 |
|
104 |
|
105 |
#Store the value of the template input name='start' in the variable $start so we can check if the user has pressed this button and started the onboarding tool process |
106 |
my $start = $query->param('start'); |
107 |
$template->param('start'=>$start); |
108 |
|
109 |
if ( $start && $start eq 'Start setting up my Koha' ){ |
110 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
111 |
$template->param(libraries => $libraries, |
112 |
group_types => [ |
113 |
{ categorytype => 'searchdomain', |
114 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], |
115 |
}, |
116 |
{ categorytype => 'properties', |
117 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], |
118 |
}, |
119 |
] |
120 |
); |
121 |
|
122 |
|
123 |
}elsif ( $start && $start eq 'Add a patron category' ){ |
124 |
#Select all the patron category records in the categories database table and give them to the template |
125 |
my $categories = Koha::Patron::Categories->search(); |
126 |
$template->param( |
127 |
categories => $categories, |
128 |
); |
129 |
|
130 |
|
131 |
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1 |
132 |
}elsif ( $step && $step == 1 ) { |
133 |
my $createlibrary = $query->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary variable |
134 |
$template->param('createlibrary'=>$createlibrary); # Hand the library values back to the template in the createlibrary variable |
135 |
|
136 |
#store inputted parameters in variables |
137 |
my $branchcode = $input->param('branchcode'); |
138 |
$branchcode = uc($branchcode); |
139 |
my $categorycode = $input->param('categorycode'); |
140 |
my $op = $input->param('op') || 'list'; |
141 |
my $message; |
142 |
my $library; |
143 |
|
144 |
#Take the text 'branchname' and store it in the @fields array |
145 |
my @fields = qw( |
146 |
branchname |
147 |
); |
148 |
|
149 |
$template->param('branchcode'=>$branchcode); |
150 |
$branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode |
151 |
|
152 |
#Create a new library object and store the branchcode and @fields array values in this new library object |
153 |
my $library = Koha::Library->new( |
154 |
{ branchcode => $branchcode, |
155 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
156 |
} |
157 |
); |
158 |
|
159 |
eval { $library->store; }; #Use the eval{} function to store the library object |
160 |
if($library){ |
161 |
$message = 'success_on_insert'; |
162 |
}else{ |
163 |
$message = 'error_on_insert'; |
164 |
} |
165 |
|
166 |
$template->param('message' => $message); |
167 |
|
168 |
|
169 |
#Check if the $step variable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1 |
170 |
}elsif ( $step && $step == 2 ){ |
171 |
my $createcat = $query->param('createcat'); #Store the inputted category code and name in $createcat |
172 |
$template->param('createcat'=>$createcat); |
173 |
|
174 |
#Initialising values |
175 |
my $searchfield = $input->param('description') // q||; |
176 |
my $categorycode = $input->param('categorycode'); |
177 |
my $op = $input->param('op') // 'list'; |
178 |
my $message; |
179 |
my $category; |
180 |
$template->param('categorycode' =>$categorycode); |
181 |
|
182 |
my ( $template, $loggedinuser, $cookie ) = C4::InstallAuth::get_template_and_user( |
183 |
{ |
184 |
template_name => "/onboarding/onboardingstep2.tt", |
185 |
query => $input, |
186 |
type => "intranet", |
187 |
authnotrequired => 0, |
188 |
flagsrequired => { parameters => 'parameters_remaining_permissions' }, |
189 |
debug => 1, |
190 |
} |
191 |
); |
192 |
|
193 |
#Once the user submits the page, this code validates the input and adds it |
194 |
#to the database as a new patron category |
195 |
$categorycode = $input->param('categorycode'); |
196 |
my $description = $input->param('description'); |
197 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
198 |
my $category_type = $input->param('category_type'); |
199 |
my $default_privacy = $input->param('default_privacy'); |
200 |
my $enrolmentperiod = $input->param('enrolmentperiod'); |
201 |
my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef; |
202 |
|
203 |
#Converts the string into a date format |
204 |
if ( $enrolmentperioddate) { |
205 |
$enrolmentperioddate = output_pref( |
206 |
{ |
207 |
dt => dt_from_string($enrolmentperioddate), |
208 |
dateformat => 'iso', |
209 |
dateonly => 1, |
210 |
} |
211 |
); |
212 |
} |
213 |
|
214 |
#Adds a new patron category to the database |
215 |
$category = Koha::Patron::Category->new({ |
216 |
categorycode=> $categorycode, |
217 |
description => $description, |
218 |
overduenoticerequired => $overduenoticerequired, |
219 |
category_type=> $category_type, |
220 |
default_privacy => $default_privacy, |
221 |
enrolmentperiod => $enrolmentperiod, |
222 |
enrolmentperioddate => $enrolmentperioddate, |
223 |
}); |
224 |
|
225 |
eval { |
226 |
$category->store; |
227 |
}; |
228 |
|
229 |
#Error messages |
230 |
if($category){ |
231 |
$message = 'success_on_insert'; |
232 |
}else{ |
233 |
$message = 'error_on_insert'; |
234 |
} |
235 |
|
236 |
$template->param('message' => $message); |
237 |
|
238 |
#Create a patron |
239 |
}elsif ( $step && $step == 3 ){ |
240 |
my $firstpassword = $input->param('password'); |
241 |
my $secondpassword = $input->param('password2'); |
242 |
|
243 |
#Find all library records in the database and hand them to the template to display in the library dropdown box |
244 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
245 |
$template->param(libraries => $libraries, |
246 |
group_types => [ |
247 |
{ categorytype => 'searchdomain', |
248 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], |
249 |
}, |
250 |
{ categorytype => 'properties', |
251 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], |
252 |
}, |
253 |
] |
254 |
); |
255 |
|
256 |
#Find all patron categories in the database and hand them to the template to display in the patron category dropdown box |
257 |
my $categories= Koha::Patron::Categories->search(); |
258 |
$template->param( |
259 |
categories => $categories, |
260 |
); |
261 |
|
262 |
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry |
263 |
my $exisiting_cardnumber = my $sth_search = $dbh->prepare("SELECT MAX(cardnumber) FROM borrowers"); |
264 |
my $new_cardnumber = $exisiting_cardnumber + 1; |
265 |
warn $new_cardnumber; |
266 |
$template->param("newcardnumber" => $new_cardnumber); |
267 |
|
268 |
|
269 |
|
270 |
my $op = $input->param('op') // 'list'; |
271 |
my $minpw = C4::Context->preference("minPasswordLength"); |
272 |
$template->param("minPasswordLength" => $minpw); |
273 |
|
274 |
my @messages; |
275 |
my @errors; |
276 |
my $nok = $input->param('nok'); |
277 |
my $firstpassword = $input->param('password'); |
278 |
my $secondpassword = $input->param('password2'); |
279 |
my $cardnumber= $input->param('cardnumber'); |
280 |
my $borrowernumber= $input->param('borrowernumber'); |
281 |
my $userid=$input->param('userid'); |
282 |
|
283 |
#If the entered cardnumber causes an error hand this error to the @errors array |
284 |
if(my $error_code = checkcardnumber($cardnumber, $borrowernumber)){ |
285 |
push @errors, $error_code == 1 |
286 |
? 'ERROR_cardnumber_already_exists' |
287 |
:$error_code == 2 |
288 |
? 'ERROR_cardnumber_length' |
289 |
:() |
290 |
} |
291 |
|
292 |
#If the entered password causes an error hand this error to the @errors array |
293 |
push @errors, "ERROR_password_mismatch" if $firstpassword ne $secondpassword; |
294 |
push @errors, "ERROR_short_password" if ($firstpassword && $minpw && $firstpassword ne '****' && (length($firstpassword) < $minpw)); |
295 |
|
296 |
|
297 |
#Passing errors to template |
298 |
$nok = $nok || scalar(@errors); |
299 |
|
300 |
#If errors have been generated from the users inputted cardnumber or password then display the error and do not insert the patron into the borrowers table |
301 |
if($nok){ |
302 |
foreach my $error (@errors){ |
303 |
if ($error eq 'ERROR_password_mismatch'){ |
304 |
$template->param(errorpasswordmismatch => 1); |
305 |
} |
306 |
if ($error eq 'ERROR_login_exist'){ |
307 |
$template->param(errorloginexists =>1); |
308 |
} |
309 |
if ($error eq 'ERROR_cardnumber_already_exists'){ |
310 |
$template->param(errorcardnumberexists => 1); |
311 |
} |
312 |
if ($error eq 'ERROR_cardnumber_length'){ |
313 |
$template->param(errorcardnumberlength => 1); |
314 |
} |
315 |
if ($error eq 'ERROR_short_password'){ |
316 |
$template->param(errorshortpassword => 1); |
317 |
} |
318 |
} |
319 |
$template->param('nok' => 1); |
320 |
|
321 |
#Else if no errors have been caused by the users inputted card number or password then insert the patron into the borrowers table |
322 |
}else{ |
323 |
my ($template, $loggedinuser, $cookie)= C4::InstallAuth::get_template_and_user({ |
324 |
template_name => "/onboarding/onboardingstep3.tt", |
325 |
query => $input, |
326 |
type => "intranet", |
327 |
authnotrequired => 0, |
328 |
flagsrequired => {borrowers => 1}, |
329 |
debug => 1, |
330 |
}); |
331 |
|
332 |
if($op eq 'add_validate'){ |
333 |
my %newdata; |
334 |
|
335 |
#Store the template form values in the newdata hash |
336 |
$newdata{borrowernumber} = $input->param('borrowernumber'); |
337 |
$newdata{surname} = $input->param('surname'); |
338 |
$newdata{firstname} = $input->param('firstname'); |
339 |
$newdata{cardnumber} = $input->param('cardnumber'); |
340 |
$newdata{branchcode} = $input->param('libraries'); |
341 |
$newdata{categorycode} = $input->param('categorycode_entry'); |
342 |
$newdata{userid} = $input->param('userid'); |
343 |
$newdata{password} = $input->param('password'); |
344 |
$newdata{password2} = $input->param('password2'); |
345 |
$newdata{dateexpiry} = '12/10/2016'; |
346 |
$newdata{privacy} = "default"; |
347 |
|
348 |
|
349 |
#Hand the newdata hash to the AddMember subroutine in the C4::Members module and it creates a patron and hands back a borrowernumber which is being stored |
350 |
my $borrowernumber = &AddMember(%newdata); |
351 |
|
352 |
#Create a hash named member2 and fill it with the borrowernumber of the borrower that has just been created |
353 |
my %member2; |
354 |
$member2{'borrowernumber'}=$borrowernumber; |
355 |
|
356 |
#Perform data validation on the flag that has been handed to onboarding.pl by the template |
357 |
my $flag = $input->param('flag'); |
358 |
if ($input->param('newflags')) { |
359 |
my $dbh=C4::Context->dbh(); |
360 |
my @perms = $input->multi_param('flag'); |
361 |
my %all_module_perms = (); |
362 |
my %sub_perms = (); |
363 |
foreach my $perm (@perms) { |
364 |
if ($perm !~ /:/) { |
365 |
$all_module_perms{$perm} = 1; |
366 |
} else { |
367 |
my ($module, $sub_perm) = split /:/, $perm, 2; |
368 |
push @{ $sub_perms{$module} }, $sub_perm; |
369 |
} |
370 |
} |
371 |
|
372 |
# construct flags |
373 |
my $module_flags = 0; |
374 |
my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit"); |
375 |
$sth->execute(); |
376 |
while (my ($bit, $flag) = $sth->fetchrow_array) { |
377 |
if (exists $all_module_perms{$flag}) { |
378 |
$module_flags += 2**$bit; |
379 |
} |
380 |
} |
381 |
|
382 |
#Set the superlibrarian permission of the newly created patron to superlibrarian |
383 |
$sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?"); |
384 |
$sth->execute($module_flags, $borrowernumber); |
385 |
|
386 |
|
387 |
#Error handling checking if the patron was created successfully |
388 |
if(!$borrowernumber){ |
389 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
390 |
}else{ |
391 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
392 |
} |
393 |
} |
394 |
} |
395 |
} |
396 |
|
397 |
}elsif ( $step && $step == 4){ |
398 |
my $createitemtype = $input->param('createitemtype'); |
399 |
$template->param('createitemtype'=> $createitemtype ); |
400 |
|
401 |
|
402 |
my( $template, $borrowernumber, $cookie) = C4::InstallAuth::get_template_and_user( |
403 |
{ template_name => "/onboarding/onboardingstep4.tt", |
404 |
query => $input, |
405 |
type => "intranet", |
406 |
authnotrequired => 0, |
407 |
flagsrequired => { parameters => 'parameters_remaining_permissions'}, |
408 |
debug => 1, |
409 |
} |
410 |
); |
411 |
|
412 |
if($op eq 'add_validate'){ |
413 |
my $description = $input->param('description'); |
414 |
my $itemtype_code = $input->param('itemtype'); |
415 |
$itemtype_code = uc($itemtype_code); |
416 |
#Create a new itemtype object using the user inputted itemtype and description |
417 |
my $itemtype= Koha::ItemType->new( |
418 |
{ itemtype => $itemtype_code, |
419 |
description => $description, |
420 |
} |
421 |
); |
422 |
|
423 |
eval{ $itemtype->store; }; |
424 |
|
425 |
my $message; |
426 |
|
427 |
#Fill the $message variable with an error if the item type object was not successfully created and inserted into the itemtypes table |
428 |
if($itemtype){ |
429 |
$message = 'success_on_insert'; |
430 |
}else{ |
431 |
$message = 'error_on_insert'; |
432 |
} |
433 |
|
434 |
$template->param('message' => $message); |
435 |
} |
436 |
}elsif ( $step && $step == 5){ |
437 |
|
438 |
#Find all the existing categories to display in a dropdown box in the template |
439 |
my $categories; |
440 |
$categories= Koha::Patron::Categories->search(); |
441 |
$template->param( |
442 |
categories => $categories, |
443 |
); |
444 |
|
445 |
#Find all the exisiting item types to display in a dropdown box in the template |
446 |
my $itemtypes; |
447 |
$itemtypes= Koha::ItemTypes->search(); |
448 |
$template->param( |
449 |
itemtypes => $itemtypes, |
450 |
); |
451 |
|
452 |
#Find all the exisiting libraries to display in a dropdown box in the template |
453 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
454 |
$template->param(libraries => $libraries, |
455 |
group_types => [ |
456 |
{ categorytype => 'searchdomain', |
457 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], |
458 |
}, |
459 |
{ categorytype => 'properties', |
460 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], |
461 |
}, |
462 |
] |
463 |
); |
464 |
|
465 |
my $input = CGI->new; |
466 |
my $dbh = C4::Context->dbh; |
467 |
|
468 |
my ($template, $loggedinuser, $cookie) = C4::InstallAuth::get_template_and_user({template_name => "/onboarding/onboardingstep5.tt", |
469 |
query => $input, |
470 |
type => "intranet", |
471 |
authnotrequired => 0, |
472 |
flagsrequired => {parameters => 'manage_circ_rules'}, |
473 |
debug => 1, |
474 |
}); |
475 |
|
476 |
#If no libraries exist then set the $branch value to * |
477 |
my $branch = $input->param('branch'); |
478 |
unless ( $branch ) { |
479 |
if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) { |
480 |
$branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch(); |
481 |
} |
482 |
else { |
483 |
$branch = C4::Context::only_my_library() ? ( C4::Context::mybranch() || '*' ) : '*'; |
484 |
} |
485 |
} |
486 |
$branch = '*' if $branch eq 'NO_LIBRARY_SET'; |
487 |
my $op = $input->param('op') || q{}; |
488 |
|
489 |
if($op eq 'add_validate'){ |
490 |
my $type = $input->param('type'); |
491 |
my $br = $input->param('branch'); |
492 |
my $bor = $input->param('categorycode'); |
493 |
my $itemtype = $input->param('itemtype'); |
494 |
my $maxissueqty = $input->param('maxissueqty'); |
495 |
my $issuelength = $input->param('issuelength'); |
496 |
my $lengthunit = $input->param('lengthunit'); |
497 |
my $renewalsallowed = $input->param('renewalsallowed'); |
498 |
my $renewalperiod = $input->param('renewalperiod'); |
499 |
my $onshelfholds = $input->param('onshelfholds') || 0; |
500 |
$maxissueqty =~ s/\s//g; |
501 |
$maxissueqty = undef if $maxissueqty !~ /^\d+/; |
502 |
$issuelength = $issuelength eq q{} ? undef : $issuelength; |
503 |
|
504 |
my $params ={ |
505 |
branchcode => $br, |
506 |
categorycode => $bor, |
507 |
itemtype => $itemtype, |
508 |
maxissueqty => $maxissueqty, |
509 |
renewalsallowed => $renewalsallowed, |
510 |
renewalperiod => $renewalperiod, |
511 |
issuelength => $issuelength, |
512 |
lengthunit => $lengthunit, |
513 |
onshelfholds => $onshelfholds, |
514 |
}; |
515 |
|
516 |
my @messages; |
517 |
|
518 |
#New code from smart-rules.tt starts here. Needs to be added to library |
519 |
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to. |
520 |
if ($branch eq "*") { |
521 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
522 |
FROM default_circ_rules"); |
523 |
my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules |
524 |
(maxissueqty, onshelfholds) |
525 |
VALUES (?, ?)"); |
526 |
my $sth_update = $dbh->prepare("UPDATE default_circ_rules |
527 |
SET maxissueqty = ?, onshelfholds = ?"); |
528 |
|
529 |
$sth_search->execute(); |
530 |
my $res = $sth_search->fetchrow_hashref(); |
531 |
if ($res->{total}) { |
532 |
$sth_update->execute($maxissueqty, $onshelfholds); |
533 |
} else { |
534 |
$sth_insert->execute($maxissueqty, $onshelfholds); |
535 |
} |
536 |
} |
537 |
|
538 |
|
539 |
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to. |
540 |
if ($bor eq "*") { |
541 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
542 |
FROM default_circ_rules"); |
543 |
my $sth_insert = $dbh->prepare(q| |
544 |
INSERT INTO default_circ_rules |
545 |
(maxissueqty) |
546 |
VALUES (?) |
547 |
|); |
548 |
my $sth_update = $dbh->prepare(q| |
549 |
UPDATE default_circ_rules |
550 |
SET maxissueqty = ? |
551 |
|); |
552 |
|
553 |
$sth_search->execute(); |
554 |
my $res = $sth_search->fetchrow_hashref(); |
555 |
if ($res->{total}) { |
556 |
$sth_update->execute($maxissueqty); |
557 |
} else { |
558 |
$sth_insert->execute($maxissueqty); |
559 |
} |
560 |
} |
561 |
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to |
562 |
if ($itemtype eq "*") { |
563 |
my $sth_search = $dbh->prepare("SELECT count(*) AS total |
564 |
FROM default_branch_circ_rules |
565 |
WHERE branchcode = ?"); |
566 |
my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules |
567 |
(branchcode, onshelfholds) |
568 |
VALUES (?, ?)"); |
569 |
my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules |
570 |
SET onshelfholds = ? |
571 |
WHERE branchcode = ?"); |
572 |
$sth_search->execute($branch); |
573 |
my $res = $sth_search->fetchrow_hashref(); |
574 |
if ($res->{total}) { |
575 |
$sth_update->execute($onshelfholds, $branch); |
576 |
} else { |
577 |
$sth_insert->execute($branch, $onshelfholds); |
578 |
} |
579 |
} |
580 |
#End new code |
581 |
|
582 |
my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype, branchcode => $br }); |
583 |
if($issuingrule){ |
584 |
$issuingrule->set($params)->store(); |
585 |
push @messages, {type=> 'error', code => 'error_on_insert'};#Stops crash of the onboarding tool if someone makes a circulation rule with the same item type, library and patron categroy as an exisiting circulation rule. |
586 |
|
587 |
}else{ |
588 |
Koha::IssuingRule->new()->set($params)->store(); |
589 |
} |
590 |
} |
591 |
} |
592 |
|
593 |
output_html_with_http_headers $input, $cookie, $template->output; |