Bug 108661: (follow-up) enshrine letting CardnumberLength specify just a maximum
[koha.git] / course_reserves / mod_course.pl
1 #!/usr/bin/perl
2
3 # Copyright 2012 ByWater Solutions
4 #
5 # This file is part of Koha.
6 #
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 2 of the License, or (at your option) any later
10 # version.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21
22 use CGI;
23
24 use C4::Output;
25 use C4::Reserves;
26 use C4::Auth;
27
28 use C4::CourseReserves qw(DelCourse ModCourse ModCourseInstructors);
29
30 my $cgi = new CGI;
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32     {   template_name   => "about.tmpl",
33         query           => $cgi,
34         type            => "intranet",
35         authnotrequired => 0,
36         flagsrequired   => { coursereserves => 'manage_courses' },
37     }
38 );
39
40 my $action = $cgi->param('action') || '';
41
42 if ( $action eq 'del' ) {
43     DelCourse( $cgi->param('course_id') );
44     print $cgi->redirect("/cgi-bin/koha/course_reserves/course-reserves.pl");
45 } else {
46     my %params;
47
48     $params{'course_id'} = $cgi->param('course_id')
49       if ( $cgi->param('course_id') );
50     $params{'department'}     = $cgi->param('department');
51     $params{'course_number'}  = $cgi->param('course_number');
52     $params{'section'}        = $cgi->param('section');
53     $params{'course_name'}    = $cgi->param('course_name');
54     $params{'term'}           = $cgi->param('term');
55     $params{'staff_note'}     = $cgi->param('staff_note');
56     $params{'public_note'}    = $cgi->param('public_note');
57     $params{'students_count'} = $cgi->param('students_count');
58     $params{'enabled'}        = ( $cgi->param('enabled') eq 'on' ) ? 'yes' : 'no';
59
60     my $course_id = ModCourse(%params);
61
62     my @instructors = $cgi->param('instructors');
63     ModCourseInstructors(
64         mode        => 'replace',
65         cardnumbers => \@instructors,
66         course_id   => $course_id
67     );
68     print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$course_id");
69 }