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