LICENSE: AGPLv2
#
# CHANGES
# 150218-0923 - First build based on callbacks_bulk_change.php
# 151025-1041 - Fixed issue with check-all
# 161105-0056 - Added options to purge uncalled callbacks, and also to revert callbacks to their most recent non-callback-dispo based on the callback entry time and the log tables.
# 170409-1548 - Added IP List validation code
# 180508-0115 - Added new help display
# 191013-0853 - Fixes for PHP7
#
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'];
$PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF);
if (isset($_GET["days"])) {$days=$_GET["days"];}
elseif (isset($_POST["days"])) {$days=$_POST["days"];}
if (isset($_GET["user"])) {$user=$_GET["user"];}
elseif (isset($_POST["user"])) {$user=$_POST["user"];}
if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
if (isset($_GET["campaign_id"])) {$campaign_id=$_GET["campaign_id"];}
elseif (isset($_POST["campaign_id"])) {$campaign_id=$_POST["campaign_id"];}
if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];}
elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
if (isset($_GET["confirm_transfer"])) {$confirm_transfer=$_GET["confirm_transfer"];}
elseif (isset($_POST["confirm_transfer"])) {$confirm_transfer=$_POST["confirm_transfer"];}
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["submit"])) {$submit=$_GET["submit"];}
elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];}
if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];}
elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];}
if (isset($_GET["new_list_id"])) {$new_list_id=$_GET["new_list_id"];}
elseif (isset($_POST["new_list_id"])) {$new_list_id=$_POST["new_list_id"];}
if (isset($_GET["new_status"])) {$new_status=$_GET["new_status"];}
elseif (isset($_POST["new_status"])) {$new_status=$_POST["new_status"];}
if (isset($_GET["cb_groups"])) {$cb_groups=$_GET["cb_groups"];}
elseif (isset($_POST["cb_groups"])) {$cb_groups=$_POST["cb_groups"];}
if (isset($_GET["cb_user_groups"])) {$cb_user_groups=$_GET["cb_user_groups"];}
elseif (isset($_POST["cb_user_groups"])) {$cb_user_groups=$_POST["cb_user_groups"];}
if (isset($_GET["cb_lists"])) {$cb_lists=$_GET["cb_lists"];}
elseif (isset($_POST["cb_lists"])) {$cb_lists=$_POST["cb_lists"];}
if (isset($_GET["cb_users"])) {$cb_users=$_GET["cb_users"];}
elseif (isset($_POST["cb_users"])) {$cb_users=$_POST["cb_users"];}
if (isset($_GET["days_uncalled"])) {$days_uncalled=$_GET["days_uncalled"];}
elseif (isset($_POST["days_uncalled"])) {$days_uncalled=$_POST["days_uncalled"];}
if (isset($_GET["purge_called_records"])) {$purge_called_records=$_GET["purge_called_records"];}
elseif (isset($_POST["purge_called_records"])) {$purge_called_records=$_POST["purge_called_records"];}
if (isset($_GET["purge_uncalled_records"])) {$purge_uncalled_records=$_GET["purge_uncalled_records"];}
elseif (isset($_POST["purge_uncalled_records"])) {$purge_uncalled_records=$_POST["purge_uncalled_records"];}
if (isset($_GET["revert_status"])) {$revert_status=$_GET["revert_status"];}
elseif (isset($_POST["revert_status"])) {$revert_status=$_POST["revert_status"];}
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,webroot_writable,outbound_autodial_active,enable_languages,language_method,qc_features_active FROM system_settings;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$qm_conf_ct = mysqli_num_rows($rslt);
if ($qm_conf_ct > 0)
{
$row=mysqli_fetch_row($rslt);
$non_latin = $row[0];
$webroot_writable = $row[1];
$SSoutbound_autodial_active = $row[2];
$SSenable_languages = $row[3];
$SSlanguage_method = $row[4];
$SSqc_features_active = $row[5];
}
##### 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);
}
else
{
$PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW);
$PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER);
}
$StarTtimE = date("U");
$TODAY = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
if (!isset($group)) {$group=array();}
if (!isset($users)) {$users=array();}
$ip = getenv("REMOTE_ADDR");
$date = date("r");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$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];
}
$category='';
$record_id='';
if (strlen($days) < 1) {$days='2';}
if (strlen($user) < 1) {$category='USERS'; $record_id=$user;}
if (strlen($user_group) < 1) {$category='USERGROUPS'; $record_id=$user_group;}
if (strlen($list_id) < 1) {$category='LISTS'; $record_id=$list_id;}
if (strlen($campaign_id) < 1) {$category='CAMPAIGNS'; $record_id=$campaign_id;}
$auth=0;
$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'',1,0);
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;
}
if ($auth_message == 'IPBLOCK')
{
$VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip";
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,change_agent_campaign,modify_timeclock_log,user_group,user_level,modify_leads from vicidial_users where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGfullname = $row[0];
$change_agent_campaign = $row[1];
$modify_timeclock_log = $row[2];
$LOGuser_group = $row[3];
$user_level = $row[4];
$LOGmodify_leads = $row[5];
if ($user_level==9)
{
$ul_clause="where user_level<=9";
}
else
{
$ul_clause="where user_level<$user_level";
}
if ($LOGmodify_leads < 1)
{
Header ("Content-type: text/html; charset=utf-8");
echo _QXZ("You do not have permissions to modify leads").": |$PHP_AUTH_USER|\n";
exit;
}
$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGallowed_campaigns = $row[0];
$LOGallowed_reports = $row[1];
$LOGadmin_viewable_groups = $row[2];
$LOGadmin_viewable_call_times = $row[3];
$LOGallowed_campaignsSQL='';
$whereLOGallowed_campaignsSQL='';
if ( (!preg_match('/\-ALL/i', $LOGallowed_campaigns)) )
{
$rawLOGallowed_campaignsSQL = preg_replace("/ -/",'',$LOGallowed_campaigns);
$rawLOGallowed_campaignsSQL = preg_replace("/ /","','",$rawLOGallowed_campaignsSQL);
$LOGallowed_campaignsSQL = "and campaign_id IN('$rawLOGallowed_campaignsSQL')";
$whereLOGallowed_campaignsSQL = "where campaign_id IN('$rawLOGallowed_campaignsSQL')";
}
$regexLOGallowed_campaigns = " $LOGallowed_campaigns ";
$LOGadmin_viewable_groupsSQL='';
$whereLOGadmin_viewable_groupsSQL='';
if ( (!preg_match('/\-\-ALL\-\-/i',$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')";
}
$LOGadmin_viewable_call_timesSQL='';
$whereLOGadmin_viewable_call_timesSQL='';
if ( (!preg_match('/\-\-ALL\-\-/i', $LOGadmin_viewable_call_times)) and (strlen($LOGadmin_viewable_call_times) > 3) )
{
$rawLOGadmin_viewable_call_timesSQL = preg_replace("/ -/",'',$LOGadmin_viewable_call_times);
$rawLOGadmin_viewable_call_timesSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_call_timesSQL);
$LOGadmin_viewable_call_timesSQL = "and call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')";
$whereLOGadmin_viewable_call_timesSQL = "where call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')";
}
$i=0;
$group_string='|';
$group_ct = count($group);
while($i < $group_ct)
{
$group_string .= "$group[$i]|";
$i++;
}
$i=0;
$users_string='|';
$users_ct = count($users);
while($i < $users_ct)
{
$users_string .= "$users[$i]|";
$i++;
}
/*
$i=0;
$user_group_string='|';
$user_group_ct = count($user_group);
while($i < $users_ct)
{
$user_group_string .= "$user_group[$i]|";
$i++;
}
*/
$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$campaigns_to_print = mysqli_num_rows($rslt);
$i=0;
while ($i < $campaigns_to_print)
{
$row=mysqli_fetch_row($rslt);
$groups[$i] =$row[0];
#if (preg_match('/\-ALL/',$group_string) )
# {$group[$i] = $groups[$i];}
$i++;
}
$stmt="SELECT user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$user_groups_to_print = mysqli_num_rows($rslt);
$i=0;
while ($i < $user_groups_to_print)
{
$row=mysqli_fetch_row($rslt);
$user_groups[$i] =$row[0];
# if (preg_match('/\-ALL/',$user_group_string)) {$user_group[$i]=$row[0];}
$i++;
}
$stmt="SELECT user, full_name from vicidial_users $whereLOGadmin_viewable_groupsSQL order by user";
$rslt=mysql_to_mysqli($stmt, $link);
if ($DB) {echo "$stmt\n";}
$users_to_print = mysqli_num_rows($rslt);
$i=0;
while ($i < $users_to_print)
{
$row=mysqli_fetch_row($rslt);
$user_list[$i]=$row[0];
$user_names[$i]=$row[1];
if ($all_users) {$user_list[$i]=$row[0];}
$i++;
}
$i=0;
$user_string='|';
$user_ct = count($users);
while($i < $user_ct)
{
$user_string .= "$users[$i]|";
# $user_SQL .= "'$users[$i]',";
$user_SQL .= " selected_agents like '%|".$users[$i]."|%' or ";
$userQS .= "&users[]=$users[$i]";
$i++;
}
if ( (preg_match('/\-\-ALL\-\-/',$user_string) ) or ($user_ct < 1) )
{$user_SQL = "";}
else
{
# $user_string=preg_replace("/^\||\|$/", "", $user_string);
$user_SQL = preg_replace('/ or $/i', '',$user_SQL);
# $user_agent_log_SQL = "and vicidial_agent_log.user IN($user_SQL)";
}
/*
$i=0;
$user_group_string='|';
$user_group_ct = count($user_group);
while($i < $user_group_ct)
{
$user_group_string .= "$user_group[$i]|";
# $user_group_SQL .= "'$user_group[$i]',";
$user_group_SQL .= " selected_user_groups like '%|".$user_group[$i]."|%' or ";
$user_groupQS .= "&user_group[]=$user_group[$i]";
$i++;
}
if ( (preg_match('/\-\-ALL\-\-/',$user_group_string) ) or ($user_group_ct < 1) )
{$user_group_SQL = "";}
else
{
# $user_group_string=preg_replace("/^\||\|$/", "", $user_group_string);
$user_group_SQL = preg_replace('/ or $/i', '',$user_group_SQL);
# $user_group_agent_log_SQL = "and vicidial_agent_log.user_group IN($user_group_SQL)";
$user_group_SQL = "and ($user_group_SQL or selected_user_groups='|')";
}
*/
$i=0;
$group_string='|';
$group_ct = count($group);
while($i < $group_ct)
{
if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) )
{
$group_string .= "$group[$i]|";
# $group_SQL .= "'$group[$i]',";
$group_SQL .= " selected_campaigns like '%|".$group[$i]."|%' or ";
$groupQS .= "&group[]=$group[$i]";
}
$i++;
}
if ( (preg_match('/\-\-ALL\-\-/',$group_string) ) or ($group_ct < 1) )
{$group_SQL = "";}
else
{
# $group_string=preg_replace("/^\||\|$/", "", $group_string);
$group_SQL = preg_replace('/ or $/i', '',$group_SQL);
$group_SQL = "and ($group_SQL or selected_campaigns='|')";
}
# $NWB = "
";
$NWB = "
";
### PRELOAD ###
$preload_campaigns=array();
$preload_lists=array();
$preload_user_groups=array();
$preload_users=array();
if ($campaign_id)
{
# Trying a three-level UNION statement to see if that's faster
$stmt="SELECT distinct campaign_id, 'CAMPAIGN' as dtype FROM vicidial_callbacks where campaign_id='$campaign_id' UNION SELECT distinct user_group, 'USER_GROUP' as dtype FROM vicidial_callbacks where campaign_id='$campaign_id' UNION SELECT distinct list_id, 'LIST_ID' as dtype from vicidial_callbacks where campaign_id='$campaign_id' UNION SELECT distinct user, 'USER' as dtype from vicidial_callbacks where campaign_id='$campaign_id' order by dtype asc;";
$rslt=mysql_to_mysqli($stmt, $link);
while ($row=mysqli_fetch_row($rslt))
{
switch ($row[1])
{
case "CAMPAIGN":
array_push($preload_campaigns, "$row[0]");
break;
case "USER_GROUP":
array_push($preload_user_groups, "$row[0]");
break;
case "USER":
array_push($preload_users, "$row[0]");
break;
case "LIST_ID":
array_push($preload_lists, "$row[0]");
break;
}
}
}
if ($list_id)
{
$preload_campaigns=array();
$preload_lists=array();
$preload_user_groups=array();
$preload_users=array();
# Trying a three-level UNION statement to see if that's faster
$stmt="SELECT distinct campaign_id, 'CAMPAIGN' as dtype FROM vicidial_callbacks where list_id='$list_id' UNION SELECT distinct user_group, 'USER_GROUP' as dtype FROM vicidial_callbacks where list_id='$list_id' UNION SELECT distinct list_id, 'LIST_ID' as dtype from vicidial_callbacks where list_id='$list_id' UNION SELECT distinct user, 'USER' as dtype from vicidial_callbacks where list_id='$list_id' order by dtype asc;";
$rslt=mysql_to_mysqli($stmt, $link);
while ($row=mysqli_fetch_row($rslt))
{
switch ($row[1])
{
case "CAMPAIGN":
array_push($preload_campaigns, "$row[0]");
break;
case "USER_GROUP":
array_push($preload_user_groups, "$row[0]");
break;
case "USER":
array_push($preload_users, "$row[0]");
break;
case "LIST_ID":
array_push($preload_lists, "$row[0]");
break;
}
}
}
if ($user)
{
$preload_campaigns=array();
$preload_lists=array();
$preload_user_groups=array();
$preload_users=array();
# Trying a three-level UNION statement to see if that's faster
$stmt="SELECT distinct campaign_id, 'CAMPAIGN' as dtype FROM vicidial_callbacks where user='$user' UNION SELECT distinct user_group, 'USER_GROUP' as dtype FROM vicidial_callbacks where user='$user' UNION SELECT distinct list_id, 'LIST_ID' as dtype from vicidial_callbacks where user='$user' UNION SELECT distinct user, 'USER' as dtype from vicidial_callbacks where user='$user' order by dtype asc;";
$rslt=mysql_to_mysqli($stmt, $link);
while ($row=mysqli_fetch_row($rslt))
{
switch ($row[1])
{
case "CAMPAIGN":
array_push($preload_campaigns, "$row[0]");
break;
case "USER_GROUP":
array_push($preload_user_groups, "$row[0]");
break;
case "USER":
array_push($preload_users, "$row[0]");
break;
case "LIST_ID":
array_push($preload_lists, "$row[0]");
break;
}
}
}
if ($user_group)
{
$preload_campaigns=array();
$preload_lists=array();
$preload_user_groups=array();
$preload_users=array();
# Trying a three-level UNION statement to see if that's faster
$stmt="SELECT distinct campaign_id, 'CAMPAIGN' as dtype FROM vicidial_callbacks where user_group='$user_group' UNION SELECT distinct user_group, 'USER_GROUP' as dtype FROM vicidial_callbacks where user_group='$user_group' UNION SELECT distinct list_id, 'LIST_ID' as dtype from vicidial_callbacks where user_group='$user_group' UNION SELECT distinct user, 'USER' as dtype from vicidial_callbacks where user_group='$user_group' order by dtype asc;";
$rslt=mysql_to_mysqli($stmt, $link);
while ($row=mysqli_fetch_row($rslt))
{
switch ($row[1])
{
case "CAMPAIGN":
array_push($preload_campaigns, "$row[0]");
break;
case "USER_GROUP":
array_push($preload_user_groups, "$row[0]");
break;
case "USER":
array_push($preload_users, "$row[0]");
break;
case "LIST_ID":
array_push($preload_lists, "$row[0]");
break;
}
}
}
###############
?>
| \n"; ### callbacks change form echo " |