/www/agc/vdc_db_query.php
https://github.com/h4ck3rm1k3/vicidial-asterisk-gui · PHP · 4409 lines · 3694 code · 293 blank · 422 comment · 876 complexity · 6ec49a8651378b68e87c50a99d035716 MD5 · raw file
Large files are truncated click here to view the full file
- <?php
- # vdc_db_query.php
- #
- # Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
- #
- # This script is designed purely to send whether the meetme conference has live channels connected and which they are
- # This script depends on the server_ip being sent and also needs to have a valid user/pass from the vicidial_users table
- #
- # required variables:
- # - $server_ip
- # - $session_name
- # - $user
- # - $pass
- # optional variables:
- # - $format - ('text','debug')
- # - $ACTION - ('regCLOSER','manDiaLnextCALL','manDiaLskip','manDiaLonly','manDiaLlookCALL','manDiaLlogCALL','userLOGout','updateDISPO','VDADpause','VDADready','VDADcheckINCOMING','UpdatEFavoritEs','CalLBacKLisT','CalLBacKCounT','PauseCodeSubmit','LogiNCamPaigns','alt_phone_change','AlertControl')
- # - $stage - ('start','finish','lookup','new')
- # - $closer_choice - ('CL_TESTCAMP_L CL_OUT123_L -')
- # - $conf_exten - ('8600011',...)
- # - $exten - ('123test',...)
- # - $ext_context - ('default','demo',...)
- # - $ext_priority - ('1','2',...)
- # - $campaign - ('testcamp',...)
- # - $dial_timeout - ('60','26',...)
- # - $dial_prefix - ('9','8',...)
- # - $campaign_cid - ('3125551212','0000000000',...)
- # - $MDnextCID - ('M06301413000000002',...)
- # - $uniqueid - ('1120232758.2406800',...)
- # - $lead_id - ('36524',...)
- # - $list_id - ('101','123456',...)
- # - $length_in_sec - ('12',...)
- # - $phone_code - ('1',...)
- # - $phone_number - ('3125551212',...)
- # - $channel - ('Zap/12-1',...)
- # - $start_epoch - ('1120236911',...)
- # - $vendor_lead_code - ('1234test',...)
- # - $title - ('Mr.',...)
- # - $first_name - ('Bob',...)
- # - $middle_initial - ('L',...)
- # - $last_name - ('Wilson',...)
- # - $address1 - ('1324 Main St.',...)
- # - $address2 - ('Apt. 12',...)
- # - $address3 - ('co Robert Wilson',...)
- # - $city - ('Chicago',...)
- # - $state - ('IL',...)
- # - $province - ('NA',...)
- # - $postal_code - ('60054',...)
- # - $country_code - ('USA',...)
- # - $gender - ('M',...)
- # - $date_of_birth - ('1970-01-01',...)
- # - $alt_phone - ('3125551213',...)
- # - $email - ('bob@bob.com',...)
- # - $security_phrase - ('Hello',...)
- # - $comments - ('Good Customer',...)
- # - $auto_dial_level - ('0','1','1.2',...)
- # - $VDstop_rec_after_each_call - ('0','1')
- # - $conf_silent_prefix - ('7','8','5',...)
- # - $extension - ('123','user123','25-1',...)
- # - $protocol - ('Zap','SIP','IAX2',...)
- # - $user_abb - ('1234','6666',...)
- # - $preview - ('YES','NO',...)
- # - $called_count - ('0','1','2',...)
- # - $agent_log_id - ('123456',...)
- # - $agent_log - ('NO',...)
- # - $favorites_list - (",'cc160','cc100'",...)
- # - $CallBackDatETimE - ('2006-04-21 14:30:00',...)
- # - $recipient - ('ANYONE,'USERONLY')
- # - $callback_id - ('12345','12346',...)
- # - $use_internal_dnc - ('Y','N')
- # - $use_campaign_dnc - ('Y','N')
- # - $omit_phone_code - ('Y','N')
- # - $no_delete_sessions - ('0','1')
- # - $LogouTKicKAlL - ('0','1');
- # - $closer_blended = ('0','1');
- # - $inOUT = ('IN','OUT');
- # - $manual_dial_filter = ('NONE','CAMPLISTS','DNC','CAMPLISTS_DNC')
- # - $agentchannel = ('Zap/1-1','SIP/testing-6ry4i3',...)
- # - $conf_dialed = ('0','1')
- # - $leaving_threeway = ('0','1')
- # - $blind_transfer = ('0','1')
- # - $usegroupalias - ('0','1')
- # - $account - ('DEFAULT',...)
- # - $agent_dialed_number - ('1','')
- # - $agent_dialed_type - ('MANUAL_OVERRIDE','MANUAL_DIALNOW','MANUAL_PREVIEW',...)
- # - $wrapup - ('WRAPUP','')
- # - $vtiger_callback_id - ('16534'...)
- #
- # CHANGELOG:
- # 50629-1044 - First build of script
- # 50630-1422 - Added manual dial action and MD channel lookup
- # 50701-1451 - Added dial log for start and end of vicidial calls
- # 50705-1239 - Added call disposition update
- # 50804-1627 - Fixed updateDispo to update vicidial_log entry
- # 50816-1605 - Added VDADpause/ready for auto dialing
- # 50816-1811 - Added basic autodial call pickup functions
- # 50817-1005 - Altered logging functions to accomodate auto_dialing
- # 50818-1305 - Added stop-all-recordings-after-each-vicidial-call option
- # 50818-1411 - Added hangup of agent phone after Logout
- # 50901-1315 - Fixed CLOSER IN-GROUP Web Form bug
- # 50902-1507 - Fixed CLOSER log length_in_sec bug
- # 50902-1730 - Added functions for manual preview dialing and revert
- # 50913-1214 - Added agent random update to leadupdate
- # 51020-1421 - Added agent_log_id framework for detailed agent activity logging
- # 51021-1717 - Allows for multi-line comments (changes \n to !N in database)
- # 51111-1046 - Added vicidial_agent_log lead_id earlier for manual dial
- # 51121-1445 - Altered echo statements for several small PHP speed optimizations
- # 51122-1328 - Fixed UserLogout issue not removing conference reservation
- # 51129-1012 - Added ability to accept calls from other VICIDIAL servers
- # 51129-1729 - Changed manual dial to use the '/n' flag for calls
- # 51221-1154 - Added SCRIPT id lookup and sending to vicidial.php for display
- # 60105-1059 - Added Updating of astguiclient favorites in the DB
- # 60208-1617 - Added dtmf buttons output per call
- # 60213-1521 - Added closer_campaigns update to vicidial_users
- # 60215-1036 - Added Callback date-time entry into vicidial_callbacks table
- # 60413-1541 - Added USERONLY Callback listings output - CalLBacKLisT
- # - Added USERONLY Callback count output - CalLBacKCounT
- # 60414-1140 - Added Callback lead lookup for manual dialing
- # 60419-1517 - After CALLBK is sent to agent, update callback record to INACTIVE
- # 60421-1419 - Check GET/POST vars lines with isset to not trigger PHP NOTICES
- # 60427-1236 - Fixed closer_choice error for CLOSER campaigns
- # 60609-1148 - Added ability to check for manual dial numbers in DNC
- # 60619-1117 - Added variable filters to close security holes for login form
- # 60623-1414 - Fixed variable filter for phone_code and fixed manual dial logic
- # 60821-1600 - Added ability to omit the phone code on vicidial lead dialing
- # 60821-1647 - Added ability to not delete sessions at logout
- # 60906-1124 - Added lookup and sending of callback data for CALLBK calls
- # 61128-2229 - Added vicidial_live_agents and vicidial_auto_calls manual dial entries
- # 70111-1600 - Added ability to use BLEND/INBND/*_C/*_B/*_I as closer campaigns
- # 70115-1733 - Added alt_dial functionality in auto-dial modes
- # 70118-1501 - Added user_group to vicidial_log,_agent_log,_closer_log,_callbacks
- # 70123-1357 - Fixed bug that would not update vicidial_closer_log status to dispo
- # 70202-1438 - Added pause code submit function
- # 70203-0930 - Added dialed_number to lead info output
- # 70203-1030 - Added dialed_label to lead info output
- # 70206-1126 - Added INBOUND status for inbound/closer calls in vicidial_live_agents
- # 70212-1253 - Fixed small issue with CXFER
- # 70213-1431 - Added QueueMetrics PAUSE/UNPAUSE/AGENTLOGIN/AGENTLOGOFF actions
- # 70214-1231 - Added queuemetrics_log_id field for server_id in queue_log
- # 70215-1210 - Added queuemetrics COMPLETEAGENT action
- # 70216-1051 - Fixed double call complete queuemetrics logging
- # 70222-1616 - Changed queue_log PAUSE/UNPAUSE to PAUSEALL/UNPAUSEALL
- # 70309-1034 - Allow amphersands and questions marks in comments to pass through
- # 70313-1052 - Allow pound signs(hash) in comments to pass through
- # 70319-1544 - Added agent disable update customer data function
- # 70322-1545 - Added sipsak display ability
- # 70413-1253 - Fixed bug for outbound call time in CLOSER-type blended campaigns
- # 70424-1100 - Fixed bug for fronter/closer calls that would delete vdac records
- # 70802-1729 - Fixed bugs with pause_sec and wait_sec under certain call handling
- # 70828-1443 - Added source_id to output of SCRIPTtab-IFRAME and WEBFORM
- # 71029-1855 - removed campaign_id naming restrictions for CLOSER-type campaigns
- # 71030-2047 - added hopper priority for auto alt dial entries
- # 71116-1011 - added calls_today count updating of the vicidial_live_agents upon INCALL
- # 71120-1520 - added LogiNCamPaigns to show only allowed campaigns for agents upon login
- # 71125-1751 - Added inbound-group default inbound group sending to vicidial.php
- # 71129-2025 - restricted callbacks count and list to campaign only
- # 71223-0318 - changed logging of closer calls
- # 71226-1117 - added option to kick all calls from conference upon logout
- # 80116-1032 - added user_closer_log logging in regCLOSER
- # 80125-1213 - fixed vicidial_log bug when call is from closer
- # 80317-2051 - Added in-group recording settings
- # 80402-0121 - Fixes for manual dial transfers on some systems, removed /n persist flag
- # 80424-0442 - Added non_latin lookup from system_settings
- # 80430-1006 - Added term_reason for vicidial_log and vicidial_closer_log
- # 80430-1957 - Changed to leave lead_id in vicidial_live_agents record until after dispo
- # 80630-2153 - Added queue_log logging for Manual dial calls
- # 80703-0139 - Added alter customer phone permissions
- # 80707-2325 - Added vicidial_id to recording_log for tracking of vicidial or closer log to recording
- # 80713-0624 - Added vicidial_list.last_local_call_time field
- # 80717-1604 - Modified logging function to use inOUT to determine call direction and place to log
- # 80719-1147 - Changed recording conf prefix
- # 80815-1019 - Added manual dial list restriction option
- # 80831-0545 - Added extended alt dial number info display support
- # 80909-1710 - Added support for campaign-specific DNC lists
- # 81010-1048 - Added support for hangup of all channels except for agent channel after attempting a 3way call
- # 81011-1404 - Fixed bugs in leave3way when transferring a manual dial call
- # 81020-1459 - Fixed bugs in queue_log logging
- # 81104-0134 - Added mysql error logging capability
- # 81104-1617 - Added multi-retry for some vicidial_live_agents table MySQL queries
- # 81106-0410 - Added force_timeclock_login option to LoginCampaigns function
- # 81107-0424 - Added carryover of script and presets for in-group calls from campaign settings
- # 81110-0058 - Changed Pause time to start new vicidial_agent_log on every pause
- # 81110-1512 - Added hangup_all_non_reserved to fix non-Hangup bug
- # 81111-1630 - Added another hangup fix for non-hangup
- # 81114-0126 - More vicidial_agent_log bug fixes
- # 81119-1809 - webform backslash fix
- # 81124-2212 - Fixes blind transfer bug
- # 81126-1522 - Fixed callback comments bug
- # 81211-0420 - Fixed Manual dial agent_log bug
- # 90120-1718 - Added external pause and dial option
- # 90126-1759 - Fixed QM section that wasn't qualified and added agent alert option
- # 90128-0231 - Added vendor_lead_code to manual dial lead lookup
- # 90304-1335 - Added support for group aliases and agent-specific variables for campaigns and in-groups
- # 90305-1041 - Added agent_dialed_number and type for user_call_log feature
- # 90307-1735 - Added Shift enforcement and manager override features
- # 90320-0306 - Fixed agent log bug when using wrapup time
- # 90323-2013 - Added function to put phone numbers in the DNC lists if they were set to status type dnc=Y
- # 90324-1316 - Added functions to log calls to Vtiger accounts and update status to siccode
- # 90327-1348 - Changed Vtiger status populate to use status name
- # 90408-0021 - Added API vtiger specific callback activity record ability
- # 90508-0726 - Changed to PHP long tags
- #
- $version = '2.2.0-109';
- $build = '90508-0726';
- $mel=1; # Mysql Error Log enabled = 1
- $mysql_log_count=212;
- $one_mysql_log=0;
- require("dbconnect.php");
- ### If you have globals turned off uncomment these lines
- 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["server_ip"])) {$server_ip=$_GET["server_ip"];}
- elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];}
- if (isset($_GET["session_name"])) {$session_name=$_GET["session_name"];}
- elseif (isset($_POST["session_name"])) {$session_name=$_POST["session_name"];}
- if (isset($_GET["format"])) {$format=$_GET["format"];}
- elseif (isset($_POST["format"])) {$format=$_POST["format"];}
- if (isset($_GET["ACTION"])) {$ACTION=$_GET["ACTION"];}
- elseif (isset($_POST["ACTION"])) {$ACTION=$_POST["ACTION"];}
- if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
- elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
- if (isset($_GET["closer_choice"])) {$closer_choice=$_GET["closer_choice"];}
- elseif (isset($_POST["closer_choice"])) {$closer_choice=$_POST["closer_choice"];}
- if (isset($_GET["conf_exten"])) {$conf_exten=$_GET["conf_exten"];}
- elseif (isset($_POST["conf_exten"])) {$conf_exten=$_POST["conf_exten"];}
- if (isset($_GET["exten"])) {$exten=$_GET["exten"];}
- elseif (isset($_POST["exten"])) {$exten=$_POST["exten"];}
- if (isset($_GET["ext_context"])) {$ext_context=$_GET["ext_context"];}
- elseif (isset($_POST["ext_context"])) {$ext_context=$_POST["ext_context"];}
- if (isset($_GET["ext_priority"])) {$ext_priority=$_GET["ext_priority"];}
- elseif (isset($_POST["ext_priority"])) {$ext_priority=$_POST["ext_priority"];}
- if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];}
- elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];}
- if (isset($_GET["dial_timeout"])) {$dial_timeout=$_GET["dial_timeout"];}
- elseif (isset($_POST["dial_timeout"])) {$dial_timeout=$_POST["dial_timeout"];}
- if (isset($_GET["dial_prefix"])) {$dial_prefix=$_GET["dial_prefix"];}
- elseif (isset($_POST["dial_prefix"])) {$dial_prefix=$_POST["dial_prefix"];}
- if (isset($_GET["campaign_cid"])) {$campaign_cid=$_GET["campaign_cid"];}
- elseif (isset($_POST["campaign_cid"])) {$campaign_cid=$_POST["campaign_cid"];}
- if (isset($_GET["MDnextCID"])) {$MDnextCID=$_GET["MDnextCID"];}
- elseif (isset($_POST["MDnextCID"])) {$MDnextCID=$_POST["MDnextCID"];}
- if (isset($_GET["uniqueid"])) {$uniqueid=$_GET["uniqueid"];}
- elseif (isset($_POST["uniqueid"])) {$uniqueid=$_POST["uniqueid"];}
- if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
- elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];}
- if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
- elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
- if (isset($_GET["length_in_sec"])) {$length_in_sec=$_GET["length_in_sec"];}
- elseif (isset($_POST["length_in_sec"])) {$length_in_sec=$_POST["length_in_sec"];}
- if (isset($_GET["phone_code"])) {$phone_code=$_GET["phone_code"];}
- elseif (isset($_POST["phone_code"])) {$phone_code=$_POST["phone_code"];}
- if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];}
- elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];}
- if (isset($_GET["channel"])) {$channel=$_GET["channel"];}
- elseif (isset($_POST["channel"])) {$channel=$_POST["channel"];}
- if (isset($_GET["start_epoch"])) {$start_epoch=$_GET["start_epoch"];}
- elseif (isset($_POST["start_epoch"])) {$start_epoch=$_POST["start_epoch"];}
- if (isset($_GET["dispo_choice"])) {$dispo_choice=$_GET["dispo_choice"];}
- elseif (isset($_POST["dispo_choice"])) {$dispo_choice=$_POST["dispo_choice"];}
- if (isset($_GET["vendor_lead_code"])) {$vendor_lead_code=$_GET["vendor_lead_code"];}
- elseif (isset($_POST["vendor_lead_code"])) {$vendor_lead_code=$_POST["vendor_lead_code"];}
- if (isset($_GET["title"])) {$title=$_GET["title"];}
- elseif (isset($_POST["title"])) {$title=$_POST["title"];}
- if (isset($_GET["first_name"])) {$first_name=$_GET["first_name"];}
- elseif (isset($_POST["first_name"])) {$first_name=$_POST["first_name"];}
- if (isset($_GET["middle_initial"])) {$middle_initial=$_GET["middle_initial"];}
- elseif (isset($_POST["middle_initial"])) {$middle_initial=$_POST["middle_initial"];}
- if (isset($_GET["last_name"])) {$last_name=$_GET["last_name"];}
- elseif (isset($_POST["last_name"])) {$last_name=$_POST["last_name"];}
- if (isset($_GET["address1"])) {$address1=$_GET["address1"];}
- elseif (isset($_POST["address1"])) {$address1=$_POST["address1"];}
- if (isset($_GET["address2"])) {$address2=$_GET["address2"];}
- elseif (isset($_POST["address2"])) {$address2=$_POST["address2"];}
- if (isset($_GET["address3"])) {$address3=$_GET["address3"];}
- elseif (isset($_POST["address3"])) {$address3=$_POST["address3"];}
- if (isset($_GET["city"])) {$city=$_GET["city"];}
- elseif (isset($_POST["city"])) {$city=$_POST["city"];}
- if (isset($_GET["state"])) {$state=$_GET["state"];}
- elseif (isset($_POST["state"])) {$state=$_POST["state"];}
- if (isset($_GET["province"])) {$province=$_GET["province"];}
- elseif (isset($_POST["province"])) {$province=$_POST["province"];}
- if (isset($_GET["postal_code"])) {$postal_code=$_GET["postal_code"];}
- elseif (isset($_POST["postal_code"])) {$postal_code=$_POST["postal_code"];}
- if (isset($_GET["country_code"])) {$country_code=$_GET["country_code"];}
- elseif (isset($_POST["country_code"])) {$country_code=$_POST["country_code"];}
- if (isset($_GET["gender"])) {$gender=$_GET["gender"];}
- elseif (isset($_POST["gender"])) {$gender=$_POST["gender"];}
- if (isset($_GET["date_of_birth"])) {$date_of_birth=$_GET["date_of_birth"];}
- elseif (isset($_POST["date_of_birth"])) {$date_of_birth=$_POST["date_of_birth"];}
- if (isset($_GET["alt_phone"])) {$alt_phone=$_GET["alt_phone"];}
- elseif (isset($_POST["alt_phone"])) {$alt_phone=$_POST["alt_phone"];}
- if (isset($_GET["email"])) {$email=$_GET["email"];}
- elseif (isset($_POST["email"])) {$email=$_POST["email"];}
- if (isset($_GET["security_phrase"])) {$security_phrase=$_GET["security_phrase"];}
- elseif (isset($_POST["security_phrase"])) {$security_phrase=$_POST["security_phrase"];}
- if (isset($_GET["comments"])) {$comments=$_GET["comments"];}
- elseif (isset($_POST["comments"])) {$comments=$_POST["comments"];}
- if (isset($_GET["auto_dial_level"])) {$auto_dial_level=$_GET["auto_dial_level"];}
- elseif (isset($_POST["auto_dial_level"])) {$auto_dial_level=$_POST["auto_dial_level"];}
- if (isset($_GET["VDstop_rec_after_each_call"])) {$VDstop_rec_after_each_call=$_GET["VDstop_rec_after_each_call"];}
- elseif (isset($_POST["VDstop_rec_after_each_call"])) {$VDstop_rec_after_each_call=$_POST["VDstop_rec_after_each_call"];}
- if (isset($_GET["conf_silent_prefix"])) {$conf_silent_prefix=$_GET["conf_silent_prefix"];}
- elseif (isset($_POST["conf_silent_prefix"])) {$conf_silent_prefix=$_POST["conf_silent_prefix"];}
- if (isset($_GET["extension"])) {$extension=$_GET["extension"];}
- elseif (isset($_POST["extension"])) {$extension=$_POST["extension"];}
- if (isset($_GET["protocol"])) {$protocol=$_GET["protocol"];}
- elseif (isset($_POST["protocol"])) {$protocol=$_POST["protocol"];}
- if (isset($_GET["user_abb"])) {$user_abb=$_GET["user_abb"];}
- elseif (isset($_POST["user_abb"])) {$user_abb=$_POST["user_abb"];}
- if (isset($_GET["preview"])) {$preview=$_GET["preview"];}
- elseif (isset($_POST["preview"])) {$preview=$_POST["preview"];}
- if (isset($_GET["called_count"])) {$called_count=$_GET["called_count"];}
- elseif (isset($_POST["called_count"])) {$called_count=$_POST["called_count"];}
- if (isset($_GET["agent_log_id"])) {$agent_log_id=$_GET["agent_log_id"];}
- elseif (isset($_POST["agent_log_id"])) {$agent_log_id=$_POST["agent_log_id"];}
- if (isset($_GET["agent_log"])) {$agent_log=$_GET["agent_log"];}
- elseif (isset($_POST["agent_log"])) {$agent_log=$_POST["agent_log"];}
- if (isset($_GET["favorites_list"])) {$favorites_list=$_GET["favorites_list"];}
- elseif (isset($_POST["favorites_list"])) {$favorites_list=$_POST["favorites_list"];}
- if (isset($_GET["CallBackDatETimE"])) {$CallBackDatETimE=$_GET["CallBackDatETimE"];}
- elseif (isset($_POST["CallBackDatETimE"])) {$CallBackDatETimE=$_POST["CallBackDatETimE"];}
- if (isset($_GET["recipient"])) {$recipient=$_GET["recipient"];}
- elseif (isset($_POST["recipient"])) {$recipient=$_POST["recipient"];}
- if (isset($_GET["callback_id"])) {$callback_id=$_GET["callback_id"];}
- elseif (isset($_POST["callback_id"])) {$callback_id=$_POST["callback_id"];}
- if (isset($_GET["use_internal_dnc"])) {$use_internal_dnc=$_GET["use_internal_dnc"];}
- elseif (isset($_POST["use_internal_dnc"])) {$use_internal_dnc=$_POST["use_internal_dnc"];}
- if (isset($_GET["use_campaign_dnc"])) {$use_campaign_dnc=$_GET["use_campaign_dnc"];}
- elseif (isset($_POST["use_campaign_dnc"])) {$use_campaign_dnc=$_POST["use_campaign_dnc"];}
- if (isset($_GET["omit_phone_code"])) {$omit_phone_code=$_GET["omit_phone_code"];}
- elseif (isset($_POST["omit_phone_code"])) {$omit_phone_code=$_POST["omit_phone_code"];}
- if (isset($_GET["phone_ip"])) {$phone_ip=$_GET["phone_ip"];}
- elseif (isset($_POST["phone_ip"])) {$phone_ip=$_POST["phone_ip"];}
- if (isset($_GET["enable_sipsak_messages"])) {$enable_sipsak_messages=$_GET["enable_sipsak_messages"];}
- elseif (isset($_POST["enable_sipsak_messages"])) {$enable_sipsak_messages=$_POST["enable_sipsak_messages"];}
- if (isset($_GET["status"])) {$status=$_GET["status"];}
- elseif (isset($_POST["status"])) {$status=$_POST["status"];}
- if (isset($_GET["LogouTKicKAlL"])) {$LogouTKicKAlL=$_GET["LogouTKicKAlL"];}
- elseif (isset($_POST["LogouTKicKAlL"])) {$LogouTKicKAlL=$_POST["LogouTKicKAlL"];}
- if (isset($_GET["closer_blended"])) {$closer_blended=$_GET["closer_blended"];}
- elseif (isset($_POST["closer_blended"])) {$closer_blended=$_POST["closer_blended"];}
- if (isset($_GET["inOUT"])) {$inOUT=$_GET["inOUT"];}
- elseif (isset($_POST["inOUT"])) {$inOUT=$_POST["inOUT"];}
- if (isset($_GET["manual_dial_filter"])) {$manual_dial_filter=$_GET["manual_dial_filter"];}
- elseif (isset($_POST["manual_dial_filter"])) {$manual_dial_filter=$_POST["manual_dial_filter"];}
- if (isset($_GET["alt_dial"])) {$alt_dial=$_GET["alt_dial"];}
- elseif (isset($_POST["alt_dial"])) {$alt_dial=$_POST["alt_dial"];}
- if (isset($_GET["agentchannel"])) {$agentchannel=$_GET["agentchannel"];}
- elseif (isset($_POST["agentchannel"])) {$agentchannel=$_POST["agentchannel"];}
- if (isset($_GET["conf_dialed"])) {$conf_dialed=$_GET["conf_dialed"];}
- elseif (isset($_POST["conf_dialed"])) {$conf_dialed=$_POST["conf_dialed"];}
- if (isset($_GET["leaving_threeway"])) {$leaving_threeway=$_GET["leaving_threeway"];}
- elseif (isset($_POST["leaving_threeway"])) {$leaving_threeway=$_POST["leaving_threeway"];}
- if (isset($_GET["hangup_all_non_reserved"])) {$hangup_all_non_reserved=$_GET["hangup_all_non_reserved"];}
- elseif (isset($_POST["hangup_all_non_reserved"])) {$hangup_all_non_reserved=$_POST["hangup_all_non_reserved"];}
- if (isset($_GET["blind_transfer"])) {$blind_transfer=$_GET["blind_transfer"];}
- elseif (isset($_POST["blind_transfer"])) {$blind_transfer=$_POST["blind_transfer"];}
- if (isset($_GET["usegroupalias"])) {$usegroupalias=$_GET["usegroupalias"];}
- elseif (isset($_POST["usegroupalias"])) {$usegroupalias=$_POST["usegroupalias"];}
- if (isset($_GET["account"])) {$account=$_GET["account"];}
- elseif (isset($_POST["account"])) {$account=$_POST["account"];}
- if (isset($_GET["agent_dialed_number"])) {$agent_dialed_number=$_GET["agent_dialed_number"];}
- elseif (isset($_POST["agent_dialed_number"])) {$agent_dialed_number=$_POST["agent_dialed_number"];}
- if (isset($_GET["agent_dialed_type"])) {$agent_dialed_type=$_GET["agent_dialed_type"];}
- elseif (isset($_POST["agent_dialed_type"])) {$agent_dialed_type=$_POST["agent_dialed_type"];}
- if (isset($_GET["wrapup"])) {$wrapup=$_GET["wrapup"];}
- elseif (isset($_POST["wrapup"])) {$wrapup=$_POST["wrapup"];}
- if (isset($_GET["vtiger_callback_id"])) {$vtiger_callback_id=$_GET["vtiger_callback_id"];}
- elseif (isset($_POST["vtiger_callback_id"])) {$vtiger_callback_id=$_POST["vtiger_callback_id"];}
- 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
- $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';
- #############################################
- ##### START SYSTEM_SETTINGS LOOKUP #####
- $stmt = "SELECT use_non_latin,timeclock_end_of_day FROM system_settings;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00001',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $qm_conf_ct = mysql_num_rows($rslt);
- $i=0;
- while ($i < $qm_conf_ct)
- {
- $row=mysql_fetch_row($rslt);
- $non_latin = $row[0];
- $timeclock_end_of_day = $row[1];
- $i++;
- }
- ##### END SETTINGS LOOKUP #####
- ###########################################
- if ($non_latin < 1)
- {
- $user=ereg_replace("[^0-9a-zA-Z]","",$user);
- $pass=ereg_replace("[^0-9a-zA-Z]","",$pass);
- $length_in_sec = ereg_replace("[^0-9]","",$length_in_sec);
- $phone_code = ereg_replace("[^0-9]","",$phone_code);
- $phone_number = ereg_replace("[^0-9]","",$phone_number);
- }
- # 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;}
- if ($ACTION == 'LogiNCamPaigns')
- {
- $skip_user_validation=1;
- }
- else
- {
- $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);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00002',$user,$server_ip,$session_name,$one_mysql_log);}
- $row=mysql_fetch_row($rslt);
- $auth=$row[0];
- if( (strlen($user)<2) or (strlen($pass)<2) or ($auth==0))
- {
- echo "Invalid Username/Password: |$user|$pass|\n";
- exit;
- }
- else
- {
- if( (strlen($server_ip)<6) or (!isset($server_ip)) or ( (strlen($session_name)<12) or (!isset($session_name)) ) )
- {
- echo "Invalid server_ip: |$server_ip| or Invalid session_name: |$session_name|\n";
- exit;
- }
- else
- {
- $stmt="SELECT count(*) from web_client_sessions where session_name='$session_name' and server_ip='$server_ip';";
- if ($DB) {echo "|$stmt|\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00003',$user,$server_ip,$session_name,$one_mysql_log);}
- $row=mysql_fetch_row($rslt);
- $SNauth=$row[0];
- if($SNauth==0)
- {
- echo "Invalid session_name: |$session_name|$server_ip|\n";
- exit;
- }
- else
- {
- # do nothing for now
- }
- }
- }
- }
- if ($format=='debug')
- {
- echo "<html>\n";
- echo "<head>\n";
- echo "<!-- VERSION: $version BUILD: $build USER: $user server_ip: $server_ip-->\n";
- echo "<title>VICIDiaL Database Query Script";
- echo "</title>\n";
- echo "</head>\n";
- echo "<BODY BGCOLOR=white marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>\n";
- }
- ################################################################################
- ### LogiNCamPaigns - generates an HTML SELECT list of allowed campaigns for a
- ### specific agent on the login screen
- ################################################################################
- if ($ACTION == 'LogiNCamPaigns')
- {
- if ( (strlen($user)<1) )
- {
- echo "<select size=1 name=VD_campaign id=VD_campaign onFocus=\"login_allowable_campaigns()\">\n";
- echo "<option value=\"\">-- ERROR --</option>\n";
- echo "</select>\n";
- exit;
- }
- else
- {
- $stmt="SELECT user_group,user_level,agent_shift_enforcement_override,shift_override_flag from vicidial_users where user='$user' and pass='$pass'";
- if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00004',$user,$server_ip,$session_name,$one_mysql_log);}
- $row=mysql_fetch_row($rslt);
- $VU_user_group = $row[0];
- $VU_user_level = $row[1];
- $VU_agent_shift_enforcement_override = $row[2];
- $VU_shift_override_flag = $row[3];
- $LOGallowed_campaignsSQL='';
- $stmt="SELECT allowed_campaigns,forced_timeclock_login,shift_enforcement,group_shifts from vicidial_user_groups where user_group='$VU_user_group';";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00005',$user,$server_ip,$session_name,$one_mysql_log);}
- $row=mysql_fetch_row($rslt);
- $forced_timeclock_login = $row[1];
- $shift_enforcement = $row[2];
- $LOGgroup_shiftsSQL = eregi_replace(' ','',$row[3]);
- $LOGgroup_shiftsSQL = eregi_replace(' ',"','",$LOGgroup_shiftsSQL);
- $LOGgroup_shiftsSQL = "shift_id IN('$LOGgroup_shiftsSQL')";
- if ( (!eregi("ALL-CAMPAIGNS",$row[0])) )
- {
- $LOGallowed_campaignsSQL = eregi_replace(' -','',$row[0]);
- $LOGallowed_campaignsSQL = eregi_replace(' ',"','",$LOGallowed_campaignsSQL);
- $LOGallowed_campaignsSQL = "and campaign_id IN('$LOGallowed_campaignsSQL')";
- }
- $show_campaign_list=1;
- ### CHECK TO SEE IF AGENT IS LOGGED IN TO TIMECLOCK, IF NOT, OUTPUT ERROR
- if ( (ereg('Y',$forced_timeclock_login)) or ( (ereg('ADMIN_EXEMPT',$forced_timeclock_login)) and ($VU_user_level < 8) ) )
- {
- $last_agent_event='';
- $HHMM = date("Hi");
- $HHteod = substr($timeclock_end_of_day,0,2);
- $MMteod = substr($timeclock_end_of_day,2,2);
- if ($HHMM < $timeclock_end_of_day)
- {$EoD = mktime($HHteod, $MMteod, 10, date("m"), date("d")-1, date("Y"));}
- else
- {$EoD = mktime($HHteod, $MMteod, 10, date("m"), date("d"), date("Y"));}
- $EoDdate = date("Y-m-d H:i:s", $EoD);
- ##### grab timeclock logged-in time for each user #####
- $stmt="SELECT event from vicidial_timeclock_log where user='$user' and event_epoch >= '$EoD' order by timeclock_id desc limit 1;";
- if ($DB>0) {echo "|$stmt|";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00184',$user,$server_ip,$session_name,$one_mysql_log);}
- $events_to_parse = mysql_num_rows($rslt);
- if ($events_to_parse > 0)
- {
- $rowx=mysql_fetch_row($rslt);
- $last_agent_event = $rowx[0];
- }
- if ( (strlen($last_agent_event)<2) or (ereg('LOGOUT',$last_agent_event)) )
- {$show_campaign_list=0;}
- }
- }
- ### CHECK TO SEE IF AGENT IS WITHIN THEIR SHIFT IF RESTRICTED, IF NOT, OUTPUT ERROR
- if ( ( (ereg("START|ALL",$shift_enforcement)) and (!ereg("OFF",$VU_agent_shift_enforcement_override)) ) or (ereg("START|ALL",$VU_agent_shift_enforcement_override)) )
- {
- $shift_ok=0;
- if ( (strlen($LOGgroup_shiftsSQL) < 3) and ($VU_shift_override_flag < 1) )
- {
- $VDdisplayMESSAGE = "<B>ERROR: There are no Shifts enabled for your user group</B>\n";
- $VDloginDISPLAY=1;
- }
- else
- {
- $HHMM = date("Hi");
- $wday = date("w");
- $stmt="SELECT shift_id,shift_start_time,shift_length,shift_weekdays from vicidial_shifts where $LOGgroup_shiftsSQL order by shift_id";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00193',$user,$server_ip,$session_name,$one_mysql_log);}
- $shifts_to_print = mysql_num_rows($rslt);
- $o=0;
- while ( ($shifts_to_print > $o) and ($shift_ok < 1) )
- {
- $rowx=mysql_fetch_row($rslt);
- $shift_id = $rowx[0];
- $shift_start_time = $rowx[1];
- $shift_length = $rowx[2];
- $shift_weekdays = $rowx[3];
- if (eregi("$wday",$shift_weekdays))
- {
- $HHshift_length = substr($shift_length,0,2);
- $MMshift_length = substr($shift_length,3,2);
- $HHshift_start_time = substr($shift_start_time,0,2);
- $MMshift_start_time = substr($shift_start_time,2,2);
- $HHshift_end_time = ($HHshift_length + $HHshift_start_time);
- $MMshift_end_time = ($MMshift_length + $MMshift_start_time);
- if ($MMshift_end_time > 59)
- {
- $MMshift_end_time = ($MMshift_end_time - 60);
- $HHshift_end_time++;
- }
- if ($HHshift_end_time > 23)
- {$HHshift_end_time = ($HHshift_end_time - 24);}
- $HHshift_end_time = sprintf("%02s", $HHshift_end_time);
- $MMshift_end_time = sprintf("%02s", $MMshift_end_time);
- $shift_end_time = "$HHshift_end_time$MMshift_end_time";
- if (
- ( ($HHMM >= $shift_start_time) and ($HHMM < $shift_end_time) ) or
- ( ($HHMM < $shift_start_time) and ($HHMM < $shift_end_time) and ($shift_end_time <= $shift_start_time) ) or
- ( ($HHMM >= $shift_start_time) and ($HHMM >= $shift_end_time) and ($shift_end_time <= $shift_start_time) )
- )
- {$shift_ok++;}
- }
- $o++;
- }
- if ( ($shift_ok < 1) and ($VU_shift_override_flag < 1) )
- {
- $VDdisplayMESSAGE = "<B>ERROR: You are not allowed to log in outside of your shift</B>\n";
- $VDloginDISPLAY=1;
- }
- }
- if ($VDloginDISPLAY > 0)
- {
- $loginDATE = date("Ymd");
- $VDdisplayMESSAGE.= "<BR><BR>MANAGER OVERRIDE:<BR>\n";
- $VDdisplayMESSAGE.= "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n";
- $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=MGR_override VALUE=\"1\">\n";
- $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=relogin VALUE=\"YES\">\n";
- $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=VD_login VALUE=\"$user\">\n";
- $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=VD_pass VALUE=\"$pass\">\n";
- $VDdisplayMESSAGE.= "Manager Login: <INPUT TYPE=TEXT NAME=\"MGR_login$loginDATE\" SIZE=10 MAXLENGTH=20><br>\n";
- $VDdisplayMESSAGE.= "Manager Password: <INPUT TYPE=PASSWORD NAME=\"MGR_pass$loginDATE\" SIZE=10 MAXLENGTH=20><br>\n";
- $VDdisplayMESSAGE.= "<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT></FORM><BR><BR><BR><BR>\n";
- echo "$VDdisplayMESSAGE";
- exit;
- }
- }
- if ($show_campaign_list > 0)
- {
- $stmt="SELECT campaign_id,campaign_name from vicidial_campaigns where active='Y' $LOGallowed_campaignsSQL order by campaign_id";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00006',$user,$server_ip,$session_name,$one_mysql_log);}
- $camps_to_print = mysql_num_rows($rslt);
- echo "<select size=1 name=VD_campaign id=VD_campaign>\n";
- echo "<option value=\"\">-- PLEASE SELECT A CAMPAIGN --</option>\n";
- $o=0;
- while ($camps_to_print > $o)
- {
- $rowx=mysql_fetch_row($rslt);
- echo "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
- $o++;
- }
- echo "</select>\n";
- }
- else
- {
- echo "<select size=1 name=VD_campaign id=VD_campaign onFocus=\"login_allowable_campaigns()\">\n";
- echo "<option value=\"\">-- YOU MUST LOG IN TO THE TIMECLOCK FIRST --</option>\n";
- echo "</select>\n";
- }
- exit;
- }
- ################################################################################
- ### regCLOSER - update the vicidial_live_agents table to reflect the closer
- ### inbound choices made upon login
- ################################################################################
- if ($ACTION == 'regCLOSER')
- {
- $row=''; $rowx='';
- $channel_live=1;
- if ( (strlen($closer_choice)<1) || (strlen($user)<1) )
- {
- $channel_live=0;
- echo "Group Choice $closer_choice is not valid\n";
- exit;
- }
- else
- {
- if ($closer_choice == "MGRLOCK-")
- {
- $stmt="SELECT closer_campaigns FROM vicidial_users where user='$user' LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00007',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $row=mysql_fetch_row($rslt);
- $closer_choice =$row[0];
- $stmt="UPDATE vicidial_live_agents set closer_campaigns='$closer_choice' where user='$user' and server_ip='$server_ip';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00008',$user,$server_ip,$session_name,$one_mysql_log);}
- }
- else
- {
- $stmt="UPDATE vicidial_live_agents set closer_campaigns='$closer_choice' where user='$user' and server_ip='$server_ip';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00009',$user,$server_ip,$session_name,$one_mysql_log);}
- $stmt="UPDATE vicidial_users set closer_campaigns='$closer_choice' where user='$user';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00010',$user,$server_ip,$session_name,$one_mysql_log);}
- }
- $stmt="INSERT INTO vicidial_user_closer_log set user='$user',campaign_id='$campaign',event_date='$NOW_TIME',blended='$closer_blended',closer_campaigns='$closer_choice';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00011',$user,$server_ip,$session_name,$one_mysql_log);}
- $stmt="DELETE FROM vicidial_live_inbound_agents where user='$user';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00012',$user,$server_ip,$session_name,$one_mysql_log);}
- $in_groups_pre = preg_replace('/-$/','',$closer_choice);
- $in_groups = explode(" ",$in_groups_pre);
- $in_groups_ct = count($in_groups);
- $k=1;
- while ($k < $in_groups_ct)
- {
- if (strlen($in_groups[$k])>1)
- {
- $stmt="SELECT group_weight,calls_today FROM vicidial_inbound_group_agents where user='$user' and group_id='$in_groups[$k]';";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00013',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $viga_ct = mysql_num_rows($rslt);
- if ($viga_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $group_weight = $row[0];
- $calls_today = $row[1];
- }
- else
- {
- $group_weight = 0;
- $calls_today = 0;
- }
- $stmt="INSERT INTO vicidial_live_inbound_agents set user='$user',group_id='$in_groups[$k]',group_weight='$group_weight',calls_today='$calls_today',last_call_time='$NOW_TIME',last_call_finish='$NOW_TIME';";
- if ($format=='debug') {echo "\n<!-- $stmt -->";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00014',$user,$server_ip,$session_name,$one_mysql_log);}
- }
- $k++;
- }
- }
- echo "Closer In Group Choice $closer_choice has been registered to user $user\n";
- }
- ################################################################################
- ### manDiaLnextCALL - for manual VICIDiaL dialing this will grab the next lead
- ### in the campaign, reserve it, send data back to client and
- ### place the call by inserting into vicidial_manager
- ################################################################################
- if ($ACTION == 'manDiaLnextCaLL')
- {
- $MT[0]='';
- $row=''; $rowx='';
- $channel_live=1;
- if ( (strlen($conf_exten)<1) || (strlen($campaign)<1) || (strlen($ext_context)<1) )
- {
- $channel_live=0;
- echo "HOPPER EMPTY\n";
- echo "Conf Exten $conf_exten or campaign $campaign or ext_context $ext_context is not valid\n";
- exit;
- }
- else
- {
- ##### grab number of calls today in this campaign and increment
- $stmt="SELECT calls_today FROM vicidial_live_agents WHERE user='$user' and campaign_id='$campaign';";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00015',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $vla_cc_ct = mysql_num_rows($rslt);
- if ($vla_cc_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $calls_today =$row[0];
- }
- else
- {$calls_today ='0';}
- $calls_today++;
- ### check if this is a callback, if it is, skip the grabbing of a new lead and mark the callback as INACTIVE
- if ( (strlen($callback_id)>0) and (strlen($lead_id)>0) )
- {
- $affected_rows=1;
- $CBleadIDset=1;
- $stmt = "UPDATE vicidial_callbacks set status='INACTIVE' where callback_id='$callback_id';";
- if ($DB) {echo "$stmt\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00016',$user,$server_ip,$session_name,$one_mysql_log);}
- }
- else
- {
- if (strlen($phone_number)>3)
- {
- if (ereg("DNC",$manual_dial_filter))
- {
- $stmt="SELECT count(*) FROM vicidial_dnc where phone_number='$phone_number';";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00017',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $row=mysql_fetch_row($rslt);
-
- if ($row[0] > 0)
- {
- echo "DNC NUMBER\n";
- exit;
- }
- $stmt="SELECT count(*) FROM vicidial_campaign_dnc where phone_number='$phone_number' and campaign_id='$campaign';";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00018',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $row=mysql_fetch_row($rslt);
-
- if ($row[0] > 0)
- {
- echo "DNC NUMBER\n";
- exit;
- }
- }
- if (ereg("CAMPLISTS",$manual_dial_filter))
- {
- $stmt="SELECT list_id,active from vicidial_lists where campaign_id='$campaign'";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00019',$user,$server_ip,$session_name,$one_mysql_log);}
- $lists_to_parse = mysql_num_rows($rslt);
- $camp_lists='';
- $o=0;
- while ($lists_to_parse > $o)
- {
- $rowx=mysql_fetch_row($rslt);
- if (ereg("Y", $rowx[1])) {$active_lists++; $camp_lists .= "'$rowx[0]',";}
- if (ereg("N", $rowx[1])) {$inactive_lists++;}
- $o++;
- }
- $camp_lists = eregi_replace(".$","",$camp_lists);
- $stmt="SELECT count(*) FROM vicidial_list where phone_number='$phone_number' and list_id IN($camp_lists);";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00020',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $row=mysql_fetch_row($rslt);
-
- if ($row[0] < 1)
- {
- echo "NUMBER NOT IN CAMPLISTS\n";
- exit;
- }
- }
- if ($stage=='lookup')
- {
- if (strlen($vendor_lead_code)>0)
- {
- $stmt="SELECT lead_id FROM vicidial_list where vendor_lead_code='$vendor_lead_code' order by modify_date desc LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $man_leadID_ct = mysql_num_rows($rslt);
- if ( ($man_leadID_ct > 0) and (strlen($phone_number) > 5) )
- {$override_phone++;}
- }
- else
- {
- $stmt="SELECT lead_id FROM vicidial_list where phone_number='$phone_number' order by modify_date desc LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $man_leadID_ct = mysql_num_rows($rslt);
- }
- if ($man_leadID_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $affected_rows=1;
- $lead_id =$row[0];
- $CBleadIDset=1;
- }
- else
- {
- ### insert a new lead in the system with this phone number
- $stmt = "INSERT INTO vicidial_list SET phone_code='$phone_code',phone_number='$phone_number',list_id='$list_id',status='QUEUE',user='$user',called_since_last_reset='Y',entry_date='$ENTRYdate',last_local_call_time='$NOW_TIME',vendor_lead_code='$vendor_lead_code';";
- if ($DB) {echo "$stmt\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00022',$user,$server_ip,$session_name,$one_mysql_log);}
- $affected_rows = mysql_affected_rows($link);
- $lead_id = mysql_insert_id($link);
- $CBleadIDset=1;
- }
- }
- else
- {
- ### insert a new lead in the system with this phone number
- $stmt = "INSERT INTO vicidial_list SET phone_code='$phone_code',phone_number='$phone_number',list_id='$list_id',status='QUEUE',user='$user',called_since_last_reset='Y',entry_date='$ENTRYdate',last_local_call_time='$NOW_TIME';";
- if ($DB) {echo "$stmt\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00023',$user,$server_ip,$session_name,$one_mysql_log);}
- $affected_rows = mysql_affected_rows($link);
- $lead_id = mysql_insert_id($link);
- $CBleadIDset=1;
- }
- }
- else
- {
- ### grab the next lead in the hopper for this campaign and reserve it for the user
- $stmt = "UPDATE vicidial_hopper set status='QUEUE', user='$user' where campaign_id='$campaign' and status='READY' order by priority desc,hopper_id LIMIT 1";
- if ($DB) {echo "$stmt\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00024',$user,$server_ip,$session_name,$one_mysql_log);}
- $affected_rows = mysql_affected_rows($link);
- }
- }
- if ($affected_rows > 0)
- {
- if (!$CBleadIDset)
- {
- ##### grab the lead_id of the reserved user in vicidial_hopper
- $stmt="SELECT lead_id FROM vicidial_hopper where campaign_id='$campaign' and status='QUEUE' and user='$user' LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00025',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $hopper_leadID_ct = mysql_num_rows($rslt);
- if ($hopper_leadID_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $lead_id =$row[0];
- }
- }
- ##### grab the data from vicidial_list for the lead_id
- $stmt="SELECT * FROM vicidial_list where lead_id='$lead_id' LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00026',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $list_lead_ct = mysql_num_rows($rslt);
- if ($list_lead_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- # $lead_id = trim("$row[0]");
- $dispo = trim("$row[3]");
- $tsr = trim("$row[4]");
- $vendor_id = trim("$row[5]");
- $source_id = trim("$row[6]");
- $list_id = trim("$row[7]");
- $gmt_offset_now = trim("$row[8]");
- $called_since_last_reset = trim("$row[9]");
- $phone_code = trim("$row[10]");
- if ($override_phone < 1)
- {$phone_number = trim("$row[11]");}
- $title = trim("$row[12]");
- $first_name = trim("$row[13]");
- $middle_initial = trim("$row[14]");
- $last_name = trim("$row[15]");
- $address1 = trim("$row[16]");
- $address2 = trim("$row[17]");
- $address3 = trim("$row[18]");
- $city = trim("$row[19]");
- $state = trim("$row[20]");
- $province = trim("$row[21]");
- $postal_code = trim("$row[22]");
- $country_code = trim("$row[23]");
- $gender = trim("$row[24]");
- $date_of_birth = trim("$row[25]");
- $alt_phone = trim("$row[26]");
- $email = trim("$row[27]");
- $security = trim("$row[28]");
- $comments = stripslashes(trim("$row[29]"));
- $called_count = trim("$row[30]");
- }
- $called_count++;
- ##### check if system is set to generate logfile for transfers
- $stmt="SELECT enable_agc_xfer_log FROM system_settings;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00027',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $enable_agc_xfer_log_ct = mysql_num_rows($rslt);
- if ($enable_agc_xfer_log_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $enable_agc_xfer_log =$row[0];
- }
- if ( ($WeBRooTWritablE > 0) and ($enable_agc_xfer_log > 0) )
- {
- # generate callerID for unique identifier in xfer_log file
- $PADlead_id = sprintf("%09s", $lead_id);
- while (strlen($PADlead_id) > 9) {$PADlead_id = substr("$PADlead_id", 0, -1);}
- # Create unique calleridname to track the call: MmmddhhmmssLLLLLLLLL
- $MqueryCID = "M$CIDdate$PADlead_id";
- # DATETIME|campaign|lead_id|phone_number|user|type
- # 2007-08-22 11:11:11|TESTCAMP|65432|3125551212|1234|M
- $fp = fopen ("./xfer_log.txt", "a");
- fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|M|$MqueryCID|\n");
- fclose($fp);
- }
- ##### if lead is a callback, grab the callback comments
- $CBentry_time = '';
- $CBcallback_time = '';
- $CBuser = '';
- $CBcomments = '';
- if (ereg("CALLBK",$dispo))
- {
- $stmt="SELECT entry_time,callback_time,user,comments FROM vicidial_callbacks where lead_id='$lead_id' order by callback_id desc LIMIT 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00028',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $cb_record_ct = mysql_num_rows($rslt);
- if ($cb_record_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $CBentry_time = trim("$row[0]");
- $CBcallback_time = trim("$row[1]");
- $CBuser = trim("$row[2]");
- $CBcomments = trim("$row[3]");
- }
- }
- $stmt = "SELECT local_gmt FROM servers where active='Y' limit 1;";
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00029',$user,$server_ip,$session_name,$one_mysql_log);}
- if ($DB) {echo "$stmt\n";}
- $server_ct = mysql_num_rows($rslt);
- if ($server_ct > 0)
- {
- $row=mysql_fetch_row($rslt);
- $local_gmt = $row[0];
- }
- $LLCT_DATE_offset = ($local_gmt - $gmt_offset_now);
- $LLCT_DATE = date("Y-m-d H:i:s", mktime(date("H")-$LLCT_DATE_offset,date("i"),date("s"),date("m"),date("d"),date("Y")));
- if (ereg('Y',$called_since_last_reset))
- {
- $called_since_last_reset = ereg_replace('Y','',$called_since_last_reset);
- if (strlen($called_since_last_reset) < 1) {$called_since_last_reset = 0;}
- $called_since_last_reset++;
- $called_since_last_reset = "Y$called_since_last_reset";
- }
- else {$called_since_last_reset = 'Y';}
- ### flag the lead as called and change it's status to INCALL
- $stmt = "UPDATE vicidial_list set status='INCALL', called_since_last_reset='$called_since_last_reset', called_count='$called_count',user='$user',last_local_call_time='$LLCT_DATE' where lead_id='$lead_id';";
- if ($DB) {echo "$stmt\n";}
- $rslt=mysql_query($stmt, $link);
- if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00030',$user,$server_ip,$session_name,$on…