Bug 29496: CheckMandatorySubfields don't work properly with select field in serials...
[koha-ffzg.git] / svc / config / systempreferences
1 #!/usr/bin/perl
2
3 # Copyright 2009 Jesse Weaver
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19 #
20
21 use Modern::Perl;
22
23 use C4::Context;
24 use C4::Service;
25 use C4::Log;
26
27 =head1 NAME
28
29 svc/config/systempreferences - Web service for setting system preferences
30
31 =head1 SYNOPSIS
32
33   POST /svc/config/systempreferences/
34
35 =head1 DESCRIPTION
36
37 This service is used to set system preferences, either one at a time or in
38 batches.
39
40 =head1 METHODS
41
42 =cut
43
44 our ( $query, $response ) = C4::Service->init( parameters => 'manage_sysprefs' );
45
46 =head2 set_preference
47
48 =over 4
49
50 =item url path
51
52 POST /svc/config/systempreferences/$preference
53
54 =item url query
55
56 value=$value
57
58 =back
59
60 Used to set a single system preference.
61
62 =cut
63
64 sub set_preference {
65     my ( $preference ) = @_;
66
67     my $value = join( ',', $query->param( 'value' ) );
68     C4::Context->set_preference( $preference, $value );
69
70     C4::Service->return_success( $response );
71 }
72
73 =head2 set_preferences
74
75 =over 4
76
77 =item url path
78
79 POST /svc/config/systempreferences/
80
81 =item url query
82
83 pref_$pref1=$value1&pref_$pref2=$value2
84
85 =back
86
87 Used to set several system preferences at once. Each preference you want to set
88 should be sent prefixed with pref. If you wanted to turn off the
89 virtualshelves syspref, for instance, you would POST the following:
90
91 pref_virtualshelves=0
92
93 =cut
94
95 sub set_preferences {
96     foreach my $param ( $query->param() ) {
97         my ( $pref ) = ( $param =~ /pref_(.*)/ );
98
99         next if ( !defined( $pref ) );
100
101         my $value = join( ',', $query->multi_param( $param ) );
102
103         C4::Context->set_preference( $pref, $value );
104     }
105
106     C4::Service->return_success( $response );
107 }
108
109 C4::Service->dispatch(
110     [ 'POST /([A-Za-z0-9_-]+)', [ 'value' ], \&set_preference ],
111     [ 'POST /', [], \&set_preferences ],
112 );