public function sendweeklyAction1() { $weeklyreport = new Application_Model_Report(); $sendReportsTo = $weeklyreport->sendRportTo(); $queueCount = count($sendReportsTo); $sendCount = 0; if (is_array($sendReportsTo)) { if (!empty($sendReportsTo)) { foreach ($sendReportsTo as $user) { $mail = new Zend_Mail(); $mail->setBodyText('Please see the weekly report:'); $mail->setFrom('*****@*****.**', 'Textmunication.com'); $mail->addTo($user['email'], 'Joseph Saunders'); $mail->addCc('*****@*****.**', 'Wais Asefi'); //$mail->addCc('*****@*****.**', 'Robert Gonzalez'); $mail->setSubject('Weekly Reports'); // Get the Excel model $excel = new Application_Model_Excel(); if ($weeklyreport->checkAdminUser($user['id']) and $user['id'] != 187) { if (isset($user['edituser'])) { $excelDataArray = $weeklyreport->getWeeklyReportByEditUser($user['edituser']); //echo "single"; print_r($excelDataArray); exit; $date = date('Ymd'); $excelFileName = "weeklyreport_pollo" . $user['edituser'] . '_' . $date; logWrite("Creating the Excel spreadsheets"); $excel = new Application_Model_Excel(); $excelFile = $excel->create($excelDataArray, $excelFileName); logWrite("Attaching the spreadsheets"); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } else { $excelDataArray = $weeklyreport->getWeeklyReport($user['id']); $date = date('Ymd'); $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date; $excel = new Application_Model_Excel(); $excelFile = $excel->create($excelDataArray, $excelFileName); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } } else { // Get the subscriber datasets $excelDataArray = $weeklyreport->getWeeklyReport(); //echo "<pre>"; print_r($excelDataArray); exit; // Get a date stamp for the file $date = date('Ymd'); // Create our file names $excelFileName = "weeklyreport_clientid" . $user['id'] . '_' . $date; // Log the steps //logWrite("Creating the Excel spreadsheets"); // Make the Excel files for each day $excelFile = $excel->create($excelDataArray, $excelFileName); $at = $mail->createAttachment(file_get_contents($excelFile['path'])); $at->filename = $excelFile['name']; } // Log the steps //logWrite("Preparing to send..."); // Send it off if (!$mail->send()) { echo "MESSAGE NOT SENT"; } else { echo "Message sent"; } } } else { $this->error = "No reports to send"; } } else { $this->error = "Send to report was not properly fetched"; } }
// Name, path, namepsace $loader->addResourceType('model', 'models', 'Model'); // Get our config file $config = new Zend_Config_Ini($apppath . '/application/configs/application.ini'); Zend_Registry::set('config', $config->production); // Because our models need it this way // Get the messages model $weeklyreport = new Application_Model_Report(); // Set up our current timestamp $timestamp = date('Y-m-d H:i:s'); // Log the start of this read logWrite("####################################"); logWrite("Begin batch send: {$timestamp}"); logWrite("------------------------------------"); // Get the queue and counts $sendReportsTo = $weeklyreport->sendRportTo(); $queueCount = count($sendReportsTo); $sendCount = 0; // Log our counts logWrite("Number of persons to whom report will bse sent: {$queueCount}\nBegin send loop:"); //logWrite("") //logWrite("") if (is_array($sendReportsTo)) { if (!empty($sendReportsTo)) { foreach ($sendReportsTo as $user) { $mail = new Zend_Mail(); $mail->setFrom('*****@*****.**', 'Textmunication.com'); $mail->addTo($user['email']); // $mail->addCc('*****@*****.**', 'Wais Asefi'); $mail->setSubject('Weekly Reports'); // Get the Excel model