11 use C4::Interface::CGI::Output;
17 my ($template, $borrowernumber, $cookie)
18 = get_template_and_user({template_name => "opac-sendbasketform.tmpl",
22 flagsrequired => {borrow => 1},
25 my $bib_list=$query->param('bib_list');
26 my $email_add=$query->param('email_add');
27 my $email_sender=$query->param('email_sender');
28 my $dbh=C4::Context->dbh;
30 $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=? order by bibid");
34 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
36 my %mail = ( To => $email_add,
39 my ($template2, $borrowernumber, $cookie)
40 = get_template_and_user({template_name => "opac-sendbasket.tmpl",
44 flagsrequired => {borrow => 1},
47 my @bibs = split(/\//, $bib_list);
50 foreach my $biblionumber (@bibs) {
51 $template2->param(biblionumber => $biblionumber);
53 my $dat = &bibdata($biblionumber);
54 my ($authorcount, $addauthor) = &getaddauthor($biblionumber);
55 my @items = &ItemInfo(undef, $biblionumber, 'opac');
57 $dat->{'additional'}=$addauthor->[0]->{'author'};
58 for (my $i = 1; $i < $authorcount; $i++) {
59 $dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
62 $dat->{'biblionumber'} = $biblionumber;
63 $dat->{ITEM_RESULTS} = \@items;
64 $sth->execute($biblionumber);
65 my ($bibid) = $sth->fetchrow;
66 my $record = MARCgetbiblio($dbh,$bibid);
67 $iso2709 .= $record->as_usmarc();
69 push (@results, $dat);
72 # Getting template result
73 my $template_res = $template2->output();
74 # Analysing information and getting mail properties
75 if ($template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s) { $mail{'subject'} = $1; }
76 else { $mail{'subject'} = "no subject"; }
78 my $email_header = "";
79 if ($template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s) { $email_header = $1; }
81 my $email_file = "basket.txt";
82 if ($template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s) { $email_file = $1; }
84 if ($template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s) { $mail{'body'} = $1; }
86 my $boundary = "====" . time() . "====";
87 # $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
89 # $email_header = encode_qp($email_header);
91 # $boundary = "--".$boundary;
95 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
97 my $message = encode_qp( "" );
99 # $file = $^X; # This is the perl executable
101 # open (F, $file) or die "Cannot read $file: $!";
102 # binmode F; undef $/;
103 $mail{body} = encode_base64($iso2709);
106 $boundary = '--'.$boundary;
107 $mail{body} = <<END_OF_BODY;
109 Content-Type: text/plain; charset="iso-8859-1"
110 Content-Transfer-Encoding: quoted-printable
114 Content-Type: application/octet-stream; name="basket"
115 Content-Transfer-Encoding: base64
116 Content-Disposition: attachment; filename="basket"
126 Content-Type: text/plain; charset="iso-8859-1"
127 Content-Transfer-Encoding: quoted-printable
136 $mail{attachment} = $iso2709;
137 # $mail{body} = <<END_OF_BODY;
139 #Content-Type: text/plain; charset="iso-8859-1"
140 #Content-Transfer-Encoding: quoted-printable
145 #Content-Type: text/plain; name="$email_file"
146 #Content-Transfer-Encoding: quoted-printable
147 #Content-Disposition: attachment; filename="$email_file"
155 if (sendmail %mail) {
156 # do something if it works....
157 # warn " ".$mail{body};
158 # warn " ".$mail{PJ};
159 $template->param(SENT => "1");
160 $template->param(email_add => $email_add);
162 # do something if it doesnt work....
163 warn "Error sending mail: $Mail::Sendmail::error \n";
166 output_html_with_http_headers $query, $cookie, $template->output;
169 $template->param(bib_list => $bib_list);
170 $template->param(url => "/cgi-bin/koha/opac-sendbasket.pl",
171 suggestion => C4::Context->preference("suggestion"),
172 virtualshelves => C4::Context->preference("virtualshelves"),
174 output_html_with_http_headers $query, $cookie, $template->output;