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
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
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.
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
35 - the user has just send datas, so we create/modify the record
37 - we show the record having primkey=$primkey and ask for deletion validation form
39 - we delete the record having primkey=$primkey
53 # FIXME, shouldnt we store this stuff in the systempreferences table?
57 $tabsysprefs{acquisitions}="Acquisitions";
58 $tabsysprefs{gist}="Acquisitions";
60 $tabsysprefs{dateformat}="Admin";
61 $tabsysprefs{delimiter}="Admin";
62 $tabsysprefs{IndependantBranches}="Admin";
63 $tabsysprefs{insecure}="Admin";
64 $tabsysprefs{KohaAdmin}="Admin";
65 $tabsysprefs{KohaAdminEmailAddress}="Admin";
66 $tabsysprefs{MIME}="Admin";
67 $tabsysprefs{timeout}="Admin";
68 $tabsysprefs{Intranet_includes}="Admin";
69 $tabsysprefs{AutoLocation}="Admin";
72 $tabsysprefs{authoritysep}="Authorities";
73 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
75 $tabsysprefs{advancedMARCEditor}="Catalogue";
76 $tabsysprefs{autoBarcode}="Catalogue";
77 $tabsysprefs{hide_marc}="Catalogue";
78 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
79 $tabsysprefs{ISBD}="Catalogue";
80 $tabsysprefs{itemcallnumber}="Catalogue";
81 $tabsysprefs{kohaspsuggest} = "Catalogue";
82 $tabsysprefs{LabelMARCView}="Catalogue";
83 $tabsysprefs{marc}="Catalogue";
84 $tabsysprefs{marcflavour}="Catalogue";
85 $tabsysprefs{serialsadditems}="Catalogue";
86 $tabsysprefs{sortbynonfiling}="Catalogue";
87 $tabsysprefs{MARCOrgCode}="Catalogue";
88 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
89 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
90 $tabsysprefs{Stemming}="Catalogue";
91 $tabsysprefs{WeightFields}="Catalogue";
92 $tabsysprefs{expandedSearchOption}="Catalogue";
95 $tabsysprefs{maxoutstanding}="Circulation";
96 $tabsysprefs{maxreserves}="Circulation";
97 $tabsysprefs{noissuescharge}="Circulation";
98 $tabsysprefs{IssuingInProcess}="Circulation";
99 $tabsysprefs{patronimages}="Circulation";
100 $tabsysprefs{printcirculationslips}="Circulation";
101 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
102 $tabsysprefs{SpecifyDueDate}="Circulation";
103 $tabsysprefs{AutomaticItemReturn}="Circulation";
104 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
105 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
106 $tabsysprefs{useDaysMode}="Circulation";
109 $tabsysprefs{TemplateEncoding}="Intranet";
110 $tabsysprefs{template}="Intranet";
111 $tabsysprefs{intranetstylesheet}="Intranet";
112 $tabsysprefs{IntranetNav}="Intranet";
113 $tabsysprefs{intranetcolorstylesheet}="Intranet";
114 $tabsysprefs{intranetuserjs}="Intranet";
116 $tabsysprefs{automembernum}="Members";
117 $tabsysprefs{checkdigit}="Members";
118 $tabsysprefs{intranetreadinghistory}="Members";
119 $tabsysprefs{NotifyBorrowerDeparture}="Members";
120 $tabsysprefs{memberofinstitution}="Members";
121 $tabsysprefs{ReadingHistory}="Members";
122 $tabsysprefs{BorrowerMandatoryField}="Members";
123 $tabsysprefs{borrowerRelationship}="Members";
124 $tabsysprefs{BorrowersTitles}="Members";
125 $tabsysprefs{patronimages}="Members";
128 $tabsysprefs{AmazonAssocTag}="OPAC";
129 $tabsysprefs{AmazonContent}="OPAC";
130 $tabsysprefs{AmazonDevKey}="OPAC";
131 $tabsysprefs{BiblioDefaultView}="OPAC";
132 $tabsysprefs{LibraryName}="OPAC";
133 $tabsysprefs{opaccolorstylesheet}="OPAC";
134 $tabsysprefs{opaccredits}="OPAC";
135 $tabsysprefs{opaclanguages}="OPAC";
136 $tabsysprefs{opaclargeimage}="OPAC";
137 $tabsysprefs{opaclayoutstylesheet}="OPAC";
138 $tabsysprefs{OpacNav}="OPAC";
139 $tabsysprefs{opacsmallimage}="OPAC";
140 $tabsysprefs{opacstylesheet}="OPAC";
141 $tabsysprefs{opacthemes}="OPAC";
142 $tabsysprefs{opacuserjs}="OPAC";
143 $tabsysprefs{SubscriptionHistory}="OPAC";
144 $tabsysprefs{opacheader}="OPAC";
147 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
148 $tabsysprefs{hidelostitems}="OPACFeatures";
149 $tabsysprefs{opacbookbag}="OPACFeatures";
150 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
151 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
152 $tabsysprefs{opacreadinghistory}="OPACFeatures";
153 $tabsysprefs{virtualshelves}="OPACFeatures";
154 $tabsysprefs{RequestOnOpac}="OPACFeatures";
155 $tabsysprefs{reviewson}="OPACFeatures";
156 $tabsysprefs{OpacTopissues}="OPACFeatures";
157 $tabsysprefs{OpacAuthorities}="OPACFeatures";
158 $tabsysprefs{OpacCloud}="OPACFeatures";
159 $tabsysprefs{opacuserlogin}="OPACFeatures";
160 $tabsysprefs{AnonSuggestions}="OPACFeatures";
161 $tabsysprefs{suggestion}="OPACFeatures";
162 $tabsysprefs{OpacTopissue}="OPACFeatures";
163 $tabsysprefs{OpacBrowser}="OPACFeatures";
166 $tabsysprefs{CataloguingLog} = "LOGFeatures";
167 $tabsysprefs{BorrowersLog} = "LOGFeatures";
168 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
169 $tabsysprefs{IssueLog} = "LOGFeatures";
170 $tabsysprefs{ReturnLog} = "LOGFeatures";
171 $tabsysprefs{LetterLog} = "LOGFeatures";
172 $tabsysprefs{FinesLog} = "LOGFeatures";
175 my ($searchstring,$type)=@_;
176 my $dbh = C4::Context->dbh;
177 $searchstring=~ s/\'/\\\'/g;
178 my @data=split(' ',$searchstring);
183 foreach my $syspref (sort keys %tabsysprefs){
184 if ($tabsysprefs{$syspref} eq $type){
185 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
186 $sth->execute($syspref);
187 while (my $data=$sth->fetchrow_hashref){
188 $data->{value} =~ s/</</g;
189 $data->{value} =~ s/>/>/g;
190 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
191 push(@results,$data);
198 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
199 foreach my $syspref (keys %tabsysprefs){
200 $strsth .= $dbh->quote($syspref).",";
203 $strsth .= " order by variable";
204 my $sth=$dbh->prepare($strsth);
206 while (my $data=$sth->fetchrow_hashref){
207 $data->{value}=substr($data->{value},0,100);
208 push(@results,$data);
213 return ($cnt,\@results);
217 my $searchfield=$input->param('searchfield');
218 my $offset=$input->param('offset');
219 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
221 my ($template, $borrowernumber, $cookie)
222 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
225 authnotrequired => 0,
226 flagsrequired => {parameters => 1},
230 my $op = $input->param('op');
231 $searchfield=~ s/\,//g;
234 $template->param(script_name => $script_name,
235 $op => 1); # we show only the TMPL_VAR names $op
237 $template->param(script_name => $script_name,
238 else => 1); # we show only the TMPL_VAR names $op
241 if ($op eq 'update_and_reedit') {
242 foreach ($input->param) {
245 if (my $currentorder=$input->param('currentorder')) {
246 my @currentorder=split /\|/, $currentorder;
248 foreach my $param ($input->param) {
249 if ($param=~m#up-(\d+).x#) {
250 my $temp=$currentorder[$1];
251 $currentorder[$1]=$currentorder[$1-1];
252 $currentorder[$1-1]=$temp;
255 } elsif ($param=~m#down-(\d+).x#) {
256 my $temp=$currentorder[$1];
257 $currentorder[$1]=$currentorder[$1+1];
258 $currentorder[$1+1]=$temp;
263 $value=join ' ', @currentorder;
266 $template->param(script_name => $script_name,
267 $op => 1); # we show only the TMPL_VAR names $op
271 $template->param(script_name => $script_name,
272 else => 1); # we show only the TMPL_VAR names $op
275 my $dbh = C4::Context->dbh;
276 my $query="select * from systempreferences where variable=?";
277 my $sth=$dbh->prepare($query);
278 $sth->execute($input->param('variable'));
280 unless (C4::Context->config('demo') eq 1) {
281 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
282 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
286 unless (C4::Context->config('demo') eq 1) {
287 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
288 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
296 ################## ADD_FORM ##################################
297 # called by default. Used to create form to add or modify a record
299 if ($op eq 'add_form') {
300 #---- if primkey exists, it's a modify action, so read values to modify...
303 my $dbh = C4::Context->dbh;
304 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
305 $sth->execute($searchfield);
306 $data=$sth->fetchrow_hashref;
308 $template->param(modify => 1);
312 foreach my $option (split(/\|/, $data->{'options'})) {
314 $option eq $data->{'value'} and $selected=1;
315 push @options, { option => $option, selected => $selected };
317 if ($data->{'type'} eq 'Choice') {
318 $template->param('type-choice' => 1);
319 } elsif ($data->{'type'} eq 'YesNo') {
320 $template->param('type-yesno' => 1);
321 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
322 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
323 } elsif ($data->{'type'} eq 'Integer') {
324 $template->param('type-free' => 1);
325 $template->param('fieldlength' => $data->{'options'});
326 } elsif ($data->{'type'} eq 'Textarea') {
327 $template->param('type-textarea' => 1);
328 $data->{options} =~ /(.*)\|(.*)/;
329 $template->param('cols' => $1, 'rows' => $2);;
330 } elsif ($data->{'type'} eq 'Float') {
331 $template->param('type-free' => 1);
332 $template->param('fieldlength' => $data->{'options'});
333 } elsif ($data->{'type'} eq 'Themes') {
334 $template->param('type-choice' => 1);
336 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
338 my $currently_selected_themes;
340 foreach my $theme (split /\s+/, $data->{'value'}) {
341 push @options, { option => $theme, counter => $counter };
342 $currently_selected_themes->{$theme}=1;
345 foreach my $theme (getallthemes($type)) {
347 next if $currently_selected_themes->{$theme};
348 push @options, { option => $theme, counter => $counter };
351 } elsif ($data->{'type'} eq 'Languages') {
352 $template->param('type-choice' => 1);
355 my $currently_selected_languages;
357 foreach my $language (split /\s+/, $data->{'value'}) {
358 next if $language eq 'images';
359 push @options, { option => $language, counter => $counter };
360 $currently_selected_languages->{$language}=1;
363 my $langavail = getTranslatedLanguages();
364 foreach my $language (@$langavail) {
366 next if $currently_selected_languages->{$language->{'language_code'}};
367 #FIXME: could add language_name and language_locale_name for better display
368 push @options, { option => $language->{'language_code'}, counter => $counter };
372 $template->param('type-free' => 1);
373 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
375 $template->param(explanation => $data->{'explanation'},
376 value => $data->{'value'},
377 type => $data->{'type'},
378 options => \@options,
379 preftype => $data->{'type'},
380 prefoptions => $data->{'options'},
381 searchfield => $searchfield);
383 ################## ADD_VALIDATE ##################################
384 # called by add_form, used to insert/modify data in DB
385 } elsif ($op eq 'add_validate') {
386 my $dbh = C4::Context->dbh;
387 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
388 $sth->execute($input->param('variable'));
390 unless (C4::Context->config('demo') eq 1) {
391 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
392 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
396 unless (C4::Context->config('demo') eq 1) {
397 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
398 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
403 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
405 ################## DELETE_CONFIRM ##################################
406 # called by default form, used to confirm deletion of data in DB
407 } elsif ($op eq 'delete_confirm') {
408 my $dbh = C4::Context->dbh;
409 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
410 $sth->execute($searchfield);
411 my $data=$sth->fetchrow_hashref;
413 $template->param(searchfield => $searchfield,
414 Tvalue => $data->{'value'},
417 # END $OP eq DELETE_CONFIRM
418 ################## DELETE_CONFIRMED ##################################
419 # called by delete_confirm, used to effectively confirm deletion of data in DB
420 } elsif ($op eq 'delete_confirmed') {
421 my $dbh = C4::Context->dbh;
422 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
423 $sth->execute($searchfield);
425 # END $OP eq DELETE_CONFIRMED
426 ################## DEFAULT ##################################
428 #Adding tab management for system preferences
429 my $tab=$input->param('tab');
431 my ($count,$results)=StringSearch($searchfield,$tab);
434 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
440 my %row_data; # get a fresh hash for the row data
441 $row_data{variable} = $results->[$i]{'variable'};
442 $row_data{value} = $results->[$i]{'value'};
443 $row_data{explanation} = $results->[$i]{'explanation'};
444 $row_data{toggle} = $toggle;
445 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
446 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
447 push(@loop_data, \%row_data);
449 $tab=($tab?$tab:"Others");
450 $template->param(loop => \@loop_data, $tab => 1);
452 my $prevpage = $offset-$pagesize;
453 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
455 if ($offset+$pagesize<$count) {
456 my $nextpage =$offset+$pagesize;
457 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
459 $template->param( tab => $tab,
461 } #---- END $OP eq DEFAULT
462 output_html_with_http_headers $input, $cookie, $template->output;