Bug 8379 don't close dbh
[koha.git] / admin / auth_tag_structure.pl
index 6314c0a..906f8d3 100755 (executable)
@@ -39,7 +39,7 @@ my $offset      = $input->param('offset') || 0;
 my $op          = $input->param('op')     || '';
 $searchfield =~ s/\,//g;
 
-my $pagesize    = 20;
+
 my $script_name = "/cgi-bin/koha/admin/auth_tag_structure.pl";
 
 my $dbh = C4::Context->dbh;
@@ -50,20 +50,19 @@ my ($template, $loggedinuser, $cookie)
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
-                            flagsrequired => {parameters => 1},
+                 flagsrequired => {parameters => 'parameters_remaining_permissions'},
                             debug => 1,
                             });
 
 # get authtype list
-my $authtypes = getauthtypes;
-my @authtypesloop;
-foreach my $thisauthtype (keys %$authtypes) {
-       my $selected = 1 if $thisauthtype eq $authtypecode;
-       my %row =(value => $thisauthtype,
-                               selected => $selected,
-                               authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
-                       );
-       push @authtypesloop, \%row;
+my $authtypes     = getauthtypes;
+my @authtypesloop = ();
+foreach my $thisauthtype ( keys %{$authtypes} ) {
+    push @authtypesloop,
+      { value        => $thisauthtype,
+        selected     => $thisauthtype eq $authtypecode,
+        authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
+      };
 }
 
 my $sth;
@@ -120,13 +119,13 @@ if ($op eq 'add_form') {
        if ($searchfield) {
                $template->param(action => "Modify tag",
                                                                searchfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" />$searchfield");
-               $template->param('heading-modify-tag-p' => 1);
+               $template->param('heading_modify_tag_p' => 1);
        } else {
                $template->param(action => "Add tag",
                                                                searchfield => "<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
-               $template->param('heading-add-tag-p' => 1);
+               $template->param('heading_add_tag_p' => 1);
        }
-       $template->param('use-heading-flags-p' => 1);
+       $template->param('use_heading_flags_p' => 1);
        $template->param(liblibrarian => $data->{'liblibrarian'},
                                                        libopac => $data->{'libopac'},
                                                        repeatable => "".$data->{'repeatable'},
@@ -188,9 +187,10 @@ if ($op eq 'add_form') {
 # called by delete_confirm, used to effectively confirm deletion of data in DB
 } elsif ($op eq 'delete_confirmed') {
        unless (C4::Context->config('demo') eq 1) {
-               $dbh->do("delete from auth_tag_structure where tagfield='$searchfield' and authtypecode='$authtypecode'");
-               $dbh->do("delete from auth_subfield_structure where tagfield='$searchfield' and authtypecode='$authtypecode'");
-        # FIXME: Secuity vulnerability -- use placeholders, prepare and execute!
+               my $sth = $dbh->prepare("delete from auth_tag_structure where tagfield=? and authtypecode=?");
+               $sth->execute($searchfield,$authtypecode);
+               my $sth = $dbh->prepare("delete from auth_subfield_structure where tagfield=? and authtypecode=?");
+               $sth->execute($searchfield,$authtypecode);
        }
     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_tag_structure.pl?searchfield=".$input->param('tagfield')."&authtypecode=$authtypecode\">";
     exit;
@@ -221,7 +221,7 @@ if ($op eq 'add_form') {
        }
        my ($count,$results)=StringSearch($searchfield,$authtypecode);
        my @loop_data = ();
-       for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+    for ( my $i = $offset ; $i < $count ; $i++ ) {
                my %row_data;  # get a fresh hash for the row data
         $row_data{tagfield}         = $results->[$i]{'tagfield'};
         $row_data{liblibrarian}     = $results->[$i]{'liblibrarian'};
@@ -237,15 +237,12 @@ if ($op eq 'add_form') {
                                        authtypecode => $authtypecode,
        );
        if ($offset>0) {
-               my $prevpage = $offset-$pagesize;
                $template->param(isprevpage => $offset,
-                                               prevpage=> $prevpage,
                                                searchfield => $searchfield,
                 );
        }
-       if ($offset+$pagesize<$count) {
-               my $nextpage =$offset+$pagesize;
-               $template->param(nextpage =>$nextpage,
+    if ( $offset < $count ) {
+               $template->param(
                                                searchfield => $searchfield,
                );
        }