LICENSE: AGPLv2
#
# This script is designed to allow agents to work with the hopper_hold_inserts features and allow leads in the hopper to be changed from RHOLD to READY status so they can be called.
#
# changes:
# 231119-1508 - First build
# 240225-1000 - Added AUTONEXT hopper_hold_inserts campaign option
#
$startMS = microtime();
$hci_version = '2.14-2h';
$build = '240225-1000';
$php_script='hci_screen.php';
$zi=0;
$default_batch_size=40;
$refresh_sec=4000;
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["lead_id"])) {$lead_id=$_GET["lead_id"];}
elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];}
if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];}
elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];}
if (isset($_GET["campaign_id"])) {$campaign_id=$_GET["campaign_id"];}
elseif (isset($_POST["campaign_id"])) {$campaign_id=$_POST["campaign_id"];}
if (isset($_GET["batch_size"])) {$batch_size=$_GET["batch_size"];}
elseif (isset($_POST["batch_size"])) {$batch_size=$_POST["batch_size"];}
if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
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"];}
$DB=preg_replace('/[^0-9]/','',$DB);
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,custom_fields_enabled,enable_languages,language_method,active_modules,log_recording_access,allow_web_debug,hopper_hold_inserts,agent_screen_colors,admin_web_directory,admin_home_url 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];
$custom_fields_enabled = $row[1];
$SSenable_languages = $row[2];
$SSlanguage_method = $row[3];
$active_modules = $row[4];
$log_recording_access = $row[5];
$SSallow_web_debug = $row[6];
$SShopper_hold_inserts = $row[7];
$agent_screen_colors = $row[8];
$admin_web_directory = $row[9];
$admin_home_url = $row[10];
}
if ($SSallow_web_debug < 1) {$DB=0;}
##### END SETTINGS LOOKUP #####
###########################################
$phone_number = preg_replace('/[^0-9]/','',$phone_number);
$batch_size = preg_replace('/[^0-9]/','',$batch_size);
$stage = preg_replace('/[^-_0-9a-zA-Z]/','',$stage);
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);
$user = preg_replace('/[^-\_0-9a-zA-Z]/','',$user);
$campaign_id = preg_replace('/[^-\_0-9a-zA-Z]/', '',$campaign_id);
$submit = preg_replace('/[^- 0-9a-zA-Z]/','',$submit);
$SUBMIT = preg_replace('/[^- 0-9a-zA-Z]/','',$SUBMIT);
}
else
{
$PHP_AUTH_USER = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_USER);
$PHP_AUTH_PW = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_PW);
$user=preg_replace('/[^-_0-9\p{L}]/u','',$user);
$campaign_id = preg_replace('/[^-\_0-9\p{L}]/u', '',$campaign_id);
$submit = preg_replace('/[^- 0-9\p{L}]/u','',$submit);
$SUBMIT = preg_replace('/[^- 0-9\p{L}]/u','',$SUBMIT);
}
if ( ($batch_size < 10) or (strlen($batch_size) < 2) )
{$batch_size = $default_batch_size;}
$STARTtime = date("U");
$defaultappointment = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s");
$ip = getenv("REMOTE_ADDR");
$browser = getenv("HTTP_USER_AGENT");
$browser=preg_replace("/\'|\"|\\\\/","",$browser);
$script_name = getenv("SCRIPT_NAME");
$server_name = getenv("SERVER_NAME");
$server_port = getenv("SERVER_PORT");
$PHP_SELF=$_SERVER['PHP_SELF'];
$PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF);
$CL=':';
if (preg_match("/443/i",$server_port)) {$HTTPprotocol = 'https://';}
else {$HTTPprotocol = 'http://';}
if (($server_port == '80') or ($server_port == '443') ) {$server_port='';}
else {$server_port = "$CL$server_port";}
$FQDN = "$server_name$server_port";
$hciPAGE = "$HTTPprotocol$server_name$server_port$script_name";
$stmt="SELECT modify_leads,qc_enabled,full_name,modify_leads,user_group,selected_language,hci_enabled from vicidial_users where user='$PHP_AUTH_USER';";
if ($non_latin > 0) {$rslt=mysql_to_mysqli("SET NAMES 'UTF8'", $link);}
$rslt=mysql_to_mysqli($stmt, $link);
$users_to_parse = mysqli_num_rows($rslt);
if ($users_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$modify_leads = $rowx[0];
$qc_enabled = $rowx[1];
$LOGfullname = $rowx[2];
$LOGmodify_leads = $rowx[3];
$LOGuser_group = $rowx[4];
$VUselected_language = $rowx[5];
$hci_enabled = $rowx[6];
}
##### BEGIN Define colors and logo #####
$SSmenu_background='015B91';
$SSframe_background='D9E6FE';
$SSstd_row1_background='9BB9FB';
$SSstd_row2_background='B9CBFD';
$SSstd_row3_background='8EBCFD';
$SSstd_row4_background='B6D3FC';
$SSstd_row5_background='A3C3D6';
$SSalt_row1_background='BDFFBD';
$SSalt_row2_background='99FF99';
$SSalt_row3_background='CCFFCC';
if ($agent_screen_colors != 'default')
{
$stmt = "SELECT menu_background,frame_background,std_row1_background,std_row2_background,std_row3_background,std_row4_background,std_row5_background,alt_row1_background,alt_row2_background,alt_row3_background,web_logo FROM vicidial_screen_colors where colors_id='$agent_screen_colors';";
$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);
$SSmenu_background = $row[0];
$SSframe_background = $row[1];
$SSstd_row1_background = $row[2];
$SSstd_row2_background = $row[3];
$SSstd_row3_background = $row[4];
$SSstd_row4_background = $row[5];
$SSstd_row5_background = $row[6];
$SSalt_row1_background = $row[7];
$SSalt_row2_background = $row[8];
$SSalt_row3_background = $row[9];
$SSweb_logo = $row[10];
}
}
$Mhead_color = $SSstd_row5_background;
$Mmain_bgcolor = $SSmenu_background;
$Mhead_color = $SSstd_row5_background;
$selected_logo = "./images/vicidial_admin_web_logo.png";
$logo_new=0;
$logo_old=0;
if (file_exists('../$admin_web_directory/images/vicidial_admin_web_logo.png')) {$logo_new++;}
if (file_exists('vicidial_admin_web_logo.gif')) {$logo_old++;}
if ($SSweb_logo=='default_new')
{
$selected_logo = "./images/vicidial_admin_web_logo.png";
}
if ( ($SSweb_logo=='default_old') and ($logo_old > 0) )
{
$selected_logo = "../$admin_web_directory/vicidial_admin_web_logo.gif";
}
if ( ($SSweb_logo!='default_new') and ($SSweb_logo!='default_old') )
{
if (file_exists("../$admin_web_directory/images/vicidial_admin_web_logo$SSweb_logo"))
{
$selected_logo = "../$admin_web_directory/images/vicidial_admin_web_logo$SSweb_logo";
}
}
$temp_logo = $selected_logo;
$auth=0;
$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'HCI',1,0);
if ( ($auth_message == 'GOOD') or ($auth_message == '2FA') )
{
$auth=1;
if ($auth_message == '2FA')
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Your session is expired").". "._QXZ("Click here to log in")." .\n";
exit;
}
}
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;
}
# check user permissions
if ($hci_enabled < 1)
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("HCI is not enabled for your user account")."\n";
exit;
}
if ($SShopper_hold_inserts < 1)
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("HCI is not enabled on this system")."\n";
exit;
}
$LOGallowed_campaignsSQL='';
$stmt="SELECT allowed_campaigns from vicidial_user_groups where user_group='$LOGuser_group';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
if ( (!preg_match("/ALL-CAMPAIGNS/i",$row[0])) )
{
$LOGallowed_campaignsSQL = preg_replace('/\s-/i','',$row[0]);
$LOGallowed_campaignsSQL = preg_replace('/\s/i',"','",$LOGallowed_campaignsSQL);
$LOGallowed_campaignsSQL = "and campaign_id IN('$LOGallowed_campaignsSQL')";
}
################################################################################
### BEGIN LOGOUT - agent logout, delete live entry, reset reserved hopper leads
################################################################################
if ( ($stage == 'LOGOUT') and (strlen($campaign_id) > 0) )
{
$stmt="DELETE FROM vicidial_hci_live_agents WHERE user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$stmt="INSERT INTO vicidial_hci_agent_log SET user='$PHP_AUTH_USER',campaign_id='$campaign_id',user_ip='$ip',login_time=NOW(),status='LOGOUT';";
$rslt=mysql_to_mysqli($stmt, $link);
$stmt="SELECT lead_id from vicidial_hci_reserve WHERE user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$vhr_ct++;
}
$vhr_ct=0;
$vh_clear=0;
$vhr_clear=0;
while ($vhr_to_parse > $vhr_ct)
{
$stmt="UPDATE vicidial_hopper SET status='RHOLD',user='' where lead_id='$Elead_id[$vhr_ct]' and status='RQUEUE';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vh_clear = ($vh_clear + $affected_rows);
$stmt="DELETE FROM vicidial_hci_reserve WHERE lead_id='$Elead_id[$vhr_ct]' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vhr_clear = ($vhr_clear + $affected_rows);
$vhr_ct++;
}
$notes = "$campaign_id $vh_clear $vhr_clear";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
}
################################################################################
### END LOGOUT - agent logout, delete live entry, reset reserved hopper leads
################################################################################
################################################################################
### BEGIN chosen_campaign - agent has chosen a campaign to log into, insert the live agent entry and a log entry
################################################################################
if ( ($stage == 'chosen_campaign') and (strlen($campaign_id) > 0) )
{
$valid_campaign=0;
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and active='Y' and hopper_hold_inserts IN('ENABLED','AUTONEXT') $LOGallowed_campaignsSQL;";
$rslt=mysql_to_mysqli($stmt, $link);
$camps_to_parse = mysqli_num_rows($rslt);
if ($camps_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$valid_campaign = $rowx[0];
}
if ($valid_campaign > 0)
{
$autonext_campaign=0;
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and hopper_hold_inserts='AUTONEXT';";
$rslt=mysql_to_mysqli($stmt, $link);
$campANs_to_parse = mysqli_num_rows($rslt);
if ($campANs_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$autonext_campaign = $rowx[0];
}
$stmt="INSERT INTO vicidial_hci_live_agents SET user='$PHP_AUTH_USER',campaign_id='$campaign_id',user_ip='$ip',login_time=NOW(),last_call_time=NOW(),last_update_time=NOW(),status='LOGIN',lead_id=0,phone_number='',random_id=0;";
$rslt=mysql_to_mysqli($stmt, $link);
$stmt="INSERT INTO vicidial_hci_agent_log SET user='$PHP_AUTH_USER',campaign_id='$campaign_id',user_ip='$ip',login_time=NOW(),status='LOGIN';";
$rslt=mysql_to_mysqli($stmt, $link);
$hopper_hold_count=0;
$stmt="SELECT count(*) from vicidial_hopper where campaign_id='$campaign_id' and status='RHOLD' and user='';";
$rslt=mysql_to_mysqli($stmt, $link);
$hop_to_parse = mysqli_num_rows($rslt);
if ($hop_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$hopper_hold_count = $rowx[0];
}
if ($hopper_hold_count > 0)
{
$stmt="UPDATE vicidial_hopper SET user='$PHP_AUTH_USER',status='RQUEUE' WHERE campaign_id='$campaign_id' and status='RHOLD' and user='' order by priority desc,hopper_id limit $batch_size;";
$rslt=mysql_to_mysqli($stmt, $link);
$vh_affected_rows = mysqli_affected_rows($link);
$stmt="SELECT lead_id from vicidial_hopper WHERE user='$PHP_AUTH_USER' and status='RQUEUE' and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$vhr_ct++;
}
$vhr_ct=0;
$vhr_insert=0;
while ($vhr_to_parse > $vhr_ct)
{
$temp_phone='';
$stmt="SELECT phone_number from vicidial_list where lead_id='$Elead_id[$vhr_ct]';";
$rslt=mysql_to_mysqli($stmt, $link);
$vl_to_parse = mysqli_num_rows($rslt);
if ($vl_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$temp_phone = $rowx[0];
}
$stmt="INSERT INTO vicidial_hci_reserve SET user='$PHP_AUTH_USER',lead_id='$Elead_id[$vhr_ct]',phone_number='$temp_phone',reserve_date=NOW(),status='NEW',campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vhr_insert = ($vhr_insert + $affected_rows);
$vhr_ct++;
}
}
$notes = "$campaign_id $ip $vh_affected_rows $vhr_to_parse $vhr_ct $vhr_insert $autonext_campaign";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
}
}
################################################################################
### END chosen_campaign - agent has chosen a campaign to log into, insert the live agent entry and a log entry
################################################################################
################################################################################
### BEGIN switch_campaign - logged-in agent has chosen to switch to a different campaign, insert the live agent entry and a log entry
################################################################################
if ( ($stage == 'switch_campaign') and (strlen($campaign_id) > 0) )
{
$valid_campaign=0;
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and active='Y' and hopper_hold_inserts IN('ENABLED','AUTONEXT') $LOGallowed_campaignsSQL;";
$rslt=mysql_to_mysqli($stmt, $link);
$camps_to_parse = mysqli_num_rows($rslt);
if ($camps_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$valid_campaign = $rowx[0];
}
if ($valid_campaign > 0)
{
$autonext_campaign=0;
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and hopper_hold_inserts='AUTONEXT';";
$rslt=mysql_to_mysqli($stmt, $link);
$campANs_to_parse = mysqli_num_rows($rslt);
if ($campANs_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$autonext_campaign = $rowx[0];
}
$stmt="SELECT campaign_id,status from vicidial_hci_live_agents where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$users_to_parse = mysqli_num_rows($rslt);
if ($users_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$old_campaign_id = $rowx[0];
$VHLAstatus = $rowx[1];
$stmt="UPDATE vicidial_hci_live_agents SET campaign_id='$campaign_id',user_ip='$ip',login_time=NOW(),last_call_time=NOW(),last_update_time=NOW(),status='SWITCH',lead_id=0,phone_number='',random_id=0 WHERE user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$stmt="INSERT INTO vicidial_hci_agent_log SET user='$PHP_AUTH_USER',campaign_id='$campaign_id',user_ip='$ip',login_time=NOW(),status='SWITCH';";
$rslt=mysql_to_mysqli($stmt, $link);
$stmt="SELECT lead_id from vicidial_hci_reserve WHERE user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$vhr_ct++;
}
$vhr_ct=0;
$vh_clear=0;
$vhr_clear=0;
while ($vhr_to_parse > $vhr_ct)
{
$stmt="UPDATE vicidial_hopper SET status='RHOLD',user='' where lead_id='$Elead_id[$vhr_ct]' and status='RQUEUE';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vh_clear = ($vh_clear + $affected_rows);
$stmt="DELETE FROM vicidial_hci_reserve WHERE lead_id='$Elead_id[$vhr_ct]' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vhr_clear = ($vhr_clear + $affected_rows);
$vhr_ct++;
}
$hopper_hold_count=0;
$stmt="SELECT count(*) from vicidial_hopper where campaign_id='$campaign_id' and status='RHOLD' and user='';";
$rslt=mysql_to_mysqli($stmt, $link);
$hop_to_parse = mysqli_num_rows($rslt);
if ($hop_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$hopper_hold_count = $rowx[0];
}
if ($hopper_hold_count > 0)
{
$stmt="UPDATE vicidial_hopper SET user='$PHP_AUTH_USER',status='RQUEUE' WHERE campaign_id='$campaign_id' and status='RHOLD' and user='' order by priority desc,hopper_id limit $batch_size;";
$rslt=mysql_to_mysqli($stmt, $link);
$vh_affected_rows = mysqli_affected_rows($link);
$stmt="SELECT lead_id from vicidial_hopper WHERE user='$PHP_AUTH_USER' and status='RQUEUE' and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$vhr_ct++;
}
$vhr_ct=0;
$vhr_insert=0;
while ($vhr_to_parse > $vhr_ct)
{
$temp_phone='';
$stmt="SELECT phone_number from vicidial_list where lead_id='$Elead_id[$vhr_ct]';";
$rslt=mysql_to_mysqli($stmt, $link);
$vl_to_parse = mysqli_num_rows($rslt);
if ($vl_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$temp_phone = $rowx[0];
}
$stmt="INSERT INTO vicidial_hci_reserve SET user='$PHP_AUTH_USER',lead_id='$Elead_id[$vhr_ct]',phone_number='$temp_phone',reserve_date=NOW(),status='NEW',campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vhr_insert = ($vhr_insert + $affected_rows);
$vhr_ct++;
}
}
$notes = "$campaign_id $old_campaign_id $VHLAstatus $vh_clear $vhr_clear $vh_affected_rows $vhr_insert $autonext_campaign";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
}
else
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Agent not logged in to HCI screen")."\n";
exit;
}
}
else
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("This is not a valid HCI campaign").": $campaign_id \n";
exit;
}
}
################################################################################
### END switch_campaign - logged-in agent has chosen to switch to a different campaign, insert the live agent entry and a log entry
################################################################################
################################################################################
### BEGIN dashboard - display dashboard stats for logged-in campaign
################################################################################
if ($stage == 'dashboard')
{
$stmt="SELECT campaign_id,status from vicidial_hci_live_agents where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$users_to_parse = mysqli_num_rows($rslt);
if ($users_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$campaign_id = $rowx[0];
$VHLAstatus = $rowx[1];
}
else
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Agent not logged in to HCI screen")."\n";
exit;
}
$hopper_ready=0;
$stmt="SELECT count(*) from vicidial_hopper WHERE status='READY' and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$hop_to_parse = mysqli_num_rows($rslt);
if ($hop_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$hopper_ready = $rowx[0];
}
$hopper_hold=0;
$stmt="SELECT count(*) from vicidial_hopper WHERE status='RHOLD' and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$hop_to_parse = mysqli_num_rows($rslt);
if ($hop_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$hopper_hold = $rowx[0];
}
$agents_ready=0;
$stmt="SELECT count(*) from vicidial_live_agents where status IN ('READY','CLOSER') and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vla_to_parse = mysqli_num_rows($rslt);
if ($vla_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$agents_ready = $rowx[0];
}
$calls_out=0;
$stmt="SELECT count(*) from vicidial_auto_calls where campaign_id='$campaign_id' and status = 'SENT';";
$rslt=mysql_to_mysqli($stmt, $link);
$vla_to_parse = mysqli_num_rows($rslt);
if ($vla_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$calls_out = $rowx[0];
}
$drops_today=0;
$drops_answers_pct=0;
$stmt="SELECT drops_today,drops_answers_today_pct from vicidial_campaign_stats where campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vla_to_parse = mysqli_num_rows($rslt);
if ($vla_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$drops_today = $rowx[0];
$drops_answers_pct = $rowx[1];
}
$camp_dial_method='';
$camp_dial_level=0;
$camp_adapt_level=0;
$max_dial_level=0;
$stmt="SELECT dial_method,auto_dial_level,adaptive_maximum_level from vicidial_campaigns where campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vla_to_parse = mysqli_num_rows($rslt);
if ($vla_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$camp_dial_method = $rowx[0];
$camp_dial_level = $rowx[1];
$camp_adapt_level = $rowx[2];
if (preg_match("/ADAPT/",$camp_dial_method))
{$max_dial_level = $camp_adapt_level;}
else
{$max_dial_level = $camp_dial_level;}
}
$calls_offset = (($agents_ready * $max_dial_level) - $calls_out);
$calls_offset_color="fa8073";
if ($calls_offset > -30)
{ $calls_offset_color="bbffb8";}
if ($calls_offset > 30)
{ $calls_offset_color="edbb47";}
echo "
";
echo "";
echo ""._QXZ("Dashboard").": ";
echo " ";
echo "$NOW_TIME ";
echo "
\n ";
echo "";
echo "\n";
echo "";
echo " ";
echo ""._QXZ("Calls in Progress")." ";
echo " ";
echo " ";
echo ""._QXZ("Calls on Hold")." ";
echo " ";
echo " ";
echo ""._QXZ("Records Remaining")." ";
echo " ";
echo "";
echo "$calls_out ";
echo "$hopper_hold ";
echo "$hopper_ready ";
echo " ";
echo " ";
echo "";
echo " ";
echo ""._QXZ("Agents Ready")." ";
echo " ";
echo " ";
echo ""._QXZ("Calls Offset")." ";
echo " ";
echo " ";
echo ""._QXZ("Drop Rate")." ";
echo " ";
echo "";
echo "$agents_ready ";
echo "$calls_offset ";
echo "$drops_answers_pct% ";
echo " ";
echo "
";
echo " ";
$notes = "$campaign_id $calls_out $hopper_hold $hopper_ready $agents_ready $calls_offset $drops_answers_pct";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
exit;
}
################################################################################
### END dashboard - display dashboard stats for logged-in campaign
################################################################################
################################################################################
### BEGIN lead_display - display reserved hold hopper leads for this agent, to be confirmed
################################################################################
if ($stage == 'lead_display')
{
$stmt="SELECT campaign_id,status from vicidial_hci_live_agents where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$users_to_parse = mysqli_num_rows($rslt);
if ($users_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$campaign_id = $rowx[0];
$VHLAstatus = $rowx[1];
}
else
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Agent not logged in to HCI screen")."\n";
exit;
}
$reserved_ct=0;
$stmt="SELECT count(*) from vicidial_hci_reserve where campaign_id='$campaign_id' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$camps_to_parse = mysqli_num_rows($rslt);
if ($camps_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$reserved_ct = $rowx[0];
}
if ($reserved_ct < $batch_size)
{
$reserve_more_hopper_leads = ($batch_size - $reserved_ct);
if ($reserve_more_hopper_leads > 0)
{
$hopper_hold_count=0;
$stmt="SELECT count(*) from vicidial_hopper where campaign_id='$campaign_id' and status='RHOLD' and user='';";
$rslt=mysql_to_mysqli($stmt, $link);
$hop_to_parse = mysqli_num_rows($rslt);
if ($hop_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$hopper_hold_count = $rowx[0];
}
if ($hopper_hold_count > 0)
{
$stmt="UPDATE vicidial_hopper SET user='$PHP_AUTH_USER',status='RQUEUE' WHERE campaign_id='$campaign_id' and status='RHOLD' and user='' order by priority desc,hopper_id limit $reserve_more_hopper_leads;";
$rslt=mysql_to_mysqli($stmt, $link);
$vh_affected_rows = mysqli_affected_rows($link);
$stmt="SELECT lead_id from vicidial_hopper WHERE user='$PHP_AUTH_USER' and status='RQUEUE' and campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$vhr_ct++;
}
$vhr_ct=0;
$vhr_insert=0;
while ($vhr_to_parse > $vhr_ct)
{
$already_reserved=0;
$stmt="SELECT count(*) from vicidial_hci_reserve where lead_id='$Elead_id[$vhr_ct]';";
$rslt=mysql_to_mysqli($stmt, $link);
$vt_to_parse = mysqli_num_rows($rslt);
if ($vt_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$already_reserved = $rowx[0];
}
if ($already_reserved < 1)
{
$temp_phone='';
$stmt="SELECT phone_number from vicidial_list where lead_id='$Elead_id[$vhr_ct]';";
$rslt=mysql_to_mysqli($stmt, $link);
$vl_to_parse = mysqli_num_rows($rslt);
if ($vl_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$temp_phone = $rowx[0];
}
$stmt="INSERT INTO vicidial_hci_reserve SET user='$PHP_AUTH_USER',lead_id='$Elead_id[$vhr_ct]',phone_number='$temp_phone',reserve_date=NOW(),status='NEW',campaign_id='$campaign_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$affected_rows = mysqli_affected_rows($link);
$vhr_insert = ($vhr_insert + $affected_rows);
}
$vhr_ct++;
}
}
$stage = 'reserve_more_leads';
$notes = "$campaign_id $reserve_more_hopper_leads $vh_clear $hopper_hold_count $vh_affected_rows $vhr_insert";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
}
}
$reserved_ct=0;
$stmt="SELECT count(*) from vicidial_hci_reserve where campaign_id='$campaign_id' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$camps_to_parse = mysqli_num_rows($rslt);
if ($camps_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$reserved_ct = $rowx[0];
}
if ($reserved_ct < 1)
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("There are no leads available")."\n";
exit;
}
else
{
$lead_phone_list='';
$stmt="SELECT lead_id,phone_number from vicidial_hci_reserve WHERE campaign_id='$campaign_id' and user='$PHP_AUTH_USER' order by reserve_date,lead_id;";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
$Elead_id = array();
$Ephone = array();
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$rowx=mysqli_fetch_row($rslt);
$Elead_id[$vhr_ct] = $rowx[0];
$Ephone[$vhr_ct] = $rowx[1];
$lead_phone_list .= $vhr_ct."_".$rowx[0]."_".$rowx[1]."|";
$vhr_ct++;
}
echo "\n";
echo ""._QXZ("Call Confirmation").": ";
$row_ct=0;
$vhr_ct=0;
while ($vhr_to_parse > $vhr_ct)
{
$USnpa = substr($Ephone[$vhr_ct], 0, 3);
$USnxx = substr($Ephone[$vhr_ct], 3, 3);
$USxxxx = substr($Ephone[$vhr_ct], 6, 4);
$temp_phone = "($USnpa) ".$USnxx.'-'.$USxxxx;
# echo "$Elead_id[$vhr_ct] - $Ephone[$vhr_ct] - $temp_phone ";
# echo " $temp_phone
\n";
echo "";
# if ($row_ct >= 3) {echo " "; $row_ct=0;}
echo " $temp_phone
";
$row_ct++;
$vhr_ct++;
}
echo "
";
}
exit;
}
################################################################################
### END lead_display - display reserved hold hopper leads for this agent, to be confirmed
################################################################################
################################################################################
### BEGIN activate_lead - set hopper lead to READY and remove entry from reserved hopper leads for this user
################################################################################
if ( ($stage == 'activate_lead') and (strlen($lead_id) > 0) )
{
$campaign_id='';
$phone_number='';
$stmt="SELECT campaign_id,phone_number from vicidial_hci_reserve WHERE user='$PHP_AUTH_USER' and lead_id='$lead_id';";
$rslt=mysql_to_mysqli($stmt, $link);
$vhr_to_parse = mysqli_num_rows($rslt);
if ($vhr_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$campaign_id = $rowx[0];
$phone_number = $rowx[1];
}
$vhr_ct=0;
$vh_clear=0;
$vhr_clear=0;
if (strlen($phone_number) > 0)
{
$stmt="UPDATE vicidial_hopper SET status='READY',user='' where lead_id='$lead_id' and status='RQUEUE' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$VHaffected_rows = mysqli_affected_rows($link);
if ($VHaffected_rows > 0)
{
$stmt="DELETE FROM vicidial_hci_reserve WHERE lead_id='$lead_id' and user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$VHRaffected_rows = mysqli_affected_rows($link);
$stmt="INSERT INTO vicidial_hci_log SET lead_id='$lead_id',user='$PHP_AUTH_USER',phone_number='$phone_number',campaign_id='$campaign_id',call_date=NOW(),user_ip='$ip',status='CONFIRMED';";
$rslt=mysql_to_mysqli($stmt, $link);
$VHLaffected_rows = mysqli_affected_rows($link);
$stmt="INSERT INTO hci_logs SET lead_id='$lead_id',user='$PHP_AUTH_USER',campaign_id='$campaign_id',date=NOW();";
$rslt=mysql_to_mysqli($stmt, $link);
$HLaffected_rows = mysqli_affected_rows($link);
}
}
$notes = "$phone_number $VHaffected_rows $VHRaffected_rows $VHLaffected_rows $HLaffected_rows";
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
exit;
}
################################################################################
### BEGIN activate_lead - set hopper lead to READY and remove entry from reserved hopper leads for this user
################################################################################
# Called AJAX functions go here
# BEGIN building main screen
$stmt="SELECT campaign_id,status from vicidial_hci_live_agents where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$users_to_parse = mysqli_num_rows($rslt);
if ($users_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$campaign_id = $rowx[0];
$VHLAstatus = $rowx[1];
}
# get list of HCI-enabled campaigns for pull-down lists
$camp_panel_code='';
$camp_form_code = "\n";
$camp_form_code .= "-- "._QXZ("Select a Campaign")." -- \n";
$stmt="SELECT campaign_id,campaign_name,hopper_hold_inserts from vicidial_campaigns where active='Y' and hopper_hold_inserts IN('ENABLED','AUTONEXT') $LOGallowed_campaignsSQL order by campaign_id;";
$rslt=mysql_to_mysqli($stmt, $link);
$camps_to_print = mysqli_num_rows($rslt);
$o=0;
while ($camps_to_print > $o)
{
$rowx=mysqli_fetch_row($rslt);
$camp_form_code .= "$rowx[0] - $rowx[1] \n";
$camp_panel_code .= "";
if ($campaign_id == $rowx[0])
{
$camp_panel_code .= " * $rowx[0] - $rowx[1] ";
}
else
{
$camp_panel_code .= " $rowx[0] - $rowx[1] ";
}
$camp_panel_code .= " ";
$o++;
}
$camp_panel_code .= "
";
$camp_form_code .= "\n";
if ($users_to_parse < 1)
{
# choose a campaign screen
?>
\n";
echo "\n";
echo "\n\n";
echo "\n\n";
echo " \n\n";
$stage='choose_campaign';
$notes='';
vicidial_ajax_log($NOW_TIME,$startMS,$link,$stage,$php_script,$PHP_AUTH_USER,$notes,$lead_id,$session_name,$stmt);
exit;
}
else
{
# See if campaign is set to AUTONEXT, and confirm system settings and user setting allow for that
$autonext_campaign=0;
$stmt="SELECT count(*) from vicidial_campaigns where campaign_id='$campaign_id' and hopper_hold_inserts='AUTONEXT';";
$rslt=mysql_to_mysqli($stmt, $link);
$campANs_to_parse = mysqli_num_rows($rslt);
if ($campANs_to_parse > 0)
{
$rowx=mysqli_fetch_row($rslt);
$autonext_campaign = $rowx[0];
}
if ( ($SShopper_hold_inserts < 2) and ($autonext_campaign > 0) )
{$autonext_campaign=0;}
if ( ($hci_enabled < 2) and ($autonext_campaign > 0) )
{$autonext_campaign=0;}
if ($autonext_campaign > 0)
{
$batch_size = ($batch_size * 3);
$refresh_sec = ($refresh_sec / 2);
}
}
?>
\n";
echo " ";
echo " \n";
echo "\n";
$ENDtime = date("U");
$RUNtime = ($ENDtime - $STARTtime);
echo "\n\n\n \n\n";
echo "";
?>
" height="206px" width="206px" alt="" />
" alt="alert" border="0">