Source for file billing.php
Documentation is available at billing.php
* Send billing data by email
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* path (bumblebee root)/inc/actions/billing.php
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
require_once 'inc/bb/configreader.php';
require_once 'inc/actions/export.php';
/** ExportType and formatting */
require_once 'inc/export/exporttypes.php';
/** Export formatting codes */
require_once 'inc/exportcodes.php';
/** db interrogation object */
require_once 'inc/formslib/dblist.php';
* Send billing data by email
* Find out what sort of report is required and generate it
* should all group leaders be send the email or just the logged in user
* mail error message (if sending mail went wrong)
* enable additional debugging information for PDF generation
* @param BumblebeeAuth $auth Authorisation object
* @param array $pdata extra state data from the call path
//$this->format = EXPORT_FORMAT_VIEW;
$this->_verb =
'billing';
$this->PD['what'] =
'billing';
$this->reportSet =
array('group' =>
'users',
'bookingbilling' =>
'groups',
'consumablegroup' =>
'users',
//echo $this->emailIndividuals ? 'true' : 'false';
* convenience function to generate a submit button
.
'<input type="radio" name="emailToGroups" value="0" checked="checked" /> '
.
T_('Email report to me').
' ('.
xssqw($this->auth->email).
')'
.
'<input type="radio" name="emailToGroups" value="1" /> '
.
T_('Email report to each group leader')
* get all the data and send it back to the user
foreach ($this->reportSet as $report =>
$pivot) {
$this->PD['pivot'] =
$pivot;
foreach ($groups['groups'] as $g) {
$exportArray->author =
$this->auth->name;
for ($r =
0; $r <
count($lists); $r++
) {
// put a restriction on what to return for this incarnation
$l->unionrestriction[] =
'groups.id = '.
$g; // $g is already qw($g)
$l->restriction[] =
'groups.id = '.
$g; // $g is already qw($g)
$noData =
$noData &&
! count($l->data);
$noGroupData =
$noGroupData &&
! count($l->data);
$this->log('Found '.
count($l->data) .
' rows');
// start rendering the data
$l->outputFormat =
$this->format;
$this->log('Creating new AE');
$this->log('Appending EA');
#preDump(count($exportArray->export));
$exportArray->appendEA($ea);
#preDump(count($exportArray->export));
$pdfExport->filename =
$filename;
$pdfExport->useBigTable =
false;
$pdfExport->writeToFile =
true;
$pdfExport->writeToFile =
false;
$pdfExport->makePDFBuffer();
$pdfs[] =
array('filename' =>
$filename,
'data' =>
$pdfExport->export,
// if there was no data, then record that fact for later reporting.
$nopdfs[] =
array('groupdata' =>
$who);
// dump out the files via email or a zip file....
for ($group=
0; $group<
count($pdfs); $group++
) {
$pdfs[$group]['groupdata']['email'],
$pdfs[$group]['groupdata'],
for ($group=
0; $group<
count($pdfs); $group++
) {
$grouplist[] =
$pdfs[$group]['groupdata']['longname'];
$gpinfo =
array('name' =>
$this->auth->name, 'longname' =>
"\n".
join($grouplist, "\n"));
$s =
'<div class="msgsuccess">'
.
T_('Reports sent by email.').
'</div>';
$s =
'<div class="msgerror">'
.
T_('An error occured sending reports by email.').
' '
?
T_('An unknown error occured.')
$s =
'<div class="msgerror">'
.
T_('<b>Note:</b> no billing data was found for some groups.').
'<br/><br/>';
foreach ($nopdfs as $group) {
$s .=
xssqw($group['groupdata']['name']).
': '
.
xssqw($group['groupdata']['longname']).
'<br/>';
echo
'<div>'.
T_('Regenerate reports:').
'<br/><br/>';
* obtain an appropriate filename for the data export
$name =
$conf->value('billing', 'filename');
* send the PDF to the appropriate person by email
* the logged in user is always included in the To list for their records
* @param string $toName name of the person to receive the email
* @param string $toEmail email addr of recipient
* @param string $group name of the group for which this report is being generated
* @param string $data PDF data to be sent
//$from = $conf->value('billing', 'emailFromName').' <'.$conf->value('main','SystemEmail').'>';
$from =
$conf->value('main', 'SystemEmail');
$returnpath =
$conf->value('main', 'SystemEmail');
$replyto =
$this->auth->name.
' <'.
$this->auth->email.
'>';
$cc =
$this->auth->name.
' <'.
$this->auth->email.
'>'; // CC a copy to the sender
$to =
$toName.
' <'.
$toEmail.
'>';
$recipient_list =
array($this->auth->email, $toEmail);
$id =
'<bumblebee-'.
time().
'-'.
rand().
'@'.
$_SERVER['SERVER_NAME'].
'>';
// Try to work around various PHP bugs in sending mail
// see: http://marc.theaimsgroup.com/?l=php-dev&m=109286883222906&w=2
// http://bugs.php.net/bug.php?id=28976
$server =
$conf->value('email', 'smtp_server');
if ($server) ini_set('SMTP', $server);
$port =
$conf->value('email', 'smtp_port');
if ($port) ini_set('smtp_port', $port);
$headers =
'Return-path: '.
$returnpath .
$eol;
$headers .=
'From: '.
$from .
$eol;
//$headers .= 'To: '.$to .$eol; // automatically added by mail()
//$headers .= 'Cc: '.$cc .$eol; // automatically added by mail() ?
$headers .=
'Reply-To: '.
$replyto.
$eol;
$headers .=
'Message-id: ' .
$id .
$eol;
$textmessage =
$this->_getEmailText($group, $start->dateString(), $stop->dateString());
//$textmessage = 'Please find attached PDF billing summaries for instrument usage.';
$subject =
($conf->value('billing', 'emailSubject')
?
$conf->value('billing', 'emailSubject') :
T_('Instrument usage summary'));
//Having read in the data for the file attachment,
//we need to set up the message headers to send a multipart/mixed message:
// Generate a boundary string
$mime_boundary =
"==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .=
'MIME-Version: 1.0'.
$eol
.
'Content-Type: multipart/mixed;'.
$eol
.
' boundary="'.
$mime_boundary.
'"'.
$eol;
// Add a multipart boundary above the plain message
$message =
'This is a multi-part message in MIME format.'.
$eol .
$eol
.
'--'.
$mime_boundary.
$eol
.
'Content-Type: text/plain; charset="iso-8859-1"'.
$eol
.
'Content-Transfer-Encoding: 7bit' .
$eol.
$eol
.
$textmessage .
$eol.
$eol;
for ($att=
0; $att<
count($data); $att++
) {
//echo strlen($data[$att]['data']);
// Base64 encode the file data
// Add file attachment to the message
$message .=
'--'.
$mime_boundary .
$eol
.
'Content-Type: '.
$data[$att]['mimetype'].
';'.
$eol
.
' name="'.
$data[$att]['filename'].
'"'.
$eol
.
'Content-Disposition: attachment;'.
$eol
.
' filename="'.
$data[$att]['filename'].
'"'.
$eol
.
'Content-Transfer-Encoding: base64'.
$eol.
$eol
$message .=
'--'.
$mime_boundary.
'--'.
$eol;
/* $fh = fopen('/tmp/mail.mbox', 'w');
fwrite($fh, $headers.$eol.$message);
// try to get more useful error messages from the mail() function
$ok =
mail(join(', ', $recipient_list), $subject, $message, $headers);
if ($ok ===
false) { // error sending mail
#print "sent mail to $to, $cc\n";
* Reads the boilerplate text for the email and customise it for this email
* @param string $group name of the group for which this report is being generated
* @param string $start the start date for the report
* @param string $stop the stop date for the report
$fh =
fopen($conf->value('billing', 'emailTemplate'), 'r');
$txt =
fread($fh, filesize($conf->value('billing', 'emailTemplate')));
'/__name__/' =>
$group['name'],
'/__groupname__/' =>
$group['longname'],
Documentation generated on Tue, 06 Mar 2007 10:00:43 +0000 by phpDocumentor 1.3.0