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