X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=members%2Fhousebound.pl;h=0584685f397f9a28568374781c0a0d1e6d1a8d09;hb=7d8b96803f664d86762a6afb966051f7d565c40e;hp=0b571e6cf9814462dbde75dcec4a19923fe4751f;hpb=b81a18ea39e1f360dc0dc4b7a874b614dc67d725;p=srvgit diff --git a/members/housebound.pl b/members/housebound.pl index 0b571e6cf9..0584685f39 100755 --- a/members/housebound.pl +++ b/members/housebound.pl @@ -4,18 +4,18 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . =head1 housebound.pl @@ -28,7 +28,6 @@ use Modern::Perl; use CGI; use C4::Auth; use C4::Context; -use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Output; use DateTime; use Koha::DateUtils; @@ -47,7 +46,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( query => $input, type => 'intranet', authnotrequired => 0, - flagsrequired => { borrowers => 1 }, + flagsrequired => { borrowers => 'edit_borrowers' }, } ); @@ -56,19 +55,14 @@ my $method = $input->param('method') // q{}; my $visit_id = $input->param('visit_id') // q{}; # Get patron -my $patron = eval { - my $borrowernumber = $input->param('borrowernumber') // q{}; - return Koha::Patrons->find($borrowernumber); -}; -push @messages, { type => 'error', code => 'error_on_patron_load' } - if ( $@ or !$patron ); +my $borrowernumber = $input->param('borrowernumber'); +my $logged_in_user = Koha::Patrons->find( $loggedinuser ); +my $patron = Koha::Patrons->find($borrowernumber); +output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); # Get supporting cast -my ( $branch, $category, $houseboundprofile, $visit, $patron_image ); -if ( $patron ) { - $patron_image = Koha::Patron::Images->find($patron->borrowernumber); - $branch = Koha::Libraries->new->find($patron->branchcode); - $category = Koha::Patron::Categories->new->find($patron->categorycode); +my ( $houseboundprofile, $visit ); +if ( $patron ) { # FIXME This test is not needed - output_and_exit_if_error handles it $houseboundprofile = $patron->housebound_profile; } if ( $visit_id ) { @@ -86,13 +80,13 @@ if ( $method eq 'updateconfirm' and $houseboundprofile ) { # We have received the input from the profile edit form. We must save the # changes, and return to simple display. $houseboundprofile->set({ - day => $input->param('day') // q{}, - frequency => $input->param('frequency') // q{}, - fav_itemtypes => $input->param('fav_itemtypes') // q{}, - fav_subjects => $input->param('fav_subjects') // q{}, - fav_authors => $input->param('fav_authors') // q{}, - referral => $input->param('referral') // q{}, - notes => $input->param('notes') // q{}, + day => scalar $input->param('day') // q{}, + frequency => scalar $input->param('frequency') // q{}, + fav_itemtypes => scalar $input->param('fav_itemtypes') // q{}, + fav_subjects => scalar $input->param('fav_subjects') // q{}, + fav_authors => scalar $input->param('fav_authors') // q{}, + referral => scalar $input->param('referral') // q{}, + notes => scalar $input->param('notes') // q{}, }); my $success = eval { return $houseboundprofile->store }; push @messages, { type => 'error', code => 'error_on_profile_store' } @@ -103,13 +97,13 @@ if ( $method eq 'updateconfirm' and $houseboundprofile ) { # save it, and return to simple display. $houseboundprofile = Koha::Patron::HouseboundProfile->new({ borrowernumber => $patron->borrowernumber, - day => $input->param('day') // q{}, - frequency => $input->param('frequency') // q{}, - fav_itemtypes => $input->param('fav_itemtypes') // q{}, - fav_subjects => $input->param('fav_subjects') // q{}, - fav_authors => $input->param('fav_authors') // q{}, - referral => $input->param('referral') // q{}, - notes => $input->param('notes') // q{}, + day => scalar $input->param('day') // q{}, + frequency => scalar $input->param('frequency') // q{}, + fav_itemtypes => scalar $input->param('fav_itemtypes') // q{}, + fav_subjects => scalar $input->param('fav_subjects') // q{}, + fav_authors => scalar $input->param('fav_authors') // q{}, + referral => scalar $input->param('referral') // q{}, + notes => scalar $input->param('notes') // q{}, }); my $success = eval { return $houseboundprofile->store }; push @messages, { type => 'error', code => 'error_on_profile_create' } @@ -130,11 +124,11 @@ if ( $method eq 'updateconfirm' and $houseboundprofile ) { # We have received input for editing a visit. We must store and return to # simple display. $visit->set({ - borrowernumber => $input->param('borrowernumber') // q{}, + borrowernumber => scalar $input->param('borrowernumber') // q{}, appointment_date => dt_from_string($input->param('date') // q{}), - day_segment => $input->param('segment') // q{}, - chooser_brwnumber => $input->param('chooser') // q{}, - deliverer_brwnumber => $input->param('deliverer') // q{}, + day_segment => scalar $input->param('segment') // q{}, + chooser_brwnumber => scalar $input->param('chooser') // q{}, + deliverer_brwnumber => scalar $input->param('deliverer') // q{}, }); my $success = eval { return $visit->store }; push @messages, { type => 'error', code => 'error_on_visit_store' } @@ -144,11 +138,11 @@ if ( $method eq 'updateconfirm' and $houseboundprofile ) { # We have received input for creating a visit. We must store and return # to simple display. my $visit = Koha::Patron::HouseboundVisit->new({ - borrowernumber => $input->param('borrowernumber') // q{}, + borrowernumber => scalar $input->param('borrowernumber') // q{}, appointment_date => dt_from_string($input->param('date') // q{}), - day_segment => $input->param('segment') // q{}, - chooser_brwnumber => $input->param('chooser') // q{}, - deliverer_brwnumber => $input->param('deliverer') // q{}, + day_segment => scalar $input->param('segment') // q{}, + chooser_brwnumber => scalar $input->param('chooser') // q{}, + deliverer_brwnumber => scalar $input->param('deliverer') // q{}, }); my $success = eval { return $visit->store }; push @messages, { type => 'error', code => 'error_on_visit_create' } @@ -160,24 +154,11 @@ if ( $method eq 'updateconfirm' and $houseboundprofile ) { $method = 'update_or_create' if ( !$houseboundprofile ); # Ensure template has all patron details. -$template->param(%{$patron->unblessed}) if ( $patron ); - -# Load extended patron attributes if necessary (taken from members/files.pl). -if ( C4::Context->preference('ExtendedPatronAttributes') and $patron ) { - my $attributes = GetBorrowerAttributes($patron->borrowernumber); - $template->param( - ExtendedPatronAttributes => 1, - extendedattributes => $attributes - ); -} +$template->param( patron => $patron ); -$template->param( adultborrower => 1 ) if ( $category->category_type eq 'A' ); $template->param( - picture => $patron_image, housebound_profile => $houseboundprofile, visit => $houseboundvisit, - branch => $branch, - category => $category, messages => \@messages, method => $method, choosers => $choosers,