Файл: adultscript-2.0.3-pro/files/admin/modules/email/components/send.php
Строк: 51
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_email_send
{
public function __construct()
{
}
public function render()
{
$cfg = VF::cfg('core.config');
$db = VF::factory('database');
$errors = array();
$messages = array();
$email = array('emails' => '', 'from' => $cfg['email_admin'], 'subject' => '', 'message' => '');
if (isset($_GET['email']) && VValid::email(trim($_GET['email']))) {
$email['emails'] = trim($_GET['email']);
}
if (isset($_POST['submit_send_email'])) {
$filter = VF::factory('filter');
$emails = $filter->get('emails');
$from = $filter->get('from');
$subject = $filter->get('subject');
$message = trim($_POST['message']);
if ($emails == '') {
$errors[] = 'Please enter at least one receiver email address!';
} elseif ($emails == 'all') {
$db->query("SELECT email FROM #__user WHERE verified = '1'");
$rows = $db->fetch_rows();
$receivers = array();
foreach ($rows as $row) {
$receivers[] = $row['email'];
}
} elseif ($emails == 'registered') {
$group_id = VAuth::get_group_id('Registered');
$db->query("SELECT email
FROM #__user
WHERE group_id = ".$group_id."
AND verified = '1'");
$rows = $db->fetch_rows();
$receivers = array();
foreach ($rows as $row) {
$receivers[] = $row['email'];
}
} elseif ($emails == 'premium') {
$group_id = VAuth::get_group_id('Premium');
$db->query("SELECT email
FROM #__user
WHERE group_id = ".$group_id."
AND verified = '1'");
$rows = $db->fetch_rows();
$receivers = array();
foreach ($rows as $row) {
$receivers[] = $row['email'];
}
} else {
if (strpos($emails, ',') !== FALSE) {
$receivers = explode(',', str_replace(' ', '', $emails));
} else {
$receivers = array($emails);
}
$valid = array();
$invalid = array();
foreach ($receivers as $receiver) {
if (VValid::email($receiver)) {
$valid[] = $receiver;
} else {
$invalid[] = $receiver;
}
}
if ($invalid) {
$errors[] = 'One or more email addresses are not valid ('.implode(', ', $invalid).')!';
} else {
$email['emails'] = implode(',', $valid);
}
}
if ($from == '') {
$errors[] = 'Please enter the sender emails address!';
} elseif (!VValid::email($from)) {
$errors[] = 'Sender email is not a valid email address!';
} else {
$email['from'] = $from;
}
if ($subject == '') {
$errors[] = 'Please enter the email subject!';
} else {
$email['subject'] = $subject;
}
if ($message == '') {
$errors[] = 'Please enter the email message!';
} else {
$email['message'] = $message;
}
if (!$errors) {
if ($emails == 'all' ) {
$random = VText::random();
$array = array(
'from' => $from,
'receivers' => $receivers,
'subject' => $subject,
'message' => $message
);
VFile::write(TMP_DIR.'/emails/'.$random.'.php', serialize($array));
$cmd = VF::cfg_core_item('php_cli_path').' '.ADMIN_DIR.'/modules/email/scripts/send.php '.$random;
exec(escapeshellcmd($cmd). ' >/dev/null &');
$messages[] = 'Email will be sent to all users in background!';
} else {
$mail = VF::factory('email');
$mail->From = $from;
if ($from == $cfg['email_admin']) {
$mail->FromName = $cfg['site_name'];
}
$mail->Sender = $from;
$mail->AddReplyTo($from);
$mail->Subject = $subject;
$mail->AltBody = $message;
$mail->Body = nl2br($message);
foreach ($valid as $address) {
$mail->AddAddress($address);
$mail->Send();
$mail->ClearAddresses();
}
$messages[] = 'Email sent!';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'email_send';
$tpl->meta_title = 'Admin::Email::Send';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->email = $email;
$tpl->load(array('header', 'email_send', 'footer'));
$tpl->display();
}
}
?>