ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / admin / auth_subfields_structure.pl
index ffa74f2..866e5f7 100755 (executable)
@@ -25,6 +25,7 @@ use C4::Context;
 use C4::Koha;
 
 use Koha::Authority::Types;
+use Koha::AuthorisedValues;
 
 use List::MoreUtils qw( uniq );
 
@@ -51,7 +52,8 @@ my $input        = new CGI;
 my $tagfield     = $input->param('tagfield');
 my $tagsubfield  = $input->param('tagsubfield');
 my $authtypecode = $input->param('authtypecode');
-my $offset       = $input->param('offset') || 0;
+my $offset       = $input->param('offset');
+$offset = 0 if not defined $offset or $offset < 0;
 my $op           = $input->param('op') || '';
 my $script_name  = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
 
@@ -60,7 +62,7 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user(
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
-        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
+        flagsrequired   => { parameters => 'manage_marc_frameworks' },
         debug           => 1,
     }
 );
@@ -92,11 +94,11 @@ if ($op eq 'add_form') {
                push @kohafields, "auth_header.".$field;
        }
        
-        # build authorised value list
-        my $authorised_values = C4::Koha::GetAuthorisedValueCategories;
-        unshift @$authorised_values, '';
-        push @$authorised_values, 'branches';
-        push @$authorised_values, 'itemtypes';
+        # build authorised value category list
+        my @authorised_value_categories = Koha::AuthorisedValues->new->categories;
+        unshift @authorised_value_categories, '';
+        push @authorised_value_categories, 'branches';
+        push @authorised_value_categories, 'itemtypes';
 
         # build thesaurus categories list
         my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search );
@@ -138,7 +140,7 @@ if ($op eq 'add_form') {
         $row_data{seealso}           = $data->{'seealso'};
         $row_data{kohafields}        = \@kohafields;
         $row_data{kohafield}         = $data->{'kohafield'};
-        $row_data{authorised_values} = $authorised_values;
+        $row_data{authorised_values} = \@authorised_value_categories;
         $row_data{authorised_value}  = $data->{'authorised_value'};
         $row_data{frameworkcodes}    = \@authtypes;
         $row_data{frameworkcode}     = $data->{'frameworkcode'};
@@ -167,7 +169,7 @@ if ($op eq 'add_form') {
     $row_data{mandatory}        = 0;
     $row_data{isurl}            = 0;
     $row_data{kohafields} = \@kohafields,
-    $row_data{authorised_values} = $authorised_values;
+    $row_data{authorised_values} = \@authorised_value_categories;
     $row_data{frameworkcodes} = \@authtypes;
     $row_data{value_builders} = \@value_builder;
     $row_data{row} = $i;
@@ -199,7 +201,7 @@ if ($op eq 'add_form') {
        my @tab                         = $input->multi_param('tab');
        my @seealso             = $input->multi_param('seealso');
     my @ohidden             = $input->multi_param('ohidden');
-       my @authorised_values   = $input->multi_param('authorised_value');
+    my @authorised_value_categories = $input->multi_param('authorised_value');
        my $authtypecode        = $input->param('authtypecode');
        my @frameworkcodes      = $input->multi_param('frameworkcode');
        my @value_builder       =$input->multi_param('value_builder');
@@ -215,14 +217,13 @@ if ($op eq 'add_form') {
                my $kohafield           =$kohafield[$i];
                my $tab                         =$tab[$i];
                my $seealso                             =$seealso[$i];
-               my $authorised_value            =$authorised_values[$i];
+        my $authorised_value = $authorised_value_categories[$i];
                my $frameworkcode               =$frameworkcodes[$i];
                my $value_builder=$value_builder[$i];
         my $defaultvalue = $defaultvalue[$i];
                my $hidden = $ohidden[$i]; #collate from 3 hiddens;
                my $isurl = $input->param("isurl$i")?1:0;
                if ($liblibrarian) {
-                       unless (C4::Context->config('demo') or C4::Context->config('demo') eq 1) {
                                if (auth_subfield_structure_exists($authtypecode, $tagfield, $tagsubfield)) {
                                        $sth_update->execute(
                                                $authtypecode,
@@ -267,7 +268,6 @@ if ($op eq 'add_form') {
                         $defaultvalue,
                                        );
                                }
-                       }
                }
        }
     print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&amp;authtypecode=$authtypecode");
@@ -291,10 +291,8 @@ if ($op eq 'add_form') {
 ################## DELETE_CONFIRMED ##################################
 # called by delete_confirm, used to effectively confirm deletion of data in DB
 } elsif ($op eq 'delete_confirmed') {
-       unless (C4::Context->config('demo') or C4::Context->config('demo') eq 1) {
-               my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
-               $sth->execute($tagfield,$tagsubfield,$authtypecode);
-       }
+    my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
+    $sth->execute($tagfield,$tagsubfield,$authtypecode);
     print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&amp;authtypecode=$authtypecode");
     exit;
                                                                                                        # END $OP eq DELETE_CONFIRMED
@@ -317,7 +315,6 @@ if ($op eq 'add_form') {
                $row_data{value_builder}        = $results->[$i]{'value_builder'};
                $row_data{hidden}       = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
                $row_data{isurl}        = $results->[$i]{'isurl'};
-               $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&amp;authtypecode=$authtypecode";
                if ($row_data{tab} eq -1) {
                        $row_data{subfield_ignored} = 1;
                }