koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/admin systempreferences.pl,1.12,1.13


From: Steve Tonnesen
Subject: [Koha-cvs] CVS: koha/admin systempreferences.pl,1.12,1.13
Date: Wed, 11 Jun 2003 11:45:40 -0700

Update of /cvsroot/koha/koha/admin
In directory sc8-pr-cvs1:/tmp/cvs-serv19075

Modified Files:
        systempreferences.pl 
Log Message:
Fixed bug #35.  System preference settings now give selectable options where
appropriate.


Index: systempreferences.pl
===================================================================
RCS file: /cvsroot/koha/koha/admin/systempreferences.pl,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** systempreferences.pl        13 Apr 2003 03:11:44 -0000      1.12
--- systempreferences.pl        11 Jun 2003 18:45:36 -0000      1.13
***************
*** 55,59 ****
        my @data=split(' ',$searchstring);
        my address@hidden;
!       my $query="Select variable,value,explanation from systempreferences 
where (variable like \"$data[0]%\") order by variable";
        my $sth=$dbh->prepare($query);
        $sth->execute;
--- 55,59 ----
        my @data=split(' ',$searchstring);
        my address@hidden;
!       my $query="Select variable,value,explanation,type,options from 
systempreferences where (variable like \"$data[0]%\") order by variable";
        my $sth=$dbh->prepare($query);
        $sth->execute;
***************
*** 61,66 ****
        my $cnt=0;
        while (my $data=$sth->fetchrow_hashref){
!       push(@results,$data);
!       $cnt ++;
        }
        $sth->finish;
--- 61,66 ----
        my $cnt=0;
        while (my $data=$sth->fetchrow_hashref){
!               push(@results,$data);
!               $cnt ++;
        }
        $sth->finish;
***************
*** 71,75 ****
  my $searchfield=$input->param('searchfield');
  my $pkfield="variable";
! my $reqsel="select variable,value,explanation from systempreferences where 
$pkfield='$searchfield'";
  my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
  my $offset=$input->param('offset');
--- 71,75 ----
  my $searchfield=$input->param('searchfield');
  my $pkfield="variable";
! my $reqsel="select variable,value,explanation,type,options from 
systempreferences where $pkfield='$searchfield'";
  my $reqdel="delete from systempreferences where $pkfield='$searchfield'";
  my $offset=$input->param('offset');
***************
*** 95,100 ****
--- 95,156 ----
                                                else              => 1); # we 
show only the TMPL_VAR names $op
  }
+ 
+ if ($op eq 'update_and_reedit') {
+     foreach ($input->param) {
+       warn "$_: ".$input->param($_)."\n";
+     }
+     my $value='';
+     if (my $currentorder=$input->param('currentorder')) {
+       my @currentorder=split /\|/, $currentorder;
+       my $orderchanged=0;
+       foreach my $param ($input->param) {
+           if ($param=~m#up-(\d+).x#) {
+               my $temp=$currentorder[$1];
+               $currentorder[$1]=$currentorder[$1-1];
+               $currentorder[$1-1]=$temp;
+               $orderchanged=1;
+               last;
+           } elsif ($param=~m#down-(\d+).x#) {
+               my $temp=$currentorder[$1];
+               $currentorder[$1]=$currentorder[$1+1];
+               $currentorder[$1+1]=$temp;
+               $orderchanged=1;
+               last;
+           }
+       }
+       $value=join ' ', @currentorder;
+       if ($orderchanged) {
+           $op='add_form';
+           $template->param(script_name => $script_name,
+                                                   $op              => 1); # 
we show only the TMPL_VAR names $op
+       } else {
+           $op='';
+           $searchfield='';
+           $template->param(script_name => $script_name,
+                                               else              => 1); # we 
show only the TMPL_VAR names $op
+       }
+     }
+     my $dbh = C4::Context->dbh;
+     my $query="select * from systempreferences where variable=?";
+     my $sth=$dbh->prepare($query);
+     $sth->execute($input->param('variable'));
+     if ($sth->rows) {
+           my $query = "update systempreferences set value=?,explanation=? 
where variable=?";
+           my $sth=$dbh->prepare($query);
+           $sth->execute($value, $input->param('explanation'), 
$input->param('variable'));
+           $sth->finish;
+     } else {
+           my $query = "insert into systempreferences 
(variable,value,explanation) values (?,?,?)";
+           my $sth=$dbh->prepare($query);
+           $sth->execute($input->param('variable'), $input->param('value'), 
$input->param('explanation'));
+           $sth->finish;
+     }
+     $sth->finish;
+ 
+ }
+ 
  ################## ADD_FORM ##################################
  # called by default. Used to create form to add or  modify a record
