Lines 41-57
use Koha::Token;
Link Here
|
41 |
use Email::Valid; |
41 |
use Email::Valid; |
42 |
use Module::Load; |
42 |
use Module::Load; |
43 |
|
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; |
54 |
|
55 |
#Setting variables |
44 |
#Setting variables |
56 |
my $input = new CGI; |
45 |
my $input = new CGI; |
57 |
my $query = new CGI; |
46 |
my $query = new CGI; |
Lines 124-130
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
124 |
|
113 |
|
125 |
}elsif ( $start && $start eq 'Add an item type' ){ |
114 |
}elsif ( $start && $start eq 'Add an item type' ){ |
126 |
my $itemtypes = Koha::ItemTypes->search(); |
115 |
my $itemtypes = Koha::ItemTypes->search(); |
127 |
warn $itemtypes; |
|
|
128 |
$template->param( |
116 |
$template->param( |
129 |
itemtypes => $itemtypes, |
117 |
itemtypes => $itemtypes, |
130 |
); |
118 |
); |
Lines 139-156
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
139 |
my $branchcode = $input->param('branchcode'); |
127 |
my $branchcode = $input->param('branchcode'); |
140 |
my $categorycode = $input->param('categorycode'); |
128 |
my $categorycode = $input->param('categorycode'); |
141 |
my $op = $input->param('op') || 'list'; |
129 |
my $op = $input->param('op') || 'list'; |
142 |
my @messages; |
130 |
my $message; |
143 |
my $library; |
131 |
my $library; |
|
|
132 |
#my @messages; |
144 |
|
133 |
|
145 |
#Take the text 'branchname' and store it in the @fields array |
134 |
#Take the text 'branchname' and store it in the @fields array |
146 |
my @fields = qw( |
135 |
my @fields = qw( |
147 |
branchname |
136 |
branchname |
148 |
); |
137 |
); |
149 |
|
138 |
|
|
|
139 |
|
140 |
#test |
141 |
$template->param('branchcode'=>$branchcode); |
142 |
|
150 |
$branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode |
143 |
$branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode |
151 |
|
144 |
|
152 |
#Create a new library object and store the branchcode and @fields array values in this new library object |
145 |
#Create a new library object and store the branchcode and @fields array values in this new library object |
153 |
my $library = Koha::Library->new( |
146 |
$library = Koha::Library->new( |
154 |
{ branchcode => $branchcode, |
147 |
{ branchcode => $branchcode, |
155 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
148 |
( map { $_ => scalar $input->param($_) || undef } @fields ) |
156 |
} |
149 |
} |
Lines 158-179
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
158 |
|
151 |
|
159 |
eval { $library->store; }; #Use the eval{} function to store the library object |
152 |
eval { $library->store; }; #Use the eval{} function to store the library object |
160 |
|
153 |
|
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 |
154 |
if($library){ |
162 |
if ($@) { |
155 |
$message = 'success_on_insert'; |
163 |
push @messages, { type => 'alert', code => 'error_on_insert' }; |
156 |
}else{ |
164 |
} else { |
157 |
$message = 'error_on_insert'; |
165 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
158 |
} |
166 |
} |
159 |
|
|
|
160 |
$template->param('message' => $message); |
161 |
|
167 |
|
162 |
|
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 |
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 |
169 |
}elsif ( $step && $step == 2 ){ |
164 |
}elsif ( $step && $step == 2 ){ |
|
|
165 |
my $createcat = $query->param('createcat'); #Store the inputted library branch code and name in $createlibrary |
166 |
$template->param('createcat'=>$createcat); # Hand the library values back to the template in the createlibrary variable |
167 |
|
170 |
|
168 |
|
171 |
#Initialising values |
169 |
#Initialising values |
172 |
my $input = new CGI; |
170 |
my $input = new CGI; |
173 |
my $searchfield = $input->param('description') // q||; |
171 |
my $searchfield = $input->param('description') // q||; |
174 |
my $categorycode = $input->param('categorycode'); |
172 |
my $categorycode = $input->param('categorycode'); |
175 |
my $op = $input->param('op') // 'list'; |
173 |
my $op = $input->param('op') // 'list'; |
176 |
my @messages; |
174 |
my $message; |
|
|
175 |
my $category; |
177 |
|
176 |
|
178 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
177 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
179 |
{ |
178 |
{ |
Lines 185-209
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
185 |
debug => 1, |
184 |
debug => 1, |
186 |
} |
185 |
} |
187 |
); |
186 |
); |
188 |
#When the user first arrives on the page |
187 |
|
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 |
|
188 |
|
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 |
189 |
#Once the user submits the page, this code validates the input and adds it |
205 |
#to the database as a new patron category |
190 |
#to the database as a new patron category |
206 |
elsif ( $op eq 'add_validate' ) { |
191 |
#} elsif ( $op eq 'add_validate' ) { |
|
|
192 |
|
207 |
my $categorycode = $input->param('categorycode'); |
193 |
my $categorycode = $input->param('categorycode'); |
208 |
my $description = $input->param('description'); |
194 |
my $description = $input->param('description'); |
209 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
195 |
my $overduenoticerequired = $input->param('overduenoticerequired'); |
Lines 223-229
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
223 |
); |
209 |
); |
224 |
} |
210 |
} |
225 |
#Adds to the database |
211 |
#Adds to the database |
226 |
my $category = Koha::Patron::Category->new({ |
212 |
$category = Koha::Patron::Category->new({ |
227 |
categorycode=> $categorycode, |
213 |
categorycode=> $categorycode, |
228 |
description => $description, |
214 |
description => $description, |
229 |
overduenoticerequired => $overduenoticerequired, |
215 |
overduenoticerequired => $overduenoticerequired, |
Lines 236-248
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
236 |
$category->store; |
222 |
$category->store; |
237 |
}; |
223 |
}; |
238 |
|
224 |
|
239 |
#Error messages |
225 |
#Error messages |
240 |
if($@){ |
226 |
if($category){ |
241 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
227 |
$message = 'success_on_insert'; |
242 |
}else{ |
228 |
}else{ |
243 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
229 |
$message = 'error_on_insert'; |
244 |
} |
230 |
} |
245 |
} |
231 |
|
|
|
232 |
$template->param('message' => $message); |
233 |
|
246 |
#Create a patron |
234 |
#Create a patron |
247 |
}elsif ( $step && $step == 3 ){ |
235 |
}elsif ( $step && $step == 3 ){ |
248 |
|
236 |
|
Lines 258-330
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
258 |
] |
246 |
] |
259 |
); |
247 |
); |
260 |
|
248 |
|
261 |
my $categories; |
249 |
my $categories; |
262 |
$categories= Koha::Patron::Categories->search(); |
250 |
$categories= Koha::Patron::Categories->search(); |
263 |
$template->param( |
251 |
$template->param( |
264 |
categories => $categories, |
252 |
categories => $categories, |
265 |
); |
253 |
); |
266 |
|
|
|
267 |
|
254 |
|
268 |
|
255 |
|
269 |
my $input = new CGI; |
256 |
my $input = new CGI; |
270 |
my $op = $input->param('op'); |
257 |
my $op = $input->param('op') // 'list'; |
|
|
258 |
|
271 |
my @messages; |
259 |
my @messages; |
272 |
|
260 |
|
273 |
my ($template, $loggedinuser, $cookie) |
261 |
my ($template, $loggedinuser, $cookie)= get_template_and_user({ |
274 |
= get_template_and_user({ |
|
|
275 |
template_name => "/onboarding/onboardingstep3.tt", |
262 |
template_name => "/onboarding/onboardingstep3.tt", |
276 |
query => $input, |
263 |
query => $input, |
277 |
type => "intranet", |
264 |
type => "intranet", |
278 |
authnotrequired => 0, |
265 |
authnotrequired => 0, |
279 |
flagsrequired => {borrowers => 1}, |
266 |
flagsrequired => {borrowers => 1}, |
280 |
debug => 1, |
267 |
debug => 1, |
281 |
}); |
268 |
}); |
282 |
|
269 |
|
283 |
if($op eq 'add_form'){ |
270 |
if($op eq 'add_form'){ |
284 |
my $member; |
271 |
my $member; |
285 |
$template->param( |
272 |
$template->param( |
286 |
member => $member, |
273 |
member => $member, |
287 |
); |
274 |
); |
288 |
|
|
|
289 |
|
290 |
} |
275 |
} |
|
|
276 |
|
291 |
elsif($op eq 'add_validate'){ |
277 |
elsif($op eq 'add_validate'){ |
292 |
my $surname => $input->param('surname'); |
278 |
|
293 |
my $firstname => $input->param('firstname'); |
279 |
my %newdata; |
294 |
my $cardnumber => $input->param('cardnumber'); |
280 |
|
295 |
my $libraries => $input->param('libraries'); |
281 |
#Store the template form values in the newdata hash |
296 |
my $categorycode_entry => $input->param('categorycode_entry'); |
282 |
$newdata{borrowernumber} = $input->param('borrowernumber'); |
297 |
my $userid => $input->param('userid'); |
283 |
$newdata{surname} = $input->param('surname'); |
298 |
my $password => $input->param('password'); |
284 |
$newdata{firstname} = $input->param('firstname'); |
299 |
my $password2 =>$input->param('password2'); |
285 |
$newdata{cardnumber} = $input->param('cardnumber'); |
300 |
|
286 |
$newdata{branchcode} = $input->param('libraries'); |
301 |
my $member = Koha::Patron->new({ |
287 |
$newdata{categorycode} = $input->param('categorycode_entry'); |
302 |
surname => $surname, |
288 |
$newdata{userid} = $input->param('userid'); |
303 |
firstname => $firstname, |
289 |
$newdata{password} = $input->param('password'); |
304 |
cardnumber => $cardnumber, |
290 |
$newdata{password2} = $input->param('password2'); |
305 |
libraries => $libraries, |
291 |
$newdata{dateexpiry} = '12/10/2016'; |
306 |
categorycode_entry => $categorycode_entry, |
292 |
|
307 |
userid => $userid, |
293 |
#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 |
308 |
password => $password, |
294 |
my $borrowernumber = &AddMember(%newdata); |
309 |
password2 => $password2, |
295 |
my %member2; |
310 |
}); |
296 |
$member2{'borrowernumber'}=$borrowernumber; |
311 |
eval { |
297 |
|
312 |
$member->store; |
298 |
my $flag = $input->param('flag'); |
313 |
}; |
299 |
|
314 |
if($@){ |
300 |
if ($input->param('newflags')) { |
|
|
301 |
my $dbh=C4::Context->dbh(); |
302 |
my @perms = $input->multi_param('flag'); |
303 |
my %all_module_perms = (); |
304 |
my %sub_perms = (); |
305 |
foreach my $perm (@perms) { |
306 |
if ($perm !~ /:/) { |
307 |
$all_module_perms{$perm} = 1; |
308 |
} else { |
309 |
my ($module, $sub_perm) = split /:/, $perm, 2; |
310 |
push @{ $sub_perms{$module} }, $sub_perm; |
311 |
} |
312 |
} |
313 |
|
314 |
|
315 |
# construct flags |
316 |
my $module_flags = 0; |
317 |
my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit"); |
318 |
$sth->execute(); |
319 |
while (my ($bit, $flag) = $sth->fetchrow_array) { |
320 |
if (exists $all_module_perms{$flag}) { |
321 |
$module_flags += 2**$bit; |
322 |
} |
323 |
} |
324 |
|
325 |
$sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?"); |
326 |
$sth->execute($module_flags, $borrowernumber); |
327 |
|
328 |
|
329 |
#Error handling checking if the patron was created successfully |
330 |
if(!$borrowernumber){ |
315 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
331 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
316 |
}else{ |
332 |
}else{ |
317 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
333 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
318 |
} |
334 |
} |
319 |
|
|
|
320 |
} |
335 |
} |
321 |
|
|
|
322 |
#Create item type |
323 |
}elsif ( $step && $step == 4){ |
336 |
}elsif ( $step && $step == 4){ |
|
|
337 |
my $createitemtype = $input->param('createitemtype'); |
338 |
$template->param('createitemtype'=> $createitemtype ); |
339 |
|
324 |
my $input = new CGI; |
340 |
my $input = new CGI; |
325 |
my $itemtype_code = $input->param('itemtype'); |
341 |
my $itemtype_code = $input->param('itemtype'); |
326 |
my $op = $input->param('op') // 'list'; |
342 |
my $op = $input->param('op') // 'list'; |
327 |
my @messages; |
343 |
my $message; |
328 |
|
344 |
|
329 |
my( $template, $borrowernumber, $cookie) = get_template_and_user( |
345 |
my( $template, $borrowernumber, $cookie) = get_template_and_user( |
330 |
{ template_name => "/onboarding/onboardingstep4.tt", |
346 |
{ template_name => "/onboarding/onboardingstep4.tt", |
Lines 338-344
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
338 |
|
354 |
|
339 |
if($op eq 'add_form'){ |
355 |
if($op eq 'add_form'){ |
340 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
356 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
341 |
template->param(itemtype=>$itemtype,); |
357 |
$template->param(itemtype=> $itemtype,); |
342 |
}elsif($op eq 'add_validate'){ |
358 |
}elsif($op eq 'add_validate'){ |
343 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
359 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
344 |
my $description = $input->param('description'); |
360 |
my $description = $input->param('description'); |
Lines 351-361
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
351 |
); |
367 |
); |
352 |
eval{ $itemtype->store; }; |
368 |
eval{ $itemtype->store; }; |
353 |
#Error messages |
369 |
#Error messages |
354 |
if($@){ |
370 |
if($itemtype){ |
355 |
push @messages, {type=> 'error', code => 'error_on_insert'}; |
371 |
$message = 'success_on_insert'; |
356 |
}else{ |
372 |
}else{ |
357 |
push @messages, {type=> 'message', code => 'success_on_insert'}; |
373 |
$message = 'error_on_insert'; |
358 |
} |
374 |
} |
|
|
375 |
|
376 |
$template->param('message' => $message); |
359 |
} |
377 |
} |
360 |
|
378 |
|
361 |
}elsif ( $step && $step == 5){ |
379 |
}elsif ( $step && $step == 5){ |
Lines 381-392
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
381 |
flagsrequired=> {parameters => 'manage_circ_rules'}, |
399 |
flagsrequired=> {parameters => 'manage_circ_rules'}, |
382 |
debug =>1, |
400 |
debug =>1, |
383 |
}); |
401 |
}); |
384 |
|
402 |
|
385 |
my $type = $input->param('type'); |
403 |
my $type = $input->param('type'); |
386 |
my $branch = $input->param('branch'); |
404 |
my $branch = $input->param('branch'); |
387 |
|
405 |
|
388 |
|
406 |
|
389 |
|
407 |
|
390 |
if($op eq 'add_form'){ |
408 |
if($op eq 'add_form'){ |
391 |
|
409 |
|
392 |
|
410 |
|
Lines 418-434
if ( $start && $start eq 'Start setting up my Koha' ){
Link Here
|
418 |
}else{ |
436 |
}else{ |
419 |
Koha::IssuingRule->new()->set($params)->store(); |
437 |
Koha::IssuingRule->new()->set($params)->store(); |
420 |
} |
438 |
} |
421 |
|
|
|
422 |
|
423 |
} |
439 |
} |
424 |
|
|
|
425 |
|
426 |
|
427 |
|
440 |
|
|
|
441 |
my $createcirculationrule = $query->param('createcirculationrule'); |
442 |
$template->param('createcirculationrule'=>$createcirculationrule); |
428 |
} |
443 |
} |
429 |
|
444 |
|
430 |
|
445 |
} |
431 |
|
|
|
432 |
|
446 |
|
433 |
output_html_with_http_headers $input, $cookie, $template->output; |
447 |
output_html_with_http_headers $input, $cookie, $template->output; |
434 |
|
448 |
|