Bug 20912: Rental Fees based on Time Period
[koha.git] / admin / authorised_values.pl
index f812038..4f95129 100755 (executable)
@@ -40,7 +40,7 @@ my @messages;
 our ($template, $borrowernumber, $cookie)= get_template_and_user({
     template_name => "admin/authorised_values.tt",
     authnotrequired => 0,
-    flagsrequired => {parameters => 'parameters_remaining_permissions'},
+    flagsrequired => {parameters => 'manage_auth_values'},
     query => $input,
     type => "intranet",
     debug => 1,
@@ -119,8 +119,8 @@ if ($op eq 'add_form') {
     elsif ( $id ) { # Update
         my $av = Koha::AuthorisedValues->new->find( $id );
 
-        $av->lib( $input->param('lib') || undef );
-        $av->lib_opac( $input->param('lib_opac') || undef );
+        $av->lib( scalar $input->param('lib') || undef );
+        $av->lib_opac( scalar $input->param('lib_opac') || undef );
         $av->category( $new_category );
         $av->authorised_value( $new_authorised_value );
         $av->imageurl( $imageurl );
@@ -167,7 +167,11 @@ if ($op eq 'add_form') {
     );
 
     if ( $already_exists ) {
-        push @messages, {type => 'error', code => 'cat_already_exists' };
+        if ( $new_category eq 'branches' or $new_category eq 'itemtypes' or $new_category eq 'cn_source' ) {
+            push @messages, {type => 'error', code => 'invalid_category_name' };
+        } else {
+            push @messages, {type => 'error', code => 'cat_already_exists' };
+        }
     }
     else { # Insert
         my $av = Koha::AuthorisedValueCategory->new( {
@@ -182,13 +186,13 @@ if ($op eq 'add_form') {
             push @messages, {type => 'error', code => 'error_on_insert_cat' };
         } else {
             push @messages, { type => 'message', code => 'success_on_insert_cat' };
+            $searchfield = $new_category;
         }
     }
 
     $op = 'list';
-    $searchfield = $new_category;
 } elsif ($op eq 'delete') {
-    my $av = Koha::AuthorisedValues->new->find( $input->param('id') );
+    my $av = Koha::AuthorisedValues->new->find( $id );
     my $deleted = eval {$av->delete};
     if ( $@ or not $deleted ) {
         push @messages, {type => 'error', code => 'error_on_delete' };
@@ -208,7 +212,7 @@ $template->param(
 
 if ( $op eq 'list' ) {
     # build categories list
-    my @categories = Koha::AuthorisedValueCategories->search({}, { order_by => ['category_name'] } );
+    my @categories = Koha::AuthorisedValueCategories->search({ category_name => { -not_in => ['', 'branches', 'itemtypes', 'cn_source']}}, { order_by => ['category_name'] } );
     my @category_list;
     for my $category ( @categories ) {
         push( @category_list, $category->category_name );