Lines 26-31
use strict;
Link Here
|
26 |
use C4::Context; |
26 |
use C4::Context; |
27 |
use C4::Branch qw(GetBranchesCount); |
27 |
use C4::Branch qw(GetBranchesCount); |
28 |
use Koha::DateUtils qw(dt_from_string); |
28 |
use Koha::DateUtils qw(dt_from_string); |
|
|
29 |
use C4::ItemType; |
29 |
use Memoize; |
30 |
use Memoize; |
30 |
use DateTime::Format::MySQL; |
31 |
use DateTime::Format::MySQL; |
31 |
use autouse 'Data::Dumper' => qw(Dumper); |
32 |
use autouse 'Data::Dumper' => qw(Dumper); |
Lines 126-209
sub subfield_is_koha_internal_p {
Link Here
|
126 |
|
127 |
|
127 |
=head2 GetSupportName |
128 |
=head2 GetSupportName |
128 |
|
129 |
|
129 |
$itemtypename = &GetSupportName($codestring); |
130 |
$lib = &GetSupportName($authorised_value); |
130 |
|
131 |
|
131 |
Returns a string with the name of the itemtype. |
132 |
Returns the name of the support corresponding to specified authorised value. |
132 |
|
133 |
|
133 |
=cut |
134 |
=cut |
134 |
|
135 |
|
135 |
sub GetSupportName{ |
136 |
sub GetSupportName { |
136 |
my ($codestring)=@_; |
137 |
my $authorised_value = shift; |
137 |
return if (! $codestring); |
138 |
return '' unless $authorised_value; |
138 |
my $resultstring; |
139 |
my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; |
139 |
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); |
140 |
if ( $supports_av eq 'itemtypes' ) { |
140 |
if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { |
141 |
my $itemtype = getitemtypeinfo($authorised_value); |
141 |
my $query = qq| |
142 |
return $itemtype->{'description'} if $itemtype; |
142 |
SELECT description |
143 |
} |
143 |
FROM itemtypes |
144 |
else { |
144 |
WHERE itemtype=? |
145 |
my $lib = GetKohaAuthorisedValueLib( $supports_av, $authorised_value ); |
145 |
order by description |
146 |
return $lib if $lib; |
146 |
|; |
147 |
} |
147 |
my $sth = C4::Context->dbh->prepare($query); |
148 |
return ''; |
148 |
$sth->execute($codestring); |
|
|
149 |
($resultstring)=$sth->fetchrow; |
150 |
return $resultstring; |
151 |
} else { |
152 |
my $sth = |
153 |
C4::Context->dbh->prepare( |
154 |
"SELECT lib FROM authorised_values WHERE category = ? AND authorised_value = ?" |
155 |
); |
156 |
$sth->execute( $advanced_search_types, $codestring ); |
157 |
my $data = $sth->fetchrow_hashref; |
158 |
return $$data{'lib'}; |
159 |
} |
160 |
|
161 |
} |
149 |
} |
|
|
150 |
|
162 |
=head2 GetSupportList |
151 |
=head2 GetSupportList |
163 |
|
152 |
|
164 |
$itemtypes = &GetSupportList(); |
153 |
$supports = &GetSupportList(); |
165 |
|
154 |
|
166 |
Returns an array ref containing informations about Support (since itemtype is rather a circulation code when item-level-itypes is used). |
155 |
Returns an array ref containing informations about support : authorised_value, lib, imageurl |
167 |
|
156 |
|
168 |
build a HTML select with the following code : |
157 |
build a HTML select with the following code : |
169 |
|
158 |
|
170 |
=head3 in PERL SCRIPT |
159 |
=head3 in PERL SCRIPT |
171 |
|
160 |
|
172 |
my $itemtypes = GetSupportList(); |
161 |
my $supports = GetSupportList(); |
173 |
$template->param(itemtypeloop => $itemtypes); |
162 |
$template->param(supportsloop => $supports); |
174 |
|
163 |
|
175 |
=head3 in TEMPLATE |
164 |
=head3 in TEMPLATE |
176 |
|
165 |
|
177 |
<form action='<!-- TMPL_VAR name="script_name" -->' method=post> |
166 |
<select id="itemtype" name="itemtype" > |
178 |
<select name="itemtype"> |
167 |
[% FOREACH itemtypeloo IN itemtypeloop %] |
179 |
<option value="">Default</option> |
168 |
[% IF ( itemtypeloo.selected ) %] |
180 |
<!-- TMPL_LOOP name="itemtypeloop" --> |
169 |
<option value="[% itemtypeloo.code %]" selected="selected"> |
181 |
<option value="<!-- TMPL_VAR name="itemtype" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->> <!--TMPL_IF Name="imageurl"--><img alt="<!-- TMPL_VAR name="description" -->" src="<!--TMPL_VAR Name="imageurl"-->><!--TMPL_ELSE-->"<!-- TMPL_VAR name="description" --><!--/TMPL_IF--></option> |
170 |
[% ELSE %] |
182 |
<!-- /TMPL_LOOP --> |
171 |
<option value="[% itemtypeloo.code %]"> |
183 |
</select> |
172 |
[% END %] |
184 |
<input type=text name=searchfield value="<!-- TMPL_VAR name="searchfield" -->"> |
173 |
[% itemtypeloo.description %]</option> |
185 |
<input type="submit" value="OK" class="button"> |
174 |
[% END %] |
186 |
</form> |
175 |
</select> |
187 |
|
176 |
|
188 |
=cut |
177 |
=cut |
189 |
|
178 |
|
190 |
sub GetSupportList{ |
179 |
sub GetSupportList { |
191 |
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); |
180 |
my $supports_av = C4::Context->preference("SupportsAuthorizedValues") || 'itemtypes'; |
192 |
if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { |
181 |
if ( $supports_av eq 'itemtypes' ) { |
193 |
my $query = qq| |
182 |
my @supports = map { |
194 |
SELECT * |
183 |
{ |
195 |
FROM itemtypes |
184 |
authorised_value => $_->{'itemtype'}, |
196 |
order by description |
185 |
lib => $_->{'description'}, |
197 |
|; |
186 |
imageurl => $_->{'imageurl'} |
198 |
my $sth = C4::Context->dbh->prepare($query); |
187 |
} |
199 |
$sth->execute; |
188 |
} C4::ItemType->all; |
200 |
return $sth->fetchall_arrayref({}); |
189 |
return \@supports; |
201 |
} else { |
190 |
} |
202 |
my $advsearchtypes = GetAuthorisedValues($advanced_search_types); |
191 |
else { |
203 |
my @results= map {{itemtype=>$$_{authorised_value},description=>$$_{lib},imageurl=>$$_{imageurl}}} @$advsearchtypes; |
192 |
return GetAuthorisedValues($supports_av); |
204 |
return \@results; |
193 |
} |
205 |
} |
|
|
206 |
} |
194 |
} |
|
|
195 |
|
207 |
=head2 GetItemTypes |
196 |
=head2 GetItemTypes |
208 |
|
197 |
|
209 |
$itemtypes = &GetItemTypes( style => $style ); |
198 |
$itemtypes = &GetItemTypes( style => $style ); |