Lines 35-167
use Koha::IssuingRules;
Link Here
|
35 |
|
35 |
|
36 |
#Setting variables |
36 |
#Setting variables |
37 |
my $input = new CGI; |
37 |
my $input = new CGI; |
38 |
my $step = $input->param('step'); |
|
|
39 |
|
38 |
|
40 |
unless ( C4::Context->preference('Version') ) { |
39 |
unless ( C4::Context->preference('Version') ) { |
41 |
print $input->redirect("/cgi-bin/koha/installer/install.pl"); |
40 |
print $input->redirect("/cgi-bin/koha/installer/install.pl"); |
42 |
exit; |
41 |
exit; |
43 |
} |
42 |
} |
44 |
|
43 |
|
45 |
#Getting the appropriate template to display to the user |
44 |
my ( $user, $cookie, $sessionID, $flags ) = |
46 |
my ( $template, $loggedinuser, $cookie ) = |
45 |
C4::InstallAuth::checkauth( $input, 0, undef, 'intranet' ); |
47 |
C4::InstallAuth::get_template_and_user( |
46 |
die "Not logged in" |
48 |
{ |
47 |
unless $user |
49 |
template_name => "/onboarding/onboardingstep" |
48 |
; # Should not happen, we should be redirect if the user is not logged in. But do not trust authentication... |
50 |
. ( $step ? $step : 1 ) . ".tt", |
|
|
51 |
query => $input, |
52 |
type => "intranet", |
53 |
authnotrequired => 0, |
54 |
debug => 1, |
55 |
} |
56 |
); |
57 |
|
49 |
|
58 |
#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. |
50 |
my $step = $input->param('step') || 1; |
59 |
my $op = $input->param('op') || ''; |
51 |
my $op = $input->param('op') || ''; |
60 |
$template->param( 'op' => $op ); |
52 |
|
|
|
53 |
my $template_params = {}; |
54 |
$template_params->{op} = $op; |
61 |
|
55 |
|
62 |
my $schema = Koha::Database->new()->schema(); |
56 |
my $schema = Koha::Database->new()->schema(); |
63 |
|
57 |
|
64 |
if ( $op && $op eq 'finish' ) |
58 |
my @messages; |
65 |
{ #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl |
|
|
66 |
print $input->redirect("/cgi-bin/koha/mainpage.pl"); |
67 |
exit; |
68 |
} |
69 |
|
59 |
|
70 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
60 |
if ( $step == 1 ) { |
71 |
$template->param( |
|
|
72 |
libraries => $libraries, |
73 |
group_types => [ |
74 |
{ |
75 |
categorytype => 'searchdomain', |
76 |
categories => [ |
77 |
Koha::LibraryCategories->search( |
78 |
{ categorytype => 'searchdomain' } |
79 |
) |
80 |
], |
81 |
}, |
82 |
{ |
83 |
categorytype => 'properties', |
84 |
categories => [ |
85 |
Koha::LibraryCategories->search( |
86 |
{ categorytype => 'properties' } |
87 |
) |
88 |
], |
89 |
}, |
90 |
] |
91 |
); |
92 |
|
61 |
|
93 |
#Select all the patron category records in the categories database table and give them to the template |
62 |
if ( $op eq 'add_validate_library' ) { |
94 |
my $categories = Koha::Patron::Categories->search(); |
|
|
95 |
$template->param( 'categories' => $categories, ); |
96 |
|
63 |
|
97 |
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1 |
64 |
my $branchcode = $input->param('branchcode'); |
98 |
my $itemtypes = Koha::ItemTypes->search(); |
65 |
$branchcode = uc($branchcode); |
99 |
$template->param( 'itemtypes' => $itemtypes, ); |
|
|
100 |
|
101 |
if ( $step && $step == 1 ) { |
102 |
|
103 |
#store inputted parameters in variables |
104 |
my $branchcode = $input->param('branchcode'); |
105 |
$branchcode = uc($branchcode); |
106 |
my $categorycode = $input->param('categorycode'); |
107 |
my $op = $input->param('op') || 'list'; |
108 |
my $message; |
109 |
my $library; |
110 |
|
111 |
#Take the text 'branchname' and store it in the @fields array |
112 |
my @fields = qw( |
113 |
branchname |
114 |
); |
115 |
|
116 |
$template->param( 'branchcode' => $branchcode ); |
117 |
$branchcode =~ s|\s||g |
118 |
; # Use a regular expression to check the value of the inputted branchcode |
119 |
|
120 |
#Create a new library object and store the branchcode and @fields array values in this new library object |
121 |
$library = Koha::Library->new( |
122 |
{ |
123 |
branchcode => $branchcode, |
124 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
125 |
} |
126 |
); |
127 |
|
66 |
|
128 |
eval { $library->store; }; #Use the eval{} function to store the library object |
67 |
$branchcode =~ s|\s||g |
129 |
if ($library) { |
68 |
; # Use a regular expression to check the value of the inputted branchcode |
130 |
$message = 'success_on_insert'; |
69 |
|
131 |
} |
70 |
my $library = Koha::Library->new( |
132 |
else { |
71 |
{ |
133 |
$message = 'error_on_insert'; |
72 |
branchcode => $branchcode, |
|
|
73 |
branchname => scalar $input->param('branchname'), |
74 |
} |
75 |
); |
76 |
|
77 |
eval { $library->store; }; |
78 |
unless ($@) { |
79 |
push @messages, |
80 |
{ type => 'message', code => 'success_on_insert_library' }; |
81 |
} |
82 |
else { |
83 |
push @messages, |
84 |
{ type => 'message', code => 'error_on_insert_library' }; |
85 |
} |
134 |
} |
86 |
} |
135 |
$template->param( 'message' => $message ); |
|
|
136 |
|
87 |
|
137 |
#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 |
88 |
$step++ if Koha::Libraries->count; |
138 |
} |
89 |
} |
139 |
elsif ( $step && $step == 2 ) { |
90 |
if ( $step == 2 ) { |
140 |
if ( $op eq "add_validate_category" ) { |
91 |
if ( $op eq "add_validate_category" ) { |
141 |
|
92 |
|
142 |
#Initialising values |
93 |
my $searchfield = $input->param('description') // q||; |
143 |
my $searchfield = $input->param('description') // q||; |
|
|
144 |
my $categorycode = $input->param('categorycode'); |
94 |
my $categorycode = $input->param('categorycode'); |
145 |
my $op = $input->param('op') // 'list'; |
|
|
146 |
my $message; |
147 |
my $category; |
95 |
my $category; |
148 |
$template->param( 'categorycode' => $categorycode ); |
96 |
$template_params->{categorycode} = $categorycode; |
149 |
|
|
|
150 |
my ( $template, $loggedinuser, $cookie ) = |
151 |
C4::InstallAuth::get_template_and_user( |
152 |
{ |
153 |
template_name => "/onboarding/onboardingstep2.tt", |
154 |
query => $input, |
155 |
type => "intranet", |
156 |
authnotrequired => 0, |
157 |
flagsrequired => |
158 |
{ parameters => 'parameters_remaining_permissions' }, |
159 |
debug => 1, |
160 |
} |
161 |
); |
162 |
|
97 |
|
163 |
#Once the user submits the page, this code validates the input and adds it |
|
|
164 |
#to the database as a new patron category |
165 |
$categorycode = $input->param('categorycode'); |
98 |
$categorycode = $input->param('categorycode'); |
166 |
my $description = $input->param('description'); |
99 |
my $description = $input->param('description'); |
167 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
100 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
Lines 196-405
elsif ( $step && $step == 2 ) {
Link Here
|
196 |
|
129 |
|
197 |
eval { $category->store; }; |
130 |
eval { $category->store; }; |
198 |
|
131 |
|
199 |
#Error messages |
132 |
unless ($@) { |
200 |
if ($category) { |
133 |
push @messages, |
201 |
$message = 'success_on_insert'; |
134 |
{ type => 'message', code => 'success_on_insert_category' }; |
202 |
} |
135 |
} |
203 |
else { |
136 |
else { |
204 |
$message = 'error_on_insert'; |
137 |
push @messages, |
|
|
138 |
{ type => 'message', code => 'error_on_insert_category' }; |
205 |
} |
139 |
} |
206 |
|
|
|
207 |
$template->param( 'message' => $message ); |
208 |
} |
140 |
} |
209 |
|
141 |
|
210 |
#Create a patron |
142 |
$step++ if Koha::Patron::Categories->count; |
211 |
} |
143 |
} |
212 |
elsif ( $step && $step == 3 ) { |
144 |
if ( $step == 3 ) { |
213 |
my $firstpassword = $input->param('password') || ''; |
145 |
if ( $op eq 'add_validate_patron' ) { |
214 |
my $secondpassword = $input->param('password2') || ''; |
146 |
|
215 |
|
147 |
#Create a patron |
216 |
#Find all patron records in the database and hand them to the template |
148 |
my $firstpassword = $input->param('password') || ''; |
217 |
my %currentpatrons = Koha::Patrons->search(); |
149 |
my $secondpassword = $input->param('password2') || ''; |
218 |
my $currentpatrons = values %currentpatrons; |
150 |
my $cardnumber = $input->param('cardnumber'); |
219 |
$template->param( 'patrons' => $currentpatrons ); |
151 |
my $userid = $input->param('userid'); |
220 |
|
152 |
|
221 |
#Find all patron categories in the database and hand them to the template to display in the patron category dropdown box |
153 |
if ( my $error_code = checkcardnumber($cardnumber) ) { |
222 |
my $categories = Koha::Patron::Categories->search(); |
154 |
if ( $error_code == 1 ) { |
223 |
$template->param( 'categories' => $categories, ); |
155 |
push @messages, |
224 |
|
156 |
{ |
225 |
#Incrementing the highest existing patron cardnumber to prevent duplicate cardnumber entry |
157 |
type => 'alert', |
226 |
|
158 |
code => 'ERROR_cardnumber_already_exists' |
227 |
my $existing_cardnumber = |
159 |
}; |
228 |
$schema->resultset('Borrower')->get_column('cardnumber')->max() // 0; |
|
|
229 |
|
230 |
my $new_cardnumber = $existing_cardnumber + 1; |
231 |
$template->param( "newcardnumber" => $new_cardnumber ); |
232 |
|
233 |
my $op = $input->param('op') // 'list'; |
234 |
my $minpw = C4::Context->preference("minPasswordLength"); |
235 |
$template->param( "minPasswordLength" => $minpw ); |
236 |
my @messages; |
237 |
my @errors; |
238 |
my $nok = $input->param('nok'); |
239 |
my $cardnumber = $input->param('cardnumber'); |
240 |
my $borrowernumber = $input->param('borrowernumber'); |
241 |
my $userid = $input->param('userid'); |
242 |
|
243 |
# function to designate mandatory fields (visually with css) |
244 |
my $check_BorrowerMandatoryField = |
245 |
C4::Context->preference("BorrowerMandatoryField"); |
246 |
my @field_check = split( /\|/, $check_BorrowerMandatoryField ); |
247 |
foreach (@field_check) { |
248 |
$template->param( "mandatory$_" => 1 ); |
249 |
$template->param( |
250 |
BorrowerMandatoryField => |
251 |
C4::Context->preference("BorrowerMandatoryField") |
252 |
, #field to test with javascript |
253 |
); |
254 |
} |
255 |
|
256 |
#If the entered cardnumber causes an error hand this error to the @errors array |
257 |
if ( my $error_code = checkcardnumber( $cardnumber, $borrowernumber ) ) { |
258 |
push @errors, |
259 |
$error_code == 1 ? 'ERROR_cardnumber_already_exists' |
260 |
: $error_code == 2 ? 'ERROR_cardnumber_length' |
261 |
: (); |
262 |
} |
263 |
|
264 |
#If the entered password causes an error hand this error to the @errors array |
265 |
push @errors, "ERROR_password_mismatch" |
266 |
if $firstpassword ne $secondpassword; |
267 |
push @errors, "ERROR_short_password" |
268 |
if ( $firstpassword |
269 |
&& $minpw |
270 |
&& $firstpassword ne '****' |
271 |
&& ( length($firstpassword) < $minpw ) ); |
272 |
|
273 |
#Passing errors to template |
274 |
$nok = $nok || scalar(@errors); |
275 |
|
276 |
#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 |
277 |
if ($nok) { |
278 |
foreach my $error (@errors) { |
279 |
if ( $error eq 'ERROR_password_mismatch' ) { |
280 |
$template->param( errorpasswordmismatch => 1 ); |
281 |
} |
160 |
} |
282 |
if ( $error eq 'ERROR_login_exist' ) { |
161 |
elsif ( $error_code == 2 ) { |
283 |
$template->param( errorloginexists => 1 ); |
162 |
push @messages, |
284 |
} |
163 |
{ type => 'alert', code => 'ERROR_cardnumber_length' }; |
285 |
if ( $error eq 'ERROR_cardnumber_already_exists' ) { |
|
|
286 |
$template->param( errorcardnumberexists => 1 ); |
287 |
} |
288 |
if ( $error eq 'ERROR_cardnumber_length' ) { |
289 |
$template->param( errorcardnumberlength => 1 ); |
290 |
} |
291 |
if ( $error eq 'ERROR_short_password' ) { |
292 |
$template->param( errorshortpassword => 1 ); |
293 |
} |
164 |
} |
294 |
} |
165 |
} |
295 |
$template->param( 'nok' => 1 ); |
166 |
elsif ( $firstpassword ne $secondpassword ) { |
|
|
167 |
|
168 |
push @messages, |
169 |
{ type => 'alert', code => 'ERROR_password_mismatch' }; |
170 |
} |
171 |
else { |
172 |
|
173 |
my $patron_data = { |
174 |
surname => scalar $input->param('surname'), |
175 |
firstname => scalar $input->param('firstname'), |
176 |
cardnumber => scalar $input->param('cardnumber'), |
177 |
branchcode => scalar $input->param('libraries'), |
178 |
categorycode => scalar $input->param('categorycode_entry'), |
179 |
userid => scalar $input->param('userid'), |
180 |
password => scalar $input->param('password'), |
181 |
password2 => scalar $input->param('password2'), |
182 |
privacy => "default", |
183 |
address => "", |
184 |
city => "", |
185 |
flags => 1, # Will be superlibrarian |
186 |
}; |
296 |
|
187 |
|
297 |
#Else if no errors have been caused by the users inputted card number or password then insert the patron into the borrowers table |
|
|
298 |
} |
299 |
else { |
300 |
my ( $template, $loggedinuser, $cookie ) = |
301 |
C4::InstallAuth::get_template_and_user( |
302 |
{ |
303 |
template_name => "/onboarding/onboardingstep3.tt", |
304 |
query => $input, |
305 |
type => "intranet", |
306 |
authnotrequired => 0, |
307 |
flagsrequired => { borrowers => 1 }, |
308 |
debug => 1, |
309 |
} |
310 |
); |
311 |
|
312 |
if ( $op eq 'add_validate' ) { |
313 |
my %newdata; |
314 |
|
315 |
#Store the template form values in the newdata hash |
316 |
$newdata{borrowernumber} = $input->param('borrowernumber'); |
317 |
$newdata{surname} = $input->param('surname'); |
318 |
$newdata{firstname} = $input->param('firstname'); |
319 |
$newdata{cardnumber} = $input->param('cardnumber'); |
320 |
$newdata{branchcode} = $input->param('libraries'); |
321 |
$newdata{categorycode} = $input->param('categorycode_entry'); |
322 |
$newdata{userid} = $input->param('userid'); |
323 |
$newdata{password} = $input->param('password'); |
324 |
$newdata{password2} = $input->param('password2'); |
325 |
$newdata{privacy} = "default"; |
326 |
$newdata{address} = ""; |
327 |
$newdata{city} = ""; |
328 |
|
329 |
#Hand tne the dateexpiry of the patron based on the patron category it is created from |
330 |
my $patron_category = |
188 |
my $patron_category = |
331 |
Koha::Patron::Categories->find( $newdata{categorycode} ); |
189 |
Koha::Patron::Categories->find( $patron_data->{categorycode} ); |
332 |
$newdata{dateexpiry} = |
190 |
$patron_data->{dateexpiry} = |
333 |
$patron_category->get_expiry_date( $newdata{dateenrolled} ); |
191 |
$patron_category->get_expiry_date( $patron_data->{dateenrolled} ); |
334 |
|
|
|
335 |
#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 |
336 |
my $borrowernumber = &AddMember(%newdata); |
337 |
|
338 |
#Create a hash named member2 and fill it with the borrowernumber of the borrower that has just been created |
339 |
my %member2; |
340 |
$member2{'borrowernumber'} = $borrowernumber; |
341 |
|
342 |
#Perform data validation on the flag that has been handed to onboarding.pl by the template |
343 |
my $flag = $input->param('flag'); |
344 |
if ( $input->param('newflags') ) { |
345 |
my @perms = $input->multi_param('flag'); |
346 |
my %all_module_perms = (); |
347 |
my %sub_perms = (); |
348 |
foreach my $perm (@perms) { |
349 |
if ( $perm !~ /:/ ) { |
350 |
$all_module_perms{$perm} = 1; |
351 |
} |
352 |
else { |
353 |
my ( $module, $sub_perm ) = split /:/, $perm, 2; |
354 |
push @{ $sub_perms{$module} }, $sub_perm; |
355 |
} |
356 |
} |
357 |
|
192 |
|
358 |
# construct flags |
193 |
my $borrowernumber = C4::Members::AddMember(%$patron_data); |
359 |
my @userflags = $schema->resultset('Userflag')->search( |
194 |
|
360 |
{}, |
195 |
#Error handling checking if the patron was created successfully |
361 |
{ |
196 |
if ($borrowernumber) { |
362 |
order_by => { -asc => 'bit' }, |
197 |
push @messages, |
363 |
} |
198 |
{ type => 'message', code => 'success_on_insert_patron' }; |
364 |
); |
199 |
} |
365 |
|
200 |
else { |
366 |
#Setting superlibrarian permissions for new patron |
201 |
push @messages, |
367 |
my $flags = |
202 |
{ type => 'error', code => 'error_on_insert_patron' }; |
368 |
Koha::Patrons->find($borrowernumber)->set( { flags => 1 } ) |
|
|
369 |
->store; |
370 |
|
371 |
#Error handling checking if the patron was created successfully |
372 |
if ( !$borrowernumber ) { |
373 |
push @messages, |
374 |
{ type => 'error', code => 'error_on_insert' }; |
375 |
} |
376 |
else { |
377 |
push @messages, |
378 |
{ type => 'message', code => 'success_on_insert' }; |
379 |
} |
380 |
} |
203 |
} |
381 |
} |
204 |
} |
382 |
} |
205 |
} |
|
|
206 |
|
207 |
$step++ if Koha::Patrons->search( { flags => 1 } )->count; |
383 |
} |
208 |
} |
384 |
elsif ( $step && $step == 4 ) { |
209 |
if ( $step == 4 ) { |
385 |
my ( $template, $borrowernumber, $cookie ) = |
210 |
if ( $op eq 'add_validate_itemtype' ) { |
386 |
C4::InstallAuth::get_template_and_user( |
|
|
387 |
{ |
388 |
template_name => "/onboarding/onboardingstep4.tt", |
389 |
query => $input, |
390 |
type => "intranet", |
391 |
authnotrequired => 0, |
392 |
flagsrequired => |
393 |
{ parameters => 'parameters_remaining_permissions' }, |
394 |
debug => 1, |
395 |
} |
396 |
); |
397 |
if ( $op eq "add_validate" ) { |
398 |
my $description = $input->param('description'); |
211 |
my $description = $input->param('description'); |
399 |
my $itemtype_code = $input->param('itemtype'); |
212 |
my $itemtype_code = $input->param('itemtype'); |
400 |
$itemtype_code = uc($itemtype_code); |
213 |
$itemtype_code = uc($itemtype_code); |
401 |
|
214 |
|
402 |
#Create a new itemtype object using the user inputted itemtype and description |
|
|
403 |
my $itemtype = Koha::ItemType->new( |
215 |
my $itemtype = Koha::ItemType->new( |
404 |
{ |
216 |
{ |
405 |
itemtype => $itemtype_code, |
217 |
itemtype => $itemtype_code, |
Lines 407-473
elsif ( $step && $step == 4 ) {
Link Here
|
407 |
} |
219 |
} |
408 |
); |
220 |
); |
409 |
eval { $itemtype->store; }; |
221 |
eval { $itemtype->store; }; |
410 |
my $message; |
|
|
411 |
|
222 |
|
412 |
#Fill the $message variable with an error if the item type object was not successfully created and inserted into the itemtypes table |
223 |
unless ($@) { |
413 |
if ($itemtype) { |
224 |
push @messages, |
414 |
$message = 'success_on_insert'; |
225 |
{ type => 'message', code => 'success_on_insert_itemtype' }; |
415 |
} |
226 |
} |
416 |
else { |
227 |
else { |
417 |
$message = 'error_on_insert'; |
228 |
push @messages, |
|
|
229 |
{ type => 'message', code => 'error_on_insert_itemtype' }; |
418 |
} |
230 |
} |
419 |
$template->param( 'message' => $message ); |
|
|
420 |
} |
231 |
} |
|
|
232 |
|
233 |
$step++ if Koha::ItemTypes->count; |
421 |
} |
234 |
} |
422 |
elsif ( $step && $step == 5 ) { |
235 |
if ( $step == 5 ) { |
423 |
|
236 |
|
424 |
#Find all the existing categories to display in a dropdown box in the template |
237 |
if ( $op eq 'add_validate_circ_rule' ) { |
425 |
my $categories; |
238 |
|
426 |
$categories = Koha::Patron::Categories->search(); |
239 |
#If no libraries exist then set the $branch value to * |
427 |
$template->param( categories => $categories, ); |
240 |
my $branch = $input->param('branch') || '*'; |
428 |
|
|
|
429 |
#Find all the exisiting item types to display in a dropdown box in the template |
430 |
my $itemtypes; |
431 |
$itemtypes = Koha::ItemTypes->search(); |
432 |
$template->param( itemtypes => $itemtypes, ); |
433 |
|
434 |
my $input = CGI->new; |
435 |
|
436 |
my ( $template, $loggedinuser, $cookie ) = |
437 |
C4::InstallAuth::get_template_and_user( |
438 |
{ |
439 |
template_name => "/onboarding/onboardingstep5.tt", |
440 |
query => $input, |
441 |
type => "intranet", |
442 |
authnotrequired => 0, |
443 |
flagsrequired => { parameters => 'manage_circ_rules' }, |
444 |
debug => 1, |
445 |
} |
446 |
); |
447 |
|
448 |
#If no libraries exist then set the $branch value to * |
449 |
my $branch = $input->param('branch'); |
450 |
unless ($branch) { |
451 |
if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) { |
452 |
$branch = |
453 |
Koha::Libraries->search->count() == 1 |
454 |
? undef |
455 |
: C4::Context::mybranch(); |
456 |
} |
457 |
else { |
458 |
$branch = |
459 |
C4::Context::only_my_library() |
460 |
? ( C4::Context::mybranch() || '*' ) |
461 |
: '*'; |
462 |
} |
463 |
} |
464 |
$branch = '*' if $branch eq 'NO_LIBRARY_SET'; |
465 |
my $op = $input->param('op') || q{}; |
466 |
|
241 |
|
467 |
if ( $op eq 'add_validate' ) { |
|
|
468 |
my $type = $input->param('type'); |
242 |
my $type = $input->param('type'); |
469 |
my $br = $input->param('branch'); |
243 |
my $branchcode = $input->param('branch'); |
470 |
my $bor = $input->param('categorycode'); |
244 |
my $categorycode = $input->param('categorycode'); |
471 |
my $itemtype = $input->param('itemtype'); |
245 |
my $itemtype = $input->param('itemtype'); |
472 |
my $maxissueqty = $input->param('maxissueqty'); |
246 |
my $maxissueqty = $input->param('maxissueqty'); |
473 |
my $issuelength = $input->param('issuelength'); |
247 |
my $issuelength = $input->param('issuelength'); |
Lines 480-487
elsif ( $step && $step == 5 ) {
Link Here
|
480 |
$issuelength = $issuelength eq q{} ? undef : $issuelength; |
254 |
$issuelength = $issuelength eq q{} ? undef : $issuelength; |
481 |
|
255 |
|
482 |
my $params = { |
256 |
my $params = { |
483 |
branchcode => $br, |
257 |
branchcode => $branchcode, |
484 |
categorycode => $bor, |
258 |
categorycode => $categorycode, |
485 |
itemtype => $itemtype, |
259 |
itemtype => $itemtype, |
486 |
maxissueqty => $maxissueqty, |
260 |
maxissueqty => $maxissueqty, |
487 |
renewalsallowed => $renewalsallowed, |
261 |
renewalsallowed => $renewalsallowed, |
Lines 491-549
elsif ( $step && $step == 5 ) {
Link Here
|
491 |
onshelfholds => $onshelfholds, |
265 |
onshelfholds => $onshelfholds, |
492 |
}; |
266 |
}; |
493 |
|
267 |
|
494 |
my @messages; |
268 |
my $issuingrule = Koha::IssuingRule->new($params); |
495 |
|
269 |
eval { $issuingrule->store; }; |
496 |
#Allows for the 'All' option to work when selecting all libraries for a circulation rule to apply to. |
|
|
497 |
if ( $branch eq "*" ) { |
498 |
my $search_default_rules = |
499 |
$schema->resultset('DefaultCircRule')->count(); |
500 |
my $insert_default_rules = |
501 |
$schema->resultset('Issuingrule') |
502 |
->new( |
503 |
{ maxissueqty => $maxissueqty, onshelfholds => $onshelfholds } |
504 |
); |
505 |
} |
506 |
|
507 |
#Allows for the 'All' option to work when selecting all patron categories for a circulation rule to apply to. |
508 |
elsif ( $bor eq "*" ) { |
509 |
|
510 |
my $search_default_rules = |
511 |
$schema->resultset('DefaultCircRule')->count(); |
512 |
my $insert_default_rules = $schema->resultset('Issuingrule') |
513 |
->new( { maxissueqty => $maxissueqty } ); |
514 |
} |
515 |
|
516 |
#Allows for the 'All' option to work when selecting all itemtypes for a circulation rule to apply to |
517 |
elsif ( $itemtype eq "*" ) { |
518 |
my $search_default_rules = |
519 |
$schema->resultset('DefaultCircRule')->search( |
520 |
{}, |
521 |
{ |
522 |
branchcode => $branch |
523 |
} |
524 |
|
525 |
); |
526 |
|
270 |
|
527 |
my $insert_default_rules = $schema->resultset('Issuingrule') |
271 |
unless ($@) { |
528 |
->new( { branchcode => $branch, onshelfholds => $onshelfholds } ); |
|
|
529 |
} |
530 |
|
531 |
my $issuingrule = Koha::IssuingRules->find( |
532 |
{ categorycode => $bor, itemtype => $itemtype, branchcode => $br } |
533 |
); |
534 |
if ($issuingrule) { |
535 |
$issuingrule->set($params)->store(); |
536 |
push @messages, |
272 |
push @messages, |
537 |
{ |
273 |
{ type => 'message', code => 'success_on_insert_circ_rule' }; |
538 |
type => 'error', |
|
|
539 |
code => 'error_on_insert' |
540 |
}; #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. |
541 |
|
542 |
} |
274 |
} |
543 |
else { |
275 |
else { |
544 |
Koha::IssuingRule->new()->set($params)->store(); |
276 |
push @messages, |
|
|
277 |
{ type => 'message', code => 'error_on_insert_circ_rule' }; |
545 |
} |
278 |
} |
546 |
} |
279 |
} |
|
|
280 |
|
281 |
$step++ if Koha::IssuingRules->count; |
282 |
} |
283 |
|
284 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
285 |
$template_params->{libraries} = $libraries; |
286 |
$template_params->{group_types} = [ |
287 |
{ |
288 |
categorytype => 'searchdomain', |
289 |
categories => [ |
290 |
Koha::LibraryCategories->search( |
291 |
{ categorytype => 'searchdomain' } |
292 |
) |
293 |
], |
294 |
}, |
295 |
{ |
296 |
categorytype => 'properties', |
297 |
categories => [ |
298 |
Koha::LibraryCategories->search( { categorytype => 'properties' } ) |
299 |
], |
300 |
}, |
301 |
]; |
302 |
|
303 |
if ( $step > 5 ) { |
304 |
$template_params->{all_done} = 1; # If step 5 is complete, we are done! |
305 |
$step = 5; |
547 |
} |
306 |
} |
548 |
|
307 |
|
|
|
308 |
#Getting the appropriate template to display to the user |
309 |
my ( $template, $loggedinuser ); |
310 |
( $template, $loggedinuser, $cookie ) = C4::InstallAuth::get_template_and_user( |
311 |
{ |
312 |
template_name => "onboarding/onboardingstep${step}.tt", |
313 |
query => $input, |
314 |
type => "intranet", |
315 |
authnotrequired => 0, |
316 |
debug => 1, |
317 |
} |
318 |
); |
319 |
|
320 |
$template_params->{messages} = \@messages; |
321 |
my $categories = Koha::Patron::Categories->search(); |
322 |
$template_params->{categories} = $categories; |
323 |
|
324 |
my $itemtypes = Koha::ItemTypes->search(); |
325 |
$template_params->{itemtypes} = $itemtypes; |
326 |
|
327 |
$template->param(%$template_params); |
328 |
|
549 |
output_html_with_http_headers $input, $cookie, $template->output; |
329 |
output_html_with_http_headers $input, $cookie, $template->output; |