@@ -, +, @@ This patch adds the following permissions: - editcatalogue.limited_item_edition: Limit item modification to barcode, status and note - editcatalogue.delete_all_items: Delete all items at once - tools.items_limited_batchmod: Limit batch item modification to item status --- cataloguing/additem.pl | 40 ++++++++++++++++---- .../data/mysql/en/mandatory/userpermissions.sql | 3 ++ installer/data/mysql/updatedatabase.pl | 19 ++++++++++ .../intranet-tmpl/prog/en/includes/cat-toolbar.inc | 2 +- .../prog/en/modules/cataloguing/additem.tt | 9 ++++- tools/batchMod.pl | 7 ++++ 6 files changed, 71 insertions(+), 9 deletions(-) --- a/cataloguing/additem.pl +++ a/cataloguing/additem.pl @@ -35,7 +35,7 @@ use List::MoreUtils qw/any/; use C4::Search; use Storable qw(thaw freeze); use URI::Escape; - +use C4::Members; use MARC::File::XML; use URI::Escape; @@ -103,9 +103,13 @@ sub _increment_barcode { sub generate_subfield_form { - my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $today_iso, $biblionumber, $temp, $loop_data, $i) = @_; + my ($tag, $subfieldtag, $value, $tagslib,$subfieldlib, $branches, $today_iso, $biblionumber, $temp, $loop_data, $i, $limitededition) = @_; - my $frameworkcode = &GetFrameworkCode($biblionumber); + my $frameworkcode = &GetFrameworkCode($biblionumber); + my ($barcodefield, $barcodesubfield) = GetMarcFromKohaField("items.barcode", $frameworkcode); + my ($notesfield, $notessubfield) = GetMarcFromKohaField("items.itemnotes", $frameworkcode); + my ($notforloanfield, $notforloansubfield) = GetMarcFromKohaField("items.notforloan", $frameworkcode); + my %subfield_data; my $dbh = C4::Context->dbh; my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib"); @@ -155,6 +159,14 @@ sub generate_subfield_form { $value = $input->param('barcode'); } my $attributes_no_value = qq(tabindex="1" id="$subfield_data{id}" name="field_value" class="input_marceditor" size="67" maxlength="$subfield_data{maxlength}" ); + $attributes_no_value .= 'readonly="readonly" ' + if ( + $limitededition + and $subfieldtag ne $barcodesubfield + and $subfieldtag ne $notessubfield + and $subfieldtag ne $notforloansubfield + ); + my $attributes = qq($attributes_no_value value="$value" ); if ( $subfieldlib->{authorised_value} ) { @@ -215,7 +227,7 @@ sub generate_subfield_form { $subfield_data{marc_value} = qq( $authorised_lib{$value}); } else { - $subfield_data{marc_value} =CGI::scrolling_list( # FIXME: factor out scrolling_list + my @scrparam = ( -name => "field_value", -values => \@authorised_values, -default => $value, @@ -227,6 +239,15 @@ sub generate_subfield_form { -id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, -class => "input_marceditor", ); + + push @scrparam, (-readonly => "readonly"), (-disabled => "disabled") + if ( + $limitededition + and $subfieldtag ne $barcodesubfield + and $subfieldtag ne $notessubfield + and $subfieldtag ne $notforloansubfield + ); + $subfield_data{marc_value} =CGI::scrolling_list(@scrparam); } } @@ -338,6 +359,12 @@ my ($template, $loggedinuser, $cookie) }); +# Does the user have a limited item edition permission? +my $uid = GetMember( borrowernumber => $loggedinuser )->{userid} if ($loggedinuser) ; +my $limitededition = haspermission($uid, {'editcatalogue' => 'limited_item_edition'}) if ($uid); +# In case user is a superlibrarian, edition is not limited +$limitededition = 0 if ($limitededition != 0 && $limitededition->{'superlibrarian'} eq 1); + my $today_iso = C4::Dates->today('iso'); my $tagslib = &GetMarcStructure(1,$frameworkcode); my $record = GetMarcBiblio($biblionumber); @@ -762,8 +789,7 @@ if($itemrecord){ next if subfield_is_koha_internal_p($subfieldtag); next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10"); - my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i); - + my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $limitededition); push @fields, "$tag$subfieldtag"; push (@loop_data, $subfield_data); $i++; @@ -787,7 +813,7 @@ foreach my $tag ( keys %{$tagslib}){ my @values = (undef); @values = $itemrecord->field($tag)->subfield($subtag) if ($itemrecord && defined($itemrecord->field($tag)->subfield($subtag))); for my $value (@values){ - my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i); + my $subfield_data = generate_subfield_form($tag, $subtag, $value, $tagslib, $tagslib->{$tag}->{$subtag}, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i, $limitededition); push (@loop_data, $subfield_data); $i++; } --- a/installer/data/mysql/en/mandatory/userpermissions.sql +++ a/installer/data/mysql/en/mandatory/userpermissions.sql @@ -8,6 +8,8 @@ INSERT INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_catalogue', 'Edit catalog (Modify bibliographic/holdings data)'), ( 9, 'fast_cataloging', 'Fast cataloging'), ( 9, 'edit_items', 'Edit Items'), + ( 9, 'limited_item_edition', 'Limit item modification to barcode, status and note (please note that edit_item is still required)'), + ( 9, 'delete_all_items', 'Delete all items'), (11, 'vendors_manage', 'Manage vendors'), (11, 'contracts_manage', 'Manage contracts'), (11, 'period_manage', 'Manage periods'), @@ -37,6 +39,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'), (13, 'schedule_tasks', 'Schedule tasks to run'), (13, 'items_batchmod', 'Perform batch modification of items'), + (13, 'items_limited_batchmod', 'Limit batch item modification to item status (please note that items_batchmod is still required)'), (13, 'items_batchdel', 'Perform batch deletion of items'), (13, 'manage_csv_profiles', 'Manage CSV export profiles'), (13, 'moderate_tags', 'Moderate patron tags'), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -6019,6 +6019,25 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + INSERT INTO permissions (module_bit, code, description) VALUES ('9', 'limited_item_edition', 'Limit item modification to barcode, status and note (please note that edit_item is still required)'); + }); + + $dbh->do(qq{ + INSERT INTO permissions (module_bit, code, description) VALUES ('9', 'delete_all_items', 'Delete all items at once'); + }); + + $dbh->do(qq{ + INSERT INTO permissions (module_bit, code, description) VALUES ('13', 'items_limited_batchmod', 'Limit batch item modification to item status (please note that items_batchmod is still required)'); + }); + + print "Upgrade to $DBversion done (Adds new permissions for cataloguing and batch item modification)\n"; + + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -118,7 +118,7 @@ function confirm_items_deletion() { [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Edit as new (duplicate)"), url: "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% biblionumber %]&frameworkcode=&op=duplicate" },[% END %] [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Replace record via Z39.50"), onclick: {fn: PopupZ3950 } },[% END %] [% IF ( CAN_user_editcatalogue_edit_catalogue ) %]{ text: _("Delete record"), onclick: {fn: confirm_deletion }[% IF ( count ) %],id:'disabled'[% END %] },[% END %] - [% IF ( CAN_user_editcatalogue_edit_items ) %]{ text: _("Delete all items"), onclick: {fn: confirm_items_deletion }[% UNLESS ( count ) %],id:'disabled'[% END %] }[% END %] + [% IF ( CAN_user_editcatalogue_delete_all_items ) %]{ text: _("Delete all items"), onclick: {fn: confirm_items_deletion }[% UNLESS ( count ) %],id:'disabled'[% END %] }[% END %] ]; if(editmenu.length){ new YAHOO.widget.Button({ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -52,6 +52,13 @@ function Check(f) { var alertString2; if (total_errors==0) { + // Explanation about this line: + // In case of limited edition permission, we have to prevent user from modifying some fields. + // But there is no such thing as readonly attribute for select elements. + // So we use disabled instead. But disabled prevent values from being passed through the form at submit. + // So we "un-disable" the elements just before submitting. + // That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that. + $("select[name=field_value]").removeAttr("disabled"); return true; } else { alertString2 = _("Form not submitted because of the following problem(s)"); @@ -222,7 +229,7 @@ $(document).ready(function() {
-
+ [% IF (popup) %] --- a/tools/batchMod.pl +++ a/tools/batchMod.pl @@ -33,6 +33,7 @@ use C4::BackgroundJob; use C4::ClassSource; use C4::Dates; use C4::Debug; +use C4::Members; use MARC::File::XML; my $input = new CGI; @@ -68,6 +69,11 @@ my ($template, $loggedinuser, $cookie) flagsrequired => $template_flag, }); +# Does the user have a limited item edition permission? +my $uid = GetMember( borrowernumber => $loggedinuser )->{userid} if ($loggedinuser) ; +my $limitededition = haspermission($uid, {'tools' => 'items_limited_batchmod'}) if ($uid); +# In case user is a superlibrarian, edition is not limited +$limitededition = 0 if ($limitededition != 0 && $limitededition->{'superlibrarian'} eq 1); my $today_iso = C4::Dates->today('iso'); $template->param(today_iso => $today_iso); @@ -281,6 +287,7 @@ foreach my $tag (sort keys %{$tagslib}) { # loop through each subfield foreach my $subfield (sort keys %{$tagslib->{$tag}}) { next if subfield_is_koha_internal_p($subfield); + next if ($limitededition && $tagslib->{$tag}->{$subfield}->{'kohafield'} ne 'items.notforloan'); next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); # barcode and stocknumber are not meant to be batch-modified next if $tagslib->{$tag}->{$subfield}->{'kohafield'} eq 'items.barcode'; --