Bug 10550: Fix database typo wthdrawn
[koha.git] / C4 / Items.pm
index e173dc2..4a98712 100644 (file)
@@ -463,7 +463,7 @@ my %default_values_for_mod_from_marc = (
     stack                => undef, 
     stocknumber          => undef, 
     uri                  => undef, 
-    wthdrawn             => 0,
+    withdrawn             => 0,
 );
 
 sub ModItemFromMarc {
@@ -751,12 +751,16 @@ Create a status selector with the following code
 
 =head3 in TEMPLATE
 
- <select name="statusloop">
-     <option value="">Default</option>
- <!-- TMPL_LOOP name="statusloop" -->
-     <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
- <!-- /TMPL_LOOP -->
- </select>
+<select name="statusloop" id="statusloop">
+    <option value="">Default</option>
+    [% FOREACH statusloo IN statusloop %]
+        [% IF ( statusloo.selected ) %]
+            <option value="[% statusloo.value %]" selected="selected">[% statusloo.statusname %]</option>
+        [% ELSE %]
+            <option value="[% statusloo.value %]">[% statusloo.statusname %]</option>
+        [% END %]
+    [% END %]
+</select>
 
 =cut
 
@@ -1136,7 +1140,7 @@ sub GetItemsByBiblioitemnumber {
             $data->{'borrowernumber'}   = $data2->{'borrowernumber'};
         }
         else {
-            # set date_due to blank, so in the template we check itemlost, and wthdrawn 
+            # set date_due to blank, so in the template we check itemlost, and withdrawn
             $data->{'date_due'} = '';                                                                                                         
         }    # else         
         # Find the last 3 people who borrowed this item.                  
@@ -1253,7 +1257,7 @@ sub GetItemsInfo {
             $data->{firstname}     = $idata->{firstname};
             $data->{lastreneweddate} = $idata->{lastreneweddate};
             $datedue                = $idata->{'date_due'};
-        if (C4::Context->preference("IndependantBranches")){
+        if (C4::Context->preference("IndependentBranches")){
         my $userenv = C4::Context->userenv;
         if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) { 
             $data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne $userenv->{branch});
@@ -1284,8 +1288,8 @@ sub GetItemsInfo {
 
         # get restricted status and description if applicable
         if ( my $code = C4::Koha::GetAuthValCode( 'items.restricted', $data->{frameworkcode} ) ) {
-            $data->{restricted}     = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted} );
             $data->{restrictedopac} = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted}, 1 );
+            $data->{restricted}     = C4::Koha::GetKohaAuthorisedValueLib( $code, $data->{restricted} );
         }
 
         # my stack procedures
@@ -1939,7 +1943,7 @@ Given an item hashref containing one or more
 columns to modify, fix up certain values.
 Specifically, set to 0 any passed value
 of C<notforloan>, C<damaged>, C<itemlost>, or
-C<wthdrawn> that is either undefined or
+C<withdrawn> that is either undefined or
 contains the empty string.
 
 =cut
@@ -1959,9 +1963,9 @@ sub _do_column_fixes_for_mod {
         (not defined $item->{'itemlost'} or $item->{'itemlost'} eq '')) {
         $item->{'itemlost'} = 0;
     }
-    if (exists $item->{'wthdrawn'} and
-        (not defined $item->{'wthdrawn'} or $item->{'wthdrawn'} eq '')) {
-        $item->{'wthdrawn'} = 0;
+    if (exists $item->{'withdrawn'} and
+        (not defined $item->{'withdrawn'} or $item->{'withdrawn'} eq '')) {
+        $item->{'withdrawn'} = 0;
     }
     if (exists $item->{'location'} && !exists $item->{'permanent_location'}) {
         $item->{'permanent_location'} = $item->{'location'};
@@ -2035,7 +2039,7 @@ C<items.itemlost>
 
 =item *
 
-C<items.wthdrawn>
+C<items.withdrawn>
 
 =back
 
@@ -2044,7 +2048,7 @@ C<items.wthdrawn>
 sub _set_defaults_for_add {
     my $item = shift;
     $item->{dateaccessioned} ||= C4::Dates->new->output('iso');
-    $item->{$_} ||= 0 for (qw( notforloan damaged itemlost wthdrawn));
+    $item->{$_} ||= 0 for (qw( notforloan damaged itemlost withdrawn));
 }
 
 =head2 _koha_new_item
@@ -2076,7 +2080,7 @@ sub _koha_new_item {
             notforloan          = ?,
             damaged             = ?,
             itemlost            = ?,
-            wthdrawn            = ?,
+            withdrawn            = ?,
             itemcallnumber      = ?,
             coded_location_qualifier = ?,
             restricted          = ?,
@@ -2118,7 +2122,7 @@ sub _koha_new_item {
             $item->{'notforloan'},
             $item->{'damaged'},
             $item->{'itemlost'},
-            $item->{'wthdrawn'},
+            $item->{'withdrawn'},
             $item->{'itemcallnumber'},
             $item->{'coded_location_qualifier'},
             $item->{'restricted'},
@@ -2213,10 +2217,9 @@ sub DelItemCheck {
     if ($onloan){
         $error = "book_on_loan" 
     }
-    elsif ( !(C4::Context->userenv->{flags} & 1) and
-            C4::Context->preference("IndependantBranches") and
-           (C4::Context->userenv->{branch} ne
-             $item->{C4::Context->preference("HomeOrHoldingBranch")||'homebranch'}) )
+    elsif ( !( C4::Context->userenv->{flags} & 1 )
+        and C4::Context->preference("IndependentBranches")
+        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
     {
         $error = "not_same_branch";
     }
@@ -2254,6 +2257,7 @@ sub _koha_modify_item {
     my $query = "UPDATE items SET ";
     my @bind;
     for my $key ( keys %$item ) {
+        next if ( $key eq 'itemnumber' );
         $query.="$key=?,";
         push @bind, $item->{$key};
     }
@@ -2689,7 +2693,7 @@ sub PrepareItemrecordDisplay {
                     # builds list, depending on authorised value...
                     #---- branch
                     if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
-                        if (   ( C4::Context->preference("IndependantBranches") )
+                        if (   ( C4::Context->preference("IndependentBranches") )
                             && ( C4::Context->userenv->{flags} % 2 != 1 ) ) {
                             my $sth = $dbh->prepare( "SELECT branchcode,branchname FROM branches WHERE branchcode = ? ORDER BY branchname" );
                             $sth->execute( C4::Context->userenv->{branch} );
@@ -2709,7 +2713,11 @@ sub PrepareItemrecordDisplay {
                                 $authorised_lib{$branchcode} = $branchname;
                             }
                         }
-                        $defaultvalue = $defaultvalues->{branchcode} || C4::Context->userenv->{branch};
+
+                        $defaultvalue = C4::Context->userenv->{branch};
+                        if ( $defaultvalues and $defaultvalues->{branchcode} ) {
+                            $defaultvalue = $defaultvalues->{branchcode};
+                        }
 
                         #----- itemtypes
                     } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {