<? if($_POST['format'] == 'html') { ?>
<?php require_once('Connections/t77_connect.php'); ?>
<?php
mysql_select_db($database_t77_connect, $t77_connect);
$query_settings = "SELECT * FROM t77_bill_settings";
$settings = mysql_query($query_settings, $t77_connect) or die(mysql_error());
$row_settings = mysql_fetch_assoc($settings);
$totalRows_settings = mysql_num_rows($settings);
$colname_doc = "7";
if (isset($_POST['id'])) {
$colname_doc = (get_magic_quotes_gpc()) ? $_POST['id'] : addslashes($_POST['id']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_doc = sprintf("SELECT * FROM t77_bill_bills, t77_bill_types, t77_bill_contacts WHERE t77_bill_bills.bill_id = %s AND t77_bill_types.bill_type = t77_bill_bills.bill_type AND t77_bill_bills.bill_contact = t77_bill_contacts.contact_id", $colname_doc);
$doc = mysql_query($query_doc, $t77_connect) or die(mysql_error());
$row_doc = mysql_fetch_assoc($doc);
$totalRows_doc = mysql_num_rows($doc);
$t77filename = str_replace(" ","_", $row_doc['order_number'] . "-" . $row_doc['bill_name'] . ".eml");
$t77To = $_POST['t77to'];
$t77message = $_POST['t77message'];
$t77From = $row_settings['company_email'];
$t77sub = $_POST['subject'];
/**
* Filename.......: example.5.php
* Project........: HTML Mime Mail class
* Last Modified..: 15 July 2002
*/
error_reporting(E_ALL);
include('./mail/htmlMimeMail.php');
/**
* Example of usage. This example shows
* how to use the class to send an email
* attached to another email. First email
* built is html/text with an embedded image
* and attachment. This is then attached
* to the second email which is plain text.
*
* Create the mail object.
*/
$mail_1 = new htmlMimeMail();
/**
* This call is usually not necessary unless you're sending the final
* mail via SMTP (Qmail won't send mail with bare LFs and you must
* therefore use CRLF), but setting this explicitly doesnt hurt.
*/
$mail_1->setCrlf("\n");
$file = $omis_hostname . "print.php?id=" . $row_doc['bill_id'];
/**
* First email.
*/ //$logo = $mail_1->getFile('logo.jpg');
$mail_1->setHTML($mail_1->getFile($omis_hostname . 'print.php?id=' . $row_doc['bill_id']), $mail_1->getFile('./mail/example.txt'), dirname(__FILE__) . '/');
//$mail_1->addHtmlImage($logo, 'logo.jpg', 'image/jpeg');
/**
* Add the attachment
*/
/**
* Don't send this email, but use the
* get_rfc822() method to assign it to a
* variable.
*/
$mail_1->setReturnPath($t77From);
$mail_1->setFrom($t77From);
$mail_1->setSubject($t77filename);
$mail = $mail_1->getRFC822(array($t77From));
/**
* Now start a new mail, and add the first
* (which is now built and contained in
* $mail) to it.
*/
$mail_2 = new htmlMimeMail();
$mail_2->setText($t77message);
$mail_2->addAttachment($mail, $t77filename, 'message/rfc822', '7bit');
$mail_2->setFrom($t77From);
$mail_2->setSubject($t77sub);
$result = $mail_2->send(array($t77To));
if($result == true) {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="refresh" content="3;URL=close.php?<? echo "ref=" . $_GET['ref'] . "&quer=" . $_GET['quer']; ?>" />
<title>Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="31"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
<td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><p><strong>Mail document </strong></p>
</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
<tr>
<td colspan="2"><h1 align="center">Email sent </h1></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html><?
} else {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="refresh" content="3;URL=close.php?<? echo "ref=" . $_GET['ref'] . "&quer=" . $_GET['quer']; ?>" />
<title>Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="31"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
<td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><p><strong>Mail document</strong></p>
</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
<tr>
<td colspan="2"><h1 align="center">Email not sent</h1></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html><?
}
?>
<?php
mysql_free_result($settings);
mysql_free_result($doc);
?>
<? } elseif($_POST['format'] == 'pdf') { ?>
<?php require_once('Connections/t77_connect.php'); ?>
<?php
//===================================================================================================
// this is the php file which creates the readme.pdf file, this is not seriously
// suggested as a good way to create such a file, nor a great example of prose,
// but hopefully it will be useful
//
// adding ?d=1 to the url calling this will cause the pdf code itself to ve echoed to the
// browser, this is quite useful for debugging purposes.
// there is no option to save directly to a file here, but this would be trivial to implement.
//
// note that this file comprisises both the demo code, and the generator of the pdf documentation
//
//===================================================================================================
// don't want any warnings turning up in the pdf code if the server is set to 'anal' mode.
//error_reporting(7);
$colname_bills = "12";
if (isset($_POST['id'])) {
$colname_bills = (get_magic_quotes_gpc()) ? $_POST['id'] : addslashes($_POST['id']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_bills = sprintf("SELECT * FROM t77_bill_bills WHERE t77_bill_bills.bill_id = %s", $colname_bills);
$bills = mysql_query($query_bills, $t77_connect) or die(mysql_error());
$row_bills = mysql_fetch_assoc($bills);
$totalRows_bills = mysql_num_rows($bills);
$colname_items = "1";
if (isset($_POST['id'])) {
$colname_items = (get_magic_quotes_gpc()) ? $_POST['id'] : addslashes($_POST['id']);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_items = sprintf("SELECT * FROM t77_bill_items WHERE t77_bill_items.bill_id = %s ORDER BY t77_bill_items.item_order", $colname_items);
$items = mysql_query($query_items, $t77_connect) or die(mysql_error());
$row_items = mysql_fetch_assoc($items);
$totalRows_items = mysql_num_rows($items);
$colname_contact = $row_bills['bill_contact'];
if (isset($row_bills['bill_contact'])) {
$colname_contact = (get_magic_quotes_gpc()) ? $row_bills['bill_contact'] : addslashes($row_bills['bill_contact']);
}
$contactSelect = $row_bills['bill_contact'];
$subtotal = 0;
$colname_contacts = "1";
if (isset($contactSelect)) {
$colname_contacts = (get_magic_quotes_gpc()) ? $contactSelect : addslashes($contactSelect);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_contacts = sprintf("SELECT * FROM t77_bill_contacts, t77_bill_companies WHERE t77_bill_contacts.contact_company_name = t77_bill_companies.company_id AND t77_bill_contacts.contact_id = %s", $colname_contacts);
$contacts = mysql_query($query_contacts, $t77_connect) or die(mysql_error());
$row_contacts = mysql_fetch_assoc($contacts);
$totalRows_contacts = mysql_num_rows($contacts);
$typeVar = $row_bills['bill_type'];
$colname_types = "1";
if (isset($typeVar)) {
$colname_types = (get_magic_quotes_gpc()) ? $typeVar : addslashes($typeVar);
}
mysql_select_db($database_t77_connect, $t77_connect);
$query_types = sprintf("SELECT * FROM t77_bill_types WHERE t77_bill_types.bill_type = %s", $colname_types);
$types = mysql_query($query_types, $t77_connect) or die(mysql_error());
$row_types = mysql_fetch_assoc($types);
$totalRows_types = mysql_num_rows($types);
mysql_select_db($database_t77_connect, $t77_connect);
$query_settings = "SELECT * FROM t77_bill_settings";
$settings = mysql_query($query_settings, $t77_connect) or die(mysql_error());
$row_settings = mysql_fetch_assoc($settings);
$totalRows_settings = mysql_num_rows($settings);
include './pdf/class.ezpdf.php';
// define a clas extension to allow the use of a callback to get the table of contents, and to put the dots in the toc
class Creport extends Cezpdf {
var $reportContents = array();
function Creport($p,$o){
$this->Cezpdf($p,$o);
}
function rf($info){
// this callback records all of the table of contents entries, it also places a destination marker there
// so that it can be linked too
$tmp = $info['p'];
$lvl = $tmp[0];
$lbl = rawurldecode(substr($tmp,1));
$num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
$this->reportContents[] = array($lbl,$num,$lvl );
$this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']);
}
function dots($info){
// draw a dotted line over to the right and put on a page number
$tmp = $info['p'];
$lvl = $tmp[0];
$lbl = substr($tmp,1);
$xpos = 520;
switch($lvl){
case '1':
$size=16;
$thick=1;
break;
case '2':
$size=12;
$thick=0.5;
break;
}
$this->saveState();
$this->setLineStyle($thick,'round','',array(0,10));
$this->line($xpos,$info['y'],$info['x']+5,$info['y']);
$this->restoreState();
$this->addText($xpos+5,$info['y'],$size,$lbl);
}
}
// I am in NZ, so will design my page for A4 paper.. but don't get me started on that.
// (defaults to legal)
// this code has been modified to use ezpdf.
//$pdf = new Cezpdf('a4','portrait');
$pdf = new Creport('a4','portrait');
$all = $pdf->openObject();
$pdf->saveState();
$pdf->addPngFromFile('logo.png',355,$pdf->y-70,180,0);
$pdf->restoreState();
$pdf->closeObject();
$pdf->addObject($all,'all');
$pdf -> ezSetMargins(120,70,70,50);
$mainFont = './pdf/fonts/Helvetica.afm';
$codeFont = './pdf/fonts/Courier.afm';
// select a font
$pdf->selectFont($mainFont);
//$pdf->openHere('Fit');
// try adding the faq's to the document, this will not work for people re-building the file from the
// download as I am not going to put in the faq file with tha
$pdf->ezStartPageNumbers(500,28,10,'','{PAGENUM} van {TOTALPAGENUM}',1);
$size=7;
$height = $pdf->getFontHeight($size);
$collecting=0;
$code='';
// content
$data1 = "<b>" . $row_contacts['company_name'] . "</b>\nt.a.v. " . $row_contacts['contact_title'] . " " . $row_contacts['contact_person'] . "\n" . $row_contacts['contact_company_address'] . "\n" . $row_contacts['contact_company_zip'] . " " . $row_contacts['contact_company_city'] . "\n" . $row_contacts['contact_country'] . "\n";
$data2 = ' ';
$data3 = "<b>" . $row_settings['company_name'] . "</b>\n" . $row_settings['company_address'] . "\n" . $row_settings['company_zip'] . " " . $row_settings['company_city'] . "\n" . "Tel : " . $row_settings['company_tel'] . "\n" . "email: " . $row_settings['company_email'] . "\n" . $row_settings['company_bank']. "\n" . $row_settings['company_COC_nr'] . "\n" . $row_settings['company_VAT_nr'];
$data = array(array('row1'=>$data1,'row2'=>$data2,'row3'=>$data3));
$pdf->ezTable($data,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0));
$pdf->ezSetDy(-40);
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
$pdf->ezSetDy(-2);
$header1 = "<b>Betreft: </b>\n" . $row_bills['bill_name'] . "\n\n" . "<b>Ordernummer: </b>\n" . $row_bills['order_number'];
$header2 = "<b>Behandeld door: </b>\n" . $row_settings['contact_name'] . "\n\n" . "<b>Type: </b>\n" . $row_types['type_description'];
$header3 = "<b>Datum: </b>\n" . DateAndTime($row_bills['bill_date']);
$header0 = array(array('row1'=>$header1,'row2'=>$header2,'row3'=>$header3));
$pdf->ezTable($header0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0));
$pdf->ezSetDy(-5);
$pdf->saveState();
$pdf->setStrokeColor(0,0,0,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
$pdf->ezSetDy(-20);
do {
$subtotal = $subtotal + $row_items['item_price'];
$item1 = "<b>" . $row_items['item_name'] . "</b>\n\n" . strip_tags(str_replace("B>","b>", str_replace("I>","1>",str_replace("U>","u>",str_replace(" "," ",str_replace("H1>","b>",str_replace("STRONG>","b>",$row_items['item_description'])))))), '<b><u><strong><h1><i>');
if($row_items['item_price'] == 0) {
$item2 = " ";
} else {
$item2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($row_items['item_price'],2,',','.') . "</b>";
}
$item0 = array(array('row1'=>$item1,'row2'=>$item2));
$pdf->ezText(" ");
$pdf->ezTable($item0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$pdf->ezText(" ");
$pdf->saveState();
$pdf->setStrokeColor(0.7,0.7,0.7,1);
$pdf->setLineStyle(0.1);
$pdf->line(70,$pdf->y,535,$pdf->y);
$pdf->restoreState();
} while ($row_items = mysql_fetch_assoc($items));
$pdf->ezText(" ");
$subtotal1 = "<b>Subtotaal:</b>\n";
$subtotal2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($subtotal,2,',','.') . "</b>";
$subtotal0 = array(array('row1'=>$subtotal1,'row2'=>$subtotal2));
$pdf->ezTable($subtotal0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$vat1 = "<b>BTW " . number_format($row_settings['VAT'],2,',','.'). "%:" . "</b>\n";
$VAT = (($subtotal/100)*$row_settings['VAT']);
$vat2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($VAT,2,',','.') . "</b>";
$vat0 = array(array('row1'=>$vat1,'row2'=>$vat2));
$pdf->ezTable($vat0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$total1 = "<b>Totaal:</b>\n";
$total2 = "<b>" . $row_settings['valuta_sign'] . " " . number_format($subtotal+$VAT,2,',','.') . "</b>";
$total0 = array(array('row1'=>$total1,'row2'=>$total2));
$pdf->ezTable($total0,'','',array('showHeadings'=>0,'shaded'=>0,'width'=>475,'showLines'=>0, 'cols'=>array('row1'=>array('justification'=>'left'), 'row2'=>array('justification'=>'right'))));
$pdf->ezText("\n\nGaarne betaling binnen 8 dagen na factuurdatum op rekeningnummer 1882.12.515. Alle transacties vinden plaats conform onze leveringsvoorwaarden.");
mysql_free_result($bills);
mysql_free_result($items);
mysql_free_result($contacts);
mysql_free_result($types);
mysql_free_result($settings);
// stopcontent
$pdf->ezStopPageNumbers(1,1);
$write_error = "<span style=\"font-family:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bold; color:#CC0000\" >Cannot write to file, please make the pdf folder writable</span>";
$t77filename = urlencode(str_replace("/","-", str_replace(" ","_", $row_bills['order_number'] . ".pdf")));
$filename = $omis_path . "/pdf/" . $t77filename;
$pdfcode = $pdf->ezOutput();
$fp = fopen($filename,'wb') or die($write_error);
fwrite($fp,$pdfcode) or die($write_error);
fclose($fp) or die($write_error);
$t77To = $_POST['t77to'];
$t77message = $_POST['t77message'];
$t77From = $row_settings['company_email'];
$t77sub = $_POST['subject'];
include('./mail/htmlMimeMail.php');
$mail = new htmlMimeMail();
$attachment = $mail->getFile($filename);
$mail->setText($t77message);
$mail->addAttachment($attachment, $t77filename, 'application/pdf');
$mail->setSubject($t77sub);
$mail->setFrom($t77From);
$result = $mail->send(array($t77To));
if($result == true) {
unlink($filename);
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="refresh" content="3;URL=close.php?<? echo "ref=" . $_GET['ref'] . "&quer=" . $_GET['quer']; ?>" />
<title>Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="31"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
<td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><p><strong>Mail document</strong></p>
</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
<tr>
<td colspan="2"><h1 align="center">Email sent</h1></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html><?
} else {
echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="refresh" content="3;URL=close.php?<? echo "ref=" . $_GET['ref'] . "&quer=" . $_GET['quer']; ?>" />
<title>Mail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="31"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><img src="images/tabletopstart.gif" width="20" height="31" /></td>
<td><table width="100%" height="30" border="0" cellpadding="5" cellspacing="0">
<tr>
<td><p><strong>Mail document</strong></p>
</td>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="tableBorder">
<tr>
<td colspan="2"><h1 align="center">Email not sent</h1></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?
}
}
?>