Пример #1
0
/**
 *
 * @author Paul Heaney
 * @todo TODO document this
*/
function saction_MailPreviousMonthsTransactions()
{
    global $CONFIG;
    /*
         Get todays date
         Subtract one from the month and find last month
         Find the last day of last month
         fope(transactions.php?mode=csv&start=X&end=Y&breakdonw=yes
         mail to people
     TODO need a mechanism to subscribe to scheduled events? Could this be done with a trigger? Hmmhhhhhh
    */
    $currentmonth = date('m');
    $currentyear = date('y');
    if ($currentmonth == 1) {
        $currentyear--;
        $lastmonth = 12;
    } else {
        $lastmonth = $currentmonth - 1;
    }
    $startdate = "{$currentyear}-{$lastmonth}-01";
    // Find last date of previous month, 5 day an arbitary choice
    $lastday = date('t', strtotime('{$currentyear}-{$lastmonth}-05'));
    $enddate = "{$currentyear}-{$lastmonth}-{$lastday}";
    $csv = transactions_report('', $startdate, $enddate, '', 'csv', TRUE);
    $extra_headers = "Reply-To: {$CONFIG['support_email']}\nErrors-To: {$CONFIG['support_email']}\n";
    // TODO should probably be different
    $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . "\n";
    $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}\n";
    //    if ($ccfield != '')  $extra_headers .= "cc: $ccfield\n";
    //    if ($bccfield != '') $extra_headers .= "Bcc: $bccfield\n";
    $extra_headers .= "\n";
    // add an extra crlf to create a null line to separate headers from body
    // this appears to be required by some email clients - INL
    $subject = sprintf($GLOBALS['strBillableIncidentsForPeriodXtoX'], $startdate, $enddate);
    $bodytext = $GLOBALS['strAttachedIsBillableIncidentsForAbovePeriod'];
    $mime = new MIME_mail($CONFIG['support_email'], $CONFIG['billing_reports_email'], html_entity_decode($subject), $bodytext, $extra_headers, '');
    $mime->attach($csv, "Billable report", OCTET, BASE64, "filename=billable_incidents_{$lastmonth}_{$currentyear}.csv");
    return $mime->send_mail();
}
Пример #2
0
    $showfoc = FALSE;
} else {
    $showfoc = TRUE;
}
if (!empty($site) and empty($sites)) {
    $sites = array($site);
}
$sitebreakdown = $_REQUEST['sitebreakdown'];
if (!empty($enddate)) {
    $a = explode("-", $enddateorig);
    $m = mktime(0, 0, 0, $a[1], $a[2] + 1, $a[0]);
    $enddate = date("Y-m-d", $m);
}
if ($sitebreakdown == 'on') {
    $sitebreakdown = TRUE;
} else {
    $sitebreakdown = FALSE;
}
$text = transactions_report($serviceid, $startdate, $enddate, $sites, $display, $sitebreakdown, $showfoc, $focaszero);
if ($display == 'html') {
    include APPLICATION_INCPATH . 'htmlheader.inc.php';
    echo "<h3>{$strTransactions}</h3>";
    echo $text;
    echo "<p align='center'><a href='{$_SERVER['HTTP_REFERER']}'>{$strReturnToPreviousPage}</a></p>";
    include APPLICATION_INCPATH . 'htmlfooter.inc.php';
} elseif ($display == 'csv') {
    header("Content-type: text/csv\r\n");
    header("Content-disposition-type: attachment\r\n");
    header("Content-disposition: filename=transactions.csv");
    echo $text;
}