From 88e67b8d3e807797badd8fdf9afcc7a4c7cafafb Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 18 May 2004 15:22:10 +0000 Subject: [PATCH] framework management : 1 MARC framework for each itemtype --- C4/Biblio.pm | 93 ++++++---- C4/Koha.pm | 4 +- acqui.simple/addbiblio.pl | 78 +++++---- acqui.simple/addbooks.pl | 15 +- acqui.simple/additem.pl | 5 +- admin/marc_subfields_structure.pl | 41 +++-- admin/marctagstructure.pl | 151 ++++++++++++---- .../default/en/acqui.simple/addbiblio.tmpl | 113 +++++++----- .../default/en/acqui.simple/addbooks.tmpl | 25 ++- .../default/en/acqui.simple/additem.tmpl | 2 +- .../default/en/catalogue/MARCdetail.tmpl | 37 ++-- .../default/en/catalogue/detail.tmpl | 148 +++++----------- .../default/en/catalogue/moredetail.tmpl | 164 ++++++++---------- .../default/en/parameters/issuingrules.tmpl | 1 + .../parameters/marc_subfields_structure.tmpl | 95 +++++----- .../en/parameters/marctagstructure.tmpl | 150 +++++++++------- 16 files changed, 614 insertions(+), 508 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b0baee599e..e54028e569 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -33,37 +33,38 @@ $VERSION = 0.01; # as the old-style API and the NEW one are the only public functions. # @EXPORT = qw( - &updateBiblio &updateBiblioItem &updateItem - &itemcount &newbiblio &newbiblioitem - &modnote &newsubject &newsubtitle - &modbiblio &checkitems - &newitems &modbibitem - &modsubtitle &modsubject &modaddauthor &moditem &countitems - &delitem &deletebiblioitem &delbiblio - &getbiblio - &getbiblioitembybiblionumber - &getbiblioitem &getitemsbybiblioitem - &skip - &newcompletebiblioitem - - &MARCfind_oldbiblionumber_from_MARCbibid - &MARCfind_MARCbibid_from_oldbiblionumber - &MARCfind_marc_from_kohafield - &MARCfindsubfield - &MARCgettagslib - - &NEWnewbiblio &NEWnewitem - &NEWmodbiblio &NEWmoditem - &NEWdelbiblio &NEWdelitem - - &MARCaddbiblio &MARCadditem - &MARCmodsubfield &MARCaddsubfield - &MARCmodbiblio &MARCmoditem - &MARCkoha2marcBiblio &MARCmarc2koha - &MARCkoha2marcItem &MARChtml2marc - &MARCgetbiblio &MARCgetitem - &MARCaddword &MARCdelword - &char_decode + &updateBiblio &updateBiblioItem &updateItem + &itemcount &newbiblio &newbiblioitem + &modnote &newsubject &newsubtitle + &modbiblio &checkitems + &newitems &modbibitem + &modsubtitle &modsubject &modaddauthor &moditem &countitems + &delitem &deletebiblioitem &delbiblio + &getbiblio + &getbiblioitembybiblionumber + &getbiblioitem &getitemsbybiblioitem + &skip + &newcompletebiblioitem + + &MARCfind_oldbiblionumber_from_MARCbibid + &MARCfind_MARCbibid_from_oldbiblionumber + &MARCfind_marc_from_kohafield + &MARCfindsubfield + &MARCfind_itemtype + &MARCgettagslib + + &NEWnewbiblio &NEWnewitem + &NEWmodbiblio &NEWmoditem + &NEWdelbiblio &NEWdelitem + + &MARCaddbiblio &MARCadditem + &MARCmodsubfield &MARCaddsubfield + &MARCmodbiblio &MARCmoditem + &MARCkoha2marcBiblio &MARCmarc2koha + &MARCkoha2marcItem &MARChtml2marc + &MARCgetbiblio &MARCgetitem + &MARCaddword &MARCdelword + &char_decode ); # @@ -129,9 +130,10 @@ the db header $dbh is always passed as parameter to avoid over-DB connexion =over 4 -=item @tagslib = &MARCgettagslib($dbh,1|0); +=item @tagslib = &MARCgettagslib($dbh,1|0,$itemtype); last param is 1 for liblibrarian and 0 for libopac +$itemtype contains the itemtype framework reference. If empty or does not exist, the default one is used returns a hash with tag/subfield meaning =item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield); @@ -219,11 +221,17 @@ used to manage MARC_word table and should not be useful elsewhere =cut sub MARCgettagslib { - my ($dbh,$forlibrarian)= @_; + my ($dbh,$forlibrarian,$itemtype)= @_; + $itemtype="" unless $itemtype; my $sth; my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac'; - $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure order by tagfield"); - $sth->execute; + # check that itemtype framework exists + $sth=$dbh->prepare("select count(*) from marc_tag_structure where itemtype=? order by ?"); + $sth->execute($itemtype,$itemtype); + my ($total) = $sth->fetchrow; + $itemtype="" unless ($total >0); + $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory from marc_tag_structure where itemtype=? order by tagfield"); + $sth->execute($itemtype); my ($lib,$tag,$res,$tab,$mandatory,$repeatable); while ( ($tag,$lib,$mandatory) = $sth->fetchrow) { $res->{$tag}->{lib}=$lib; @@ -231,8 +239,8 @@ sub MARCgettagslib { $res->{$tag}->{mandatory}=$mandatory; } - $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso from marc_subfield_structure order by tagfield,tagsubfield"); - $sth->execute; + $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso from marc_subfield_structure where itemtype=? order by tagfield,tagsubfield"); + $sth->execute($itemtype); my $subfield; my $authorised_value; @@ -691,6 +699,14 @@ sub MARCfindsubfieldid { return $res; } +sub MARCfind_itemtype { + my ($dbh,$bibid) = @_; + my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.itemtype"); + my $sth = $dbh->prepare("select subfieldvalue from marc_subfield_table where bibid=? and tag=? and subfieldcode=?"); + $sth->execute($bibid,$tagfield,$tagsubfield); + my ($subfieldvalue) = $sth->fetchrow; + return $subfieldvalue; +} sub MARCdelsubfield { # delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_; @@ -2178,6 +2194,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.88 2004/05/18 15:23:49 tipaul +# framework management : 1 MARC framework for each itemtype +# # Revision 1.87 2004/05/18 11:54:07 tipaul # getitemtypes moved in Koha.pm # diff --git a/C4/Koha.pm b/C4/Koha.pm index 69642a492d..7faad9d0c2 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -199,7 +199,7 @@ sub getbranches { # returns a reference to a hash of references to branches... my %branches; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select * from branches"); + my $sth=$dbh->prepare("select * from branches order by branchname"); $sth->execute; while (my $branch=$sth->fetchrow_hashref) { my $nsth = $dbh->prepare("select categorycode from branchrelations where branchcode = ?"); @@ -263,7 +263,7 @@ sub getitemtypes { # returns a reference to a hash of references to branches... my %itemtypes; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select * from itemtypes"); + my $sth=$dbh->prepare("select * from itemtypes order by description"); $sth->execute; while (my $IT=$sth->fetchrow_hashref) { $itemtypes{$IT->{'itemtype'}}=$IT; diff --git a/acqui.simple/addbiblio.pl b/acqui.simple/addbiblio.pl index f637628447..11f0d1b032 100755 --- a/acqui.simple/addbiblio.pl +++ b/acqui.simple/addbiblio.pl @@ -34,6 +34,8 @@ use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); +my $itemtype; # created here because it can be used in build_authorized_values_list sub + =item find_value ($indicators, $value) = find_value($tag, $subfield, $record,$encoding); @@ -103,49 +105,47 @@ sub MARCfindbreeding { =cut sub build_authorized_values_list ($$$$$) { - my($tag, $subfield, $value, $dbh,$authorised_values_sth) = @_; + my($tag, $subfield, $value, $dbh,$authorised_values_sth) = @_; - my @authorised_values; - my %authorised_lib; + my @authorised_values; + my %authorised_lib; - # builds list, depending on authorised value... + # builds list, depending on authorised value... - #---- branch - if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { - my $sth=$dbh->prepare("select branchcode,branchname from branches"); + #---- branch + if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { + my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname"); $sth->execute; push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); while (my ($branchcode,$branchname) = $sth->fetchrow_array) { - push @authorised_values, $branchcode; - $authorised_lib{$branchcode}=$branchname; - } - - #----- itemtypes - } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") { - my $sth=$dbh->prepare("select itemtype,description from itemtypes"); - $sth->execute; - push @authorised_values, "" - unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - - while (my ($itemtype,$description) = $sth->fetchrow_array) { - push @authorised_values, $itemtype; - $authorised_lib{$itemtype}=$description; + push @authorised_values, $branchcode; + $authorised_lib{$branchcode}=$branchname; } - #---- "true" authorised value - } else { - $authorised_values_sth->execute - ($tagslib->{$tag}->{$subfield}->{authorised_value}); + #----- itemtypes + } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") { + my $sth=$dbh->prepare("select itemtype,description from itemtypes order by description"); + $sth->execute; + push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + + while (my ($itemtype,$description) = $sth->fetchrow_array) { + push @authorised_values, $itemtype; + $authorised_lib{$itemtype}=$description; + } + $value=$itemtype unless ($value); - push @authorised_values, "" - unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + #---- "true" authorised value + } else { + $authorised_values_sth->execute($tagslib->{$tag}->{$subfield}->{authorised_value}); - while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) { - push @authorised_values, $value; - $authorised_lib{$value}=$lib; - } + push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + + while (my ($value,$lib) = $authorised_values_sth->fetchrow_array) { + push @authorised_values, $value; + $authorised_lib{$value}=$lib; + } } return CGI::scrolling_list( -name => 'field_value', -values => \@authorised_values, @@ -313,12 +313,16 @@ my $oldbiblionumber=$input->param('oldbiblionumber'); # if bib exists, it's a mo my $breedingid = $input->param('breedingid'); my $z3950 = $input->param('z3950'); my $op = $input->param('op'); +$itemtype = $input->param('itemtype'); my $dbh = C4::Context->dbh; my $bibid; if ($oldbiblionumber) { $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$oldbiblionumber); + # find itemtype + $itemtype = &MARCfind_itemtype($dbh,$bibid) if $bibid; }else { $bibid = $input->param('bibid'); + $itemtype = &MARCfind_itemtype($dbh,$bibid) if $bibid; } my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "acqui.simple/addbiblio.tmpl", @@ -329,10 +333,11 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); -$tagslib = &MARCgettagslib($dbh,1); +$tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record=-1; my $encoding=""; $record = MARCgetbiblio($dbh,$bibid) if ($bibid); +warn "R".$record->as_formatted; ($record,$encoding) = MARCfindbreeding($dbh,$breedingid) if ($breedingid); $is_a_modif=0; @@ -372,7 +377,8 @@ if ($op eq "addbiblio") { ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record); } # now, redirect to additem page - print $input->redirect("additem.pl?bibid=$bibid"); + print $input->redirect("additem.pl?bibid=$bibid&itemtype=$itemtype"); + warn "redirect : $itemtype"; exit; #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "addfield") { @@ -434,7 +440,8 @@ if ($op eq "addbiblio") { &NEWdelbiblio($dbh,$bibid); print "Content-Type: text/html\n\n"; exit; -#------------------------------------------------------------------------------------------------------------------------------#------------------------------------------------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------------------------------------------------ +#------------------------------------------------------------------------------------------------------------------------------ } else { #------------------------------------------------------------------------------------------------------------------------------ build_tabs ($template, $record, $dbh,$encoding); @@ -448,4 +455,7 @@ if ($op eq "addbiblio") { oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield, oldbiblioitemnumber => $oldbiblioitemnumber ); } +$template->param( + itemtype => $itemtype + ); output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/acqui.simple/addbooks.pl b/acqui.simple/addbooks.pl index ec47b093fe..b5ed428461 100755 --- a/acqui.simple/addbooks.pl +++ b/acqui.simple/addbooks.pl @@ -40,6 +40,7 @@ use C4::Biblio; use C4::Output; use C4::Interface::CGI::Output; use HTML::Template; +use C4::Koha; my $query = new CGI; @@ -55,7 +56,19 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); + +# get itemtype list +my $itemtypes = getitemtypes; +my @itemtypesloop; +foreach my $thisitemtype (keys %$itemtypes) { + my %row =(value => $thisitemtype, + description => $itemtypes->{$thisitemtype}->{'description'}, + ); + push @itemtypesloop, \%row; +} + my $marc_p = C4::Context->boolean_preference("marc"); -$template->param( NOTMARC => !$marc_p ); +$template->param( NOTMARC => !$marc_p, + itemtypeloop => \@itemtypesloop ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/acqui.simple/additem.pl b/acqui.simple/additem.pl index 115ab270d1..807e1c568d 100755 --- a/acqui.simple/additem.pl +++ b/acqui.simple/additem.pl @@ -55,7 +55,10 @@ my $oldbiblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid); my $op = $input->param('op'); my $itemnum = $input->param('itemnum'); -my $tagslib = &MARCgettagslib($dbh,1); +# find itemtype +my $itemtype = &MARCfind_itemtype($dbh,$bibid); + +my $tagslib = &MARCgettagslib($dbh,1,$itemtype); my $record = MARCgetbiblio($dbh,$bibid); my $itemrecord; my $nextop="additem"; diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index 3a4b2c90ca..bc1b728482 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -28,20 +28,19 @@ use C4::Context; use HTML::Template; sub StringSearch { - my ($env,$searchstring,$type)=@_; + my ($env,$searchstring,$itemtype)=@_; my $dbh = C4::Context->dbh; $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where (tagfield like ?) order by tagfield"); - $sth->execute("$searchstring%"); + my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where (tagfield like ? and itemtype=?) order by tagfield"); + $sth->execute("$searchstring%",$itemtype); my @results; my $cnt=0; while (my $data=$sth->fetchrow_hashref){ - push(@results,$data); - $cnt ++; + push(@results,$data); + $cnt ++; } - # $sth->execute; $sth->finish; $dbh->disconnect; return ($cnt,\@results); @@ -50,6 +49,7 @@ sub StringSearch { my $input = new CGI; my $tagfield=$input->param('tagfield'); my $tagsubfield=$input->param('tagsubfield'); +my $itemtype=$input->param('itemtype'); my $pkfield="tagfield"; my $offset=$input->param('offset'); my $script_name="/cgi-bin/koha/admin/marc_subfields_structure.pl"; @@ -69,10 +69,12 @@ $tagfield=~ s/\,//g; if ($op) { $template->param(script_name => $script_name, tagfield =>$tagfield, + itemtype => $itemtype, $op => 1); # we show only the TMPL_VAR names $op } else { $template->param(script_name => $script_name, tagfield =>$tagfield, + itemtype => $itemtype, else => 1); # we show only the TMPL_VAR names $op } @@ -137,8 +139,8 @@ if ($op eq 'add_form') { closedir DIR; # build values list - my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield=?"); # and tagsubfield='$tagsubfield'"); - $sth->execute($tagfield); + my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield=? and itemtype=?"); # and tagsubfield='$tagsubfield'"); + $sth->execute($tagfield,$itemtype); my @loop_data = (); my $toggle="white"; my $i=0; @@ -247,8 +249,8 @@ if ($op eq 'add_form') { } elsif ($op eq 'add_validate') { my $dbh = C4::Context->dbh; $template->param(tagfield => "$input->param('tagfield')"); - my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder) - values (?,?,?,?,?,?,?,?,?,?,?,?)"); + my $sth=$dbh->prepare("replace marc_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,thesaurus_category,value_builder,itemtype) + values (?,?,?,?,?,?,?,?,?,?,?,?,?)"); my @tagsubfield = $input->param('tagsubfield'); my @liblibrarian = $input->param('liblibrarian'); my @libopac = $input->param('libopac'); @@ -285,12 +287,12 @@ if ($op eq 'add_form') { $seealso, $authorised_value, $thesaurus_category, - $value_builder); + $value_builder,$itemtype); } } } $sth->finish; - print "Content-Type: text/html\n\n"; + print "Content-Type: text/html\n\n"; exit; # END $OP eq ADD_VALIDATE @@ -298,7 +300,7 @@ if ($op eq 'add_form') { # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield=? and tagsubfield=?"); + my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder from marc_subfield_structure where tagfield=? and tagsubfield=? and itemtype=?"); $sth->execute($tagfield,$tagsubfield); my $data=$sth->fetchrow_hashref; $sth->finish; @@ -307,6 +309,7 @@ if ($op eq 'add_form') { delete_link => $script_name, tagfield =>$tagfield, tagsubfield => $tagsubfield, + itemtype => $itemtype, ); # END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## @@ -314,18 +317,18 @@ if ($op eq 'add_form') { } elsif ($op eq 'delete_confirmed') { my $dbh = C4::Context->dbh; unless (C4::Context->config('demo') eq 1) { - my $sth=$dbh->prepare("delete from marc_subfield_structure where tagfield=? and tagsubfield=?"); - $sth->execute($tagfield,$tagsubfield); + my $sth=$dbh->prepare("delete from marc_subfield_structure where tagfield=? and tagsubfield=? and itemtype=?"); + $sth->execute($tagfield,$tagsubfield,$itemtype); $sth->finish; } - print "Content-Type: text/html\n\n"; + print "Content-Type: text/html\n\n"; exit; $template->param(tagfield => $tagfield); # END $OP eq DELETE_CONFIRMED ################## DEFAULT ################################## } else { # DEFAULT my $env; - my ($count,$results)=StringSearch($env,$tagfield,'web'); + my ($count,$results)=StringSearch($env,$tagfield,$itemtype); my $toggle="white"; my @loop_data = (); for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ @@ -346,12 +349,12 @@ if ($op eq 'add_form') { $row_data{authorised_value} = $results->[$i]{'authorised_value'}; $row_data{thesaurus_category} = $results->[$i]{'thesaurus_category'}; $row_data{value_builder} = $results->[$i]{'value_builder'}; - $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}; + $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&itemtype=$itemtype"; $row_data{bgcolor} = $toggle; push(@loop_data, \%row_data); } $template->param(loop => \@loop_data); - $template->param(edit => ""); + $template->param(edit => ""); if ($offset>0) { my $prevpage = $offset-$pagesize; $template->param(prev =>""); diff --git a/admin/marctagstructure.pl b/admin/marctagstructure.pl index 53558fda5f..fc3603eb56 100755 --- a/admin/marctagstructure.pl +++ b/admin/marctagstructure.pl @@ -21,6 +21,7 @@ use strict; use CGI; use C4::Auth; +use C4::Koha; use C4::Context; use C4::Output; use C4::Interface::CGI::Output; @@ -28,31 +29,26 @@ use C4::Search; use C4::Context; use HTML::Template; -sub StringSearch { - my ($env,$searchstring,$type)=@_; - my $dbh = C4::Context->dbh; - $searchstring=~ s/\'/\\\'/g; - my @data=split(' ',$searchstring); - my $count=@data; - my $sth=$dbh->prepare("Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= ?) order by tagfield"); - $sth->execute($data[0]); - my @results; - while (my $data=$sth->fetchrow_hashref){ - push(@results,$data); - } - # $sth->execute; - $sth->finish; - return (scalar(@results),\@results); -} - +# retrieve parameters my $input = new CGI; +my $itemtype = $input->param('itemtype'); # set to select framework +$itemtype="" unless $itemtype; +my $existingitemtype = $input->param('existingitemtype'); # set when we have to create a new framework (in itemtype) by copying an old one (in existingitemtype) +$existingitemtype = "" unless $existingitemtype; +my $itemtypeinfo = getitemtypeinfo($itemtype); my $searchfield=$input->param('searchfield'); $searchfield=0 unless $searchfield; +$searchfield=~ s/\,//g; + my $offset=$input->param('offset'); +my $op = $input->param('op'); +my $pagesize=20; + my $script_name="/cgi-bin/koha/admin/marctagstructure.pl"; my $dbh = C4::Context->dbh; +# open template my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "parameters/marctagstructure.tmpl", query => $input, @@ -61,10 +57,34 @@ my ($template, $loggedinuser, $cookie) flagsrequired => {parameters => 1}, debug => 1, }); -my $pagesize=20; -my $op = $input->param('op'); -$searchfield=~ s/\,//g; +# get itemtype list +my $itemtypes = getitemtypes; +my @itemtypesloop; +foreach my $thisitemtype (keys %$itemtypes) { + my $selected = 1 if $thisitemtype eq $itemtype; + my %row =(value => $thisitemtype, + selected => $selected, + description => $itemtypes->{$thisitemtype}->{'description'}, + ); + push @itemtypesloop, \%row; +} + +# check that itemtype framework is defined in marc_tag_structure +my $sth=$dbh->prepare("select count(*) from marc_tag_structure where itemtype=?"); +$sth->execute($itemtype); +my ($itemtypeexist) = $sth->fetchrow; +if ($itemtypeexist) { +} else { + # if itemtype does not exists, then OP must be changed to "create itemtype" if we are not on the way to create it + # (op = itemtyp_create_confirm) + if ($op eq "itemtype_create_confirm") { + duplicate_framework($itemtype, $existingitemtype); + } else { + $op = "itemtype_create"; + } +} +$template->param(itemtypeloop => \@itemtypesloop); if ($op) { $template->param(script_name => $script_name, $op => 1); # we show only the TMPL_VAR names $op @@ -73,14 +93,15 @@ $template->param(script_name => $script_name, else => 1); # we show only the TMPL_VAR names $op } + ################## ADD_FORM ################################## # called by default. Used to create form to add or modify a record if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $data; if ($searchfield) { - my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?"); - $sth->execute($searchfield); + $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=? and itemtype=?"); + $sth->execute($searchfield,$itemtype); $data=$sth->fetchrow_hashref; $sth->finish; } @@ -113,13 +134,13 @@ if ($op eq 'add_form') { repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''), mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''), authorised_value => $authorised_value, + itemtype => $itemtype, ); # 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 marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value) values (?,?,?,?,?,?)"); + $sth=$dbh->prepare("replace marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,itemtype) values (?,?,?,?,?,?,?)"); my $tagfield =$input->param('tagfield'); my $liblibrarian = $input->param('liblibrarian'); my $libopac =$input->param('libopac'); @@ -132,18 +153,18 @@ if ($op eq 'add_form') { $libopac, $repeatable?1:0, $mandatory?1:0, - $authorised_value + $authorised_value, + $itemtype ); } $sth->finish; - print "Content-Type: text/html\n\n"; + print "Content-Type: text/html\n\n"; exit; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { - my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?"); + $sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where tagfield=?"); $sth->execute($searchfield); my $data=$sth->fetchrow_hashref; $sth->finish; @@ -154,19 +175,37 @@ if ($op eq 'add_form') { ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB } elsif ($op eq 'delete_confirmed') { - my $dbh = C4::Context->dbh; unless (C4::Context->config('demo') eq 1) { $dbh->do("delete from marc_tag_structure where tagfield='$searchfield'"); $dbh->do("delete from marc_subfield_structure where tagfield='$searchfield'"); } # END $OP eq DELETE_CONFIRMED +################## ITEMTYPE_CREATE ################################## +# called automatically if an unexisting itemtype is selected +} elsif ($op eq 'itemtype_create') { + $sth = $dbh->prepare("select count(*),marc_tag_structure.itemtype,description from marc_tag_structure,itemtypes where itemtypes.itemtype=marc_tag_structure.itemtype group by marc_tag_structure.itemtype"); + $sth->execute; + my @existingitemtypeloop; + while (my ($tot,$thisitemtype,$description) = $sth->fetchrow) { + if ($tot>0) { + my %line = ( value => $thisitemtype, + description => $description, + ); + push @existingitemtypeloop,\%line; + } + } + $template->param(existingitemtypeloop => \@existingitemtypeloop, + itemtype => $itemtype, + ITdescription => $itemtypeinfo->{description}, + ); ################## DEFAULT ################################## } else { # DEFAULT + # here, $op can be unset or set to "itemtype_create_confirm". if ($searchfield ne '') { - $template->param(searchfield => "

