3 # Copyright 2009 Jesse Weaver
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>.
30 svc/config/systempreferences - Web service for setting system preferences
34 POST /svc/config/systempreferences/
38 This service is used to set system preferences, either one at a time or in
45 our ( $query, $response ) = C4::Service->init( parameters => 'manage_sysprefs' );
53 POST /svc/config/systempreferences/$preference
61 Used to set a single system preference.
66 my ( $preference ) = @_;
67 die "wrong_csrf_token\n" unless Koha::Token->new->check_csrf(
69 session_id => scalar $query->cookie('CGISESSID'),
70 token => scalar $query->param('csrf_token'),
74 my $value = join( ',', $query->param( 'value' ) );
75 C4::Context->set_preference( $preference, $value );
77 C4::Service->return_success( $response );
80 =head2 set_preferences
86 POST /svc/config/systempreferences/
90 pref_$pref1=$value1&pref_$pref2=$value2
94 Used to set several system preferences at once. Each preference you want to set
95 should be sent prefixed with pref. If you wanted to turn off the
96 virtualshelves syspref, for instance, you would POST the following:
102 sub set_preferences {
103 die "wrong_csrf_token\n" unless Koha::Token->new->check_csrf(
105 session_id => scalar $query->cookie('CGISESSID'),
106 token => scalar $query->param('csrf_token'),
110 foreach my $param ( $query->param() ) {
111 my ( $pref ) = ( $param =~ /pref_(.*)/ );
113 next if ( !defined( $pref ) );
115 my $value = join( ',', $query->multi_param( $param ) );
117 C4::Context->set_preference( $pref, $value );
120 C4::Service->return_success( $response );
123 C4::Service->dispatch(
124 [ 'POST /([A-Za-z0-9_-]+)', [ 'value' ], \&set_preference ],
125 [ 'POST /', [], \&set_preferences ],