| Lines 41-47
          BEGIN {
      
      
        Link Here | 
        
          | 41 | 	@ISA    = qw(Exporter); | 41 | 	@ISA    = qw(Exporter); | 
        
          | 42 | 	@EXPORT = qw( | 42 | 	@EXPORT = qw( | 
        
          | 43 |         &GetPrinters &GetPrinter | 43 |         &GetPrinters &GetPrinter | 
          
            
              | 44 |         &GetItemTypes &getitemtypeinfo | 44 |         &getitemtypeinfo | 
        
          | 45 |         &GetItemTypesCategorized | 45 |         &GetItemTypesCategorized | 
        
          | 46 |         &getallthemes | 46 |         &getallthemes | 
        
          | 47 |         &getFacets | 47 |         &getFacets | 
  
    | Lines 87-176
          Koha.pm provides many functions for Koha scripts.
      
      
        Link Here | 
        
          | 87 |  | 87 |  | 
        
          | 88 | =cut | 88 | =cut | 
        
          | 89 |  | 89 |  | 
            
              | 90 | =head2 GetItemTypes |  |  | 
            
              | 91 |  | 
            
              | 92 |   $itemtypes = &GetItemTypes( style => $style ); | 
            
              | 93 |  | 
            
              | 94 | Returns information about existing itemtypes. | 
            
              | 95 |  | 
            
              | 96 | Params: | 
            
              | 97 |     style: either 'array' or 'hash', defaults to 'hash'. | 
            
              | 98 |            'array' returns an arrayref, | 
            
              | 99 |            'hash' return a hashref with the itemtype value as the key | 
            
              | 100 |  | 
            
              | 101 | build a HTML select with the following code : | 
            
              | 102 |  | 
            
              | 103 | =head3 in PERL SCRIPT | 
            
              | 104 |  | 
            
              | 105 |     my $itemtypes = GetItemTypes; | 
            
              | 106 |     my @itemtypesloop; | 
            
              | 107 |     foreach my $thisitemtype (sort keys %$itemtypes) { | 
            
              | 108 |         my $selected = 1 if $thisitemtype eq $itemtype; | 
            
              | 109 |         my %row =(value => $thisitemtype, | 
            
              | 110 |                     selected => $selected, | 
            
              | 111 |                     description => $itemtypes->{$thisitemtype}->{'description'}, | 
            
              | 112 |                 ); | 
            
              | 113 |         push @itemtypesloop, \%row; | 
            
              | 114 |     } | 
            
              | 115 |     $template->param(itemtypeloop => \@itemtypesloop); | 
            
              | 116 |  | 
            
              | 117 | =head3 in TEMPLATE | 
            
              | 118 |  | 
            
              | 119 |     <form action='<!-- TMPL_VAR name="script_name" -->' method=post> | 
            
              | 120 |         <select name="itemtype"> | 
            
              | 121 |             <option value="">Default</option> | 
            
              | 122 |         <!-- TMPL_LOOP name="itemtypeloop" --> | 
            
              | 123 |             <option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="description" --></option> | 
            
              | 124 |         <!-- /TMPL_LOOP --> | 
            
              | 125 |         </select> | 
            
              | 126 |         <input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->"> | 
            
              | 127 |         <input type="submit" value="OK" class="button"> | 
            
              | 128 |     </form> | 
            
              | 129 |  | 
            
              | 130 | =cut | 
            
              | 131 |  | 
            
              | 132 | sub GetItemTypes { | 
            
              | 133 |     my ( %params ) = @_; | 
            
              | 134 |     my $style = defined( $params{'style'} ) ? $params{'style'} : 'hash'; | 
            
              | 135 |  | 
            
              | 136 |     require C4::Languages; | 
            
              | 137 |     my $language = C4::Languages::getlanguage(); | 
            
              | 138 |     # returns a reference to a hash of references to itemtypes... | 
            
              | 139 |     my $dbh   = C4::Context->dbh; | 
            
              | 140 |     my $query = q| | 
            
              | 141 |         SELECT | 
            
              | 142 |                itemtypes.itemtype, | 
            
              | 143 |                itemtypes.description, | 
            
              | 144 |                itemtypes.rentalcharge, | 
            
              | 145 |                itemtypes.notforloan, | 
            
              | 146 |                itemtypes.imageurl, | 
            
              | 147 |                itemtypes.summary, | 
            
              | 148 |                itemtypes.checkinmsg, | 
            
              | 149 |                itemtypes.checkinmsgtype, | 
            
              | 150 |                itemtypes.sip_media_type, | 
            
              | 151 |                itemtypes.hideinopac, | 
            
              | 152 |                itemtypes.searchcategory, | 
            
              | 153 |                COALESCE( localization.translation, itemtypes.description ) AS translated_description | 
            
              | 154 |         FROM   itemtypes | 
            
              | 155 |         LEFT JOIN localization ON itemtypes.itemtype = localization.code | 
            
              | 156 |             AND localization.entity = 'itemtypes' | 
            
              | 157 |             AND localization.lang = ? | 
            
              | 158 |         ORDER BY itemtype | 
            
              | 159 |     |; | 
            
              | 160 |     my $sth = $dbh->prepare($query); | 
            
              | 161 |     $sth->execute( $language ); | 
            
              | 162 |  | 
            
              | 163 |     if ( $style eq 'hash' ) { | 
            
              | 164 |         my %itemtypes; | 
            
              | 165 |         while ( my $IT = $sth->fetchrow_hashref ) { | 
            
              | 166 |             $itemtypes{ $IT->{'itemtype'} } = $IT; | 
            
              | 167 |         } | 
            
              | 168 |         return ( \%itemtypes ); | 
            
              | 169 |     } else { | 
            
              | 170 |         return [ sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @{ $sth->fetchall_arrayref( {} ) } ]; | 
            
              | 171 |     } | 
            
              | 172 | } | 
            
              | 173 |  | 
        
          | 174 | =head2 GetItemTypesCategorized | 90 | =head2 GetItemTypesCategorized | 
        
          | 175 |  | 91 |  | 
        
          | 176 |     $categories = GetItemTypesCategorized(); | 92 |     $categories = GetItemTypesCategorized(); |