-if ($op eq 'add_form') {
- my $data;
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value from marc_subfield_structure where tagfield='$tagfield'"); # and tagsubfield='$tagsubfield'");
- $sth->execute;
- # builds kohafield tables
- my @kohafields;
- push @kohafields, "";
- my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
- $sth2->execute;
- while ((my $field) = $sth2->fetchrow_array) {
- push @kohafields, "biblio.".$field;
- }
- my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
- $sth2->execute;
- while ((my $field) = $sth2->fetchrow_array) {
- push @kohafields, "biblioitems.".$field;
- }
- my $sth2=$dbh->prepare("SHOW COLUMNS from items");
- $sth2->execute;
- while ((my $field) = $sth2->fetchrow_array) {
- push @kohafields, "items.".$field;
- }
- # buiild authorised value list
- $sth2->finish;
- $sth2 = $dbh->prepare("select distinct category from authorised_values");
- $sth2->execute;
- my @authorised_values;
- push @authorised_values,"";
- while ((my $category) = $sth2->fetchrow_array) {
- push @authorised_values, $category;
- }
- $template->param(action => "Edit subfields",
- tagfield => "<input type=hidden name=tagfield value='$tagfield'>$tagfield",
- );
- my @loop_data = ();
- my $toggle="white";
- my $i=0;
- while ($data =$sth->fetchrow_hashref) {
- my %row_data; # get a fresh hash for the row data
- if ($toggle eq 'white'){
- $toggle="#ffffcc";
- } else {
- $toggle="white";
- }
- $row_data{tab} = CGI::scrolling_list(-name=>'tab',
- -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
- -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
- '2' =>'2','3'=>'3','4'=>'4',
- '5' =>'5','6'=>'6','7'=>'7',
- '8' =>'8','9'=>'9','10'=>'items (10)',
- },
- -default=>$data->{'tab'},
- -size=>1,
- -multiple=>0,
- );
- $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
- $row_data{liblibrarian} = $data->{'liblibrarian'};
- $row_data{libopac} = $data->{'libopac'};
- $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
- -values=> \@kohafields,
- -default=> "$data->{'kohafield'}",
- -size=>1,
- -multiple=>0,
- );
- $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
- -values=> \@authorised_values,
- -default=>$data->{'authorised_value'},
- -size=>1,
- -multiple=>0,
- );
-# $row_data{kohafield} = $data->{'kohafield'};
- $row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
- $row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
- $row_data{bgcolor} = $toggle;
- push(@loop_data, \%row_data);
- $i++;
- }
- # add an empty line for add if needed
- my %row_data; # get a fresh hash for the row data
- $row_data{tab} = CGI::scrolling_list(-name=>'tab',
- -values=>['-1','0','1','2','3','4','5','6','7','8','9','10'],
- -labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
- '2' =>'2','3'=>'3','4'=>'4',
- '5' =>'5','6'=>'6','7'=>'7',
- '8' =>'8','9'=>'9','10'=>'items (10)',
- },
- -default=>"",
- -size=>1,
- -multiple=>0,
- );
- $row_data{tagsubfield} = "<input type='text' name='tagsubfield' value='".$data->{'tagsubfield'}."' size=3 maxlength=1>";
- $row_data{liblibrarian} = "";
- $row_data{libopac} = "";
- $row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
- $row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
- $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
- -values=> \@kohafields,
- -default=> "",
- -size=>1,
- -multiple=>0,
- );
- $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
- -values=> \@authorised_values,
- -size=>1,
- -multiple=>0,
- );
- $row_data{bgcolor} = $toggle;
- push(@loop_data, \%row_data);
+if ( $op eq 'add_form' ) {
+ my $data;
+ my $dbh = C4::Context->dbh;
+ my $more_subfields = $input->param("more_subfields") + 1;
+
+ # builds kohafield tables
+ my @kohafields;
+ push @kohafields, "";
+ my $sth2 = $dbh->prepare("SHOW COLUMNS from biblio");
+ $sth2->execute;
+ while ( ( my $field ) = $sth2->fetchrow_array ) {
+ push @kohafields, "biblio." . $field;
+ }
+ $sth2 = $dbh->prepare("SHOW COLUMNS from biblioitems");
+ $sth2->execute;
+ while ( ( my $field ) = $sth2->fetchrow_array ) {
+ if ( $field eq 'notes' ) { $field = 'bnotes'; }
+ push @kohafields, "biblioitems." . $field;
+ }
+ $sth2 = $dbh->prepare("SHOW COLUMNS from items");
+ $sth2->execute;
+ while ( ( my $field ) = $sth2->fetchrow_array ) {
+ push @kohafields, "items." . $field;
+ }
+
+ # build authorised value list
+ $sth2->finish;
+ $sth2 = $dbh->prepare("select distinct category from authorised_values");
+ $sth2->execute;
+ my @authorised_values;
+ push @authorised_values, "";
+ while ( ( my $category ) = $sth2->fetchrow_array ) {
+ push @authorised_values, $category;
+ }
+ push( @authorised_values, "branches" );
+ push( @authorised_values, "itemtypes" );
+ push( @authorised_values, "cn_source" );
+
+ # build thesaurus categories list
+ $sth2->finish;
+ $sth2 = $dbh->prepare("select authtypecode from auth_types");
+ $sth2->execute;
+ my @authtypes;
+ push @authtypes, "";
+ while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
+ push @authtypes, $authtypecode;
+ }
+
+ # build value_builder list
+ my @value_builder = ('');
+
+ # read value_builder directory.
+ # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
+ # on a standard install, /cgi-bin need to be added.
+ # test one, then the other
+ my $cgidir = C4::Context->intranetdir . "/cgi-bin";
+ unless ( opendir( DIR, "$cgidir/cataloguing/value_builder" ) ) {
+ $cgidir = C4::Context->intranetdir;
+ opendir( DIR, "$cgidir/cataloguing/value_builder" )
+ || die "can't opendir $cgidir/value_builder: $!";
+ }
+ while ( my $line = readdir(DIR) ) {
+ if ( $line =~ /\.pl$/ ) {
+ push( @value_builder, $line );
+ }
+ }
+ @value_builder= sort {$a cmp $b} @value_builder;
+ closedir DIR;