12 use C4::Interface::CGI::Output;
18 my ($template, $borrowernumber, $cookie)
19 = get_template_and_user({template_name => "opac-sendbasketform.tmpl",
23 flagsrequired => {borrow => 1},
26 my $bib_list=$query->param('bib_list');
27 my $email_add=$query->param('email_add');
28 my $email_sender=$query->param('email_sender');
29 my $dbh=C4::Context->dbh;
31 $sth=$dbh->prepare("select bibid from marc_biblio where biblionumber=? order by bibid");
35 my $email_from = C4::Context->preference('KohaAdminEmailAddress');
37 my %mail = ( To => $email_add,
40 my ($template2, $borrowernumber, $cookie)
41 = get_template_and_user({template_name => "opac-sendbasket.tmpl",
45 flagsrequired => {borrow => 1},
48 my @bibs = split(/\//, $bib_list);
51 foreach my $biblionumber (@bibs) {
52 $template2->param(biblionumber => $biblionumber);
54 my $dat = &bibdata($biblionumber);
55 my ($authorcount, $addauthor) = &addauthor($biblionumber);
56 my @items = &ItemInfo(undef, $biblionumber, 'opac');
58 $dat->{'additional'}=$addauthor->[0]->{'author'};
59 for (my $i = 1; $i < $authorcount; $i++) {
60 $dat->{'additional'} .= "|" . $addauthor->[$i]->{'author'};
63 $dat->{'biblionumber'} = $biblionumber;
64 $dat->{ITEM_RESULTS} = \@items;
65 $sth->execute($biblionumber);
66 my ($bibid) = $sth->fetchrow;
67 my $record = MARCgetbiblio($dbh,$bibid);
68 $iso2709 .= $record->as_usmarc();
70 push (@results, $dat);
73 # Getting template result
74 my $template_res = $template2->output();
75 # Analysing information and getting mail properties
76 if ($template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s) { $mail{'subject'} = $1; }
77 else { $mail{'subject'} = "no subject"; }
79 my $email_header = "";
80 if ($template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s) { $email_header = $1; }
82 my $email_file = "basket.txt";
83 if ($template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s) { $email_file = $1; }
85 if ($template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s) { $mail{'body'} = $1; }
87 my $boundary = "====" . time() . "====";
88 # $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
90 # $email_header = encode_qp($email_header);
92 # $boundary = "--".$boundary;
96 $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
98 my $message = encode_qp( "" );
100 # $file = $^X; # This is the perl executable
102 # open (F, $file) or die "Cannot read $file: $!";
103 # binmode F; undef $/;
104 $mail{body} = encode_base64($iso2709);
107 $boundary = '--'.$boundary;
108 $mail{body} = <<END_OF_BODY;
110 Content-Type: text/plain; charset="iso-8859-1"
111 Content-Transfer-Encoding: quoted-printable
115 Content-Type: application/octet-stream; name="basket"
116 Content-Transfer-Encoding: base64
117 Content-Disposition: attachment; filename="basket"
127 Content-Type: text/plain; charset="iso-8859-1"
128 Content-Transfer-Encoding: quoted-printable
137 $mail{attachment} = $iso2709;
138 # $mail{body} = <<END_OF_BODY;
140 #Content-Type: text/plain; charset="iso-8859-1"
141 #Content-Transfer-Encoding: quoted-printable
146 #Content-Type: text/plain; name="$email_file"
147 #Content-Transfer-Encoding: quoted-printable
148 #Content-Disposition: attachment; filename="$email_file"
156 if (sendmail %mail) {
157 # do something if it works....
158 # warn " ".$mail{body};
159 # warn " ".$mail{PJ};
160 $template->param(SENT => "1");
161 $template->param(email_add => $email_add);
163 # do something if it doesnt work....
164 warn "Error sending mail: $Mail::Sendmail::error \n";
167 output_html_with_http_headers $query, $cookie, $template->output;
170 $template->param(bib_list => $bib_list);
171 $template->param(url => "/cgi-bin/koha/opac-sendbasket.pl",
172 suggestion => C4::Context->preference("suggestion"),
173 virtualshelves => C4::Context->preference("virtualshelves"),
175 output_html_with_http_headers $query, $cookie, $template->output;