-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;
- }
- 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;
- }
- # 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");
- # build thesaurus categories list
- $sth2->finish;
- $sth2 = $dbh->prepare("select distinct category from bibliothesaurus");
- $sth2->execute;
- my @thesaurus_category;
- push @thesaurus_category,"";
- while ((my $category) = $sth2->fetchrow_array) {
- push @thesaurus_category, $category;
- }
- # build value_builder list
- my @value_builder=('');
- opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
- while (my $line = readdir(DIR)) {
- if ($line =~ /\.pl$/) {
- push (@value_builder,$line);
- }
- }
- closedir DIR;
+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;
+
+ # build values list
+ my $sth =
+ $dbh->prepare(
+"select * from marc_subfield_structure where tagfield=? and frameworkcode=?"
+ ); # and tagsubfield='$tagsubfield'");
+ $sth->execute( $tagfield, $frameworkcode );
+ my @loop_data = ();
+ my $toggle = 1;
+ my $i = 0;
+ while ( $data = $sth->fetchrow_hashref ) {
+ my %row_data; # get a fresh hash for the row data
+ if ( $toggle eq 1 ) {
+ $toggle = 0;
+ }
+ else {
+ $toggle = 1;
+ }
+ $row_data{defaultvalue} = $data->{defaultvalue};
+ $row_data{tab} = CGI::scrolling_list(
+ -name => 'tab',
+ -id => "tab$i",
+ -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'}
+ . "\" id=\"tagsubfield\" />";
+ $row_data{subfieldcode} = $data->{'tagsubfield'} eq '@'?'_':$data->{'tagsubfield'};
+ $row_data{urisubfieldcode} = $row_data{subfieldcode} eq '%' ? 'pct' : $row_data{subfieldcode};
+ $row_data{liblibrarian} = CGI::escapeHTML( $data->{'liblibrarian'} );
+ $row_data{libopac} = CGI::escapeHTML( $data->{'libopac'} );
+ $row_data{seealso} = CGI::escapeHTML( $data->{'seealso'} );
+ $row_data{kohafield} = CGI::scrolling_list(
+ -name => "kohafield",
+ -id => "kohafield$i",
+ -values => \@kohafields,
+ -default => "$data->{'kohafield'}",
+ -size => 1,
+ -multiple => 0,
+ );
+ $row_data{authorised_value} = CGI::scrolling_list(
+ -name => "authorised_value",
+ -id => "authorised_value$i",
+ -values => \@authorised_values,
+ -default => $data->{'authorised_value'},
+ -size => 1,
+ -multiple => 0,
+ );
+ $row_data{value_builder} = CGI::scrolling_list(
+ -name => "value_builder",
+ -id => "value_builder$i",
+ -values => \@value_builder,
+ -default => $data->{'value_builder'},
+ -size => 1,
+ -multiple => 0,
+ );
+ $row_data{authtypes} = CGI::scrolling_list(
+ -name => "authtypecode",
+ -id => "authtypecode$i",
+ -values => \@authtypes,
+ -default => $data->{'authtypecode'},
+ -size => 1,
+ -multiple => 0,
+ );
+ $row_data{repeatable} = CGI::checkbox(
+ -name => "repeatable$i",
+ -checked => $data->{'repeatable'} ? 'checked' : '',
+ -value => 1,
+ -label => '',
+ -id => "repeatable$i"
+ );
+ $row_data{mandatory} = CGI::checkbox(
+ -name => "mandatory$i",
+ -checked => $data->{'mandatory'} ? 'checked' : '',
+ -value => 1,
+ -label => '',
+ -id => "mandatory$i"
+ );
+ $row_data{hidden} = CGI::escapeHTML( $data->{hidden} );
+ $row_data{isurl} = CGI::checkbox(
+ -name => "isurl$i",
+ -id => "isurl$i",
+ -checked => $data->{'isurl'} ? 'checked' : '',
+ -value => 1,
+ -label => ''
+ );
+ $row_data{row} = $i;
+ $row_data{toggle} = $toggle;
+ $row_data{link} = CGI::escapeHTML( $data->{'link'} );
+ push( @loop_data, \%row_data );
+ $i++;
+ }