public function sendmail() { $this->checkPermission(EMAIL_PILOTS); echo '<h3>Sending email</h3>'; if ($this->post->subject == '' || trim($this->post->message) == '') { $this->set('message', 'You must enter a subject and message!'); $this->render('core_error.php'); return; } if (count($this->post->groups) == 0) { $this->set('message', 'You must select groups to send to!'); $this->render('core_error.php'); return; } echo 'Sending email...<br />'; $pilotarray = array(); //Begin the nice long assembly of e-mail addresses foreach ($this->post->groups as $groupid) { if ($groupid == 'all') { $all_pilots = PilotData::findPilots(array()); foreach ($all_pilots as $pilot) { $pilotarray[$pilot->pilotid] = $pilot; } break; } else { $tmp = PilotGroups::getUsersInGroup($groupid); if (count($tmp) == 0 || !is_array($tmp)) { continue; } foreach ($tmp as $pilot) { $pilotarray[$pilot->pilotid] = $pilot; } } } $subject = DB::escape($this->post->subject); $message = stripslashes($this->post->message) . PHP_EOL . PHP_EOL; # Do some quick fixing of obvious formatting errors $message = str_replace('<br>', '<br />', $message); foreach ($pilotarray as $pilot) { echo 'Sending for ' . $pilot->firstname . ' ' . $pilot->lastname . '<br />'; # Variable replacements $send_message = str_replace('{PILOT_FNAME}', $pilot->firstname, $message); $send_message = str_replace('{PILOT_LNAME}', $pilot->lastname, $send_message); $send_message = str_replace('{PILOT_ID}', PilotData::GetPilotCode($pilot->code, $pilot->pilotid), $send_message); $send_message = utf8_encode($send_message); Util::SendEmail($pilot->email, $subject, $send_message); } echo 'Complete!'; LogData::addLog(Auth::$userinfo->pilotid, 'Sent pass mail'); return; }
/** * Get all the users from a group * * @param mixed $groupid Group name or group ID * @return array Return the array with the pilot details * */ public static function getUsersInGroup($groupid) { return PilotGroups::getUsersInGroup($groupid); }
?> "> <p> <strong>Subject: </strong> <input type="text" name="subject" value="" /> </p> <p> <strong>Message:</strong> </p> <p> <textarea name="message" id="editor" style="width: 600px; height: 250px;">To: {PILOT_FNAME} {PILOT_LNAME}, </textarea> </p> <p>Select groups to send to:<br /> <?php $total = StatsData::PilotCount(); ?> <input type="checkbox" name="groups[]" value="all" />All Pilots (<?php echo $total; ?> pilots)<br /> <?php foreach ($allgroups as $group) { $total = count(PilotGroups::getUsersInGroup($group->groupid)); echo "<input type=\"checkbox\" name=\"groups[]\" value=\"{$group->groupid}\" />{$group->name} - ({$total} pilots)<br />"; } ?> </p> <p> <input type="submit" name="submit" value="Send Email" /> </p> </form>