root/modules/branches/2.3/core/agi-bin/dialparties.agi

Revision 4904, 24.7 kB (checked in by p_lindheimer, 5 years ago)

#2299 revert back to , for | in dialparties.agi until behavior is determined for 1.4 or likely a bug in the agi library

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/php -q
2 <?php
3
4 // Copyright (C) 2003 Zac Sprackett <zsprackett-asterisk@sprackett.com>
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // Amended by Coalescent Systems Inc. Sept, 2004
17 // to include support for DND, Call Waiting, and CF to external trunk
18 // info@coalescentsystems.ca
19 //
20 // This script has been ported to PHP by
21 // Diego Iastrubni <diego.iastrubni@xorcom.com> and the FreePBX community
22
23 /* --------WARNING---------
24  *
25  * This script is auto-copied from an included module and will get overwritten.
26  * If you modify it, you must change it to write only, in the agi-bin directory,
27  * to keep it from getting changed.
28  */
29
30 require_once "phpagi.php";
31 require_once "phpagi-asmanager.php";
32
33 $ext      = array();    // Hash that will contain our list of extensions to call
34 $ext_hunt = array();    // Hash that will contain our list of extensions to call used by huntgroup
35 $cidnum   = "";   // Caller ID Number for this call
36 $cidname  = "";   // Caller ID Name for this call
37 $timer    = "";   // Call timer for Dial command
38 $dialopts = "";   // options for dialing
39 $rc       = "";   // Catch return code
40 $priority = "";   // Next priority
41 $rgmethod = "";   // If Ring Group what ringing method was chosen
42 $dsarray  = array();  // This will hold all the dial strings, used to check for duplicate extensions
43
44 $AGI = new AGI();
45 debug("Starting New Dialparties.agi", 1);
46
47 // Get required channels variables that used to come from amportal.conf
48 $ampmgruser  = get_var( $AGI, "AMPMGRUSER" );
49 $ampmgrpass  = get_var( $AGI, "AMPMGRPASS" );
50 $cwinusebusy = get_var( $AGI, "CWINUSEBUSY" );
51
52 $astman = new AGI_AsteriskManager( );
53 if (!$astman->connect("127.0.0.1", $ampmgruser , $ampmgrpass)) {
54   exit (1);
55 }
56
57 $priority = get_var( $AGI, "priority" ) + 1;
58
59 // Caller ID info is stored in $request in AGI class, passed from Asterisk
60 $cidnum = $AGI->request['agi_callerid'];
61 $cidname = $AGI->request['agi_calleridname'];
62 debug("Caller ID name is '$cidname' number is '$cidnum'", 1);
63
64 // From this point forward, Set KEEPCID in the channel so subsequent calls, CF, etc. retain the incoming
65 // CID that get sent down channel local.
66 $AGI->set_variable('__KEEPCID','TRUE');
67
68 // Set to '' in case it was previously set
69 //
70 $AGI->set_variable('DIALSTATUS_CW','');           
71
72 $timer    = get_var( $AGI, "ARG1" );
73 $dialopts = get_var( $AGI, "ARG2" );
74 $rgmethod = get_var( $AGI, "RingGroupMethod" );
75
76 $alertinfo = get_var( $AGI, "ALERT_INFO" );
77 if ($alertinfo) {
78   debug("Setting Alert-Info:  $alertinfo", 4);
79   $AGI->set_alertinfo($alertinfo);           
80 }
81
82 $sippheader = get_var( $AGI, "SIPADDHEADER" );
83 if ($sippheader) {
84   $fields = explode(':',$sippheader,2);
85   debug("Setting sipheader ".$fields[0].": ".$fields[1], 4);
86   $AGI->exec_sipaddheader($fields[0], $fields[1]);
87 }
88
89 /* TODO: this does not work but should, moved to macro-dial for now
90  *
91 $mohclass = get_var( $AGI, "MOHCLASS" );
92 if ($mohclass) {
93   debug("Setting MoH Class:  $mohclass", 4);
94   $AGI->set_music(true, $mohclass);           
95 }
96  */
97
98 $pr_dialstatus  = get_var( $AGI, "PR_DIALSTATUS" );
99
100 $fmgrp  = get_var( $AGI, "FMGRP" );
101 $nodest = get_var( $AGI, "NODEST" );
102 if (empty($nodest)) $nodest = '';
103
104 $ringgroup_index  = get_var( $AGI, "RINGGROUP_INDEX" );
105 $use_confirmation = get_var( $AGI, "USE_CONFIRMATION" );
106 if (empty($use_confirmation)) $use_confirmation = "FALSE";
107 debug("USE_CONFIRMATION:  '$use_confirmation'", 5);
108 debug("RINGGROUP_INDEX:   '$ringgroup_index'", 5);
109
110 if (empty($timer))  $timer    = 0;
111 if (empty($dialopts)) $dialopts = "";
112 if (empty($rgmethod)) $rgmethod = "none";
113
114 debug("Methodology of ring is  '$rgmethod'", 1);
115
116 // reset the ringgroup method to its fundamental algorithm and pull out if
117 // master mode.
118
119 $recall_mastermode=$rgmethod;
120
121 switch ($rgmethod) {
122   case 'ringall-prim':
123     $rgmethod = "ringall";
124     $mastermode = 1;
125     break;
126   case 'hunt-prim':
127     $rgmethod = "hunt";
128     $mastermode = 1;
129     break;
130   case 'memoryhunt-prim':
131     $rgmethod = "memoryhunt";
132     $mastermode = 1;
133     break;
134   case 'ringallv2-prim':
135     $rgmethod = "ringallv2";
136     $mastermode = 1;
137     break;
138   default:
139     $mastermode = 0;
140     $pr_dialstatus = ""; // not relevant if not mastermode, clear it so dnd doesn't propagate, and other
141 }
142
143 // call confirmation only works with ringall and ringall-prim. The javascripts in ringgroups
144 // and follow-me should enforce this. If that has been overridden then force ringall.
145 // Keep this code after the matermode check above, since they will at least get mastermode
146 // if they set a -prim mode in one of the others
147 //
148 if ( ($use_confirmation != "FALSE") && (trim($rgmethod) != "ringall") && (trim($rgmethod) != "ringallv2") ) {
149   debug("Unsupported RingMethod: '$rgmethod' resetting to ringall", 1);
150   $rgmethod = "ringall";
151 }
152
153 // Start with Arg Count set to 3 as two args are used
154 $arg_cnt = 3;
155 while($arg = get_var($AGI,"ARG". $arg_cnt)) {
156   // not sure why, dialparties will get stuck in a loop if noresponse
157   if ($arg == '-') {
158     debug("get_variable got a \"noresponse\"!  Exiting",3);
159     exit($arg_cnt);
160   }
161   $extarray = split( '-', $arg );
162   foreach ( $extarray as $k ) {
163     $ext[] = $k;
164     debug("Added extension $k to extension map", 3);
165   }
166   $arg_cnt++;
167 }
168
169 // FollowMe Preparation for Pre-Ring:
170 //
171 // If the primary extension is in the ringgroup list, then it should be rung
172 // during both the pre-ring time and the list time, so it's real prering time
173 // is the entire time. If it is not in the list, then it should only ring
174 // for the pre-ring time. This section determines the times and then adds it
175 // to the list if not already there, so that the dialstring is computed
176 // appropriately. This section also makes sure that the primary extension
177 // is at the top of the list.
178 //
179 // Notes before I forget. The primary may have been in the list and screwed
180 // above. So ... do I need to move this up, probably.
181 //
182 if ($rgmethod == "ringallv2" && $fmgrp != "") {
183
184   $fmgrp_primaryremoved = 0;
185
186   $fmgrp_prering  = $AGI->database_get('AMPUSER', $fmgrp."/followme/prering");
187   $fmgrp_prering  = $fmgrp_prering['data'] > 1 ? $fmgrp_prering['data'] : 2;
188      
189   $fmgrp_grptime  = $AGI->database_get('AMPUSER', $fmgrp."/followme/grptime");
190   $fmgrp_grptime  = $fmgrp_grptime['data'];
191   debug("got fmgrp_prering: $fmgrp_prering, fmgrp_grptime: $fmgrp_grptime",4);
192
193   $fmgrp_totalprering = $fmgrp_grptime + $fmgrp_prering;
194   debug("fmgrp_totalprering: $fmgrp_totalprering",4);
195
196   if (in_array($fmgrp, $ext)) {
197     debug("found extension in pre-ring and array",4);
198     $fmgrp_realprering = $fmgrp_totalprering;
199     if ($ext[0] != $fmgrp) {
200       $tmpx=array_flip($ext);
201       unset($ext[$tmpx[$fmgrp]]);
202       array_unshift($ext,$fmgrp);
203     }
204   } else {
205     debug("extension not in group list, ringging only during perring time",4);
206     $fmgrp_realprering = $fmgrp_prering;
207     array_unshift($ext,$fmgrp);
208   }
209   debug("ringallv2 ring times: REALPRERING: $fmgrp_realprering, PRERING: $fmgrp_prering",4);
210 }
211
212 // IF THE FIRST EXTENSION IS CALL FORWARD ENABLED (put in logic) then we don't do master mode
213 // which means we reset the flag here after detecting that and just say we are not in master
214 // mode and all is well. That means the loop below needs to be modified to detect the first
215 // extension and do this if the case.
216
217 // Check for call forwarding first
218 // If call forward is enabled, we use chan_local
219 // Hacky. We should be using an associative array, shouldn't we?
220 $count = 0;
221 foreach( $ext as $k) {
222   $cf  = $AGI->database_get('CF',$k);
223   $cf  = $cf['data'];
224   if (strlen($cf)) {
225     // append a hash sign so we can send out on chan_local below.
226     $ext[$count] = $cf.'#'; 
227     debug("Extension $k has call forward set to $cf", 1);
228
229     // if this is the primary extension and CF enabled, then cancel mastermode
230     // whether it is or not, no need to check.
231     //
232     if ($count == 0) {
233       $mastermode = 0;
234       $pr_dialstatus = ""; // not relevant if not mastermode, clear it so dnd doesn't propagate, and other
235       debug("Primary ext is CF so disabling mastermode if it was set", 4);
236     }
237   }
238   else {
239     debug("Extension $k cf is disabled", 3);
240   }
241   $count++;
242 }
243
244 // IF DND AND we process it as a DND (no CF enabled) then we need to some how flag that ALL THE REST
245 // should now be ignored and not processed if in master mode (and this primary). Do this by setting some
246 // sort of flag that says master mode DND so skip everything else below (set them all to "").
247 //
248
249 // Hacky.
250 $count = 0;
251 $dndprimary = 0;
252 // Now check for DND
253 foreach ( $ext as $k ) {
254   if ( (strpos($k,"#")==0) ) {
255     // no point in doing if cf is enabled
256     $dnd = $AGI->database_get('DND',$k);
257     $dnd = $dnd['data'];
258     if (strlen($dnd) || $pr_dialstatus == "BUSY") {
259       debug("Extension $k has do not disturb enabled, or followme pre-ring returned busy", 2);
260       unset($ext[$count]);
261       $AGI->set_variable('DIALSTATUS','BUSY');           
262       // if this is primary set dndprimary and figure out if needed below
263       //
264       if ($count == 0 && $mastermode) {
265         $dndprimary = 1;
266         debug("Primary extension is DND, so if mastermode, all should be dnd", 4);
267       }
268       if ($count == 0) {
269         $fmgrp_primaryremoved = 1;
270       }
271     }
272     else {
273       debug("Extension $k do not disturb is disabled", 3);
274     }
275   }
276   $count++;
277 }
278
279 // Main calling loop
280 //
281 $skipremaining = 0; // used to allow primary to ring but skip the rest
282 $ds = '';
283 foreach ( $ext as $k ) {
284   // mastermode description:
285   //
286   // if mastermode is set then the first extension will be examined and mastermode will be reset so that the others
287   // are left alone. If the remaining extensions are not to be tried, skpremaining will be set to 1 which will
288   // result in dndprimary being set to 1 thus diabling the remaining list.
289   //
290   // if cf unconditional was already detected on the primary, then mastermode will have been reset at this point
291   // since that will negate the mastermode concpet.
292   //
293   // if dnd was set on the primary then dndprimary will already be set resulting in a completly blanked out list
294   // since dnd on the primary means don't bother me on any.
295
296   // Don't bother checking these if we will be blanking the extnum anyhow
297   if ($skipremaining == 1) {
298     $dndprimary = 1;
299   }
300   if ($dndprimary == 0) {
301     // TODO what are these comments...? do we need to remove them...?
302     $extnum    = $k;
303     $exthascw  = $AGI->database_get('CW', $extnum);// ? 1 : 0;
304     $exthascw  = $exthascw['data']? 1:0;
305     $extcfb    = $AGI->database_get('CFB', $extnum);//? 1 : 0;
306     $extcfb    = $extcfb['data'];
307     $exthascfb = (strlen($extcfb) > 0) ? 1 : 0;
308     $extcfu    = $AGI->database_get('CFU', $extnum);// ? 1 : 0;
309     $extcfu    = $extcfu['data'];
310     $exthascfu = (strlen($extcfu) > 0) ? 1 : 0;
311  
312     // Dump details in level 4
313     debug("extnum $extnum has:  cw: $exthascw; hascfb: $exthascfb [$extcfb] hascfu: $exthascfu [$extcfu]",4);
314
315     // check if mastermode and then reset here. If mastermode, this will be the first extension so
316     // the state is checked and a decision is made as to what to do. We have gotten all the cf variables
317     // above. If CF unconditional was set, we never get here because we alread reset mastermode. If DND
318     // were set then we never get here becasue didprimary was set
319     if ($mastermode == 1) {
320       $mastermode = 0;
321       $extstate = is_ext_avail($extnum);
322       debug("Extension $extnum has ExtensionState: $extstate",1);
323
324       if ( ($exthascw == 1) && ($extstate == 1) ) {
325         // process this one extension but the remaining should be skipped since there is cw and
326         // the extension is occupied. This will try this extension but not the others.
327         $skipremaining = 1;
328         debug("In mastermode with cw enabled so $extnum will be tried and others skipped",4);
329       } elseif ( ($exthascw == 0) && ($extstate == 1) ) {
330         // no cw, ext is busy. So if cfb is set, it will forward there and if not, it will be
331         // ignored as normal behavior. In either case, we skip the remaining numbers.
332         $skipremaining = 1;
333         debug("In mastermode with cw disabled so $extnum will be processed in case cfb set",4);
334       }
335       // All other cases should act like normal. Unavailable, not busy, ringing, etc.
336       // should not be effected
337     }
338   } // end if ($dndprimary == 0)
339   // $dndprimary == 1 so clear the extension
340   else {
341     // clear the current extension if dndprimary has been set. This will only be the case if in mastermode so no need to check
342     // that. Use this to skip remaining extensions also if just ringing the primary.
343     $extnum = '';
344   }
345
346   // if CF is not in use and $dndprimary is not set otherwise $extnum has been cleared and nothing to do
347   //
348   if ( (strpos($k,"#")==0) && $dndprimary == 0) {
349     // CW is not in use or CFB is in use on this extension, then we need to check!
350     if ( ($exthascw == 0) || ($exthascfb == 1) || ($exthascfu == 1) ) {
351       // get ExtensionState: 0-idle; 1-busy; 4-unavail; 8-ringing <--- these are unconfirmed
352       $extstate = is_ext_avail($extnum);
353       debug("Extension $extnum has ExtensionState: $extstate",1);
354  
355       // Ext has CFU and is Unavailable
356       if ( ($exthascfu == 1) && ($extstate == 4) ) {
357         // If part of a ring group, then just do what CF does, otherwise needs to
358         // drop back to dialplan with NOANSWER
359         if ($rgmethod != '' && $rgmethod != 'none') {
360           debug("Extension $extnum has call forward on no answer set and is unavailable and is part of a Ring Group forwarding to '$extcfu'",1);
361           $extnum = $extcfu . '#';   # same method as the normal cf, i.e. send to Local
362         } else {
363           debug("Extension $extnum has call forward on no answer set and is unavailable",1);
364           $extnum = '';
365           $AGI->set_variable('DIALSTATUS','NOANSWER');
366         }
367       } elseif ( ($exthascw == 0) || ($exthascfb == 1) ) {
368         debug("Checking CW and CFB status for extension $extnum",3);
369         // extension in use
370         if ($extstate > 0 && $extstate != 4) {
371           debug("Extension $extnum is not available to be called", 1);
372           // extension in use
373           if ($exthascfb == 1) {
374             debug("Extension $extnum has call forward on busy set to $extcfb",1);
375             $extnum = $extcfb . '#';   # same method as the normal cf, i.e. send to Local
376           // CW not in use
377           } elseif ($exthascw == 0) {
378             debug("Extension $extnum has call waiting disabled",1);
379             $extnum = '';
380             $AGI->set_variable('DIALSTATUS','BUSY');           
381           } else {
382             debug("Extension $extnum has call waiting enabled",1);
383           }
384         }
385       // -1 means couldn't read status usually due to missing HINT
386       } elseif ($extstate < 0) {
387         debug("ExtensionState for $extnum could not be read...assuming ok",3);
388       } else {
389         debug("Extension $extnum is available",1);
390       }
391     } elseif ($rgmethod == "none" && $exthascw == 1 && $cwinusebusy) {
392       $extstate = is_ext_avail($extnum);
393       if ($extstate == 1) {
394         $AGI->set_variable('DIALSTATUS_CW','BUSY');           
395         debug("Extension $extnum has call waiting enabled with state: $extstate",1);
396       }
397     // get ExtensionState: 0-idle; 1-busy; 4-unavail; 8-ringing <--- these are unconfirmed
398     } elseif ( ($exthascw == 1) && ($rgmethod == 'firstnotonphone') ) {
399       $extstate = is_ext_avail($extnum);
400       debug("Extension $extnum has ExtensionState: $extstate",1);
401       // CW in use - but blocked for hunt
402       if ($extstate == 1) {
403         debug("Extension $extnum has call waiting enabled but blocked for hunt",1);
404         $extnum = '';
405         $AGI->set_variable('DIALSTATUS','BUSY'); 
406       }
407     }
408   }
409  
410   if ($extnum != '') {
411     // Still got an extension to be called?
412     // check if we already have a dial string for this extension
413     // if so, ignore it as it's pointless ringing it twice !
414     $realext = str_replace("#", "", $extnum);
415     if ( isset($dsarray[$realext]) ) {
416       debug("Extension '$realext' already in the dialstring, ignoring duplicate",1);
417     } else {
418       $dsarray[$realext] = 1;  // could be dial string i suppose but currently only using for duplicate check
419       $extds = get_dial_string( $AGI, $extnum, $use_confirmation, $ringgroup_index);
420       if (strlen($extds)) {
421         $ds .= $extds . '&';
422       }
423       // Update Caller ID for calltrace application
424       if ((strpos($k,"#")==0) && (($rgmethod != "hunt") && ($rgmethod != "memoryhunt") && ($rgmethod != "firstavailable") && ($rgmethod != "firstnotonphone")) ) {
425         if ( isset($cidnum) && is_numeric($cidnum) ) {
426           $rc = $AGI->database_put('CALLTRACE', $k, $cidnum);
427           if ($rc['result'] == 1) {
428             debug("dbset CALLTRACE/$k to $cidnum", 3);
429           } else {
430             debug("Failed to DbSet CALLTRACE/$k to $cidnum ({$rc['result']})", 1);
431           }
432         } else {
433           // We don't care about retval, this key may not exist
434           $AGI->database_del('CALLTRACE', $k);
435           debug("DbDel CALLTRACE/$k - Caller ID is not defined", 3);
436         }
437       } else {
438         $ext_hunt[$k]=$extds; // Need to have the extension HASH set with technology for hunt group ring
439       }
440     }
441   }
442 } // end foreach ( $ext as $k )
443
444 $dshunt   = '';
445 $loops    = 0;
446 $myhuntmember = "";
447
448 if (($rgmethod == "hunt") || ($rgmethod == "memoryhunt") || ($rgmethod == "firstavailable") || ($rgmethod == "firstnotonphone")) {
449   if ($cidnum) {
450     $AGI->set_variable('CALLTRACE_HUNT',$cidnum);
451   }
452   foreach ($extarray as $k ) {
453     // we loop through the original array to get the extensions in order of importance
454     if ($ext_hunt[$k]) {
455       //If the original array is included in the extension hash then set variables
456       $myhuntmember="HuntMember"."$loops";
457       if (($rgmethod == "hunt") || ($rgmethod == "firstavailable") || ($rgmethod == "firstnotonphone")) {
458         $AGI->set_variable($myhuntmember,$ext_hunt[$k]);
459       } elseif ($rgmethod == "memoryhunt") {
460         if ($loops==0) {
461           $dshunt =$ext_hunt[$k];
462         } else {
463           $dshunt .='&'.$ext_hunt[$k];
464         }
465         $AGI->set_variable($myhuntmember,$dshunt);
466       }
467       $loops += 1;
468     }
469   }
470 }
471
472 $ds = chop($ds," &");
473
474 if ($nodest != '' && $use_confirmation == 'FALSE') {
475   if (strpos($dialopts,"M(auto-blkvm)") > 0  || strpos($dialopts,"M(auto-blkvm)") === 0 ||
476       strpos($dialopts,"M(auto-confirm") > 0 || strpos($dialopts,"M(auto-confirm") === 0 ||
477       strpos($dialopts,"M(confirm") > 0      || strpos($dialopts,"M(confirm") === 0) {
478     debug("NODEST: $nodest blkvm enabled macro already in dialopts: $dialopts",4);
479   } else {
480     $dialopts .= "M(auto-blkvm)";
481     debug("NODEST: $nodest adding M(auto-blkvm) to dialopts: $dialopts",4);
482   }
483 }
484
485 // FollowMe Changes:
486 //
487 // We need to determine if the generated dialstring can be dialed as is. This will be the case if there are no
488 // or is only a single extension to dial.
489 //
490 // First, unset any blank fields so we know how many extensions there are to call.
491 //
492 // If mastermode (skipremaining == 1) was triggered then we just set the ringtime to what the primary extension
493 // should ring for and let this dialstring go.
494 //
495 // If there is only one extension in the list, then we need to determine how long to ring it (depending on if it
496 // was the primary or another extension, then let the generated dialstring ring it.
497 //
498 // Otherwise, we need to re-create the dialstring to be processed by our special dialplan that will ring the
499 // primary extension and hold the group list for the required delay. Also - if we are in a call confirmation mode
500 // then we need to reset the call confirm variables with one level of inheritance so that they remain in the new
501 // channels but don't get further propogated after that. We also clear it for the remainder of this instance since
502 // we are not yet triggering further actions until the next call.
503 //
504 // Notes: $fmgrp_primaryremoved is set to 1 if the primary has been removed from the list so we know that it was dnd-ed.
505 //        this only matters in non-prim mode, where we need to know if the remaining list contains the primary extension
506 //        or not.
507 //
508 if ($rgmethod == 'ringallv2') {
509   $count = 0;
510   foreach ($ext as $x) {
511     if ($x == '') {
512       unset($ext[$count]);
513     }
514     $count++;
515   }
516
517   if (($skipremaining == 1) || (count($ext) == 1 && $fmgrp_primaryremoved == 0)) {
518     $timer = $fmgrp_realprering;
519   } elseif (count($ext) == 1 && $fmgrp_primaryremoved == 1) {
520     $timer = $fmgrp_grptime;
521   } elseif (count($ext) == 1) {
522     $timer = $fmgrp_totalprering; // not sure what would trigger this ?
523   } else {
524     $timer = $fmgrp_totalprering;
525     $ds = "Local/FMPR-".array_shift($ext)."@from-internal&Local/FMGL-".implode('-',$ext)."@from-internal";
526
527     $fmgrp_fmunique = $AGI->request['agi_channel'];
528     $AGI->set_variable('_FMUNIQUE',$fmgrp_fmunique);           
529     $AGI->set_variable('_RingGroupMethod',"ringall");           
530     $fmgrp_prering -= 2;
531     $AGI->set_variable('_FMPRERING',$fmgrp_prering);           
532     $AGI->set_variable('_FMREALPRERING',$fmgrp_realprering);           
533     $AGI->set_variable('_FMGRPTIME',$fmgrp_grptime);           
534     $AGI->set_variable('_FMPRIME',($recall_mastermode == "ringallv2")?"FALSE":"TRUE");           
535
536     debug("FMUNIQUE: $fmgrp_fmunique, FMRERING: $fmgrp_prering, FMREALPRERING: $fmgrp_realprering, FMGRPTIME: $fmgrp_grptime",6);
537
538     if ($use_confirmation != 'FALSE') {
539       $AGI->set_variable('_USE_CONFIRMATION',$use_confirmation);           
540       $AGI->set_variable('_RINGGROUP_INDEX',$ringgroup_index);           
541       $use_confirmation = 'FALSE';
542     }
543   }
544 }
545
546 if ($nodest != '' && $use_confirmation == 'FALSE') {
547   if (strpos($dialopts,"M(auto-blkvm)") > 0  || strpos($dialopts,"M(auto-blkvm)") === 0 ||
548       strpos($dialopts,"M(auto-confirm") > 0 || strpos($dialopts,"M(auto-confirm") === 0 ||
549       strpos($dialopts,"M(confirm") > 0      || strpos($dialopts,"M(confirm") === 0) {
550     debug("NODEST: $nodest blkvm enabled macro already in dialopts: $dialopts",4);
551   } else {
552     $dialopts .= "M(auto-blkvm)";
553     debug("NODEST: $nodest adding M(auto-blkvm) to dialopts: $dialopts",4);
554   }
555 }
556
557 if (!strlen($ds)) {
558   $AGI->noop('');
559 } else {
560   if (($rgmethod == "hunt") || ($rgmethod == "memoryhunt") || ($rgmethod == "firstavailable") || ($rgmethod == "firstnotonphone")) {
561     $ds = '|';
562     if ($timer) {
563       $ds .= $timer;
564     }
565     $ds .= '|' . $dialopts; // pound to transfer, provide ringing
566     $AGI->set_variable('ds',$ds);
567     $AGI->set_variable("HuntMembers",$loops);
568     $AGI->set_priority(20); // dial command is at priority 20 where dialplan handles calling a ringgroup with strategy of "hunt" or "MemoryHunt"
569   } else {
570     $ds .= '|';
571     if ($timer) {
572       $ds .= $timer;
573       if (trim($use_confirmation) != "FALSE") {
574         $AGI->set_variable('__RT',$timer);
575       }
576     }
577     $ds .= '|' . $dialopts; // pound to transfer, provide ringing
578     if (trim($use_confirmation) != "FALSE") {
579       $AGI->set_variable('__RG_IDX',$ringgroup_index);
580       if ( isset($cidnum) && is_numeric($cidnum) ) {
581         $AGI->set_variable('__CALLCONFIRMCID',$cidnum);
582       } else {
583         $AGI->set_variable('__CALLCONFIRMCID',"999");
584       }
585     }
586     $AGI->set_variable('ds',$ds);
587     $AGI->set_priority(10); // dial command is at priority 10
588   }
589 }
590
591 // sanity check make sure dialstatus is set to something
592 //
593 if (! $ds) {
594   $dialstatus  = get_var( $AGI, "DIALSTATUS" );
595   if (! $dialstatus) {
596     debug("Setting default NOANSWER DIALSTATUS since no extensions available",1);
597     $AGI->set_variable('DIALSTATUS','NOANSWER');
598   }
599 }
600
601 $astman->disconnect();
602
603 // EOF dialparties.agi
604 exit( 0 );
605
606 // helper functions
607 function get_var( $agi, $value) {
608   $r = $agi->get_variable( $value );
609  
610   if ($r['result'] == 1) {
611     $result = $r['data'];
612     return $result;
613   }
614   return '';
615 }
616
617 function get_dial_string( $agi, $extnum, $use_confirmation, $ringgroup_index ) {
618   $dialstring = '';
619  
620   if (strpos($extnum,'#') != 0) {
621     // "#" used to identify external numbers in forwards and callgourps
622     // If using call confirmation, need to put the # back into the new dialstring
623     // we then place all external calls (denoted with a # at the end) through
624     // the [grps] extension for the RINGGROUP_INDEX that was called. This
625     // triggers the call confirmation macro along with the required messages
626     // that were set.
627     //
628     $extnum = str_replace("#", "", $extnum);
629     if (trim($use_confirmation) == "FALSE") {
630       $dialstring = 'Local/'.$extnum.'@from-internal/n';
631     } else {
632       $dialstring = 'Local/RG-'.$ringgroup_index.'-'.$extnum.'#@from-internal';
633     }
634     debug("Built External dialstring component for $extnum: $dialstring", 4);
635   } else {
636     $device_str = sprintf("%s/device", $extnum);
637     $device = $agi->database_get('AMPUSER',$device_str);
638     $device = $device['data'];
639    
640     // a user can be logged into multipe devices, append the dial string for each   
641     $device_array = split( '&', $device );
642     foreach ($device_array as $adevice) {
643       if (trim($use_confirmation) == "FALSE") {
644         $dds = $agi->database_get('DEVICE',$adevice.'/dial');
645         $dialstring .= $dds['data'];
646         $dialstring .= '&';
647       } else {
648         $dialstring .= 'Local/LC-'.$adevice.'@from-internal&';
649       }
650     }
651     $dialstring = trim($dialstring," &");
652   }
653   return $dialstring;
654 }
655
656 function debug($string, $level=3) {
657   global $AGI;
658   $AGI->verbose($string, $level);
659 }
660
661 function mycallback( $rc ) {
662   debug("User hung up. (rc=" . $rc . ")", 1);
663   exit ($rc);
664 }
665
666 function is_ext_avail( $extnum ) {
667   global $astman;
668  
669   $status = $astman->ExtensionState( $extnum, 'from-internal' );
670    
671   $status = $status['Status'];
672   debug("ExtensionState: $status", 4);
673   return $status;
674 }
675
676 ?>
Note: See TracBrowser for help on using the browser.