First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
require_once("include/globals.php");
|
||||
//require("include/sendmail.php");
|
||||
require_once("include/quicksend.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;
|
||||
}
|
||||
|
||||
|
||||
$PrimaryTable = "contacts";
|
||||
$FormFile = "email-quicksend-form.php";
|
||||
|
||||
//
|
||||
// Process requests to send quick emails to contacts
|
||||
//
|
||||
switch ($naction) {
|
||||
case "confirm":
|
||||
$table = new Table("$PrimaryTable");
|
||||
$next_naction = "confirm";
|
||||
extract($_POST);
|
||||
|
||||
// insert new category, if input field entered
|
||||
if ($category_num == 'Add Other...' || !$category_num) {
|
||||
unset ($category_num);
|
||||
if ($category_add) {
|
||||
db_query("INSERT INTO categories SET category='$category_add', active='Y'");
|
||||
$category_num = db_insert_id();
|
||||
}
|
||||
}
|
||||
|
||||
// insert new industry, if input field entered
|
||||
if ($industry_num == 'Add Other...' || !$industry_num) {
|
||||
unset ($industry_num);
|
||||
if ($industry_add) {
|
||||
db_query("INSERT INTO industries SET industry='$industry_add', active='Y'");
|
||||
$industry_num = db_insert_id();
|
||||
}
|
||||
}
|
||||
|
||||
// insert new region, if input field entered
|
||||
if ($region_num == 'Add Other...' || !$region_num) {
|
||||
unset ($region_num);
|
||||
if ($region_add) {
|
||||
db_query("INSERT INTO regions SET region='$region_add', active='Y'");
|
||||
$region_num = db_insert_id();
|
||||
}
|
||||
}
|
||||
|
||||
// find contact if exists
|
||||
$searchSQL = "WHERE email='$email' ";
|
||||
|
||||
// if group specified (staff - theirs, admin - any) add to search sql
|
||||
if ($group_num > 0) {
|
||||
$searchSQL .= "AND (group_num='$group_num' OR group_num='0')";
|
||||
}
|
||||
$query = "SELECT record_num FROM $PrimaryTable {$searchSQL} LIMIT 1";
|
||||
$cid = db_getVal("SELECT record_num FROM $PrimaryTable {$searchSQL} LIMIT 1");
|
||||
|
||||
if (!$cid) {
|
||||
// insert into contacts table
|
||||
$query = $table->BuildInsert();
|
||||
db_query($query);
|
||||
$cid = db_insert_id();
|
||||
|
||||
echo("<p class='success'>Contact $email has been INSERTED<br>Email has been sent for processing</p>\n");
|
||||
}
|
||||
else {
|
||||
// update record fields only if set
|
||||
if (!$name) unset($name);
|
||||
if (!$title) unset($title);
|
||||
if (!$phone) unset($phone);
|
||||
if (!$url) unset($url);
|
||||
if (!$email) unset($email);
|
||||
if (!$company) unset($company);
|
||||
if (!$address) unset($address);
|
||||
if (!$city) unset($city);
|
||||
if (!$province) unset($province);
|
||||
if (!$country) unset($country);
|
||||
if (!$postal) unset($postal);
|
||||
if (!$category_num) unset($category_num);
|
||||
if (!$industry_num) unset($industry_num);
|
||||
if (!$region_num) unset($region_num);
|
||||
if (!$active) unset($active);
|
||||
|
||||
// update group only if set to public
|
||||
if ($group_num != '0') unset($group_num);
|
||||
|
||||
// set the record_num for the update
|
||||
$record_num = $cid;
|
||||
|
||||
$query = $table->BuildUpdate();
|
||||
db_query($query);
|
||||
|
||||
echo("<p class='success'>Contact $email has been UPDATED<br>Email has been sent for processing</p>\n");
|
||||
}
|
||||
|
||||
// Define email category and description
|
||||
$Category = "Quick Send";
|
||||
$Description = "Quick Send to contact $email";
|
||||
|
||||
// Define the default query to be used
|
||||
$Parameters = "";
|
||||
$EmailField = "email";
|
||||
$Query = "SELECT * FROM $PrimaryTable WHERE $EmailField='$email' AND active!='N' LIMIT 1";
|
||||
$num_rows = 1;
|
||||
|
||||
// Get the message to send
|
||||
$content = db_query("SELECT * FROM formatted_content WHERE record_num = '$MessageID'");
|
||||
$row = db_fetch_array($content);
|
||||
$EmailSubject = db_escape_string($row["content_id"]);
|
||||
$EmailMessage = db_escape_string($row["content"]);
|
||||
|
||||
// Process logged in user's details into email message
|
||||
$ufields = array("first_name","last_name","email","title");
|
||||
for ($i = 0; $i < count($ufields); $i++) {
|
||||
$fname = $ufields[$i];
|
||||
$EmailMessage = preg_replace('/({|%7[Bb])users.' . $fname . '(}|%7[Dd])/',$_SESSION['UserInfo'][$fname],$EmailMessage);
|
||||
}
|
||||
|
||||
// Process custom fields into email message
|
||||
foreach ($_POST as $fieldname => $fieldvalue) {
|
||||
if (preg_matches('^custom_([a-z0-9_]+)$', $fieldname, $matches)) {
|
||||
$field_code = $matches[1];
|
||||
$fieldvalue = db_escape_string(nl2br($fieldvalue));
|
||||
$EmailMessage = preg_replace('/({|%7b)custom\.[a-z]+\.' . $field_code . '(}|%7d)/',$fieldvalue,$EmailMessage);
|
||||
}
|
||||
}
|
||||
|
||||
$Category = db_escape_string($Category);
|
||||
$Description = db_escape_string($Description);
|
||||
$ReplyDescription = db_escape_string($ReplyDescription);
|
||||
|
||||
// make the attachments list
|
||||
$attachList = '';
|
||||
if (count($attachments) > 0) {
|
||||
$attachList = implode(",", $attachments);
|
||||
}
|
||||
|
||||
$groupid = $_SESSION['UserInfo']['group_num'];
|
||||
|
||||
// Write email_header record
|
||||
$Query = db_escape_string($Query);
|
||||
$equery = "INSERT INTO email_header " .
|
||||
"(category, description, reply_address, reply_description, email_message_id, subject, message_text, email_template, " .
|
||||
"posted, send_after, matching_records, processed_records, sent_successfully, skipped, errors, email_field_name, primary_table, " .
|
||||
"query, parameters, status, sender_id, attachments, group_num) " .
|
||||
"VALUES ('$Category', '$Description', '$ReplyTo', '$ReplyDescription', '$MessageID', '$EmailSubject', '$EmailMessage', '$EmailTemplate', " .
|
||||
"now(), now(), '$num_rows', 0, 0, 0, 0, '$EmailField', '$PrimaryTable', '$Query', '$Parameters', 'completed', '$loggedInId', '$attachList', " .
|
||||
"'$groupid')";
|
||||
|
||||
quickEmail($equery);
|
||||
|
||||
include $FormFile;
|
||||
break;
|
||||
|
||||
default:
|
||||
include $FormFile;
|
||||
break;
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user