Advertisement
Guest User

MassMailer.php

a guest
Aug 24th, 2011
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.87 KB | None | 0 0
  1. <?php
  2. /**
  3.  * phpVMS - Virtual Airline Administration Software
  4.  * Copyright (c) 2008 Nabeel Shahzad
  5.  * For more information, visit www.phpvms.net
  6.  *  Forums: http://www.phpvms.net/forum
  7.  *  Documentation: http://www.phpvms.net/docs
  8.  *
  9.  * phpVMS is licenced under the following license:
  10.  *   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
  11.  *   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  12.  *
  13.  * @author Nabeel Shahzad
  14.  * @copyright Copyright (c) 2008, Nabeel Shahzad
  15.  * @link http://www.phpvms.net
  16.  * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
  17.  *
  18.  *This particular section was built by Cale Cunningham; basically a modified version
  19.  *of the contact form found in the core.
  20.  */
  21.  
  22. class MassMailer extends CodonModule
  23. {
  24.    
  25.     public function HTMLHead()
  26.     {
  27.         $this->set('sidebar', 'sidebar_mailer.tpl');
  28.     }
  29.    
  30.     public function index()
  31.     {
  32.         $this->set('allgroups', PilotGroups::getAllGroups());
  33.         $this->render('mailer_form.tpl');
  34.     }
  35.     #------------Individual Pilot Mailing------------------------------------------------------------
  36.     #Copyrights dimitris phpvms forum
  37.     public function mail_pilot() {
  38.         $this->render('mailer_mailpilot_form.tpl');    
  39.     }
  40.     public function sendmail_pilot(){
  41.         echo '<h3>Sending email...</h3>';
  42.         if($this->post->subject == '' || trim($this->post->message) == '')
  43.         {
  44.             $this->set('message', 'You must enter a subject and message!');
  45.             $this->render('core_error.tpl');
  46.             return;
  47.         }
  48.         $subject = DB::escape($this->post->subject);
  49.         $emailp  = DB::escape($this->post->email_pilot);
  50.         $message = stripslashes($this->post->message). PHP_EOL . PHP_EOL;
  51.         $message = str_replace('<br>', '<br />', $message);
  52.         Util::SendEmail($emailp, $subject, $message);
  53.         echo 'Completed! Email sent.';
  54.         LogData::addLog(Auth::$userinfo->pilotid, 'Sent a private mail');
  55.         return;
  56.     }
  57.     #----------------------------------------------------------------------------------------------
  58.     public function sendmail()
  59.     {
  60.         echo '<h3>Sending email</h3>';
  61.         if($this->post->subject == '' || trim($this->post->message) == '')
  62.         {
  63.             $this->set('message', 'You must enter a subject and message!');
  64.             $this->render('core_error.tpl');
  65.             return;
  66.         }
  67.        
  68.         if(count($this->post->groups) == 0)
  69.         {
  70.             $this->set('message', 'You must select groups to send to!');
  71.             $this->render('core_error.tpl');
  72.             return;
  73.         }
  74.        
  75.         echo 'Sending email...<br />';
  76.        
  77.         $pilotarray = array();
  78.         //Begin the nice long assembly of e-mail addresses
  79.         foreach($this->post->groups as $groupid)
  80.         {
  81.             if($groupid == 'all')
  82.             {
  83.                 $all_pilots = PilotData::findPilots(array());
  84.                 foreach($all_pilots as $pilot)
  85.                 {
  86.                     $pilotarray[$pilot->pilotid] = $pilot;
  87.                 }
  88.                
  89.                 break;
  90.             }
  91.             else
  92.             {
  93.                 $tmp = PilotGroups::getUsersInGroup($groupid);
  94.                 if(count($tmp) == 0 || ! is_array($tmp))
  95.                 {
  96.                     continue;
  97.                 }
  98.                
  99.                 foreach($tmp as $pilot)
  100.                 {
  101.                     $pilotarray[$pilot->pilotid] = $pilot;
  102.                 }
  103.             }
  104.         }
  105.        
  106.         $subject = DB::escape($this->post->subject);
  107.         $message = stripslashes($this->post->message). PHP_EOL . PHP_EOL;
  108.        
  109.         # Do some quick fixing of obvious formatting errors
  110.         $message = str_replace('<br>', '<br />', $message);
  111.         foreach($pilotarray as $pilot)
  112.         {
  113.             echo 'Sending for '.$pilot->firstname.' '.$pilot->lastname.'<br />';
  114.            
  115.             # Variable replacements
  116.             $send_message = str_replace('{PILOT_FNAME}', $pilot->firstname, $message);
  117.             $send_message = str_replace('{PILOT_LNAME}', $pilot->lastname, $send_message);
  118.             $send_message = str_replace('{PILOT_ID}', PilotData::GetPilotCode($pilot->code, $pilot->pilotid), $send_message);
  119.             $send_message = utf8_encode($send_message);
  120.            
  121.             Util::SendEmail($pilot->email, $subject, $send_message);
  122.         }
  123.        
  124.         echo 'Complete!';
  125.        
  126.         LogData::addLog(Auth::$userinfo->pilotid, 'Sent pass mail');
  127.         return;
  128.     }
  129.    
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement