From c66d4eb161371fbaab85e54093ce6d222a800357 Mon Sep 17 00:00:00 2001 From: plg Date: Fri, 7 Apr 2006 11:10:25 +0000 Subject: [PATCH] modification: on itemtypes management screen, useless form are replaced by simple links. improvement: support of itemtype icons on prog template. The icons are displayed on itemtypes management screen and on moremember screen. improvement: use of pagination_bar on itemtypes management screen. new: function were added in C4::Koha to manage itemtype image location (local/remote). Warning: you must copy or symlink the itemtypeimg directory from the opac template into the intranet template. --- C4/Koha.pm | 35 +++ admin/itemtypes.pl | 161 ++++++----- .../prog/en/admin/itemtypes.tmpl | 269 +++++++++++++----- .../prog/en/members/moremember.tmpl | 7 +- members/moremember.pl | 6 +- 5 files changed, 335 insertions(+), 143 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 48f4d67ae5..a7b92834b7 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -63,6 +63,9 @@ Koha.pm provides many functions for Koha scripts. &getallthemes &getalllanguages &getallbranches &getletters getnbpages + getitemtypeimagedir + getitemtypeimagesrc + getitemtypeimagesrcfromurl $DEBUG); use vars qw(); @@ -543,9 +546,41 @@ sub getitemtypeinfo { my $sth=$dbh->prepare("select * from itemtypes where itemtype=?"); $sth->execute($itemtype); my $res = $sth->fetchrow_hashref; + + $res->{imageurl} = getitemtypeimagesrcfromurl($res->{imageurl}); + return $res; } +sub getitemtypeimagesrcfromurl { + my ($imageurl) = @_; + + if (defined $imageurl and $imageurl !~ m/^http/) { + $imageurl = + getitemtypeimagesrc() + .'/'.$imageurl + ; + } + + return $imageurl; +} + +sub getitemtypeimagedir { + return + C4::Context->intrahtdocs + .'/'.C4::Context->preference('template') + .'/itemtypeimg' + ; +} + +sub getitemtypeimagesrc { + return + '/intranet-tmpl' + .'/'.C4::Context->preference('template') + .'/itemtypeimg' + ; +} + =head2 getprinters $printers = &getprinters($env); diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 10fbe39b40..a00c713aa5 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -40,12 +40,15 @@ use strict; use CGI; +use HTML::Template; +use List::Util qw/min/; + +use C4::Koha; use C4::Context; use C4::Output; use C4::Search; use C4::Auth; use C4::Interface::CGI::Output; -use HTML::Template; sub StringSearch { my ($env,$searchstring,$type)=@_; @@ -66,10 +69,9 @@ sub StringSearch { my $input = new CGI; my $searchfield=$input->param('description'); -my $offset=$input->param('offset'); my $script_name="/cgi-bin/koha/admin/itemtypes.pl"; my $itemtype=$input->param('itemtype'); -my $pagesize=20; +my $pagesize=5; my $op = $input->param('op'); $searchfield=~ s/\,//g; my ($template, $borrowernumber, $cookie) @@ -102,49 +104,70 @@ if ($op eq 'add_form') { $sth->finish; } # build list of images - my $imagedir = C4::Context->opachtdocs."/".C4::Context->preference('opacthemes'); - warn "img : $imagedir"; - unless (opendir(DIR, "$imagedir/itemtypeimg/")) { -# my $cgidir = C4::Context->intranetdir; - opendir(DIR, "$imagedir/value_builder") || die "can't opendir $imagedir/value_builder: $!"; - } + my $imagedir_filesystem = getitemtypeimagedir(); + my $imagedir_web = getitemtypeimagesrc(); + opendir(DIR, $imagedir_filesystem) + or die "can't opendir ".$imagedir_filesystem.": ".$!; my @imagelist; while (my $line = readdir(DIR)) { - if ($line =~ /\.gif$/) { - my %x; - $x{KohaImage} = "$line"; - push @imagelist, \%x; + if ($line =~ /\.(gif|png)$/i) { + push( + @imagelist, + { + KohaImage => $line, + KohaImageSrc => $imagedir_web.'/'.$line, + checked => $line eq $data->{imageurl} ? 1 : 0, + } + ); } } closedir DIR; -# my $CGIitemtypes = CGI::scrolling_list(-name=>'itemtypes', -# -id=>"itemtypes", -# -values=> \@imagelist, -# -size=>1, -# -multiple=>0, -# ); -# - $template->param(itemtype => $itemtype, - description => $data->{'description'}, - renewalsallowed => $data->{'renewalsallowed'}, - rentalcharge => sprintf("%.2f",$data->{'rentalcharge'}), - notforloan => $data->{'notforloan'}, - imageurl => $data->{'imageurl'}, - opacthemes => C4::Context->preference('opacthemes'), - IMAGESLOOP => \@imagelist, - ); -; + + my $remote_image = undef; + if (defined $data->{imageurl} and $data->{imageurl} =~ m/^http/) { + $remote_image = $data->{imageurl}; + } + + $template->param( + itemtype => $itemtype, + description => $data->{'description'}, + renewalsallowed => $data->{'renewalsallowed'}, + rentalcharge => sprintf("%.2f",$data->{'rentalcharge'}), + notforloan => $data->{'notforloan'}, + imageurl => $data->{'imageurl'}, + template => C4::Context->preference('template'), + IMAGESLOOP => \@imagelist, + remote_image => $remote_image, + ); # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB } elsif ($op eq 'add_validate') { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("replace itemtypes (itemtype,description,renewalsallowed,rentalcharge,notforloan,imageurl) values (?,?,?,?,?,?)"); + + my $query = ' +UPDATE itemtypes + SET description = ? + , renewalsallowed = ? + , rentalcharge = ? + , notforloan = ? + , imageurl = ? + WHERE itemtype = ? +'; + my $sth=$dbh->prepare($query); $sth->execute( - $input->param('itemtype'),$input->param('description'), - $input->param('renewalsallowed'),$input->param('rentalcharge'), - $input->param('notforloan')?1:0, - $input->param('imageurl')); + $input->param('description'), + $input->param('renewalsallowed'), + $input->param('rentalcharge'), + $input->param('notforloan') ? 1 : 0, + $input->param('image') eq 'removeImage' + ? undef + : $input->param('image') eq 'remoteImage' + ? $input->param('remoteImage') + : $input->param('image'), + $input->param('itemtype'), + ); + $sth->finish; print "Content-Type: text/html\n\n"; exit; @@ -192,40 +215,40 @@ if ($op eq 'add_form') { # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT - my $env; - my ($count,$results)=StringSearch($env,$searchfield,'web'); - my $toggle=0; - my @loop_data; - for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ - my %row_data; - if ($toggle eq 0){ - $toggle=1; - } else { - $toggle=0; - } - $row_data{toggle} = $toggle; - $row_data{itemtype} = $results->[$i]{itemtype}; - $row_data{description} = $results->[$i]{description}; - $row_data{renewalsallowed} = $results->[$i]{renewalsallowed}; - $row_data{notforloan} = $results->[$i]{notforloan}; - if ($results->[$i]{imageurl} =~ /^http/) { - $row_data{absoluteurl} = 1; - } - $row_data{imageurl} = $results->[$i]{imageurl}; - $row_data{rentalcharge} = sprintf("%.2f",$results->[$i]{rentalcharge}); - push(@loop_data, \%row_data); - } - $template->param(loop => \@loop_data, - opacthemes => C4::Context->preference('opacthemes') - ); - if ($offset>0) { - my $prevpage = $offset-$pagesize; - $template->param(previous => "$script_name?offset=".$prevpage); - } - if ($offset+$pagesize<$count) { - my $nextpage =$offset+$pagesize; - $template->param(next => "$script_name?offset=".$nextpage); - } + my $env; + my ($count,$results)=StringSearch($env,$searchfield,'web'); + + my $page = $input->param('page') || 1; + my $first = ($page - 1) * $pagesize; + + # if we are on the last page, the number of the last word to display + # must not exceed the length of the results array + my $last = min( + $first + $pagesize - 1, + scalar @{$results} - 1, + ); + + my $toggle = 0; + my @loop; + foreach my $result (@{$results}[$first .. $last]) { + my $itemtype = $result; + $itemtype->{toggle} = ($toggle eq 0 ? 1 : 0); + $itemtype->{imageurl} = + getitemtypeimagesrcfromurl($itemtype->{imageurl}); + $itemtype->{rentalcharge} = sprintf('%.2f', $itemtype->{rentalcharge}); + + push(@loop, $itemtype); + } + + $template->param( + loop => \@loop, + pagination_bar => pagination_bar( + $script_name, + getnbpages(scalar @{$results}, $pagesize), + $page, + 'page' + ) + ); } #---- END $OP eq DEFAULT output_html_with_http_headers $input, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/admin/itemtypes.tmpl b/koha-tmpl/intranet-tmpl/prog/en/admin/itemtypes.tmpl index 3eaa5f4792..022a4b1877 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/admin/itemtypes.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/admin/itemtypes.tmpl @@ -1,8 +1,30 @@ -Koha -- System Administration: -Modify item type ''Add item type -Cannot Delete Item Type ''Delete Item Type ''? -Data Deleted -Item Types Administration + +Koha -- System Administration: + + + +Modify item type '' + +Add item type + + + + + +Cannot Delete Item Type '' + +Delete Item Type ''? + + + + +Data Deleted + + + +Item Types Administration + + @@ -10,40 +32,133 @@ -
" name="Aform" method="post"> - - +" name="Aform" method="post"> + + + + Modify item type + + Add item type + + + + + - - - - - - - - - - - - - - - - - - - - - - - - -
- Modify item type - - Add item type -
" />
" /> 
checked="checked" value="1"> (if checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item)
" value="1" />
" />
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + " /> + +
+ + + +
+ + + " /> +
Image +

+ + + +

+
+

+ + " + onmousedown="document.getElementById('remote_image_check').checked = true;" + /> + + + " /> + +

+
+

+ +

+
+ + + + checked="checked" + + value="1"> + (if checked, no item of this type can be issued. If not checked, every item of this type can be issued unless notforloan is set for a specific item) +
+ + + + + " value="1" /> +
+ + + " /> +
+ +

+ + +

+ + @@ -70,44 +185,54 @@ +

Item Types Administration

- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
Item Types Administration
CodeDescriptionNot for LoanRenewableChargeEditDelete
?op=add_form&itemtype=">Yes  - time(s) - - No - -
" method="get">" />
" method="get">" />
imageCodeDescriptionNot for LoanRenewableChargeActions
" /> + ?op=add_form&itemtype="> + + + Yes  + + time(s) + + No + + + + + + + ?op=add_form&itemtype=">Edit + ?op=delete_confirm&itemtype=">Delete +
-
" method="post"> -

- -'; return false;" value="<< Previous Page" /> - - +

-'; return false;" value="Next Page >>" /> -

+

?op=add_form">Add Item type

diff --git a/koha-tmpl/intranet-tmpl/prog/en/members/moremember.tmpl b/koha-tmpl/intranet-tmpl/prog/en/members/moremember.tmpl index 56a9b3a2ea..7b7a1824cd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/members/moremember.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/members/moremember.tmpl @@ -177,7 +177,12 @@ - + + + + " /> + + diff --git a/members/moremember.pl b/members/moremember.pl index 0a3e4fb624..0efdaecd91 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -177,7 +177,11 @@ for (my $i=0;$i<$count;$i++){ # return the correct item type either (or a properly-formatted # charge, for that matter). my ($charge,$itemtype)=calc_charges($dbh,$issue->[$i]{'itemnumber'},$bornum); - $row{'itemtype'} = getitemtypeinfo($itemtype)->{description}; + + my $itemtypeinfo = getitemtypeinfo($itemtype); + $row{'itemtype_description'} = $itemtypeinfo->{description}; + $row{'itemtype_image'} = $itemtypeinfo->{imageurl}; + $row{'charge'}= sprintf("%.2f",$charge); #check item is not reserved -- 2.39.5