-
Notifications
You must be signed in to change notification settings - Fork 9
/
agi-VDAD_ALL_inbound.agi
executable file
·5354 lines (4808 loc) · 222 KB
/
agi-VDAD_ALL_inbound.agi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
#
# agi-VDAD_ALL_inbound.agi version 2.6
#
# runs when a call comes in from an inbound call. This script will
# send the calls out to the closers that are logged in.
# ## THIS SCRIPT CONSOLIDATES THIRTEEN SEPARATE VDAD closer inbound SCRIPTS ##
#
#
# You need to put lines similar to those below in your extensions.conf file:
# ; Below are the parameters needed for the script to be run properly
# ; 1. the method of call handling for the script:
# ; - CID - CID received, add record with phone number
# ; - CIDLOOKUP - Lookup CID to find record in whole system
# ; - CIDLOOKUPRL - Restrict lookup to one list
# ; - CIDLOOKUPRC - Restrict lookup to one campaign's lists
# ; - CIDLOOKUPALT - Lookup CID to find record in whole system by phone number then alt_phone
# ; - CIDLOOKUPRLALT - Restrict lookup to one list by phone number then alt_phone
# ; - CIDLOOKUPRCALT - Restrict lookup to one campaign's lists by phone number then alt_phone
# ; - CIDLOOKUPADDR3 - Lookup CID to find record in whole system by phone number then address3
# ; - CIDLOOKUPRLADDR3 - Restrict lookup to one list by phone number then address3
# ; - CIDLOOKUPRCADDR3 - Restrict lookup to one campaign's lists by phone number then address3
# ; - CIDLOOKUPALTADDR3 - Lookup CID to find record in whole system by phone number then alt_phone then address3
# ; - CIDLOOKUPRLALTADDR3 - Restrict lookup to one list by phone number then alt_phone then address3
# ; - CIDLOOKUPRCALTADDR3 - Restrict lookup to one campaign's lists by phone number then alt_phone then address3
# ; - CLOSER - Closer calls from VICIDIAL fronters(and previous in-group calls)
# ; - ANI - ANI received, add record with phone number (based on RBS T1s)
# ; - ANILOOKUP - Lookup ANI to find record in whole system
# ; - ANILOOKUPRL - Restrict lookup to one list
# ; - ANILOOKUPRC - Restrict lookup to one campaign's lists
# ; - VID - Add record with Vendor Lead Code received as argument 12
# ; - VIDLOOKUP - Lookup Vendor Lead Code received as argument 12 to find record in whole system
# ; - VIDLOOKUPRL - Restrict lookup to one list (argument 12)
# ; - VIDLOOKUPRC - Restrict lookup to one campaign's lists (argument 12)
# ; - VIDPROMPT - Prompt Vendor Lead Code to User with IVR to add record with Vendor Lead Code
# ; - VIDPROMPTLOOKUP - Prompt Vendor Lead Code to User with IVR to find record in whole system
# ; - VIDPROMPTLOOKUPRL - Restrict lookup to one list
# ; - VIDPROMPTLOOKUPRC - Restrict lookup to one campaign's lists
# ; - 3DIGITID - Enter 3 digit code to go to agent
# ; - 4DIGITID - Enter 4 digit code to go to agent
# ; - XDIGITID - Enter X digit code to go to agent(variable, i.e. 9DIGITID, 12DIGITID, etc...)
# ; 2. the method of searching for an available agent:
# ; - LO - Load Balance Overflow only (priority to home server)
# ; - LB - <default> Load Balance total system
# ; - SO - Home server only
# ; 3. the full name of the IN GROUP to be used in vicidial for the inbound call
# ; 4. the phone number that was called, for the log entry
# ; 5. the callerID or lead_id of the person that called(usually overridden)
# ; 6. the park extension audio file name if used
# ; 7. the status of the call initially(usually not used)
# ; 8. the list_id to insert the new lead under if it is new (and CID/ANI available)
# ; 9. the phone dialing code to insert with the new lead if new (and CID/ANI available)
# ; 10. the campaign_id to search within lists if CIDLOOKUPRC
# ; 11. the user to queue the call to for AGENTDIRECT in-group calls
# ; 12. vendor_lead_code if external mechanism like custom IVR is used to prompt user for ID
# ; you can also set the vendor_lead_code variable instead if you are using VIDPROMPT
# ; 13. VID enter prompt filename to play if method is set to a VID* option
# ; 14. VID you-have-entered filename to play if method is set to a VID* option
# ; 15. VID confirm prompt filename to play if method is set to a VID* option
# ; 16. VID digit length validation to use if method is set to a VID* option, set to empty or X to disable
#
# ;inbound VICIDIAL calls:
#exten => 1234,1,Answer ; Answer the line
#exten => 1234,2,AGI(agi-VDAD_ALL_inbound.agi,CID-----LB-----INB-----7274515134-----Closer-----park----------999-----1-----OUTB)
#exten => 1234,3,Hangup
#
# ;inbound with removal of first digit of callerID on all calls:
#exten => 1234,1,Answer ; Answer the line
#exten => 1234,n,set(CALLERID(num)=${CALLERID(num):1})
#exten => 1234,n,AGI(agi-VDAD_ALL_inbound.agi,CID-----LB-----INB-----7274515134-----Closer-----park----------999-----1-----OUTB)
#exten => 1234,n,Hangup
#
#; inbound VICIDIAL transfer calls [can arrive through PRI T1 crossover, IAX or SIP channel]
#exten => _90009.,1,Answer ; Answer the line
#exten => _90009.,2,AGI(agi-VDAD_ALL_inbound.agi,CLOSER-----LB-----CL_TESTCAMP-----7275551212-----Closer-----park----------999-----1)
#exten => _90009.,3,Hangup
#exten => _990009.,1,Answer ; Answer the line
#exten => _990009.,2,AGI(agi-VDAD_ALL_inbound.agi,CLOSER-----LB-----CL_TESTCAMP-----7275551212-----Closer-----park----------999-----1)
#exten => _990009.,3,Hangup
#; DID forwarded calls
#exten => _99909*.,1,Answer
#exten => _99909*.,2,AGI(agi-VDAD_ALL_inbound.agi)
#exten => _99909*.,3,Hangup
#
# Copyright (C) 2013 Matt Florell <[email protected]> LICENSE: AGPLv2
#
# changes:
# 70828-0924 - First Build
# 71013-0310 - Added use of default Music-on-hold instead of generic on-hold message
# 71020-1714 - fixed issues with MoH and stream_file messages
# 71024-2153 - Added CLOSER functionality for calls coming from VICIDIAL fronters
# 71029-1726 - Changed CLOSER-type campaigns to use new campaign_allow_inbound field
# 71030-0713 - fixed after-hours logging
# 71030-0939 - fixed issue where MoH was still playing, added ding and wait before transfer
# 71103-2305 - added group rank and fewest calls options to next_agent_call
# 71112-0058 - fixed multi-logging bug on CLOSER calls
# 71116-1045 - added fewest_calls_campaign agent call routing option
# 71128-1758 - added CIDLOOKUPRC method to search all lists within a campaign
# 80109-2348 - added option to trigger a system process when the call is sent to an agent
# 80227-0335 - added queue priority functionality
# 80302-0232 - added drop_action and transfer to in-group
# 80402-0142 - added code for manual dial transfer duplicate check
# 80430-1144 - added term_reason to vicidial_closer_log, QUEUETIMEOUT, AFTERHOURS
# 80501-0515 - added after hours transfer in-group
# 80525-1040 - added ability to convert IVR status inbound calls to LIVE in-group calls
# 80630-2232 - added queue_log logging of inbound calls
# 80821-0133 - fixed non-play issue with hold message
# 80918-0505 - Added place in line and estimated time on hold
# 81002-1120 - Added processing for DID forwarded calls
# 81011-1019 - Added option for press 1 to leave voicemail if wait time > hold-time-option-seconds
# 81020-0237 - Added term_reason logging for all possible exits of the script
# 81021-2315 - Changed and add queue_log logging
# 81024-0006 - Changed LOOKUP to insert new lead if phone_number < 3 digits, changed queue_sec calculation
# 81104-0301 - Changed code to alter callerIDnumber for remote agents to the number of the caller
# 81105-0248 - Added MySQL error logging
# 90103-0311 - Added sip-silences before transfers to fix rare MoH issues
# 90115-0601 - Added AGENTDIRECT functionality
# 90607-1717 - Fix for AGENTDIRECT bug under certain configurations
# 90623-0724 - Changed prompts to multi-file prompts, changed agent alert exten to a prompt
# 90627-0546 - Added no-agent-no-queue options
# 90702-2129 - Fixed rare agent alert bug, added option to send to remote agent as phone*vendor_id
# 90709-1648 - Fixed alt-number transfers
# 90712-2307 - Added agent grab call in queue
# 90720-0023 - Added checks for filename validity before streaming, changed initial heavy search from 3 to 2 seconds
# 90726-0114 - Fixed bug on some calls for agent grab
# 90808-0307 - Added longest_wait_time as agent routing option
# 91004-0959 - Fix for queue_log consultative transfers
# 91105-1258 - Added CallerIDnumber change on Drop when sending call out
# 91122-2352 - Added queue_log IVR and DID entry linking
# 91125-0921 - Fixed no-agent-no-queue AGENTDIRECT bug
# 91213-0942 - Added queue_position to queue_log COMPLETE... records
# 91214-2034 - Fixes for rare in-group rank route bug
# 91223-0959 - Added VID(vendor_lead_code) options
# 91230-0911 - Reset to original callerID when sending the call to VMAIL/CALLMENU/PHONE/etc...
# 100121-1954 - Added TIMEOT/AFTHRS/NANQUE dropping event statuses
# 100123-1015 - Added voicemail_id lookup for user from AGENTDIRECT drop
# 100212-0653 - Added AGENTVMAIL AGENTDIRECT option for no-queue, hold time and after hours features
# 100226-0927 - Fixed reinsert issue in vicidial_auto_calls table with auto_call_id
# 100319-0614 - Added extension group remote agent feature
# 100414-2046 - Added extension_appended_cidname option
# 100424-1234 - Added unique status options and extended logging
# 100429-1457 - Remote agent fixes
# 100512-2118 - Added several press-1 hold time options
# 100513-2338 - Changed hold time callback filename to after press filename and now plays after all PRESS-1
# 100518-0710 - Added call time after hours override options
# 100527-0111 - Added on-hold and hold-time-option no-block options and message seconds, NA CID cleaning
# 100616-1600 - Added VID filename and digit validation options
# 100718-1822 - Added second hold time option and wait time options
# 100805-1530 - Added FILTER from-did-route feature, changed active=n to go to after hours action
# 100811-0751 - Added calculate_estimated_hold_seconds option
# 100830-1445 - Allow the changing of the queue priority of a call while the call is in queue
# 100903-0041 - Changed lead_id max length to 10 digits
# 100929-1201 - Added add_lead_url feature
# 101008-0410 - Added option for alternate Minimum Hold Time Message
# 101219-2110 - Added call time overflow
# 110224-1735 - Added compatibility with QM phone environment logging
# 110303-2338 - Added on-hook agent compatibility and rewrote a few sections
# 110324-2330 - Added recording of remote agent calls, per in-group and campaign recording settings
# 110325-1409 - Added user recording override settings checking for remote agent recording
# 110505-1620 - Fixed minor voicemail issue
# 110525-1555 - Added CLOSER compatibility with outbound and in-group calls that went through Call Menu
# 110626-2343 - Added queuemetrics_pe_phone_append
# 110707-0646 - Added AGENTEXT option in drop message to send to extension(user_custom_five) field
# 110707-1302 - Added last_inbound_call_time and finish to next agent call options
# 110731-0141 - Added call_id variable to add_lead_url function calls
# 110801-0841 - Added on_hook_cid option and group_calldate field
# 110822-1256 - Added optional did_agent_log logging
# 110920-1426 - Small fix for rare remote agent recording issue
# 110922-2149 - Added compatibility with DID remote agent extension overrides
# 110923-1133 - Added drop and after-hours to callmenu, and added action transfer cid setting
# 111102-2014 - Added in-group max_calls_ feature
# 111116-0157 - Added ALT and ADDR3 methods for CIDLOOKUP
# 111201-1457 - Added grade-random next-agent-call option for inbound
# 111219-2124 - Added max stats updating
# 111229-1726 - Changed call time overflow to look at previous day stop time
# 120130-1708 - Fix for ring agent EXTERNAL protocol phone issue
# 120430-2214 - Converted call to Monitor app to be asterisk 1.8 compatible
# 120430-2237 - For AGI commands not made through the AGI object added a read from STDIN before calling checkresult
# 120513-0051 - Added ability to have Dial In-Group agent calls go directly to agents
# 120514-0953 - Added force checks for dial-ingroup calls
# 121025-2210 - If AGENTDIRECT and no agent defined, set drop call seconds to 1
# 121114-1936 - Added INGROUP recording option
# 121120-0921 - Added QM socket-send functionality
# 121124-1345 - Added call times holidays function
# 121129-1618 - Small fix for estimated hold time, excluding QUEUE status
# 130108-1804 - Changes for Asterisk 1.8 compatibility
#
$script = 'agi-VDAD_ALL_inbound.agi';
$dtmf_silent_prefix = '7';
$DROP_TIME = 720; ### default number of seconds to wait until you drop a waiting call
$start_moh=1;
$wait_prompt_runs=0;
$at='@';
$S='*';
$mel=1; # Mysql Error Log enabled = 1
$mysql_log_count=195;
$one_mysql_log=0;
$dial_ingroup_flag=0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($mon < 10) {$mon = "0$mon";}
if ($mday < 10) {$mday = "0$mday";}
if ($hour < 10) {$hour = "0$hour";}
if ($min < 10) {$min = "0$min";}
if ($sec < 10) {$sec = "0$sec";}
$hm = "$hour$min";
$hm = ($hm + 0);
$now_date_epoch = time();
$start_epoch = $now_date_epoch;
$now_date = "$year-$mon-$mday $hour:$min:$sec";
$CLInow_date = "$year-$mon-$mday\\ $hour:$min:$sec";
$YMD = "$year-$mon-$mday";
$start_time=$now_date;
$CIDdate = "$mon$mday$hour$min$sec";
$tsSQLdate = "$year$mon$mday$hour$min$sec";
$SQLdate = "$year-$mon-$mday $hour:$min:$sec";
$SQLdateBEGIN = $SQLdate;
$ORIGINAL_call_time = $SQLdate;
while (length($CIDdate) > 9) {$CIDdate =~ s/^.//gi;} # 0902235959 changed to 902235959
$BDtarget = ($now_date_epoch - 5);
($Bsec,$Bmin,$Bhour,$Bmday,$Bmon,$Byear,$Bwday,$Byday,$Bisdst) = localtime($BDtarget);
$Byear = ($Byear + 1900);
$Bmon++;
if ($Bmon < 10) {$Bmon = "0$Bmon";}
if ($Bmday < 10) {$Bmday = "0$Bmday";}
if ($Bhour < 10) {$Bhour = "0$Bhour";}
if ($Bmin < 10) {$Bmin = "0$Bmin";}
if ($Bsec < 10) {$Bsec = "0$Bsec";}
$BDtsSQLdate = "$Byear$Bmon$Bmday$Bhour$Bmin$Bsec";
# default path to astguiclient configuration file:
$PATHconf = '/etc/astguiclient.conf';
open(conf, "$PATHconf") || die "can't open $PATHconf: $!\n";
@conf = <conf>;
close(conf);
$i=0;
foreach(@conf)
{
$line = $conf[$i];
$line =~ s/ |>|\n|\r|\t|\#.*|;.*//gi;
if ( ($line =~ /^PATHhome/) && ($CLIhome < 1) )
{$PATHhome = $line; $PATHhome =~ s/.*=//gi;}
if ( ($line =~ /^PATHlogs/) && ($CLIlogs < 1) )
{$PATHlogs = $line; $PATHlogs =~ s/.*=//gi;}
if ( ($line =~ /^PATHagi/) && ($CLIagi < 1) )
{$PATHagi = $line; $PATHagi =~ s/.*=//gi;}
if ( ($line =~ /^PATHweb/) && ($CLIweb < 1) )
{$PATHweb = $line; $PATHweb =~ s/.*=//gi;}
if ( ($line =~ /^PATHsounds/) && ($CLIsounds < 1) )
{$PATHsounds = $line; $PATHsounds =~ s/.*=//gi;}
if ( ($line =~ /^PATHmonitor/) && ($CLImonitor < 1) )
{$PATHmonitor = $line; $PATHmonitor =~ s/.*=//gi;}
if ( ($line =~ /^VARserver_ip/) && ($CLIserver_ip < 1) )
{$VARserver_ip = $line; $VARserver_ip =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_server/) && ($CLIDB_server < 1) )
{$VARDB_server = $line; $VARDB_server =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_database/) && ($CLIDB_database < 1) )
{$VARDB_database = $line; $VARDB_database =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_user/) && ($CLIDB_user < 1) )
{$VARDB_user = $line; $VARDB_user =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_pass/) && ($CLIDB_pass < 1) )
{$VARDB_pass = $line; $VARDB_pass =~ s/.*=//gi;}
if ( ($line =~ /^VARDB_port/) && ($CLIDB_port < 1) )
{$VARDB_port = $line; $VARDB_port =~ s/.*=//gi;}
$i++;
}
if (!$VARDB_port) {$VARDB_port='3306';}
if (!$AGILOGfile) {$AGILOGfile = "$PATHlogs/agiout.$year-$mon-$mday";}
if (!$PRSLOGfile) {$PRSLOGfile = "$PATHlogs/prsout.$year-$mon-$mday";}
if (!$PRSTESTfile) {$PRSTESTfile = "$PATHlogs/prstest.$year-$mon-$mday";}
if (!$ERRLOGfile) {$ERRLOGfile = "$PATHlogs/MySQLerror.$year-$mon-$mday";}
use DBI;
use Time::HiRes ('gettimeofday','usleep','sleep'); # necessary to have perl sleep command of less than one second
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARDB_port", "$VARDB_user", "$VARDB_pass")
or die "Couldn't connect to database: " . DBI->errstr;
### Grab Server values from the database
$stmtA = "SELECT agi_output,local_gmt FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02001'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
$rec_count=0;
while ($sthArows > $rec_count)
{
$AGILOG = '0';
@aryA = $sthA->fetchrow_array;
$DBagi_output = $aryA[0];
$local_gmt = $aryA[1];
if ($DBagi_output =~ /STDERR/) {$AGILOG = '1';}
if ($DBagi_output =~ /FILE/) {$AGILOG = '2';}
if ($DBagi_output =~ /BOTH/) {$AGILOG = '3';}
$rec_count++;
}
$sthA->finish();
### begin parsing run-time options ###
if (length($ARGV[0])>1)
{
if ($AGILOG) {$agi_string = "Perl Environment Dump:"; &agi_output;}
$i=0;
while ($#ARGV >= $i)
{
$args = "$args $ARGV[$i]";
if ($AGILOG) {$agi_string = "$i|$ARGV[$i]"; &agi_output;}
$i++;
}
### list of command-line array arguments:
@ARGV_vars = split(/-----/, $ARGV[0]);
$call_handle_method = $ARGV_vars[0];
$agent_search_method = $ARGV_vars[1];
$channel_group = $ARGV_vars[2];
$inbound_number = $ARGV_vars[3];
$parked_by = $ARGV_vars[4];
$park_extension = $ARGV_vars[5];
$status = $ARGV_vars[6];
$list_id = $ARGV_vars[7];
$phone_code = $ARGV_vars[8];
$Scampaign_id = $ARGV_vars[9];
$agent_only = $ARGV_vars[10];
$vendor_id = $ARGV_vars[11];
$vid_enter_filename = $ARGV_vars[12];
$vid_id_number_filename = $ARGV_vars[13];
$vid_confirm_filename = $ARGV_vars[14];
$vid_validate_digits = $ARGV_vars[15];
}
$|=1;
while(<STDIN>)
{
chomp;
last unless length($_);
if ($AGILOG)
{
if (/^agi_(\w+)\:\s+(.*)$/)
{
$AGI{$1} = $2;
}
}
if (/^agi_uniqueid\:\s+(.*)$/) {$unique_id = $1; $uniqueid = $unique_id;}
if (/^agi_channel\:\s+(.*)$/) {$channel = $1;}
if (/^agi_extension\:\s+(.*)$/) {$extension = $1;}
if (/^agi_type\:\s+(.*)$/) {$type = $1;}
if (/^agi_callerid\:\s+(.*)$/) {$callerid = $1;}
if (/^agi_calleridname\:\s+(.*)$/) {$calleridname = $1;}
}
if ($calleridname =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
{$callerid = $calleridname;}
if ( ($callerid =~ /\".*\"/) && ( (!$calleridname) or ($calleridname =~ /unknown/) ) )
{
$calleridname = $callerid;
$calleridname =~ s/\<\d\d\d\d\d\d\d\d\d\d\>//gi;
$calleridname =~ s/\"|\" //gi;
}
if ($callerid !~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
{
$callerid =~ s/\D|\'//gi;
$calleridname =~ s/unknown|\'//gi;
if ( (!$callerid) or ($callerid =~ /unknown/) )
{$callerid = $calleridname;}
}
##### find out if this call is already in the vicidial_log_extended table
#$VLEcount=0;
#$stmtA = "SELECT count(*) FROM vicidial_log_extended where uniqueid='$uniqueid';";
#$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
#$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
#$sthArows=$sthA->rows;
# $dbhP=$dbhA; $mysql_count='02144'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
#if ($sthArows > 0)
# {
# @aryA = $sthA->fetchrow_array;
# $VLEcount = $aryA[0];
# }
#$sthA->finish();
$user_unavailable_action='';
##### special processing for DID forwarded calls "99909*1***DID"
if ($extension =~ /^999\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$referring_extension = $EXT_vars[0]; # initial extension sent
$did_id = $EXT_vars[1]; # the DID ID to grab settings from
$in_group_override = $EXT_vars[2]; # the in-group override, if set
$agentdirect_override = $EXT_vars[3]; # the agentdirect override, if set
$route_type = $EXT_vars[4]; # DID or FILTER from the did, if set
### Grab DID values from the database
if ($route_type =~ /FILTER/)
{
$stmtA = "SELECT filter_call_handle_method,filter_agent_search_method,filter_group_id,did_pattern,filter_list_id,filter_phone_code,filter_campaign_id,filter_user,filter_user_unavailable_action,filter_user_route_settings_ingroup,filter_action,filter_voicemail_ext,filter_extension,filter_exten_context,filter_phone,filter_server_ip FROM vicidial_inbound_dids where did_id = '$did_id';";
}
else
{
$stmtA = "SELECT call_handle_method,agent_search_method,group_id,did_pattern,list_id,phone_code,campaign_id,user,user_unavailable_action,user_route_settings_ingroup,did_route,voicemail_ext,extension,exten_context,phone,server_ip FROM vicidial_inbound_dids where did_id = '$did_id';";
}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02002'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$call_handle_method = $aryA[0];
$agent_search_method = $aryA[1];
$did_in_group = $aryA[2];
$inbound_number = $aryA[3];
$list_id = $aryA[4];
$phone_code = $aryA[5];
$Scampaign_id = $aryA[6];
$agent_only = $aryA[7];
$user_unavailable_action = $aryA[8];
$user_route_settings_ingroup = $aryA[9];
$did_route = $aryA[10];
$did_voicemail_ext = $aryA[11];
$did_extension = $aryA[12];
$did_exten_context = $aryA[13];
$did_phone = $aryA[14];
$did_phone_server_ip = $aryA[15];
if ($did_route =~ /AGENT/)
{$channel_group = $user_route_settings_ingroup;}
else
{$channel_group = $did_in_group;}
}
$sthA->finish();
if (length($agentdirect_override) > 0) {$agent_only = $agentdirect_override;}
if (length($in_group_override) > 1)
{
$igo_valid=0;
### if in_group_override is set, make sure it's valid
$stmtA = "SELECT count(*) FROM vicidial_inbound_groups where group_id='$in_group_override' and active='Y';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='01139'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$igo_valid = $aryA[0];
}
$sthA->finish();
if ($igo_valid > 0)
{
$channel_group = $in_group_override;
if ($AGILOG) {$agi_string = "In-Group Override: $in_group_override"; &agi_output;}
}
}
}
if ( ($phone_code =~ /^1$/) && ($callerid =~ /^1/) && (length($callerid) > 10) )
{
$callerid =~ s/^1//gi;
if ($AGILOG) {$agi_string = "North America CID Check: $phone_code|$callerid|"; &agi_output;}
}
$originalCID = $callerid;
if ($call_handle_method =~ /^CLOSER/)
{
### allow for internal PRI/IAX/SIP transfer data string "90009*CL_uk3survy_*8301*10000123*universal*7275551212*1234*"
if ($extension =~ /^900\d\d\*|^9900\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$referring_extension = $EXT_vars[0]; # initial extension sent
$channel_group = $EXT_vars[1]; # name of the parked group "In-group"
$inbound_number = $EXT_vars[2]; # extension to send call to after parsing
$parked_by = $EXT_vars[3]; # leadID
$park_extension = $EXT_vars[4]; # filename of the on-hold music file
$phone_number = $EXT_vars[5]; # phone number of customer
$fronter = $EXT_vars[6]; # user of the fronter that transferred the call
$fronter_call_seconds = $EXT_vars[8]; # not currently used
$dial_ingroup_flag = $EXT_vars[9]; # used by dial in-group feature
if ( ($channel_group =~ /AGENTDIRECT/i) || ($dial_ingroup_flag > 0) )
{
$agent_only = $EXT_vars[7]; # optional AGENTDIRECT user to queue call for
$agent_grab_extension = $EXT_vars[10]; # used by dial in-group feature
}
$CIDlead_id = $parked_by;
$originalCID = $phone_number;
$PADlead_id = sprintf("%010s", $parked_by); while (length($PADlead_id) > 10) {chop($PADlead_id);}
# JmmddhhmmssLLLLLLLLL
$JqueryCID = "J$CIDdate$PADlead_id";
$callerid = $JqueryCID;
$VCcallerid = $JqueryCID;
### set the new call callerid to track the call
$Jnewcallerid = "\"$JqueryCID <$phone_number>\"";
$AGI->set_callerid($Jnewcallerid);
if ($AGILOG) {$agi_string = "callerID changed: $Jnewcallerid"; &agi_output;}
}
### allow for outbound auto-dial calls or previous in-group calls passed through call menus
if ($callerid =~ /^V\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d|^Y\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d/)
{
$CIDlead_id = substr($callerid, 10, 10);
$CIDlead_id = ($CIDlead_id + 0);
$VCcallerid = $callerid;
$insert_lead_id = $CIDlead_id;
$stmtA= "SELECT phone_number from vicidial_list where lead_id='$insert_lead_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02180'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$phone_number = $aryA[0];
$originalCID = $phone_number;
}
$sthA->finish();
### set the call callerid to track the call
# YmmddhhmmssLLLLLLLLL
# $PADlead_id = sprintf("%010s", $insert_lead_id); while (length($PADlead_id) > 10) {chop($PADlead_id);}
# $YqueryCID = "Y$CIDdate$PADlead_id";
$Jnewcallerid = "\"$callerid <$phone_number>\"";
$AGI->set_callerid($Jnewcallerid);
if ($AGILOG) {$agi_string = "Lead ID found: $insert_lead_id|$phone_number| |$Jnewcallerid|"; &agi_output;}
}
}
if ( ($call_handle_method =~ /^CID/) || ($call_handle_method =~ /^VID/) )
{
if (length($callerid)>0) {$phone_number = $callerid;}
else {$phone_number = '';}
if (length($calleridname)>0) {$VLcomments = $calleridname;}
else {$VLcomments = '';}
}
# if ($channel =~ /^SIP/) {$channel =~ s/-.*//gi;}
# if ($channel =~ /^Zap\//) {$channel =~ s/-\d$//gi;}
if (length($callerid)<10) {$callerid = $parked_by;}
if (length($pin)>0) {$callerid = $pin;}
if ($call_handle_method =~ /^ANI/)
{
$phone_number='';
### allow for external ANI to be collected on older RBS T1 circuits
if ($extension =~ /\*\d\d\d\d\d\d\d\d\d\d\*/)
{
@EXT_vars = split(/\*/, $extension);
$phone_number = $EXT_vars[1];
if ($AGILOG) {$agi_string = "ANI found: |$phone_number|"; &agi_output;}
}
}
# When VID or VIDPROMPT, methods are not used, no Vendor Lead Code can be supplied. Fill it with inbound_number
if ($call_handle_method !~ /^VID/)
{$vendor_id = $inbound_number;}
foreach $i (sort keys %AGI)
{
if ($AGILOG) {$agi_string = " -- $i = $AGI{$i}"; &agi_output;}
}
if ($AGILOG) {$agi_string = "AGI Variables: |$unique_id|$channel|$extension|$type|$callerid|"; &agi_output;}
if (length($pin) < 1) {$pin=$inbound_number;}
$fronter = $pin;
if ($AGILOG) {$agi_string = "+++++ INBOUND CALL VDCL STARTED : |$channel_group|$callerid-$pin|$now_date"; &agi_output;}
$VDADphone='';
$VDADphone_code='';
$VCcallerid = $channel_group;
if (length($VCcallerid)<2)
{$VCcallerid = 'ViciDial Inbound';}
if ($channel =~ /Local/i)
{
if ( ($inbound_number =~ /CXFER/) || ($call_handle_method =~ /^CLOSER/) )
{
if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: CXFER OVERRIDE- $priority"; &agi_output;}
if ($call_handle_method =~ /^CLOSER/)
{
### sleep for 99 hundredths of a second
usleep(1*990*1000);
$stmtA = "SELECT count(*) FROM vicidial_auto_calls where lead_id='$CIDlead_id' and call_type='IN' and campaign_id='$channel_group' and channel NOT LIKE \"Local%\";";
if ($AGILOG) {$agi_string = "|$stmtA|"; &agi_output;}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02003'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
$rec_count=0;
while ($sthArows > $rec_count)
{
@aryA = $sthA->fetchrow_array;
$Pseudo_duplicate_count = $aryA[0];
$rec_count++;
}
$sthA->finish();
if ($Pseudo_duplicate_count > 0)
{
if ($AGILOG) {$agi_string = "+++++ INBOUND LOCAL DUPLICATE: EXITING- $priority"; &agi_output;}
exit;
}
}
}
else
{
if ($AGILOG) {$agi_string = "+++++ VDAD START LOCAL CHANNEL: EXITING- $priority"; &agi_output;}
exit;
}
}
### Grab Server values from the database
$cbc=0;
$stmtA = "SELECT voicemail_dump_exten,ext_context,answer_transfer_agent,local_gmt,asterisk_version,max_vicidial_trunks FROM servers where server_ip = '$VARserver_ip';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02004'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$DBvoicemail_dump_exten = $aryA[0];
$DBext_context = $aryA[1];
$DBanswer_transfer_agent = $aryA[2];
$DBSERVER_GMT = $aryA[3];
$asterisk_version = $aryA[4];
$DBmax_vicidial_trunks = $aryA[5];
if ($DBvoicemail_dump_exten) {$voicemail_dump_exten = $DBvoicemail_dump_exten;}
if ($DBext_context) {$ext_context = $DBext_context;}
if ($DBanswer_transfer_agent) {$answer_transfer_agent = $DBanswer_transfer_agent;}
if ($DBSERVER_GMT) {$SERVER_GMT = $DBSERVER_GMT;}
if ($asterisk_version) {$AST_ver = $asterisk_version;}
if ($DBmax_vicidial_trunks) {$max_vicidial_trunks = $DBmax_vicidial_trunks;}
$cbc++;
}
$sthA->finish();
### Update calldate on the in-group record
$stmtA = "UPDATE vicidial_inbound_groups SET group_calldate='$SQLdate' where group_id='$channel_group';";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02179'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
### Grab inbound groups values from the database
$cbc=0;
$stmtA = "SELECT call_time_id,after_hours_action,after_hours_message_filename,after_hours_exten,after_hours_voicemail,welcome_message_filename,moh_context,onhold_prompt_filename,prompt_interval,agent_alert_exten,agent_alert_delay,drop_call_seconds,drop_action,drop_exten,next_agent_call,voicemail_ext,queue_priority,drop_inbound_group,afterhours_xfer_group,play_place_in_line,play_estimate_hold_time,hold_time_option,hold_time_option_seconds,hold_time_option_exten,hold_time_option_voicemail,hold_time_option_xfer_group,hold_time_option_callback_filename,hold_time_option_callback_list_id,hold_recall_xfer_group,no_delay_call_route,play_welcome_message,no_agent_no_queue,no_agent_action,no_agent_action_value,extension_appended_cidname,uniqueid_status_display,uniqueid_status_prefix,hold_time_option_minimum,hold_time_option_press_filename,hold_time_option_callmenu,onhold_prompt_no_block,onhold_prompt_seconds,hold_time_option_no_block,hold_time_option_prompt_seconds,hold_time_second_option,hold_time_third_option,wait_hold_option_priority,wait_time_option,wait_time_second_option,wait_time_third_option,wait_time_option_seconds,wait_time_option_exten,wait_time_option_voicemail,wait_time_option_xfer_group,wait_time_option_callmenu,wait_time_option_callback_filename,wait_time_option_callback_list_id,wait_time_option_press_filename,wait_time_option_no_block,wait_time_option_prompt_seconds,active,calculate_estimated_hold_seconds,add_lead_url,eht_minimum_prompt_filename,eht_minimum_prompt_no_block,eht_minimum_prompt_seconds,on_hook_ring_time,ingroup_recording_override,ingroup_rec_filename,on_hook_cid,action_xfer_cid,drop_callmenu,after_hours_callmenu,max_calls_method,max_calls_count,max_calls_action FROM vicidial_inbound_groups where group_id = '$channel_group';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02005'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$call_time_id = $aryA[0];
$after_hours_action = $aryA[1];
$after_hours_message_filename = $aryA[2];
$after_hours_exten = $aryA[3];
$after_hours_voicemail = $aryA[4];
$welcome_message_filename = $aryA[5];
$moh_context = $aryA[6];
$onhold_prompt_filename = $aryA[7];
$prompt_interval = $aryA[8];
$agent_alert_exten = $aryA[9];
$agent_alert_delay = $aryA[10];
$drop_call_seconds = $aryA[11];
$DROP_TIME = $drop_call_seconds;
$drop_action = $aryA[12];
$drop_exten = $aryA[13];
$CAMP_callorder = $aryA[14];
$VDADvoicemail_ext = $aryA[15];
# $VDADvoicemail_ext =~ s/\D//gi;
$queue_priority = $aryA[16];
$drop_inbound_group = $aryA[17];
$afterhours_xfer_group = $aryA[18];
$play_place_in_line = $aryA[19];
$play_estimate_hold_time = $aryA[20];
$hold_time_option = $aryA[21];
$hold_time_option_seconds = $aryA[22];
$hold_time_option_exten = $aryA[23];
$hold_time_option_voicemail = $aryA[24];
$hold_time_option_xfer_group = $aryA[25];
$hold_time_option_callback_filename = $aryA[26];
$hold_time_option_callback_list_id = $aryA[27];
$hold_recall_xfer_group = $aryA[28];
$no_delay_call_route = $aryA[29];
if ($hold_time_option =~ /DROP_ACTION/)
{$hold_time_option = $drop_action;}
$hold_time_option_SETTING = $hold_time_option;
$play_welcome_message = $aryA[30];
$no_agent_no_queue = $aryA[31];
$no_agent_action = $aryA[32];
$no_agent_action_value = $aryA[33];
$extension_appended_cidname = $aryA[34];
$uniqueid_status_display = $aryA[35];
$uniqueid_status_prefix = $aryA[36];
$hold_time_option_minimum = $aryA[37];
$hold_time_option_press_filename = $aryA[38];
$hold_time_option_callmenu = $aryA[39];
$onhold_prompt_no_block = $aryA[40];
$onhold_prompt_seconds = $aryA[41];
$hold_time_option_no_block = $aryA[42];
$hold_time_option_prompt_seconds = $aryA[43];
$hold_time_second_option = $aryA[44];
$hold_time_third_option = $aryA[45];
$wait_hold_option_priority = $aryA[46];
$wait_time_option = $aryA[47];
$wait_time_option_SETTING = $wait_time_option;
$wait_time_second_option = $aryA[48];
$wait_time_third_option = $aryA[49];
$wait_time_option_seconds = $aryA[50];
$wait_time_option_exten = $aryA[51];
$wait_time_option_voicemail = $aryA[52];
$wait_time_option_xfer_group = $aryA[53];
$wait_time_option_callmenu = $aryA[54];
$wait_time_option_callback_filename = $aryA[55];
$wait_time_option_callback_list_id = $aryA[56];
$wait_time_option_press_filename = $aryA[57];
$wait_time_option_no_block = $aryA[58];
$wait_time_option_prompt_seconds = $aryA[59];
$ingroup_active = $aryA[60];
$calculate_estimated_hold_seconds = $aryA[61];
$add_lead_url = $aryA[62];
$eht_minimum_prompt_filename = $aryA[63];
$eht_minimum_prompt_no_block = $aryA[64];
$eht_minimum_prompt_seconds = $aryA[65];
$on_hook_ring_time = $aryA[66];
$ingroup_recording_override = $aryA[67];
$campaign_rec_filename = $aryA[68];
$on_hook_cid = $aryA[69];
$action_xfer_cid = $aryA[70];
$drop_callmenu = $aryA[71];
$after_hours_callmenu = $aryA[72];
$max_calls_method = $aryA[73];
$max_calls_count = $aryA[74];
$max_calls_action = $aryA[75];
$custom_call_id='';
if ($uniqueid_status_display =~ /ENABLED/)
{$custom_call_id = "$uniqueid";}
if ($uniqueid_status_display =~ /ENABLED_PREFIX/)
{$custom_call_id = "$uniqueid_status_prefix$uniqueid";}
}
$sthA->finish();
if ($wday==0)
{
$daySQL=',ct_sunday_start,ct_sunday_stop,sunday_afterhours_filename_override';
$yestSQL=',ct_saturday_start,ct_saturday_stop';
}
if ($wday==1)
{
$daySQL=',ct_monday_start,ct_monday_stop,monday_afterhours_filename_override';
$yestSQL=',ct_sunday_start,ct_sunday_stop';
}
if ($wday==2)
{
$daySQL=',ct_tuesday_start,ct_tuesday_stop,tuesday_afterhours_filename_override';
$yestSQL=',ct_monday_start,ct_monday_stop';
}
if ($wday==3)
{
$daySQL=',ct_wednesday_start,ct_wednesday_stop,wednesday_afterhours_filename_override';
$yestSQL=',ct_tuesday_start,ct_tuesday_stop';
}
if ($wday==4)
{
$daySQL=',ct_thursday_start,ct_thursday_stop,thursday_afterhours_filename_override';
$yestSQL=',ct_wednesday_start,ct_wednesday_stop';
}
if ($wday==5)
{
$daySQL=',ct_friday_start,ct_friday_stop,friday_afterhours_filename_override';
$yestSQL=',ct_thursday_start,ct_thursday_stop';
}
if ($wday==6)
{
$daySQL=',ct_saturday_start,ct_saturday_stop,saturday_afterhours_filename_override';
$yestSQL=',ct_friday_start,ct_friday_stop';
}
### Grab call_times values from the database
$stmtA = "SELECT ct_default_start,ct_default_stop,default_afterhours_filename_override $daySQL $yestSQL,ct_holidays FROM vicidial_call_times where call_time_id = '$call_time_id';";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02006'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
@aryA = $sthA->fetchrow_array;
$ct_default_start = $aryA[0];
$ct_default_stop = $aryA[1];
$deafult_afterhours_filename_override = $aryA[2];
$ct_day_start = $aryA[3];
$ct_day_stop = $aryA[4];
$day_afterhours_filename_override = $aryA[5];
$ct_yest_start = $aryA[6];
$ct_yest_stop = $aryA[7];
$ct_holidays = $aryA[8];
$sthA->finish();
if ( ($ct_yest_start < 1) && ($ct_yest_stop < 1) )
{
$ct_yest_start = $ct_default_start;
$ct_yest_stop = $ct_default_stop;
}
if ( ($ct_day_start > 0) || ($ct_day_stop > 0) )
{
$ct_default_start = $ct_day_start;
$ct_default_stop = $ct_day_stop;
}
if (length($ct_holidays) > 2)
{
$stmtA = "SELECT count(*) from vicidial_call_time_holidays where holiday_date='$YMD' and holiday_status='ACTIVE';";
if ($DBX) {print " |$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
@aryA = $sthA->fetchrow_array;
$holiday_today_count = $aryA[0];
if ($AGILOG) {$agi_string = "Holiday check: |$holiday_today_count|$stmtA|$ct_holidays|"; &agi_output;}
$ct_hrs=0;
$b=0;
if ($holiday_today_count > 0)
{
@holiday_rules = split(/\|/,$ct_holidays);
$ct_hrs = ($#holiday_rules - 0);
while($ct_hrs >= $b)
{
if (length($holiday_rules[$b])>1)
{
$stmtA = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop,default_afterhours_filename_override from vicidial_call_time_holidays where holiday_id='$holiday_rules[$b]' and holiday_status='ACTIVE' and holiday_date='$YMD';";
if ($DBX) {print " |$stmtA|\n";}
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$holiday_id = $aryA[0];
$holiday_date = $aryA[1];
$holiday_name = $aryA[2];
$ct_default_start = $aryA[3];
$ct_default_stop = $aryA[4];
$default_afterhours_filename_override = $aryA[5];
$holiday_afterhours_filename_override = $aryA[5];
if ($AGILOG) {$agi_string = "Active Holiday found! |$holiday_id|$holiday_date|$holiday_name|$ct_default_start|$ct_default_stop|$default_afterhours_filename_override|"; &agi_output;}
}
$sthA->finish();
}
$b++;
}
}
}
if ( (length($deafult_afterhours_filename_override) > 0) && ($deafult_afterhours_filename_override !~ /---NONE---/) )
{$after_hours_message_filename = $deafult_afterhours_filename_override;}
if ( (length($day_afterhours_filename_override) > 0) && ($day_afterhours_filename_override !~ /---NONE---/) )
{$after_hours_message_filename = $day_afterhours_filename_override;}
if ( (length($holiday_afterhours_filename_override) > 0) && ($holiday_afterhours_filename_override !~ /---NONE---/) )
{$after_hours_message_filename = $holiday_afterhours_filename_override;}
# send call to after hours action if in-group is set to inactive
if ($ingroup_active !~ /Y/)
{
$ct_default_start = 2400;
$ct_default_stop = 2400;
if ($AGILOG) {$agi_string = "IN-GROUP INACTIVE! Sending to After Hours Action: |$after_hours_action|$ingroup_active|"; &agi_output;}
}
# set the drop time to 1 second if AGENTDIRECT without a user assigned
if ( ($channel_group =~ /AGENTDIRECT/i) && (length($agent_only) < 1) )
{
if ($AGILOG) {$agi_string = "AGENTDIRECT with no agent defined! Setting drop seconds to 1: |$channel_group|$agent_only|"; &agi_output;}
$DROP_TIME = 1;
$drop_call_seconds = 1;
}
$AGI->stream_file('sip-silence');
$AGI->stream_file('sip-silence');
if ($call_handle_method =~ /DIGITID$/)
{
&enter_pin_number;
if (length($pin) > 0)
{$fronter = $pin;}
}
if ($call_handle_method =~ /^VIDPROMPT/)
{
$vendor_lead_code = $AGI->get_variable('vendor_lead_code');
if ( ($AGILOG) && (length($vendor_lead_code)>0) ) {$agi_string = "vendor id AGI variable: |$vendor_lead_code|"; &agi_output;}
if (length($vendor_lead_code)>2)
{
$vendor_id = $vendor_lead_code;
}
else
{
&enter_id_number;
}
}
if ($call_handle_method =~ /LOOKUP/)
{
if ( ( ($call_handle_method =~ /^VID/) && (length($vendor_id)) < 3) || (length($phone_number) < 3) )
{
### insert a record into the vicidial_list table
$stmtA = "INSERT INTO vicidial_list (entry_date,modify_date,status,user,vendor_lead_code,source_id,list_id,called_since_last_reset,phone_code,phone_number,security_phrase,called_count,gmt_offset_now,comments) values('$SQLdate','$tsSQLdate','INBND','$fronter','$vendor_id','VDCL','$list_id','Y','$phone_code','$phone_number','$channel_group','1','$local_gmt','$VLcomments');";
$affected_rows = $dbhA->do($stmtA);
$dbhP=$dbhA; $mysql_count='02007'; $MEL_aff_rows=$affected_rows; &mysql_error_logging;
$cbc=0;
$stmtB = "SELECT LAST_INSERT_ID() LIMIT 1;";
$sthA = $dbhA->prepare($stmtB) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $stmtA=$stmtB; $mysql_count='02008'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
if ($sthArows > 0)
{
@aryA = $sthA->fetchrow_array;
$insert_lead_id = $aryA[0];
$cbc++;
}
$sthA->finish();
### Start the Add-Lead-URL get proccess
if (length($add_lead_url) > 5)
{
$PADlead_id = sprintf("%010s", $insert_lead_id); while (length($PADlead_id) > 10) {chop($PADlead_id);}
$XXqueryCID = "Y$CIDdate$PADlead_id";
$launch = $PATHhome . "/AST_send_URL.pl";
$launch .= " --SYSLOG" if ($SYSLOG);
$launch .= " --lead_id=" . $insert_lead_id;
$launch .= " --phone_number=" . $phone_number;
$launch .= " --user=";
$launch .= " --call_type=IN";
$launch .= " --campaign=" . $channel_group;
$launch .= " --uniqueid=" . $uniqueid;
$launch .= " --alt_dial=MAIN";
$launch .= " --call_id=" . $XXqueryCID;
$launch .= " --function=INGROUP_ADD_LEAD_URL";
system($launch . ' &');
if ($AGILOG) {$agi_string = "$launch|"; &agi_output;}
}
if ($AGILOG) {$agi_string = "VDAD vicidial_list insert |$insert_lead_id|$stmtA|"; &agi_output;}
}
else
{
$listSQL = '';
if ($call_handle_method =~ /LOOKUPRL$/)
{$listSQL = "and list_id='$list_id'";}
else
{
if ($call_handle_method =~ /LOOKUPRC$/)
{
### Grab all lists associated with Scampaign_id
$cbc=0;
$SlistsSQL='';
$stmtA = "SELECT list_id FROM vicidial_lists where campaign_id='$Scampaign_id' limit 1000;";
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
$sthArows=$sthA->rows;
$dbhP=$dbhA; $mysql_count='02009'; $MEL_aff_rows=$sthArows; &mysql_error_logging;
while ($sthArows > $cbc)
{
@aryA = $sthA->fetchrow_array;
$SlistsSQL .= "'$aryA[0]',";
$cbc++;