View | Details | Raw Unified | Return to bug 18278
Collapse All | Expand All

(-)a/C4/Items.pm (-87 lines)
Lines 67-73 BEGIN { Link Here
67
    
67
    
68
        CheckItemPreSave
68
        CheckItemPreSave
69
    
69
    
70
        GetItemLocation
71
        GetLostItems
70
        GetLostItems
72
        GetItemsForInventory
71
        GetItemsForInventory
73
        GetItemsCount
72
        GetItemsCount
Lines 779-869 has copy-and-paste work. Link Here
779
778
780
=cut
779
=cut
781
780
782
=head2 GetItemLocation
783
784
  $itemlochash = GetItemLocation($fwk);
785
786
Returns a list of valid values for the
787
C<items.location> field.
788
789
NOTE: does B<not> return an individual item's
790
location.
791
792
where fwk stands for an optional framework code.
793
Create a location selector with the following code
794
795
=head3 in PERL SCRIPT
796
797
  my $itemlochash = getitemlocation;
798
  my @itemlocloop;
799
  foreach my $thisloc (keys %$itemlochash) {
800
      my $selected = 1 if $thisbranch eq $branch;
801
      my %row =(locval => $thisloc,
802
                  selected => $selected,
803
                  locname => $itemlochash->{$thisloc},
804
               );
805
      push @itemlocloop, \%row;
806
  }
807
  $template->param(itemlocationloop => \@itemlocloop);
808
809
=head3 in TEMPLATE
810
811
  <select name="location">
812
      <option value="">Default</option>
813
  <!-- TMPL_LOOP name="itemlocationloop" -->
814
      <option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
815
  <!-- /TMPL_LOOP -->
816
  </select>
817
818
=cut
819
820
sub GetItemLocation {
821
822
    # returns a reference to a hash of references to location...
823
    my ($fwk) = @_;
824
    my %itemlocation;
825
    my $dbh = C4::Context->dbh;
826
    my $sth;
827
    $fwk = '' unless ($fwk);
828
    my ( $tag, $subfield ) =
829
      GetMarcFromKohaField( "items.location", $fwk );
830
    if ( $tag and $subfield ) {
831
        my $sth =
832
          $dbh->prepare(
833
            "SELECT authorised_value
834
            FROM marc_subfield_structure 
835
            WHERE tagfield=? 
836
                AND tagsubfield=? 
837
                AND frameworkcode=?"
838
          );
839
        $sth->execute( $tag, $subfield, $fwk );
840
        if ( my ($authorisedvaluecat) = $sth->fetchrow ) {
841
            my $authvalsth =
842
              $dbh->prepare(
843
                "SELECT authorised_value,lib
844
                FROM authorised_values
845
                WHERE category=?
846
                ORDER BY lib"
847
              );
848
            $authvalsth->execute($authorisedvaluecat);
849
            while ( my ( $authorisedvalue, $lib ) = $authvalsth->fetchrow ) {
850
                $itemlocation{$authorisedvalue} = $lib;
851
            }
852
            return \%itemlocation;
853
        }
854
        else {
855
856
            #No authvalue list
857
            # build default
858
        }
859
    }
860
861
    #No authvalue list
862
    #build default
863
    $itemlocation{"1"} = "Not For Loan";
864
    return \%itemlocation;
865
}
866
867
=head2 GetLostItems
781
=head2 GetLostItems
868
782
869
  $items = GetLostItems( $where );
783
  $items = GetLostItems( $where );
870
- 

Return to bug 18278