Added inbound email queue to agent support

git-svn-id: svn://192.168.202.10@1905 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2012-12-23 04:28:32 +00:00
parent ba378e1176
commit 1b9a742810
21 changed files with 6245 additions and 372 deletions
+14
View File
@@ -1902,6 +1902,20 @@ OTHER CHANGES:
15. Tested new asterisk-perl module (0.09) and found that it is NOT compatible.
Please make sure you use asterisk-perl-0.08 ONLY.
16. Added email support, it needs to be enabled in your System Settings. Also,
the following perl modules need to be installed on your voicemail server
install LWP::UserAgent
install HTML::Entities
install HTML::Strip
install HTML::FormatText
install HTML::TreeBuilder
install Switch
install Time::Local
install MIME::Decoder
install Mail::POP3Client
install Mail::IMAPClient
install Mail::Message
+28 -2
View File
@@ -76,6 +76,7 @@
# 120820-1026 - Added clearing of vicidial_session_data table at end of day
# 121019-1021 - Added voicemail greeting option
# 121124-1440 - Added holiday expiration function
# 121215-2036 - Added email inbound script keepalive, option E
#
$DB=0; # Debug flag
@@ -197,6 +198,7 @@ foreach(@conf)
# 7 - AST_VDauto_dial_FILL\n";
# 8 - ip_relay for blind monitoring\n";
# 9 - Timeclock auto logout\n";
# E - Email parser script
# - Other setting are set by configuring them in the database
if ($VARactive_keepalives =~ /X/)
@@ -211,6 +213,7 @@ $AST_VDauto_dial=0;
$AST_VDremote_agents=0;
$AST_VDadapt=0;
$FastAGI_log=0;
$email_inbound=0;
$AST_VDauto_dial_FILL=0;
$ip_relay=0;
$timeclock_auto_logout=0;
@@ -224,6 +227,7 @@ $runningFastAGI_log=0;
$runningAST_VDauto_dial_FILL=0;
$runningip_relay=0;
$runningAST_conf_3way=0;
$runningemail_inbound=0;
$AST_conf_3way=0;
if ($VARactive_keepalives =~ /1/)
@@ -271,6 +275,11 @@ if ($VARactive_keepalives =~ /9/)
$timeclock_auto_logout=1;
if ($DB) {print "Check to see if Timeclock auto logout should run\n";}
}
if ($VARactive_keepalives =~ /E/)
{
$email_inbound=1;
if ($DB) {print "Check to see if email parser should run\n";}
}
if ($cu3way > 0)
{
$AST_conf_3way=1;
@@ -344,6 +353,11 @@ foreach (@psoutput)
$runningAST_VDauto_dial_FILL++;
if ($DB) {print "AST_VDauto_dial_FILL RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/VD_email_inbound\.pl/)
{
$runningemail_inbound++;
if ($DB) {print "VD_email_inbound RUNNING:|$psline[1]|\n";}
}
if ($psoutput[$i] =~ / ip_relay /)
{
$runningip_relay++;
@@ -425,7 +439,8 @@ if (
( ($FastAGI_log > 0) && ($runningFastAGI_log < 1) ) ||
( ($AST_VDauto_dial_FILL > 0) && ($runningAST_VDauto_dial_FILL < 1) ) ||
( ($ip_relay > 0) && ($runningip_relay < 1) ) ||
( ($AST_conf_3way > 0) && ($runningAST_conf_3way < 1) )
( ($AST_conf_3way > 0) && ($runningAST_conf_3way < 1) ) ||
( ($email_inbound > 0) && ($runningemail_inbound < 1) )
)
{
@@ -444,7 +459,7 @@ if (
$i=0;
foreach (@psoutput2)
{
chomp($psoutput2[$i]);
chomp($psoutput2[$i]);
if ($DBX) {print "$i|$psoutput2[$i]| \n";}
@psline = split(/\/usr\/bin\/perl /,$psoutput2[$i]);
@@ -488,6 +503,11 @@ if (
$runningAST_VDauto_dial_FILL++;
if ($DB) {print "AST_VDauto_dial_FILL RUNNING: |$psline[1]|\n";}
}
if ($psline[1] =~ /$REGhome\/VD_email_inbound\.pl/)
{
$runningemail_inbound++;
if ($DB) {print "VD_email_inbound RUNNING:|$psline[1]|\n";}
}
if ($psoutput2[$i] =~ / ip_relay /)
{
$runningip_relay++;
@@ -550,6 +570,12 @@ if (
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTVDautoFILL $PATHhome/AST_VDauto_dial_FILL.pl`;
}
if ( ($email_inbound > 0) && ($runningemail_inbound < 1) )
{
if ($DB) {print "starting VD_email_inbound...\n";}
# add a '-L' to the command below to activate logging
`/usr/bin/screen -d -m -S ASTemail $PATHhome/VD_email_inbound.pl`;
}
if ( ($ip_relay > 0) && ($runningip_relay < 1) )
{
if ($DB) {print "starting ip_relay through relay_control...\n";}
@@ -0,0 +1,801 @@
#!/usr/bin/perl
#use strict;
# use warnings;
use HTML::Entities;
use HTML::Strip;
use Switch;
use Time::Local;
use MIME::Decoder;
# Copyright (C) 2012 Joe Johnson <freewermadmin@gmail.com> LICENSE: AGPLv2
#
# AST_inbound_email_parser.pl - This script is essential for periodically checking any active POP3 or IMAP
# email accounts set up through the Vicidial admin.
#
# You cannot check an email account more often than 5 minutes at a time. This is in place because several
# email providers will lock an email account if it is being checked too often; currently the most restrictive
# email provider encountered allows no more than three logins every 15 minutes, hence 5 minutes being the
# most frequent time allowed.
#
# Upon execution, this script will query the vicidial_email_accounts table in the asterisk database and
# gather the information for all email accounts set up through the dialer that are currently active. It
# will then check the time setting on each of those accounts to see if it is time to check that particular
# account. If so, the program then will attempt to access the account using the appropriate Perl module
# depending on the account protocol (POP3 or IMAP). If the program successfully connects to the email
# account, then it will download any unread email messages, and grab any important information in the
# email headers, along with any attachments and the message itself. Each bit of information will be
# stored in the vicidial_email_list table, and any attachments will be stored in the
# inbound_email_attachments table as BLOB data.
#
# Additionally, depending on the email account settings, prior to putting the email record into the
# vicidial_email_list table, the accounts can be set up to check if the "from" address is already part
# of a lead in the vicidial_list table. The accounts can be set up to not check at all (EMAIL), in
# which all email messages go in as new leads, first in the vicidial_list table and then in the
# vicidial_email_list table with the lead_id gleaned from the vicidial_list insert. They can also be
# set up to check if the email address is already on a lead in a particular list (EMAILLOOKUPRL), or
# if the email address is in a lead belonging to any list in a given campaign (EMAILLOOKUPRC), or if
# the email address is on any lead currently in the vicidial_list table (EMAILLOOKUP). In these
# cases, the script will grab the lead_id of the most recently loaded lead (i.e. highest lead_id value),
# and use that as the lead_id in the vicidial_email_list table without creating a new lead.
#
# After checking and downloading any unread messages, the script will then log off the email account,
# and when all active email accounts have been checked in this manner, the script will exit.
#
# This script should be set up in the cron to run once per minute, not continuously.
# * * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl
#
# Use the --debug variable when executing the script to have it print out what it is attempting to do on a
# step-by-step basis. Use the --debugX variable to include outputting of mail information and SQL queries the script
# attempts to execute.
#
# changes:
# 121213-2200 - First Build
#
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
$|=1;
if ($ARGV[0]=~/--help/) {
print "AST_inbound_email_parser.pl - This script is essential for periodically checking any active POP3 or IMAP \n";
print "email accounts set up through the Vicidial admin.\n";
print "\n";
print "You cannot check an email account more often than 5 minutes at a time. This is in place because several \n";
print "email providers will lock an email account if it is being checked too often; currently the most restrictive\n";
print "email provider encountered allows no more than three logins every 15 minutes, hence 5 minutes being the\n";
print "most frequent time allowed.\n";
print "\n";
print "Upon execution, this script will query the vicidial_email_accounts table in the asterisk database and \n";
print "gather the information for all email accounts set up through the dialer that are currently active. It\n";
print "will then check the time setting on each of those accounts to see if it is time to check that particular \n";
print "account. If so, the program then will attempt to access the account using the appropriate Perl module\n";
print "depending on the account protocol (POP3 or IMAP). If the program successfully connects to the email \n";
print "account, then it will download any unread email messages, and grab any important information in the \n";
print "email headers, along with any attachments and the message itself. Each bit of information will be \n";
print "stored in the vicidial_email_list table, and any attachments will be stored in the \n";
print "inbound_email_attachments table as BLOB data.\n";
print "\n";
print "Additionally, depending on the email account settings, prior to putting the email record into the \n";
print "vicidial_email_list table, the accounts can be set up to check if the 'from' address is already part \n";
print "of a lead in the vicidial_list table. The accounts can be set up to not check at all (EMAIL), in \n";
print "which all email messages go in as new leads, first in the vicidial_list table and then in the \n";
print "vicidial_email_list table with the lead_id gleaned from the vicidial_list insert. They can also be\n";
print "set up to check if the email address is already on a lead in a particular list (EMAILLOOKUPRL), or\n";
print "if the email address is in a lead belonging to any list in a given campaign (EMAILLOOKUPRC), or if \n";
print "the email address is on any lead currently in the vicidial_list table (EMAILLOOKUP). In these \n";
print "cases, the script will grab the lead_id of the most recently loaded lead (i.e. highest lead_id value), \n";
print "and use that as the lead_id in the vicidial_email_list table without creating a new lead.\n";
print "\n";
print "After checking and downloading any unread messages, the script will then log off the email account, \n";
print "and when all active email accounts have been checked in this manner, the script will exit.\n";
print "\n";
print "This script should be set up in the cron to run once per minute, not continuously.\n";
print "* * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl\n";
print "\n";
print "Use the --debug variable when executing the script to have it print out what it is attempting to do on a\n";
print "step-by-step basis. Use the --debugX variable to include outputting of mail information and SQL queries the script \n";
print "attempts to execute.\n";
exit;
}
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
if (!$VARDB_port) {$VARDB_port='3306';}
use DBI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhA2 = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhA3 = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if($min==0) {$min=60;}
$minutes=($hour*60)+$min;
$minutes=0;
$stmt="select * from vicidial_email_accounts where active='Y'";
$rslt=$dbhA->prepare($stmt);
$rslt->execute();
while (@row=$rslt->fetchrow_array) {
$VARemail_ID=$row[0];
$VARemail_protocol=$row[4];
$VARemail_server=$row[6];
$VARemail_user=$row[7];
$VARemail_pwd=$row[8];
$VARemail_frequency=$row[10];
$VARemail_groupid=$row[11];
$default_list_id=$row[12];
$call_handle_method=$row[13];
$agent_search_method=$row[14];
$campaign_id=$row[15];
$list_id=$row[16];
if ($minutes%$VARemail_frequency==0) {
if ($ARGV[0]=~/debug/i) {print "Attempting to connect to $VARemail_protocol server ($VARemail_server)\n\n";}
if ($VARemail_protocol eq "IMAP") {
# if (!$sleep_time || $sleep_time<10) {$sleep_time=10;} # Ten second minimum wait time for IMAP.
# Connect to IMAP server
use Mail::IMAPClient;
use Mail::Message;
my $client = Mail::IMAPClient->new(
Server => "$VARemail_server",
User => "$VARemail_user",
Password => "$VARemail_pwd",
Port => 993,
Ssl => 1,
)
or die "Cannot connect through IMAPClient: $!";
# Include options for folders in IMAP? POP3 doesn't support this.
# List folders on remote server (see if all is ok)
if ( $client->IsAuthenticated() ) {
#print "Folders:\n";
$new_messages=0;
my @folder_array=$client->folders("INBOX");
for (my $i=0; $i<scalar(@folder_array); $i++) {
#print "- ".$folder_array[$i]."\n" ;
my $msgcount = $client->message_count($folder_array[$i]);
#print "+---+ Messages: ".$msgcount."\n";
if ($msgcount>0) {
$client->select($folder_array[$i]);
my @msgs = $client->messages or die "Could not messages: $@\n";
my @unseenMsgs = $client->unseen;
for(my $j=0; $j<scalar(@msgs); $j++) {
if (grep {$_ eq $msgs[$j]} @unseenMsgs) {
$new_messages++;
my $hashref = $client->parse_headers($msgs[$j], 'ALL');
my %email_values=%{$hashref};
my $email_to=$email_values{"To"}->[0];
my $email_from=$email_values{"From"}->[0];
my $email_date=$email_values{"Date"}->[0];
my $subject=$email_values{"Subject"}->[0];
my $mime_type=$email_values{"MIME-Version"}->[0];
my $content_type=$email_values{"Content-Type"}->[0];
my $x_mailer=$email_values{"X-Mailer"}->[0];
my $auth_results=$email_values{"Authentication-Results"}->[0];
my $spf=$email_values{"Received-SPF"}->[0];
$message = $client->body_string($msgs[$j]);
$text_written=0; ## Keeps track of whether or not text of email was grabbed
$attach_ct=0; ## Keeps number
@ins_values=();
@output_ins_values=();
if ($email_date=~/[0-9]{1,2}\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+[0-9]{4}\s+[0-9]{1,2}\:[0-9]{1,2}(\:[0-9]{1,2})?/) {
$email_date=$&;
$email_date=~s/\s+/ /gi;
@date_array=split(/\s/, $email_date);
$day=substr("0".$date_array[0], -2);
$month=$date_array[1];
$year=$date_array[2];
@time_array=split(/\:/, $date_array[3]);
$hour=substr("00".$time_array[0], -2);
$min=substr("00".$time_array[1], -2);
$sec=substr("00".$time_array[2], -2);
$email_date="$day $month $year $hour:$min:$sec";
if ($ARGV[0]=~/debug/) {print "Time stamp on email is $email_date\n";}
} elsif ($ARGV[0]=~/debug/) {print "WARNING: Time stamp on email is $email_date\n";}
############# MESSAGE ACTIONS
if ($content_type=~/^text\/plain/i) {
## Do nothing - it's plain text and needs no further work on it.
if ($ARGV[0]=~/debug/i) {print "Email message is text/plain. Nothing needs to be done.\n\n";}
} elsif ($content_type=~/^text\/html/i) {
## Message is HTML, so it needs to be stripped.
if ($ARGV[0]=~/debug/i) {print "Email message is text/html. Needs to have tags stripped via HTML::Strip.\n\n";}
StripHTML();
} elsif ($content_type=~/^multipart\/(alternative|mixed)/i) {
## Message is multipart/alternative, so it needs to be read and partitioned. The multipart/alternative subtype indicates that each part is an "alternative"
## version of the same (or similar) content, each in a different format denoted by its "Content-Type" header. The formats are ordered by how faithful they are to
## the original, with the least faithful first and the most faithful last. Systems can then choose the "best" representation they are capable of processing; in
## general, this will be the last part that the system can understand, although other factors may affect this.
if ($ARGV[0]=~/debug/i) {print "Email message is multipart. Need to select the best format type and parse it.\n";}
## First, get the boundary from the content-type and use it to break the email into it's multiple parts
if ($content_type=~/boundary\=\"?[^\"]+\"?/i) {
$boundary=$&;
$boundary=~s/(^boundary=\"?|\"?$)//gi;
$boundary="--".$boundary;
@alternatives_array=split(/$boundary/, $message);
for ($k=1; $k<(scalar(@alternatives_array)-1); $k++) { # Ignore the first and last entry in the array; it's just a blank entry and the two dashes after the last boundary.
## Grab the message by using Mail::Message to strip header information
$alt_email_text=$alternatives_array[$k];
$alt_email_text=~s/(^(\s|\r|\n)+|(\s|\r|\n)+$)//; # This needs to be trimmed so the Mail::Message->read command will strip out the headers - leading carriage returns ruin it
# Reset certain variables;
$sub_content_disposition="";
$sub_content_type="";
$attachment_fulltype="";
$attachment_filename="";
$attachment_type="";
if ($alt_email_text=~/Content\-Type\:\s+(.*?)\n/i) {$sub_content_type=$&;}
if ($alt_email_text=~/Content\-Disposition\:\s+(.*?)\n/i) {$sub_content_disposition=$&;}
if ($alt_email_text=~/Content\-Transfer\-Encoding\:\s+(.*?)\n/i) {
$encoding_type=$&;
$encoding_type=~s/(^Content-Transfer-Encoding\:\s+|\;$)//gi;
$encoding_type=~s/[\r\n]//g;
}
$sub_content_type=~s/[\r\n]//g;
$sub_content_disposition=~s/[\r\n]//g;
my $msg = Mail::Message->read($alt_email_text);
$body_contents=$msg->body;
$attachment_filesize=$msg->size();
$head=$msg->head;
if ($ARGV[0]=~/debugX/i) {print "Part content disposition is $sub_content_disposition\n Part content type is $sub_content_type.\n";}
if ($ARGV[0]=~/debugX/i) {print "Part content size is $attachment_filesize\n";}
## Check if the content-type is plain or html
if ($alt_email_text=~/Content\-Type\:\s+text\/html/i && $text_written==0) {
$message=$body_contents;
if ($ARGV[0]=~/debug/i) {print "First acceptable content-type match is text/html. Stripping headers and stripping tags from the body/message...\n";}
if ($ARGV[0]=~/debugX/i) {print "$k)\n***Pre-HTML strip:\n$message\n***\n";}
StripHTML();
if ($ARGV[0]=~/debugX/i) {print "$k)\n***Post-HTML strip:\n$message\n***\n";}
$text_written=1;
} elsif ($alt_email_text=~/Content\-Type\:\s+text\/plain/i && $text_written==0) {
if ($ARGV[0]=~/debug/i) {print "First acceptable content-type match is text/plain. Stripping headers to get text...\n";}
$text_written=1;
$message=$body_contents;
}
## Check for attachments
if ($sub_content_disposition=~/attachment/) {
$attachment_fulltype="";
$attachment_filename="";
## Check to see if attachment is an accepted filetype
$sub_content_type=~/Content-Type\:\s+[^\;]+\;/i; $attachment_type=$&;
$attachment_type=~s/(^Content-Type\:\s+|\;$)//gi;
$attachment_type=~s/[\r\n]//g;
switch ($attachment_type) {
case "application/pdf" {$attachment_fulltype="PDF";}
case "image/jpeg" {$attachment_fulltype="JPG";}
case "image/jpg" {$attachment_fulltype="JPG";}
case "image/gif" {$attachment_fulltype="GIF";}
case "image/x-png" {$attachment_fulltype="PNG";}
case "image/png" {$attachment_fulltype="PNG";}
case "image/bmp" {$attachment_fulltype="BMP";}
case "image/x-ms-bmp" {$attachment_fulltype="BMP";}
case "application/msword" {$attachment_fulltype="DOC";}
case "application/rtf" {$attachment_fulltype="RTF";}
case "application/vnd.ms-powerpoint" {$attachment_fulltype="PPT";}
case "application/vnd.ms-excel" {$attachment_fulltype="XLS";}
case "application/x-msexcel" {$attachment_fulltype="XLS";}
case "application/ms-excel" {$attachment_fulltype="XLS";}
case "application/zip" {$attachment_fulltype="ZIP";}
case "text/csv" {$attachment_fulltype="CSV";}
case "text/plain" {$attachment_fulltype="TXT";}
case "application/vnd.oasis.opendocument.text" {$attachment_fulltype="ODT";}
case "application/vnd.oasis.opendocument.spreadsheet" {$attachment_fulltype="ODS";}
}
if ($sub_content_disposition=~/filename\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
if (length($attachment_filename)==0) {
if ($ARGV[0]=~/debug/i) {print "Couldn't find file name with content-disposition. Searching full header for 'filename' value...\n";}
if ($alt_email_text=~/filename\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
if (length($attachment_filename)==0) {
if ($ARGV[0]=~/debug/i) {print "Couldn't find file name anywhere in header. Searching Content-Type for 'name' value...\n";}
if ($sub_content_type=~/name\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
}
}
$attachment_filename=~s/(file)?name\=\"?|\"?$//gi;
# If the attachment check is good, then proceed with storing the attachment. Otherwise continue.
if ($attachment_fulltype && $attachment_fulltype ne "") {
if ($attachment_filename && $attachment_filename ne "") {
if ($ARGV[0]=~/debug/i) {print "Found valid attachment, type $attachment_type \n Attachment filename is $attachment_filename ($attachment_fulltype)\nFile can be stored in database....\n";}
$ins_values[$attach_ct]="'$attachment_filename','$attachment_type','$encoding_type','$attachment_filesize','$attachment_fulltype','$body_contents'";
$output_ins_values[$attach_ct]="'$attachment_filename','$attachment_type','$encoding_type','$attachment_filesize','$attachment_fulltype','<FILE CONTENTS>'";
$attach_ct++;
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Found valid attachment, type $attachment_type \n Attachment does not have file name. Skipping...\n";}
}
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Found attachment $attachment_filename, but is NOT a valid file type \n Attachment type is $attachment_type. Skipping...\n";}
}
}
# print "\n";
}
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Mail is multi-part, but no boundary value was found. Email will be ignored.\n";}
}
}
#print "\n";
$message=~s/(\"|\||\'|\;)/\\$&/g;
$email_to=~s/(\"|\||\'|\;)/\\$&/g;
$email_from=~s/(\"|\||\'|\;)/\\$&/g;
$subject=~s/(\"|\||\'|\;)/\\$&/g;
$mime_type=~s/(\"|\||\'|\;)/\\$&/g;
$content_type=~s/(\"|\||\'|\;)/\\$&/g;
$x_mailer=~s/(\"|\||\'|\;)/\\$&/g;
$sender_ip=~s/(\"|\||\'|\;)/\\$&/g;
$message=~s/\s{2,}/ /gi;
my $status="NEW";
### Parses the actual email address from the "Email From:" value in order to run it against vicidial_list
### Not sure how accurate this is
$email_from_name=$email_from;
$email_from_name=~s/\<?([^\s\@])+\@(([^\s\@\.])+\.)+[a-zA-Z]{2,}\>?//gi;
$email_from_name=~s/^\s*(.*?)\s*$/$1/;
$email_from=~/\<?([^\s\@])+\@(([^\s\@\.])+\.)+[a-zA-Z]{2,}\>?/i;
$email_from=$&;
$email_from=~s/(^\<)|(\>$)//gi;
$auth_results=~/([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}/i;
my $sender_ip=$&;
$spf=~/([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}/i;
my $sender_ip2=$&;
if (length($sender_ip)==0) {$sender_ip=$sender_ip2;}
$limit=1;
$call_handle_clause="";
if ($call_handle_method eq "EMAILLOOKUP") {
$call_handle_clause="where email='$email_from' order by lead_id desc";
} elsif ($call_handle_method eq "EMAILLOOKUPRL") {
$call_handle_clause="where email='$email_from' and list_id='$list_id' order by lead_id desc";
} elsif ($call_handle_method eq "EMAILLOOKUPRC") {
my $list_id_stmt="select list_id from vicidial_lists where campaign_id='$campaign_id'";
my $list_id_rslt=$dbhA->prepare($list_id_stmt);
$list_id_rslt->execute();
$list_id_str="";
while (@list_id_row=$list_id_rslt->fetchrow_array) {
$list_id_str.="$list_id_row[0],";
}
$list_id_str=substr($list_id_str, 0, -1);
$call_handle_clause="where email='$email_from' and list_id in ($list_id_str) order by lead_id desc";
} else {
$limit=0;
}
### CHECK if lead exists in vicidial_list table via a search by email based on the email account settings
my $vicidial_lead_check_stmt="select lead_id, list_id from vicidial_list $call_handle_clause limit $limit";
if ($ARGV[0]=~/debugX/i) {print $vicidial_lead_check_stmt;}
my $vicidial_lead_check_rslt=$dbhA->prepare($vicidial_lead_check_stmt);
$vicidial_lead_check_rslt->execute();
if ($vicidial_lead_check_rslt->rows>0) {
my @lead_id_row=$vicidial_lead_check_rslt->fetchrow_array;
$lead_id=$lead_id_row[0];
} else {
my $vicidial_list_stmt="insert into vicidial_list(list_id, email, comments, status) values('$default_list_id', '$email_from', '".substr($message,0,255)."', '$status')";
if ($ARGV[0]=~/debugX/i) {print $vicidial_list_stmt;}
my $vicidial_list_rslt=$dbhA->prepare($vicidial_list_stmt);
if ($vicidial_list_rslt->execute()) {
$lead_id=$dbhA->last_insert_id(undef, undef, 'vicidial_list', 'lead_id');
} else {
die "Vicidial list insert failed. Check SQL in:\n $vicidial_list_stmt\n";
}
}
## Insert a new record into vicidial_email_list. This is ALWAYS done for new email messages.
$ins_stmt="insert into vicidial_email_list(lead_id, protocol, email_date, email_to, email_from, email_from_name, subject, mime_type, content_type, x_mailer, sender_ip, message, email_account_id, group_id, status, direction) values('$lead_id', 'IMAP', STR_TO_DATE('$email_date', '%d %b %Y %T'), '$email_to', '$email_from', '$email_from_name', '$subject', '$mime_type', '$content_type', '$x_mailer', '$sender_ip', trim('$message'), '$VARemail_ID', '$VARemail_groupid', '$status', 'INBOUND')";
if ($ARGV[0]=~/debugX/i) {print $ins_stmt."\n";}
my $ins_rslt=$dbhA->prepare($ins_stmt);
if ($ins_rslt->execute()) {
if ($attach_ct>0) {
$email_id=$dbhA->last_insert_id(undef, undef, 'vicidial_email_list', 'email_row_id');
$multistmt="";
for ($k=0; $k<$attach_ct; $k++) {
$ins_values[$k]="('$email_id',$ins_values[$k])";
$multistmt.="$ins_values[$k],";
$output_ins_values[$k]="('$email_id',$output_ins_values[$k])";
$output_multistmt.="$output_ins_values[$k],";
}
$attachment_ins_stmt="insert into inbound_email_attachments(email_row_id, filename, file_type, file_encoding, file_size, file_extension, file_contents) VALUES ".substr($multistmt,0,-1);
$attachment_ins_rslt=$dbhA->prepare($attachment_ins_stmt);
$attachment_ins_rslt->execute();
$output_ins_stmt="insert into inbound_email_attachments(email_row_id, filename, file_type, file_encoding, file_size, file_extension, file_contents) VALUES ".substr($output_multistmt,0,-1);
if ($ARGV[0]=~/debugX/i) {print $output_ins_stmt."\n";}
}
if ($ARGV[0]=~/debug/i) {print "\n Found $attach_ct attachments in email\n";}
} else {
die "Email insert failed. Check SQL in:\n $ins_stmt\n";
}
}
}
}
}
if ($ARGV[0]=~/debug/i) {
if ($ARGV[0]=~/debugX/i) {
print "Iteration #$q - found ".($new_messages+0)." new messages\n";
} else {
# print ".";
}
}
# sleep($sleep_time);
}
$client->logout();
} elsif ($VARemail_protocol eq "POP3") {
# if (!$sleep_time || $sleep_time<300) {$sleep_time=300;} # Some servers don't allow multiple connections within a certain time frame.
# if ($ARGV[0]=~/debug/) {$mail_check_iterations=5;} else {$mail_check_iterations=1000000;}
use Mail::POP3Client;
$pop = new Mail::POP3Client( USER => "$VARemail_user",
PASSWORD => "$VARemail_pwd",
HOST => "$VARemail_server",
PORT => 995,
USESSL => true,
DEBUG => true,
)
or die "Cannot connect through POP3Client: $!";
if ($pop->Count()<0) {die "Error connecting to server. Please try again later.\n";}
for( $i = 1; $i <= $pop->Count(); $i++ ) {
foreach( $pop->Head( $i ) ) {
if ($_=~/^(To|From|Date|Subject|MIME-Version|Content-Type|X-Mailer|Authentication-Results|Received-SPF|Message|Body):\s+/i) {
$value=$_;
$ptn=$&;
$value=~s/$ptn//i;
$ptn=~s/^\s*(.*?)\s*$/$1/;
$ptn=~s/:$//;
$ptn=~s/\-/_/i;
$varname=lc($ptn);
$$varname=$value;
}
if ($_=~/boundary\=\"?[^\"]+\"?/i) {
$bkup_boundary=$&;
}
}
$message=$pop->Body( $i );
$text_written=0; ## Keeps track of whether or not text of email was grabbed
$attach_ct=0; ## Keeps number
@ins_values=();
@output_ins_values=();
if ($content_type=~/^text\/plain/i) {
## Do nothing - it's plain text and needs no further work on it.
if ($ARGV[0]=~/debug/i) {print "Email message is text/plain. Nothing needs to be done.\n\n";}
} elsif ($content_type=~/^text\/html/i) {
## Message is HTML, so it needs to be stripped.
if ($ARGV[0]=~/debug/i) {print "Email message is text/html. Needs to have tags stripped via HTML::Strip.\n\n";}
StripHTML();
} elsif ($content_type=~/^multipart\/(alternative|mixed)/i) {
## Message is multipart/alternative, so it needs to be read and partitioned. The multipart/alternative subtype indicates that each part is an "alternative"
## version of the same (or similar) content, each in a different format denoted by its "Content-Type" header. The formats are ordered by how faithful they are to
## the original, with the least faithful first and the most faithful last. Systems can then choose the "best" representation they are capable of processing; in
## general, this will be the last part that the system can understand, although other factors may affect this.
if ($ARGV[0]=~/debug/i) {print "Email message is multipart. Need to select the best format type and parse it.\n";}
## First, get the boundary from the content-type and use it to break the email into it's multiple parts
if ($content_type=~/boundary\=\"?[^\"]+\"?/i) {
$boundary=$&;
} else {
$boundary=$bkup_boundary;
}
if (length($boundary)>0) {
$boundary=~s/(^boundary=\"?|\"?$)//gi;
$boundary="--".$boundary;
@alternatives_array=split(/$boundary/, $message);
for ($k=1; $k<(scalar(@alternatives_array)-1); $k++) { # Ignore the first and last entry in the array; it's just a blank entry and the two dashes after the last boundary.
## Grab the message by using Mail::Message to strip header information
$alt_email_text=$alternatives_array[$k];
$alt_email_text=~s/(^(\s|\r|\n)+|(\s|\r|\n)+$)//; # This needs to be trimmed so the Mail::Message->read command will strip out the headers - leading carriage returns ruin it
# Reset certain variables;
$sub_content_disposition="";
$sub_content_type="";
$attachment_fulltype="";
$attachment_filename="";
$attachment_type="";
if ($alt_email_text=~/Content\-Type\:\s+(.*?)\n/i) {$sub_content_type=$&;}
if ($alt_email_text=~/Content\-Disposition\:\s+(.*?)\n/i) {$sub_content_disposition=$&;}
if ($alt_email_text=~/Content\-Transfer\-Encoding\:\s+(.*?)\n/i) {
$encoding_type=$&;
$encoding_type=~s/(^Content-Transfer-Encoding\:\s+|\;$)//gi;
$encoding_type=~s/[\r\n]//g;
}
$sub_content_type=~s/[\r\n]//g;
$sub_content_disposition=~s/[\r\n]//g;
my $msg = Mail::Message->read($alt_email_text);
$body_contents=$msg->body;
$attachment_filesize=$msg->size();
$head=$msg->head;
if ($ARGV[0]=~/debugX/i) {print "Part content disposition is $sub_content_disposition\n Part content type is $sub_content_type.\n";}
if ($ARGV[0]=~/debugX/i) {print "Part content size is $attachment_filesize\n";}
## Check if the content-type is plain or html
if ($alt_email_text=~/Content\-Type\:\s+text\/html/i && $text_written==0) {
$message=$body_contents;
if ($ARGV[0]=~/debug/i) {print "First acceptable content-type match is text/html. Stripping headers and stripping tags from the body/message...\n";}
if ($ARGV[0]=~/debugX/i) {print "$k)\n***Pre-HTML strip:\n$message\n***\n";}
StripHTML();
if ($ARGV[0]=~/debugX/i) {print "$k)\n***Post-HTML strip:\n$message\n***\n";}
$text_written=1;
} elsif ($alt_email_text=~/Content\-Type\:\s+text\/plain/i && $text_written==0) {
if ($ARGV[0]=~/debug/i) {print "First acceptable content-type match is text/plain. Stripping headers to get text...\n";}
$text_written=1;
$message=$body_contents;
}
## Check for attachments
if ($sub_content_disposition=~/attachment/) {
$attachment_fulltype="";
$attachment_filename="";
## Check to see if attachment is an accepted filetype
$sub_content_type=~/Content-Type\:\s+[^\;]+\;/i; $attachment_type=$&;
$attachment_type=~s/(^Content-Type\:\s+|\;$)//gi;
$attachment_type=~s/[\r\n]//g;
switch ($attachment_type) {
case "application/pdf" {$attachment_fulltype="PDF";}
case "image/jpeg" {$attachment_fulltype="JPG";}
case "image/jpg" {$attachment_fulltype="JPG";}
case "image/gif" {$attachment_fulltype="GIF";}
case "image/x-png" {$attachment_fulltype="PNG";}
case "image/png" {$attachment_fulltype="PNG";}
case "image/bmp" {$attachment_fulltype="BMP";}
case "image/x-ms-bmp" {$attachment_fulltype="BMP";}
case "application/msword" {$attachment_fulltype="DOC";}
case "application/rtf" {$attachment_fulltype="RTF";}
case "application/vnd.ms-powerpoint" {$attachment_fulltype="PPT";}
case "application/vnd.ms-excel" {$attachment_fulltype="XLS";}
case "application/x-msexcel" {$attachment_fulltype="XLS";}
case "application/ms-excel" {$attachment_fulltype="XLS";}
case "application/zip" {$attachment_fulltype="ZIP";}
case "text/csv" {$attachment_fulltype="CSV";}
case "text/plain" {$attachment_fulltype="TXT";}
case "application/vnd.oasis.opendocument.text" {$attachment_fulltype="ODT";}
case "application/vnd.oasis.opendocument.spreadsheet" {$attachment_fulltype="ODS";}
}
if ($sub_content_disposition=~/filename\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
if (length($attachment_filename)==0) {
if ($ARGV[0]=~/debug/i) {print "Couldn't find file name with content-disposition. Searching full header for 'filename' value...\n";}
if ($alt_email_text=~/filename\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
if (length($attachment_filename)==0) {
if ($ARGV[0]=~/debug/i) {print "Couldn't find file name anywhere in header. Searching Content-Type for 'name' value...\n";}
if ($sub_content_type=~/name\=\"?(.*?)\"?$/i) {$attachment_filename=$&;}
}
}
$attachment_filename=~s/(file)?name\=\"?|\"?$//gi;
# If the attachment check is good, then proceed with storing the attachment. Otherwise continue.
if ($attachment_fulltype && $attachment_fulltype ne "") {
if ($attachment_filename && $attachment_filename ne "") {
$body_contents=~s/(\"|\||\'|\;)/\\$&/g; # This is a problem for POP3 (of course) in the attachment contents.
if ($ARGV[0]=~/debug/i) {print "Found valid attachment, type $attachment_type \n Attachment filename is $attachment_filename ($attachment_fulltype)\nFile can be stored in database....\n";}
$ins_values[$attach_ct]="'$attachment_filename','$attachment_type','$encoding_type','$attachment_filesize','$attachment_fulltype','$body_contents'";
$output_ins_values[$attach_ct]="'$attachment_filename','$attachment_type','$encoding_type','$attachment_filesize','$attachment_fulltype','<FILE CONTENTS>'";
$attach_ct++;
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Found valid attachment, type $attachment_type \n Attachment does not have file name. Skipping...\n";}
}
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Found attachment $attachment_filename, but is NOT a valid file type \n Attachment type is $attachment_type. Skipping...\n";}
}
}
# print "\n";
}
} else {
if ($ARGV[0]=~/debug/i) {print "!!!!WARNING - Mail is multi-part, but no boundary value was found. Email will be ignored.\n";}
}
}
# print "\n";
if ($date=~/[0-9]{1,2}\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+[0-9]{4}\s+[0-9]{1,2}\:[0-9]{1,2}(\:[0-9]{1,2})?/) {
$date=$&;
$date=~s/\s+/ /gi;
@date_array=split(/\s/, $date);
$day=substr("0".$date_array[0], -2);
$month=$date_array[1];
$year=$date_array[2];
@time_array=split(/\:/, $date_array[3]);
$hour=substr("00".$time_array[0], -2);
$min=substr("00".$time_array[1], -2);
$sec=substr("00".$time_array[2], -2);
$date="$day $month $year $hour:$min:$sec";
if ($ARGV[0]=~/debug/) {print "Time stamp on email is $date\n";}
} elsif ($ARGV[0]=~/debug/) {print "WARNING: Time stamp on email is $date\n";}
$message=~s/(\"|\||\'|\;)/\\$&/g;
$email_to=~s/(\"|\||\'|\;)/\\$&/g;
$email_from=~s/(\"|\||\'|\;)/\\$&/g;
$subject=~s/(\"|\||\'|\;)/\\$&/g;
$mime_type=~s/(\"|\||\'|\;)/\\$&/g;
$content_type=~s/(\"|\||\'|\;)/\\$&/g;
$x_mailer=~s/(\"|\||\'|\;)/\\$&/g;
$sender_ip=~s/(\"|\||\'|\;)/\\$&/g;
$message=~s/\s{2,}/ /gi;
my $status="NEW";
$message=~s/\s{2,}/ /gi;
### Parses the actual email address from the "Email From:" value in order to run it against vicidial_list
### Not sure how accurate this is
$email_from_name=$email_from;
$email_from_name=~s/\<?([^\s\@])+\@(([^\s\@\.])+\.)+[a-zA-Z]{2,}\>?//gi;
$email_from_name=~s/^\s*(.*?)\s*$/$1/;
$email_from=~/\<?([^\s\@])+\@(([^\s\@\.])+\.)+[a-zA-Z]{2,}\>?/i;
$email_from=$&;
$email_from=~s/(^\<)|(\>$)//gi;
$status="NEW";
$authentication_results=~/([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}/i;
$sender_ip=$&;
$received_spf=~/([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}/i;
$sender_ip2=$&;
if (length($sender_ip)==0) {$sender_ip=$sender_ip2;}
$limit=1;
$call_handle_clause="";
if ($call_handle_method eq "EMAILLOOKUP") {
$call_handle_clause="where email='$email_from' order by lead_id desc";
} elsif ($call_handle_method eq "EMAILLOOKUPRL") {
$call_handle_clause="where email='$email_from' and list_id='$list_id' order by lead_id desc";
} elsif ($call_handle_method eq "EMAILLOOKUPRC") {
my $list_id_stmt="select list_id from vicidial_lists where campaign_id='$campaign_id'";
my $list_id_rslt=$dbhA->prepare($list_id_stmt);
$list_id_rslt->execute();
$list_id_str="";
while (@list_id_row=$list_id_rslt->fetchrow_array) {
$list_id_str.="$list_id_row[0],";
}
$list_id_str=substr($list_id_str, 0, -1);
$call_handle_clause="where email='$email_from' and list_id in ($list_id_str) order by lead_id desc";
} else {
$limit=0;
}
### CHECK if lead exists in vicidial_list table via a search by email based on the email account settings
my $vicidial_lead_check_stmt="select lead_id from vicidial_list $call_handle_clause limit $limit";
my $vicidial_lead_check_rslt=$dbhA->prepare($vicidial_lead_check_stmt);
$vicidial_lead_check_rslt->execute();
if ($vicidial_lead_check_rslt->rows>0) {
my @lead_id_row=$vicidial_lead_check_rslt->fetchrow_array;
$lead_id=$lead_id_row[0];
} else {
my $vicidial_list_stmt="insert into vicidial_list(list_id, email, comments, status) values('$default_list_id', '$email_from', '".substr($message,0,255)."', '$status')";
if ($ARGV[0]=~/debugX/i) {print $vicidial_list_stmt;}
my $vicidial_list_rslt=$dbhA->prepare($vicidial_list_stmt);
if ($vicidial_list_rslt->execute()) {
$lead_id=$dbhA->last_insert_id(undef, undef, 'vicidial_list', 'lead_id');
} else {
die "Vicidial list insert failed. Check SQL in:\n $vicidial_list_stmt\n";
}
}
## Insert a new record into vicidial_email_list. This is ALWAYS done for new email messages.
my $ins_stmt="insert into vicidial_email_list(lead_id, protocol, email_date, email_to, email_from, email_from_name, subject, mime_type, content_type, x_mailer, sender_ip, message, email_account_id, group_id, status, direction) values('$lead_id', 'IMAP', STR_TO_DATE('$email_date', '%d %b %Y %T'), '$email_to', '$email_from', '$email_from_name', '$subject', '$mime_type', '$content_type', '$x_mailer', '$sender_ip', trim('$message'), '$VARemail_ID', '$VARemail_groupid', '$status', 'INBOUND')";
if ($ARGV[0]=~/debugX/i) {print $ins_stmt;}
my $ins_rslt=$dbhA->prepare($ins_stmt);
if ($ins_rslt->execute()) {
$pop->Delete($i);
if ($attach_ct>0) {
$email_id=$dbhA->last_insert_id(undef, undef, 'vicidial_email_list', 'email_row_id');
$multistmt="";
for ($k=0; $k<$attach_ct; $k++) {
$ins_values[$k]="('$email_id',$ins_values[$k])";
$multistmt.="$ins_values[$k],";
$output_ins_values[$k]="('$email_id',$output_ins_values[$k])";
$output_multistmt.="$output_ins_values[$k],";
}
$attachment_ins_stmt="insert into inbound_email_attachments(email_row_id, filename, file_type, file_encoding, file_size, file_extension, file_contents) VALUES ".substr($multistmt,0,-1);
$attachment_ins_rslt=$dbhA->prepare($attachment_ins_stmt);
$attachment_ins_rslt->execute();
$output_ins_stmt="insert into inbound_email_attachments(email_row_id, filename, file_type, file_encoding, file_size, file_extension, file_contents) VALUES ".substr($output_multistmt,0,-1);
if ($ARGV[0]=~/debugX/i) {print $output_ins_stmt."\n";}
}
if ($ARGV[0]=~/debug/i) {print "\n $attach_ct attachments in email\n";}
} else {
die "Email insert failed. Check SQL in:\n $ins_stmt\n";
}
}
#### END CYCLING THROUGH EMAILS
if ($ARGV[0]=~/debug/i) {
if ($ARGV[0]=~/debugX/i) {
print "Iteration #$q - found ".($pop->Count()+0)." new messages\n";
}
}
if ($ARGV[0]=~/debugX/i) {
print "Closing connection to finalize deletion of emails\n";
}
$pop->Close();
# sleep($sleep_time);
if ($ARGV[0]=~/debugX/i) {
print "Reconnecting to email account...\n";
}
$pop = new Mail::POP3Client( USER => "$VARemail_user",
PASSWORD => "$VARemail_pwd",
HOST => "$VARemail_server",
PORT => 995,
USESSL => true,
#DEBUG => true,
)
or die "Cannot connect through POP3Client: $!";
$pop->Close();
} else {
die "No valid protocol specified for this program: ($VARemail_protocol) is the current protocol - needs to be IMAP or POP3.\n";
}
}
}
sub StripHTML()
{
$message=~s/^\s*(.*?)\s*$/$1/;
$message=~s/[\r\n]/ /g;
if ($message=~/<html.*?<\/html>/i) {
$message=$&;
my $hs = HTML::Strip->new();
$message = $hs->parse( $message );
$hs->eof;
}
}
+385
View File
@@ -0,0 +1,385 @@
#!/usr/bin/perl
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
# Copyright (C) 2012 Joe Johnson, Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# VD_email_inbound.pl
# This script is responsible for assigning transferred and new emails to
# available agents. This is done by repeatedly checking for transferred emails
# waiting to be assigned sorted by email group rank, then all new emails
# waiting to be assigned, also sorted by email group rank. Then it checks
# the vicidial_live_agents table for agents with READY or CLOSER status.
#
# As it cycles through the prioritized emails to assign, it takes the inbound group
# each email belongs to, selects the agent it should be assigned to based on the
# next_agent_call setting, and puts that lead in QUEUE, as well as putting the
# chosen agent in a special MQUEUE status. Programming in other parts of Vicidial
# will cause these emails to be displayed in the agent's interface.
#
# This script should be set up on ONLY ONE SERVER. You set it up using the "E"
# keepalive option in the /etc/astguiclient.conf file on one of the servers in
# your cluster.
#
# changes:
# 121214-2303 - First Build
#
if ($ARGV[0]=~/--help/)
{
print "VD_email_inbound.pl\n";
print "\n";
print "This script is responsible for assigning transferred and new emails to\n";
print "available agents. This is done by repeatedly checking for transferred emails\n";
print "waiting to be assigned sorted by email group rank, then all new emails\n";
print "waiting to be assigned, also sorted by email group rank. Then it checks\n";
print "the vicidial_live_agents table for agents with READY or CLOSER status.\n";
print "\n";
print "As it cycles through the prioritized emails to assign, it takes the inbound\n";
print "group each email belongs to, selects the agent it should be assigned to based\n";
print "on the next_agent_call setting, and puts that lead in QUEUE, as well as putting\n";
print "the chosen agent in a special MQUEUE status. Programming in other parts of \n";
print "Vicidial will cause these emails to be displayed in the agent's interface.\n";
print "\n";
print "This script should be set up on ONLY ONE SERVER. You set it up using the \"E\"\n";
print "keepalive option in the /etc/astguiclient.conf file on one of the servers in\n";
print "your cluster.\n";
print "\n";
print "Use the --debug variable when executing the script to have it print out the SQL\n";
print "statements it is attempting to execute.\n";
exit;
}
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
$|=1;
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
if (!$PRSLOGfile) {$PRSLOGfile = "$PATHlogs/prsout.$year-$mon-$mday";}
if (!$PRSTESTfile) {$PRSTESTfile = "$PATHlogs/prstest.$year-$mon-$mday";}
if (!$ERRLOGfile) {$ERRLOGfile = "$PATHlogs/MySQLerror.$year-$mon-$mday";}
use DBI;
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
$dbhB = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$hm = "$hour$min";
$hm = ($hm + 0);
$now_date_epoch = time();
$start_epoch = $now_date_epoch;
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$CLInow_date = "$year-$mon-$mday\\ $hour:$min:$sec";
$YMD = "$year-$mon-$mday";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec";
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$ORIGINAL_call_time = $SQLdate;
while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959
$BDtarget = ($now_date_epoch - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
#$ADUfindSQL - for AGENTDIRECT, not necessary
#$INBOUNDcampsSQL*
#$BDtsSQLdate*
#$ring_no_answer_agents - not necessary?
#$vlia_users - queue_priority, already handled?
#$qp_groupWAIT_camp_SQL - queue_priority, already handled?
#$qp_groupWAIT_SQL - queue_priority, already handled?
#$vig_stmt="select campaign_id, queue_priority, next_agent_call from vicidial_inbound_groups where group_handling='EMAIL' and active='Y' order by queue_priority desc";
#$vig_rslt=$dbhA->prepare($vig_stmt);
#$vig_rslt->execute();
for ($i=0; $i<=1000000; $i++)
{
$vci=0;
$INBOUNDcampsSQL='';
$stmtA = "SELECT campaign_id FROM vicidial_campaigns where active='Y' and campaign_allow_inbound='Y';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02033'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $vci)
{
@aryA = $sthA->fetchrow_array;
if ($vci < 1) {$INBOUNDcampsSQL = "'$aryA[0]'";}
else {$INBOUNDcampsSQL .= ",'$aryA[0]'";}
$vci++;
}
$sthA->finish();
# CHECK IF THERE ARE ANY EMAIL GROUPS ACTIVE TO SCAN
$order_stmt="select group_id, next_agent_call from vicidial_inbound_groups where group_handling='EMAIL' and active='Y'";
$order_rslt=$dbhA->prepare($order_stmt);
$order_rslt->execute or die "executing: $order_stmt ", $dbhA->errstr;
if ($order_rslt->rows>0)
{
%group_orders=();
while (@order_row=$order_rslt->fetchrow_array)
{
$group_orders{"$order_row[0]"}=$order_row[1];
}
$email_ct=0;
## CHECK IF THERE ARE ANY TRANSFERS TO ASSIGN
$xfer_stmt="select email_row_id, vicidial_xfer_log.lead_id, vicidial_xfer_log.campaign_id, vicidial_inbound_groups.next_agent_call from vicidial_email_list, vicidial_inbound_groups, vicidial_xfer_log where vicidial_inbound_groups.group_handling='EMAIL' and vicidial_inbound_groups.active='Y' and vicidial_inbound_groups.group_id=vicidial_xfer_log.campaign_id and vicidial_xfer_log.closer='EMAIL_XFER' and vicidial_xfer_log.lead_id=vicidial_email_list.lead_id and vicidial_xfer_log.xfercallid=vicidial_email_list.xfercallid order by queue_priority desc, email_date asc";
if ($ARGV[0]=~/debug/i) {print $xfer_stmt."\n";}
$xfer_rslt=$dbhB->prepare($xfer_stmt);
$xfer_rslt->execute or die "executing: $xfer_stmt ", $dbhB->errstr;
$xfers_to_assign=$xfer_rslt->rows;
if ($xfers_to_assign>0)
{
while (@xfer_row=$xfer_rslt->fetchrow_array)
{
$row_id_ary[$email_ct]=$xfer_row[0];
$lead_id_ary[$email_ct]=$xfer_row[1];
$group_id_ary[$email_ct]=$xfer_row[2];
$email_type_ary[$email_ct]="XFER";
$email_ct++;
}
}
$xfer_rslt->finish();
## CHECK IF THERE ARE ANY REGULAR EMAILS TO ASSIGN
$inb_stmt="select email_row_id, lead_id, vicidial_email_list.group_id, vicidial_inbound_groups.next_agent_call from vicidial_email_list, vicidial_inbound_groups where group_handling='EMAIL' and active='Y' and vicidial_inbound_groups.group_id=vicidial_email_list.group_id and vicidial_email_list.status='NEW' order by queue_priority desc, email_date asc";
if ($ARGV[0]=~/debug/i) {print $inb_stmt."\n";}
$inb_rslt=$dbhB->prepare($inb_stmt);
$inb_rslt->execute or die "executing: $inb_stmt ", $dbhB->errstr;
$emails_to_assign=$inb_rslt->rows;
if ($emails_to_assign>0)
{
while (@inb_row=$inb_rslt->fetchrow_array)
{
$row_id_ary[$email_ct]=$inb_row[0];
$lead_id_ary[$email_ct]=$inb_row[1];
$group_id_ary[$email_ct]=$inb_row[2];
$email_type_ary[$email_ct]="INCOMING";
$email_ct++;
}
}
$inb_rslt->finish();
if ($email_ct>0) {AssignAgents();} else {if ($ARGV[0]=~/debug/i) {print "**** NO EMAILS TO QUEUE ****\n";}}
}
usleep(100000);
}
sub AssignAgents()
{
if ($ARGV[0]=~/debug/i) {print $xfers_to_assign." transfers to assign\n".$emails_to_assign." incoming emails to assign...\n";}
for ($q=0; $q<$email_ct; $q++)
{
$CAMP_callorder=$group_orders{"$group_id_ary[$q]"};
$email_row_id=$row_id_ary[$q];
$lead_id=$lead_id_ary[$q];
$email_type=$email_type_ary[$q];
$group_id=$group_id_ary[$q];
$ADUfindSQL='';
$user='';
$ring_no_answer_agents = "''";
$aco_sub=0;
$agent_call_order='order by last_call_finish';
if ($CAMP_callorder =~ /longest_wait_time/i) {$agent_call_order = 'order by vicidial_live_agents.last_state_change';}
if ($CAMP_callorder =~ /overall_user_level/i) {$agent_call_order = 'order by user_level desc,last_call_finish';}
if ($CAMP_callorder =~ /oldest_call_start/i) {$agent_call_order = 'order by vicidial_live_agents.last_call_time';} #
if ($CAMP_callorder =~ /oldest_call_finish/i) {$agent_call_order = 'order by vicidial_live_agents.last_call_finish';}
if ($CAMP_callorder =~ /oldest_inbound_call_start/i) {$agent_call_order = 'order by vicidial_live_agents.last_inbound_call_time';} #
if ($CAMP_callorder =~ /oldest_inbound_call_finish/i) {$agent_call_order = 'order by vicidial_live_agents.last_inbound_call_finish';} #
if ($CAMP_callorder =~ /random/i) {$agent_call_order = 'order by random_id';}
if ($CAMP_callorder =~ /campaign_rank/i) {$agent_call_order = 'order by campaign_weight desc,last_call_finish';}
if ($CAMP_callorder =~ /fewest_calls_campaign/i) {$agent_call_order = 'order by vicidial_live_agents.calls_today,vicidial_live_agents.last_call_finish';}
if ($CAMP_callorder =~ /ingroup_grade_random/i) {$aco_sub=1; $agent_call_order = 'order by random_id';}
if ($CAMP_callorder =~ /campaign_grade_random/i) {$aco_sub=1; $agent_call_order = 'order by random_id';}
if ($CAMP_callorder =~ /inbound_group_rank/i) {$aco_sub=1; $agent_call_order = 'order by group_weight desc,vicidial_live_inbound_agents.last_call_finish';}
if ($CAMP_callorder =~ /fewest_calls$/i) {$aco_sub=1; $agent_call_order = 'order by vicidial_live_inbound_agents.calls_today,vicidial_live_inbound_agents.last_call_finish';}
if ($aco_sub > 0)
{
$stmtA = "LOCK TABLES vicidial_live_agents WRITE, vicidial_live_inbound_agents WRITE;";
my $LOCKaffected_rows = $dbhA->do($stmtA);
$stmtA = "SELECT vicidial_live_agents.user from vicidial_live_agents, vicidial_live_inbound_agents WHERE vicidial_live_agents.user=vicidial_live_inbound_agents.user and status IN('CLOSER','READY') and lead_id<1 $ADUfindSQL and vicidial_live_inbound_agents.group_id='$group_id' and last_update_time > '$BDtsSQLdate' and vicidial_live_agents.user NOT IN($ring_no_answer_agents$vlia_users) and ring_callerid='' $qp_groupWAIT_camp_SQL $agent_call_order limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($ARGV[0]=~/debug/i) {print $stmtA."\n";}
# if ($CAMP_callorder =~ /grade/)
# {
# $stmtA = "SELECT vicidial_live_agents.user,vicidial_live_inbound_agents.group_grade,vicidial_live_agents.campaign_grade from vicidial_live_agents, vicidial_live_inbound_agents WHERE vicidial_live_agents.user=vicidial_live_inbound_agents.user and status IN('CLOSER','READY') and lead_id<1 $ADUfindSQL and vicidial_live_inbound_agents.group_id='$group_id' and last_update_time > '$BDtsSQLdate' and vicidial_live_agents.user NOT IN($ring_no_answer_agents$vlia_users) and ring_callerid='' $qp_groupWAIT_camp_SQL limit 1000;";
# $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
# $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
# $sthArows=$sthA->rows;
# }
# else
# {
# $stmtA = "SELECT vicidial_live_agents.conf_exten,vicidial_live_agents.user,vicidial_live_agents.extension,vicidial_live_agents.server_ip,vicidial_live_inbound_agents.group_weight,ra_user,vicidial_live_agents.campaign_id,on_hook_agent,on_hook_ring_time,vicidial_live_inbound_agents.group_grade,vicidial_live_agents.campaign_grade from vicidial_live_agents, vicidial_live_inbound_agents WHERE vicidial_live_agents.user=vicidial_live_inbound_agents.user and status IN('CLOSER','READY') and lead_id<1 $ADUfindSQL and vicidial_live_inbound_agents.group_id='$group_id' and last_update_time > '$BDtsSQLdate' and vicidial_live_agents.user NOT IN($ring_no_answer_agents$vlia_users) and ring_callerid='' $qp_groupWAIT_camp_SQL $agent_call_order limit 1;";
# $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
# $sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
# $sthArows=$sthA->rows;
# }
if ($sthArows>0)
{
while (@user_row=$sthA->fetchrow_array)
{
$user=$user_row[0];
}
$sthA->finish();
}
if ($user ne "")
{
$upd_stmt="update vicidial_email_list set status='QUEUE', user='$user' where email_row_id='$email_row_id'";
$upd_rslt=$dbhB->prepare($upd_stmt);
$upd_rslt->execute or die "executing: $upd_stmt ", $dbhB->errstr;
$upd_rslt->finish();
if ($ARGV[0]=~/debug/i) {print $upd_stmt."\n";}
$upd_stmt="update vicidial_live_agents set status='MQUEUE' where user='$user'";
$upd_rslt=$dbhA->prepare($upd_stmt);
$upd_rslt->execute or die "executing: $upd_stmt ", $dbhB->errstr;
$upd_rslt->finish();
if ($ARGV[0]=~/debug/i) {print $upd_stmt."\n";}
}
$stmtA = "UNLOCK TABLES;";
my $LOCKaffected_rows = $dbhA->do($stmtA);
}
else
{
$stmtA = "LOCK TABLES vicidial_live_agents WRITE;";
my $LOCKaffected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02158'; $MEL_aff_rows=$LOCKaffected_rows; &mysql_error_logging;
$stmtA = "SELECT user FROM vicidial_live_agents where status IN('CLOSER','READY') and lead_id<1 $ADUfindSQL and campaign_id IN($INBOUNDcampsSQL) and closer_campaigns LIKE \"% $group_id %\" and last_update_time > '$BDtsSQLdate' and vicidial_live_agents.user NOT IN($ring_no_answer_agents) $qp_groupWAIT_SQL $qp_groupWAIT_camp_SQL $agent_call_order limit 1;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
if ($ARGV[0]=~/debug/i) {print $stmtA."\n";}
$sthArows=$sthA->rows;
if ($sthArows>0)
{
while (@user_row=$sthA->fetchrow_array)
{
$user=$user_row[0];
}
$sthA->finish();
}
if ($user ne "")
{
$upd_stmt="update vicidial_email_list set status='QUEUE', user='$user' where email_row_id='$email_row_id'";
$upd_rslt=$dbhB->prepare($upd_stmt);
$upd_rslt->execute or die "executing: $upd_stmt ", $dbhB->errstr;
$upd_rslt->finish();
if ($ARGV[0]=~/debug/i) {print $upd_stmt."\n";}
$upd_stmt="update vicidial_live_agents set status='MQUEUE' where user='$user'";
$upd_rslt=$dbhA->prepare($upd_stmt);
$upd_rslt->execute or die "executing: $upd_stmt ", $dbhB->errstr;
$upd_rslt->finish();
if ($ARGV[0]=~/debug/i) {print $upd_stmt."\n";}
}
$stmtA = "UNLOCK TABLES;";
my $LOCKaffected_rows = $dbhA->do($stmtA);
}
}
if ($ARGV[0]=~/debug/i) {print "\n\n";}
}
sub mysql_error_logging
{
($Lsec,$Lmin,$Lhour,$Lmday,$Lmon,$Lyear,$Lwday,$Lyday,$Lisdst) = localtime(time);
if ($Lhour < 10) {$Lhour = "0$Lhour";}
if ($Lmin < 10) {$Lmin = "0$Lmin";}
if ($Lsec < 10) {$Lsec = "0$Lsec";}
$LOGtime = "$Lhour:$Lmin:$Lsec";
$errno='';
$error='';
if ( ($mel > 0) || ($one_mysql_log > 0) )
{
$errno = $dbhP->err();
if ( ($errno > 0) || ($mel > 1) || ($one_mysql_log > 0) )
{
$error = $dbhP->errstr();
### open the log file for writing ###
open(Eout, ">>$ERRLOGfile")
|| die "Can't open $ERRLOGfile: $!\n";
print Eout "$now_date|$LOGtime|$script|$mysql_count|$MEL_aff_rows|$errno|$error|$stmtA|$callerid|$insert_lead_id|\n";
close(Eout);
}
}
$one_mysql_log=0;
}
+3
View File
@@ -475,6 +475,9 @@ PHASE 6: ADDING CRONTAB ENTRIES FOR ASTGUICLIENT/VICIDIAL SCRIPTS
### VICIDIAL agent time log weekly summary report generation
2 0 * * 0 /usr/share/astguiclient/AST_agent_week.pl
### inbound email parser
#* * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl
### remove old recordings more than 7 days old
#24 0 * * * /usr/bin/find /var/spool/asterisk/monitorDONE -maxdepth 2 -type f -mtime +7 -print | xargs rm -f
+25
View File
@@ -0,0 +1,25 @@
In order to use this feature, the very first thing you need is an email account to handle your incoming emails. This account must operate under either the IMAP or POP3 mail protocols, as these are currenty the only two that Vicidial supports. You can sign up for a free Gmail account, which uses the IMAP protocol, or a Yahoo! account, which uses POP3. People using this feature may find it more feasible to use an email that operates under the IMAP protocol. The reason for this is that if you use a POP3 account, messages sent to it will be erased upon discovery by your Vicidial installation. This is because the programming involved does not allow POP3 accounts to have their email messages marked to prevent repeat pullings from the mailbox, and therefore the email message must be erased once imported, whereas IMAP accounts are supported such that they can be marked as read.
Once you have created your new email account, you must set it up in the dialer so that the dialer will be able to connect to it and collect any emails in it and import those into the dialer. First, the dialer must have the "Emails Enabled" setting turned on under the "System Settings" page in the "Admin" section. Ensure that this value is set to "1" and if not, switch it to that and submit the changed system settings. Now, you must also turn on the modification privileges for the users who will be able to modify email accounts. This can be found under the "Admin Interface Options" section on the user's account page and is called "Modify Email Accounts".
With the email settings enabled and having users who can update email account-related information, you must now create an email group that Vicidial will "file" incoming emails under so that they can be routed to the appropriate agents in the appropriate campaigns. This is done by clicking on the "Inbound" link at left. From the list of links that appear beneath the "Inbound" link, click on the "Add New Email Group". This will take you to a form that you must fill out. All new email groups must be given a group ID and a group name. Click the "SUBMIT" button and if the form was filled out correctly, you will have created an inbound group that will handle email messages, as opposed to the "regular" in-groups which handle phone calls. Remember to set the "Active" setting to "Y" once you're ready to have email messages collected and stored.
When the email setting is enabled and the email in-group is created, you can create the email account settings that will tell the dialer where and how to connect to your email account and the in-group to file them under. Under the "Admin" section, click on the "Email Accounts" setting. Click on the "Add a New Account" link at the top of the page and you will be taken to the form you must fill out with all the necessary information for Vicidial to connect to your email account. You must set an email account ID and an email account description, both of which are relatively arbitrary. More importantly, make sure the proper protocol (IMAP or POP3) is selected, and that the email reply-to address (which is just the actual email address on the account) and the email account server is entered properly (ex: gmail is imap.gmail.com). You also need to enter the username and password that is used to access the account, and also the frequency that Vicidial should check your account for new emails. Some email accounts do not allow more than a few logins over a set amount of time, so at the moment the highest rate of frequency that Vicidial will allow is one login attempt every five minutes. Fill out the remaining fields (click the "?" button by any field that needs explaining - if you are familiar with inbound groups, most of these fields work in the same way) and submit the new email account. When you are ready to have Vicidial start checking it for emails, be sure the "Active" setting is set to "Y".
The checking of email accounts is handled by a cron job that should only be active on ONE server on your Vicidial installation:
* * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl
This script will check to see if any active email account is due to be checked for new messages, per the "Email Frequency Check Rate" setting on the active accounts. If new emails are found in an active account, one of two things will happen, depending on the account protocol. As stated earlier, IMAP accounts will have the message marked as read, so it will not be pulled into your Vicidial database again, but in POP3 accounts the message will be erased. When this script finds an email to insert into the Vicidial dialer, it will parse out the pertininent information from the header and body of the email, and then based on the "In-Group Call Handle Method" setting for the associated email account, it will insert the data as a new lead in the vicidial_list table or check the vicidial_list table for the email address and use the lead_id from the found record to create a new lead in the vicidial_email_list table. Both tables can be tied together by the lead_id column. Also, if the email message has any attachments, those will be inserted into the inbound_email_attachments table, with the email_row_id column in that table tying back to the column of the same name in vicidial_email_list.
With the email messages being imported into your Vicidial system, you can now set up campaigns to distribute the messages out to agents who log in to the appropriate campaigns. This is identical to the procedure for setting up inbound calls. All you do is view the "Detail View" for the campaign(s) that is/are to receive these emails, and under the "Allowed Inbound Groups" section, check the box next to each email in-group that the campaign will take. Campaigns must be set as RATIO, INBOUND_MAN, or any of the ADAPT dial methods(?). Emails can even be transferred to other agents, similar to transferring phone calls. This is done in the same way; set up an email in-group, and then under the "Detail View" setting for a campaign, check the box for that group under the "Allowed Transfer Group" to allow emails to be transferred to that ingroup, and in turn another campaign can be set up to accept these transfers by making that in-group an "Allowed Inbound Group".
Once this is all set up, emails will start to come in to your system. In the agent interface, there is now a new tab called "EMAIL" at the top of the screen. This is the default call launch for email messages, and is the screen that will automatically be displayed for the agents. From here, agents can see the sent message and the address of the person who sent it (and sometimes the sender name), and can even view any attachments the sender included. Agents can type a plain text response to the incoming message, and can also send back attachments of their own. The system will notify the agent if an email attempt is successful, and these message "calls" can be terminated in the same way as a regular phone call, by clicking the "HANGUP CUSTOMER" button or using HotKeys.
The order in which incoming emails will be distributed to the agents is determined by the queue_priority setting on each in-group, and then by the date in which the email was sent. In other words, unless one email-group has a higher priority over another, agents will always receive the oldest emails first. In addition, email in-groups will also prioritize agents based on the "Next agent call" setting for each ingroup. Agents can be prioritized based on the number of calls/emails they have received, or by rank or by one of the time values stored in the vicidial_live_agent table.
The determination of the order in which emails are distributed out to agents and the determination of the order of which agents are to receive emails are both handled by a single script, VD_email_inbound.pl, which is implemented thusly in ONE server's crontab:
* * * * * /usr/share/astguiclient/VD_email_inbound.pl
This is a perpetually-running script that is constantly checking the vicidial_email_list and vicidial_xfer_log tables for any email messages that need to be queued and handled by an agent. Emails from transfer in-groups always take precedence over regular incoming emails, regardless of the queue priority setting. However, the queue priority is taken into consideration if multiple transfer in-groups have emails that need handling. This script first checks the vicidial_xfer_log table for email messages that have been transferred by an agent, and then checks the vicidial_email_list table for any new email messages that have not yet been handled by any agent. Once a list of emails to queue has been generated, this script go through each email one at a time, and will take the in-group the email belongs to and check the system for any agents in a READY or CLOSER status who are currently taking emails that in-group. If more than one agent is available, the agents selected to receive the messages is determined by the "Next agent call" setting for the group the message belongs to. The script will proceed in this fashion until all email messages have been assigned or all active agents have been given a message. The script will then sleep for a brief period and then repeat the process.
@@ -74,6 +74,17 @@ install Text::CSV_PP
install File::Temp
install Text::CSV_XS
install Spreadsheet::Read
install LWP::UserAgent
install HTML::Entities
install HTML::Strip
install HTML::FormatText
install HTML::TreeBuilder
install Switch
install Time::Local
install MIME::Decoder
install Mail::POP3Client
install Mail::IMAPClient
install Mail::Message
quit
+14
View File
@@ -448,6 +448,17 @@ following modules first: (say YES if asked to install prerequisites)
- install File::Temp
- install Text::CSV_XS
- install Spreadsheet::Read
- install LWP::UserAgent
- install HTML::Entities
- install HTML::Strip
- install HTML::FormatText
- install HTML::TreeBuilder
- install Switch
- install Time::Local
- install MIME::Decoder
- install Mail::POP3Client
- install Mail::IMAPClient
- install Mail::Message
- then quit cpan, you are done
5. Go to http://asterisk.gnuinter.net/ and download the asterisk-perl module
(backup link: http://download.vicidial.com/packages/asterisk-perl-0.08.tar.gz)
@@ -2462,6 +2473,9 @@ SUBPHASE 6.5: setting up astguiclient scripts for continuous running
#32 0 * * * /usr/share/astguiclient/AST_VDsales_export.pl
#42 0 * * * /usr/share/astguiclient/AST_sourceID_summary_export.pl
### inbound email parser
#* * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl
### inventory report optional
#1 7 * * * /usr/share/astguiclient/AST_dialer_inventory_snapshot.pl -q --override-24hours
@@ -357,7 +357,7 @@ user VARCHAR(20),
server_ip VARCHAR(15) NOT NULL,
conf_exten VARCHAR(20),
extension VARCHAR(100),
status ENUM('READY','QUEUE','INCALL','PAUSED','CLOSER') default 'PAUSED',
status ENUM('READY','QUEUE','INCALL','PAUSED','CLOSER','MQUEUE') default 'PAUSED',
lead_id INT(9) UNSIGNED NOT NULL,
campaign_id VARCHAR(8),
uniqueid VARCHAR(20),
@@ -599,7 +599,9 @@ preset_contact_search ENUM('NOT_ACTIVE','ENABLED','DISABLED') default 'NOT_ACTIV
modify_contacts ENUM('1','0') default '0',
modify_same_user_level ENUM('0','1') default '1',
admin_hide_lead_data ENUM('0','1') default '0',
admin_hide_phone_data ENUM('0','1','2_DIGITS','3_DIGITS','4_DIGITS') default '0'
admin_hide_phone_data ENUM('0','1','2_DIGITS','3_DIGITS','4_DIGITS') default '0',
agentcall_email ENUM('0','1') default '0',
modify_email_accounts ENUM('0','1') default '0'
);
CREATE UNIQUE INDEX user ON vicidial_users (user);
@@ -860,7 +862,8 @@ in_group_dial_select ENUM('AGENT_SELECTED','CAMPAIGN_SELECTED','ALL_USER_GROUP')
safe_harbor_audio_field VARCHAR(30) default 'DISABLED',
pause_after_next_call ENUM('ENABLED','DISABLED') default 'DISABLED',
owner_populate ENUM('ENABLED','DISABLED') default 'DISABLED',
use_other_campaign_dnc VARCHAR(8) default ''
use_other_campaign_dnc VARCHAR(8) default '',
allow_emails ENUM('Y','N') default 'N'
);
CREATE TABLE vicidial_lists (
@@ -961,7 +964,7 @@ voicemail_ext VARCHAR(10),
next_agent_call VARCHAR(30) default 'longest_wait_time',
fronter_display ENUM('Y','N') default 'Y',
ingroup_script VARCHAR(10),
get_call_launch ENUM('NONE','SCRIPT','WEBFORM','WEBFORMTWO','FORM') default 'NONE',
get_call_launch ENUM('NONE','SCRIPT','WEBFORM','WEBFORMTWO','FORM','EMAIL') default 'NONE',
xferconf_a_dtmf VARCHAR(50),
xferconf_a_number VARCHAR(50),
xferconf_b_dtmf VARCHAR(50),
@@ -1064,7 +1067,8 @@ user_group VARCHAR(20) default '---ALL---',
max_calls_method ENUM('TOTAL','IN_QUEUE','DISABLED') default 'DISABLED',
max_calls_count SMALLINT(5) default '0',
max_calls_action ENUM('DROP','AFTERHOURS','NO_AGENT_NO_QUEUE') default 'NO_AGENT_NO_QUEUE',
dial_ingroup_cid VARCHAR(20) default ''
dial_ingroup_cid VARCHAR(20) default '',
group_handling ENUM('PHONE','EMAIL') default 'PHONE'
);
CREATE TABLE vicidial_stations (
@@ -1499,7 +1503,8 @@ audio_store_purge TEXT,
svn_revision INT(9) default '0',
queuemetrics_socket VARCHAR(20) default 'NONE',
queuemetrics_socket_url TEXT,
enhanced_disconnect_logging ENUM('0','1') default '0'
enhanced_disconnect_logging ENUM('0','1') default '0',
allow_emails ENUM('0','1') default '0'
);
CREATE TABLE vicidial_campaigns_list_mix (
@@ -2770,6 +2775,84 @@ default_afterhours_filename_override VARCHAR(255) default '',
user_group VARCHAR(20) default '---ALL---'
);
CREATE TABLE vicidial_email_list (
email_row_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
lead_id INT(9) UNSIGNED DEFAULT NULL,
email_date DATETIME DEFAULT NULL,
protocol ENUM('POP3','IMAP','NONE') DEFAULT 'IMAP',
email_to VARCHAR(255) DEFAULT NULL,
email_from VARCHAR(255) DEFAULT NULL,
email_from_name VARCHAR(255) DEFAULT NULL,
subject TEXT,
mime_type TEXT,
content_type TEXT,
x_mailer TEXT,
sender_ip VARCHAR(25) DEFAULT NULL,
message TEXT,
email_account_id VARCHAR(20) DEFAULT NULL,
group_id VARCHAR(20) DEFAULT NULL,
user VARCHAR(20) DEFAULT NULL,
status VARCHAR(10) DEFAULT NULL,
direction ENUM('INBOUND','OUTBOUND') DEFAULT 'INBOUND',
uniqueid VARCHAR(20) DEFAULT NULL,
xfercallid INT(9) UNSIGNED DEFAULT NULL,
PRIMARY KEY (email_row_id),
KEY email_list_account_key (email_account_id),
KEY email_list_user_key (user),
KEY vicidial_email_lead_id_key (lead_id)
);
CREATE TABLE vicidial_email_accounts (
email_account_id VARCHAR(20) NOT NULL,
email_account_name VARCHAR(100) DEFAULT NULL,
email_account_description VARCHAR(255) DEFAULT NULL,
user_group VARCHAR(20) DEFAULT '---ALL---',
protocol ENUM('POP3','IMAP','SMTP') DEFAULT 'IMAP',
email_replyto_address VARCHAR(255) DEFAULT NULL,
email_account_server VARCHAR(255) DEFAULT NULL,
email_account_user VARCHAR(255) DEFAULT NULL,
email_account_pass VARCHAR(100) DEFAULT NULL,
active ENUM('Y','N') DEFAULT 'N',
email_frequency_check_mins TINYINT(3) UNSIGNED DEFAULT '5',
group_id VARCHAR(20) DEFAULT NULL,
default_list_id BIGINT(14) UNSIGNED DEFAULT NULL,
call_handle_method VARCHAR(20) DEFAULT 'CID',
agent_search_method ENUM('LO','LB','SO') DEFAULT 'LB',
campaign_id VARCHAR(8) DEFAULT NULL,
list_id BIGINT(14) UNSIGNED DEFAULT NULL,
email_account_type ENUM('INBOUND','OUTBOUND') DEFAULT 'INBOUND',
PRIMARY KEY (email_account_id),
KEY email_accounts_group_key (group_id)
);
CREATE TABLE inbound_email_attachments (
attachment_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
email_row_id INT(10) UNSIGNED DEFAULT NULL,
filename VARCHAR(250) NOT NULL DEFAULT '',
file_type VARCHAR(100) DEFAULT NULL,
file_encoding VARCHAR(20) DEFAULT NULL,
file_size VARCHAR(45) DEFAULT NULL,
file_extension VARCHAR(5) NOT NULL DEFAULT '',
file_contents LONGBLOB NOT NULL,
PRIMARY KEY (attachment_id),
KEY attachments_email_id_key (email_row_id)
);
CREATE TABLE vicidial_email_log (
email_log_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
email_row_id INT(10) UNSIGNED DEFAULT NULL,
lead_id INT(9) UNSIGNED DEFAULT NULL,
email_date DATETIME DEFAULT NULL,
user VARCHAR(20) DEFAULT NULL,
email_to VARCHAR(255) DEFAULT NULL,
message TEXT,
campaign_id VARCHAR(10) DEFAULT NULL,
attachments TEXT,
PRIMARY KEY (email_log_id),
KEY vicidial_email_log_lead_id_key (lead_id),
KEY vicidial_email_log_email_row_id_key (email_row_id)
);
ALTER TABLE vicidial_qc_codes ADD qc_result_type ENUM( 'PASS', 'FAIL', 'CANCEL', 'COMMIT' ) NOT NULL;
@@ -3005,4 +3088,4 @@ UPDATE vicidial_configuration set value='1766' where name='qc_database_version';
UPDATE system_settings set vdc_agent_api_active='1';
UPDATE system_settings SET db_schema_version='1336',db_schema_update_date=NOW();
UPDATE system_settings SET db_schema_version='1337',db_schema_update_date=NOW();
+92
View File
@@ -199,3 +199,95 @@ ALTER TABLE vicidial_campaigns MODIFY agent_lead_search ENUM('ENABLED','LIVE_CAL
ALTER TABLE vicidial_users MODIFY agent_lead_search_override ENUM('NOT_ACTIVE','ENABLED','LIVE_CALL_INBOUND','LIVE_CALL_INBOUND_AND_MANUAL','DISABLED') default 'NOT_ACTIVE';
UPDATE system_settings SET db_schema_version='1336',db_schema_update_date=NOW() where db_schema_version < 1336;
CREATE TABLE vicidial_email_list (
email_row_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
lead_id INT(9) UNSIGNED DEFAULT NULL,
email_date DATETIME DEFAULT NULL,
protocol ENUM('POP3','IMAP','NONE') DEFAULT 'IMAP',
email_to VARCHAR(255) DEFAULT NULL,
email_from VARCHAR(255) DEFAULT NULL,
email_from_name VARCHAR(255) DEFAULT NULL,
subject TEXT,
mime_type TEXT,
content_type TEXT,
x_mailer TEXT,
sender_ip VARCHAR(25) DEFAULT NULL,
message TEXT,
email_account_id VARCHAR(20) DEFAULT NULL,
group_id VARCHAR(20) DEFAULT NULL,
user VARCHAR(20) DEFAULT NULL,
status VARCHAR(10) DEFAULT NULL,
direction ENUM('INBOUND','OUTBOUND') DEFAULT 'INBOUND',
uniqueid VARCHAR(20) DEFAULT NULL,
xfercallid INT(9) UNSIGNED DEFAULT NULL,
PRIMARY KEY (email_row_id),
KEY email_list_account_key (email_account_id),
KEY email_list_user_key (user),
KEY vicidial_email_lead_id_key (lead_id)
);
CREATE TABLE vicidial_email_accounts (
email_account_id VARCHAR(20) NOT NULL,
email_account_name VARCHAR(100) DEFAULT NULL,
email_account_description VARCHAR(255) DEFAULT NULL,
user_group VARCHAR(20) DEFAULT '---ALL---',
protocol ENUM('POP3','IMAP','SMTP') DEFAULT 'IMAP',
email_replyto_address VARCHAR(255) DEFAULT NULL,
email_account_server VARCHAR(255) DEFAULT NULL,
email_account_user VARCHAR(255) DEFAULT NULL,
email_account_pass VARCHAR(100) DEFAULT NULL,
active ENUM('Y','N') DEFAULT 'N',
email_frequency_check_mins TINYINT(3) UNSIGNED DEFAULT '5',
group_id VARCHAR(20) DEFAULT NULL,
default_list_id BIGINT(14) UNSIGNED DEFAULT NULL,
call_handle_method VARCHAR(20) DEFAULT 'CID',
agent_search_method ENUM('LO','LB','SO') DEFAULT 'LB',
campaign_id VARCHAR(8) DEFAULT NULL,
list_id BIGINT(14) UNSIGNED DEFAULT NULL,
email_account_type ENUM('INBOUND','OUTBOUND') DEFAULT 'INBOUND',
PRIMARY KEY (email_account_id),
KEY email_accounts_group_key (group_id)
);
CREATE TABLE inbound_email_attachments (
attachment_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
email_row_id INT(10) UNSIGNED DEFAULT NULL,
filename VARCHAR(250) NOT NULL DEFAULT '',
file_type VARCHAR(100) DEFAULT NULL,
file_encoding VARCHAR(20) DEFAULT NULL,
file_size VARCHAR(45) DEFAULT NULL,
file_extension VARCHAR(5) NOT NULL DEFAULT '',
file_contents LONGBLOB NOT NULL,
PRIMARY KEY (attachment_id),
KEY attachments_email_id_key (email_row_id)
);
CREATE TABLE vicidial_email_log (
email_log_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
email_row_id INT(10) UNSIGNED DEFAULT NULL,
lead_id INT(9) UNSIGNED DEFAULT NULL,
email_date DATETIME DEFAULT NULL,
user VARCHAR(20) DEFAULT NULL,
email_to VARCHAR(255) DEFAULT NULL,
message TEXT,
campaign_id VARCHAR(10) DEFAULT NULL,
attachments TEXT,
PRIMARY KEY (email_log_id),
KEY vicidial_email_log_lead_id_key (lead_id),
KEY vicidial_email_log_email_row_id_key (email_row_id)
);
ALTER TABLE system_settings ADD allow_emails ENUM('0','1') default '0';
ALTER TABLE vicidial_campaigns ADD allow_emails ENUM('Y','N') default 'N';
ALTER TABLE vicidial_inbound_groups ADD group_handling ENUM('PHONE','EMAIL') default 'PHONE';
ALTER TABLE vicidial_inbound_groups MODIFY get_call_launch get_call_launch ENUM('NONE','SCRIPT','WEBFORM','WEBFORMTWO','FORM','EMAIL') default 'NONE';
ALTER TABLE vicidial_users ADD agentcall_email ENUM('0','1') default '0';
ALTER TABLE vicidial_users ADD modify_email_accounts ENUM('0','1') default '0';
ALTER TABLE vicidial_live_agents MODIFY status ENUM('READY','QUEUE','INCALL','PAUSED','CLOSER','MQUEUE') default 'PAUSED';
UPDATE system_settings SET db_schema_version='1337',db_schema_update_date=NOW() where db_schema_version < 1337;
+4
View File
@@ -27,6 +27,7 @@
# 110812-1510 - Added tts sound directories creation
# 120224-1614 - Added function to clear out web auth log files
# 121027-1750 - Added svn logging information
# 121215-2059 - Added keepalive option E for email process
#
############################################
@@ -189,6 +190,7 @@ if (length($ARGV[0])>1)
print " 7 - AST_VDauto_dial_FILL (only for multi-server, this must only be on one server)\n";
print " 8 - ip_relay (used for blind agent monitoring)\n";
print " 9 - Timeclock auto-logout\n";
print " E - Email processor, (If multi-server system, this must only be on one server)\n";
print " [--asterisk_version] = set the asterisk version you want to install for\n";
print " [--copy_sample_conf_files] = copies the sample conf files to /etc/asterisk/\n";
print " [--web-languages] = copy language translations (WARNING! may not work on trunk installs)\n";
@@ -1800,6 +1802,7 @@ else
print " 7 - AST_VDauto_dial_FILL (only for multi-server, this must only be on one server)\n";
print " 8 - ip_relay (used for blind agent monitoring)\n";
print " 9 - Timeclock auto logout\n";
print " E - Email processor, (If multi-server system, this must only be on one server)\n";
print "Enter active keepalives or press enter for default: [$VARactive_keepalives] ";
$PROMPTactive_keepalives = <STDIN>;
chomp($PROMPTactive_keepalives);
@@ -2378,6 +2381,7 @@ print conf "# 6 - FastAGI_log\n";
print conf "# 7 - AST_VDauto_dial_FILL (only for multi-server, this must only be on one server)\n";
print conf "# 8 - ip_relay (used for blind agent monitoring)\n";
print conf "# 9 - Timeclock auto logout\n";
print conf "# E - Email processor, (If multi-server system, this must only be on one server)\n";
print conf "VARactive_keepalives => $VARactive_keepalives\n";
print conf "\n";
print conf "# Asterisk version VICIDIAL is installed for\n";
@@ -81,6 +81,98 @@ Enhanced Disconnect Logging||
This setting enables logging of calls that get a CONGESTION signal with a cause code of 1, 19, 21, 34 or 38. We usually do not recommend enabling this in the USA. Default is 0 for disabled||
LIVE_CALL_INBOUND will allow search for a lead while on an inbound call only. LIVE_CALL_INBOUND_AND_MANUAL will allow search for a lead while on an inbound call or while paused. When Lead Search is used on a live inbound call, the lead of the call when it went to the agent will be changed to a status of LSMERG, and the logs for the call will be modified to link to the agent selected lead instead||
If this is a call that will go to a Call Menu and then back to an in-group, we suggest you use CUSTOMERCLOSER in this field, and also you need to set the In-Group Search Method in the Call Menu to CLOSER||
Add New EMAIL In-Group||
Copy EMAIL In-Group||
New Email Group Addition||
New Copied Email Group Addition||
Modify EMAIL In-Group||
Email In-Groups||
Modify Email Accounts||
This option if set to 1 allows the user to modify email accounts in the email account management page||
Allow Emails||
This is where you can set whether the users of this campaign will be able to receive inbound emails in addition to phone calls||
This is where you can set whether this system will be able to receive inbound emails in addition to phone calls||
VICIDIAL EMAIL ACCOUNTS||
The Vicidial Email Accounts management section allows you to create, copy, and delete email account settings that will allow you to have email messages come into your Vicidial system and be treated as regular calls. EMAIL ACCOUNTS MUST BE SET UP BY YOU AND AN EMAIL SERVICE PROVIDER - THAT IS NOT COVERED BY THIS MODULE||
Email Account ID||
This is the short name of the email account, it is not editable after initial submission, must not contain any spaces and must be between 2 and 20 characters in length||
Email Account Name||
This is the full name of the email account, it must be between 2 and 30 characters in length||
This determines whether this account will be checked for new email messages to be loaded into the dialer||
Email Account Description||
This allows for a lengthy description, if needed, of the email account. 255 characters max||
Email Account Type||
Specifies whether the account is used for inbound or outbound email messages. Should be set to INBOUND||
Admin User Group||
This is the administrative user group for this inbound group, this allows admin viewing of this in-group restricted by user group. Default is --ALL-- which allows any admin user to view this in-group||
Email Account Protocol||
This is the email protocol used by the account you are setting up access to. Currently only IMAP and POP3 accounts are supported||
Email Reply-to Address||
The email address of the account you are setting up access to. Replies to email messages from the agent interface will read as coming from this address||
Email Account Server||
The email server that the account is housed on||
Email Account User||
The login used to access this account. Usually it's the portion of the reply-to address before the -at- symbol||
Email Account Password||
The password used to access this account. This is usually set at the time the email account is created||
Email Frequency Check Rate (mins)||
How often this email account should be checked. The highest rate of frequency at the moment is five minutes; some email providers will not allow more than three login attempts in fifteen minutes before locking the account for an indeterminate amount of time||
In-Group ID||
The In-Group that email messages will be sent to||
Default List ID||
The List ID that leads will be inserted into if necessary||
In-Group Call Handle Method||
This is the action that will be taken when a new email is found in the account. EMAIL means all email messages will be inserted into vicidial_list as a new lead. EMAILLOOKUP will search the entire vicidial_list table for the email address in the email column - if the lead is found, that lead's list ID will be used in the record that goes into the vicidial_email_list table. EMAILLOOKUPRC does the same, but it will only search lists belonging to the campaign selected in the "In-Group Campaign ID" box below. EMAILLOOKUPRL will only search one particular list, which is the one entered into the "In-Group List ID" box below||
In-Group Agent Search Method||
The agent search method to be used by the inbound group, LO is Load-Balanced-Overflow and will try to send the call to an agent on the local server before trying to send it to an agent on another server, LB is Load-Balanced and will try to send the call to the next agent no matter what server they are on, SO is Server-Only and will only try to send the calls to agents on the server that the call came in on. Default is LB.||
In-Group List ID||
This is the List ID that will be used to search for a match within||
In-Group Campaign ID||
This is the Campaign ID that will be used to search for a match within||
Group Handling||
COPY EMAIL GROUP||
Email Group ID||
Email Group Name||
Source Email Group ID||
Email Accounts||
Next Agent Email||
Start Email URL||
Dispo Email URL||
No Agent Email URL||
EMAIL ACCOUNTS USING THIS IN-GROUP||
EMAIL GROUP NOT ADDED||
Email group ID must be between 2 and 20 characters in length and contain no||
Email group name and group color must be at least 2 characters in length||
EMAIL GROUP ADDED||
Show Email Accounts||
Add A New Account||
Copy An Account||
Dialer Email Account fields||
NEW ACCOUNT||
SUCCESSFULLY CREATED||
All Admin User Groups||
ERROR: Inbound emails are not active on this system||
invalid or null||
SUCCESSFULLY MODIFIED||
There was an unknown error when attempting to copy the new account||
SUCCESSFULLY COPIED FROM||
source email does not exist||
ACCOUNT NOT COPIED||
Copy New Account from Existing Account||
Account ID to Copy From||
New Account ID||
New Account Name||
There are no existing accounts to copy from||
The data you submitted has the following errors||
ACCOUNT NOT INSERTED||
ADD NEW INBOUND EMAIL ACCOUNT||
CONFIRM DELETION OF INBOUND EMAIL ACCOUNT||
Click to delete account||
ACCOUNT NOT UPDATED||
UPDATE AN EXISTING INBOUND EMAIL ACCOUNT||
INBOUND EMAIL ACCOUNT LISTINGS||
UNREAD EMAILS||
Un-handled Emails||
############################################################ CLIENT
@@ -103,6 +195,7 @@ View Comment History||
reset form||
SELECT THIS LEAD||
YOU MUST BE ON AN ACTIVE INBOUND CALL TO SEARCH FOR A LEAD||
Attachments||
############################################################ MANAGER Manual
File diff suppressed because it is too large Load Diff
+362
View File
@@ -0,0 +1,362 @@
<?php
# vdc_email_display.php - VICIDIAL administration page
#
# Copyright (C) 2012 Joe Johnson <freewermadmin@gmail.com> LICENSE: AGPLv2
#
# This page displays any incoming emails in the Vicidial user interface. It
# also allows the user to download and view any attachments sent in the email,
# and also gives the user the ability to respond to the email and even
# attach files to it. The page also logs all email messages that are sent
# through it to the vicidial_email_log table
#
# changes:
# 121214-2300 - First Build
#
require("dbconnect.php");
require("functions.php");
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["attachment_id"])) {$attachment_id=$_GET["attachment_id"];}
elseif (isset($_POST["attachment_id"])) {$attachment_id=$_POST["attachment_id"];}
if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];}
if (isset($_GET["email_row_id"])) {$email_row_id=$_GET["email_row_id"];}
elseif (isset($_POST["email_row_id"])) {$email_row_id=$_POST["email_row_id"];}
if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];}
elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];}
if (isset($_GET["user"])) {$user=$_GET["user"];}
elseif (isset($_POST["user"])) {$user=$_POST["user"];}
if (isset($_GET["pass"])) {$pass=$_GET["pass"];}
elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
if (isset($_GET["sender_email"])) {$sender_email=$_GET["sender_email"];}
elseif (isset($_POST["sender_email"])) {$sender_email=$_POST["sender_email"];}
if (isset($_GET["reply_subject"])) {$reply_subject=$_GET["reply_subject"];}
elseif (isset($_POST["reply_subject"])) {$reply_subject=$_POST["reply_subject"];}
if (isset($_GET["reply_to_address"])) {$reply_to_address=$_GET["reply_to_address"];}
elseif (isset($_POST["reply_to_address"])) {$reply_to_address=$_POST["reply_to_address"];}
if (isset($_GET["reply_from_address"])) {$reply_from_address=$_GET["reply_from_address"];}
elseif (isset($_POST["reply_from_address"])) {$reply_from_address=$_POST["reply_from_address"];}
if (isset($_GET["reply_message"])) {$reply_message=$_GET["reply_message"];}
elseif (isset($_POST["reply_message"])) {$reply_message=$_POST["reply_message"];}
if (isset($_GET["REPLY"])) {$REPLY=$_GET["REPLY"];}
elseif (isset($_POST["REPLY"])) {$REPLY=$_POST["REPLY"];}
$attachment1=$_FILES["attachment1"];
$A1_orig = $_FILES['attachment1']['name'];
$A1_path = $_FILES['attachment1']['tmp_name'];
$A1_type = $_FILES['attachment1']['type'];
$attachment2=$_FILES["attachment2"];
$A2_orig = $_FILES['attachment2']['name'];
$A2_path = $_FILES['attachment2']['tmp_name'];
$A2_type = $_FILES['attachment2']['type'];
$attachment3=$_FILES["attachment3"];
$A3_orig = $_FILES['attachment3']['name'];
$A3_path = $_FILES['attachment3']['tmp_name'];
$A3_type = $_FILES['attachment3']['type'];
$attachment4=$_FILES["attachment4"];
$A4_orig = $_FILES['attachment4']['name'];
$A4_path = $_FILES['attachment4']['tmp_name'];
$A4_type = $_FILES['attachment4']['type'];
$attachment5=$_FILES["attachment5"];
$A5_orig = $_FILES['attachment5']['name'];
$A5_path = $_FILES['attachment5']['tmp_name'];
$A5_type = $_FILES['attachment5']['type'];
header ("Content-type: text/html; charset=utf-8");
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
if ($stage=='WELCOME')
{echo "EMAIL"; exit;}
$txt = '.txt';
$StarTtime = date("U");
$NOW_DATE = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$CIDdate = date("mdHis");
$ENTRYdate = date("YmdHis");
$MT[0]='';
$agents='@agents';
$script_height = ($script_height - 20);
if (strlen($bgcolor) < 6) {$bgcolor='FFFFFF';}
$IFRAME=0;
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,timeclock_end_of_day,agentonly_callback_campaign_lock,custom_fields_enabled,allow_emails FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
if ($qm_conf_ct > 0)
{
$row=mysql_fetch_row($rslt);
$non_latin = $row[0];
$timeclock_end_of_day = $row[1];
$agentonly_callback_campaign_lock = $row[2];
$custom_fields_enabled = $row[3];
$allow_emails = $row[4];
}
##### END SETTINGS LOOKUP #####
###########################################
if ($allow_emails<1)
{
echo "Your system does not have the email setting enabled\n";
exit;
}
if ($non_latin < 1)
{
$user=ereg_replace("[^-_0-9a-zA-Z]","",$user);
$pass=ereg_replace("[^-_0-9a-zA-Z]","",$pass);
}
else
{
$user = ereg_replace("'|\"|\\\\|;","",$user);
$pass = ereg_replace("'|\"|\\\\|;","",$pass);
}
# default optional vars if not set
if (!isset($format)) {$format="text";}
if ($format == 'debug') {$DB=1;}
if (!isset($ACTION)) {$ACTION="refresh";}
if (!isset($query_date)) {$query_date = $NOW_DATE;}
$stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and user_level > 0;";
if ($DB) {echo "|$stmt|\n";}
if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$auth=$row[0];
$stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and modify_leads='1';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$VUmodify=$row[0];
$stmt="SELECT count(*) from vicidial_live_agents where user='$user';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$LVAactive=$row[0];
$LVAactive=9;
if ( (strlen($user)<2) or (strlen($pass)<2) or ($auth==0) or ( ($LVAactive < 1) ) )
{
echo "Invalid Username/Password: |$user|$pass|\n";
echo "<form action=./vdc_email_display.php method=POST name=email_display_form id=email_display_form>\n";
echo "<input type=hidden name=user id=user value=\"$user\">\n";
echo "</form>\n";
exit;
}
else
{
# do nothing for now
}
if ($REPLY)
{
$to = "$reply_to_address";
$from = "$reply_from_address";
$subject ="$reply_subject";
$message = "$reply_message";
$headers = "From: $from";
$attachment_str="";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
$message .= "--{$mime_boundary}\n";
for ($i=1; $i<=5; $i++)
{
$attachment_orig_name="A".$i."_orig";
$attachment_path="A".$i."_path";
$LF_orig=$$attachment_orig_name;
$LF_path=$$attachment_path;
#echo "<p>".$$attachment_name."<BR/>".$$attachment_orig_name."<BR/>".$$attachment_path."<BR/><p>";
if ($LF_orig)
{
if (preg_match("/;|:|\/|\^|\[|\]|\"|\'|\*/",$LF_orig))
{
echo "ERROR: Invalid File Name: $LF_orig\n";
exit;
}
else
{
copy($LF_path, "/tmp/$LF_orig");
$file = fopen("/tmp/$LF_orig","rb");
$data = fread($file,filesize("/tmp/$LF_orig"));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$LF_orig\"\n" .
"Content-Disposition: attachment;\n" . " filename=\"$LF_orig\"\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
$attachment_str.="$LF_orig|";
}
}
}
$sendmail = @mail($to, $subject, $message, $headers);
if ($sendmail)
{
$reply_message=preg_replace('/(\"|\||\'|\;)/', '\\\$1', $reply_message);
$log_stmt="insert into vicidial_email_log(email_row_id, lead_id, email_date, user, email_to, message, campaign_id, attachments) VALUES('$email_row_id', '$lead_id', now(), '$user', '$reply_to_address', '$reply_message', '$campaign', '$attachment_str')";
$log_rslt=mysql_query($log_stmt, $link);
echo "<p>mail sent to $to!</p>";
}
else
{
echo "<p>mail could not be sent!</p>";
}
exit;
}
if ($lead_id) {
$stmt="select * from vicidial_email_list where lead_id='$lead_id' and direction='INBOUND' and status IN('NEW','INCALL') order by email_date asc";
$rslt=mysql_query($stmt, $link);
if (mysql_num_rows($rslt)>0) {
$row=mysql_fetch_array($rslt);
$email_row_id=$row["email_row_id"];
preg_match('/\<[^\>\@]+\@[^\>\@]+\>/', $row["email_from"], $matches);
if (strlen($matches[0])>0) {
$email_from = substr($matches[0],1,-1);
} else {
$email_from = $row["email_from"];
}
preg_match('/\<[^\>\@]+\@[^\>\@]+\>/', $row["email_to"], $matches);
if (strlen($matches[0])>0) {
$row["email_from"]=preg_replace('/\>/', '&gt;', $row["email_from"]);
$row["email_from"]=preg_replace('/\</', '&lt;', $row["email_from"]);
$email_to = substr($matches[0],1,-1);
} else {
$row["email_to"]=preg_replace('/\>/', '\>', $row["email_to"]);
$email_to = $row["email_to"];
}
$EMAIL_form="<center><TABLE cellspacing=2 cellpadding=2 bgcolor='#CCCCCC' width='500'>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Date received:</td><td align='left' valign='top' width='*'>$row[email_date]</td></tr>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>From:</td><td align='left' valign='top' width='*'>$row[email_from]</td></tr>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Subject:</td><td align='left' valign='top' width='*'>$row[subject]</td></tr>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Message:</td><td align='left' valign='top' width='*'><pre>$row[message]</pre></td></tr>\n";
$att_stmt="select * from inbound_email_attachments where email_row_id='$email_row_id'";
$att_rslt=mysql_query($att_stmt, $link);
if (mysql_num_rows($att_rslt)>0) {
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Attachments:</td><td align='left' valign='top' width='*'><pre>";
while($att_row=mysql_fetch_array($att_rslt)) {
$EMAIL_form.="<LI><a href='$_SERVER[PHP_SELF]?attachment_id=$att_row[attachment_id]&lead_id=$lead_id'>$att_row[filename]</a>\n";
}
$EMAIL_form.="</pre></td></tr>";
}
$EMAIL_form.="<tr><td colspan='2'><HR></td></tr>";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Response:</td><td align='left' valign='top' width='*'>RE: $row[subject]<input type='hidden' name='reply_subject' value='RE: $row[subject]'></td></tr>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Reply:<BR><BR><input type='button' name='copy' value='COPY MESSAGE >>>' onClick='CopyMessage($row[email_row_id])'></td><td align='left' valign='top' width='*'><textarea rows='8' cols='50' name='reply_message' id='reply_message'>$reply_message</textarea></td></tr>\n";
$EMAIL_form.="<tr bgcolor=white><td align='right' valign='top' width='150'>Attachments:</td><td align='left' valign='top' width='*'>";
$EMAIL_form.="<span id='attachment_span1'><input type=file name='attachment1' value='$attachment1'></span><BR/>";
$EMAIL_form.="<span id='attachment_span2'><input type=file name='attachment2'></span><BR/>";
$EMAIL_form.="<span id='attachment_span3'><input type=file name='attachment3'></span><BR/>";
$EMAIL_form.="<span id='attachment_span4'><input type=file name='attachment4'></span><BR/>";
$EMAIL_form.="<span id='attachment_span5'><input type=file name='attachment5'></span>";
$EMAIL_form.="</td></tr>\n";
$EMAIL_form.="<tr><td colspan='2' align='center'><input type='submit' name='REPLY' value='REPLY'></td></tr>";
$EMAIL_form.="</table></center>\n";
$EMAIL_form.="<input type='hidden' name='reply_to_address' value='$email_from'>\n";
$EMAIL_form.="<input type='hidden' name='reply_from_address' value='$email_to'>\n";
$EMAIL_form.="<input type='hidden' name='campaign' value='$campaign'>\n";
$EMAIL_form.="<input type='hidden' name='lead_id' value='$lead_id'>\n";
$EMAIL_form.="<input type='hidden' name='email_row_id' value='$email_row_id'>\n";
$EMAIL_form.="<input type='hidden' name='user' value='$user'>\n";
$EMAIL_form.="<input type='hidden' name='pass' value='$pass'>\n";
}
if ($attachment_id) {
$stmt="select * from inbound_email_attachments where attachment_id='$attachment_id'";
$rslt=mysql_query($stmt, $link);
if (mysql_num_rows($rslt)>0) {
$row=mysql_fetch_array($rslt);
$filename=$row["filename"];
$encoding=$row["file_encoding"];
$file_size=$row["file_size"];
$file_type=$row["file_type"];
$file_contents=$row["file_contents"];
if ($encoding=="base64") {
$file_contents=base64_decode($file_contents);
$file_size=strlen($file_contents);
}
header("Content-length: ".$file_size."");
header("Content-type: ".$file_type."");
header('Content-Disposition: attachment; filename="'.$filename.'"');
echo $file_contents;
}
} else {
?>
<html>
<head>
<title>VICIDIAL email frame</title>
</head>
<script language="Javascript">
function ParseFileName()
{
for (var i=1; i<=5; i++)
{
var attachment_field=eval("document.forms[0].attachment"+i);
var endstr=attachment_field.value.lastIndexOf('\\');
if (endstr>-1)
{
endstr++;
var filename=attachment_field.value.substring(endstr);
attachment_field.value=filename;
}
}
}
function CopyMessage()
{
<?php echo "var message=\"".preg_replace('/\"/', '\\\"', $row["message"])."\";\n"; ?>
var msg_array=message.split(" ");
var full_msg="";
var msg_line="> ";
for (var i=0; i<msg_array.length; i++)
{
if (msg_array[i].length>=48)
{
msg_line+=msg_array[i]+" ";
}
if (msg_line.length+msg_array[i].length<50)
{
msg_line+=msg_array[i]+" ";
}
else
{
full_msg+=msg_line+"\n";
msg_line="> ";
}
}
var email_field_value=document.getElementById("reply_message").value+"\n";
email_field_value+=full_msg;
document.getElementById("reply_message").value=email_field_value;
}
</script>
<style type="text/css">
pre { white-space: pre-wrap; }
</style>
<body>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='get' name="email_display_form" id="email_display_form" onSubmit="if (this.submitted) return false; this.submitted=true" enctype="multipart/form-data">
<?php echo $EMAIL_form; ?>
</form>
</body>
</html>
<?php
}
} else {
echo "ERROR - ID variable missing";
}
?>
File diff suppressed because it is too large Load Diff
@@ -77,10 +77,11 @@
# 111103-1220 - Added admin_hide_phone_data and admin_hide_lead_data options
# 120223-1934 - Added user group options
# 120612-2150 - Added percentages to counts for carrier stats and TOTAL line to carrier display stats as well
# 121222-2151 - Added email status
#
$version = '2.4-67';
$build = '120223-1934';
$version = '2.6-68';
$build = '121222-2151';
header ("Content-type: text/html; charset=utf-8");
@@ -2600,7 +2601,7 @@ $talking_to_print = mysql_num_rows($rslt);
}
else
{
if (!ereg("$Acallerid[$i]\|",$callerids))
if (!ereg("$Acallerid[$i]\|",$callerids) && !eregi("EMAIL",$comments))
{
$Acall_time[$i]=$Astate_change[$i];
@@ -2616,6 +2617,8 @@ $talking_to_print = mysql_num_rows($rslt);
{
if (eregi("INBOUND",$comments))
{$CM='I';}
else if (eregi("EMAIL",$comments))
{$CM='E';}
else
{$CM='M';}
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,864 @@
<?php
# admin_email_accounts.php
#
# Copyright (C) 2012 Joe Johnson <freewermadmin@gmail.com> LICENSE: AGPLv2
#
# This page manages the inbound email accounts in ViciDial
#
# changes:
# 121214-2245 - First Build
#
$admin_version = '2.6-1';
$build = '121214-2245';
$sh="emails";
require("dbconnect.php");
$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_SELF=$_SERVER['PHP_SELF'];
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["action"])) {$action=$_GET["action"];}
elseif (isset($_POST["action"])) {$action=$_POST["action"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (isset($_GET["eact"])) {$eact=$_GET["eact"];}
elseif (isset($_POST["eact"])) {$eact=$_POST["eact"];}
if (isset($_GET["email_account_id"])) {$email_account_id=$_GET["email_account_id"];}
elseif (isset($_POST["email_account_id"])) {$email_account_id=$_POST["email_account_id"];}
if (isset($_GET["email_account_name"])) {$email_account_name=$_GET["email_account_name"];}
elseif (isset($_POST["email_account_name"])) {$email_account_name=$_POST["email_account_name"];}
if (isset($_GET["email_account_description"])) {$email_account_description=$_GET["email_account_description"];}
elseif (isset($_POST["email_account_description"])) {$email_account_description=$_POST["email_account_description"];}
if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];}
elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];}
if (isset($_GET["protocol"])) {$protocol=$_GET["protocol"];}
elseif (isset($_POST["protocol"])) {$protocol=$_POST["protocol"];}
if (isset($_GET["email_account_server"])) {$email_account_server=$_GET["email_account_server"];}
elseif (isset($_POST["email_account_server"])) {$email_account_server=$_POST["email_account_server"];}
if (isset($_GET["email_account_user"])) {$email_account_user=$_GET["email_account_user"];}
elseif (isset($_POST["email_account_user"])) {$email_account_user=$_POST["email_account_user"];}
if (isset($_GET["email_account_pass"])) {$email_account_pass=$_GET["email_account_pass"];}
elseif (isset($_POST["email_account_pass"])) {$email_account_pass=$_POST["email_account_pass"];}
if (isset($_GET["active"])) {$active=$_GET["active"];}
elseif (isset($_POST["active"])) {$active=$_POST["active"];}
if (isset($_GET["email_frequency_check_mins"])) {$email_frequency_check_mins=$_GET["email_frequency_check_mins"];}
elseif (isset($_POST["email_frequency_check_mins"])) {$email_frequency_check_mins=$_POST["email_frequency_check_mins"];}
if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
if (isset($_GET["default_list_id"])) {$default_list_id=$_GET["default_list_id"];}
elseif (isset($_POST["default_list_id"])) {$default_list_id=$_POST["default_list_id"];}
if (isset($_GET["group_id"])) {$group_id=$_GET["group_id"];}
elseif (isset($_POST["group_id"])) {$group_id=$_POST["group_id"];}
if (isset($_GET["campaign_id"])) {$campaign_id=$_GET["campaign_id"];}
elseif (isset($_POST["campaign_id"])) {$campaign_id=$_POST["campaign_id"];}
if (isset($_GET["new_account_id"])) {$new_account_id=$_GET["new_account_id"];}
elseif (isset($_POST["new_account_id"])) {$new_account_id=$_POST["new_account_id"];}
if (isset($_GET["source_email_account"])) {$source_email_account=$_GET["source_email_account"];}
elseif (isset($_POST["source_email_account"])) {$source_email_account=$_POST["source_email_account"];}
if (isset($_GET["confirm_deletion"])) {$confirm_deletion=$_GET["confirm_deletion"];}
elseif (isset($_POST["confirm_deletion"])) {$confirm_deletion=$_POST["confirm_deletion"];}
if (isset($_GET["email_replyto_address"])) {$email_replyto_address=$_GET["email_replyto_address"];}
elseif (isset($_POST["email_replyto_address"])) {$email_replyto_address=$_POST["email_replyto_address"];}
if (isset($_GET["email_replyto_address"])) {$email_replyto_address=$_GET["email_replyto_address"];}
elseif (isset($_POST["email_replyto_address"])) {$email_replyto_address=$_POST["email_replyto_address"];}
if (isset($_GET["email_account_type"])) {$email_account_type=$_GET["email_account_type"];}
elseif (isset($_POST["email_account_type"])) {$email_account_type=$_POST["email_account_type"];}
if (isset($_GET["call_handle_method"])) {$call_handle_method=$_GET["call_handle_method"];}
elseif (isset($_POST["call_handle_method"])) {$call_handle_method=$_POST["call_handle_method"];}
if (isset($_GET["agent_search_method"])) {$agent_search_method=$_GET["agent_search_method"];}
elseif (isset($_POST["agent_search_method"])) {$agent_search_method=$_POST["agent_search_method"];}
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,enable_queuemetrics_logging,enable_vtiger_integration,qc_features_active,outbound_autodial_active,sounds_central_control_active,enable_second_webform,user_territories_active,custom_fields_enabled,admin_web_directory,webphone_url,first_login_trigger,hosted_settings,default_phone_registration_password,default_phone_login_password,default_server_password,test_campaign_calls,active_voicemail_server,voicemail_timezones,default_voicemail_timezone,default_local_gmt,campaign_cid_areacodes_enabled,pllb_grouping_limit,did_ra_extensions_enabled,expanded_list_stats,contacts_enabled,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,allow_emails,email_enabled FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
if ($qm_conf_ct > 0)
{
$row=mysql_fetch_row($rslt);
$non_latin = $row[0];
$SSenable_queuemetrics_logging = $row[1];
$SSenable_vtiger_integration = $row[2];
$SSqc_features_active = $row[3];
$SSoutbound_autodial_active = $row[4];
$SSsounds_central_control_active = $row[5];
$SSenable_second_webform = $row[6];
$SSuser_territories_active = $row[7];
$SScustom_fields_enabled = $row[8];
$SSadmin_web_directory = $row[9];
$SSwebphone_url = $row[10];
$SSfirst_login_trigger = $row[11];
$SShosted_settings = $row[12];
$SSdefault_phone_registration_password =$row[13];
$SSdefault_phone_login_password = $row[14];
$SSdefault_server_password = $row[15];
$SStest_campaign_calls = $row[16];
$SSactive_voicemail_server = $row[17];
$SSvoicemail_timezones = $row[18];
$SSdefault_voicemail_timezone = $row[19];
$SSdefault_local_gmt = $row[20];
$SScampaign_cid_areacodes_enabled = $row[21];
$SSpllb_grouping_limit = $row[22];
$SSdid_ra_extensions_enabled = $row[23];
$SSexpanded_list_stats = $row[24];
$SScontacts_enabled = $row[25];
$SSalt_log_server_ip = $row[26];
$SSalt_log_dbname = $row[27];
$SSalt_log_login = $row[28];
$SSalt_log_pass = $row[29];
$SStables_use_alt_log_db = $row[30];
$SSallow_emails = $row[31];
$SSemail_enabled = $row[32];
}
##### END SETTINGS LOOKUP #####
###########################################
if ($non_latin < 1)
{
$PHP_AUTH_USER = ereg_replace("[^-_0-9a-zA-Z]","",$PHP_AUTH_USER);
$PHP_AUTH_PW = ereg_replace("[^-_0-9a-zA-Z]","",$PHP_AUTH_PW);
$email_account_id = ereg_replace("[^_0-9a-zA-Z]","",$email_account_id);
$email_account_name = ereg_replace("[^ \.\,-\_0-9a-zA-Z]","",$email_account_name);
$email_account_description = ereg_replace("[^ \.\,-\_0-9a-zA-Z]","",$email_account_description);
$user_group = ereg_replace("[^_0-9a-zA-Z]","",$user_group);
$protocol = preg_replace("/^(IMAP|POP3|SMTP)/","",$protocol);
$email_account_server = ereg_replace("[^\.\-\_0-9a-zA-Z]","",$email_account_server);
$active = preg_replace("/^(Y|N)/","",$active);
$email_frequency_check_mins = preg_replace("/^0-9/","",$email_frequency_check_mins);
$list_id = ereg_replace("[^0-9]","",$list_id);
} # end of non_latin
else
{
$PHP_AUTH_USER = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_USER);
$PHP_AUTH_PW = ereg_replace("'|\"|\\\\|;","",$PHP_AUTH_PW);
}
$STARTtime = date("U");
$TODAY = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7 and modify_email_accounts='1';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$auth=$row[0];
if ($webroot_writable > 0)
{$fp = fopen ("./project_auth_entries.txt", "a");}
$date = date("r");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$user = $PHP_AUTH_USER;
if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth))
{
Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\"");
Header("HTTP/1.0 401 Unauthorized");
echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n";
exit;
}
else
{
if ($auth>0)
{
$office_no=strtoupper($PHP_AUTH_USER);
$password=strtoupper($PHP_AUTH_PW);
$stmt="SELECT full_name,user_level,user_group,modify_email_accounts from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$LOGfullname = $row[0];
$LOGuser_level = $row[1];
$LOGuser_group = $row[2];
$LOGemails_modify = $row[3];
$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$LOGallowed_campaigns = $row[0];
$LOGallowed_reports = $row[1];
$LOGadmin_viewable_groups = $row[2];
$LOGadmin_viewable_call_times = $row[3];
$admin_viewable_groupsALL=0;
$LOGadmin_viewable_groupsSQL='';
$whereLOGadmin_viewable_groupsSQL='';
$valLOGadmin_viewable_groupsSQL='';
$vmLOGadmin_viewable_groupsSQL='';
if ( (!eregi("--ALL--",$LOGadmin_viewable_groups)) and (strlen($LOGadmin_viewable_groups) > 3) )
{
$rawLOGadmin_viewable_groupsSQL = preg_replace("/ -/",'',$LOGadmin_viewable_groups);
$rawLOGadmin_viewable_groupsSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_groupsSQL);
$LOGadmin_viewable_groupsSQL = "and user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')";
$whereLOGadmin_viewable_groupsSQL = "where user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')";
$valLOGadmin_viewable_groupsSQL = "and val.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')";
$vmLOGadmin_viewable_groupsSQL = "and vm.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')";
}
else
{$admin_viewable_groupsALL=1;}
$regexLOGadmin_viewable_groups = " $LOGadmin_viewable_groups ";
$UUgroups_list='';
if ($admin_viewable_groupsALL > 0)
{$UUgroups_list .= "<option value=\"---ALL---\">All Admin User Groups</option>\n";}
$stmt="SELECT user_group,group_name from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;";
$rslt=mysql_query($stmt, $link);
$UUgroups_to_print = mysql_num_rows($rslt);
$o=0;
while ($UUgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$UUgroups_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
$stmt="SELECT group_id,group_name from vicidial_inbound_groups where group_handling='EMAIL' $LOGadmin_viewable_groupsSQL order by group_id;";
# $stmt="SELECT group_id,group_name from vicidial_inbound_groups where group_id NOT IN('AGENTDIRECT') order by group_id";
$rslt=mysql_query($stmt, $link);
$Dgroups_to_print = mysql_num_rows($rslt);
$Dgroups_menu='';
$Dgroups_selected=0;
$o=0;
while ($Dgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$Dgroups_menu .= "<option ";
if ($drop_inbound_group == "$rowx[0]")
{
$Dgroups_menu .= "SELECTED ";
$Dgroups_selected++;
}
$Dgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
if ($Dgroups_selected < 1)
{$Dgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$Dgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
if ($webroot_writable > 0)
{
fwrite ($fp, "VICIDIAL|GOOD|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|$LOGfullname|\n");
fclose($fp);
}
}
else
{
if ($webroot_writable > 0)
{
fwrite ($fp, "VICIDIAL|FAIL|$date|$PHP_AUTH_USER|XXXX|$ip|$browser|\n");
fclose($fp);
}
}
}
?>
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<title>ADMINISTRATION: Dialer Email Account fields
<?php
##### BEGIN Set variables to make header show properly #####
$ADD = '0';
$hh = 'admin';
$sh = 'emails';
$LOGast_admin_access = '1';
$ADMIN = 'admin.php';
$page_width='770';
$section_width='750';
$header_font_size='3';
$subheader_font_size='2';
$subcamp_font_size='2';
$header_selected_bold='<b>';
$header_nonselected_bold='';
$admin_color = '#FFFF99';
$admin_font = 'BLACK';
$admin_color = '#E6E6E6';
$emails_color = '#FFFF99';
$emails_font = 'BLACK';
$emails_color = '#C6C6C6';
$subcamp_color = '#C6C6C6';
##### END Set variables to make header show properly #####
require("admin_header.php");
if ( ($LOGemails_modify < 1) or ($LOGuser_level < 8) )
{
echo "You are not authorized to view this section\n";
exit;
}
if ($SSemail_enabled < 1)
{
echo "ERROR: Inbound emails are not active on this system\n";
exit;
}
$NWB = " &nbsp; <a href=\"javascript:openNewWindow('admin.php?ADD=99999";
$NWE = "')\"><IMG SRC=\"help.gif\" WIDTH=20 HEIGHT=20 BORDER=0 ALT=\"HELP\" ALIGN=TOP></A>";
if ($DB > 0)
{
echo "$DB,$action,$ip,$user,$copy_option,$field_id,$list_id,$source_email_account,$field_label,$field_name,$field_description,$field_rank,$field_help,$field_type,$field_options,$field_size,$field_max,$field_default,$field_required,$field_cost,$multi_position,$name_position,$field_order";
}
if ($eact=="DELETE" && $confirm_deletion=="yes" && $email_account_id)
{
$del_stmt="delete from vicidial_email_accounts where email_account_id='$email_account_id'";
$del_rslt=mysql_query($del_stmt, $link);
$message="ACCOUNT $email_account_id DELETED<BR/>";
$eact="";
}
if (($SUBMIT=="SUBMIT" || $SUBMIT=="UPDATE") && $email_account_id)
{
$error_msg="";
if (!$list_id) {$error_msg.="- Default list ID is invalid or null<BR/>";}
if (!$email_account_id) {$error_msg.="- Email account ID is invalid or null<BR/>";}
if (!$email_account_name) {$error_msg.="- Email account name is invalid or null<BR/>";}
if (!$email_account_server) {$error_msg.="- Email account server is invalid or null<BR/>";}
if (!$email_account_user) {$error_msg.="- Email account user is invalid or null<BR/>";}
if (!$email_account_pass) {$error_msg.="- Email account password is invalid or null<BR/>";}
if (!filter_var($email_replyto_address, FILTER_VALIDATE_EMAIL)) {$error_msg.="- Email reply-to address is invalid or null<BR/>";}
if (!$error_msg)
{
if ($SUBMIT=="SUBMIT")
{
$ins_stmt="INSERT INTO vicidial_email_accounts(email_account_id, email_account_name, email_account_description, user_group, email_replyto_address, protocol, email_account_server, email_account_user, email_account_pass, active, email_frequency_check_mins, group_id, default_list_id, email_account_type, call_handle_method, agent_search_method, list_id, campaign_id) VALUES('$email_account_id', '$email_account_name', '$email_account_description', '$user_group', '$email_replyto_address', '$protocol', '$email_account_server', '$email_account_user', '$email_account_pass', '$active', '$email_frequency_check_mins', '$group_id', '$default_list_id', '$email_account_type', '$call_handle_method', '$agent_search_method', '$list_id', '$campaign_id')";
$ins_rslt=mysql_query($ins_stmt, $link);
if (mysql_affected_rows($link)==0)
{
$error_msg.="- There was an unknown error when attempting to create the new account<BR/>";
if($DB>0) {$error_msg.="<B>$ins_stmt</B><BR>";}
}
else
{
$message="NEW ACCOUNT $email_account_id SUCCESSFULLY CREATED";
$eact="";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$ins_stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='EMAIL', event_type='ADD', record_id='$user', event_code='NEW EMAIL ACCOUNT ADDED', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
else
{
$upd_stmt="update vicidial_email_accounts set email_account_name='$email_account_name', email_account_description='$email_account_description', user_group='$user_group', protocol='$protocol', email_replyto_address='$email_replyto_address', email_account_server='$email_account_server', email_account_user='$email_account_user', email_account_pass='$email_account_pass', active='$active', email_frequency_check_mins='$email_frequency_check_mins', group_id='$group_id', default_list_id='$default_list_id', email_account_type='$email_account_type', call_handle_method='$call_handle_method', agent_search_method='$agent_search_method', campaign_id='$campaign_id', list_id='$list_id' WHERE email_account_id='$email_account_id'";
$upd_rslt=mysql_query($upd_stmt, $link);
if (mysql_affected_rows($link)==0)
{
$error_msg.="- There was an unknown error when attempting to update account $email_account_id<BR/>";
if($DB>0) {$error_msg.="<B>$upd_stmt</B><BR>";}
}
else
{
$message="ACCOUNT $email_account_id SUCCESSFULLY MODIFIED";
# $eact="";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$upd_stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='EMAIL', event_type='MODIFY', record_id='$user', event_code='EMAIL ACCOUNT MODIFIED', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
}
}
else if ($SUBMIT=="COPY")
{
$stmt="select * from vicidial_email_accounts where email_account_id='$source_email_account'";
$rslt=mysql_query($stmt, $link);
if (mysql_num_rows($rslt)>0)
{
$row=mysql_fetch_array($rslt);
$ins_stmt="insert into vicidial_email_accounts(email_account_id, email_account_name, email_account_description, user_group, protocol, email_replyto_address, email_account_server, email_account_user, email_account_pass, active, email_frequency_check_mins, group_id, default_list_id, email_account_type, call_handle_method, agent_search_method, list_id, campaign_id) VALUES('$new_account_id', '$email_account_name', '$row[email_account_description]', '$row[user_group]', '$row[protocol]', '$row[email_replyto_address]', '$row[email_account_server]', '$row[email_account_user]', '$row[email_account_pass]', '$row[active]', '$row[email_frequency_check_mins]', '$row[group_id]','$row[default_list_id]', '$row[email_account_type]', '$row[call_handle_method]','$row[agent_search_method]', '$row[list_id]', '$row[campaign_id]')";
$ins_rslt=mysql_query($ins_stmt, $link);
if (mysql_affected_rows($link)==0)
{
$error_msg.="- There was an unknown error when attempting to copy the new account<BR/>";
if($DB>0) {$error_msg.="<B>$ins_stmt</B><BR>";}
}
else
{
$message="NEW ACCOUNT $new_account_id SUCCESSFULLY COPIED FROM $source_email_account<BR/>";
$eact="";
### LOG INSERTION Admin Log Table ###
$SQL_log = "$ins_stmt|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date=now(), user='$PHP_AUTH_USER', ip_address='$ip', event_section='EMAIL', event_type='ADD', record_id='$user', event_code='NEW EMAIL ACCOUNT ADDED', event_sql=\"$SQL_log\", event_notes='';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
}
}
else
{
$error_msg="- Error - source email does not exist<BR/>";
if($DB>0) {$error_msg.="<B>$stmt</B><BR>";}
}
}
################################################################################
##### BEGIN copy fields to a list form
if ($eact == "COPY")
{
##### get lists listing for dynamic pulldown
$stmt="SELECT email_account_id, email_account_name from vicidial_email_accounts order by email_account_id";
$rsltx=mysql_query($stmt, $link);
$accounts_to_print = mysql_num_rows($rsltx);
$accounts_list='';
$o=0;
if ($accounts_to_print>0)
{
while ($accounts_to_print > $o)
{
$rowx=mysql_fetch_row($rsltx);
$accounts_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
if ($error_msg) {echo "ACCOUNT NOT COPIED<BR/>The data you submitted has the following errors:<BR/>$error_msg";}
echo "<br>Copy New Account from Existing Account<form action='$PHP_SELF' method='GET'>\n";
echo "<input type=hidden name=DB value=\"$DB\">\n";
echo "<input type=hidden name=action value=COPY_EMAIL_SUBMIT>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Account ID to Copy From: </td><td align=left><select size=1 name=source_email_account>\n";
echo "$accounts_list";
echo "</select></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>New Account ID: </td><td align=left><input type=text name=new_account_id value='$new_account_id' size=10 maxlength=20></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>New Account Name: </td><td align=left><input type=text name=email_account_name size=40 maxlength=100>$NWB#vicidial_email_accounts-carrier_name$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT value='COPY'></td></tr>\n";
echo "</TABLE></center>\n";
echo "</TD></TR></TABLE>\n";
}
else
{
echo "<TABLE><TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br><br>*** There are no existing accounts to copy from ***\n";
echo "</TD></TR></TABLE>\n";
}
}
### END copy fields to a list form
else if ($eact == "ADD")
{
if ( ($LOGemails_modify==1) )
{
$stmt="SELECT campaign_id,campaign_name from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;";
$rslt=mysql_query($stmt, $link);
$campaigns_to_print = mysql_num_rows($rslt);
$campaigns_list='';
$o=0;
while ($campaigns_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$campaigns_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
##### get in-groups listings for dynamic pulldown
$stmt="SELECT group_id,group_name from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;";
$rslt=mysql_query($stmt, $link);
$Xgroups_to_print = mysql_num_rows($rslt);
$Xgroups_menu='';
$Xgroups_selected=0;
$FXgroups_menu='';
$FXgroups_selected=0;
$o=0;
while ($Xgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$Xgroups_menu .= "<option ";
$FXgroups_menu .= "<option ";
if ($user_route_settings_ingroup == "$rowx[0]")
{
$Xgroups_menu .= "SELECTED ";
$Xgroups_selected++;
}
if ($filter_user_route_settings_ingroup == "$rowx[0]")
{
$FXgroups_menu .= "SELECTED ";
$FXgroups_selected++;
}
$Xgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$FXgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
if ($Xgroups_selected < 1)
{$Xgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$Xgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
if ($FXgroups_selected < 1)
{$FXgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$FXgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
##### get in-groups listings for dynamic pulldown
$stmt="SELECT group_id,group_name from vicidial_inbound_groups where group_id NOT IN('AGENTDIRECT') $LOGadmin_viewable_groupsSQL order by group_id;";
$rslt=mysql_query($stmt, $link);
$Dgroups_to_print = mysql_num_rows($rslt);
$Dgroups_menu='';
$Dgroups_selected=0;
$FDgroups_menu='';
$FDgroups_selected=0;
$o=0;
while ($Dgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$Dgroups_menu .= "<option ";
$FDgroups_menu .= "<option ";
if ($group_id == "$rowx[0]")
{
$Dgroups_menu .= "SELECTED ";
$Dgroups_selected++;
}
if ($filter_group_id == "$rowx[0]")
{
$FDgroups_menu .= "SELECTED ";
$FDgroups_selected++;
}
$Dgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$FDgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
if ($Dgroups_selected < 1)
{$Dgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$Dgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
if ($FDgroups_selected < 1)
{$FDgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$FDgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
echo "<TABLE>\n";
echo "<TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
if ($error_msg) {echo "ACCOUNT NOT INSERTED<BR/>The data you submitted has the following errors:<BR/>$error_msg";}
echo "<br>ADD NEW INBOUND EMAIL ACCOUNT<form action='$PHP_SELF' method='GET'>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account ID: </td><td align=left><input type=text name=email_account_id size=15 maxlength=20 value='$email_account_id'>$NWB#vicidial_email_accounts-email_account_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Name: </td><td align=left><input type=text name=email_account_name size=40 maxlength=100 value='$email_account_name'>$NWB#vicidial_email_accounts-email_account_name$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Active: </td><td align=left><select size=1 name=active><option>Y</option><option SELECTED>N</option></select>$NWB#vicidial_email_accounts-email_account_active$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Description: </td><td align=left><input type=text name=email_account_description size=70 maxlength=255 value='$email_account_description'>$NWB#vicidial_email_accounts-email_account_description$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Type: </td><td align=left><select size=1 name=email_account_type><option>INBOUND</option></select>$NWB#vicidial_email_accounts-email_account_type$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Admin User Group: </td><td align=left><select size=1 name=user_group>\n";
echo "$UUgroups_list";
echo "<option SELECTED value=\"---ALL---\">All Admin User Groups</option>\n";
echo "</select>$NWB#vicidial_email_accounts-admin_user_group$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Protocol: </td><td align=left><select size=1 name=protocol><option SELECTED>IMAP</option><option>POP3</option></select>$NWB#vicidial_email_accounts-protocol$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Reply-to Address: </td><td align=left><input type=text name=email_replyto_address size=70 maxlength=255 value='$email_replyto_address'>$NWB#vicidial_email_accounts-email_replyto_address$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Server: </td><td align=left><input type=text name=email_account_server size=70 maxlength=255 value='$email_account_server'>$NWB#vicidial_email_accounts-email_account_server$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account User: </td><td align=left><input type=text name=email_account_user size=30 maxlength=255 value='$email_account_user'>$NWB#vicidial_email_accounts-email_account_user$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Password: </td><td align=left><input type=text name=email_account_pass size=30 maxlength=100 value='$email_account_pass'>$NWB#vicidial_email_accounts-email_account_pass$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Frequency Check Rate (mins): </td><td align=left><select name='email_frequency_check_mins'>";
$i=5;
while ($i<=60)
{
echo "<option value='$i'>$i</option>";
$i+=5;
}
echo "</select>$NWB#vicidial_email_accounts-email_frequency_check_mins$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right><a href=\"admin.php?ADD=1000\">In-Group ID</a>: </td><td align=left><select size=1 name=group_id>";
echo "$Dgroups_menu";
echo "</select>$NWB#vicidial_email_accounts-in_group$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right><a href=\"admin.php?ADD=1000\">Default List ID</a>: </td><td align=left><input type=text name=default_list_id size=20 maxlength=255 value='$default_list_id'>$NWB#vicidial_email_accounts-default_list_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Call Handle Method: </td><td align=left><select size=1 name=call_handle_method><option>CID</option><option>CIDLOOKUP</option><option>CIDLOOKUPRL</option><option>CIDLOOKUPRC</option><option SELECTED>$call_handle_method</option></select>$NWB#vicidial_email_accounts-call_handle_method$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Agent Search Method: </td><td align=left><select size=1 name=agent_search_method><option value=\"LB\">LB - Load Balanced</option><option value=\"LO\">LO - Load Balanced Overflow</option><option value=\"SO\">SO - Server Only</option><option SELECTED>$agent_search_method</option></select>$NWB#vicidial_email_accounts-agent_search_method$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group List ID: </td><td align=left><input type=text name=list_id size=14 maxlength=14 value=\"$list_id\">$NWB#vicidial_email_accounts-ingroup_list_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Campaign ID: </td><td align=left><select size=1 name=campaign_id>\n";
echo "$campaigns_list";
echo "<option SELECTED>$campaign_id</option>\n";
echo "</select>$NWB#vicidial_email_accounts-ingroup_campaign_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT VALUE=SUBMIT><input type=hidden name='eact' value='ADD'></td></tr>\n";
echo "</TABLE></center></form>\n";
}
else
{
echo "You do not have permission to view this page\n";
exit;
}
}
else if (($eact=="DELETE" || $eact=="UPDATE") && $email_account_id)
{
if ( ($LOGemails_modify==1) )
{
$stmt="SELECT * from vicidial_email_accounts where email_account_id='$email_account_id'";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_array($rslt);
$email_account_id=$row["email_account_id"];
$email_account_name=$row["email_account_name"];
$email_account_description=$row["email_account_description"];
$user_group=$row["user_group"];
$protocol=$row["protocol"];
$email_replyto_address=$row["email_replyto_address"];
$email_account_server=$row["email_account_server"];
$email_account_user=$row["email_account_user"];
$email_account_pass=$row["email_account_pass"];
$active=$row["active"];
$email_frequency_check_mins=$row["email_frequency_check_mins"];
$group_id=$row["group_id"];
$call_handle_method=$row["call_handle_method"];
$agent_search_method=$row["agent_search_method"];
$campaign_id=$row["campaign_id"];
$list_id=$row["list_id"];
$default_list_id=$row["default_list_id"];
$email_account_type=$row["email_account_type"];
if ($eact=="DELETE" && $email_account_id)
{
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
echo "<br><B>CONFIRM DELETION OF INBOUND EMAIL ACCOUNT $email_account_id</B><BR>\n";
echo "<a href='$PHP_SELF?eact=DELETE&email_account_id=$email_account_id&confirm_deletion=yes'>Click to delete account $email_account_id</a>\n";
echo "</font>";
}
$stmt="SELECT campaign_id,campaign_name from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;";
$rslt=mysql_query($stmt, $link);
$campaigns_to_print = mysql_num_rows($rslt);
$campaigns_list='';
$o=0;
while ($campaigns_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$campaigns_list .= "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
##### get in-groups listings for dynamic pulldown
$stmt="SELECT group_id,group_name from vicidial_inbound_groups $whereLOGadmin_viewable_groupsSQL order by group_id;";
$rslt=mysql_query($stmt, $link);
$Xgroups_to_print = mysql_num_rows($rslt);
$Xgroups_menu='';
$Xgroups_selected=0;
$FXgroups_menu='';
$FXgroups_selected=0;
$o=0;
while ($Xgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$Xgroups_menu .= "<option ";
$FXgroups_menu .= "<option ";
if ($user_route_settings_ingroup == "$rowx[0]")
{
$Xgroups_menu .= "SELECTED ";
$Xgroups_selected++;
}
if ($filter_user_route_settings_ingroup == "$rowx[0]")
{
$FXgroups_menu .= "SELECTED ";
$FXgroups_selected++;
}
$Xgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$FXgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
if ($Xgroups_selected < 1)
{$Xgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$Xgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
if ($FXgroups_selected < 1)
{$FXgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$FXgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
##### get in-groups listings for dynamic pulldown
$stmt="SELECT group_id,group_name from vicidial_inbound_groups where group_id NOT IN('AGENTDIRECT') $LOGadmin_viewable_groupsSQL order by group_id;";
$rslt=mysql_query($stmt, $link);
$Dgroups_to_print = mysql_num_rows($rslt);
$Dgroups_menu='';
$Dgroups_selected=0;
$FDgroups_menu='';
$FDgroups_selected=0;
$o=0;
while ($Dgroups_to_print > $o)
{
$rowx=mysql_fetch_row($rslt);
$Dgroups_menu .= "<option ";
$FDgroups_menu .= "<option ";
if ($group_id == "$rowx[0]")
{
$Dgroups_menu .= "SELECTED ";
$Dgroups_selected++;
}
if ($filter_group_id == "$rowx[0]")
{
$FDgroups_menu .= "SELECTED ";
$FDgroups_selected++;
}
$Dgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$FDgroups_menu .= "value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
$o++;
}
if ($Dgroups_selected < 1)
{$Dgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$Dgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
if ($FDgroups_selected < 1)
{$FDgroups_menu .= "<option SELECTED value=\"---NONE---\">---NONE---</option>\n";}
else
{$FDgroups_menu .= "<option value=\"---NONE---\">---NONE---</option>\n";}
## Get unhandled count
$stmt="select count(*) From vicidial_email_list where status='NEW' and email_account_id='$email_account_id'";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$unhandled_emails=$row[0];
echo "<TABLE>\n";
echo "<TR><TD>\n";
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
if ($message) {echo "<B>$message</B><BR>";}
if ($error_msg) {echo "ACCOUNT NOT UPDATED<BR/>The data you submitted has the following errors:<BR/>$error_msg";}
echo "<br>UPDATE AN EXISTING INBOUND EMAIL ACCOUNT<form action='$PHP_SELF' method='GET'>\n";
echo "<center><TABLE width=$section_width cellspacing=3>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account ID: </td><td align=left><input type=hidden name=email_account_id value='$email_account_id'><B>$email_account_id$NWB#vicidial_email_accounts-email_account_id$NWE</B></td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Name: </td><td align=left><input type=text name=email_account_name size=40 maxlength=100 value='$email_account_name'>$NWB#vicidial_email_accounts-email_account_name$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Active: </td><td align=left><select size=1 name=active>";
echo "<option value='$active' selected>$active</option>";
echo "<option>Y</option><option>N</option></select>$NWB#vicidial_email_accounts-email_account_active$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Description: </td><td align=left><input type=text name=email_account_description size=70 maxlength=255 value='$email_account_description'>$NWB#vicidial_email_accounts-email_account_description$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Type: </td><td align=left><select size=1 name=email_account_type><option value='$email_account_type' selected>$email_account_type</option><option>INBOUND</option></select>$NWB#vicidial_email_accounts-email_account_type$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Admin User Group: </td><td align=left><select size=1 name=user_group>\n";
echo "<option value='$user_group' selected>$user_group</option>";
echo "$UUgroups_list";
echo "<option SELECTED value=\"---ALL---\">All Admin User Groups</option>\n";
echo "</select>$NWB#vicidial_email_accounts-admin_user_group$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Protocol: </td><td align=left><select size=1 name=protocol><option>IMAP</option><option>POP3</option><option SELECTED>$protocol</option></select>$NWB#vicidial_email_accounts-protocol$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Reply-to Address: </td><td align=left><input type=text name=email_replyto_address size=70 maxlength=255 value='$email_replyto_address'>$NWB#vicidial_email_accounts-email_replyto_address$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Server: </td><td align=left><input type=text name=email_account_server size=70 maxlength=255 value='$email_account_server'>$NWB#vicidial_email_accounts-email_account_server$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account User: </td><td align=left><input type=text name=email_account_user size=30 maxlength=255 value='$email_account_user'>$NWB#vicidial_email_accounts-email_account_user$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Account Password: </td><td align=left><input type=text name=email_account_pass size=30 maxlength=100 value='$email_account_pass'>$NWB#vicidial_email_accounts-email_account_pass$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Email Frequency Check Rate (mins): </td><td align=left><select name='email_frequency_check_mins'>";
echo "<option value='$email_frequency_check_mins' selected>$email_frequency_check_mins</option>";
$i=5;
while ($i<=60)
{
echo "<option value='$i'>$i</option>";
$i+=5;
}
echo "</select>$NWB#vicidial_email_accounts-email_frequency_check_mins$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right><a href=\"admin.php?ADD=3811&group_id=$group_id\">In-Group ID</a>: </td><td align=left><select size=1 name=group_id>";
echo "$Dgroups_menu";
echo "<option value='$group_id' selected>$group_id</option></select>$NWB#vicidial_email_accounts-in_group$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right><a href=\"admin.php?ADD=1000\">Default List ID</a>: </td><td align=left><input type=text name=default_list_id size=20 maxlength=255 value='$default_list_id'>$NWB#vicidial_email_accounts-default_list_id$NWE</td></tr>\n";
###############
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Call Handle Method: </td><td align=left><select size=1 name=call_handle_method><option>EMAIL</option><option>EMAILLOOKUP</option><option>EMAILLOOKUPRL</option><option>EMAILLOOKUPRC</option><option SELECTED>$call_handle_method</option></select>$NWB#vicidial_email_accounts-call_handle_method$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Agent Search Method: </td><td align=left><select size=1 name=agent_search_method><option value=\"LB\">LB - Load Balanced</option><option value=\"LO\">LO - Load Balanced Overflow</option><option value=\"SO\">SO - Server Only</option><option SELECTED>$agent_search_method</option></select>$NWB#vicidial_email_accounts-agent_search_method$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group List ID: </td><td align=left><input type=text name=list_id size=14 maxlength=14 value=\"$list_id\">$NWB#vicidial_email_accounts-ingroup_list_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>In-Group Campaign ID: </td><td align=left><select size=1 name=campaign_id>\n";
echo "$campaigns_list";
echo "<option SELECTED>$campaign_id</option>\n";
echo "</select>$NWB#vicidial_email_accounts-ingroup_campaign_id$NWE</td></tr>\n";
echo "<tr bgcolor=#B6D3FC><td align=right>Un-handled Emails: </td><td align=left><B>$unhandled_emails</B></td></tr>\n";
################
echo "<tr bgcolor=#B6D3FC><td align=center colspan=2><input type=submit name=SUBMIT VALUE=UPDATE><input type=hidden name='eact' value='UPDATE'></td></tr>\n";
echo "</TABLE><BR><BR>";
if ($LOGuser_level >= 9)
{
echo "<br><br><a href=\"admin.php?ADD=720000000000000&category=EMAIL&stage=$user\">Click here to see Admin changes to this record</FONT>\n";
}
echo "<BR><BR><a href='$PHP_SELF?eact=DELETE&email_account_id=$email_account_id'>DELETE EMAIL ACCOUNT</a></center></form>\n";
}
else
{
echo "You do not have permission to view this page\n";
exit;
}
}
else
{
echo "<FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=2>";
if ($message) {echo "<B>$message</B><BR>";}
echo "<br>INBOUND EMAIL ACCOUNT LISTINGS:\n";
echo "<center><TABLE width=750 cellspacing=0 cellpadding=1>\n";
echo "<TR BGCOLOR=BLACK>\n";
echo "<TD><font size=1 color=white>ACCOUNT ID</TD>\n";
echo "<TD><font size=1 color=white>ACCOUNT NAME</TD>\n";
echo "<TD><font size=1 color=white>DESCRIPTION</TD>\n";
echo "<TD><font size=1 color=white>REPLY-TO ADDRESS</TD>\n";
echo "<TD><font size=1 color=white>PROTOCOL</TD>\n";
echo "<TD><font size=1 color=white>SERVER</TD>\n";
echo "<TD><font size=1 color=white>FREQUENCY</TD>\n";
echo "<TD><font size=1 color=white>ACTIVE</TD>\n";
echo "<TD><font size=1 color=white>UNREAD EMAILS</TD>\n";
echo "<TD><font size=1 color=white>MODIFY</TD></tr>\n";
$stmt="SELECT email_account_id, email_account_name, email_account_description, email_replyto_address, protocol, email_account_server, email_frequency_check_mins, active from vicidial_email_accounts $whereLOGadmin_viewable_groupsSQL order by email_account_id;";
$rslt=mysql_query($stmt, $link);
$accounts_to_print = mysql_num_rows($rslt);
$o=0;
while ($accounts_to_print > $o)
{
$row=mysql_fetch_array($rslt);
## Get unhandled count
$ct_stmt="select count(*) From vicidial_email_list where status='NEW' and email_account_id='$row[email_account_id]'";
$ct_rslt=mysql_query($ct_stmt, $link);
$ct_row=mysql_fetch_row($ct_rslt);
$unhandled_emails=$ct_row[0];
if (eregi("1$|3$|5$|7$|9$", $o))
{$bgcolor='bgcolor="#B9CBFD"';}
else
{$bgcolor='bgcolor="#9BB9FB"';}
echo "<tr $bgcolor><td><font size=1><a href=\"$PHP_SELF?eact=UPDATE&email_account_id=$row[email_account_id]\">$row[email_account_id]</a></font></td>";
echo "<td><font size=1> $row[email_account_name]</font></td>";
echo "<td><font size=1> $row[email_account_description]</font></td>";
echo "<td><font size=1> $row[email_replyto_address]</font></td>";
echo "<td><font size=1> $row[protocol]</font></td>";
echo "<td><font size=1> $row[email_account_server]</font></td>";
echo "<td><font size=1> $row[email_frequency_check_mins] mins</font></td>";
echo "<td><font size=1> $row[active]</font></td>";
echo "<td><font size=1> $unhandled_emails</font></td>";
echo "<td><font size=1><a href=\"$PHP_SELF?eact=UPDATE&email_account_id=$row[email_account_id]\">MODIFY</a></font></td></tr>\n";
$o++;
}
echo "</table></font>";
}
$ENDtime = date("U");
$RUNtime = ($ENDtime - $STARTtime);
echo "\n\n\n<br><br><br>\n<font size=1> runtime: $RUNtime seconds &nbsp; &nbsp; &nbsp; &nbsp; Version: $admin_version &nbsp; &nbsp; Build: $build</font>";
?>
</body>
</html>
+33 -4
View File
@@ -39,6 +39,7 @@
# 120402-2134 - Changed lead loader link to fourth gen
# 121116-1412 - Added QC functionality
# 121123-0911 - Added Call Times Holidays Inbound functionality
# 121214-2238 - Added email menus
#
@@ -872,7 +873,7 @@ if ( ($ADD==3511) or ($ADD==2511) or ($ADD==2611) or ($ADD==4511) or ($ADD==5511
}
### Javascript for dynamic in-group option value entries
if ( ($ADD==3111) or ($ADD==2111) or ($ADD==2011) or ($ADD==4111) or ($ADD==5111) )
if ( ($ADD==2811) or ($ADD==3811) or ($ADD==3111) or ($ADD==2111) or ($ADD==2011) or ($ADD==4111) or ($ADD==5111) )
{
?>
@@ -1057,14 +1058,14 @@ else
echo "<!-- INTERNATIONALIZATION-LINKS-PLACEHOLDER-VICIDIAL -->\n";
$stmt="SELECT admin_home_url,enable_tts_integration,callcard_enabled,custom_fields_enabled from system_settings;";
$stmt="SELECT admin_home_url,enable_tts_integration,callcard_enabled,custom_fields_enabled,allow_emails from system_settings;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$admin_home_url_LU = $row[0];
$SSenable_tts_integration = $row[1];
$SScallcard_enabled = $row[2];
$SScustom_fields_enabled = $row[3];
$SSemail_enabled = $row[4];
?>
<CENTER>
@@ -1261,6 +1262,20 @@ $SScustom_fields_enabled = $row[3];
</TD></TR><TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=1211"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Copy In-Group </a>
<HR>
<?php
if ($SSemail_enabled>0)
{
?>
<TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=1800"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Show Email Groups </a>
</TD></TR><TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=1811"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Add New Email Group </a>
</TD></TR><TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=1911"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Copy Email Group </a>
<HR>
<?php
}
?>
</TD></TR><TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=1300"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Show DIDs </a>
</TD></TR><TR BGCOLOR=<?php echo $ingroups_color ?>><TD ALIGN=LEFT> &nbsp;
@@ -1370,6 +1385,9 @@ $SScustom_fields_enabled = $row[3];
else {$cc_sh=''; $cc_fc='BLACK';}
if ($sh=='cts') {$cts_sh="bgcolor=\"$cts_color\""; $cts_fc="$cc_font";}
else {$cts_sh=''; $cts_fc='BLACK';}
if ($sh=='emails') {$emails_sh="bgcolor=\"$subcamp_color\""; $emails_fc="$subcamp_font";}
else {$emails_sh=''; $emails_fc='BLACK';}
?>
<TR BGCOLOR=<?php echo $admin_color ?>>
@@ -1396,7 +1414,14 @@ $SScustom_fields_enabled = $row[3];
</TR><TR BGCOLOR=<?php echo $admin_color ?>><TD ALIGN=LEFT <?php echo $vm_sh ?>> &nbsp;
<a href="<?php echo $ADMIN ?>?ADD=170000000000"><FONT FACE="ARIAL,HELVETICA" COLOR=<?php echo $vm_fc ?> SIZE=<?php echo $header_font_size ?>> Voicemail </a></TD>
</TR>
<?php if ( ($sounds_central_control_active > 0) or ($SSsounds_central_control_active > 0) )
<?php
if ($SSemail_enabled > 0)
{ ?>
<TR BGCOLOR=<?php echo $admin_color ?>><TD ALIGN=LEFT <?php echo $emails_sh ?>> &nbsp;
<a href="admin_email_accounts.php"><FONT FACE="ARIAL,HELVETICA" COLOR=<?php echo $emails_fc ?> SIZE=<?php echo $header_font_size ?>> Email Accounts </a></TD>
</TR>
<?php }
if ( ($sounds_central_control_active > 0) or ($SSsounds_central_control_active > 0) )
{ ?>
<TR BGCOLOR=<?php echo $admin_color ?>><TD ALIGN=LEFT <?php echo $audio_sh ?>> &nbsp;
<a href="audio_store.php"><FONT FACE="ARIAL,HELVETICA" COLOR=<?php echo $audio_fc ?> SIZE=<?php echo $header_font_size ?>> Audio Store </a></TD>
@@ -1490,6 +1515,10 @@ $SScustom_fields_enabled = $row[3];
?>
<TR BGCOLOR=<?php echo $carriers_color ?>><TD ALIGN=LEFT COLSPAN=2> &nbsp; <a href="<?php echo $ADMIN ?>?ADD=140000000000"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Show Carriers </a> &nbsp; | &nbsp; <a href="<?php echo $ADMIN ?>?ADD=141111111111"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Add A New Carrier </a> &nbsp; | &nbsp; <a href="<?php echo $ADMIN ?>?ADD=140111111111"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Copy A Carrier </a></TD></TR>
<?php }
if ( (strlen($emails_sh) > 1) and (strlen($admin_hh) > 1) ) {
?>
<TR BGCOLOR=<?php echo $emails_color ?>><TD ALIGN=LEFT COLSPAN=2> &nbsp; <a href="admin_email_accounts.php"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Show Email Accounts </a> &nbsp; | &nbsp; <a href="admin_email_accounts.php?eact=ADD"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=2> Add A New Account </a> &nbsp; | &nbsp; <a href="admin_email_accounts.php?eact=COPY"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Copy An Account </a></TD></TR>
<?php }
if ( (strlen($tts_sh) > 1) and (strlen($admin_hh) > 1) ) {
?>
<TR BGCOLOR=<?php echo $tts_color ?>><TD ALIGN=LEFT COLSPAN=2> &nbsp; <a href="<?php echo $ADMIN ?>?ADD=150000000000"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Show TTS Entries </a> &nbsp; | &nbsp; <a href="<?php echo $ADMIN ?>?ADD=151111111111"><FONT FACE="ARIAL,HELVETICA" COLOR=BLACK SIZE=<?php echo $subheader_font_size ?>> Add A New TTS Entry </a></TD></TR>
@@ -50,6 +50,7 @@
# 120529-1635 - Added User Group Campaign-Lists validation
# 121116-1411 - Added QC functionality
# 121130-1033 - Changed scheduled callback user ID field to be 20 characters, issue #467
# 121222-2145 - Added email log
#
require("dbconnect.php");
@@ -169,7 +170,7 @@ $NOW_TIME = date("Y-m-d H:i:s");
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,custom_fields_enabled,webroot_writable FROM system_settings;";
$stmt = "SELECT use_non_latin,custom_fields_enabled,webroot_writable,allow_emails FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
@@ -179,6 +180,7 @@ if ($qm_conf_ct > 0)
$non_latin = $row[0];
$custom_fields_enabled = $row[1];
$webroot_writable = $row[2];
$allow_emails = $row[3];
}
##### END SETTINGS LOOKUP #####
###########################################
@@ -1330,6 +1332,46 @@ else
echo "</TABLE><BR><BR>\n";
##### vicidial agent outbound calls for this time period #####
if ($allow_emails>0)
{
echo "<B>OUTBOUND EMAILS FOR THIS LEAD:</B>\n";
echo "<TABLE width=750 cellspacing=1 cellpadding=1>\n";
echo "<tr><td><font size=1># </td><td><font size=2>DATE/TIME </td><td align=right><font size=2> USER</td><td align=right><font size=2> CAMPAIGN</td><td align=left><font size=2>EMAIL TO</td><td align=left><font size=2> MESSAGE</td><td align=right><font size=2> ATTACHMENTS</td></tr>\n";
$stmt="select * from vicidial_email_log where lead_id='" . mysql_real_escape_string($lead_id) . "' order by email_date desc limit 500;";
$rslt=mysql_query($stmt, $link);
$logs_to_print = mysql_num_rows($rslt);
$u=0;
while ($logs_to_print > $u)
{
$row=mysql_fetch_row($rslt);
if (eregi("1$|3$|5$|7$|9$", $u))
{$bgcolor='bgcolor="#B9CBFD"';}
else
{$bgcolor='bgcolor="#9BB9FB"';}
if (strlen($row[6])>100) {$row[6]=substr($row[6],0,100)."...";}
$row[8]=preg_replace('/\|/', ', ', $row[8]);
$row[8]=preg_replace('/,\s+$/', '', $row[8]);
$u++;
echo "<tr $bgcolor>";
echo "<td><font size=1>$u</td>";
echo "<td><font size=1>$row[3]</td>";
echo "<td align=right><font size=2> <A HREF=\"user_stats.php?lead_id=$row[4]\" target=\"_blank\">$row[4]</A> </td>\n";
echo "<td align=left><font size=2> $row[7]</td>\n";
echo "<td align=left><font size=1> $row[5]</td>\n";
echo "<td align=left><font size=1> $row[6] </td>\n";
echo "<td align=right><font size=1> $row[8] </td></tr>\n";
}
echo "</TABLE><BR><BR>\n";
}
echo "<B>RECORDINGS FOR THIS LEAD:</B>\n";
echo "<TABLE width=750 cellspacing=1 cellpadding=1>\n";
+51 -1
View File
@@ -34,6 +34,7 @@
# 111103-1050 - Added admin_hide_phone_data and admin_hide_lead_data options
# 111106-1105 - Added user_group restrictions
# 120223-2135 - Removed logging of good login passwords if webroot writable is enabled
# 121222-2152 - Added email log display
#
@@ -46,7 +47,7 @@ $db_source = 'M';
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,user_territories_active,webroot_writable FROM system_settings;";
$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,user_territories_active,webroot_writable,allow_emails FROM system_settings;";
$rslt=mysql_query($stmt, $link);
if ($DB) {$MAIN.="$stmt\n";}
$qm_conf_ct = mysql_num_rows($rslt);
@@ -59,6 +60,7 @@ if ($qm_conf_ct > 0)
$reports_use_slave_db = $row[3];
$user_territories_active = $row[4];
$webroot_writable = $row[5];
$allow_emails = $row[6];
}
##### END SETTINGS LOOKUP #####
###########################################
@@ -695,6 +697,54 @@ if ($did < 1)
$MAIN.="</TABLE><BR><BR>\n";
}
##### vicidial agent outbound emails for this time period #####
if ($allow_emails>0)
{
$MAIN.="<B>OUTBOUND EMAILS FOR THIS TIME PERIOD: (10000 record limit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='$download_link&file_download=5'>[DOWNLOAD]</a></B>\n";
$MAIN.="<TABLE width=670 cellspacing=0 cellpadding=3>\n";
$MAIN.="<tr><td><font size=1># </td><td><font size=2>DATE/TIME </td><td align=left><font size=2>USER</td><td align=left><font size=2> CAMPAIGN</td><td align=left><font size=2> EMAIL TO</td><td align=right><font size=2> ATTACHMENTS</td><td align=right><font size=2> LEAD</td></tr>\n";
$CSV_text5.="\"OUTBOUND EMAILS FOR THIS TIME PERIOD: (10000 record limit)\"\n";
$CSV_text5.="\"\",\"#\",\"DATE/TIME\",\"USER\",\"CAMPAIGN\",\"EMAIL TO\",\"ATTACHMENT\",\"LEAD\",\"MESSAGE\"\n";
$stmt="select * from vicidial_email_log where user='" . mysql_real_escape_string($user) . "' and email_date >= '" . mysql_real_escape_string($begin_date) . " 0:00:01' and email_date <= '" . mysql_real_escape_string($end_date) . " 23:59:59' order by email_date desc limit 10000;";
$rslt=mysql_query($stmt, $link);
$logs_to_print = mysql_num_rows($rslt);
$u=0;
while ($logs_to_print > $u)
{
$row=mysql_fetch_row($rslt);
if (eregi("1$|3$|5$|7$|9$", $u))
{$bgcolor='bgcolor="#B9CBFD"';}
else
{$bgcolor='bgcolor="#9BB9FB"';}
if (strlen($row[6])>400) {$row[6]=substr($row[6],0,400)."...";}
$row[8]=preg_replace('/\|/', ', ', $row[8]);
$row[8]=preg_replace('/,\s+$/', '', $row[8]);
$u++;
$MAIN .= "<tr $bgcolor>";
$MAIN .= "<td><font size=1>$u</td>";
$MAIN .= "<td align=left><font size=1> &nbsp; $row[3]</td>";
$MAIN .= "<td align=left><font size=2> &nbsp; $row[4] </td>\n";
$MAIN .= "<td align=left><font size=2> &nbsp; $row[7]</td>\n";
$MAIN .= "<td align=left><font size=1> &nbsp; $row[5]</td>\n";
$MAIN .= "<td align=left><font size=1> &nbsp; $row[8] </td>\n";
$MAIN .= "<td align=left><font size=1> &nbsp; <A HREF=\"admin_modify_lead.php?lead_id=$row[2]\" target=\"_blank\">$row[2]</A> </td>\n";
$MAIN .= "</tr>\n";
$MAIN .= "<tr>";
$MAIN .= "<td><font size=1> &nbsp; </td>\n";
$MAIN .= "<td align=left colspan=6 $bgcolor><font size=1> MESSAGE: $row[6] </td>\n";
$MAIN .= "</tr>\n";
$CSV_text5.="\"\",\"$u\",\"$row[3]\",\"$row[4]\",\"$row[7]\",\"$row[5]\",\"$row[8]\",\"$row[2]\",\"$row[6]\"\n";
}
$MAIN.="</TABLE><BR><BR>\n";
}
##### vicidial agent inbound calls for this time period #####
$MAIN.="<B>INBOUND/CLOSER CALLS FOR THIS TIME PERIOD: (10000 record limit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='$download_link&file_download=6'>[DOWNLOAD]</a></B>\n";