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