Exemple #1
0
 public function sendEmail()
 {
     require_once 'modules/Emails/mail.php';
     require_once 'modules/Emails/Emails.php';
     global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $currentModule;
     $recipientEmails = $this->getRecipientEmails();
     $emails_to = '';
     foreach ($recipientEmails as $name => $email) {
         $emails_to .= $email . ',';
     }
     $emails_to = trim($emails_to, ',');
     $currentTime = date('Y-m-d H:i:s');
     $subject = $this->reportname . ' - ' . $currentTime . ' (' . DateTimeField::getDBTimeZone() . ')';
     $contents = getTranslatedString('LBL_AUTO_GENERATED_REPORT_EMAIL', $currentModule) . '<br/><br/>';
     $contents .= '<b>' . getTranslatedString('LBL_REPORT_NAME', $currentModule) . ' :</b> ' . $this->reportname . '<br/>';
     $contents .= '<b>' . getTranslatedString('LBL_DESCRIPTION', $currentModule) . ' :</b><br/>' . $this->reportdescription . '<br/><br/>';
     $baseFileName = utf8_decode(preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $this->reportname) . '_' . preg_replace('/[^a-zA-Z0-9_-\\s]/', '', date('YmdHis')));
     $oReportRun = new ReportRun($this->id);
     $reportFormat = $this->scheduledFormat;
     $attachments = array();
     if ($reportFormat == 'pdf' || $reportFormat == 'both') {
         $fileName = $baseFileName . '.pdf';
         $filePath = 'storage/' . $fileName;
         $attachments[$fileName] = $filePath;
         $_REQUEST['filename_hidden_pdf'] = $filePath;
         $pdf = $oReportRun->getReportPDF(NULL);
         $pdf->Output($filePath, 'F');
     }
     if ($reportFormat == 'excel' || $reportFormat == 'both') {
         $fileName = $baseFileName . '.xls';
         $filePath = 'storage/' . $fileName;
         $attachments[$fileName] = $filePath;
         $_REQUEST['filename_hidden_xls'] = $filePath;
         $oReportRun->writeReportToExcelFile($filePath, NULL);
     }
     $sendifempty = GlobalVariable::getVariable('Report_Send_Scheduled_ifEmpty', 1);
     if ($sendifempty or $oReportRun->number_of_rows > 0) {
         $mail_status = send_mail('Emails', $emails_to, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents, '', '', 'attReports');
         foreach ($attachments as $attachmentName => $path) {
             unlink($path);
         }
     }
 }
Exemple #2
0
require_once "modules/Reports/Reports.php";
global $tmp_dir, $root_directory;
$fname = tempnam($root_directory . $tmp_dir, "merge2.xls");
# Write out the data
$reportid = vtlib_purify($_REQUEST["record"]);
$oReport = new Reports($reportid);
$filtercolumn = $_REQUEST['stdDateFilterField'];
$startdate = $_REQUEST['startdate'];
$enddate = $_REQUEST['enddate'];
if (!empty($startdate) && !empty($enddate) && $startdate != "0000-00-00" && $enddate != "0000-00-00") {
    $filter = $_REQUEST['stdDateFilter'];
    $date = new DateTimeField($_REQUEST['startdate']);
    $endDate = new DateTimeField($_REQUEST['enddate']);
    $startdate = $date->getDBInsertDateValue();
    //Convert the user date format to DB date format
    $enddate = $endDate->getDBInsertDateValue();
    //Convert the user date format to DB date format
}
$oReportRun = new ReportRun($reportid);
$filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate);
$oReportRun->writeReportToExcelFile($fname, $filterlist);
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
    header("Pragma: public");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
}
header("Content-Type: application/x-msexcel");
header("Content-Length: " . @filesize($fname));
header('Content-disposition: attachment; filename="Reports.xls"');
$fh = fopen($fname, "rb");
fpassthru($fh);
//unlink($fname);
 public function sendEmail()
 {
     global $currentModule;
     require_once 'vtlib/Vtiger/Mailer.php';
     $vtigerMailer = new Vtiger_Mailer();
     $recipientEmails = $this->getRecipientEmails();
     foreach ($recipientEmails as $name => $email) {
         $vtigerMailer->AddAddress($email, $name);
     }
     $currentTime = date('Y-m-d H:i:s');
     $subject = $this->reportname . ' - ' . $currentTime . ' (' . DateTimeField::getDBTimeZone() . ')';
     $contents = getTranslatedString('LBL_AUTO_GENERATED_REPORT_EMAIL', $currentModule) . '<br/><br/>';
     $contents .= '<b>' . getTranslatedString('LBL_REPORT_NAME', $currentModule) . ' :</b> ' . $this->reportname . '<br/>';
     $contents .= '<b>' . getTranslatedString('LBL_DESCRIPTION', $currentModule) . ' :</b><br/>' . $this->reportdescription . '<br/><br/>';
     $vtigerMailer->Subject = $subject;
     $vtigerMailer->Body = $contents;
     $vtigerMailer->ContentType = "text/html";
     $baseFileName = preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $this->reportname) . '_' . preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $currentTime);
     $oReportRun = new ReportRun($this->id);
     $reportFormat = $this->scheduledFormat;
     $attachments = array();
     if ($reportFormat == 'pdf' || $reportFormat == 'both') {
         $fileName = $baseFileName . '.pdf';
         $filePath = 'storage/' . $fileName;
         $attachements[$fileName] = $filePath;
         $pdf = $oReportRun->getReportPDF();
         $pdf->Output($filePath, 'F');
     }
     if ($reportFormat == 'excel' || $reportFormat == 'both') {
         $fileName = $baseFileName . '.xls';
         $filePath = 'storage/' . $fileName;
         $attachements[$fileName] = $filePath;
         $oReportRun->writeReportToExcelFile($filePath);
     }
     foreach ($attachements as $attachmentName => $path) {
         $vtigerMailer->AddAttachment($path, $attachmentName);
     }
     $vtigerMailer->Send(true);
     foreach ($attachements as $attachmentName => $path) {
         unlink($path);
     }
 }