Ejemplo n.º 1
0
 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";
     }
 }