From 4fd1bc729f84a43227eb15d4e5e59158c9519ba0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 30 Jan 2024 11:55:16 -0300 Subject: [PATCH] Bug 34478: Manual fix - Course reserves Signed-off-by: Jonathan Druart --- course_reserves/course-details.pl | 27 ++++++------ course_reserves/mod_course.pl | 15 ++++--- .../modules/course_reserves/course-details.tt | 43 ++++++++++++++++--- .../prog/en/modules/course_reserves/course.tt | 7 ++- 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/course_reserves/course-details.pl b/course_reserves/course-details.pl index c5d74f950e..b2ca9e8c87 100755 --- a/course_reserves/course-details.pl +++ b/course_reserves/course-details.pl @@ -22,36 +22,36 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Auth qw( get_template_and_user ); +use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::CourseReserves qw( DelCourse DelCourseReserve GetCourse GetCourseReserve GetCourseReserves ); my $cgi = CGI->new; -my $action = $cgi->param('action') || ''; +my $op = $cgi->param('op') || ''; my $course_id = $cgi->param('course_id'); my $flagsrequired; -$flagsrequired->{coursereserves} = 'delete_reserves' if ( $action eq 'del_reserve' or $action eq 'rm_all' ); +$flagsrequired->{coursereserves} = 'delete_reserves' if ( $op eq 'cud-del_reserve' or $op eq 'cud-rm_all' ); my $tmpl = ($course_id) ? "course-details.tt" : "invalid-course.tt"; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { template_name => "course_reserves/$tmpl", - query => $cgi, - type => "intranet", - flagsrequired => $flagsrequired, + { + template_name => "course_reserves/$tmpl", + query => $cgi, + type => "intranet", + flagsrequired => $flagsrequired, } ); -if ( $action eq 'del_reserve' ) { +if ( $op eq 'cud-del_reserve' ) { DelCourseReserve( cr_id => scalar $cgi->param('cr_id') ); -} -elsif ( $action eq 'rm_all' ) { - my $course_res = GetCourseReserves(course_id => $course_id); +} elsif ( $op eq 'cud-rm_all' ) { + my $course_res = GetCourseReserves( course_id => $course_id ); foreach my $cr (@$course_res) { - if(exists $cr->{'cr_id'}) { - DelCourseReserve(cr_id => $cr->{cr_id}); + if ( exists $cr->{'cr_id'} ) { + DelCourseReserve( cr_id => $cr->{cr_id} ); } } } @@ -66,7 +66,6 @@ my $course_reserves = GetCourseReserves( $template->param( course => $course, course_reserves => $course_reserves, - user => Koha::Patrons->find( $loggedinuser ), ); output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/course_reserves/mod_course.pl b/course_reserves/mod_course.pl index 48d7d1c3bc..a29e141ac2 100755 --- a/course_reserves/mod_course.pl +++ b/course_reserves/mod_course.pl @@ -29,15 +29,15 @@ use C4::CourseReserves qw( DelCourse ModCourse ModCourseInstructors ); my $cgi = CGI->new; -checkauth($cgi, 0, { coursereserves => 'manage_courses' }, 'intranet'); +checkauth( $cgi, 0, { coursereserves => 'manage_courses' }, 'intranet' ); -my $action = $cgi->param('action') || ''; +my $op = $cgi->param('op') || ''; my $course_id = $cgi->param('course_id'); -if ( $action eq 'cud-del' ) { - DelCourse( $course_id ); +if ( $op eq 'cud-del' ) { + DelCourse($course_id); print $cgi->redirect("/cgi-bin/koha/course_reserves/course-reserves.pl"); -} else { +} elsif ( $op eq 'cud-update' or $op eq 'cud-add' ) { my %params; $params{'course_id'} = $course_id; @@ -55,9 +55,10 @@ if ( $action eq 'cud-del' ) { my @instructors = $cgi->multi_param('instructors'); ModCourseInstructors( - mode => 'replace', + mode => 'replace', borrowernumbers => \@instructors, - course_id => $new_course_id + course_id => $new_course_id ); + print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$new_course_id"); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt index dee719c6a4..dfcb472ba6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt @@ -61,13 +61,23 @@ Batch add reserves [% END %] [% IF CAN_user_coursereserves_delete_reserves && course_reserves %] - Remove all reserves +
+ [% INCLUDE 'csrf-token.inc' %] + + +
+ Remove all reserves [% END %] [% IF ( CAN_user_coursereserves_manage_courses ) %] Edit course [% END %] [% IF ( CAN_user_coursereserves_manage_courses ) %] - Delete course +
+ [% INCLUDE 'csrf-token.inc' %] + + +
+ Delete course [% END %] [% END %] @@ -293,13 +303,18 @@ [% IF CAN_user_coursereserves_add_reserves || CAN_user_coursereserves_delete_reserves %] - [% IF CAN_user_coursereserves_add_reserves && user.can_edit_items_from( cr.item.homebranch ) %] + [% IF CAN_user_coursereserves_add_reserves && logged_in_user.can_edit_items_from( cr.item.homebranch ) %] Edit [% END %] [% IF CAN_user_coursereserves_delete_reserves %] - - Remove +
+ [% INCLUDE 'csrf-token.inc' %] + + + +
+ Remove [% END %] [% END %] @@ -318,13 +333,27 @@