IMPORTANT : biblioitems.editionresponsibility field was sometimes spelled with a 'a'
[koha_gimpoz] / admin / letter.pl
index 7089773..ff522cd 100755 (executable)
@@ -43,12 +43,10 @@ use C4::Date;
 use C4::Auth;
 use C4::Context;
 use C4::Output;
-use C4::Interface::CGI::Output;
-use C4::Search;
-use HTML::Template;
+
 
 sub StringSearch  {
-       my ($env,$searchstring,$type)=@_;
+       my ($searchstring,$type)=@_;
        my $dbh = C4::Context->dbh;
        $searchstring=~ s/\'/\\\'/g;
        my @data=split(' ',$searchstring);
@@ -71,13 +69,14 @@ my $searchfield=$input->param('searchfield');
 my $offset=$input->param('offset');
 my $script_name="/cgi-bin/koha/admin/letter.pl";
 my $code=$input->param('code');
+my $module = $input->param('module');
 my $pagesize=20;
 my $op = $input->param('op');
 $searchfield=~ s/\,//g;
 my $dbh = C4::Context->dbh;
 
 my ($template, $borrowernumber, $cookie)
-    = get_template_and_user({template_name => "parameters/letter.tmpl",
+    = get_template_and_user({template_name => "tools/letter.tmpl",
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
@@ -100,18 +99,34 @@ if ($op eq 'add_form') {
        #---- if primkey exists, it's a modify action, so read values to modify...
        my $letter;
        if ($code) {
-               my $sth=$dbh->prepare("select * from letter where code=?");
-               $sth->execute($code);
+               my $sth=$dbh->prepare("select * from letter where module=? and code=?");
+               $sth->execute($module,$code);
                $letter=$sth->fetchrow_hashref;
                $sth->finish;
        }
        # build field list
        my @SQLfieldname;
+       my %line = ('value' => "LibrarianFirstname", 'text' => 'LibrarianFirstname');
+       push @SQLfieldname, \%line;
+       my %line = ('value' => "LibrarianSurname", 'text' => 'LibrarianSurname');
+       push @SQLfieldname, \%line;
+       my %line = ('value' => "LibrarianEmailaddress", 'text' => 'LibrarianEmailaddress');
+       push @SQLfieldname, \%line;
+       my $sth2=$dbh->prepare("SHOW COLUMNS from branches");
+       $sth2->execute;
+       my %line = ('value' => "", 'text' => '---BRANCHES---');
+       push @SQLfieldname, \%line;
+       while ((my $field) = $sth2->fetchrow_array) {
+               my %line = ('value' => "branches.".$field, 'text' => "branches.".$field);
+               push @SQLfieldname, \%line;
+       }
        my $sth2=$dbh->prepare("SHOW COLUMNS from biblio");
        $sth2->execute;
        my %line = ('value' => "", 'text' => '---BIBLIO---');
+
        push @SQLfieldname, \%line;
        while ((my $field) = $sth2->fetchrow_array) {
+               # note : %line is redefined, otherwise \%line contains the same value for every entry of the list
                my %line = ('value' => "biblio.".$field, 'text' => "biblio.".$field);
                push @SQLfieldname, \%line;
        }
@@ -144,6 +159,7 @@ if ($op eq 'add_form') {
        }
        $template->param(name => $letter->{name},title => $letter->{title},
                                        content => $letter->{content},
+                                       $letter->{module} => 1,
                                        SQLfieldname => \@SQLfieldname,);
                                                                                                        # END $OP eq ADD_FORM
 ################## ADD_VALIDATE ##################################
@@ -187,8 +203,7 @@ if ($op eq 'add_form') {
                $template->param(search => 1);
                $template->param(searchfield => $searchfield);
        }
-       my $env;
-       my ($count,$results)=StringSearch($env,$searchfield,'web');
+       my ($count,$results)=StringSearch($searchfield,'web');
        my $toggle="white";
        my @loop_data =();
        for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){