3 # Copyright 2016 PTFS-Europe Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 Script to handle housebound management for patrons. This single script
23 handles display, creation, deletion and management of profiles and visits.
31 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
37 use Koha
::Patron
::Categories
;
38 use Koha
::Patron
::HouseboundProfile
;
39 use Koha
::Patron
::HouseboundVisit
;
40 use Koha
::Patron
::HouseboundVisits
;
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
46 template_name
=> 'members/housebound.tt',
50 flagsrequired
=> { borrowers
=> 1 },
54 my @messages; # For error messages.
55 my $method = $input->param('method') // q{};
56 my $visit_id = $input->param('visit_id') // q{};
60 my $borrowernumber = $input->param('borrowernumber') // q{};
61 return Koha
::Patrons
->find($borrowernumber);
63 push @messages, { type
=> 'error', code
=> 'error_on_patron_load' }
64 if ( $@
or !$patron );
67 my ( $branch, $category, $houseboundprofile, $visit, $patron_image );
69 $patron_image = Koha
::Patron
::Images
->find($patron->borrowernumber);
70 $branch = Koha
::Libraries
->new->find($patron->branchcode);
71 $category = Koha
::Patron
::Categories
->new->find($patron->categorycode);
72 $houseboundprofile = $patron->housebound_profile;
76 return Koha
::Patron
::HouseboundVisits
->find($visit_id);
78 push @messages, { type
=> 'error', code
=> 'error_on_visit_load' }
83 my ( $deliverers, $choosers, $houseboundvisit );
85 if ( $method eq 'updateconfirm' and $houseboundprofile ) {
86 # We have received the input from the profile edit form. We must save the
87 # changes, and return to simple display.
88 $houseboundprofile->set({
89 day
=> $input->param('day') // q{},
90 frequency
=> $input->param('frequency') // q{},
91 fav_itemtypes
=> $input->param('fav_itemtypes') // q{},
92 fav_subjects
=> $input->param('fav_subjects') // q{},
93 fav_authors
=> $input->param('fav_authors') // q{},
94 referral
=> $input->param('referral') // q{},
95 notes
=> $input->param('notes') // q{},
97 my $success = eval { return $houseboundprofile->store };
98 push @messages, { type
=> 'error', code
=> 'error_on_profile_store' }
99 if ( $@
or !$success );
101 } elsif ( $method eq 'createconfirm' ) {
102 # We have received the input necessary to create a new profile. We must
103 # save it, and return to simple display.
104 $houseboundprofile = Koha
::Patron
::HouseboundProfile
->new({
105 borrowernumber
=> $patron->borrowernumber,
106 day
=> $input->param('day') // q{},
107 frequency
=> $input->param('frequency') // q{},
108 fav_itemtypes
=> $input->param('fav_itemtypes') // q{},
109 fav_subjects
=> $input->param('fav_subjects') // q{},
110 fav_authors
=> $input->param('fav_authors') // q{},
111 referral
=> $input->param('referral') // q{},
112 notes
=> $input->param('notes') // q{},
114 my $success = eval { return $houseboundprofile->store };
115 push @messages, { type
=> 'error', code
=> 'error_on_profile_create' }
116 if ( $@
or !$success );
118 } elsif ( $method eq 'visit_update_or_create' ) {
119 # We want to edit, edit a visit, so we must pass its details.
120 $deliverers = Koha
::Patrons
->search_housebound_deliverers;
121 $choosers = Koha
::Patrons
->search_housebound_choosers;
122 $houseboundvisit = $visit;
123 } elsif ( $method eq 'visit_delete' and $visit ) {
124 # We want ot delete a specific visit.
125 my $success = eval { return $visit->delete };
126 push @messages, { type
=> 'error', code
=> 'error_on_visit_delete' }
127 if ( $@
or !$success );
129 } elsif ( $method eq 'editvisitconfirm' and $visit ) {
130 # We have received input for editing a visit. We must store and return to
133 borrowernumber
=> $input->param('borrowernumber') // q{},
134 appointment_date
=> dt_from_string
($input->param('date') // q{}),
135 day_segment
=> $input->param('segment') // q{},
136 chooser_brwnumber
=> $input->param('chooser') // q{},
137 deliverer_brwnumber
=> $input->param('deliverer') // q{},
139 my $success = eval { return $visit->store };
140 push @messages, { type
=> 'error', code
=> 'error_on_visit_store' }
141 if ( $@
or !$success );
143 } elsif ( $method eq 'addvisitconfirm' and !$visit ) {
144 # We have received input for creating a visit. We must store and return
146 my $visit = Koha
::Patron
::HouseboundVisit
->new({
147 borrowernumber
=> $input->param('borrowernumber') // q{},
148 appointment_date
=> dt_from_string
($input->param('date') // q{}),
149 day_segment
=> $input->param('segment') // q{},
150 chooser_brwnumber
=> $input->param('chooser') // q{},
151 deliverer_brwnumber
=> $input->param('deliverer') // q{},
153 my $success = eval { return $visit->store };
154 push @messages, { type
=> 'error', code
=> 'error_on_visit_create' }
155 if ( $@
or !$success );
159 # We don't have any profile information, so we must display a creation form.
160 $method = 'update_or_create' if ( !$houseboundprofile );
162 # Ensure template has all patron details.
163 $template->param(%{$patron->unblessed}) if ( $patron );
165 # Load extended patron attributes if necessary (taken from members/files.pl).
166 if ( C4
::Context
->preference('ExtendedPatronAttributes') and $patron ) {
167 my $attributes = GetBorrowerAttributes
($patron->borrowernumber);
169 ExtendedPatronAttributes
=> 1,
170 extendedattributes
=> $attributes
174 $template->param( adultborrower
=> 1 ) if ( $category->category_type eq 'A' || $category->category_type eq 'I' );
176 picture
=> $patron_image,
177 housebound_profile
=> $houseboundprofile,
178 visit
=> $houseboundvisit,
180 category
=> $category,
181 messages
=> \
@messages,
183 choosers
=> $choosers,
184 deliverers
=> $deliverers,
185 houseboundview
=> 'on',
188 output_html_with_http_headers
$input, $cookie, $template->output;
192 Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>