+ 
  if ($op eq 'add_form') {
        #---- if primkey exists, it's a modify action, so read values to 
modify...
***************
*** 102,116 ****
        if ($searchfield) {
                my $dbh = C4::Context->dbh;
!               my $sth=$dbh->prepare("select variable,value,explanation from 
systempreferences where variable='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
-       }
-       if ($searchfield) {
                $template->param(modify => 1);
        }
  
        $template->param(explanation => $data->{'explanation'},
                         value => $data->{'value'},
                         searchfield => $searchfield);
  
--- 158,230 ----
        if ($searchfield) {
                my $dbh = C4::Context->dbh;
!               my $sth=$dbh->prepare("select 
variable,value,explanation,type,options from systempreferences where 
variable='$searchfield'");
                $sth->execute;
                $data=$sth->fetchrow_hashref;
                $sth->finish;
                $template->param(modify => 1);
        }
  
+       my @options;
+       foreach my $option (split(/\|/, $data->{'options'})) {
+               my $selected='0';
+               $option eq $data->{'value'} and $selected=1;
+               push @options, { option => $option, selected => $selected };
+       }
+       if ($data->{'type'} eq 'Choice') {
+               $template->param('type-choice' => 1);
+       } elsif ($data->{'type'} eq 'YesNo') {
+               $template->param('type-yesno' => 1);
+               ($data->{'value'} eq 'yes') ? 
($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
+       } elsif ($data->{'type'} eq 'free') {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => $data->{'options'});
+       } elsif ($data->{'type'} eq 'Integer') {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => $data->{'options'});
+       } elsif ($data->{'type'} eq 'Float') {
+               $template->param('type-free' => 1);
+               $template->param('fieldlength' => $data->{'options'});
+       } elsif ($data->{'type'} eq 'Themes') {
+               $template->param('type-reorderlist' => 1);
+               my $type='';
+               ($data->{'variable'}=~m#opac#i) ? ($type='opac') : 
($type='intranet');
+               @options=();
+               my $currently_selected_themes;
+               my $counter=0;
+               foreach my $theme (split /\s+/, $data->{'value'}) {
+                   push @options, { option => $theme, counter => $counter };
+                   $currently_selected_themes->{$theme}=1;
+                   $counter++;
+               }
+               foreach my $theme (getallthemes($type)) {
+                       my $selected='0';
+                       next if $currently_selected_themes->{$theme};
+                       push @options, { option => $theme, counter => $counter 
};
+                       $counter++;
+               }
+       } elsif ($data->{'type'} eq 'Languages') {
+               $template->param('type-reorderlist' => 1);
+               my $type='';
+               @options=();
+               my $currently_selected_languages;
+               my $counter=0;
+               foreach my $language (split /\s+/, $data->{'value'}) {
+                   next if $language eq 'images';
+                   push @options, { option => $language, counter => $counter };
+                   $currently_selected_languages->{$language}=1;
+                   $counter++;
+               }
+               foreach my $language (getalllanguages()) {
+                       next if $language eq 'images';
+                       my $selected='0';
+                       next if $currently_selected_languages->{$language};
+                       push @options, { option => $language, counter => 
$counter };
+                       $counter++;
+               }
+       }
        $template->param(explanation => $data->{'explanation'},
                         value => $data->{'value'},
+                        type => $data->{'type'},
+                        options => address@hidden,
                         searchfield => $searchfield);
  
***************
*** 119,128 ****
  } elsif ($op eq 'add_validate') {
        my $dbh = C4::Context->dbh;
!       my $query = "replace systempreferences (variable,value,explanation) 
values (";
!       $query.= $dbh->quote($input->param('variable')).",";
!       $query.= $dbh->quote($input->param('value')).",";
!       $query.= $dbh->quote($input->param('explanation')).")";
        my $sth=$dbh->prepare($query);
!       $sth->execute;
        $sth->finish;
  ################## DELETE_CONFIRM ##################################
--- 233,250 ----
  } elsif ($op eq 'add_validate') {
        my $dbh = C4::Context->dbh;
!       my $query="select * from systempreferences where variable=?";
        my $sth=$dbh->prepare($query);
!       $sth->execute($input->param('variable'));
!       if ($sth->rows) {
!               my $query = "update systempreferences set value=?,explanation=? 
where variable=?";
!               my $sth=$dbh->prepare($query);
!               $sth->execute($input->param('value'), 
$input->param('explanation'), $input->param('variable'));
!               $sth->finish;
!       } else {
!               my $query = "insert into systempreferences 
(variable,value,explanation) values (?,?,?)";
!               my $sth=$dbh->prepare($query);
!               $sth->execute($input->param('variable'), 
$input->param('value'), $input->param('explanation'));
!               $sth->finish;
!       }
        $sth->finish;
  ################## DELETE_CONFIRM ##################################




reply via email to

[Prev in Thread] Current Thread [Next in Thread]