You Searched for $searchfield

"); + $template->param(searchfield => $searchfield); } my $env; - my ($count,$results)=StringSearch($env,$searchfield,'web'); + my ($count,$results)=StringSearch($env,$searchfield,$itemtype); my $toggle="white"; my @loop_data = (); for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){ @@ -181,9 +220,9 @@ if ($op eq 'add_form') { $row_data{repeatable} = $results->[$i]{'repeatable'}; $row_data{mandatory} = $results->[$i]{'mandatory'}; $row_data{authorised_value} = $results->[$i]{'authorised_value'}; - $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'}; - $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'}; - $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'}; + $row_data{subfield_link} ="marc_subfields_structure.pl?tagfield=".$results->[$i]{'tagfield'}."&itemtype=".$itemtype; + $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'tagfield'}."&itemtype=".$itemtype; + $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'tagfield'}."&itemtype=".$itemtype; $row_data{bgcolor} = $toggle; push(@loop_data, \%row_data); } @@ -194,6 +233,7 @@ if ($op eq 'add_form') { prevpage=> $prevpage, searchfield => $searchfield, script_name => $script_name, + itemtype => $itemtype, ); } if ($offset+$pagesize<$count) { @@ -201,9 +241,52 @@ if ($op eq 'add_form') { $template->param(nextpage =>$nextpage, searchfield => $searchfield, script_name => $script_name, + itemtype => $itemtype, ); } } #---- END $OP eq DEFAULT $template->param(loggeninuser => $loggedinuser); output_html_with_http_headers $input, $cookie, $template->output; + + +# +# the sub used for searches +# +sub StringSearch { + my ($env,$searchstring,$itemtype)=@_; + my $dbh = C4::Context->dbh; + $searchstring=~ s/\'/\\\'/g; + my @data=split(' ',$searchstring); + my $count=@data; + my $sth=$dbh->prepare("Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where (tagfield >= ? and itemtype=?) order by tagfield"); + $sth->execute($data[0], $itemtype); + my @results; + while (my $data=$sth->fetchrow_hashref){ + push(@results,$data); + } + # $sth->execute; + $sth->finish; + return (scalar(@results),\@results); +} + +# +# the sub used to duplicate a framework from an existing one in MARC parameters tables. +# +sub duplicate_framework { + my ($newitemtype,$olditemtype) = @_; + my $sth = $dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from marc_tag_structure where itemtype=?"); + $sth->execute($olditemtype); + my $sth_insert = $dbh->prepare("insert into marc_tag_structure (tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, itemtype) values (?,?,?,?,?,?,?)"); + while ( my ($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = $sth->fetchrow) { + $sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newitemtype); + } + + $sth = $dbh->prepare("select itemtype,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder,seealso from marc_subfield_structure where itemtype=?"); + $sth->execute($olditemtype); + $sth_insert = $dbh->prepare("insert into marc_subfield_structure (itemtype,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder,seealso) values (?,?,?,?,?,?,?,?,?,?,?,?,?)"); + while ( my ($itemtype, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso) = $sth->fetchrow) { + $sth_insert->execute($newitemtype, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso); + } +} + diff --git a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl index bea09f507d..4a193ffab2 100644 --- a/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/acqui.simple/addbiblio.tmpl @@ -7,6 +7,7 @@

+ "> "> @@ -15,40 +16,43 @@ z3950 search

+ +
- 0 + 0 - 1 + 1 - 2 + 2 - 3 + 3 - 4 + 4 - 5 + 5 - 6 + 6 - 7 + 7 - 8 + 8 - 9 + 9
-
- + +
+
@@ -79,8 +83,8 @@
-
- +
+
@@ -108,11 +112,11 @@ -
-
+ + -
- +
+
@@ -140,11 +144,11 @@ -
-
+ + -
- +
+
@@ -172,11 +176,11 @@ -
-
+ + -
- +
+
@@ -204,11 +208,11 @@ -
-
+ + -
- +
+
@@ -236,11 +240,11 @@ -
-
+ + -
- +
+
@@ -268,11 +272,11 @@ -
-
+ + -
- +
+
@@ -300,11 +304,11 @@ -
-
+ + -
- +
+
@@ -332,11 +336,11 @@ -
-
+ + -
- +
+
@@ -364,10 +368,11 @@ - +
+
- +
@@ -401,6 +406,18 @@