165 lines
3.4 KiB
Perl
Executable File
165 lines
3.4 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
# Copyright 2009 Jesse Weaver
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <https://www.gnu.org/licenses>.
|
|
#
|
|
|
|
use Modern::Perl;
|
|
|
|
use C4::Context;
|
|
use C4::Service;
|
|
use C4::Log;
|
|
use Koha::Token;
|
|
use CGI::Cookie;
|
|
use C4::Auth qw( get_session );
|
|
|
|
=head1 NAME
|
|
|
|
svc/config/systempreferences - Web service for setting system preferences
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
POST /svc/config/systempreferences/
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This service is used to set system preferences, either one at a time or in
|
|
batches.
|
|
|
|
=head1 METHODS
|
|
|
|
=cut
|
|
|
|
our ( $query, $response ) = C4::Service->init( parameters => 'manage_sysprefs' );
|
|
|
|
=head2 set_preference
|
|
|
|
=over 4
|
|
|
|
=item url path
|
|
|
|
POST /svc/config/systempreferences/$preference
|
|
|
|
=item url query
|
|
|
|
value=$value
|
|
|
|
=back
|
|
|
|
Used to set a single system preference.
|
|
|
|
=cut
|
|
|
|
sub set_preference {
|
|
my ($preference) = @_;
|
|
|
|
my $value = join( ',', $query->param('value') );
|
|
C4::Context->set_preference( $preference, $value );
|
|
|
|
C4::Service->return_success($response);
|
|
}
|
|
|
|
=head2 get_preference
|
|
|
|
=over 4
|
|
|
|
=item url path
|
|
|
|
GET /svc/config/systempreferences/$preference
|
|
|
|
=item url query
|
|
|
|
pref=$pref_name
|
|
|
|
or
|
|
|
|
pref=$pref_name1&pref=$pref_name2
|
|
|
|
|
|
=back
|
|
|
|
Used to get a single system preference value or a list of system preference values
|
|
|
|
=cut
|
|
|
|
sub get_preference {
|
|
my @prefs = $query->multi_param('pref');
|
|
|
|
if ( scalar @prefs > 1 ) {
|
|
my %results = map { $_ => C4::Context->preference($_) } @prefs;
|
|
$response->param( value => \%results );
|
|
} else {
|
|
my $value = C4::Context->preference( $prefs[0] );
|
|
$response->param( value => $value );
|
|
}
|
|
|
|
C4::Service->return_success($response);
|
|
}
|
|
|
|
=head2 set_preferences
|
|
|
|
=over 4
|
|
|
|
=item url path
|
|
|
|
POST /svc/config/systempreferences/
|
|
|
|
=item url query
|
|
|
|
pref_$pref1=$value1&pref_$pref2=$value2
|
|
|
|
=back
|
|
|
|
Used to set several system preferences at once. Each preference you want to set
|
|
should be sent prefixed with pref. If you wanted to turn off the
|
|
virtualshelves syspref, for instance, you would POST the following:
|
|
|
|
pref_virtualshelves=0
|
|
|
|
=cut
|
|
|
|
sub set_preferences {
|
|
|
|
foreach my $param ( $query->param() ) {
|
|
my ($pref) = ( $param =~ /pref_(.*)/ );
|
|
|
|
next if ( !defined($pref) );
|
|
|
|
my $value = join( ',', $query->multi_param($param) );
|
|
|
|
C4::Context->set_preference( $pref, $value );
|
|
}
|
|
|
|
C4::Service->return_success($response);
|
|
}
|
|
|
|
my %cookies = CGI::Cookie->fetch;
|
|
|
|
if ( exists $cookies{'CGISESSID'} ) {
|
|
my $sessionID = $cookies{'CGISESSID'}->value;
|
|
if ($sessionID) {
|
|
my $session = get_session($sessionID);
|
|
C4::Context->interface( $session->param('interface') ) if ($session);
|
|
}
|
|
}
|
|
|
|
C4::Service->dispatch(
|
|
[ 'POST /([A-Za-z0-9_-]+)', ['value'], \&set_preference ],
|
|
[ 'POST /', [], \&set_preferences ],
|
|
[ 'GET /', ['pref'], \&get_preference ],
|
|
);
|