Add holds policies
[koha.git] / admin / systempreferences.pl
blobd323a51776d15bbf957d1be148be947ff74f843d
1 #!/usr/bin/perl
3 # script to administer the systempref table
4 # written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 systempreferences.pl
26 ALGO :
27 this script use an $op to know what to do.
28 if $op is empty or none of the above values,
29 - the default screen is build (with all records, or filtered datas).
30 - the user can clic on add, modify or delete record.
31 if $op=add_form
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
34 if $op=add_validate
35 - the user has just send datas, so we create/modify the record
36 if $op=delete_form
37 - we show the record having primkey=$primkey and ask for deletion validation form
38 if $op=delete_confirm
39 - we delete the record having primkey=$primkey
41 =cut
43 use strict;
44 use warnings;
46 use CGI;
47 use C4::Auth;
48 use C4::Context;
49 use C4::Koha;
50 use C4::Languages qw(getTranslatedLanguages);
51 use C4::ClassSource;
52 use C4::Log;
53 use C4::Output;
55 # use Smart::Comments;
57 # FIXME, shouldnt we store this stuff in the systempreferences table?
59 # FIXME: This uses hash in a backwards way. What we really want is:
60 # $tabsysprefs{key} = $array_ref;
61 # like
62 # $tabsysprefs{Cataloguing} = [qw(autoBarcode ISBD marc ...)];
64 # Because some things *should* be on more than one tab.
65 # And the tabname is the unique part (the key).
67 my %tabsysprefs;
69 # Acquisitions
70 $tabsysprefs{acquisitions} = "Acquisitions";
71 $tabsysprefs{gist} = "Acquisitions";
72 $tabsysprefs{emailPurchaseSuggestions} = "Acquisitions";
73 $tabsysprefs{RenewSerialAddsSuggestion} = "Acquisitions";
75 # Admin
76 $tabsysprefs{singleBranchMode} = "Admin";
77 $tabsysprefs{staffClientBaseURL} = "Admin";
78 $tabsysprefs{Version} = "Admin";
79 $tabsysprefs{OpacMaintenance} = "Admin";
80 $tabsysprefs{FrameworksLoaded} = "Admin";
81 $tabsysprefs{libraryAddress} = "Admin";
82 $tabsysprefs{delimiter} = "Admin";
83 $tabsysprefs{IndependantBranches} = "Admin";
84 $tabsysprefs{insecure} = "Admin";
85 $tabsysprefs{KohaAdmin} = "Admin";
86 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
87 $tabsysprefs{MIME} = "Admin";
88 $tabsysprefs{timeout} = "Admin";
89 $tabsysprefs{Intranet_includes} = "Admin";
90 $tabsysprefs{AutoLocation} = "Admin";
91 $tabsysprefs{DebugLevel} = "Admin";
92 $tabsysprefs{SessionStorage} = "Admin";
93 $tabsysprefs{noItemTypeImages} = "Admin";
94 $tabsysprefs{OPACBaseURL} = "Admin";
95 $tabsysprefs{GranularPermissions} = "Admin";
97 # Authorities
98 $tabsysprefs{authoritysep} = "Authorities";
99 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
100 $tabsysprefs{dontmerge} = "Authorities";
101 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
103 # Cataloguing
104 $tabsysprefs{advancedMARCEditor} = "Cataloguing";
105 $tabsysprefs{autoBarcode} = "Cataloguing";
106 $tabsysprefs{hide_marc} = "Cataloguing";
107 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
108 $tabsysprefs{ISBD} = "Cataloguing";
109 $tabsysprefs{itemcallnumber} = "Cataloguing";
110 $tabsysprefs{LabelMARCView} = "Cataloguing";
111 $tabsysprefs{marc} = "Cataloguing";
112 $tabsysprefs{marcflavour} = "Cataloguing";
113 $tabsysprefs{MARCOrgCode} = "Cataloguing";
114 $tabsysprefs{z3950AuthorAuthFields} = "Cataloguing";
115 $tabsysprefs{z3950NormalizeAuthor} = "Cataloguing";
116 $tabsysprefs{Stemming} = "Cataloguing";
117 $tabsysprefs{WeightFields} = "Cataloguing";
118 $tabsysprefs{NoZebra} = "Cataloguing";
119 $tabsysprefs{NoZebraIndexes} = "Cataloguing";
120 $tabsysprefs{ReceiveBackIssues} = "Cataloguing";
121 $tabsysprefs{DefaultClassificationSource} = "Cataloguing";
122 $tabsysprefs{RoutingSerials} = "Cataloguing";
123 $tabsysprefs{'item-level_itypes'} = "Cataloguing";
124 $tabsysprefs{OpacSuppression} = "Cataloguing";
126 # Circulation
127 $tabsysprefs{maxoutstanding} = "Circulation";
128 $tabsysprefs{maxreserves} = "Circulation";
129 $tabsysprefs{noissuescharge} = "Circulation";
130 $tabsysprefs{IssuingInProcess} = "Circulation";
131 $tabsysprefs{patronimages} = "Circulation";
132 $tabsysprefs{printcirculationslips} = "Circulation";
133 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
134 $tabsysprefs{SpecifyDueDate} = "Circulation";
135 $tabsysprefs{AutomaticItemReturn} = "Circulation";
136 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
137 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
138 $tabsysprefs{useDaysMode} = "Circulation";
139 $tabsysprefs{ReservesNeedReturns} = "Circulation";
140 $tabsysprefs{CircAutocompl} = "Circulation";
141 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
142 $tabsysprefs{canreservefromotherbranches} = "Circulation";
143 $tabsysprefs{finesMode} = "Circulation";
144 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
145 $tabsysprefs{globalDueDate} = "Circulation";
146 $tabsysprefs{holdCancelLength} = "Circulation";
147 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
148 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
149 $tabsysprefs{CircControl} = "Circulation";
150 $tabsysprefs{finesCalendar} = "Circulation";
151 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
152 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
153 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
154 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
155 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
156 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
157 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
158 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
159 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
161 # Staff Client
162 $tabsysprefs{TemplateEncoding} = "StaffClient";
163 $tabsysprefs{template} = "StaffClient";
164 $tabsysprefs{intranetstylesheet} = "StaffClient";
165 $tabsysprefs{IntranetNav} = "StaffClient";
166 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
167 $tabsysprefs{intranetuserjs} = "StaffClient";
168 $tabsysprefs{yuipath} = "StaffClient";
169 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
171 # Patrons
172 $tabsysprefs{autoMemberNum} = "Patrons";
173 $tabsysprefs{checkdigit} = "Patrons";
174 $tabsysprefs{intranetreadinghistory} = "Patrons";
175 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
176 $tabsysprefs{memberofinstitution} = "Patrons";
177 $tabsysprefs{ReadingHistory} = "Patrons";
178 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
179 $tabsysprefs{borrowerRelationship} = "Patrons";
180 $tabsysprefs{BorrowersTitles} = "Patrons";
181 $tabsysprefs{patronimages} = "Patrons";
182 $tabsysprefs{MinPasswordLength} = "Patrons";
183 $tabsysprefs{uppercasesurnames} = "Patrons";
184 $tabsysprefs{NoReturnSetLost} = "Patrons";
185 $tabsysprefs{MaxFine} = "Patrons";
186 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
187 $tabsysprefs{AddPatronLists} = "Patrons";
188 $tabsysprefs{PatronsPerPage} = "Patrons";
189 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
190 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
191 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
192 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
193 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
195 # I18N/L10N
196 $tabsysprefs{dateformat} = "I18N/L10N";
197 $tabsysprefs{opaclanguages} = "I18N/L10N";
198 $tabsysprefs{opacthemes} = "I18N/L10N";
199 $tabsysprefs{language} = "I18N/L10N";
201 # Searching
202 $tabsysprefs{defaultSortField} = "Searching";
203 $tabsysprefs{defaultSortOrder} = "Searching";
204 $tabsysprefs{numSearchResults} = "Searching";
205 $tabsysprefs{OPACdefaultSortField} = "Searching";
206 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
207 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
208 $tabsysprefs{OPACnumSearchResults} = "Searching";
209 $tabsysprefs{QueryFuzzy} = "Searching";
210 $tabsysprefs{QueryStemming} = "Searching";
211 $tabsysprefs{QueryWeightFields} = "Searching";
212 $tabsysprefs{expandedSearchOption} = "Searching";
213 $tabsysprefs{sortbynonfiling} = "Searching";
214 $tabsysprefs{QueryAutoTruncate} = "Searching";
215 $tabsysprefs{QueryRemoveStopwords} = "Searching";
216 $tabsysprefs{AdvancedSearchTypes} = "Searching";
218 # EnhancedContent
219 $tabsysprefs{AmazonContent} = "EnhancedContent";
220 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
221 $tabsysprefs{AmazonLocale} = "EnhancedContent";
222 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
223 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
224 $tabsysprefs{OPACAmazonContent} = "EnhancedContent";
225 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
227 # Baker & Taylor
228 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
229 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
230 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
231 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
233 # FRBR
234 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
235 $tabsysprefs{XISBN} = "EnhancedContent";
236 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
237 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
238 $tabsysprefs{PINESISBN} = "EnhancedContent";
239 $tabsysprefs{ThingISBN} = "EnhancedContent";
240 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
242 # Tags
243 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
244 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
245 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
246 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
247 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
248 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
249 $tabsysprefs{TagsModeration} = 'EnhancedContent';
250 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
251 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
253 # OPAC
254 $tabsysprefs{BiblioDefaultView} = "OPAC";
255 $tabsysprefs{LibraryName} = "OPAC";
256 $tabsysprefs{opaccolorstylesheet} = "OPAC";
257 $tabsysprefs{opaccredits} = "OPAC";
258 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
259 $tabsysprefs{OpacNav} = "OPAC";
260 $tabsysprefs{opacsmallimage} = "OPAC";
261 $tabsysprefs{opacstylesheet} = "OPAC";
262 $tabsysprefs{opacthemes} = "OPAC";
263 $tabsysprefs{opacuserjs} = "OPAC";
264 $tabsysprefs{SubscriptionHistory} = "OPAC";
265 $tabsysprefs{opacheader} = "OPAC";
266 $tabsysprefs{noOPACUserLogin} = "OPAC";
267 $tabsysprefs{hideBiblioNumber} = "OPAC";
268 $tabsysprefs{OPACDisplayExtendedSubInfo} = "OPAC";
269 $tabsysprefs{OpacMainUserBlock} = "OPAC";
270 $tabsysprefs{OPACSubscriptionDisplay} = "OPAC";
271 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
272 $tabsysprefs{OPACUserCSS} = "OPAC";
273 $tabsysprefs{OPACHighlightedWords} = "OPAC";
274 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
275 $tabsysprefs{URLLinkText} = "OPAC";
276 $tabsysprefs{OPACShelfBrowser} = "OPAC";
277 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
279 # OPAC
280 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
281 $tabsysprefs{hidelostitems} = "OPAC";
282 $tabsysprefs{opacbookbag} = "OPAC";
283 $tabsysprefs{opaclanguagesdisplay} = "OPAC";
284 $tabsysprefs{OpacPasswordChange} = "OPAC";
285 $tabsysprefs{opacreadinghistory} = "OPAC";
286 $tabsysprefs{virtualshelves} = "OPAC";
287 $tabsysprefs{RequestOnOpac} = "OPAC";
288 $tabsysprefs{reviewson} = "OPAC";
289 $tabsysprefs{OpacTopissues} = "OPAC";
290 $tabsysprefs{OpacAuthorities} = "OPAC";
291 $tabsysprefs{OpacCloud} = "OPAC";
292 $tabsysprefs{opacuserlogin} = "OPAC";
293 $tabsysprefs{AnonSuggestions} = "OPAC";
294 $tabsysprefs{suggestion} = "OPAC";
295 $tabsysprefs{OpacTopissue} = "OPAC";
296 $tabsysprefs{OpacBrowser} = "OPAC";
297 $tabsysprefs{kohaspsuggest} = "OPAC";
298 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
299 $tabsysprefs{OPACItemHolds} = "OPAC";
300 $tabsysprefs{OPACGroupResults} = "OPAC";
301 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
302 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
304 # LOGFeatures
305 $tabsysprefs{CataloguingLog} = "Logs";
306 $tabsysprefs{BorrowersLog} = "Logs";
307 $tabsysprefs{SubscriptionLog} = "Logs";
308 $tabsysprefs{IssueLog} = "Logs";
309 $tabsysprefs{ReturnLog} = "Logs";
310 $tabsysprefs{LetterLog} = "Logs";
311 $tabsysprefs{FinesLog} = "Logs";
313 # OAI-PMH variables
314 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
315 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
316 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
317 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
318 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
320 sub StringSearch {
321 my ( $searchstring, $type ) = @_;
322 my $dbh = C4::Context->dbh;
323 $searchstring =~ s/\'/\\\'/g;
324 my @data = split( ' ', $searchstring );
325 my $count = @data;
326 my @results;
327 my $cnt = 0;
328 my $sth;
330 # used for doing a plain-old sys-pref search
331 if ( $type && $type ne 'all' ) {
332 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
333 if ( $tabsysprefs{$syspref} eq $type ) {
334 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
335 $sth->execute($syspref);
336 while ( my $data = $sth->fetchrow_hashref ) {
337 $data->{shortvalue} = $data->{value};
338 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
339 push( @results, $data );
340 $cnt++;
342 $sth->finish;
345 } else {
346 my $sth;
348 if ( $type and $type eq 'all' ) {
349 $sth = $dbh->prepare( "
350 SELECT *
351 FROM systempreferences
352 WHERE variable LIKE ? OR explanation LIKE ?
353 ORDER BY VARIABLE" );
354 $sth->execute( "%$searchstring%", "%$searchstring%" );
355 } else {
356 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
357 foreach my $syspref ( keys %tabsysprefs ) {
358 $strsth .= $dbh->quote($syspref) . ",";
360 $strsth =~ s/,$/) /;
361 $strsth .= " order by variable";
362 $sth = $dbh->prepare($strsth);
363 $sth->execute();
366 while ( my $data = $sth->fetchrow_hashref ) {
367 $data->{shortvalue} = $data->{value};
368 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
369 push( @results, $data );
370 $cnt++;
373 $sth->finish;
375 return ( $cnt, \@results );
378 sub GetPrefParams {
379 my $data = shift;
380 my $params = $data;
381 my @options;
383 if ( defined $data->{'options'} ) {
384 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
385 my $selected = '0';
386 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
387 push @options, { option => $option, selected => $selected };
391 $params->{'prefoptions'} = $data->{'options'};
393 if ( not defined( $data->{'type'} ) ) {
394 $params->{'type-free'} = 1;
395 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
396 } elsif ( $data->{'type'} eq 'Choice' ) {
397 $params->{'type-choice'} = 1;
398 } elsif ( $data->{'type'} eq 'YesNo' ) {
399 $params->{'type-yesno'} = 1;
400 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
401 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
402 $params->{'value-yes'} = 1;
403 } else {
404 $params->{'value-no'} = 1;
406 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
407 $params->{'type-free'} = 1;
408 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
409 } elsif ( $data->{'type'} eq 'Textarea' ) {
410 $params->{'type-textarea'} = 1;
411 $data->{options} =~ /(.*)\|(.*)/;
412 $params->{'cols'} = $1;
413 $params->{'rows'} = $2;
414 } elsif ( $data->{'type'} eq 'Themes' ) {
415 $params->{'type-choice'} = 1;
416 my $type = '';
417 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
418 @options = ();
419 my $currently_selected_themes;
420 my $counter = 0;
421 foreach my $theme ( split /\s+/, $data->{'value'} ) {
422 push @options, { option => $theme, counter => $counter };
423 $currently_selected_themes->{$theme} = 1;
424 $counter++;
426 foreach my $theme ( getallthemes($type) ) {
427 my $selected = '0';
428 next if $currently_selected_themes->{$theme};
429 push @options, { option => $theme, counter => $counter };
430 $counter++;
432 } elsif ( $data->{'type'} eq 'ClassSources' ) {
433 $params->{'type-choice'} = 1;
434 my $type = '';
435 @options = ();
436 my $sources = GetClassSources();
437 my $counter = 0;
438 foreach my $cn_source ( sort keys %$sources ) {
439 if ( $cn_source eq $data->{'value'} ) {
440 push @options, { option => $cn_source, counter => $counter, selected => 1 };
441 } else {
442 push @options, { option => $cn_source, counter => $counter };
444 $counter++;
446 } elsif ( $data->{'type'} eq 'Languages' ) {
447 my $currently_selected_languages;
448 foreach my $language ( split /\s+/, $data->{'value'} ) {
449 $currently_selected_languages->{$language} = 1;
452 # current language
453 my $lang = $params->{'lang'};
454 my $theme;
455 my $interface;
456 if ( $data->{'variable'} =~ /opac/ ) {
458 # this is the OPAC
459 $interface = 'opac';
460 $theme = C4::Context->preference('opacthemes');
461 } else {
463 # this is the staff client
464 $interface = 'intranet';
465 $theme = C4::Context->preference('template');
467 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
469 $params->{'languages_loop'} = $languages_loop;
470 $params->{'type-langselector'} = 1;
471 } else {
472 $params->{'type-free'} = 1;
473 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
476 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
477 $params->{'oneline'} = 1;
480 $params->{'preftype'} = $data->{'type'};
481 $params->{'options'} = \@options;
483 return $params;
486 my $input = new CGI;
487 my $searchfield = $input->param('searchfield') || '';
488 my $Tvalue = $input->param('Tvalue');
489 my $offset = $input->param('offset') || 0;
490 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
492 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
493 { template_name => "admin/systempreferences.tmpl",
494 query => $input,
495 type => "intranet",
496 authnotrequired => 0,
497 flagsrequired => { parameters => 1 },
498 debug => 1,
501 my $pagesize = 100;
502 my $op = $input->param('op') || '';
503 $searchfield =~ s/\,//g;
505 if ($op) {
506 $template->param(
507 script_name => $script_name,
508 $op => 1
509 ); # we show only the TMPL_VAR names $op
510 } else {
511 $template->param(
512 script_name => $script_name,
513 else => 1
514 ); # we show only the TMPL_VAR names $op
517 if ( $op eq 'update_and_reedit' ) {
518 foreach ( $input->param ) {
520 my $value = '';
521 if ( my $currentorder = $input->param('currentorder') ) {
522 my @currentorder = split /\|/, $currentorder;
523 my $orderchanged = 0;
524 foreach my $param ( $input->param ) {
525 if ( $param =~ m#up-(\d+).x# ) {
526 my $temp = $currentorder[$1];
527 $currentorder[$1] = $currentorder[ $1 - 1 ];
528 $currentorder[ $1 - 1 ] = $temp;
529 $orderchanged = 1;
530 last;
531 } elsif ( $param =~ m#down-(\d+).x# ) {
532 my $temp = $currentorder[$1];
533 $currentorder[$1] = $currentorder[ $1 + 1 ];
534 $currentorder[ $1 + 1 ] = $temp;
535 $orderchanged = 1;
536 last;
539 $value = join ' ', @currentorder;
540 if ($orderchanged) {
541 $op = 'add_form';
542 $template->param(
543 script_name => $script_name,
544 $op => 1
545 ); # we show only the TMPL_VAR names $op
546 } else {
547 $op = '';
548 $searchfield = '';
549 $template->param(
550 script_name => $script_name,
551 else => 1
552 ); # we show only the TMPL_VAR names $op
555 my $dbh = C4::Context->dbh;
556 my $query = "select * from systempreferences where variable=?";
557 my $sth = $dbh->prepare($query);
558 $sth->execute( $input->param('variable') );
559 if ( $sth->rows ) {
560 unless ( C4::Context->config('demo') ) {
561 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
562 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
563 $sth->finish;
564 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
566 } else {
567 unless ( C4::Context->config('demo') ) {
568 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
569 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
570 $sth->finish;
571 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
574 $sth->finish;
578 ################## ADD_FORM ##################################
579 # called by default. Used to create form to add or modify a record
581 if ( $op eq 'add_form' ) {
583 #---- if primkey exists, it's a modify action, so read values to modify...
584 my $data;
585 if ($searchfield) {
586 my $dbh = C4::Context->dbh;
587 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
588 $sth->execute($searchfield);
589 $data = $sth->fetchrow_hashref;
590 $sth->finish;
591 $template->param( modify => 1 );
593 # save tab to return to if user cancels edit
594 $template->param( return_tab => $tabsysprefs{$searchfield} );
597 $data->{'lang'} = $template->param('lang');
599 $template->param( GetPrefParams($data) );
601 $template->param( searchfield => $searchfield );
603 ################## ADD_VALIDATE ##################################
604 # called by add_form, used to insert/modify data in DB
605 } elsif ( $op eq 'add_validate' ) {
606 my $dbh = C4::Context->dbh;
607 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
608 $sth->execute( $input->param('variable') );
610 # to handle multiple values
611 my $value;
613 # handle multiple value strings (separated by ',')
614 my $params = $input->Vars;
615 if ( defined $params->{'value'} ) {
616 my @values = ();
617 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
618 if (@values) {
619 $value = "";
620 for my $vl (@values) {
621 $value .= "$vl,";
623 $value =~ s/,$//;
624 } else {
625 $value = $params->{'value'};
628 if ( $sth->rows ) {
629 unless ( C4::Context->config('demo') ) {
630 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
631 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
632 $sth->finish;
633 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
635 } else {
636 unless ( C4::Context->config('demo') ) {
637 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
638 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
639 $sth->finish;
640 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
643 $sth->finish;
644 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
645 exit;
646 ################## DELETE_CONFIRM ##################################
647 # called by default form, used to confirm deletion of data in DB
648 } elsif ( $op eq 'delete_confirm' ) {
649 my $dbh = C4::Context->dbh;
650 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
651 $sth->execute($searchfield);
652 my $data = $sth->fetchrow_hashref;
653 $sth->finish;
654 $template->param(
655 searchfield => $searchfield,
656 Tvalue => $data->{'value'},
659 # END $OP eq DELETE_CONFIRM
660 ################## DELETE_CONFIRMED ##################################
661 # called by delete_confirm, used to effectively confirm deletion of data in DB
662 } elsif ( $op eq 'delete_confirmed' ) {
663 my $dbh = C4::Context->dbh;
664 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
665 $sth->execute($searchfield);
666 my $logstring = $searchfield . " | " . $Tvalue;
667 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
668 $sth->finish;
670 # END $OP eq DELETE_CONFIRMED
671 ################## DEFAULT ##################################
672 } else { # DEFAULT
673 #Adding tab management for system preferences
674 my $tab = $input->param('tab');
675 $template->param( $tab => 1 );
676 my ( $count, $results ) = StringSearch( $searchfield, $tab );
677 my @loop_data = ();
678 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
679 my $row_data = $results->[$i];
680 $row_data->{'lang'} = $template->param('lang');
681 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
682 $row_data->{edit} = "$script_name?op=add_form&amp;searchfield=" . $results->[$i]{'variable'};
683 $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
684 push( @loop_data, $row_data );
686 $tab = ( $tab ? $tab : "Local Use" );
687 $template->param( loop => \@loop_data, $tab => 1 );
688 if ( $offset > 0 ) {
689 my $prevpage = $offset - $pagesize;
690 $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
692 if ( $offset + $pagesize < $count ) {
693 my $nextpage = $offset + $pagesize;
694 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
696 $template->param( tab => $tab, );
697 } #---- END $OP eq DEFAULT
698 output_html_with_http_headers $input, $cookie, $template->output;