|
Lines 26-38
Link Here
|
| 26 |
# And for patron attributes. |
26 |
# And for patron attributes. |
| 27 |
|
27 |
|
| 28 |
use Modern::Perl; |
28 |
use Modern::Perl; |
| 29 |
use CGI qw ( -utf8 ); |
29 |
use CGI qw ( -utf8 ); |
| 30 |
use C4::Auth qw( get_template_and_user ); |
30 |
use C4::Auth qw( get_template_and_user ); |
| 31 |
use C4::Koha qw( GetAuthorisedValues ); |
31 |
use C4::Koha qw( GetAuthorisedValues ); |
| 32 |
use C4::Members; |
32 |
use C4::Members; |
| 33 |
use C4::Output qw( output_html_with_http_headers ); |
33 |
use C4::Output qw( output_html_with_http_headers ); |
| 34 |
use C4::Context; |
34 |
use C4::Context; |
| 35 |
use Koha::DateUtils qw( dt_from_string ); |
35 |
use Koha::DateUtils qw( dt_from_string ); |
| 36 |
use Koha::List::Patron qw( GetPatronLists ); |
36 |
use Koha::List::Patron qw( GetPatronLists ); |
| 37 |
use Koha::Libraries; |
37 |
use Koha::Libraries; |
| 38 |
use Koha::Patron::Categories; |
38 |
use Koha::Patron::Categories; |
|
Lines 42-61
use List::MoreUtils qw(uniq);
Link Here
|
| 42 |
use Koha::Patron::Messages; |
42 |
use Koha::Patron::Messages; |
| 43 |
|
43 |
|
| 44 |
my $input = CGI->new; |
44 |
my $input = CGI->new; |
| 45 |
my $op = $input->param('op') || 'show_form'; |
45 |
my $op = $input->param('op') || 'show_form'; |
| 46 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
46 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
| 47 |
{ template_name => "tools/modborrowers.tt", |
47 |
{ |
| 48 |
query => $input, |
48 |
template_name => "tools/modborrowers.tt", |
| 49 |
type => "intranet", |
49 |
query => $input, |
| 50 |
flagsrequired => { tools => "edit_patrons" }, |
50 |
type => "intranet", |
|
|
51 |
flagsrequired => { tools => "edit_patrons" }, |
| 51 |
} |
52 |
} |
| 52 |
); |
53 |
); |
| 53 |
|
54 |
|
| 54 |
my $logged_in_user = Koha::Patrons->find( $loggedinuser ); |
55 |
my $logged_in_user = Koha::Patrons->find($loggedinuser); |
| 55 |
|
56 |
|
| 56 |
$template->param( CanUpdatePasswordExpiration => 1 ) if $logged_in_user->is_superlibrarian; |
57 |
$template->param( CanUpdatePasswordExpiration => 1 ) if $logged_in_user->is_superlibrarian; |
| 57 |
|
58 |
|
| 58 |
my $dbh = C4::Context->dbh; |
59 |
my $dbh = C4::Context->dbh; |
| 59 |
|
60 |
|
| 60 |
# Show borrower informations |
61 |
# Show borrower informations |
| 61 |
if ( $op eq 'cud-show' || $op eq 'show' ) { |
62 |
if ( $op eq 'cud-show' || $op eq 'show' ) { |
|
Lines 65-74
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 65 |
my $useborrowernumbers = 0; |
66 |
my $useborrowernumbers = 0; |
| 66 |
|
67 |
|
| 67 |
# Get cardnumbers from a file or the input area |
68 |
# Get cardnumbers from a file or the input area |
| 68 |
if( my $cardnumberlist = $input->param('cardnumberlist') ){ |
69 |
if ( my $cardnumberlist = $input->param('cardnumberlist') ) { |
|
|
70 |
|
| 69 |
# User submitted a list of card numbers |
71 |
# User submitted a list of card numbers |
| 70 |
push @patronidnumbers, split( /\s\n/, $cardnumberlist ); |
72 |
push @patronidnumbers, split( /\s\n/, $cardnumberlist ); |
| 71 |
} elsif ( my $cardnumberuploadfile = $input->param('cardnumberuploadfile') ){ |
73 |
} elsif ( my $cardnumberuploadfile = $input->param('cardnumberuploadfile') ) { |
|
|
74 |
|
| 72 |
# User uploaded a file of card numbers |
75 |
# User uploaded a file of card numbers |
| 73 |
binmode $cardnumberuploadfile, ':encoding(UTF-8)'; |
76 |
binmode $cardnumberuploadfile, ':encoding(UTF-8)'; |
| 74 |
while ( my $content = <$cardnumberuploadfile> ) { |
77 |
while ( my $content = <$cardnumberuploadfile> ) { |
|
Lines 76-86
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 76 |
$content =~ s/[\r\n]*$//; |
79 |
$content =~ s/[\r\n]*$//; |
| 77 |
push @patronidnumbers, $content if $content; |
80 |
push @patronidnumbers, $content if $content; |
| 78 |
} |
81 |
} |
| 79 |
} elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ){ |
82 |
} elsif ( my $borrowernumberlist = $input->param('borrowernumberlist') ) { |
|
|
83 |
|
| 80 |
# User submitted a list of borrowernumbers |
84 |
# User submitted a list of borrowernumbers |
| 81 |
$useborrowernumbers = 1; |
85 |
$useborrowernumbers = 1; |
| 82 |
push @patronidnumbers, split( /\s\n/, $borrowernumberlist ); |
86 |
push @patronidnumbers, split( /\s\n/, $borrowernumberlist ); |
| 83 |
} elsif ( my $borrowernumberuploadfile = $input->param('borrowernumberuploadfile') ){ |
87 |
} elsif ( my $borrowernumberuploadfile = $input->param('borrowernumberuploadfile') ) { |
|
|
88 |
|
| 84 |
# User uploaded a file of borrowernumbers |
89 |
# User uploaded a file of borrowernumbers |
| 85 |
$useborrowernumbers = 1; |
90 |
$useborrowernumbers = 1; |
| 86 |
binmode $borrowernumberuploadfile, ':encoding(UTF-8)'; |
91 |
binmode $borrowernumberuploadfile, ':encoding(UTF-8)'; |
|
Lines 89-127
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 89 |
$content =~ s/[\r\n]*$//; |
94 |
$content =~ s/[\r\n]*$//; |
| 90 |
push @patronidnumbers, $content if $content; |
95 |
push @patronidnumbers, $content if $content; |
| 91 |
} |
96 |
} |
| 92 |
} elsif ( my $patron_list_id = $input->param('patron_list_id') ){ |
97 |
} elsif ( my $patron_list_id = $input->param('patron_list_id') ) { |
|
|
98 |
|
| 93 |
# User selected a patron list |
99 |
# User selected a patron list |
| 94 |
my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); |
100 |
my ($list) = GetPatronLists( { patron_list_id => $patron_list_id } ); |
| 95 |
@patronidnumbers = |
101 |
@patronidnumbers = |
| 96 |
$list->patron_list_patrons()->search_related('borrowernumber') |
102 |
$list->patron_list_patrons()->search_related('borrowernumber')->get_column('cardnumber')->all(); |
| 97 |
->get_column('cardnumber')->all(); |
|
|
| 98 |
} |
103 |
} |
| 99 |
|
104 |
|
| 100 |
my $max_nb_attr = 0; |
105 |
my $max_nb_attr = 0; |
| 101 |
|
106 |
|
| 102 |
# Make sure there is only one of each patron id number |
107 |
# Make sure there is only one of each patron id number |
| 103 |
@patronidnumbers = uniq( @patronidnumbers ); |
108 |
@patronidnumbers = uniq(@patronidnumbers); |
| 104 |
|
109 |
|
| 105 |
for my $patronidnumber ( @patronidnumbers ) { |
110 |
for my $patronidnumber (@patronidnumbers) { |
| 106 |
my $patron; |
111 |
my $patron; |
| 107 |
if( $useborrowernumbers == 1 ){ |
112 |
if ( $useborrowernumbers == 1 ) { |
| 108 |
$patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } ); |
113 |
$patron = Koha::Patrons->find( { borrowernumber => $patronidnumber } ); |
| 109 |
} else { |
114 |
} else { |
| 110 |
$patron = Koha::Patrons->find( { cardnumber => $patronidnumber } ); |
115 |
$patron = Koha::Patrons->find( { cardnumber => $patronidnumber } ); |
| 111 |
} |
116 |
} |
| 112 |
if ( $patron ) { |
117 |
if ($patron) { |
| 113 |
if ( $logged_in_user->can_see_patron_infos( $patron ) ) { |
118 |
if ( $logged_in_user->can_see_patron_infos($patron) ) { |
| 114 |
my $borrower = $patron->unblessed; |
119 |
my $borrower = $patron->unblessed; |
| 115 |
my $attributes = $patron->extended_attributes; |
120 |
my $attributes = $patron->extended_attributes; |
| 116 |
my $patron_messages = Koha::Patron::Messages->search( |
121 |
my $patron_messages = Koha::Patron::Messages->search( |
| 117 |
{ |
122 |
{ |
| 118 |
'me.borrowernumber' => $patron->borrowernumber, |
123 |
'me.borrowernumber' => $patron->borrowernumber, |
| 119 |
} |
124 |
} |
| 120 |
); |
125 |
); |
| 121 |
$borrower->{patron_messages} = $patron_messages->as_list; |
126 |
$borrower->{patron_messages} = $patron_messages->as_list; |
| 122 |
$borrower->{patron_attributes} = $attributes->as_list; |
127 |
$borrower->{patron_attributes} = $attributes->as_list; |
| 123 |
$borrower->{patron_attributes_count} = $attributes->count; |
128 |
$borrower->{patron_attributes_count} = $attributes->count; |
| 124 |
$max_nb_attr = $borrower->{patron_attributes_count} if $borrower->{patron_attributes_count} > $max_nb_attr; |
129 |
$max_nb_attr = $borrower->{patron_attributes_count} |
|
|
130 |
if $borrower->{patron_attributes_count} > $max_nb_attr; |
| 125 |
push @borrowers, $borrower; |
131 |
push @borrowers, $borrower; |
| 126 |
} else { |
132 |
} else { |
| 127 |
push @notfoundcardnumbers, $patronidnumber; |
133 |
push @notfoundcardnumbers, $patronidnumber; |
|
Lines 132-157
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 132 |
} |
138 |
} |
| 133 |
|
139 |
|
| 134 |
# Just for a correct display |
140 |
# Just for a correct display |
| 135 |
for my $borrower ( @borrowers ) { |
141 |
for my $borrower (@borrowers) { |
| 136 |
my $length = $borrower->{patron_attributes_count}; |
142 |
my $length = $borrower->{patron_attributes_count}; |
| 137 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); |
143 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1 ); |
| 138 |
} |
144 |
} |
| 139 |
|
145 |
|
| 140 |
# Construct the patron attributes list |
146 |
# Construct the patron attributes list |
| 141 |
my @patron_attributes_values; |
147 |
my @patron_attributes_values; |
| 142 |
my @patron_attributes_codes; |
148 |
my @patron_attributes_codes; |
| 143 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
149 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
| 144 |
my $patron_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id); |
150 |
my $patron_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id ); |
| 145 |
my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']})->as_list; |
151 |
my @patron_categories = |
|
|
152 |
Koha::Patron::Categories->search_with_library_limits( {}, { order_by => ['description'] } )->as_list; |
| 146 |
while ( my $attr_type = $patron_attribute_types->next ) { |
153 |
while ( my $attr_type = $patron_attribute_types->next ) { |
| 147 |
next if $attr_type->unique_id; # Don't display patron attributes that must be unqiue |
154 |
next if $attr_type->unique_id; # Don't display patron attributes that must be unqiue |
| 148 |
my $options = $attr_type->authorised_value_category |
155 |
my $options = |
|
|
156 |
$attr_type->authorised_value_category |
| 149 |
? GetAuthorisedValues( $attr_type->authorised_value_category ) |
157 |
? GetAuthorisedValues( $attr_type->authorised_value_category ) |
| 150 |
: undef; |
158 |
: undef; |
| 151 |
push @patron_attributes_values, |
159 |
push @patron_attributes_values, |
| 152 |
{ |
160 |
{ |
| 153 |
attribute_code => $attr_type->code, |
161 |
attribute_code => $attr_type->code, |
| 154 |
options => $options, |
162 |
options => $options, |
| 155 |
}; |
163 |
}; |
| 156 |
|
164 |
|
| 157 |
my $category_code = $attr_type->category_code; |
165 |
my $category_code = $attr_type->category_code; |
|
Lines 160-177
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 160 |
@patron_categories; |
168 |
@patron_categories; |
| 161 |
push @patron_attributes_codes, |
169 |
push @patron_attributes_codes, |
| 162 |
{ |
170 |
{ |
| 163 |
attribute_code => $attr_type->code, |
171 |
attribute_code => $attr_type->code, |
| 164 |
attribute_lib => $attr_type->description, |
172 |
attribute_lib => $attr_type->description, |
| 165 |
category_lib => $category_lib, |
173 |
category_lib => $category_lib, |
| 166 |
type => $attr_type->authorised_value_category ? 'select' : 'text', |
174 |
type => $attr_type->authorised_value_category ? 'select' : 'text', |
| 167 |
}; |
175 |
}; |
| 168 |
} |
176 |
} |
| 169 |
|
177 |
|
| 170 |
my @attributes_header = (); |
178 |
my @attributes_header = (); |
| 171 |
for ( 1 .. scalar( $max_nb_attr ) ) { |
179 |
for ( 1 .. scalar($max_nb_attr) ) { |
| 172 |
push @attributes_header, { attribute => "Attributes $_" }; |
180 |
push @attributes_header, { attribute => "Attributes $_" }; |
| 173 |
} |
181 |
} |
| 174 |
$template->param( borrowers => \@borrowers ); |
182 |
$template->param( borrowers => \@borrowers ); |
| 175 |
$template->param( attributes_header => \@attributes_header ); |
183 |
$template->param( attributes_header => \@attributes_header ); |
| 176 |
@notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers; |
184 |
@notfoundcardnumbers = map { { cardnumber => $_ } } @notfoundcardnumbers; |
| 177 |
$template->param( notfoundcardnumbers => \@notfoundcardnumbers ) |
185 |
$template->param( notfoundcardnumbers => \@notfoundcardnumbers ) |
|
Lines 179-185
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 179 |
$template->param( useborrowernumbers => $useborrowernumbers ); |
187 |
$template->param( useborrowernumbers => $useborrowernumbers ); |
| 180 |
|
188 |
|
| 181 |
# Construct drop-down list values |
189 |
# Construct drop-down list values |
| 182 |
my $branches = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; |
190 |
my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed; |
| 183 |
my @branches_option; |
191 |
my @branches_option; |
| 184 |
push @branches_option, { value => $_->{branchcode}, lib => $_->{branchname} } for @$branches; |
192 |
push @branches_option, { value => $_->{branchcode}, lib => $_->{branchname} } for @$branches; |
| 185 |
unshift @branches_option, { value => "", lib => "" }; |
193 |
unshift @branches_option, { value => "", lib => "" }; |
|
Lines 201-358
if ( $op eq 'cud-show' || $op eq 'show' ) {
Link Here
|
| 201 |
|
209 |
|
| 202 |
my @fields = ( |
210 |
my @fields = ( |
| 203 |
{ |
211 |
{ |
| 204 |
name => "surname", |
212 |
name => "surname", |
| 205 |
type => "text", |
213 |
type => "text", |
| 206 |
mandatory => ( grep /surname/, @mandatoryFields ) ? 1 : 0 |
214 |
mandatory => ( grep /surname/, @mandatoryFields ) ? 1 : 0 |
| 207 |
} |
215 |
}, |
| 208 |
, |
|
|
| 209 |
{ |
216 |
{ |
| 210 |
name => "firstname", |
217 |
name => "firstname", |
| 211 |
type => "text", |
218 |
type => "text", |
| 212 |
mandatory => ( grep /firstname/, @mandatoryFields ) ? 1 : 0, |
219 |
mandatory => ( grep /firstname/, @mandatoryFields ) ? 1 : 0, |
| 213 |
} |
220 |
}, |
| 214 |
, |
|
|
| 215 |
{ |
221 |
{ |
| 216 |
name => "branchcode", |
222 |
name => "branchcode", |
| 217 |
type => "select", |
223 |
type => "select", |
| 218 |
option => \@branches_option, |
224 |
option => \@branches_option, |
| 219 |
mandatory => ( grep /branchcode/, @mandatoryFields ) ? 1 : 0, |
225 |
mandatory => ( grep /branchcode/, @mandatoryFields ) ? 1 : 0, |
| 220 |
} |
226 |
}, |
| 221 |
, |
|
|
| 222 |
{ |
227 |
{ |
| 223 |
name => "categorycode", |
228 |
name => "categorycode", |
| 224 |
type => "select", |
229 |
type => "select", |
| 225 |
option => \@categories_option, |
230 |
option => \@categories_option, |
| 226 |
mandatory => ( grep /categorycode/, @mandatoryFields ) ? 1 : 0, |
231 |
mandatory => ( grep /categorycode/, @mandatoryFields ) ? 1 : 0, |
| 227 |
} |
232 |
}, |
| 228 |
, |
|
|
| 229 |
{ |
233 |
{ |
| 230 |
name => "streetnumber", |
234 |
name => "streetnumber", |
| 231 |
type => "text", |
235 |
type => "text", |
| 232 |
mandatory => ( grep /streetnumber/, @mandatoryFields ) ? 1 : 0, |
236 |
mandatory => ( grep /streetnumber/, @mandatoryFields ) ? 1 : 0, |
| 233 |
} |
237 |
}, |
| 234 |
, |
|
|
| 235 |
{ |
238 |
{ |
| 236 |
name => "address", |
239 |
name => "address", |
| 237 |
type => "text", |
240 |
type => "text", |
| 238 |
mandatory => ( grep /address/, @mandatoryFields ) ? 1 : 0, |
241 |
mandatory => ( grep /address/, @mandatoryFields ) ? 1 : 0, |
| 239 |
} |
242 |
}, |
| 240 |
, |
|
|
| 241 |
{ |
243 |
{ |
| 242 |
name => "address2", |
244 |
name => "address2", |
| 243 |
type => "text", |
245 |
type => "text", |
| 244 |
mandatory => ( grep /address2/, @mandatoryFields ) ? 1 : 0, |
246 |
mandatory => ( grep /address2/, @mandatoryFields ) ? 1 : 0, |
| 245 |
} |
247 |
}, |
| 246 |
, |
|
|
| 247 |
{ |
248 |
{ |
| 248 |
name => "city", |
249 |
name => "city", |
| 249 |
type => "text", |
250 |
type => "text", |
| 250 |
mandatory => ( grep /city/, @mandatoryFields ) ? 1 : 0, |
251 |
mandatory => ( grep /city/, @mandatoryFields ) ? 1 : 0, |
| 251 |
} |
252 |
}, |
| 252 |
, |
|
|
| 253 |
{ |
253 |
{ |
| 254 |
name => "state", |
254 |
name => "state", |
| 255 |
type => "text", |
255 |
type => "text", |
| 256 |
mandatory => ( grep /state/, @mandatoryFields ) ? 1 : 0, |
256 |
mandatory => ( grep /state/, @mandatoryFields ) ? 1 : 0, |
| 257 |
} |
257 |
}, |
| 258 |
, |
|
|
| 259 |
{ |
258 |
{ |
| 260 |
name => "zipcode", |
259 |
name => "zipcode", |
| 261 |
type => "text", |
260 |
type => "text", |
| 262 |
mandatory => ( grep /zipcode/, @mandatoryFields ) ? 1 : 0, |
261 |
mandatory => ( grep /zipcode/, @mandatoryFields ) ? 1 : 0, |
| 263 |
} |
262 |
}, |
| 264 |
, |
|
|
| 265 |
{ |
263 |
{ |
| 266 |
name => "country", |
264 |
name => "country", |
| 267 |
type => "text", |
265 |
type => "text", |
| 268 |
mandatory => ( grep /country/, @mandatoryFields ) ? 1 : 0, |
266 |
mandatory => ( grep /country/, @mandatoryFields ) ? 1 : 0, |
| 269 |
} |
267 |
}, |
| 270 |
, |
|
|
| 271 |
{ |
268 |
{ |
| 272 |
name => "email", |
269 |
name => "email", |
| 273 |
type => "text", |
270 |
type => "text", |
| 274 |
mandatory => ( grep /email/, @mandatoryFields ) ? 1 : 0, |
271 |
mandatory => ( grep /email/, @mandatoryFields ) ? 1 : 0, |
| 275 |
} |
272 |
}, |
| 276 |
, |
|
|
| 277 |
{ |
273 |
{ |
| 278 |
name => "phone", |
274 |
name => "phone", |
| 279 |
type => "text", |
275 |
type => "text", |
| 280 |
mandatory => ( grep /phone/, @mandatoryFields ) ? 1 : 0, |
276 |
mandatory => ( grep /phone/, @mandatoryFields ) ? 1 : 0, |
| 281 |
} |
277 |
}, |
| 282 |
, |
|
|
| 283 |
{ |
278 |
{ |
| 284 |
name => "mobile", |
279 |
name => "mobile", |
| 285 |
type => "text", |
280 |
type => "text", |
| 286 |
mandatory => ( grep /mobile/, @mandatoryFields ) ? 1 : 0, |
281 |
mandatory => ( grep /mobile/, @mandatoryFields ) ? 1 : 0, |
| 287 |
} |
282 |
}, |
| 288 |
, |
|
|
| 289 |
{ |
283 |
{ |
| 290 |
name => "fax", |
284 |
name => "fax", |
| 291 |
type => "text", |
285 |
type => "text", |
| 292 |
mandatory => ( grep /fax/, @mandatoryFields ) ? 1 : 0, |
286 |
mandatory => ( grep /fax/, @mandatoryFields ) ? 1 : 0, |
| 293 |
} |
287 |
}, |
| 294 |
, |
|
|
| 295 |
{ |
288 |
{ |
| 296 |
name => "sort1", |
289 |
name => "sort1", |
| 297 |
type => @sort1_option ? "select" : "text", |
290 |
type => @sort1_option ? "select" : "text", |
| 298 |
option => \@sort1_option, |
291 |
option => \@sort1_option, |
| 299 |
mandatory => ( grep /sort1/, @mandatoryFields ) ? 1 : 0, |
292 |
mandatory => ( grep /sort1/, @mandatoryFields ) ? 1 : 0, |
| 300 |
} |
293 |
}, |
| 301 |
, |
|
|
| 302 |
{ |
294 |
{ |
| 303 |
name => "sort2", |
295 |
name => "sort2", |
| 304 |
type => @sort2_option ? "select" : "text", |
296 |
type => @sort2_option ? "select" : "text", |
| 305 |
option => \@sort2_option, |
297 |
option => \@sort2_option, |
| 306 |
mandatory => ( grep /sort2/, @mandatoryFields ) ? 1 : 0, |
298 |
mandatory => ( grep /sort2/, @mandatoryFields ) ? 1 : 0, |
| 307 |
} |
299 |
}, |
| 308 |
, |
|
|
| 309 |
{ |
300 |
{ |
| 310 |
name => "dateenrolled", |
301 |
name => "dateenrolled", |
| 311 |
type => "date", |
302 |
type => "date", |
| 312 |
mandatory => ( grep /dateenrolled/, @mandatoryFields ) ? 1 : 0, |
303 |
mandatory => ( grep /dateenrolled/, @mandatoryFields ) ? 1 : 0, |
| 313 |
} |
304 |
}, |
| 314 |
, |
|
|
| 315 |
{ |
305 |
{ |
| 316 |
name => "dateexpiry", |
306 |
name => "dateexpiry", |
| 317 |
type => "date", |
307 |
type => "date", |
| 318 |
mandatory => ( grep /dateexpiry/, @mandatoryFields ) ? 1 : 0, |
308 |
mandatory => ( grep /dateexpiry/, @mandatoryFields ) ? 1 : 0, |
| 319 |
} |
309 |
}, |
| 320 |
, |
|
|
| 321 |
{ |
310 |
{ |
| 322 |
name => "borrowernotes", |
311 |
name => "borrowernotes", |
| 323 |
type => "text", |
312 |
type => "text", |
| 324 |
mandatory => ( grep /borrowernotes/, @mandatoryFields ) ? 1 : 0, |
313 |
mandatory => ( grep /borrowernotes/, @mandatoryFields ) ? 1 : 0, |
| 325 |
} |
314 |
}, |
| 326 |
, |
|
|
| 327 |
{ |
315 |
{ |
| 328 |
name => "opacnote", |
316 |
name => "opacnote", |
| 329 |
type => "text", |
317 |
type => "text", |
| 330 |
mandatory => ( grep /opacnote/, @mandatoryFields ) ? 1 : 0, |
318 |
mandatory => ( grep /opacnote/, @mandatoryFields ) ? 1 : 0, |
| 331 |
} |
319 |
}, |
| 332 |
, |
|
|
| 333 |
{ |
320 |
{ |
| 334 |
name => "message", |
321 |
name => "message", |
| 335 |
type => "message_type", |
322 |
type => "message_type", |
| 336 |
mandatory => ( grep /message/, @mandatoryFields ) ? 1 : 0, |
323 |
mandatory => ( grep /message/, @mandatoryFields ) ? 1 : 0, |
| 337 |
} |
324 |
}, |
| 338 |
, |
|
|
| 339 |
{ |
325 |
{ |
| 340 |
name => "debarred", |
326 |
name => "debarred", |
| 341 |
type => "date", |
327 |
type => "date", |
| 342 |
mandatory => ( grep /debarred/, @mandatoryFields ) ? 1 : 0, |
328 |
mandatory => ( grep /debarred/, @mandatoryFields ) ? 1 : 0, |
| 343 |
} |
329 |
}, |
| 344 |
, |
|
|
| 345 |
{ |
330 |
{ |
| 346 |
name => "debarredcomment", |
331 |
name => "debarredcomment", |
| 347 |
type => "text", |
332 |
type => "text", |
| 348 |
mandatory => ( grep /debarredcomment/, @mandatoryFields ) ? 1 : 0, |
333 |
mandatory => ( grep /debarredcomment/, @mandatoryFields ) ? 1 : 0, |
| 349 |
}, |
334 |
}, |
| 350 |
); |
335 |
); |
| 351 |
|
336 |
|
| 352 |
push @fields, { name => "password_expiration_date", type => "date" } if $logged_in_user->is_superlibrarian; |
337 |
push @fields, { name => "password_expiration_date", type => "date" } if $logged_in_user->is_superlibrarian; |
| 353 |
|
338 |
|
| 354 |
$template->param('patron_attributes_codes', \@patron_attributes_codes); |
339 |
$template->param( 'patron_attributes_codes', \@patron_attributes_codes ); |
| 355 |
$template->param('patron_attributes_values', \@patron_attributes_values); |
340 |
$template->param( 'patron_attributes_values', \@patron_attributes_values ); |
| 356 |
|
341 |
|
| 357 |
$template->param( fields => \@fields ); |
342 |
$template->param( fields => \@fields ); |
| 358 |
$op = 'show'; |
343 |
$op = 'show'; |
|
Lines 372-390
if ( $op eq 'cud-do' ) {
Link Here
|
| 372 |
$infos->{$field} = "" if grep { $_ eq $field } @disabled; |
357 |
$infos->{$field} = "" if grep { $_ eq $field } @disabled; |
| 373 |
} |
358 |
} |
| 374 |
|
359 |
|
| 375 |
for my $field ( qw( dateenrolled dateexpiry debarred password_expiration_date ) ) { |
360 |
for my $field (qw( dateenrolled dateexpiry debarred password_expiration_date )) { |
| 376 |
$infos->{$field} = dt_from_string($infos->{$field}) if $infos->{$field}; |
361 |
$infos->{$field} = dt_from_string( $infos->{$field} ) if $infos->{$field}; |
| 377 |
} |
362 |
} |
| 378 |
|
363 |
|
| 379 |
delete $infos->{password_expiration_date} unless $logged_in_user->is_superlibrarian; |
364 |
delete $infos->{password_expiration_date} unless $logged_in_user->is_superlibrarian; |
| 380 |
|
365 |
|
| 381 |
my @errors; |
366 |
my @errors; |
| 382 |
my @borrowernumbers = $input->multi_param('borrowernumber'); |
367 |
my @borrowernumbers = $input->multi_param('borrowernumber'); |
|
|
368 |
|
| 383 |
# For each borrower selected |
369 |
# For each borrower selected |
| 384 |
for my $borrowernumber ( @borrowernumbers ) { |
370 |
for my $borrowernumber (@borrowernumbers) { |
| 385 |
|
371 |
|
| 386 |
# If at least one field are filled, we want to modify the borrower |
372 |
# If at least one field are filled, we want to modify the borrower |
| 387 |
if ( defined $infos ) { |
373 |
if ( defined $infos ) { |
|
|
374 |
|
| 388 |
# If a debarred date or debarred comment has been submitted make a new debarment |
375 |
# If a debarred date or debarred comment has been submitted make a new debarment |
| 389 |
if ( $infos->{debarred} || $infos->{debarredcomment} ) { |
376 |
if ( $infos->{debarred} || $infos->{debarredcomment} ) { |
| 390 |
AddDebarment( |
377 |
AddDebarment( |
|
Lines 393-432
if ( $op eq 'cud-do' ) {
Link Here
|
| 393 |
type => 'MANUAL', |
380 |
type => 'MANUAL', |
| 394 |
comment => $infos->{debarredcomment}, |
381 |
comment => $infos->{debarredcomment}, |
| 395 |
expiration => $infos->{debarred}, |
382 |
expiration => $infos->{debarred}, |
| 396 |
}); |
383 |
} |
|
|
384 |
); |
| 397 |
} |
385 |
} |
| 398 |
|
386 |
|
| 399 |
# If debarment date or debarment comment are disabled then remove all debarrments |
387 |
# If debarment date or debarment comment are disabled then remove all debarrments |
| 400 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
388 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 401 |
if ( grep { /debarred/ } @disabled ) { |
389 |
if ( grep { /debarred/ } @disabled ) { |
| 402 |
eval { |
390 |
eval { |
| 403 |
my $debarrments = $patron->restrictions; |
391 |
my $debarrments = $patron->restrictions; |
| 404 |
while( my $debarment = $debarrments->next ) { |
392 |
while ( my $debarment = $debarrments->next ) { |
| 405 |
DelDebarment( $debarment->borrower_debarment_id ); |
393 |
DelDebarment( $debarment->borrower_debarment_id ); |
| 406 |
} |
394 |
} |
| 407 |
}; |
395 |
}; |
| 408 |
} |
396 |
} |
|
|
397 |
|
| 409 |
# If 'message' or 'add_message_type' is defined then delete both at the same time |
398 |
# If 'message' or 'add_message_type' is defined then delete both at the same time |
| 410 |
if ( grep { $_ eq 'message' } @disabled) { |
399 |
if ( grep { $_ eq 'message' } @disabled ) { |
| 411 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
400 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 412 |
$patron->messages()->delete(); |
401 |
$patron->messages()->delete(); |
| 413 |
} |
402 |
} |
| 414 |
$infos->{borrowernumber} = $borrowernumber; |
403 |
$infos->{borrowernumber} = $borrowernumber; |
| 415 |
eval { $patron->set($infos)->store; }; |
404 |
eval { $patron->set($infos)->store; }; |
| 416 |
if ( $@ ) { # FIXME We could provide better error handling here |
405 |
if ($@) { # FIXME We could provide better error handling here |
| 417 |
$infos->{cardnumber} = $patron ? $patron->cardnumber || '' : ''; |
406 |
$infos->{cardnumber} = $patron ? $patron->cardnumber || '' : ''; |
| 418 |
push @errors, { error => "can_not_update", borrowernumber => $infos->{borrowernumber}, cardnumber => $infos->{cardnumber} }; |
407 |
push @errors, |
|
|
408 |
{ |
| 409 |
error => "can_not_update", borrowernumber => $infos->{borrowernumber}, |
| 410 |
cardnumber => $infos->{cardnumber} |
| 411 |
}; |
| 419 |
} |
412 |
} |
| 420 |
} |
413 |
} |
| 421 |
|
414 |
|
| 422 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
415 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 423 |
my @attributes = $input->multi_param('patron_attributes'); |
416 |
my @attributes = $input->multi_param('patron_attributes'); |
| 424 |
my @attr_values = $input->multi_param('patron_attributes_value'); |
417 |
my @attr_values = $input->multi_param('patron_attributes_value'); |
| 425 |
my $attributes; |
418 |
my $attributes; |
| 426 |
my $i = 0; |
419 |
my $i = 0; |
| 427 |
for my $code ( @attributes ) { |
420 |
for my $code (@attributes) { |
| 428 |
push @{ $attributes->{$code}->{values} }, shift @attr_values; # Handling repeatables |
421 |
push @{ $attributes->{$code}->{values} }, shift @attr_values; # Handling repeatables |
| 429 |
$attributes->{$code}->{disabled} = grep { $_ eq sprintf("attr%s_value", ++$i) } @disabled; |
422 |
$attributes->{$code}->{disabled} = grep { $_ eq sprintf( "attr%s_value", ++$i ) } @disabled; |
| 430 |
} |
423 |
} |
| 431 |
|
424 |
|
| 432 |
for my $code ( keys %$attributes ) { |
425 |
for my $code ( keys %$attributes ) { |
|
Lines 438-461
if ( $op eq 'cud-do' ) {
Link Here
|
| 438 |
next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; |
431 |
next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode; |
| 439 |
|
432 |
|
| 440 |
if ( $attributes->{$code}->{disabled} ) { |
433 |
if ( $attributes->{$code}->{disabled} ) { |
|
|
434 |
|
| 441 |
# The attribute is disabled, we remove it for this borrower ! |
435 |
# The attribute is disabled, we remove it for this borrower ! |
| 442 |
eval { |
436 |
eval { |
| 443 |
$patron->extended_attributes->search({'me.code' => $code})->filter_by_branch_limitations->delete; |
437 |
$patron->extended_attributes->search( { 'me.code' => $code } ) |
|
|
438 |
->filter_by_branch_limitations->delete; |
| 444 |
}; |
439 |
}; |
| 445 |
push @errors, { error => $@ } if $@; |
440 |
push @errors, { error => $@ } if $@; |
| 446 |
} else { |
441 |
} else { |
| 447 |
eval { |
442 |
eval { |
| 448 |
$patron->extended_attributes->search({'me.code' => $code})->filter_by_branch_limitations->delete; |
443 |
$patron->extended_attributes->search( { 'me.code' => $code } ) |
| 449 |
$patron->add_extended_attribute({ code => $code, attribute => $_ }) for @{$attributes->{$code}->{values}}; |
444 |
->filter_by_branch_limitations->delete; |
|
|
445 |
$patron->add_extended_attribute( { code => $code, attribute => $_ } ) |
| 446 |
for @{ $attributes->{$code}->{values} }; |
| 450 |
}; |
447 |
}; |
| 451 |
push @errors, { error => $@ } if $@; |
448 |
push @errors, { error => $@ } if $@; |
| 452 |
} |
449 |
} |
| 453 |
} |
450 |
} |
| 454 |
|
451 |
|
| 455 |
# Handle patron messages |
452 |
# Handle patron messages |
| 456 |
my $message = $input->param('message'); |
453 |
my $message = $input->param('message'); |
| 457 |
my $branchcode = C4::Context::mybranch; |
454 |
my $branchcode = C4::Context::mybranch; |
| 458 |
my $message_type = $input->param('add_message_type'); |
455 |
my $message_type = $input->param('add_message_type'); |
| 459 |
|
456 |
|
| 460 |
Koha::Patron::Message->new( |
457 |
Koha::Patron::Message->new( |
| 461 |
{ |
458 |
{ |
|
Lines 467-488
if ( $op eq 'cud-do' ) {
Link Here
|
| 467 |
)->store; |
464 |
)->store; |
| 468 |
} |
465 |
} |
| 469 |
|
466 |
|
| 470 |
$op = "show_results"; # We have process modifications, the user want to view its |
467 |
$op = "show_results"; # We have process modifications, the user want to view its |
| 471 |
|
468 |
|
| 472 |
# Construct the results list |
469 |
# Construct the results list |
| 473 |
my @borrowers; |
470 |
my @borrowers; |
| 474 |
my $max_nb_attr = 0; |
471 |
my $max_nb_attr = 0; |
| 475 |
for my $borrowernumber ( @borrowernumbers ) { |
472 |
for my $borrowernumber (@borrowernumbers) { |
| 476 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
473 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 477 |
if ( $patron ) { |
474 |
if ($patron) { |
| 478 |
my $category_description = $patron->category->description; |
475 |
my $category_description = $patron->category->description; |
| 479 |
my $borrower = $patron->unblessed; |
476 |
my $borrower = $patron->unblessed; |
| 480 |
my $patron_messages = Koha::Patron::Messages->search( |
477 |
my $patron_messages = Koha::Patron::Messages->search( |
| 481 |
{ |
478 |
{ |
| 482 |
'me.borrowernumber' => $patron->borrowernumber, |
479 |
'me.borrowernumber' => $patron->borrowernumber, |
| 483 |
} |
480 |
} |
| 484 |
); |
481 |
); |
| 485 |
$borrower->{patron_messages} = $patron_messages->as_list; |
482 |
$borrower->{patron_messages} = $patron_messages->as_list; |
| 486 |
$borrower->{category_description} = $category_description; |
483 |
$borrower->{category_description} = $category_description; |
| 487 |
my $attributes = $patron->extended_attributes; |
484 |
my $attributes = $patron->extended_attributes; |
| 488 |
$borrower->{patron_attributes} = $attributes->as_list; |
485 |
$borrower->{patron_attributes} = $attributes->as_list; |
|
Lines 491-508
if ( $op eq 'cud-do' ) {
Link Here
|
| 491 |
} |
488 |
} |
| 492 |
} |
489 |
} |
| 493 |
my @patron_attributes_option; |
490 |
my @patron_attributes_option; |
| 494 |
for my $borrower ( @borrowers ) { |
491 |
for my $borrower (@borrowers) { |
| 495 |
push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } for @{ $borrower->{patron_attributes} }; |
492 |
push @patron_attributes_option, { value => "$_->{code}", lib => $_->{code} } |
|
|
493 |
for @{ $borrower->{patron_attributes} }; |
| 496 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
494 |
my $length = scalar( @{ $borrower->{patron_attributes} } ); |
| 497 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1); |
495 |
push @{ $borrower->{patron_attributes} }, {} for ( $length .. $max_nb_attr - 1 ); |
| 498 |
} |
496 |
} |
| 499 |
|
497 |
|
| 500 |
my @attributes_header = (); |
498 |
my @attributes_header = (); |
| 501 |
for ( 1 .. scalar( $max_nb_attr ) ) { |
499 |
for ( 1 .. scalar($max_nb_attr) ) { |
| 502 |
push @attributes_header, { attribute => "Attributes $_" }; |
500 |
push @attributes_header, { attribute => "Attributes $_" }; |
| 503 |
} |
501 |
} |
| 504 |
|
502 |
|
| 505 |
$template->param( borrowers => \@borrowers ); |
503 |
$template->param( borrowers => \@borrowers ); |
| 506 |
$template->param( attributes_header => \@attributes_header ); |
504 |
$template->param( attributes_header => \@attributes_header ); |
| 507 |
|
505 |
|
| 508 |
$template->param( errors => \@errors ); |
506 |
$template->param( errors => \@errors ); |
| 509 |
- |
|
|