Fix typo in patch for bug 7849
[koha.git] / admin / patron-attr-types.pl
index 188b040..638456e 100755 (executable)
@@ -1,6 +1,7 @@
 #! /usr/bin/perl
 #
 # Copyright 2008 LibLime
+# Parts copyright 2010 BibLibre
 #
 # This file is part of Koha.
 #
 use strict;
 use warnings;
 use CGI;
+use List::MoreUtils qw/uniq/;
+
 use C4::Auth;
 use C4::Context;
 use C4::Output;
 use C4::Koha;
+use C4::Members qw/GetBorrowercategoryList/;
 use C4::Members::AttributeTypes;
 
 my $script_name = "/cgi-bin/koha/admin/patron-attr-types.pl";
 
-my $input = new CGI;
+our $input = new CGI;
 my $op = $input->param('op') || '';
 
 
-my ($template, $loggedinuser, $cookie)
+our ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "admin/patron-attr-types.tmpl",
                  query => $input,
                  type => "intranet",
@@ -81,8 +85,10 @@ sub add_attribute_type_form {
     $template->param(
         attribute_type_form => 1,
         confirm_op => 'add_attribute_type_confirmed',
+        categories => GetBorrowercategoryList,
     );
     authorised_value_category_list($template);
+    pa_classes($template);
 }
 
 sub error_add_attribute_type_form {
@@ -91,21 +97,27 @@ sub error_add_attribute_type_form {
     $template->param(description => $input->param('description'));
 
     if ($input->param('repeatable')) {
-        $template->param(repeatable_checked => 'checked="checked"');
+        $template->param(repeatable_checked => 1);
     }
     if ($input->param('unique_id')) {
-        $template->param(unique_id_checked => 'checked="checked"');
+        $template->param(unique_id_checked => 1);
     }
     if ($input->param('password_allowed')) {
-        $template->param(password_allowed_checked => 'checked="checked"');
+        $template->param(password_allowed_checked => 1);
     }
     if ($input->param('opac_display')) {
-        $template->param(opac_display_checked => 'checked="checked"');
+        $template->param(opac_display_checked => 1);
     }
     if ($input->param('staff_searchable')) {
-        $template->param(staff_searchable_checked => 'checked="checked"');
+        $template->param(staff_searchable_checked => 1);
+    }
+    if ($input->param('display_checkout')) {
+        $template->param(display_checkout_checked => 'checked="checked"');
     }
 
+    $template->param( category_code => $input->param('category_code') );
+    $template->param( class => $input->param('class') );
+
     $template->param(
         attribute_type_form => 1,
         confirm_op => 'add_attribute_type_confirmed',
@@ -146,6 +158,10 @@ sub add_update_attribute_type {
     $attr_type->authorised_value_category($authorised_value_category);
     my $password_allowed = $input->param('password_allowed');
     $attr_type->password_allowed($password_allowed);
+    my $display_checkout = $input->param('display_checkout');
+    $attr_type->display_checkout($display_checkout);
+    $attr_type->category_code($input->param('category_code'));
+    $attr_type->class($input->param('class'));
 
     if ($op eq 'edit') {
         $template->param(edited_attribute_type => $attr_type->code());
@@ -203,40 +219,64 @@ sub edit_attribute_type_form {
 
     $template->param(code => $code);
     $template->param(description => $attr_type->description());
+    $template->param(class => $attr_type->class());
 
     if ($attr_type->repeatable()) {
-        $template->param(repeatable_checked => 'checked="checked"');
+        $template->param(repeatable_checked => 1);
     }
-    $template->param(repeatable_disabled => 'disabled="disabled"');
+    $template->param(repeatable_disabled => 1);
     if ($attr_type->unique_id()) {
-        $template->param(unique_id_checked => 'checked="checked"');
+        $template->param(unique_id_checked => 1);
     }
-    $template->param(unique_id_disabled => 'disabled="disabled"');
+    $template->param(unique_id_disabled => 1);
     if ($attr_type->password_allowed()) {
-        $template->param(password_allowed_checked => 'checked="checked"');
+        $template->param(password_allowed_checked => 1);
     }
     if ($attr_type->opac_display()) {
-        $template->param(opac_display_checked => 'checked="checked"');
+        $template->param(opac_display_checked => 1);
     }
     if ($attr_type->staff_searchable()) {
-        $template->param(staff_searchable_checked => 'checked="checked"');
+        $template->param(staff_searchable_checked => 1);
+    }
+    if ($attr_type->display_checkout()) {
+        $template->param(display_checkout_checked => 'checked="checked"');
     }
-
     authorised_value_category_list($template, $attr_type->authorised_value_category());
+    pa_classes( $template, $attr_type->class );
+
+    $template->param ( category_code => $attr_type->category_code );
+    $template->param ( category_description => $attr_type->category_description );
 
     $template->param(
         attribute_type_form => 1,
         edit_attribute_type => 1,
         confirm_op => 'edit_attribute_type_confirmed',
+        categories => GetBorrowercategoryList,
     );
 
 }
 
 sub patron_attribute_type_list {
     my $template = shift;
-    
+
     my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes();
-    $template->param(available_attribute_types => \@attr_types);
+    my @classes = uniq( map {$_->{class}} @attr_types );
+    @classes = sort @classes;
+
+    my @attributes_loop;
+    for my $class (@classes) {
+        my @items;
+        for my $attr (@attr_types) {
+            push @items, $attr if $attr->{class} eq $class
+        }
+        my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
+        push @attributes_loop, {
+            class => $class,
+            items => \@items,
+            lib   => $lib,
+        };
+    }
+    $template->param(available_attribute_types => \@attributes_loop);
     $template->param(display_list => 1);
 }
 
@@ -253,3 +293,10 @@ sub authorised_value_category_list {
     }
     $template->param(authorised_value_categories => \@list);
 }
+
+sub pa_classes {
+    my $template = shift;
+    my $selected = @_ ? shift : '';
+
+    $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS', $selected ) );
+}