Bug fixing : 2516
[koha.git] / admin / auth_subfields_structure.pl
index 86531e9..ed92de6 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-
 # Copyright 2000-2002 Katipo Communications
 #
 # This file is part of Koha.
 
 use strict;
 use C4::Output;
-use C4::Interface::CGI::Output;
 use C4::Auth;
 use CGI;
-use C4::Search;
 use C4::Context;
-use HTML::Template;
+
 
 sub StringSearch  {
-       my ($env,$searchstring,$authtypecode)=@_;
+       my ($searchstring,$authtypecode)=@_;
        my $dbh = C4::Context->dbh;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
@@ -44,7 +41,6 @@ sub StringSearch  {
                $u++;
        }
        $sth->finish;
-       $dbh->disconnect;
        return ($cnt,\@results);
 }
 
@@ -106,6 +102,16 @@ if ($op eq 'add_form') {
        }
        push (@authorised_values,"branches");
        push (@authorised_values,"itemtypes");
+    
+    # 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=('');
@@ -115,15 +121,16 @@ if ($op eq 'add_form') {
        # 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/value_builder")) {
+       unless (opendir(DIR, "$cgidir/cataloguing/value_builder")) {
                $cgidir = C4::Context->intranetdir;
-               opendir(DIR, "$cgidir/value_builder") || die "can't opendir $cgidir/value_builder: $!";
+               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
@@ -142,9 +149,21 @@ if ($op eq 'add_form') {
                }
                $row_data{tab} = CGI::scrolling_list(-name=>'tab',
                                        -id=>"tab$i",
-                                       -values=>['-1','0'],
-                                       -labels => {'-1' =>'ignore','0'=>'0',
-                                                                       },
+                                        -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',
+                                        },
                                        -default=>$data->{'tab'},
                                        -size=>1,
                                        -tabindex=>'',
@@ -176,11 +195,12 @@ if ($op eq 'add_form') {
                                        -labels => {'0'=>'Show','1'=>'Show Collapsed',
                                                                        '2' =>'Hide',
                                                                        },
-                                       -default=>substr($data->{'hidden'},2,1),
+                                       -default=>substr($data->{'hidden'}."  ",2,1),
                                        -size=>1,
                                        -multiple=>0,
                                        );
-               $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\">";
+               $row_data{tagsubfieldinput} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
+               $row_data{tagsubfield} = $data->{'tagsubfield'};
                $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
                $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
                $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
@@ -192,15 +212,23 @@ if ($op eq 'add_form') {
                                        -multiple=>0,
                                        );
                $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
-                                       -id=>'authorised_value',
+                                       -id=>"authorised_value$i",
                                        -values=> \@authorised_values,
                                        -default=>$data->{'authorised_value'},
                                        -size=>1,
                                        -tabindex=>'',
                                        -multiple=>0,
                                        );
+               $row_data{frameworkcode}  = CGI::scrolling_list(-name=>'frameworkcode',
+                                       -id=>"frameworkcode$i",
+                                       -values=> \@authtypes,
+                                       -default=>$data->{'frameworkcode'},
+                                       -size=>1,
+                                       -tabindex=>'',
+                                       -multiple=>0,
+                                       );
                $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
-                                       -id=>'value_builder',
+                                       -id=>"value_builder$i",
                                        -values=> \@value_builder,
                                        -default=>$data->{'value_builder'},
                                        -size=>1,
@@ -224,25 +252,32 @@ if ($op eq 'add_form') {
                        -checked => $data->{'isurl'}?'checked':'',
                        -value => 1,
                        -label => '');
-               $row_data{link} = CGI::checkbox( -name => "link$i",
-                       -id => "link$i",
-                       -checked => $data->{'link'}?'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++;
        }
        # add more_subfields empty lines for add if needed
        for (my $i=1;$i<=$more_subfields;$i++) {
                my %row_data;  # get a fresh hash for the row data
+        $row_data{'new_subfield'} = 1;
                $row_data{tab} = CGI::scrolling_list(-name=>'tab',
                                        -id => "tab$i",
-                                       -values=>['-1','0'],
-                                       -labels => {'-1' =>'ignore','0'=>'0',
-                                                                       },
+                                        -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',
+                                        },
                                        -default=>"",
                                        -size=>1,
                                        -tabindex=>'',
@@ -279,7 +314,8 @@ if ($op eq 'add_form') {
                                        -size=>1,
                                        -multiple=>0,
                                        );
-               $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\">";
+               $row_data{tagsubfieldinput} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
+               $row_data{tagsubfield} = $data->{'tagsubfield'};
                $row_data{liblibrarian} = "";
                $row_data{libopac} = "";
                $row_data{seealso} = "";
@@ -306,6 +342,14 @@ if ($op eq 'add_form') {
                                        -size=>1,
                                        -multiple=>0,
                                        );
+               $row_data{frameworkcode}  = CGI::scrolling_list(-name=>'frameworkcode',
+                                       -id=>'frameworkcode',
+                                       -values=> \@authtypes,
+                                       -default=>$data->{'frameworkcode'},
+                                       -size=>1,
+                                       -tabindex=>'',
+                                       -multiple=>0,
+                                       );
                $row_data{authorised_value}  = CGI::scrolling_list(-name=>'authorised_value',
                                        -id => 'authorised_value',
                                        -values=> \@authorised_values,
@@ -313,12 +357,14 @@ if ($op eq 'add_form') {
                                        -tabindex=>'',
                                        -multiple=>0,
                                        );
-               $row_data{link} = CGI::checkbox( -name => "link",
-                       -id => "link$i",
-                       -checked => '',
-                       -value => 1,
-                       -label => '');
-               # $row_data{link} = CGI::escapeHTML($data->{'link'});
+               $row_data{value_builder}  = CGI::scrolling_list(-name=>'value_builder',
+                                       -id=>'value_builder',
+                                       -values=> \@value_builder,
+                                       -default=>$data->{'value_builder'},
+                                       -size=>1,
+                                       -tabindex=>'',
+                                       -multiple=>0,
+                                       );
                $row_data{toggle} = $toggle;
                $row_data{row} = $i;
                push(@loop_data, \%row_data);
@@ -326,7 +372,8 @@ if ($op eq 'add_form') {
        $template->param('use-heading-flags-p' => 1);
        $template->param('heading-edit-subfields-p' => 1);
        $template->param(action => "Edit subfields",
-                                                       tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />$tagfield",
+                                                       tagfield => $tagfield,
+                                                       tagfieldinput => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
                                                        loop => \@loop_data,
                                                        more_subfields => $more_subfields,
                                                        more_tag => $tagfield);
@@ -337,23 +384,22 @@ 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 auth_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl, link)
+       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 @tagsubfield = $input->param('tagsubfield');
        my @liblibrarian        = $input->param('liblibrarian');
        my @libopac             = $input->param('libopac');
-       my @kohafield           = $input->param('kohafield');
+       my @kohafield           = ''.$input->param('kohafield');
        my @tab                         = $input->param('tab');
        my @seealso             = $input->param('seealso');
-       #my @hidden             = $input->param('hidden');
        my @hidden;
        my @ohidden             = $input->param('ohidden');
        my @ihidden             = $input->param('ihidden');
        my @ehidden             = $input->param('ehidden');
        my @authorised_values   = $input->param('authorised_value');
-#      my $authtypecodes       = $input->param('authtypecode');
+       my $authtypecode        = $input->param('authtypecode');
+       my @frameworkcodes      = $input->param('frameworkcode');
        my @value_builder       =$input->param('value_builder');
-       my @link                =$input->param('link');
        for (my $i=0; $i<= $#tagsubfield ; $i++) {
                my $tagfield                    =$input->param('tagfield');
                my $tagsubfield         =$tagsubfield[$i];
@@ -366,30 +412,27 @@ if ($op eq 'add_form') {
                my $tab                         =$tab[$i];
                my $seealso                             =$seealso[$i];
                my $authorised_value            =$authorised_values[$i];
-#              my $authtypecode                =$authtypecodes;
+               my $frameworkcode               =$frameworkcodes[$i];
                my $value_builder=$value_builder[$i];
                my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
                my $isurl = $input->param("isurl$i")?1:0;
-               my $link = $input->param("link$i")?1:0;
                if ($liblibrarian) {
                        unless (C4::Context->config('demo') eq 1) {
-                               $sth->execute ($tagfield,
-                                                                       $tagsubfield,
-                                                                       $liblibrarian,
-                                                                       $libopac,
-                                                                       $repeatable,
-                                                                       $mandatory,
-                                                                       $kohafield,
-                                                                       $tab,
-                                                                       $seealso,
-                                                                       $authorised_value,
-                                                                       $authtypecode,
-                                                                       $value_builder,
-                                                                       $hidden,
-                                                                       $isurl,
-                                                                       
-
-        $link,
+                               $sth->execute($authtypecode,
+                              $tagfield,
+                              $tagsubfield,
+                              $liblibrarian,
+                              $libopac,
+                              $repeatable,
+                              $mandatory,
+                              $kohafield,
+                              $tab,
+                              $seealso,
+                              $authorised_value,
+                              $frameworkcode,
+                              $value_builder,
+                              $hidden,
+                              $isurl,
                                              );
                        }
                }
@@ -431,8 +474,7 @@ if ($op eq 'add_form') {
                                                                                                        # END $OP eq DELETE_CONFIRMED
 ################## DEFAULT ##################################
 } else { # DEFAULT
-       my $env;
-       my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
+       my ($count,$results)=StringSearch($tagfield,$authtypecode);
        my $toggle=1;
        my @loop_data = ();
        for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
@@ -455,8 +497,7 @@ if ($op eq 'add_form') {
                $row_data{value_builder}        = $results->[$i]{'value_builder'};
                $row_data{hidden}       = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
                $row_data{isurl}        = $results->[$i]{'isurl'};
-               $row_data{link} = $results->[$i]{'link'};
-               $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
+               $row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&amp;authtypecode=$authtypecode";
                $row_data{toggle} = $toggle;
                if ($row_data{tab} eq -1) {
                        $row_data{subfield_ignored} = 1;
@@ -477,8 +518,4 @@ if ($op eq 'add_form') {
                $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
        }
 } #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
-               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-               IntranetNav => C4::Context->preference("IntranetNav"),
-               );
 output_html_with_http_headers $input, $cookie, $template->output;