Added : New mass email
This commit is contained in:
parent
efaa5fc765
commit
871361a98e
5 changed files with 505 additions and 199 deletions
|
@ -16,91 +16,40 @@ if(!empty($_GET['email'])){
|
|||
Assign('email',$_GET['email']);
|
||||
}
|
||||
|
||||
//Sending Message To Multiple Users
|
||||
if(isset($_POST['send_to_all']))
|
||||
//Creating an mass email
|
||||
if(isset($_POST['create_email']))
|
||||
{
|
||||
$from = mysql_clean($_POST['from']);
|
||||
$subject = mysql_clean($_POST['subj']);
|
||||
$message = $_POST['msg'];
|
||||
|
||||
$uarray = array();
|
||||
|
||||
if(empty($from))
|
||||
e("From field was empty");
|
||||
if(empty($subject))
|
||||
e("Subject field was empty");
|
||||
if(empty($message))
|
||||
e("Message field was empty");
|
||||
|
||||
//Checking if admin wants to send email to active users only....
|
||||
if($_POST['active']!='')
|
||||
$uarray['status'] = $_POST['active'];
|
||||
//Checking if admin wants to send email to banned or unbanned users only...
|
||||
if($_POST['ban']!='')
|
||||
$uarray['ban'] = $_POST['ban'];
|
||||
//Checking if admin wants to send email to specific leveled users
|
||||
if($_POST['level']!='')
|
||||
$uarray['level'] = $_POST['level'];
|
||||
//Checkinf if admin wants to send email to specfic categorized users
|
||||
if($_POST['category']!='')
|
||||
$uarray['category'] = $_POST['category'];
|
||||
|
||||
|
||||
if(!error())
|
||||
if($cbemail->add_mass_email())
|
||||
{
|
||||
$users = get_users($uarray);
|
||||
foreach($users as $user)
|
||||
{
|
||||
$keys = array("[username]","[email]","[datejoined]","[avcode]");
|
||||
$rplc = array($user['username'],$user['email'],$user['doj'],$user['avcode']);
|
||||
$message = nl2br(str_replace($keys, $rplc, $message));
|
||||
//send_email($from,$data['email'],$subject,$msg);
|
||||
|
||||
cbmail(array('from'=>$from,'to'=>$user['email'],'subject'=>$subject,'content'=>$message));
|
||||
}
|
||||
e('Your Email has Been Sent To All Users','m');
|
||||
unset($_POST);
|
||||
}
|
||||
}
|
||||
|
||||
//Deleting Email
|
||||
if(isset($_GET['delete']))
|
||||
{
|
||||
$del = mysql_clean($_GET['delete']);
|
||||
$cbemail->action($del,'delete');
|
||||
}
|
||||
|
||||
|
||||
//Send Message To Individual
|
||||
if(isset($_POST['send_mail'])){
|
||||
$from = mysql_clean($_POST['from']);
|
||||
$subject = mysql_clean($_POST['subj']);
|
||||
$message = $_POST['msg'];
|
||||
$users = $_POST['to'];
|
||||
$new_users = explode(',',$users);
|
||||
|
||||
if(empty($from))
|
||||
e("From field was empty");
|
||||
if(empty($subject))
|
||||
e("Subject field was empty");
|
||||
if(empty($message))
|
||||
e("Message field was empty");
|
||||
if(empty($users))
|
||||
e("Users field was empty");
|
||||
|
||||
if(!error())
|
||||
//Sending Email
|
||||
if(isset($_GET['send_email']))
|
||||
{
|
||||
$eId = mysql_clean($_GET['send_email']);
|
||||
$email = $cbemail->get_email($eId);
|
||||
if($email)
|
||||
{
|
||||
foreach($new_users as $theuser)
|
||||
{
|
||||
$user = $userquery->get_user_details($theuser);
|
||||
if($user)
|
||||
{
|
||||
$keys = array("[username]","[email]","[datejoined]","[avcode]");
|
||||
$rplc = array($user['username'],$user['email'],$user['doj'],$user['avcode']);
|
||||
$msg = nl2br(str_replace($keys, $rplc, $message));
|
||||
//send_email($from,$data['email'],$subject,$msg);
|
||||
$msgs = $cbemail->send_emails($email);
|
||||
assign('msgs',$msgs);
|
||||
|
||||
cbmail(array('from'=>$from,'to'=>$user['email'],'subject'=>$subject,'content'=>$msg));
|
||||
}
|
||||
}
|
||||
e('Your Email has Been Sent To Sepecified users','m');
|
||||
$email = $cbemail->get_email($eId);
|
||||
assign('send_email',$email);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Getting List of emails
|
||||
$emails = $cbemail->get_mass_emails();
|
||||
assign('emails',$emails);
|
||||
|
||||
//Category Array...
|
||||
if(is_array($_POST['category']))
|
||||
|
|
|
@ -1,128 +1,228 @@
|
|||
<h2>Mass Email</h2>
|
||||
<h2>Send email to users</h2>
|
||||
|
||||
<p><br />
|
||||
Send mass email to your users with our new and updated email manager
|
||||
</p>
|
||||
|
||||
|
||||
<table width="800" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="10" align="center" valign="middle" class="left_head"> </td>
|
||||
<td class="head">Send Email To All Users</td>
|
||||
<td width="50" class="right_head"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
{if $send_email==""}
|
||||
<form name="mass_email" method="post" action="mass_email.php?action=new">
|
||||
<div class="cb_title">
|
||||
Email manager
|
||||
</div>
|
||||
|
||||
<div style="padding:5px" class="cb_form">
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>Email to send at once</strong>
|
||||
<br />loop size of emails when mass emails are sent</div>
|
||||
<div class="cb_fieldR"><input name="loop_size" type="text" value="500"/></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>From</strong>
|
||||
<br />Enter email address to tell user who sent it</div>
|
||||
<div class="cb_fieldR"><input type="text" name="from" value="{'from'|post}"/></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>Subject</strong>
|
||||
<br />Enter your email subject</div>
|
||||
<div class="cb_fieldR"><input type="text" name="subject" value="{'subject'|post}"//></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>Message</strong>
|
||||
<br />Enter your email message</div>
|
||||
<div class="cb_fieldR"><textarea name="message" cols="50" rows="5" draggable="true"></textarea><br />
|
||||
{literal}You can use {username}, {userid}, {email}, {datejoined},{avcode} in your message{/literal}</div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont" style="display:none">
|
||||
<div class="cb_fieldL"><strong>Email delivery method</strong>
|
||||
<br />Please choose weather you want browser to send emails or create a background process </div>
|
||||
<div class="cb_fieldR"><label><input type="radio" name="method" value="browser" checked="checked" />Browser</label>
|
||||
<label><input type="radio" name="method" value="background" />Background Process</label></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="cb_title" style="background-color:#FFFFFF; margin-top:10px">
|
||||
More options
|
||||
</div>
|
||||
|
||||
<div style="padding:5px" class="cb_form">
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>Active status</strong>
|
||||
<br />Choose weather to send to active users or non active</div>
|
||||
<div class="cb_fieldR"><label><input name="active" type="radio" value="yes" checked="checked" />Yes</label>
|
||||
<label><input type="radio" name="active" value="no" />No</label><label><input name="active" type="radio" value="any" />Any</label></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>Banned status</strong>
|
||||
<br />Send email to banned users</div>
|
||||
<div class="cb_fieldR"><label><input type="radio" name="ban" value="yes" />Yes</label>
|
||||
<label><input name="ban" type="radio" value="no" checked="checked" />No</label>
|
||||
<label><input name="ban" type="radio" value="any" />Any</label></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>User level</strong>
|
||||
<br />Choose which user level to send email</div>
|
||||
<div class="cb_fieldR">
|
||||
|
||||
<form name="send_to_all" method="post">
|
||||
<table width="800" border="0" cellpadding="2" cellspacing="0" class="block">
|
||||
<tr>
|
||||
<td width="200" align="right" valign="top"><span class="td_body">From</span></td>
|
||||
<td valign="top"><input name="from" type="text" id="from" value="{'from'|post}" size="45"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top"><span class="td_body">Subject</span></td>
|
||||
<td valign="top"><span class="td_body">
|
||||
<input name="subj" type="text" id="subj" value="{'subj'|post}" size="45">
|
||||
</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top"><span class="td_body">Message </span></td>
|
||||
<td valign="top"><textarea name="msg" cols="45" rows="6" id="msg">{'msg'|post}</textarea>
|
||||
<span class="td_body">
|
||||
<label><br>
|
||||
Keywords<br>
|
||||
[username] [email] [datejoined]</label>
|
||||
</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top">Active only</td>
|
||||
<td align="left" valign="top"><select name="active" id="active" class="input">
|
||||
<option value="" ></option>
|
||||
<option value="Ok" {if $smarty.post.active=='Ok'} selected="selected"{/if}>Yes</option>
|
||||
<option value="ToActivate" {if $smarty.post.active=='no'} selected="selected"{/if}>No</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top">User Level</td>
|
||||
<td align="left" valign="top"><select name="level" id="level">
|
||||
<option value="" ></option>
|
||||
{assign var=levels value=$userquery->get_levels()}
|
||||
{foreach from=$levels item=level}
|
||||
{if $level.user_level_id !='4'}
|
||||
<option value="{$level.user_level_id}" {if $smarty.post.level==$level.user_level_id} selected="selected"{/if}>{$level.user_level_name}</option>
|
||||
<label style="width:120px; float:left"><input type='checkbox'
|
||||
name="level[]" value="{$level.user_level_id}" checked="checked"/>{$level.user_level_name}</label>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top">Banned</td>
|
||||
<td align="left" valign="top"><select name="ban" id="ban" class="input">
|
||||
<option value="" ></option>
|
||||
<option value="yes" {if $smarty.post.ban=='yes'} selected="selected"{/if}>Yes</option>
|
||||
<option value="no" {if $smarty.post.ban=='no'} selected="selected"{/if}>No</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top">Category</td>
|
||||
<td align="left" valign="top">{if $cat_array}{$formObj->createField($cat_array)}{/if}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"> </td>
|
||||
<td align="right" valign="top"><input type="submit" name="send_to_all" value="Send Email" class="button" id="send_to_all" ></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="cb_field_cont">
|
||||
<div class="cb_fieldL"><strong>User category</strong>
|
||||
<br />User category</div>
|
||||
<div class="cb_fieldR">
|
||||
{assign var=cats value=$userquery->get_categories()}
|
||||
{foreach from=$cats item=cat}
|
||||
|
||||
<label style="width:120px; float:left">
|
||||
<input type='checkbox' name="cat[]" value="{$cat.category_id}" checked="checked"/>{$cat.category_name}</label>
|
||||
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="cb_field_cont" style="display:none">
|
||||
<div class="cb_fieldL"><strong>Send to specified users</strong>
|
||||
<br />Enter emails or usernames, seperate by commas,leave blank to follow criteria given above</div>
|
||||
<div class="cb_fieldR"><textarea name="users" cols="50" rows="5" draggable="true" id="users"></textarea></div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<input name="create_email" type="submit" class="button" id="create" value="Create email" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
<div style="height:30px"></div>
|
||||
<div class="cb_title">
|
||||
Mass email campains
|
||||
</div>
|
||||
{if $emails}
|
||||
{foreach from=$emails item=email}
|
||||
<div class="cb_row">
|
||||
<div>
|
||||
<strong>{$email.email_subj}</strong> —
|
||||
<a href="?send_email={$email.id}">Send Email</a> |
|
||||
<a href="?delete={$email.id}">Delete</a> | <a href="javascript:void(0)" onclick="$('#mytest').dialog('open')">View</a><br />
|
||||
<span style="font-size:11px; color:#666"><strong>From</strong>
|
||||
: {$email.email_from} • <strong>Method</strong> : {$email.method}
|
||||
• <strong>Sent</strong> : {$email.sent} • <strong>Status</strong> : {$email.status}</span><br />
|
||||
{$email.date_added|niceTime}
|
||||
</div>
|
||||
<div id="mytest" style="display:none" class="email_content">{$email.email_msg|nl2br}</div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
{/foreach}
|
||||
{else}
|
||||
<div class="cb_row">
|
||||
<span style="font-weight:bold">No email was campaign found</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
$( ".email_content" ).dialog({autoOpen:false,modal:true});
|
||||
</script>
|
||||
{/literal}
|
||||
|
||||
|
||||
{else}
|
||||
|
||||
<div class="cb_title">
|
||||
Sending emails — <a href="mass_email.php">Go back to mass email page</a></div>
|
||||
{if $send_email}
|
||||
{assign var=email value=$send_email}
|
||||
<div class="cb_row">
|
||||
<div>
|
||||
<strong>{$email.email_subj}</strong> —
|
||||
<a href="javascript:void(0)" onclick="$('#mytest').dialog('open')">View</a><br />
|
||||
<span style="font-size:11px; color:#666"><strong>From</strong>
|
||||
: {$email.email_from} • <strong>Method</strong> : {$email.method}
|
||||
• <strong>Sent</strong> : {$email.sent} • <strong>Status</strong> : {$email.status}</span><br />
|
||||
{$email.date_added|niceTime}
|
||||
</div>
|
||||
<div id="mytest" style="display:none" class="email_content">{$email.email_msg|nl2br}</div>
|
||||
<div class="clear clearfix"></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div style="height:10px"></div>
|
||||
{$eh->message_list.0}
|
||||
{if $msgs}
|
||||
<ul>
|
||||
{foreach from=$msgs item=msg}
|
||||
<li>{$msg}</li>
|
||||
{/foreach}
|
||||
</ul>
|
||||
{/if}
|
||||
|
||||
|
||||
<div style="height:20px"></div>
|
||||
{if ($email.total==$email.sent && $email.sent>0)|| $email.status=='completed'}
|
||||
<div style="background-color:#fff9e3; border:1px solid #e1d5a8; padding:8px; font-size:12px; margin-left:5px">
|
||||
Email has been sent to {$email.total} users
|
||||
</div>
|
||||
{else}
|
||||
<div style="background-color:#fff9e3; border:1px solid #e1d5a8; padding:8px; font-size:12px; margin-left:5px">
|
||||
Pelase wait, do not close this window...
|
||||
|
||||
(<a href="javascript:void(0);" id="pause" onclick="pause=true; $('#pause,#resume').toggle()">pause</a><a href="javascript:void(0);" onclick="$(window.location).attr('href', '?send_email='+email_id+'&index='+start_index); $('#pause,#resume').toggle()" id="resume" style="display:none">resume</a>)
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var start_index = '{$email.start_index}';
|
||||
var email_id = '{$email.id}';
|
||||
var pause = false;
|
||||
{literal}$(document).oneTime(5000,function(){
|
||||
if(!pause)
|
||||
$(window.location).attr('href', '?send_email='+email_id+'&index='+start_index)});{/literal}
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{/if}
|
||||
|
||||
{literal}
|
||||
<script type="text/javascript">
|
||||
$( ".email_content" ).dialog({autoOpen:false,modal:true});
|
||||
</script>
|
||||
{/literal}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<table width="800" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td width="10" align="center" valign="middle" class="left_head"> </td>
|
||||
<td class="head">Send Email To Specific Users</td>
|
||||
<td width="50" class="right_head"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<form name="send_to_selected" method="post">
|
||||
<table width="800" border="0" cellpadding="2" cellspacing="0" class="block">
|
||||
<tr>
|
||||
<td width="200" align="right" valign="top"><span class="td_body">From</span></td>
|
||||
<td valign="top"><input name="from" type="text" id="from" value="{'from'|post}" size="45"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top"><span class="td_body">Subject</span></td>
|
||||
<td valign="top"><span class="td_body">
|
||||
<input name="subj" type="text" id="subj" value="{'subj'|post}" size="45">
|
||||
</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top"><span class="td_body">Send To </span></td>
|
||||
<td valign="top"><span class="td_body">
|
||||
<input name="to" type="text" id="to" value="{'to'|post}" size="45">
|
||||
<br>
|
||||
Seperate Usernames or Emails by comma ie arslan, zohaib@thewebsite.com</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right" valign="top"><span class="td_body">Message </span></td>
|
||||
<td valign="top"><textarea name="msg" cols="45" rows="6" id="msg">{'msg'|post}</textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"> </td>
|
||||
<td align="left" valign="top"><span class="td_body">
|
||||
<label>Keywords<br>
|
||||
[username] [firstname] [lastname] [email] [datejoined]<br>
|
||||
eg Hello [username] </label>
|
||||
</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top"> </td>
|
||||
<td align="right" valign="top"><input type="submit" name="send_mail" value="Send Email" class="button" ></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
{/if}
|
|
@ -351,3 +351,14 @@ li.myAdminList input[disabled=disabled].disabled { font:normal 11px Tahoma; padd
|
|||
.li_links ul{display:block;}
|
||||
.li_links a{display:block; padding:3px; background-color:#fff;font-size:13px}
|
||||
.li_links li:nth-child(2n) a{ background-color:#eee}
|
||||
|
||||
.cb_title{background-color:#f3f3f3; font-size:12px; font-weight:bold; color:#333; border-bottom:1px solid #cccccc; height:27px; line-height:27px; padding-left:5px}
|
||||
.cb_form select,.cb_form input,.cb_form textarea{border:1px solid #bbb; font-size:11px; width:200px; color:#333; padding:3px}
|
||||
.cb_form textarea{width:auto}
|
||||
.cb_form .cb_fieldL{float:left; width:300px; margin-right:10px}
|
||||
.cb_form .cb_fieldR{float:left; width:400px;}
|
||||
.cb_form .cb_field_cont{margin-bottom:10px;}
|
||||
.cb_form input[type=radio],.cb_form input[type=checkbox]{width:auto !important}
|
||||
.cb_form input[type=submit]{width:auto !important; color:#fff; border:1px solid #003}
|
||||
|
||||
.cb_row{margin:5px 0px; padding-left:5px}
|
|
@ -128,9 +128,255 @@ class CBEmail
|
|||
}
|
||||
|
||||
/**
|
||||
* Function used to send email via smtp
|
||||
* Mass Email
|
||||
*/
|
||||
//functio cbemail_smtp($to,$from,$subj,$message,
|
||||
function add_mass_email($array=NULL)
|
||||
{
|
||||
if(!$array)
|
||||
$array = $_POST;
|
||||
|
||||
global $userquery,$db;
|
||||
|
||||
$from = $array['from']; unset($array['from']);
|
||||
$loop = $array['loop_size'];
|
||||
$subj = $array['subject']; unset($array['subject']);
|
||||
$msg = $array['message']; unset($array['message']);
|
||||
$users = $array['users']; unset($array['users']);
|
||||
$method = $array['method']; unset($array['method']);
|
||||
|
||||
$settings = $array;
|
||||
|
||||
unset($array);
|
||||
|
||||
if(!isValidEmail($from))
|
||||
e(lang("Please enter valid email in 'from' field"));
|
||||
if(!is_numeric($loop) || $loop <1 || $loop>10000)
|
||||
e(lang("Please enter valid numeric value from 1 to 10000 for loop size"));
|
||||
if(!$subj)
|
||||
e(lang("Please enter a valid subject for your email"));
|
||||
if(!$msg)
|
||||
e(lang("Email body was empty, please enter your email content"));
|
||||
|
||||
if(!error())
|
||||
{
|
||||
$db->insert(tbl('mass_emails'),array('email_subj','email_from','email_msg','configs','users','method','status','date_added'),
|
||||
array($subj,$from,'|no_mc|'.$msg,'|no_mc|'.json_encode($settings),$users,$method,'pending',now()));
|
||||
|
||||
e("Mass email has been added","m");
|
||||
return true;
|
||||
}else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* function used to get email
|
||||
*/
|
||||
function get_mass_emails()
|
||||
{
|
||||
global $db;
|
||||
$results = $db->select(tbl("mass_emails"),"*");
|
||||
|
||||
if($db->num_rows>0)
|
||||
{
|
||||
return $results;
|
||||
}else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* function used to delete, send emails
|
||||
*/
|
||||
function action($id,$action)
|
||||
{
|
||||
global $db;
|
||||
$email = $this->email_exists($id);
|
||||
if(!$email)
|
||||
{
|
||||
e(lang("Email does not exist"));
|
||||
return false;
|
||||
}
|
||||
|
||||
switch($action)
|
||||
{
|
||||
case "delete":
|
||||
{
|
||||
$db->Execute("DELETE FROM ".tbl('mass_emails')." WHERE id='$id'");
|
||||
e(lang("Email has been deleted"),"m");
|
||||
}
|
||||
break;
|
||||
|
||||
case "send_email":
|
||||
{
|
||||
$this->send_emails($email);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* functionn used to check email exists or not
|
||||
*/
|
||||
function get_email($id)
|
||||
{
|
||||
global $db;
|
||||
$result = $db->select(tbl("mass_emails"),"*","id='$id'");
|
||||
if($db->num_rows>0)
|
||||
{
|
||||
return $result[0];
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function email_exists($id){ return $this->get_email($id); }
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* function send emails
|
||||
*/
|
||||
function send_emails($id)
|
||||
{
|
||||
global $db,$userquery,$cbemail;
|
||||
if(!is_array($id))
|
||||
{
|
||||
$email = $this->get_email($id);
|
||||
}else
|
||||
{
|
||||
$email = $id;
|
||||
}
|
||||
|
||||
if($email['status']=='completed')
|
||||
return false;
|
||||
$settings = json_decode($email['configs'],true);
|
||||
$users = $email['users'];
|
||||
$total = $email['total'];
|
||||
|
||||
//Creating limit
|
||||
$start_index = $email['start_index'];
|
||||
$limit = $start_index.','.$settings['loop_size'];
|
||||
|
||||
//Creating condition
|
||||
$condition = "";
|
||||
|
||||
//Levels
|
||||
$level_query = "";
|
||||
$levels = $settings['level'];
|
||||
if($levels)
|
||||
{
|
||||
foreach($levels as $level)
|
||||
{
|
||||
if($level_query)
|
||||
$level_query .= " OR ";
|
||||
$level_query .= " level='$level' ";
|
||||
}
|
||||
|
||||
if($condition)
|
||||
$condition .= " AND ";
|
||||
$condition = $level_query = " ( ".$level_query.") ";
|
||||
}
|
||||
|
||||
//Categories
|
||||
$cats_query = "";
|
||||
$cats = $settings['cat'];
|
||||
if($cats)
|
||||
{
|
||||
foreach($cats as $cat)
|
||||
{
|
||||
if($cats_query)
|
||||
$cats_query .= " OR ";
|
||||
$cats_query .= " category='$cat' ";
|
||||
}
|
||||
|
||||
$cats_query = " ( ".$cats_query.") ";
|
||||
if($condition)
|
||||
$condition .= " AND ";
|
||||
$condition .= $cats_query;
|
||||
}
|
||||
|
||||
|
||||
//Ative users
|
||||
if($settings['active']!='any')
|
||||
{
|
||||
if($condition)
|
||||
$condition .= " AND ";
|
||||
|
||||
if($settings['active']=='yes')
|
||||
$condition .= " usr_status = 'Ok' ";
|
||||
if($settings['active']=='no')
|
||||
$condition .= " usr_status = 'ToActivate' ";
|
||||
}
|
||||
|
||||
//Banned users
|
||||
if($settings['ban']!='any')
|
||||
{
|
||||
if($condition)
|
||||
$condition .= " AND ";
|
||||
|
||||
if($settings['ban']=='yes')
|
||||
$condition .= " ban_status = 'yes' ";
|
||||
if($settings['ban']=='no')
|
||||
$condition .= " ban_status = 'no' ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$users)
|
||||
{
|
||||
$users = $db->select(tbl("users"),"*",$condition,$limit," userid ASC ");
|
||||
|
||||
if(!$total)
|
||||
{
|
||||
$total = $db->count(tbl("users"),"userid",$condition);
|
||||
}
|
||||
|
||||
$sent = $email['sent'];
|
||||
$send_msg = array();
|
||||
foreach($users as $user)
|
||||
{
|
||||
$var = array
|
||||
('{username}' => $user['username'],
|
||||
'{userid}' => $user['userid'],
|
||||
'{email}' => $user['email'],
|
||||
'{datejoined}' => $user['doj'],
|
||||
'{avcode}' => $user['avcode'],
|
||||
'{avlink}' => BASEURL.'/activation.php?av_username='.$user['username'].'&avcode='.$user['avcode'],
|
||||
);
|
||||
$subj = $cbemail->replace($email['email_subj'],$var);
|
||||
$msg = nl2br($cbemail->replace($email['email_msg'],$var));
|
||||
|
||||
$send_message = "";
|
||||
|
||||
//Now Finally Sending Email
|
||||
cbmail(array('to'=>$user['email'],'from'=>$email['from'],'subject'=>$subj,'content'=>$msg));
|
||||
$sent++;
|
||||
|
||||
$send_msg[] = $user['userid'].": Email has been sent to <strong><em>".$user['username']."</em></strong>";
|
||||
|
||||
}
|
||||
|
||||
$sent_to = $start_index+$settings['loop_size'];
|
||||
|
||||
if($sent_to>$total)
|
||||
$sent_to = $total;
|
||||
|
||||
e(sprintf(lang("Sending email from %s to %s"),$start_index+1,$sent_to),"m");
|
||||
|
||||
$start_index = $start_index+$settings['loop_size'];
|
||||
|
||||
if($sent==$total || $sent>$total)
|
||||
$status = 'completed';
|
||||
else
|
||||
$status = 'sending';
|
||||
|
||||
$db->update(tbl('mass_emails'),array('sent','total','start_index','status','last_update'),
|
||||
array($sent,$total,$start_index,$status,now())," id='".$email['id']."' ");
|
||||
|
||||
return $send_msg;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -279,10 +279,10 @@
|
|||
{
|
||||
foreach($to as $name)
|
||||
{
|
||||
$mail->AddAddress($name, $to_name);
|
||||
$mail->AddAddress(strtolower($name), $to_name);
|
||||
}
|
||||
} else {
|
||||
$mail->AddAddress($to, $to_name);
|
||||
$mail->AddAddress(strtolower($to), $to_name);
|
||||
}
|
||||
|
||||
$mail->Subject = $subject;
|
||||
|
|
Loading…
Add table
Reference in a new issue