big commit, still breaking things...
[koha.git] / admin / systempreferences.pl
index b314821..a18d7b7 100755 (executable)
@@ -48,6 +48,39 @@ use C4::Search;
 use HTML::Template;
 use C4::Context;
 
+my %tabsysprefs;
+$tabsysprefs{acquisitions}="Acquisitions";
+$tabsysprefs{gist}="Acquisitions";
+$tabsysprefs{authoritysep}="Authorities";
+$tabsysprefs{ISBD}="Catalogue";
+$tabsysprefs{marc}="Catalogue";
+$tabsysprefs{autoBarcode}="Catalogue";
+$tabsysprefs{marcflavour}="Catalogue";
+$tabsysprefs{SubscriptionHistory}="OPAC";
+$tabsysprefs{maxoutstanding}="Circulation";
+$tabsysprefs{printcirculationslips}="Circulation";
+$tabsysprefs{ReturnBeforeExpiry}="Circulation";
+$tabsysprefs{suggestion}="OPAC";
+$tabsysprefs{automembernum}="Members";
+$tabsysprefs{noissuescharge}="Circulation";
+$tabsysprefs{opacthemes}="OPAC";
+$tabsysprefs{opaclanguages}="OPAC";
+$tabsysprefs{LibraryName}="OPAC";
+$tabsysprefs{opacstylesheet}="OPAC";
+$tabsysprefs{BiblioDefaultView}="OPAC";
+$tabsysprefs{opaclargeimage}="OPAC";
+$tabsysprefs{opacsmallimage}="OPAC";
+$tabsysprefs{hidelostitems}="OPAC";
+$tabsysprefs{KohaAdmin}="Admin";
+$tabsysprefs{checkdigit}="Members";
+$tabsysprefs{dateformat}="Admin";
+$tabsysprefs{insecure}="Admin";
+$tabsysprefs{ldapinfos}="Admin";
+$tabsysprefs{ldapserver}="Admin";
+$tabsysprefs{itemcallnumber}="Catalogue";
+$tabsysprefs{maxreserves}="Circulation";
+$tabsysprefs{virtualshelves}="OPAC";
+$tabsysprefs{hide_marc}="Catalogue";
 
 sub StringSearch  {
        my ($env,$searchstring,$type)=@_;
@@ -55,18 +88,40 @@ sub StringSearch  {
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
        my $count=@data;
-       my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
-       $sth->execute("$data[0]%");
        my @results;
        my $cnt=0;
-       while (my $data=$sth->fetchrow_hashref){
-               push(@results,$data);
-               $cnt ++;
+       if ($type){
+               foreach my $syspref (sort keys %tabsysprefs){
+                       if ($tabsysprefs{$syspref} eq $type){
+                               my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
+                               $sth->execute($syspref);
+                               while (my $data=$sth->fetchrow_hashref){
+                                       push(@results,$data);
+                                       $cnt++;
+                               }
+                               $sth->finish;
+                       }
+               }
+       } else {
+               my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";  
+               foreach my $syspref (keys %tabsysprefs){
+                       $strsth .= $dbh->quote($syspref).",";
+               }
+               $strsth =~ s/,$/) /;
+               $strsth .= " order by variable";
+               warn $strsth;
+               my $sth=$dbh->prepare($strsth);
+               $sth->execute();
+               while (my $data=$sth->fetchrow_hashref){
+                       push(@results,$data);
+                       $cnt++;
+               }
+               $sth->finish;
        }
-       $sth->finish;
        return ($cnt,\@results);
 }
 
+
 my $input = new CGI;
 my $searchfield=$input->param('searchfield');
 my $offset=$input->param('offset');
@@ -86,10 +141,10 @@ $searchfield=~ s/\,//g;
 
 if ($op) {
 $template->param(script_name => $script_name,
-                                               $op              => 1); # we show only the TMPL_VAR names $op
+                                               $op              => 1,); # we show only the TMPL_VAR names $op
 } else {
 $template->param(script_name => $script_name,
-                                               else              => 1); # we show only the TMPL_VAR names $op
+                                               else              => 1,); # we show only the TMPL_VAR names $op
 }
 
 if ($op eq 'update_and_reedit') {
@@ -253,7 +308,7 @@ if ($op eq 'add_form') {
                }
        }
        $sth->finish;
-       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl\"></html>";
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
        exit;
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
@@ -278,11 +333,11 @@ if ($op eq 'add_form') {
                                                                                                        # END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ##################################
 } else { # DEFAULT
-       if  ($searchfield ne '') {
-                $template->param(searchfield => "<p>You Searched for <strong>$searchfield</strong></p>");
-       }
+       #Adding tab management for system preferences
+       my $tab=$input->param('tab');
+       
        my $env;
-       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my ($count,$results)=StringSearch($env,$searchfield,$tab);
        my $toggle=0;
        my @loop_data = ();
        for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
@@ -300,7 +355,8 @@ if ($op eq 'add_form') {
                $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'variable'};
                push(@loop_data, \%row_data);
        }
-       $template->param(loop => \@loop_data);
+       $tab=($tab?$tab:"Others");
+       $template->param(loop => \@loop_data, $tab => 1);
        if ($offset>0) {
                my $prevpage = $offset-$pagesize;
                $template->param("<a href=$script_name?offset=".$prevpage.'&lt;&lt; Prev</a>');