/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

  1. <?php
  2. # vdc_db_query.php
  3. #
  4. # Copyright (C) 2009 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
  5. #
  6. # This script is designed purely to send whether the meetme conference has live channels connected and which they are
  7. # This script depends on the server_ip being sent and also needs to have a valid user/pass from the vicidial_users table
  8. #
  9. # required variables:
  10. # - $server_ip
  11. # - $session_name
  12. # - $user
  13. # - $pass
  14. # optional variables:
  15. # - $format - ('text','debug')
  16. # - $ACTION - ('regCLOSER','manDiaLnextCALL','manDiaLskip','manDiaLonly','manDiaLlookCALL','manDiaLlogCALL','userLOGout','updateDISPO','VDADpause','VDADready','VDADcheckINCOMING','UpdatEFavoritEs','CalLBacKLisT','CalLBacKCounT','PauseCodeSubmit','LogiNCamPaigns','alt_phone_change','AlertControl')
  17. # - $stage - ('start','finish','lookup','new')
  18. # - $closer_choice - ('CL_TESTCAMP_L CL_OUT123_L -')
  19. # - $conf_exten - ('8600011',...)
  20. # - $exten - ('123test',...)
  21. # - $ext_context - ('default','demo',...)
  22. # - $ext_priority - ('1','2',...)
  23. # - $campaign - ('testcamp',...)
  24. # - $dial_timeout - ('60','26',...)
  25. # - $dial_prefix - ('9','8',...)
  26. # - $campaign_cid - ('3125551212','0000000000',...)
  27. # - $MDnextCID - ('M06301413000000002',...)
  28. # - $uniqueid - ('1120232758.2406800',...)
  29. # - $lead_id - ('36524',...)
  30. # - $list_id - ('101','123456',...)
  31. # - $length_in_sec - ('12',...)
  32. # - $phone_code - ('1',...)
  33. # - $phone_number - ('3125551212',...)
  34. # - $channel - ('Zap/12-1',...)
  35. # - $start_epoch - ('1120236911',...)
  36. # - $vendor_lead_code - ('1234test',...)
  37. # - $title - ('Mr.',...)
  38. # - $first_name - ('Bob',...)
  39. # - $middle_initial - ('L',...)
  40. # - $last_name - ('Wilson',...)
  41. # - $address1 - ('1324 Main St.',...)
  42. # - $address2 - ('Apt. 12',...)
  43. # - $address3 - ('co Robert Wilson',...)
  44. # - $city - ('Chicago',...)
  45. # - $state - ('IL',...)
  46. # - $province - ('NA',...)
  47. # - $postal_code - ('60054',...)
  48. # - $country_code - ('USA',...)
  49. # - $gender - ('M',...)
  50. # - $date_of_birth - ('1970-01-01',...)
  51. # - $alt_phone - ('3125551213',...)
  52. # - $email - ('bob@bob.com',...)
  53. # - $security_phrase - ('Hello',...)
  54. # - $comments - ('Good Customer',...)
  55. # - $auto_dial_level - ('0','1','1.2',...)
  56. # - $VDstop_rec_after_each_call - ('0','1')
  57. # - $conf_silent_prefix - ('7','8','5',...)
  58. # - $extension - ('123','user123','25-1',...)
  59. # - $protocol - ('Zap','SIP','IAX2',...)
  60. # - $user_abb - ('1234','6666',...)
  61. # - $preview - ('YES','NO',...)
  62. # - $called_count - ('0','1','2',...)
  63. # - $agent_log_id - ('123456',...)
  64. # - $agent_log - ('NO',...)
  65. # - $favorites_list - (",'cc160','cc100'",...)
  66. # - $CallBackDatETimE - ('2006-04-21 14:30:00',...)
  67. # - $recipient - ('ANYONE,'USERONLY')
  68. # - $callback_id - ('12345','12346',...)
  69. # - $use_internal_dnc - ('Y','N')
  70. # - $use_campaign_dnc - ('Y','N')
  71. # - $omit_phone_code - ('Y','N')
  72. # - $no_delete_sessions - ('0','1')
  73. # - $LogouTKicKAlL - ('0','1');
  74. # - $closer_blended = ('0','1');
  75. # - $inOUT = ('IN','OUT');
  76. # - $manual_dial_filter = ('NONE','CAMPLISTS','DNC','CAMPLISTS_DNC')
  77. # - $agentchannel = ('Zap/1-1','SIP/testing-6ry4i3',...)
  78. # - $conf_dialed = ('0','1')
  79. # - $leaving_threeway = ('0','1')
  80. # - $blind_transfer = ('0','1')
  81. # - $usegroupalias - ('0','1')
  82. # - $account - ('DEFAULT',...)
  83. # - $agent_dialed_number - ('1','')
  84. # - $agent_dialed_type - ('MANUAL_OVERRIDE','MANUAL_DIALNOW','MANUAL_PREVIEW',...)
  85. # - $wrapup - ('WRAPUP','')
  86. # - $vtiger_callback_id - ('16534'...)
  87. #
  88. # CHANGELOG:
  89. # 50629-1044 - First build of script
  90. # 50630-1422 - Added manual dial action and MD channel lookup
  91. # 50701-1451 - Added dial log for start and end of vicidial calls
  92. # 50705-1239 - Added call disposition update
  93. # 50804-1627 - Fixed updateDispo to update vicidial_log entry
  94. # 50816-1605 - Added VDADpause/ready for auto dialing
  95. # 50816-1811 - Added basic autodial call pickup functions
  96. # 50817-1005 - Altered logging functions to accomodate auto_dialing
  97. # 50818-1305 - Added stop-all-recordings-after-each-vicidial-call option
  98. # 50818-1411 - Added hangup of agent phone after Logout
  99. # 50901-1315 - Fixed CLOSER IN-GROUP Web Form bug
  100. # 50902-1507 - Fixed CLOSER log length_in_sec bug
  101. # 50902-1730 - Added functions for manual preview dialing and revert
  102. # 50913-1214 - Added agent random update to leadupdate
  103. # 51020-1421 - Added agent_log_id framework for detailed agent activity logging
  104. # 51021-1717 - Allows for multi-line comments (changes \n to !N in database)
  105. # 51111-1046 - Added vicidial_agent_log lead_id earlier for manual dial
  106. # 51121-1445 - Altered echo statements for several small PHP speed optimizations
  107. # 51122-1328 - Fixed UserLogout issue not removing conference reservation
  108. # 51129-1012 - Added ability to accept calls from other VICIDIAL servers
  109. # 51129-1729 - Changed manual dial to use the '/n' flag for calls
  110. # 51221-1154 - Added SCRIPT id lookup and sending to vicidial.php for display
  111. # 60105-1059 - Added Updating of astguiclient favorites in the DB
  112. # 60208-1617 - Added dtmf buttons output per call
  113. # 60213-1521 - Added closer_campaigns update to vicidial_users
  114. # 60215-1036 - Added Callback date-time entry into vicidial_callbacks table
  115. # 60413-1541 - Added USERONLY Callback listings output - CalLBacKLisT
  116. # - Added USERONLY Callback count output - CalLBacKCounT
  117. # 60414-1140 - Added Callback lead lookup for manual dialing
  118. # 60419-1517 - After CALLBK is sent to agent, update callback record to INACTIVE
  119. # 60421-1419 - Check GET/POST vars lines with isset to not trigger PHP NOTICES
  120. # 60427-1236 - Fixed closer_choice error for CLOSER campaigns
  121. # 60609-1148 - Added ability to check for manual dial numbers in DNC
  122. # 60619-1117 - Added variable filters to close security holes for login form
  123. # 60623-1414 - Fixed variable filter for phone_code and fixed manual dial logic
  124. # 60821-1600 - Added ability to omit the phone code on vicidial lead dialing
  125. # 60821-1647 - Added ability to not delete sessions at logout
  126. # 60906-1124 - Added lookup and sending of callback data for CALLBK calls
  127. # 61128-2229 - Added vicidial_live_agents and vicidial_auto_calls manual dial entries
  128. # 70111-1600 - Added ability to use BLEND/INBND/*_C/*_B/*_I as closer campaigns
  129. # 70115-1733 - Added alt_dial functionality in auto-dial modes
  130. # 70118-1501 - Added user_group to vicidial_log,_agent_log,_closer_log,_callbacks
  131. # 70123-1357 - Fixed bug that would not update vicidial_closer_log status to dispo
  132. # 70202-1438 - Added pause code submit function
  133. # 70203-0930 - Added dialed_number to lead info output
  134. # 70203-1030 - Added dialed_label to lead info output
  135. # 70206-1126 - Added INBOUND status for inbound/closer calls in vicidial_live_agents
  136. # 70212-1253 - Fixed small issue with CXFER
  137. # 70213-1431 - Added QueueMetrics PAUSE/UNPAUSE/AGENTLOGIN/AGENTLOGOFF actions
  138. # 70214-1231 - Added queuemetrics_log_id field for server_id in queue_log
  139. # 70215-1210 - Added queuemetrics COMPLETEAGENT action
  140. # 70216-1051 - Fixed double call complete queuemetrics logging
  141. # 70222-1616 - Changed queue_log PAUSE/UNPAUSE to PAUSEALL/UNPAUSEALL
  142. # 70309-1034 - Allow amphersands and questions marks in comments to pass through
  143. # 70313-1052 - Allow pound signs(hash) in comments to pass through
  144. # 70319-1544 - Added agent disable update customer data function
  145. # 70322-1545 - Added sipsak display ability
  146. # 70413-1253 - Fixed bug for outbound call time in CLOSER-type blended campaigns
  147. # 70424-1100 - Fixed bug for fronter/closer calls that would delete vdac records
  148. # 70802-1729 - Fixed bugs with pause_sec and wait_sec under certain call handling
  149. # 70828-1443 - Added source_id to output of SCRIPTtab-IFRAME and WEBFORM
  150. # 71029-1855 - removed campaign_id naming restrictions for CLOSER-type campaigns
  151. # 71030-2047 - added hopper priority for auto alt dial entries
  152. # 71116-1011 - added calls_today count updating of the vicidial_live_agents upon INCALL
  153. # 71120-1520 - added LogiNCamPaigns to show only allowed campaigns for agents upon login
  154. # 71125-1751 - Added inbound-group default inbound group sending to vicidial.php
  155. # 71129-2025 - restricted callbacks count and list to campaign only
  156. # 71223-0318 - changed logging of closer calls
  157. # 71226-1117 - added option to kick all calls from conference upon logout
  158. # 80116-1032 - added user_closer_log logging in regCLOSER
  159. # 80125-1213 - fixed vicidial_log bug when call is from closer
  160. # 80317-2051 - Added in-group recording settings
  161. # 80402-0121 - Fixes for manual dial transfers on some systems, removed /n persist flag
  162. # 80424-0442 - Added non_latin lookup from system_settings
  163. # 80430-1006 - Added term_reason for vicidial_log and vicidial_closer_log
  164. # 80430-1957 - Changed to leave lead_id in vicidial_live_agents record until after dispo
  165. # 80630-2153 - Added queue_log logging for Manual dial calls
  166. # 80703-0139 - Added alter customer phone permissions
  167. # 80707-2325 - Added vicidial_id to recording_log for tracking of vicidial or closer log to recording
  168. # 80713-0624 - Added vicidial_list.last_local_call_time field
  169. # 80717-1604 - Modified logging function to use inOUT to determine call direction and place to log
  170. # 80719-1147 - Changed recording conf prefix
  171. # 80815-1019 - Added manual dial list restriction option
  172. # 80831-0545 - Added extended alt dial number info display support
  173. # 80909-1710 - Added support for campaign-specific DNC lists
  174. # 81010-1048 - Added support for hangup of all channels except for agent channel after attempting a 3way call
  175. # 81011-1404 - Fixed bugs in leave3way when transferring a manual dial call
  176. # 81020-1459 - Fixed bugs in queue_log logging
  177. # 81104-0134 - Added mysql error logging capability
  178. # 81104-1617 - Added multi-retry for some vicidial_live_agents table MySQL queries
  179. # 81106-0410 - Added force_timeclock_login option to LoginCampaigns function
  180. # 81107-0424 - Added carryover of script and presets for in-group calls from campaign settings
  181. # 81110-0058 - Changed Pause time to start new vicidial_agent_log on every pause
  182. # 81110-1512 - Added hangup_all_non_reserved to fix non-Hangup bug
  183. # 81111-1630 - Added another hangup fix for non-hangup
  184. # 81114-0126 - More vicidial_agent_log bug fixes
  185. # 81119-1809 - webform backslash fix
  186. # 81124-2212 - Fixes blind transfer bug
  187. # 81126-1522 - Fixed callback comments bug
  188. # 81211-0420 - Fixed Manual dial agent_log bug
  189. # 90120-1718 - Added external pause and dial option
  190. # 90126-1759 - Fixed QM section that wasn't qualified and added agent alert option
  191. # 90128-0231 - Added vendor_lead_code to manual dial lead lookup
  192. # 90304-1335 - Added support for group aliases and agent-specific variables for campaigns and in-groups
  193. # 90305-1041 - Added agent_dialed_number and type for user_call_log feature
  194. # 90307-1735 - Added Shift enforcement and manager override features
  195. # 90320-0306 - Fixed agent log bug when using wrapup time
  196. # 90323-2013 - Added function to put phone numbers in the DNC lists if they were set to status type dnc=Y
  197. # 90324-1316 - Added functions to log calls to Vtiger accounts and update status to siccode
  198. # 90327-1348 - Changed Vtiger status populate to use status name
  199. # 90408-0021 - Added API vtiger specific callback activity record ability
  200. # 90508-0726 - Changed to PHP long tags
  201. #
  202. $version = '2.2.0-109';
  203. $build = '90508-0726';
  204. $mel=1; # Mysql Error Log enabled = 1
  205. $mysql_log_count=212;
  206. $one_mysql_log=0;
  207. require("dbconnect.php");
  208. ### If you have globals turned off uncomment these lines
  209. if (isset($_GET["user"])) {$user=$_GET["user"];}
  210. elseif (isset($_POST["user"])) {$user=$_POST["user"];}
  211. if (isset($_GET["pass"])) {$pass=$_GET["pass"];}
  212. elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];}
  213. if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];}
  214. elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];}
  215. if (isset($_GET["session_name"])) {$session_name=$_GET["session_name"];}
  216. elseif (isset($_POST["session_name"])) {$session_name=$_POST["session_name"];}
  217. if (isset($_GET["format"])) {$format=$_GET["format"];}
  218. elseif (isset($_POST["format"])) {$format=$_POST["format"];}
  219. if (isset($_GET["ACTION"])) {$ACTION=$_GET["ACTION"];}
  220. elseif (isset($_POST["ACTION"])) {$ACTION=$_POST["ACTION"];}
  221. if (isset($_GET["stage"])) {$stage=$_GET["stage"];}
  222. elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];}
  223. if (isset($_GET["closer_choice"])) {$closer_choice=$_GET["closer_choice"];}
  224. elseif (isset($_POST["closer_choice"])) {$closer_choice=$_POST["closer_choice"];}
  225. if (isset($_GET["conf_exten"])) {$conf_exten=$_GET["conf_exten"];}
  226. elseif (isset($_POST["conf_exten"])) {$conf_exten=$_POST["conf_exten"];}
  227. if (isset($_GET["exten"])) {$exten=$_GET["exten"];}
  228. elseif (isset($_POST["exten"])) {$exten=$_POST["exten"];}
  229. if (isset($_GET["ext_context"])) {$ext_context=$_GET["ext_context"];}
  230. elseif (isset($_POST["ext_context"])) {$ext_context=$_POST["ext_context"];}
  231. if (isset($_GET["ext_priority"])) {$ext_priority=$_GET["ext_priority"];}
  232. elseif (isset($_POST["ext_priority"])) {$ext_priority=$_POST["ext_priority"];}
  233. if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];}
  234. elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];}
  235. if (isset($_GET["dial_timeout"])) {$dial_timeout=$_GET["dial_timeout"];}
  236. elseif (isset($_POST["dial_timeout"])) {$dial_timeout=$_POST["dial_timeout"];}
  237. if (isset($_GET["dial_prefix"])) {$dial_prefix=$_GET["dial_prefix"];}
  238. elseif (isset($_POST["dial_prefix"])) {$dial_prefix=$_POST["dial_prefix"];}
  239. if (isset($_GET["campaign_cid"])) {$campaign_cid=$_GET["campaign_cid"];}
  240. elseif (isset($_POST["campaign_cid"])) {$campaign_cid=$_POST["campaign_cid"];}
  241. if (isset($_GET["MDnextCID"])) {$MDnextCID=$_GET["MDnextCID"];}
  242. elseif (isset($_POST["MDnextCID"])) {$MDnextCID=$_POST["MDnextCID"];}
  243. if (isset($_GET["uniqueid"])) {$uniqueid=$_GET["uniqueid"];}
  244. elseif (isset($_POST["uniqueid"])) {$uniqueid=$_POST["uniqueid"];}
  245. if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];}
  246. elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];}
  247. if (isset($_GET["list_id"])) {$list_id=$_GET["list_id"];}
  248. elseif (isset($_POST["list_id"])) {$list_id=$_POST["list_id"];}
  249. if (isset($_GET["length_in_sec"])) {$length_in_sec=$_GET["length_in_sec"];}
  250. elseif (isset($_POST["length_in_sec"])) {$length_in_sec=$_POST["length_in_sec"];}
  251. if (isset($_GET["phone_code"])) {$phone_code=$_GET["phone_code"];}
  252. elseif (isset($_POST["phone_code"])) {$phone_code=$_POST["phone_code"];}
  253. if (isset($_GET["phone_number"])) {$phone_number=$_GET["phone_number"];}
  254. elseif (isset($_POST["phone_number"])) {$phone_number=$_POST["phone_number"];}
  255. if (isset($_GET["channel"])) {$channel=$_GET["channel"];}
  256. elseif (isset($_POST["channel"])) {$channel=$_POST["channel"];}
  257. if (isset($_GET["start_epoch"])) {$start_epoch=$_GET["start_epoch"];}
  258. elseif (isset($_POST["start_epoch"])) {$start_epoch=$_POST["start_epoch"];}
  259. if (isset($_GET["dispo_choice"])) {$dispo_choice=$_GET["dispo_choice"];}
  260. elseif (isset($_POST["dispo_choice"])) {$dispo_choice=$_POST["dispo_choice"];}
  261. if (isset($_GET["vendor_lead_code"])) {$vendor_lead_code=$_GET["vendor_lead_code"];}
  262. elseif (isset($_POST["vendor_lead_code"])) {$vendor_lead_code=$_POST["vendor_lead_code"];}
  263. if (isset($_GET["title"])) {$title=$_GET["title"];}
  264. elseif (isset($_POST["title"])) {$title=$_POST["title"];}
  265. if (isset($_GET["first_name"])) {$first_name=$_GET["first_name"];}
  266. elseif (isset($_POST["first_name"])) {$first_name=$_POST["first_name"];}
  267. if (isset($_GET["middle_initial"])) {$middle_initial=$_GET["middle_initial"];}
  268. elseif (isset($_POST["middle_initial"])) {$middle_initial=$_POST["middle_initial"];}
  269. if (isset($_GET["last_name"])) {$last_name=$_GET["last_name"];}
  270. elseif (isset($_POST["last_name"])) {$last_name=$_POST["last_name"];}
  271. if (isset($_GET["address1"])) {$address1=$_GET["address1"];}
  272. elseif (isset($_POST["address1"])) {$address1=$_POST["address1"];}
  273. if (isset($_GET["address2"])) {$address2=$_GET["address2"];}
  274. elseif (isset($_POST["address2"])) {$address2=$_POST["address2"];}
  275. if (isset($_GET["address3"])) {$address3=$_GET["address3"];}
  276. elseif (isset($_POST["address3"])) {$address3=$_POST["address3"];}
  277. if (isset($_GET["city"])) {$city=$_GET["city"];}
  278. elseif (isset($_POST["city"])) {$city=$_POST["city"];}
  279. if (isset($_GET["state"])) {$state=$_GET["state"];}
  280. elseif (isset($_POST["state"])) {$state=$_POST["state"];}
  281. if (isset($_GET["province"])) {$province=$_GET["province"];}
  282. elseif (isset($_POST["province"])) {$province=$_POST["province"];}
  283. if (isset($_GET["postal_code"])) {$postal_code=$_GET["postal_code"];}
  284. elseif (isset($_POST["postal_code"])) {$postal_code=$_POST["postal_code"];}
  285. if (isset($_GET["country_code"])) {$country_code=$_GET["country_code"];}
  286. elseif (isset($_POST["country_code"])) {$country_code=$_POST["country_code"];}
  287. if (isset($_GET["gender"])) {$gender=$_GET["gender"];}
  288. elseif (isset($_POST["gender"])) {$gender=$_POST["gender"];}
  289. if (isset($_GET["date_of_birth"])) {$date_of_birth=$_GET["date_of_birth"];}
  290. elseif (isset($_POST["date_of_birth"])) {$date_of_birth=$_POST["date_of_birth"];}
  291. if (isset($_GET["alt_phone"])) {$alt_phone=$_GET["alt_phone"];}
  292. elseif (isset($_POST["alt_phone"])) {$alt_phone=$_POST["alt_phone"];}
  293. if (isset($_GET["email"])) {$email=$_GET["email"];}
  294. elseif (isset($_POST["email"])) {$email=$_POST["email"];}
  295. if (isset($_GET["security_phrase"])) {$security_phrase=$_GET["security_phrase"];}
  296. elseif (isset($_POST["security_phrase"])) {$security_phrase=$_POST["security_phrase"];}
  297. if (isset($_GET["comments"])) {$comments=$_GET["comments"];}
  298. elseif (isset($_POST["comments"])) {$comments=$_POST["comments"];}
  299. if (isset($_GET["auto_dial_level"])) {$auto_dial_level=$_GET["auto_dial_level"];}
  300. elseif (isset($_POST["auto_dial_level"])) {$auto_dial_level=$_POST["auto_dial_level"];}
  301. if (isset($_GET["VDstop_rec_after_each_call"])) {$VDstop_rec_after_each_call=$_GET["VDstop_rec_after_each_call"];}
  302. elseif (isset($_POST["VDstop_rec_after_each_call"])) {$VDstop_rec_after_each_call=$_POST["VDstop_rec_after_each_call"];}
  303. if (isset($_GET["conf_silent_prefix"])) {$conf_silent_prefix=$_GET["conf_silent_prefix"];}
  304. elseif (isset($_POST["conf_silent_prefix"])) {$conf_silent_prefix=$_POST["conf_silent_prefix"];}
  305. if (isset($_GET["extension"])) {$extension=$_GET["extension"];}
  306. elseif (isset($_POST["extension"])) {$extension=$_POST["extension"];}
  307. if (isset($_GET["protocol"])) {$protocol=$_GET["protocol"];}
  308. elseif (isset($_POST["protocol"])) {$protocol=$_POST["protocol"];}
  309. if (isset($_GET["user_abb"])) {$user_abb=$_GET["user_abb"];}
  310. elseif (isset($_POST["user_abb"])) {$user_abb=$_POST["user_abb"];}
  311. if (isset($_GET["preview"])) {$preview=$_GET["preview"];}
  312. elseif (isset($_POST["preview"])) {$preview=$_POST["preview"];}
  313. if (isset($_GET["called_count"])) {$called_count=$_GET["called_count"];}
  314. elseif (isset($_POST["called_count"])) {$called_count=$_POST["called_count"];}
  315. if (isset($_GET["agent_log_id"])) {$agent_log_id=$_GET["agent_log_id"];}
  316. elseif (isset($_POST["agent_log_id"])) {$agent_log_id=$_POST["agent_log_id"];}
  317. if (isset($_GET["agent_log"])) {$agent_log=$_GET["agent_log"];}
  318. elseif (isset($_POST["agent_log"])) {$agent_log=$_POST["agent_log"];}
  319. if (isset($_GET["favorites_list"])) {$favorites_list=$_GET["favorites_list"];}
  320. elseif (isset($_POST["favorites_list"])) {$favorites_list=$_POST["favorites_list"];}
  321. if (isset($_GET["CallBackDatETimE"])) {$CallBackDatETimE=$_GET["CallBackDatETimE"];}
  322. elseif (isset($_POST["CallBackDatETimE"])) {$CallBackDatETimE=$_POST["CallBackDatETimE"];}
  323. if (isset($_GET["recipient"])) {$recipient=$_GET["recipient"];}
  324. elseif (isset($_POST["recipient"])) {$recipient=$_POST["recipient"];}
  325. if (isset($_GET["callback_id"])) {$callback_id=$_GET["callback_id"];}
  326. elseif (isset($_POST["callback_id"])) {$callback_id=$_POST["callback_id"];}
  327. if (isset($_GET["use_internal_dnc"])) {$use_internal_dnc=$_GET["use_internal_dnc"];}
  328. elseif (isset($_POST["use_internal_dnc"])) {$use_internal_dnc=$_POST["use_internal_dnc"];}
  329. if (isset($_GET["use_campaign_dnc"])) {$use_campaign_dnc=$_GET["use_campaign_dnc"];}
  330. elseif (isset($_POST["use_campaign_dnc"])) {$use_campaign_dnc=$_POST["use_campaign_dnc"];}
  331. if (isset($_GET["omit_phone_code"])) {$omit_phone_code=$_GET["omit_phone_code"];}
  332. elseif (isset($_POST["omit_phone_code"])) {$omit_phone_code=$_POST["omit_phone_code"];}
  333. if (isset($_GET["phone_ip"])) {$phone_ip=$_GET["phone_ip"];}
  334. elseif (isset($_POST["phone_ip"])) {$phone_ip=$_POST["phone_ip"];}
  335. if (isset($_GET["enable_sipsak_messages"])) {$enable_sipsak_messages=$_GET["enable_sipsak_messages"];}
  336. elseif (isset($_POST["enable_sipsak_messages"])) {$enable_sipsak_messages=$_POST["enable_sipsak_messages"];}
  337. if (isset($_GET["status"])) {$status=$_GET["status"];}
  338. elseif (isset($_POST["status"])) {$status=$_POST["status"];}
  339. if (isset($_GET["LogouTKicKAlL"])) {$LogouTKicKAlL=$_GET["LogouTKicKAlL"];}
  340. elseif (isset($_POST["LogouTKicKAlL"])) {$LogouTKicKAlL=$_POST["LogouTKicKAlL"];}
  341. if (isset($_GET["closer_blended"])) {$closer_blended=$_GET["closer_blended"];}
  342. elseif (isset($_POST["closer_blended"])) {$closer_blended=$_POST["closer_blended"];}
  343. if (isset($_GET["inOUT"])) {$inOUT=$_GET["inOUT"];}
  344. elseif (isset($_POST["inOUT"])) {$inOUT=$_POST["inOUT"];}
  345. if (isset($_GET["manual_dial_filter"])) {$manual_dial_filter=$_GET["manual_dial_filter"];}
  346. elseif (isset($_POST["manual_dial_filter"])) {$manual_dial_filter=$_POST["manual_dial_filter"];}
  347. if (isset($_GET["alt_dial"])) {$alt_dial=$_GET["alt_dial"];}
  348. elseif (isset($_POST["alt_dial"])) {$alt_dial=$_POST["alt_dial"];}
  349. if (isset($_GET["agentchannel"])) {$agentchannel=$_GET["agentchannel"];}
  350. elseif (isset($_POST["agentchannel"])) {$agentchannel=$_POST["agentchannel"];}
  351. if (isset($_GET["conf_dialed"])) {$conf_dialed=$_GET["conf_dialed"];}
  352. elseif (isset($_POST["conf_dialed"])) {$conf_dialed=$_POST["conf_dialed"];}
  353. if (isset($_GET["leaving_threeway"])) {$leaving_threeway=$_GET["leaving_threeway"];}
  354. elseif (isset($_POST["leaving_threeway"])) {$leaving_threeway=$_POST["leaving_threeway"];}
  355. if (isset($_GET["hangup_all_non_reserved"])) {$hangup_all_non_reserved=$_GET["hangup_all_non_reserved"];}
  356. elseif (isset($_POST["hangup_all_non_reserved"])) {$hangup_all_non_reserved=$_POST["hangup_all_non_reserved"];}
  357. if (isset($_GET["blind_transfer"])) {$blind_transfer=$_GET["blind_transfer"];}
  358. elseif (isset($_POST["blind_transfer"])) {$blind_transfer=$_POST["blind_transfer"];}
  359. if (isset($_GET["usegroupalias"])) {$usegroupalias=$_GET["usegroupalias"];}
  360. elseif (isset($_POST["usegroupalias"])) {$usegroupalias=$_POST["usegroupalias"];}
  361. if (isset($_GET["account"])) {$account=$_GET["account"];}
  362. elseif (isset($_POST["account"])) {$account=$_POST["account"];}
  363. if (isset($_GET["agent_dialed_number"])) {$agent_dialed_number=$_GET["agent_dialed_number"];}
  364. elseif (isset($_POST["agent_dialed_number"])) {$agent_dialed_number=$_POST["agent_dialed_number"];}
  365. if (isset($_GET["agent_dialed_type"])) {$agent_dialed_type=$_GET["agent_dialed_type"];}
  366. elseif (isset($_POST["agent_dialed_type"])) {$agent_dialed_type=$_POST["agent_dialed_type"];}
  367. if (isset($_GET["wrapup"])) {$wrapup=$_GET["wrapup"];}
  368. elseif (isset($_POST["wrapup"])) {$wrapup=$_POST["wrapup"];}
  369. if (isset($_GET["vtiger_callback_id"])) {$vtiger_callback_id=$_GET["vtiger_callback_id"];}
  370. elseif (isset($_POST["vtiger_callback_id"])) {$vtiger_callback_id=$_POST["vtiger_callback_id"];}
  371. header ("Content-type: text/html; charset=utf-8");
  372. header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  373. header ("Pragma: no-cache"); // HTTP/1.0
  374. $txt = '.txt';
  375. $StarTtime = date("U");
  376. $NOW_DATE = date("Y-m-d");
  377. $NOW_TIME = date("Y-m-d H:i:s");
  378. $CIDdate = date("mdHis");
  379. $ENTRYdate = date("YmdHis");
  380. $MT[0]='';
  381. $agents='@agents';
  382. #############################################
  383. ##### START SYSTEM_SETTINGS LOOKUP #####
  384. $stmt = "SELECT use_non_latin,timeclock_end_of_day FROM system_settings;";
  385. $rslt=mysql_query($stmt, $link);
  386. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00001',$user,$server_ip,$session_name,$one_mysql_log);}
  387. if ($DB) {echo "$stmt\n";}
  388. $qm_conf_ct = mysql_num_rows($rslt);
  389. $i=0;
  390. while ($i < $qm_conf_ct)
  391. {
  392. $row=mysql_fetch_row($rslt);
  393. $non_latin = $row[0];
  394. $timeclock_end_of_day = $row[1];
  395. $i++;
  396. }
  397. ##### END SETTINGS LOOKUP #####
  398. ###########################################
  399. if ($non_latin < 1)
  400. {
  401. $user=ereg_replace("[^0-9a-zA-Z]","",$user);
  402. $pass=ereg_replace("[^0-9a-zA-Z]","",$pass);
  403. $length_in_sec = ereg_replace("[^0-9]","",$length_in_sec);
  404. $phone_code = ereg_replace("[^0-9]","",$phone_code);
  405. $phone_number = ereg_replace("[^0-9]","",$phone_number);
  406. }
  407. # default optional vars if not set
  408. if (!isset($format)) {$format="text";}
  409. if ($format == 'debug') {$DB=1;}
  410. if (!isset($ACTION)) {$ACTION="refresh";}
  411. if (!isset($query_date)) {$query_date = $NOW_DATE;}
  412. if ($ACTION == 'LogiNCamPaigns')
  413. {
  414. $skip_user_validation=1;
  415. }
  416. else
  417. {
  418. $stmt="SELECT count(*) from vicidial_users where user='$user' and pass='$pass' and user_level > 0;";
  419. if ($DB) {echo "|$stmt|\n";}
  420. if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
  421. $rslt=mysql_query($stmt, $link);
  422. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00002',$user,$server_ip,$session_name,$one_mysql_log);}
  423. $row=mysql_fetch_row($rslt);
  424. $auth=$row[0];
  425. if( (strlen($user)<2) or (strlen($pass)<2) or ($auth==0))
  426. {
  427. echo "Invalid Username/Password: |$user|$pass|\n";
  428. exit;
  429. }
  430. else
  431. {
  432. if( (strlen($server_ip)<6) or (!isset($server_ip)) or ( (strlen($session_name)<12) or (!isset($session_name)) ) )
  433. {
  434. echo "Invalid server_ip: |$server_ip| or Invalid session_name: |$session_name|\n";
  435. exit;
  436. }
  437. else
  438. {
  439. $stmt="SELECT count(*) from web_client_sessions where session_name='$session_name' and server_ip='$server_ip';";
  440. if ($DB) {echo "|$stmt|\n";}
  441. $rslt=mysql_query($stmt, $link);
  442. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00003',$user,$server_ip,$session_name,$one_mysql_log);}
  443. $row=mysql_fetch_row($rslt);
  444. $SNauth=$row[0];
  445. if($SNauth==0)
  446. {
  447. echo "Invalid session_name: |$session_name|$server_ip|\n";
  448. exit;
  449. }
  450. else
  451. {
  452. # do nothing for now
  453. }
  454. }
  455. }
  456. }
  457. if ($format=='debug')
  458. {
  459. echo "<html>\n";
  460. echo "<head>\n";
  461. echo "<!-- VERSION: $version BUILD: $build USER: $user server_ip: $server_ip-->\n";
  462. echo "<title>VICIDiaL Database Query Script";
  463. echo "</title>\n";
  464. echo "</head>\n";
  465. echo "<BODY BGCOLOR=white marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>\n";
  466. }
  467. ################################################################################
  468. ### LogiNCamPaigns - generates an HTML SELECT list of allowed campaigns for a
  469. ### specific agent on the login screen
  470. ################################################################################
  471. if ($ACTION == 'LogiNCamPaigns')
  472. {
  473. if ( (strlen($user)<1) )
  474. {
  475. echo "<select size=1 name=VD_campaign id=VD_campaign onFocus=\"login_allowable_campaigns()\">\n";
  476. echo "<option value=\"\">-- ERROR --</option>\n";
  477. echo "</select>\n";
  478. exit;
  479. }
  480. else
  481. {
  482. $stmt="SELECT user_group,user_level,agent_shift_enforcement_override,shift_override_flag from vicidial_users where user='$user' and pass='$pass'";
  483. if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");}
  484. $rslt=mysql_query($stmt, $link);
  485. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00004',$user,$server_ip,$session_name,$one_mysql_log);}
  486. $row=mysql_fetch_row($rslt);
  487. $VU_user_group = $row[0];
  488. $VU_user_level = $row[1];
  489. $VU_agent_shift_enforcement_override = $row[2];
  490. $VU_shift_override_flag = $row[3];
  491. $LOGallowed_campaignsSQL='';
  492. $stmt="SELECT allowed_campaigns,forced_timeclock_login,shift_enforcement,group_shifts from vicidial_user_groups where user_group='$VU_user_group';";
  493. $rslt=mysql_query($stmt, $link);
  494. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00005',$user,$server_ip,$session_name,$one_mysql_log);}
  495. $row=mysql_fetch_row($rslt);
  496. $forced_timeclock_login = $row[1];
  497. $shift_enforcement = $row[2];
  498. $LOGgroup_shiftsSQL = eregi_replace(' ','',$row[3]);
  499. $LOGgroup_shiftsSQL = eregi_replace(' ',"','",$LOGgroup_shiftsSQL);
  500. $LOGgroup_shiftsSQL = "shift_id IN('$LOGgroup_shiftsSQL')";
  501. if ( (!eregi("ALL-CAMPAIGNS",$row[0])) )
  502. {
  503. $LOGallowed_campaignsSQL = eregi_replace(' -','',$row[0]);
  504. $LOGallowed_campaignsSQL = eregi_replace(' ',"','",$LOGallowed_campaignsSQL);
  505. $LOGallowed_campaignsSQL = "and campaign_id IN('$LOGallowed_campaignsSQL')";
  506. }
  507. $show_campaign_list=1;
  508. ### CHECK TO SEE IF AGENT IS LOGGED IN TO TIMECLOCK, IF NOT, OUTPUT ERROR
  509. if ( (ereg('Y',$forced_timeclock_login)) or ( (ereg('ADMIN_EXEMPT',$forced_timeclock_login)) and ($VU_user_level < 8) ) )
  510. {
  511. $last_agent_event='';
  512. $HHMM = date("Hi");
  513. $HHteod = substr($timeclock_end_of_day,0,2);
  514. $MMteod = substr($timeclock_end_of_day,2,2);
  515. if ($HHMM < $timeclock_end_of_day)
  516. {$EoD = mktime($HHteod, $MMteod, 10, date("m"), date("d")-1, date("Y"));}
  517. else
  518. {$EoD = mktime($HHteod, $MMteod, 10, date("m"), date("d"), date("Y"));}
  519. $EoDdate = date("Y-m-d H:i:s", $EoD);
  520. ##### grab timeclock logged-in time for each user #####
  521. $stmt="SELECT event from vicidial_timeclock_log where user='$user' and event_epoch >= '$EoD' order by timeclock_id desc limit 1;";
  522. if ($DB>0) {echo "|$stmt|";}
  523. $rslt=mysql_query($stmt, $link);
  524. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00184',$user,$server_ip,$session_name,$one_mysql_log);}
  525. $events_to_parse = mysql_num_rows($rslt);
  526. if ($events_to_parse > 0)
  527. {
  528. $rowx=mysql_fetch_row($rslt);
  529. $last_agent_event = $rowx[0];
  530. }
  531. if ( (strlen($last_agent_event)<2) or (ereg('LOGOUT',$last_agent_event)) )
  532. {$show_campaign_list=0;}
  533. }
  534. }
  535. ### CHECK TO SEE IF AGENT IS WITHIN THEIR SHIFT IF RESTRICTED, IF NOT, OUTPUT ERROR
  536. if ( ( (ereg("START|ALL",$shift_enforcement)) and (!ereg("OFF",$VU_agent_shift_enforcement_override)) ) or (ereg("START|ALL",$VU_agent_shift_enforcement_override)) )
  537. {
  538. $shift_ok=0;
  539. if ( (strlen($LOGgroup_shiftsSQL) < 3) and ($VU_shift_override_flag < 1) )
  540. {
  541. $VDdisplayMESSAGE = "<B>ERROR: There are no Shifts enabled for your user group</B>\n";
  542. $VDloginDISPLAY=1;
  543. }
  544. else
  545. {
  546. $HHMM = date("Hi");
  547. $wday = date("w");
  548. $stmt="SELECT shift_id,shift_start_time,shift_length,shift_weekdays from vicidial_shifts where $LOGgroup_shiftsSQL order by shift_id";
  549. $rslt=mysql_query($stmt, $link);
  550. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00193',$user,$server_ip,$session_name,$one_mysql_log);}
  551. $shifts_to_print = mysql_num_rows($rslt);
  552. $o=0;
  553. while ( ($shifts_to_print > $o) and ($shift_ok < 1) )
  554. {
  555. $rowx=mysql_fetch_row($rslt);
  556. $shift_id = $rowx[0];
  557. $shift_start_time = $rowx[1];
  558. $shift_length = $rowx[2];
  559. $shift_weekdays = $rowx[3];
  560. if (eregi("$wday",$shift_weekdays))
  561. {
  562. $HHshift_length = substr($shift_length,0,2);
  563. $MMshift_length = substr($shift_length,3,2);
  564. $HHshift_start_time = substr($shift_start_time,0,2);
  565. $MMshift_start_time = substr($shift_start_time,2,2);
  566. $HHshift_end_time = ($HHshift_length + $HHshift_start_time);
  567. $MMshift_end_time = ($MMshift_length + $MMshift_start_time);
  568. if ($MMshift_end_time > 59)
  569. {
  570. $MMshift_end_time = ($MMshift_end_time - 60);
  571. $HHshift_end_time++;
  572. }
  573. if ($HHshift_end_time > 23)
  574. {$HHshift_end_time = ($HHshift_end_time - 24);}
  575. $HHshift_end_time = sprintf("%02s", $HHshift_end_time);
  576. $MMshift_end_time = sprintf("%02s", $MMshift_end_time);
  577. $shift_end_time = "$HHshift_end_time$MMshift_end_time";
  578. if (
  579. ( ($HHMM >= $shift_start_time) and ($HHMM < $shift_end_time) ) or
  580. ( ($HHMM < $shift_start_time) and ($HHMM < $shift_end_time) and ($shift_end_time <= $shift_start_time) ) or
  581. ( ($HHMM >= $shift_start_time) and ($HHMM >= $shift_end_time) and ($shift_end_time <= $shift_start_time) )
  582. )
  583. {$shift_ok++;}
  584. }
  585. $o++;
  586. }
  587. if ( ($shift_ok < 1) and ($VU_shift_override_flag < 1) )
  588. {
  589. $VDdisplayMESSAGE = "<B>ERROR: You are not allowed to log in outside of your shift</B>\n";
  590. $VDloginDISPLAY=1;
  591. }
  592. }
  593. if ($VDloginDISPLAY > 0)
  594. {
  595. $loginDATE = date("Ymd");
  596. $VDdisplayMESSAGE.= "<BR><BR>MANAGER OVERRIDE:<BR>\n";
  597. $VDdisplayMESSAGE.= "<FORM ACTION=\"$PHP_SELF\" METHOD=POST>\n";
  598. $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=MGR_override VALUE=\"1\">\n";
  599. $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=relogin VALUE=\"YES\">\n";
  600. $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=VD_login VALUE=\"$user\">\n";
  601. $VDdisplayMESSAGE.= "<INPUT TYPE=HIDDEN NAME=VD_pass VALUE=\"$pass\">\n";
  602. $VDdisplayMESSAGE.= "Manager Login: <INPUT TYPE=TEXT NAME=\"MGR_login$loginDATE\" SIZE=10 MAXLENGTH=20><br>\n";
  603. $VDdisplayMESSAGE.= "Manager Password: <INPUT TYPE=PASSWORD NAME=\"MGR_pass$loginDATE\" SIZE=10 MAXLENGTH=20><br>\n";
  604. $VDdisplayMESSAGE.= "<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=SUBMIT></FORM><BR><BR><BR><BR>\n";
  605. echo "$VDdisplayMESSAGE";
  606. exit;
  607. }
  608. }
  609. if ($show_campaign_list > 0)
  610. {
  611. $stmt="SELECT campaign_id,campaign_name from vicidial_campaigns where active='Y' $LOGallowed_campaignsSQL order by campaign_id";
  612. $rslt=mysql_query($stmt, $link);
  613. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00006',$user,$server_ip,$session_name,$one_mysql_log);}
  614. $camps_to_print = mysql_num_rows($rslt);
  615. echo "<select size=1 name=VD_campaign id=VD_campaign>\n";
  616. echo "<option value=\"\">-- PLEASE SELECT A CAMPAIGN --</option>\n";
  617. $o=0;
  618. while ($camps_to_print > $o)
  619. {
  620. $rowx=mysql_fetch_row($rslt);
  621. echo "<option value=\"$rowx[0]\">$rowx[0] - $rowx[1]</option>\n";
  622. $o++;
  623. }
  624. echo "</select>\n";
  625. }
  626. else
  627. {
  628. echo "<select size=1 name=VD_campaign id=VD_campaign onFocus=\"login_allowable_campaigns()\">\n";
  629. echo "<option value=\"\">-- YOU MUST LOG IN TO THE TIMECLOCK FIRST --</option>\n";
  630. echo "</select>\n";
  631. }
  632. exit;
  633. }
  634. ################################################################################
  635. ### regCLOSER - update the vicidial_live_agents table to reflect the closer
  636. ### inbound choices made upon login
  637. ################################################################################
  638. if ($ACTION == 'regCLOSER')
  639. {
  640. $row=''; $rowx='';
  641. $channel_live=1;
  642. if ( (strlen($closer_choice)<1) || (strlen($user)<1) )
  643. {
  644. $channel_live=0;
  645. echo "Group Choice $closer_choice is not valid\n";
  646. exit;
  647. }
  648. else
  649. {
  650. if ($closer_choice == "MGRLOCK-")
  651. {
  652. $stmt="SELECT closer_campaigns FROM vicidial_users where user='$user' LIMIT 1;";
  653. $rslt=mysql_query($stmt, $link);
  654. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00007',$user,$server_ip,$session_name,$one_mysql_log);}
  655. if ($DB) {echo "$stmt\n";}
  656. $row=mysql_fetch_row($rslt);
  657. $closer_choice =$row[0];
  658. $stmt="UPDATE vicidial_live_agents set closer_campaigns='$closer_choice' where user='$user' and server_ip='$server_ip';";
  659. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  660. $rslt=mysql_query($stmt, $link);
  661. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00008',$user,$server_ip,$session_name,$one_mysql_log);}
  662. }
  663. else
  664. {
  665. $stmt="UPDATE vicidial_live_agents set closer_campaigns='$closer_choice' where user='$user' and server_ip='$server_ip';";
  666. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  667. $rslt=mysql_query($stmt, $link);
  668. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00009',$user,$server_ip,$session_name,$one_mysql_log);}
  669. $stmt="UPDATE vicidial_users set closer_campaigns='$closer_choice' where user='$user';";
  670. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  671. $rslt=mysql_query($stmt, $link);
  672. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00010',$user,$server_ip,$session_name,$one_mysql_log);}
  673. }
  674. $stmt="INSERT INTO vicidial_user_closer_log set user='$user',campaign_id='$campaign',event_date='$NOW_TIME',blended='$closer_blended',closer_campaigns='$closer_choice';";
  675. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  676. $rslt=mysql_query($stmt, $link);
  677. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00011',$user,$server_ip,$session_name,$one_mysql_log);}
  678. $stmt="DELETE FROM vicidial_live_inbound_agents where user='$user';";
  679. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  680. $rslt=mysql_query($stmt, $link);
  681. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00012',$user,$server_ip,$session_name,$one_mysql_log);}
  682. $in_groups_pre = preg_replace('/-$/','',$closer_choice);
  683. $in_groups = explode(" ",$in_groups_pre);
  684. $in_groups_ct = count($in_groups);
  685. $k=1;
  686. while ($k < $in_groups_ct)
  687. {
  688. if (strlen($in_groups[$k])>1)
  689. {
  690. $stmt="SELECT group_weight,calls_today FROM vicidial_inbound_group_agents where user='$user' and group_id='$in_groups[$k]';";
  691. $rslt=mysql_query($stmt, $link);
  692. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00013',$user,$server_ip,$session_name,$one_mysql_log);}
  693. if ($DB) {echo "$stmt\n";}
  694. $viga_ct = mysql_num_rows($rslt);
  695. if ($viga_ct > 0)
  696. {
  697. $row=mysql_fetch_row($rslt);
  698. $group_weight = $row[0];
  699. $calls_today = $row[1];
  700. }
  701. else
  702. {
  703. $group_weight = 0;
  704. $calls_today = 0;
  705. }
  706. $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';";
  707. if ($format=='debug') {echo "\n<!-- $stmt -->";}
  708. $rslt=mysql_query($stmt, $link);
  709. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00014',$user,$server_ip,$session_name,$one_mysql_log);}
  710. }
  711. $k++;
  712. }
  713. }
  714. echo "Closer In Group Choice $closer_choice has been registered to user $user\n";
  715. }
  716. ################################################################################
  717. ### manDiaLnextCALL - for manual VICIDiaL dialing this will grab the next lead
  718. ### in the campaign, reserve it, send data back to client and
  719. ### place the call by inserting into vicidial_manager
  720. ################################################################################
  721. if ($ACTION == 'manDiaLnextCaLL')
  722. {
  723. $MT[0]='';
  724. $row=''; $rowx='';
  725. $channel_live=1;
  726. if ( (strlen($conf_exten)<1) || (strlen($campaign)<1) || (strlen($ext_context)<1) )
  727. {
  728. $channel_live=0;
  729. echo "HOPPER EMPTY\n";
  730. echo "Conf Exten $conf_exten or campaign $campaign or ext_context $ext_context is not valid\n";
  731. exit;
  732. }
  733. else
  734. {
  735. ##### grab number of calls today in this campaign and increment
  736. $stmt="SELECT calls_today FROM vicidial_live_agents WHERE user='$user' and campaign_id='$campaign';";
  737. $rslt=mysql_query($stmt, $link);
  738. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00015',$user,$server_ip,$session_name,$one_mysql_log);}
  739. if ($DB) {echo "$stmt\n";}
  740. $vla_cc_ct = mysql_num_rows($rslt);
  741. if ($vla_cc_ct > 0)
  742. {
  743. $row=mysql_fetch_row($rslt);
  744. $calls_today =$row[0];
  745. }
  746. else
  747. {$calls_today ='0';}
  748. $calls_today++;
  749. ### check if this is a callback, if it is, skip the grabbing of a new lead and mark the callback as INACTIVE
  750. if ( (strlen($callback_id)>0) and (strlen($lead_id)>0) )
  751. {
  752. $affected_rows=1;
  753. $CBleadIDset=1;
  754. $stmt = "UPDATE vicidial_callbacks set status='INACTIVE' where callback_id='$callback_id';";
  755. if ($DB) {echo "$stmt\n";}
  756. $rslt=mysql_query($stmt, $link);
  757. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00016',$user,$server_ip,$session_name,$one_mysql_log);}
  758. }
  759. else
  760. {
  761. if (strlen($phone_number)>3)
  762. {
  763. if (ereg("DNC",$manual_dial_filter))
  764. {
  765. $stmt="SELECT count(*) FROM vicidial_dnc where phone_number='$phone_number';";
  766. $rslt=mysql_query($stmt, $link);
  767. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00017',$user,$server_ip,$session_name,$one_mysql_log);}
  768. if ($DB) {echo "$stmt\n";}
  769. $row=mysql_fetch_row($rslt);
  770. if ($row[0] > 0)
  771. {
  772. echo "DNC NUMBER\n";
  773. exit;
  774. }
  775. $stmt="SELECT count(*) FROM vicidial_campaign_dnc where phone_number='$phone_number' and campaign_id='$campaign';";
  776. $rslt=mysql_query($stmt, $link);
  777. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00018',$user,$server_ip,$session_name,$one_mysql_log);}
  778. if ($DB) {echo "$stmt\n";}
  779. $row=mysql_fetch_row($rslt);
  780. if ($row[0] > 0)
  781. {
  782. echo "DNC NUMBER\n";
  783. exit;
  784. }
  785. }
  786. if (ereg("CAMPLISTS",$manual_dial_filter))
  787. {
  788. $stmt="SELECT list_id,active from vicidial_lists where campaign_id='$campaign'";
  789. $rslt=mysql_query($stmt, $link);
  790. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00019',$user,$server_ip,$session_name,$one_mysql_log);}
  791. $lists_to_parse = mysql_num_rows($rslt);
  792. $camp_lists='';
  793. $o=0;
  794. while ($lists_to_parse > $o)
  795. {
  796. $rowx=mysql_fetch_row($rslt);
  797. if (ereg("Y", $rowx[1])) {$active_lists++; $camp_lists .= "'$rowx[0]',";}
  798. if (ereg("N", $rowx[1])) {$inactive_lists++;}
  799. $o++;
  800. }
  801. $camp_lists = eregi_replace(".$","",$camp_lists);
  802. $stmt="SELECT count(*) FROM vicidial_list where phone_number='$phone_number' and list_id IN($camp_lists);";
  803. $rslt=mysql_query($stmt, $link);
  804. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00020',$user,$server_ip,$session_name,$one_mysql_log);}
  805. if ($DB) {echo "$stmt\n";}
  806. $row=mysql_fetch_row($rslt);
  807. if ($row[0] < 1)
  808. {
  809. echo "NUMBER NOT IN CAMPLISTS\n";
  810. exit;
  811. }
  812. }
  813. if ($stage=='lookup')
  814. {
  815. if (strlen($vendor_lead_code)>0)
  816. {
  817. $stmt="SELECT lead_id FROM vicidial_list where vendor_lead_code='$vendor_lead_code' order by modify_date desc LIMIT 1;";
  818. $rslt=mysql_query($stmt, $link);
  819. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);}
  820. if ($DB) {echo "$stmt\n";}
  821. $man_leadID_ct = mysql_num_rows($rslt);
  822. if ( ($man_leadID_ct > 0) and (strlen($phone_number) > 5) )
  823. {$override_phone++;}
  824. }
  825. else
  826. {
  827. $stmt="SELECT lead_id FROM vicidial_list where phone_number='$phone_number' order by modify_date desc LIMIT 1;";
  828. $rslt=mysql_query($stmt, $link);
  829. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00021',$user,$server_ip,$session_name,$one_mysql_log);}
  830. if ($DB) {echo "$stmt\n";}
  831. $man_leadID_ct = mysql_num_rows($rslt);
  832. }
  833. if ($man_leadID_ct > 0)
  834. {
  835. $row=mysql_fetch_row($rslt);
  836. $affected_rows=1;
  837. $lead_id =$row[0];
  838. $CBleadIDset=1;
  839. }
  840. else
  841. {
  842. ### insert a new lead in the system with this phone number
  843. $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';";
  844. if ($DB) {echo "$stmt\n";}
  845. $rslt=mysql_query($stmt, $link);
  846. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00022',$user,$server_ip,$session_name,$one_mysql_log);}
  847. $affected_rows = mysql_affected_rows($link);
  848. $lead_id = mysql_insert_id($link);
  849. $CBleadIDset=1;
  850. }
  851. }
  852. else
  853. {
  854. ### insert a new lead in the system with this phone number
  855. $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';";
  856. if ($DB) {echo "$stmt\n";}
  857. $rslt=mysql_query($stmt, $link);
  858. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00023',$user,$server_ip,$session_name,$one_mysql_log);}
  859. $affected_rows = mysql_affected_rows($link);
  860. $lead_id = mysql_insert_id($link);
  861. $CBleadIDset=1;
  862. }
  863. }
  864. else
  865. {
  866. ### grab the next lead in the hopper for this campaign and reserve it for the user
  867. $stmt = "UPDATE vicidial_hopper set status='QUEUE', user='$user' where campaign_id='$campaign' and status='READY' order by priority desc,hopper_id LIMIT 1";
  868. if ($DB) {echo "$stmt\n";}
  869. $rslt=mysql_query($stmt, $link);
  870. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00024',$user,$server_ip,$session_name,$one_mysql_log);}
  871. $affected_rows = mysql_affected_rows($link);
  872. }
  873. }
  874. if ($affected_rows > 0)
  875. {
  876. if (!$CBleadIDset)
  877. {
  878. ##### grab the lead_id of the reserved user in vicidial_hopper
  879. $stmt="SELECT lead_id FROM vicidial_hopper where campaign_id='$campaign' and status='QUEUE' and user='$user' LIMIT 1;";
  880. $rslt=mysql_query($stmt, $link);
  881. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00025',$user,$server_ip,$session_name,$one_mysql_log);}
  882. if ($DB) {echo "$stmt\n";}
  883. $hopper_leadID_ct = mysql_num_rows($rslt);
  884. if ($hopper_leadID_ct > 0)
  885. {
  886. $row=mysql_fetch_row($rslt);
  887. $lead_id =$row[0];
  888. }
  889. }
  890. ##### grab the data from vicidial_list for the lead_id
  891. $stmt="SELECT * FROM vicidial_list where lead_id='$lead_id' LIMIT 1;";
  892. $rslt=mysql_query($stmt, $link);
  893. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00026',$user,$server_ip,$session_name,$one_mysql_log);}
  894. if ($DB) {echo "$stmt\n";}
  895. $list_lead_ct = mysql_num_rows($rslt);
  896. if ($list_lead_ct > 0)
  897. {
  898. $row=mysql_fetch_row($rslt);
  899. # $lead_id = trim("$row[0]");
  900. $dispo = trim("$row[3]");
  901. $tsr = trim("$row[4]");
  902. $vendor_id = trim("$row[5]");
  903. $source_id = trim("$row[6]");
  904. $list_id = trim("$row[7]");
  905. $gmt_offset_now = trim("$row[8]");
  906. $called_since_last_reset = trim("$row[9]");
  907. $phone_code = trim("$row[10]");
  908. if ($override_phone < 1)
  909. {$phone_number = trim("$row[11]");}
  910. $title = trim("$row[12]");
  911. $first_name = trim("$row[13]");
  912. $middle_initial = trim("$row[14]");
  913. $last_name = trim("$row[15]");
  914. $address1 = trim("$row[16]");
  915. $address2 = trim("$row[17]");
  916. $address3 = trim("$row[18]");
  917. $city = trim("$row[19]");
  918. $state = trim("$row[20]");
  919. $province = trim("$row[21]");
  920. $postal_code = trim("$row[22]");
  921. $country_code = trim("$row[23]");
  922. $gender = trim("$row[24]");
  923. $date_of_birth = trim("$row[25]");
  924. $alt_phone = trim("$row[26]");
  925. $email = trim("$row[27]");
  926. $security = trim("$row[28]");
  927. $comments = stripslashes(trim("$row[29]"));
  928. $called_count = trim("$row[30]");
  929. }
  930. $called_count++;
  931. ##### check if system is set to generate logfile for transfers
  932. $stmt="SELECT enable_agc_xfer_log FROM system_settings;";
  933. $rslt=mysql_query($stmt, $link);
  934. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00027',$user,$server_ip,$session_name,$one_mysql_log);}
  935. if ($DB) {echo "$stmt\n";}
  936. $enable_agc_xfer_log_ct = mysql_num_rows($rslt);
  937. if ($enable_agc_xfer_log_ct > 0)
  938. {
  939. $row=mysql_fetch_row($rslt);
  940. $enable_agc_xfer_log =$row[0];
  941. }
  942. if ( ($WeBRooTWritablE > 0) and ($enable_agc_xfer_log > 0) )
  943. {
  944. # generate callerID for unique identifier in xfer_log file
  945. $PADlead_id = sprintf("%09s", $lead_id);
  946. while (strlen($PADlead_id) > 9) {$PADlead_id = substr("$PADlead_id", 0, -1);}
  947. # Create unique calleridname to track the call: MmmddhhmmssLLLLLLLLL
  948. $MqueryCID = "M$CIDdate$PADlead_id";
  949. # DATETIME|campaign|lead_id|phone_number|user|type
  950. # 2007-08-22 11:11:11|TESTCAMP|65432|3125551212|1234|M
  951. $fp = fopen ("./xfer_log.txt", "a");
  952. fwrite ($fp, "$NOW_TIME|$campaign|$lead_id|$phone_number|$user|M|$MqueryCID|\n");
  953. fclose($fp);
  954. }
  955. ##### if lead is a callback, grab the callback comments
  956. $CBentry_time = '';
  957. $CBcallback_time = '';
  958. $CBuser = '';
  959. $CBcomments = '';
  960. if (ereg("CALLBK",$dispo))
  961. {
  962. $stmt="SELECT entry_time,callback_time,user,comments FROM vicidial_callbacks where lead_id='$lead_id' order by callback_id desc LIMIT 1;";
  963. $rslt=mysql_query($stmt, $link);
  964. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00028',$user,$server_ip,$session_name,$one_mysql_log);}
  965. if ($DB) {echo "$stmt\n";}
  966. $cb_record_ct = mysql_num_rows($rslt);
  967. if ($cb_record_ct > 0)
  968. {
  969. $row=mysql_fetch_row($rslt);
  970. $CBentry_time = trim("$row[0]");
  971. $CBcallback_time = trim("$row[1]");
  972. $CBuser = trim("$row[2]");
  973. $CBcomments = trim("$row[3]");
  974. }
  975. }
  976. $stmt = "SELECT local_gmt FROM servers where active='Y' limit 1;";
  977. $rslt=mysql_query($stmt, $link);
  978. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00029',$user,$server_ip,$session_name,$one_mysql_log);}
  979. if ($DB) {echo "$stmt\n";}
  980. $server_ct = mysql_num_rows($rslt);
  981. if ($server_ct > 0)
  982. {
  983. $row=mysql_fetch_row($rslt);
  984. $local_gmt = $row[0];
  985. }
  986. $LLCT_DATE_offset = ($local_gmt - $gmt_offset_now);
  987. $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")));
  988. if (ereg('Y',$called_since_last_reset))
  989. {
  990. $called_since_last_reset = ereg_replace('Y','',$called_since_last_reset);
  991. if (strlen($called_since_last_reset) < 1) {$called_since_last_reset = 0;}
  992. $called_since_last_reset++;
  993. $called_since_last_reset = "Y$called_since_last_reset";
  994. }
  995. else {$called_since_last_reset = 'Y';}
  996. ### flag the lead as called and change it's status to INCALL
  997. $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';";
  998. if ($DB) {echo "$stmt\n";}
  999. $rslt=mysql_query($stmt, $link);
  1000. if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00030',$user,$server_ip,$session_name,$on…