393 lines
13 KiB
PHP
393 lines
13 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
|
|
// Ensure that only admin users have access to this module
|
|
$AllowedUserTypes = array('SuperUser','System Administrator','Communications Administrator');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
echo("<br>\n");
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
// Build a database query based on the input data provided
|
|
//
|
|
if (!$_POST) return;
|
|
extract($_POST);
|
|
|
|
$PrimaryTable = "contacts";
|
|
|
|
//
|
|
// Define the default query to be used
|
|
//
|
|
$Parameters = "";
|
|
$EmailField = "email";
|
|
$Recipients = array("email","name","active");
|
|
|
|
|
|
// Define email category and description
|
|
$Category = "Contacts Broadcast";
|
|
$Description = "Broadcast to contacts";
|
|
|
|
$Where = "";
|
|
$Join = "";
|
|
|
|
if (array_key_exists('sel',$_POST)) {
|
|
if (is_array($_POST['sel'])) {
|
|
$_POST['sel'] = join(",", $_POST['sel']);
|
|
}
|
|
$Where = " and record_num IN ({$_POST['sel']})";
|
|
$Description .= " (custom recipient list)";
|
|
}
|
|
else {
|
|
// creates the join condition
|
|
if ($campaign_num) {
|
|
$Join .= " LEFT JOIN campaign_contacts AS cc ON cc.contact_id = c.record_num";
|
|
$Where .= " and cc.campaign_id = '$campaign_num'";
|
|
|
|
$query = "select campaign from campaigns where record_num = '$campaign_num'";
|
|
$campaign = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " campaign = '$campaign'";
|
|
}
|
|
|
|
// creates the where conditions
|
|
if ($group_num > 0) {
|
|
$Where .= " and c.group_num = '$group_num'";
|
|
|
|
$query = "select group_name from groups where record_num = '$group_num'";
|
|
$group = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " group = '$group'";
|
|
}
|
|
elseif ($group_num == 0) {
|
|
$Where .= " and c.group_num = '0'";
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " group = 'Public'";
|
|
}
|
|
|
|
if ($salesperson_num) {
|
|
$Where .= " and c.salesperson_num = '$salesperson_num'";
|
|
|
|
$query = "select userid from users where record_num = '$salesperson_num'";
|
|
$salesperson = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " salesperson = '$salesperson'";
|
|
}
|
|
|
|
if ($category_num) {
|
|
$Where .= " and c.category_num = '$category_num'";
|
|
|
|
$query = "select category from categories where record_num = '$category_num'";
|
|
$category = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " category = '$category'";
|
|
}
|
|
|
|
if ($industry_num) {
|
|
$Where .= " and c.industry_num = '$industry_num'";
|
|
|
|
$query = "select industry from industries where record_num = '$industry_num'";
|
|
$industry = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " industry = '$industry'";
|
|
}
|
|
|
|
if ($region_num) {
|
|
$Where .= " and c.region_num = '$region_num'";
|
|
|
|
$query = "select region from regions where record_num = '$region_num'";
|
|
$region = db_getVal($query);
|
|
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " region = '$region'";
|
|
}
|
|
|
|
|
|
if ($name || $name_sel) {
|
|
if (!$name) $name = $name_sel;
|
|
$name = str_replace('*','%',$name);
|
|
$Where .= " and c.name like '$name'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " name like '$name'";
|
|
}
|
|
if ($title) {
|
|
$title = str_replace("*","%",$title);
|
|
$Where .= " and c.title like '$title'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " title like '$title'";
|
|
}
|
|
if ($phone) {
|
|
$phone = str_replace("*","%",$phone);
|
|
$Where .= " and c.phone like '$phone'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " phone like '$phone'";
|
|
}
|
|
|
|
if ($email) {
|
|
$email = str_replace("*","%",$email);
|
|
$Where .= " and c.email like '$email'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " email like '$email'";
|
|
}
|
|
if ($company) {
|
|
$company = str_replace("*","%",$company);
|
|
$Where .= " and c.company like '$company'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " company like '$company'";
|
|
}
|
|
if ($address) {
|
|
$address = str_replace("*","%",$address);
|
|
$Where .= " and c.address like '$address'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " address like '$address'";
|
|
}
|
|
if ($city) {
|
|
$city = str_replace("*","%",$city);
|
|
$Where .= " and c.city like '$city'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " city like '$city'";
|
|
}
|
|
if ($province) {
|
|
$province = str_replace("*","%",$province);
|
|
$Where .= " and c.province like '$province'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " province like '$province'";
|
|
}
|
|
if ($country) {
|
|
$country = str_replace("*","%",$country);
|
|
$Where .= " and c.country like '$country'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " country like '$country'";
|
|
}
|
|
if ($postal) {
|
|
$postal = str_replace("*","%",$postal);
|
|
$Where .= " and c.postal like '$postal'";
|
|
if (strpos($Description, " where") === false) $Description .= " where";
|
|
else $Description .= " and";
|
|
$Description .= " postal like '$postal'";
|
|
}
|
|
}
|
|
|
|
// create attachment list
|
|
if (array_key_exists('attachments',$_POST)) {
|
|
if (is_array($_POST['attachments'])) {
|
|
$attachments = $_POST['attachments'] = join(",", $_POST['attachments']);
|
|
}
|
|
}
|
|
|
|
$Query = "SELECT * FROM $PrimaryTable AS c $Join ".
|
|
"WHERE c.$EmailField is not null and c.$EmailField != '' and c.active != 'N' $Where {$permissions} ".
|
|
"ORDER BY c.$EmailField, c.record_num";
|
|
|
|
$Count = "SELECT count(*) FROM $PrimaryTable AS c $Join ".
|
|
"WHERE c.$EmailField is not null and c.$EmailField != '' and c.active != 'N' $Where {$permissions}";
|
|
|
|
|
|
//
|
|
// Determine how many emails will be sent
|
|
//
|
|
$results = db_query($Count);
|
|
$row = db_fetch_array($results);
|
|
$num_rows = $row[0];
|
|
|
|
?>
|
|
<center>
|
|
<form method="post" action="/">
|
|
<table width='90%' cellpadding='2' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td align='left'>
|
|
<h3>Confirm Email Send</h3>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td align='left'>
|
|
<table width='400' cellpadding='5' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td align='left' colspan='2'><p><strong><?php echo($num_rows) ?> record(s) found</strong></p></td>
|
|
</tr>
|
|
<?php
|
|
if ($num_rows > 0) {
|
|
echo("$Category:<br>");
|
|
echo("$Description:<br>\n");
|
|
?>
|
|
<tr>
|
|
<td align='left'>Send Emails:</td>
|
|
<td align='left'>
|
|
<select name="SendAfter">
|
|
<?php include "email-send-times.php"; ?>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan='2' align='center'>
|
|
<br>
|
|
<input type="submit" class="vlgbutton" value="Proceed to Send Emails">
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<input type="hidden" name="ReplyTo" value="<?php echo($ReplyTo) ?>">
|
|
<input type="hidden" name="ReplyDescription" value="<?php echo($ReplyDescription) ?>">
|
|
<input type="hidden" name="MessageID" value="<?php echo($MessageID) ?>">
|
|
<input type="hidden" name="EmailTemplate" value="<?php echo($EmailTemplate) ?>">
|
|
<input type="hidden" name="Category" value="<?php echo($Category) ?>">
|
|
<input type="hidden" name="Description" value="<?php echo($Description) ?>">
|
|
<input type="hidden" name="Query" value="<?php echo($Query) ?>">
|
|
<input type="hidden" name="EmailField" value="<?php echo($EmailField) ?>">
|
|
<input type="hidden" name="attachments" value="<?php echo($attachments) ?>">
|
|
<input type="hidden" name="Parameters" value="<?php echo($Parameters) ?>">
|
|
<input type="hidden" name="PrimaryTable" value="<?php echo($PrimaryTable) ?>">
|
|
<?php
|
|
$post_fields = array_keys($_POST);
|
|
for ($i = 0; $i < count($post_fields); $i++) {
|
|
$field_name = $post_fields[$i];
|
|
$field_value = htmlentities($_POST[$field_name]);
|
|
if (strpos($field_name, 'custom_') === 0) {
|
|
echo(" <input type='hidden' name=\"{$field_name}\" value=\"{$field_value}\">\n");
|
|
}
|
|
}
|
|
?>
|
|
<input type="hidden" name="action" value="email-contacts">
|
|
<input type="hidden" name="naction" value="send">
|
|
</form>
|
|
<?php if ($view_recipients != 'Y') { ?>
|
|
<form method='post' action='/'>
|
|
<table width='90%' cellpadding='2' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td align='left'>
|
|
<table width='400' cellpadding='5' cellspacing='0' border='0'>
|
|
<tr>
|
|
<td align='center'>
|
|
<input type="submit" class="vlgbutton" value="View Recipient List">
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
$post_fields = array_keys($_POST);
|
|
for ($i = 0; $i < count($post_fields); $i++) {
|
|
$field_name = $post_fields[$i];
|
|
$field_value = $_POST[$field_name];
|
|
if (is_array($field_value)) {
|
|
foreach ($field_value as $a => $b) {
|
|
echo(" <input type='hidden' name='{$field_name}[{$a}]' value='$b'>\n");
|
|
}
|
|
} else {
|
|
echo(" <input type='hidden' name='$field_name' value='$field_value'>\n");
|
|
}
|
|
}
|
|
?>
|
|
<input type='hidden' name='view_recipients' value='Y'>
|
|
</form>
|
|
<?php } else { ?>
|
|
<h3>Recipient List</h3>
|
|
<form action="/" method=post>
|
|
<!--<input type="hidden" name="cat" value="contact-email">-->
|
|
<input type="hidden" name="action" value="email-contacts">
|
|
<input type="hidden" name="naction" value="confirm">
|
|
<input type="hidden" name="ReplyTo" value="<?php echo $_POST['ReplyTo'] ?>">
|
|
<input type="hidden" name="ReplyDescription" value="<?php echo $_POST['ReplyDescription'] ?>">
|
|
<input type="hidden" name="MessageID" value="<?php echo $_POST['MessageID'] ?>">
|
|
<input type="hidden" name="EmailTemplate" value="<?php echo $_POST['EmailTemplate'] ?>">
|
|
<input type="hidden" name="attachments" value="<?php echo $_POST['attachments'] ?>">
|
|
<input type="hidden" name="sel[]" value="0">
|
|
<input type="submit" value="Update Recipient List"><br><br>
|
|
|
|
<table width='500' cellpadding='3' cellspacing='1' border='0'>
|
|
<tr>
|
|
<?php
|
|
for ($i = 0; $i < count($Recipients); $i++) {
|
|
$field = ucwords(str_replace("_"," ",$Recipients[$i]));
|
|
echo(" <td align='left' bgcolor='#dddddd'>$field</td>\n");
|
|
}
|
|
?>
|
|
<th align=center bgcolor=#dddddd style="font-size: 12px;"><a href="javascript:checkAll();">All</a> <a href="javascript:checkNone();">None</a></th>
|
|
</tr>
|
|
<?php
|
|
$results = db_query($Query);
|
|
$bgcolors = array('#bbc7c8','#ffffff');
|
|
$count = 0;
|
|
|
|
while ($row = db_fetch_array($results)) {
|
|
$bgcolor = $bgcolors[$count % 2];
|
|
$count++;
|
|
echo(" <tr>\n");
|
|
|
|
for ($i = 0; $i < count($Recipients); $i++) {
|
|
$field = $Recipients[$i];
|
|
echo(" <td align='left' bgcolor='$bgcolor'>$row[$field]</td>\n");
|
|
}
|
|
echo("<td bgcolor='$bgcolor' align=center><input class=checkbox type=checkbox name=\"sel[]\" id=sel{$count} checked value=\"{$row['record_num']}\"></td>");
|
|
echo(" </tr>\n");
|
|
}
|
|
?>
|
|
</table>
|
|
<br><input type=submit value="Update Recipient List">
|
|
</form>
|
|
<script type="text/javascript">
|
|
function checkAll() {
|
|
for (i=1; i<= <?php echo $count ?>; i++) {
|
|
document.getElementById('sel'+i).checked = true;
|
|
}
|
|
}
|
|
function checkNone() {
|
|
for (i=1; i<= <?php echo $count ?>; i++) {
|
|
document.getElementById('sel'+i).checked = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
}
|
|
}
|
|
else {
|
|
?>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
}
|
|
?>
|
|
|
|
<br>
|
|
<br>
|
|
<br>
|