- my $itype = $params{'itype'};
- my $ccode = $params{'ccode'};
- my $holdingbranch = $params{'holdingbranch'};
- my $location = $params{'location'};
-
- return unless ( $ci_id || $course_item );
-
- $course_item = GetCourseItem( ci_id => $ci_id )
- unless ($course_item);
- $ci_id = $course_item->{'ci_id'} unless ($ci_id);
-
- ## Revert fields that had an 'original' value, but now don't
- ## Update the item fields to the stored values from course_items
- ## and then set those fields in course_items to NULL
- my @fields_to_revert;
- foreach (@FIELDS) {
- if ( !$params{$_} && $course_item->{$_} ) {
- push( @fields_to_revert, $_ );
- }
- }
- _RevertFields(
- ci_id => $ci_id,
- fields => \@fields_to_revert,
- course_item => $course_item
- ) if (@fields_to_revert);
-
- ## Update fields that still have an original value, but it has changed
- ## This necessitates only changing the current item values, as we still
- ## have the original values stored in course_items
- my %mod_params;
- foreach (@FIELDS) {
- if ( $params{$_}
- && $course_item->{$_}
- && $params{$_} ne $course_item->{$_} ) {
- $mod_params{$_} = $params{$_};
- }
- }
- ModItem( \%mod_params, undef, $course_item->{'itemnumber'} ) if %mod_params;
-
- ## Update fields that didn't have an original value, but now do
- ## We must save the original value in course_items, and also
- ## update the item fields to the new value
- my $item = GetItem( $course_item->{'itemnumber'} );
- my %mod_params_new;
- my %mod_params_old;
- foreach (@FIELDS) {
- if ( $params{$_} && !$course_item->{$_} ) {
- $mod_params_new{$_} = $params{$_};
- $mod_params_old{$_} = $item->{$_};
- }
- }
- _ModStoredFields( 'ci_id' => $params{'ci_id'}, %mod_params_old );
- ModItem( \%mod_params_new, undef, $course_item->{'itemnumber'} ) if %mod_params_new;
-
-}
-
-=head2 _ModStoredFields
-
- _ModStoredFields( %params );
-
- Updates the values for the 'original' fields in course_items
- for a given ci_id