Lines 6-36
use diagnostics;
Link Here
|
6 |
|
6 |
|
7 |
|
7 |
|
8 |
use Modern::Perl; |
8 |
use Modern::Perl; |
|
|
9 |
|
10 |
#External modules |
9 |
use CGI qw ( -utf8 ); |
11 |
use CGI qw ( -utf8 ); |
|
|
12 |
use List::MoreUtils qw/uniq/; |
13 |
use Digest::MD5 qw(md5_base64); |
14 |
use Encode qw( encode ); |
15 |
|
16 |
#Internal modules |
10 |
use C4::Koha; |
17 |
use C4::Koha; |
11 |
use C4::Auth; |
18 |
use C4::Auth; |
12 |
use C4::Context; |
19 |
use C4::Context; |
13 |
use C4::Output; |
20 |
use C4::Output; |
|
|
21 |
use C4::Members; |
22 |
use C4::Members::Attributes; |
23 |
use C4::Members::AttributeTypes; |
24 |
use C4::Log; |
25 |
use C4::Letters; |
26 |
use C4::Form::MessagingPreferences; |
27 |
use Koha::AuthorisedValues; |
28 |
use Koha::Patron::Debarments; |
29 |
use Koha::Cities; |
14 |
use Koha::Patrons; |
30 |
use Koha::Patrons; |
15 |
use Koha::Items; |
31 |
use Koha::Items; |
16 |
use Koha::Libraries; |
32 |
use Koha::Libraries; |
17 |
use Koha::LibraryCategories; |
33 |
use Koha::LibraryCategories; |
18 |
|
34 |
use Koha::Database; |
19 |
|
35 |
use Koha::DateUtils; |
20 |
#use POSIX; |
36 |
use Koha::Patron::Categories; |
21 |
#use C4::Templates; |
37 |
use Koha::ItemTypes; |
22 |
#use C4::Languages qw(getAllLanguages getTranslatedLanguages); |
38 |
use Koha::Patron::HouseboundRole; |
23 |
#use C4::Installer; |
39 |
use Koha::Patron::HouseboundRoles; |
24 |
#use Koha; |
40 |
use Koha::Token; |
|
|
41 |
use Email::Valid; |
42 |
use Module::Load; |
43 |
|
44 |
#Imports for item types step 4 |
45 |
use Koha::ItemTypes; |
46 |
use Koha::Localizations; |
47 |
|
48 |
#Imports for circulation rule step 5 |
49 |
use Koha::IssuingRule; |
50 |
use Koha::IssuingRules; |
51 |
use Koha::Logger; |
52 |
use Koha::RefundLostItemFeeRule; |
53 |
use Koha::RefundLostItemFeeRules; |
25 |
|
54 |
|
26 |
#Setting variables |
55 |
#Setting variables |
27 |
my $input = new CGI; |
56 |
my $input = new CGI; |
28 |
my $query = new CGI; |
57 |
my $query = new CGI; |
29 |
my $step = $query->param('step'); |
58 |
my $step = $query->param('step'); |
30 |
|
59 |
|
|
|
60 |
#Getting the appropriate template to display to the user--> |
31 |
my ( $template, $loggedinuser, $cookie) = get_template_and_user( |
61 |
my ( $template, $loggedinuser, $cookie) = get_template_and_user( |
32 |
{ |
62 |
{ |
33 |
template_name => "/onboarding/onboardingstep" . ( $step ? $step : 1 ) . ".tt", |
63 |
template_name => "/onboarding/onboardingstep" . ( $step ? $step : 0 ) . ".tt", |
34 |
query => $query, |
64 |
query => $query, |
35 |
type => "intranet", |
65 |
type => "intranet", |
36 |
authnotrequired => 0, |
66 |
authnotrequired => 0, |
Lines 57-180
my $dbh = DBI->connect(
Link Here
|
57 |
); |
87 |
); |
58 |
|
88 |
|
59 |
|
89 |
|
|
|
90 |
#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. |
91 |
my $op = $query->param('op'); |
92 |
$template->param('op'=>$op); |
93 |
if ( $op && $op eq 'finish' ) { #If the value of $op equals 'finish' then redirect user to /cgi-bin/koha/mainpage.pl |
94 |
print $query->redirect("/cgi-bin/koha/mainpage.pl"); |
95 |
exit; |
96 |
} |
60 |
|
97 |
|
61 |
my $op = $query->param('op'); |
|
|
62 |
$template->param('op'=>$op); |
63 |
warn $op; |
64 |
if ( $op && $op eq 'finish' ) { |
65 |
print $query->redirect("/cgi-bin/koha/mainpage.pl"); |
66 |
exit; |
67 |
} |
68 |
|
69 |
|
70 |
|
71 |
#Performing each step of the onboarding tool |
72 |
if ( $step && $step == 1 ) { |
73 |
#This is the Initial step of the onboarding tool to create a library |
74 |
|
75 |
|
76 |
my $createlibrary = $query->param('createlibrary'); |
77 |
$template->param('createlibrary'=>$createlibrary); |
78 |
|
98 |
|
79 |
#store inputted parameters in variables |
99 |
#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 |
|
|
100 |
my $start = $query->param('start'); |
101 |
$template->param('start'=>$start); #Hand the start variable back to the template |
102 |
if ( $start && $start eq 'Start setting up my Koha' ){ |
103 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
104 |
$template->param(libraries => $libraries, |
105 |
group_types => [ |
106 |
{ categorytype => 'searchdomain', |
107 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], |
108 |
}, |
109 |
{ categorytype => 'properties', |
110 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], |
111 |
}, |
112 |
] |
113 |
); |
114 |
|
115 |
|
116 |
#Select any library records from the database and hand them back to the template in the libraries variable. |
117 |
}elsif ( $start && $start eq 'Add a patron category' ){ |
118 |
|
119 |
#Select all the patron category records in the categories database table and store them in the newly declared variable $categories |
120 |
my $categories = Koha::Patron::Categories->search(); |
121 |
$template->param( |
122 |
categories => $categories, |
123 |
); #Hand the variable categories back to the template |
124 |
|
125 |
}elsif ( $start && $start eq 'Add an item type' ){ |
126 |
my $itemtypes = Koha::ItemTypes->search(); |
127 |
warn $itemtypes; |
128 |
$template->param( |
129 |
itemtypes => $itemtypes, |
130 |
); |
131 |
|
132 |
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1 |
133 |
}elsif ( $step && $step == 1 ) { |
134 |
|
135 |
my $createlibrary = $query->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary |
136 |
$template->param('createlibrary'=>$createlibrary); # Hand the library values back to the template in the createlibrary variable |
137 |
|
138 |
#store inputted parameters in variables |
80 |
my $branchcode = $input->param('branchcode'); |
139 |
my $branchcode = $input->param('branchcode'); |
81 |
my $categorycode = $input->param('categorycode'); |
140 |
my $categorycode = $input->param('categorycode'); |
82 |
my $op = $input->param('op') || 'list'; |
141 |
my $op = $input->param('op') || 'list'; |
83 |
my @messages; |
142 |
my @messages; |
84 |
my $library; |
143 |
my $library; |
85 |
|
144 |
|
86 |
#Find branchcode if it exists |
145 |
#Take the text 'branchname' and store it in the @fields array |
87 |
if ( $op eq 'add_form' ) { |
146 |
my @fields = qw( |
88 |
if ($branchcode) { |
147 |
branchname |
89 |
$library = Koha::Libraries->find($branchcode); |
148 |
); |
90 |
} |
|
|
91 |
|
149 |
|
92 |
$template->param( |
150 |
$branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode |
93 |
library => $library, |
|
|
94 |
categories => [ Koha::LibraryCategories->search( {}, { order_by => [ 'categorytype', 'categoryname' ] } ) ], |
95 |
$library ? ( selected_categorycodes => [ map { $_->categorycode } $library->get_categories ] ) : (), |
96 |
); |
97 |
} elsif ( $op eq 'add_validate' ) { |
98 |
my @fields = qw( |
99 |
branchname |
100 |
); |
101 |
|
151 |
|
102 |
my $is_a_modif = $input->param('is_a_modif'); |
152 |
#Create a new library object and store the branchcode and @fields array values in this new library object |
103 |
|
153 |
my $library = Koha::Library->new( |
104 |
my @categories; |
154 |
{ branchcode => $branchcode, |
105 |
for my $category ( Koha::LibraryCategories->search ) { |
155 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
106 |
push @categories, $category |
156 |
} |
107 |
if $input->param( "selected_categorycode_" . $category->categorycode ); |
157 |
); |
108 |
} |
|
|
109 |
if ($is_a_modif) { |
110 |
my $library = Koha::Libraries->find($branchcode); |
111 |
for my $field (@fields) { |
112 |
$library->$field( scalar $input->param($field) ); |
113 |
} |
114 |
$library->update_categories( \@categories ); |
115 |
|
158 |
|
116 |
eval { $library->store; }; |
159 |
eval { $library->store; }; #Use the eval{} function to store the library object |
117 |
|
160 |
|
118 |
if ($@) { |
161 |
#If there are values in the $@ then push the values type => 'alert', code => 'error_on_insert' into the @messages array el se push the values type => 'message', code => 'success_on_insert' to that array |
119 |
push @messages, { type => 'alert', code => 'error_on_update' }; |
162 |
if ($@) { |
120 |
} else { |
163 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
121 |
push @messages, { type => 'message', code => 'success_on_update' }; |
164 |
} else { |
122 |
} |
165 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
123 |
} else { |
|
|
124 |
$branchcode =~ s|\s||g; |
125 |
my $library = Koha::Library->new( |
126 |
{ branchcode => $branchcode, |
127 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
128 |
} |
129 |
); |
130 |
eval { $library->store; }; |
131 |
$library->add_to_categories( \@categories ); |
132 |
if ($@) { |
133 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
134 |
} else { |
135 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
136 |
} |
137 |
} |
138 |
$op = 'list'; |
139 |
} |
166 |
} |
140 |
|
167 |
|
141 |
|
168 |
#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 |
142 |
}elsif ( $step && $step == 2 ){ |
169 |
}elsif ( $step && $step == 2 ){ |
143 |
|
170 |
|
144 |
my $createpatroncategory = $query->param('createpatroncategory'); |
171 |
#Initialising values |
145 |
$template->param('createpatroncategory'=>$createpatroncategory); |
172 |
my $input = new CGI; |
|
|
173 |
my $searchfield = $input->param('description') // q||; |
174 |
my $categorycode = $input->param('categorycode'); |
175 |
my $op = $input->param('op') // 'list'; |
176 |
my @messages; |
146 |
|
177 |
|
|
|
178 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
179 |
{ |
180 |
template_name => "/onboarding/onboardingstep2.tt", |
181 |
query => $input, |
182 |
type => "intranet", |
183 |
authnotrequired => 0, |
184 |
flagsrequired => { parameters => 'parameters_remaining_permissions' }, |
185 |
debug => 1, |
186 |
} |
187 |
); |
188 |
#When the user first arrives on the page |
189 |
if ( $op eq 'add_form' ) { |
190 |
my $category; |
191 |
if ($categorycode) { |
192 |
$category = Koha::Patron::Categories->find($categorycode); |
193 |
} |
194 |
|
195 |
$template->param( |
196 |
category => $category, |
197 |
); |
198 |
|
199 |
if ( C4::Context->preference('EnhancedMessagingPreferences') ) { |
200 |
C4::Form::MessagingPreferences::set_form_values( |
201 |
{ categorycode => $categorycode }, $template ); |
202 |
} |
203 |
} |
204 |
#Once the user submits the page, this code validates the input and adds it |
205 |
#to the database as a new patron category |
206 |
elsif ( $op eq 'add_validate' ) { |
207 |
my $categorycode = $input->param('categorycode'); |
208 |
my $description = $input->param('description'); |
209 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
210 |
my $category_type = $input->param('category_type'); |
211 |
my $default_privacy = $input->param('default_privacy'); |
212 |
my $enrolmentperiod = $input->param('enrolmentperiod'); |
213 |
my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef; |
214 |
|
215 |
#Converts the string into a date format |
216 |
if ( $enrolmentperioddate) { |
217 |
$enrolmentperioddate = output_pref( |
218 |
{ |
219 |
dt => dt_from_string($enrolmentperioddate), |
220 |
dateformat => 'iso', |
221 |
dateonly => 1, |
222 |
} |
223 |
); |
224 |
} |
225 |
#Adds to the database |
226 |
my $category = Koha::Patron::Category->new({ |
227 |
categorycode=> $categorycode, |
228 |
description => $description, |
229 |
overduenoticerequired => $overduenoticerequired, |
230 |
category_type=> $category_type, |
231 |
default_privacy => $default_privacy, |
232 |
enrolmentperiod => $enrolmentperiod, |
233 |
enrolmentperioddate => $enrolmentperioddate, |
234 |
}); |
235 |
eval { |
236 |
$category->store; |
237 |
}; |
238 |
|
239 |
#Error messages |
240 |
if($@){ |
241 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
242 |
}else{ |
243 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
244 |
} |
245 |
} |
246 |
#Create a patron |
147 |
}elsif ( $step && $step == 3 ){ |
247 |
}elsif ( $step && $step == 3 ){ |
148 |
|
248 |
|
149 |
my $createpatron = $query->param('createpatron'); |
249 |
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); |
150 |
$template->param('createpatron'=>$createpatron); |
250 |
$template->param(libraries => $libraries, |
|
|
251 |
group_types => [ |
252 |
{ categorytype => 'searchdomain', |
253 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'searchdomain' } ) ], |
254 |
}, |
255 |
{ categorytype => 'properties', |
256 |
categories => [ Koha::LibraryCategories->search( { categorytype => 'properties' } ) ], |
257 |
}, |
258 |
] |
259 |
); |
260 |
|
261 |
my $categories; |
262 |
$categories= Koha::Patron::Categories->search(); |
263 |
$template->param( |
264 |
categories => $categories, |
265 |
); |
151 |
|
266 |
|
152 |
}elsif ( $step && $step == 4){ |
|
|
153 |
|
267 |
|
154 |
my $createitemtype = $query->param('createitemtype'); |
|
|
155 |
$template->param('createitemtype'=>$createitemtype); |
156 |
|
268 |
|
157 |
}elsif ( $step && $step == 5){ |
269 |
my $input = new CGI; |
|
|
270 |
my $op = $input->param('op'); |
271 |
my @messages; |
158 |
|
272 |
|
159 |
my $createcirculationrule = $query->param('createcirculationrule'); |
273 |
my ($template, $loggedinuser, $cookie) |
160 |
$template->param('createcirculationrule'=>$createcirculationrule); |
274 |
= get_template_and_user({ |
|
|
275 |
template_name => "/onboarding/onboardingstep3.tt", |
276 |
query => $input, |
277 |
type => "intranet", |
278 |
authnotrequired => 0, |
279 |
flagsrequired => {borrowers => 1}, |
280 |
debug => 1, |
281 |
}); |
161 |
|
282 |
|
|
|
283 |
if($op eq 'add_form'){ |
284 |
my $member; |
285 |
$template->param( |
286 |
member => $member, |
287 |
); |
162 |
|
288 |
|
163 |
} |
|
|
164 |
|
289 |
|
|
|
290 |
} |
291 |
elsif($op eq 'add_validate'){ |
292 |
my $surname => $input->param('surname'); |
293 |
my $firstname => $input->param('firstname'); |
294 |
my $cardnumber => $input->param('cardnumber'); |
295 |
my $libraries => $input->param('libraries'); |
296 |
my $categorycode_entry => $input->param('categorycode_entry'); |
297 |
my $userid => $input->param('userid'); |
298 |
my $password => $input->param('password'); |
299 |
my $password2 =>$input->param('password2'); |
300 |
|
301 |
my $member = Koha::Patron->new({ |
302 |
surname => $surname, |
303 |
firstname => $firstname, |
304 |
cardnumber => $cardnumber, |
305 |
libraries => $libraries, |
306 |
categorycode_entry => $categorycode_entry, |
307 |
userid => $userid, |
308 |
password => $password, |
309 |
password2 => $password2, |
310 |
}); |
311 |
eval { |
312 |
$member->store; |
313 |
}; |
314 |
if($@){ |
315 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
316 |
}else{ |
317 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
318 |
} |
319 |
|
320 |
} |
165 |
|
321 |
|
|
|
322 |
#Create item type |
323 |
}elsif ( $step && $step == 4){ |
324 |
my $input = new CGI; |
325 |
my $itemtype_code = $input->param('itemtype'); |
326 |
my $op = $input->param('op') // 'list'; |
327 |
my @messages; |
166 |
|
328 |
|
|
|
329 |
my( $template, $borrowernumber, $cookie) = get_template_and_user( |
330 |
{ template_name => "/onboarding/onboardingstep4.tt", |
331 |
query => $input, |
332 |
type => "intranet", |
333 |
authnotrequired => 0, |
334 |
flagsrequired => { parameters => 'parameters_remaining_permissions'}, |
335 |
debug => 1, |
336 |
} |
337 |
); |
338 |
|
339 |
if($op eq 'add_form'){ |
340 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
341 |
template->param(itemtype=>$itemtype,); |
342 |
}elsif($op eq 'add_validate'){ |
343 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
344 |
my $description = $input->param('description'); |
345 |
|
346 |
#store the input from the form - only 2 fields |
347 |
my $itemtype= Koha::ItemType->new( |
348 |
{ itemtype => $itemtype_code, |
349 |
description => $description, |
350 |
} |
351 |
); |
352 |
eval{ $itemtype->store; }; |
353 |
#Error messages |
354 |
if($@){ |
355 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
356 |
}else{ |
357 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
358 |
} |
359 |
} |
167 |
|
360 |
|
|
|
361 |
}elsif ( $step && $step == 5){ |
362 |
#Fetching all the existing categories to display in a drop down box |
363 |
my $categories; |
364 |
$categories= Koha::Patron::Categories->search(); |
365 |
$template->param( |
366 |
categories => $categories, |
367 |
); |
368 |
|
369 |
my $itemtypes; |
370 |
$itemtypes= Koha::ItemTypes->search(); |
371 |
$template->param( |
372 |
itemtypes => $itemtypes, |
373 |
); |
374 |
|
375 |
my $input = CGI->new; |
376 |
my($template, $loggedinuser, $cookie) =get_template_and_user({ |
377 |
template_name => "/onboarding/onboardingstep5.tt", |
378 |
query => $input, |
379 |
type => "intranet", |
380 |
authnotrequired=>0, |
381 |
flagsrequired=> {parameters => 'manage_circ_rules'}, |
382 |
debug =>1, |
383 |
}); |
384 |
|
385 |
my $type = $input->param('type'); |
386 |
my $branch = $input->param('branch'); |
387 |
|
388 |
|
389 |
|
390 |
if($op eq 'add_form'){ |
168 |
|
391 |
|
169 |
|
392 |
|
170 |
|
393 |
|
171 |
output_html_with_http_headers $input, $cookie, $template->output; |
394 |
} |
|
|
395 |
elsif($op eq 'add_validate'){ |
396 |
my $bor = $input->param('categorycode'); |
397 |
my $itemtype = $input->param('itemtype'); |
398 |
my $maxissueqty = $input->param('maxissueqty'); |
399 |
my $issuelength = $input->param('issuelength'); |
400 |
#$issuelength = $issuelength eq q{} ? undef : $issuelength; |
401 |
my $lengthunit = $input->param('lengthunit'); |
402 |
my $renewalsallowed = $input->param('renewalsallowed'); |
403 |
my $renewalperiod = $input->param('renewalperiod'); |
404 |
my $onshelfholds = $input->param('onshelfholds'); |
405 |
|
406 |
my $params ={ |
407 |
categorycode => $bor, |
408 |
itemtype => $itemtype, |
409 |
maxissueqty => $maxissueqty, |
410 |
renewalsallowed => $renewalsallowed, |
411 |
renewalperiod => $renewalperiod, |
412 |
lengthunit => $lengthunit, |
413 |
onshelfholds => $onshelfholds, |
414 |
}; |
415 |
my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype}); |
416 |
if($issuingrule){ |
417 |
$issuingrule->set($params)->store(); |
418 |
}else{ |
419 |
Koha::IssuingRule->new()->set($params)->store(); |
420 |
} |
172 |
|
421 |
|
|
|
422 |
|
423 |
} |
424 |
|
173 |
|
425 |
|
174 |
|
426 |
|
175 |
|
427 |
|
|
|
428 |
} |
176 |
|
429 |
|
177 |
|
430 |
|
178 |
|
431 |
|
179 |
|
432 |
|
|
|
433 |
output_html_with_http_headers $input, $cookie, $template->output; |
180 |
|
434 |
|