From c0666bccff8deaee1c6d0d06f3ece2419693c705 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Jul 2013 14:38:55 +0200 Subject: [PATCH] Bug 10602: Set a default value for authorities Some code already exist but the feature does not work. This patch allows to define default values in the authorities framework. Test plan: 1/ Choose a framework, field and subfields. 2/ Define a default value. 3/ Create a new authority and check that the subfield is automatically filled with the default value. --- C4/AuthoritiesMarc.pm | 6 ++++-- admin/auth_subfields_structure.pl | 9 +++++++-- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 12 ++++++++++++ .../prog/en/modules/admin/auth_subfields_structure.tt | 13 ++++++++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 9ea3b2d..7bfaf00 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -520,7 +520,7 @@ sub GetTagsLabels { $res->{$tag}->{repeatable} = $repeatable; } $sth= $dbh->prepare( -"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl +"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue FROM auth_subfield_structure WHERE authtypecode=? ORDER BY tagfield,tagsubfield" @@ -535,12 +535,13 @@ ORDER BY tagfield,tagsubfield" my $hidden; my $isurl; my $link; + my $defaultvalue; while ( ( $tag, $subfield, $liblibrarian, , $libopac, $tab, $mandatory, $repeatable, $authorised_value, $authtypecode, $value_builder, $kohafield, $seealso, $hidden, - $isurl, $link ) + $isurl, $defaultvalue, $link ) = $sth->fetchrow ) { @@ -556,6 +557,7 @@ ORDER BY tagfield,tagsubfield" $res->{$tag}->{$subfield}->{hidden} = $hidden; $res->{$tag}->{$subfield}->{isurl} = $isurl; $res->{$tag}->{$subfield}->{link} = $link; + $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue; } return $res; } diff --git a/admin/auth_subfields_structure.pl b/admin/auth_subfields_structure.pl index 537f0ea..1e45c14 100755 --- a/admin/auth_subfields_structure.pl +++ b/admin/auth_subfields_structure.pl @@ -139,6 +139,7 @@ if ($op eq 'add_form') { while ($data =$sth->fetchrow_hashref) { my %row_data; # get a fresh hash for the row data + $row_data{defaultvalue} = $data->{defaultvalue}; $row_data{tab} = CGI::scrolling_list(-name=>'tab', -id=>"tab$i", -values => @@ -386,9 +387,9 @@ if ($op eq 'add_form') { $template->param(tagfield => "$input->param('tagfield')"); # my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) + my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=? + my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=? where authtypecode=? and tagfield=? and tagsubfield=?"); my @tagsubfield = $input->param('tagsubfield'); my @liblibrarian = $input->param('liblibrarian'); @@ -404,6 +405,7 @@ if ($op eq 'add_form') { my $authtypecode = $input->param('authtypecode'); my @frameworkcodes = $input->param('frameworkcode'); my @value_builder =$input->param('value_builder'); + my @defaultvalue = $input->param('defaultvalue'); for (my $i=0; $i<= $#tagsubfield ; $i++) { my $tagfield =$input->param('tagfield'); my $tagsubfield =$tagsubfield[$i]; @@ -418,6 +420,7 @@ if ($op eq 'add_form') { my $authorised_value =$authorised_values[$i]; my $frameworkcode =$frameworkcodes[$i]; my $value_builder=$value_builder[$i]; + my $defaultvalue = $value_builder[$i]; #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens; my $hidden = $ohidden[$i]; #collate from 3 hiddens; my $isurl = $input->param("isurl$i")?1:0; @@ -440,6 +443,7 @@ if ($op eq 'add_form') { $value_builder, $hidden, $isurl, + $defaultvalue, ( $authtypecode, $tagfield, @@ -463,6 +467,7 @@ if ($op eq 'add_form') { $value_builder, $hidden, $isurl, + $defaultvalue, ); } } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index fdab879..36cb26e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -56,6 +56,7 @@ CREATE TABLE `auth_subfield_structure` ( `linkid` tinyint(1) NOT NULL default 0, `kohafield` varchar(45) NULL default '', `frameworkcode` varchar(10) NOT NULL default '', + `defaultvalue` TEXT DEFAULT '', PRIMARY KEY (`authtypecode`,`tagfield`,`tagsubfield`), KEY `tab` (`authtypecode`,`tab`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 31f494a..35dc091 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7139,6 +7139,18 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } + + + +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| + ALTER TABLE auth_subfield_structure ADD COLUMN defaultvalue TEXT DEFAULT NULL AFTER frameworkcode + |); + print "Upgrade to $DBversion done (Bug 10602: Add the column auth_subfield_structure.defaultvalue)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt index 688bd71..3d22192 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt @@ -99,7 +99,18 @@ function displayMoreConstraint(numlayer){ -
  • [% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)
  • +
  • +
    + Advanced constraints: +
      +
    1. [% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)
    2. +
    3. + + +
    4. +
    +
    +
  • Help input
      -- 1.7.10.4