Bug 10215: Increase the size of opacnote and librariannote for table subscriptionhistory
[koha.git] / clubs / templates-add-modify.pl
blob254a99e2191525d551c6efd3d352ec53236f4f46
1 #!/usr/bin/perl
3 # Copyright 2013 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use CGI;
24 use C4::Auth;
25 use C4::Output;
27 use Koha::DateUtils qw(dt_from_string);
28 use Koha::Club::Templates;
29 use Koha::Club::Template::Fields;
30 use Koha::Club::Template::EnrollmentFields;
32 use Koha::Database;
33 my $schema = Koha::Database->new()->schema();
35 my $cgi = new CGI;
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 template_name => 'clubs/templates-add-modify.tt',
40 query => $cgi,
41 type => 'intranet',
42 authnotrequired => 0,
43 flagsrequired => { clubs => 'edit_templates' },
47 my $id = $cgi->param('id');
49 my $club_template;
50 my $stored;
52 if ( $cgi->param('name') ) { # Update or create club
53 if ($id) {
54 $club_template = Koha::Club::Templates->find($id);
55 $stored = 'updated';
57 else {
58 $club_template = Koha::Club::Template->new();
59 $stored = 'created';
62 $club_template->set(
64 id => $id || undef,
65 name => scalar $cgi->param('name') || undef,
66 description => scalar $cgi->param('description') || undef,
67 branchcode => scalar $cgi->param('branchcode') || undef,
68 date_updated => dt_from_string(),
69 is_email_required => scalar $cgi->param('is_email_required') ? 1 : 0,
70 is_enrollable_from_opac => scalar $cgi->param('is_enrollable_from_opac') ? 1 : 0,
72 )->store();
74 $id ||= $club_template->id();
76 # Update club creation fields
77 my @field_id = $cgi->multi_param('club_template_field_id');
78 my @field_name = $cgi->multi_param('club_template_field_name');
79 my @field_description = $cgi->multi_param('club_template_field_description');
80 my @field_authorised_value_category = $cgi->multi_param('club_template_field_authorised_value_category');
82 my @field_delete = $cgi->multi_param('club_template_field_delete');
84 for ( my $i = 0 ; $i < @field_id ; $i++ ) {
85 my $field_id = $field_id[$i];
86 my $field_name = $field_name[$i];
87 my $field_description = $field_description[$i];
88 my $field_authorised_value_category = $field_authorised_value_category[$i];
90 my $field =
91 $field_id
92 ? Koha::Club::Template::Fields->find($field_id)
93 : Koha::Club::Template::Field->new();
95 if ( grep( /^$field_id$/, @field_delete ) ) {
96 $field->delete();
98 else {
99 $field->set(
101 club_template_id => $id,
102 name => $field_name,
103 description => $field_description,
104 authorised_value_category => $field_authorised_value_category,
106 )->store();
110 # Update club enrollment fields
111 @field_id = $cgi->multi_param('club_template_enrollment_field_id');
112 @field_name = $cgi->multi_param('club_template_enrollment_field_name');
113 @field_description = $cgi->multi_param('club_template_enrollment_field_description');
114 @field_authorised_value_category = $cgi->multi_param('club_template_enrollment_field_authorised_value_category');
116 @field_delete = $cgi->multi_param('club_template_enrollment_field_delete');
118 for ( my $i = 0 ; $i < @field_id ; $i++ ) {
119 my $field_id = $field_id[$i];
120 my $field_name = $field_name[$i];
121 my $field_description = $field_description[$i];
122 my $field_authorised_value_category = $field_authorised_value_category[$i];
124 my $field =
125 $field_id
126 ? Koha::Club::Template::EnrollmentFields->find($field_id)
127 : Koha::Club::Template::EnrollmentField->new();
129 if ( grep( /^$field_id$/, @field_delete ) ) {
130 $field->delete();
132 else {
133 $field->set(
135 id => $field_id,
136 club_template_id => $id,
137 name => $field_name,
138 description => $field_description,
139 authorised_value_category => $field_authorised_value_category,
141 )->store();
145 print $cgi->redirect("/cgi-bin/koha/clubs/clubs.pl?stored=$stored&club_template_id=$id");
146 exit;
149 $club_template ||= Koha::Club::Templates->find($id);
150 $template->param( club_template => $club_template );
152 output_html_with_http_headers( $cgi, $cookie, $template->output );