LICENSE: AGPLv2
#
# this screen will control the *amd* settings needed when the Campaign setting
# "AM Message Wildcards" is enabled. This screen allows for multiple messages
# and fields to be entered and ranked in the order in which they are are to be
# searched.
#
# changes:
# 151109-1653 - First Build
# 160801-1201 - Added colors features
#
$admin_version = '2.12-2';
$build = '160801-1201';
require("dbconnect_mysqli.php");
require("functions.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["amm_id"])) {$amm_id=$_GET["amm_id"];}
elseif (isset($_POST["amm_id"])) {$amm_id=$_POST["amm_id"];}
if (isset($_GET["campaign_id"])) {$campaign_id=$_GET["campaign_id"];}
elseif (isset($_POST["campaign_id"])) {$campaign_id=$_POST["campaign_id"];}
if (isset($_GET["entry_type"])) {$entry_type=$_GET["entry_type"];}
elseif (isset($_POST["entry_type"])) {$entry_type=$_POST["entry_type"];}
if (isset($_GET["active"])) {$active=$_GET["active"];}
elseif (isset($_POST["active"])) {$active=$_POST["active"];}
if (isset($_GET["amm_field"])) {$amm_field=$_GET["amm_field"];}
elseif (isset($_POST["amm_field"])) {$amm_field=$_POST["amm_field"];}
if (isset($_GET["amm_rank"])) {$amm_rank=$_GET["amm_rank"];}
elseif (isset($_POST["amm_rank"])) {$amm_rank=$_POST["amm_rank"];}
if (isset($_GET["amm_wildcard"])) {$amm_wildcard=$_GET["amm_wildcard"];}
elseif (isset($_POST["amm_wildcard"])) {$amm_wildcard=$_POST["amm_wildcard"];}
if (isset($_GET["amm_description"])) {$amm_description=$_GET["amm_description"];}
elseif (isset($_POST["amm_description"])) {$amm_description=$_POST["amm_description"];}
if (isset($_GET["amm_filename"])) {$amm_filename=$_GET["amm_filename"];}
elseif (isset($_POST["amm_filename"])) {$amm_filename=$_POST["amm_filename"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (strlen($action) < 2)
{$action = 'BLANK';}
if (strlen($DB) < 1)
{$DB=0;}
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,webroot_writable,enable_languages,language_method,qc_features_active FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$ss_conf_ct = mysqli_num_rows($rslt);
if ($ss_conf_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$non_latin = $row[0];
$webroot_writable = $row[1];
$SSenable_languages = $row[2];
$SSlanguage_method = $row[3];
$SSqc_features_active = $row[4];
}
##### END SETTINGS LOOKUP #####
###########################################
if ($non_latin < 1)
{
$PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/','',$PHP_AUTH_USER);
$PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/','',$PHP_AUTH_PW);
$amm_id = preg_replace('/[^0-9]/','',$amm_id);
$campaign_id = preg_replace('/[^-_0-9a-zA-Z]/','',$campaign_id);
$entry_type = preg_replace('/[^_0-9a-zA-Z]/','',$entry_type);
$active = preg_replace('/[^A-Z]/','',$active);
$amm_field = preg_replace('/[^_0-9a-zA-Z]/','',$amm_field);
$amm_rank = preg_replace('/[^-0-9]/','',$amm_rank);
$amm_wildcard = preg_replace('/[^- _0-9a-zA-Z]/','',$amm_wildcard);
$amm_description = preg_replace('/[^- \.\,\_0-9a-zA-Z]/','',$amm_description);
$amm_filename = preg_replace('/[^- \|\.\,\_0-9a-zA-Z]/','',$amm_filename);
} # end of non_latin
else
{
$PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER);
$PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW);
}
$STARTtime = date("U");
$TODAY = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$date = date("r");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$user = $PHP_AUTH_USER;
$NWB = " ";
$stmt="SELECT selected_language,qc_enabled from vicidial_users where user='$PHP_AUTH_USER';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$sl_ct = mysqli_num_rows($rslt);
if ($sl_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$VUselected_language = $row[0];
$qc_auth = $row[1];
}
$auth=0;
$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'',1);
if ($auth_message == 'GOOD')
{$auth=1;}
if ($auth < 1)
{
$VDdisplayMESSAGE = _QXZ("Login incorrect, please try again");
if ($auth_message == 'LOCK')
{
$VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes");
Header ("Content-type: text/html; charset=utf-8");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n";
exit;
}
Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\"");
Header("HTTP/1.0 401 Unauthorized");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n";
exit;
}
$stmt="SELECT full_name,modify_campaigns,user_level from vicidial_users where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGfullname = $row[0];
$LOGmodify_campaigns = $row[1];
$LOGuser_level = $row[2];
if ($LOGmodify_campaigns < 1)
{
Header ("Content-type: text/html; charset=utf-8");
echo _QXZ("You do not have permissions to modify campaigns")."\n";
exit;
}
##### BEGIN Set variables to make header show properly #####
$ADD = '31';
$SUB = '26';
$hh = 'campaigns';
$sh = 'detail';
$LOGast_admin_access = '1';
$SSoutbound_autodial_active = '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='';
$header_nonselected_bold='';
$campaigns_color = '#FFFF99';
$campaigns_font = 'BLACK';
$campaigns_color = '#E6E6E6';
$subcamp_color = '#C6C6C6';
$ingroups_font = 'BLACK';
$ingroups_color = '#E6E6E6';
$lists_font = 'BLACK';
$lists_color = '#E6E6E6';
##### END Set variables to make header show properly #####
if (strlen($campaign_id) < 1)
{
echo _QXZ("ERROR: ID not defined:");
exit;
}
if ($entry_type == 'campaign')
{
$ADD = '31';
$hh = 'campaigns';
$stmt_name="SELECT campaign_name from vicidial_campaigns where campaign_id='$campaign_id';";
$mod_link = "ADD=$ADD&campaign_id=";
$event_section = 'CAMPAIGNS';
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and am_message_wildcards='Y';";
}
elseif ($entry_type == 'ingroup')
{
$ADD = '3111';
$hh = 'ingroups';
$stmt_name="SELECT group_name from vicidial_inbound_groups where group_id='$campaign_id';";
$mod_link = "ADD=$ADD&group_id=";
$event_section = 'INGROUPS';
$stmt="SELECT count(*) from vicidial_inbound_groups where group_id='$campaign_id' and am_message_wildcards='Y';";
}
else
{
echo _QXZ("ERROR: no entry type defined:") . $entry_type;
exit;
}
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$camp_multi=$row[0];
$camp_name='';
$rslt=mysql_to_mysqli($stmt_name, $link);
$names_to_print = mysqli_num_rows($rslt);
if ($names_to_print > 0)
{
$row=mysqli_fetch_row($rslt);
$camp_name = $row[0];
}
?>
0)
{
echo "$DB,$action,$campaign_id,$amm_id,$entry_type,$active,$amm_field,$amm_rank,$amm_wildcard,$amm_description\n ";
}
################################################################################
##### BEGIN AMM multi NEW section
if ($action == "AMM_MULTI_NEW")
{
if ( (strlen($active)<1) or (strlen($amm_rank)<1) or (strlen($amm_wildcard)<1) or (strlen($amm_description)<1) or (strlen($amm_filename)<1) )
{
echo _QXZ("ERROR: You must fill in all fields").": |$active|$amm_rank|$amm_wildcard|$amm_description|$amm_filename|\n ";
exit;
}
$stmt="INSERT INTO vicidial_amm_multi SET campaign_id='$campaign_id',entry_type='$entry_type',amm_field='$amm_field',active='$active',amm_rank='$amm_rank',amm_wildcard='$amm_wildcard',amm_description='$amm_description',amm_filename='" . mysqli_real_escape_string($link, $amm_filename) . "';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
if ($DB > 0) {echo "$affected_rows|$stmt\n ";}
if ($affected_rows > 0)
{
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = preg_replace('/;/', '', $SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='$event_section', event_type='ADD', record_id='$campaign_id', event_code='ADD MULTI AMM', event_sql=\"$SQL_log\", event_notes='$amm_field';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB > 0) {echo "$campaign_id|$stmt\n ";}
echo " $affected_rows "._QXZ("MULTI AM MESSAGE ADDED")."
";
}
else
{echo _QXZ("ERROR: Problem adding AM Message").": $affected_rows|$stmt\n ";}
$action='BLANK';
}
##### END AMM multi NEW section
################################################################################
##### BEGIN AMM multi MODIFY section
if ($action == "AMM_MULTI_MODIFY")
{
if ( (strlen($amm_id)<1) or (strlen($active)<1) or (strlen($amm_rank)<1) or (strlen($amm_wildcard)<1) or (strlen($amm_description)<1) or (strlen($amm_filename)<1) )
{
echo _QXZ("ERROR: You must fill in all fields").": |$amm_id|$active|$amm_rank|$amm_wildcard|$amm_description|$amm_filename|\n ";
exit;
}
$stmt="SELECT count(*) from vicidial_amm_multi where campaign_id='$campaign_id' and entry_type='$entry_type' and amm_field='$amm_field' and amm_id='$amm_id';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$amm_count=$row[0];
if ($amm_count < 1)
{
echo _QXZ("ERROR: AM MESSAGE entry does not exist").": |$amm_id|$campaign_id|$entry_type|$amm_field|\n ";
exit;
}
$stmt="UPDATE vicidial_amm_multi SET active='$active',amm_rank='$amm_rank',amm_wildcard='$amm_wildcard',amm_description='$amm_description',amm_filename='" . mysqli_real_escape_string($link, $amm_filename) . "' where campaign_id='$campaign_id' and entry_type='$entry_type' and amm_field='$amm_field' and amm_id='$amm_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
if ($DB > 0) {echo "$affected_rows|$stmt\n ";}
if ($affected_rows > 0)
{
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = preg_replace('/;/', '', $SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='$event_section', event_type='MODIFY', record_id='$campaign_id', event_code='MODIFY MULTI AMM', event_sql=\"$SQL_log\", event_notes='$amm_field ID: $amm_id';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB > 0) {echo "$campaign_id|$stmt\n ";}
echo " $affected_rows "._QXZ("MULTI AM MESSAGE MODIFIED")." (ID: $amm_id)
";
}
else
{echo _QXZ("ERROR: Problem modifying AM MESSAGE").": $affected_rows|$stmt\n ";}
$action='BLANK';
}
##### END AMM multi MODIFY section
################################################################################
##### BEGIN AMM multi DELETE section
if ($action == "AMM_MULTI_DELETE")
{
if ( (strlen($amm_id)<1) or (strlen($campaign_id)<1) or (strlen($entry_type)<1) or (strlen($amm_field)<1) )
{
echo _QXZ("ERROR: You must fill in all fields").": |$amm_id|$campaign_id|$entry_type|$amm_field|\n ";
exit;
}
$stmt="SELECT count(*) from vicidial_amm_multi where campaign_id='$campaign_id' and entry_type='$entry_type' and amm_field='$amm_field' and amm_id='$amm_id' and active='N';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$amm_count=$row[0];
if ($amm_count < 1)
{
echo _QXZ("ERROR: AM MESSAGE entry must be set to not active before you delete it").": |$amm_id|$campaign_id|$entry_type|$amm_field|\n ";
}
else
{
$stmt="DELETE FROM vicidial_amm_multi where campaign_id='$campaign_id' and entry_type='$entry_type' and amm_field='$amm_field' and amm_id='$amm_id' and active='N';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
if ($DB > 0) {echo "$affected_rows|$stmt\n ";}
if ($affected_rows > 0)
{
### LOG INSERTION Admin Log Table ###
$SQL_log = "$stmt|";
$SQL_log = preg_replace('/;/', '', $SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='$event_section', event_type='DELETE', record_id='$campaign_id', event_code='DELETE MULTI AMM', event_sql=\"$SQL_log\", event_notes='$amm_field ID: $amm_id';";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB > 0) {echo "$campaign_id|$stmt\n ";}
echo " $affected_rows "._QXZ("MULTI AM MESSAGE DELETED")." (ID: $amm_id)
";
}
else
{echo _QXZ("ERROR: Problem deleting AM MESSAGE").": $affected_rows|$stmt\n ";}
}
$action='BLANK';
}
##### END AMM multi DELETE section
################################################################################
##### BEGIN AMM multi control form
if ($action == "BLANK")
{
$bgcolor='bgcolor="#'. $SSstd_row2_background .'"';
echo "