root/modules/branches/2.2/ringgroups/functions.inc.php

Revision 3168, 6.3 kB (checked in by p_lindheimer, 6 years ago)

add NODEST to queues, ringgroups and findmefollow, this allows ringgroups and queues to tell its children not to go to voicemail or other destination-if-no-answer which is often voicemail or other undesirable places. Ringgroups can be both a parent and a child of such

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2
3 // The destinations this module provides
4 // returns a associative arrays with keys 'destination' and 'description'
5 function ringgroups_destinations() {
6     //get the list of ringgroups
7     $results = ringgroups_list();
8     
9     // return an associative array with destination and description
10     if (isset($results)) {
11         foreach($results as $result){
12                 $thisgrp = ringgroups_get(ltrim($result['0']));
13                 $extens[] = array('destination' => 'ext-group,'.ltrim($result['0']).',1', 'description' => $thisgrp['description'].' <'.ltrim($result['0']).'>');
14         }
15     }
16     
17     if (isset($extens))
18         return $extens;
19     else
20         return null;
21 }
22
23 /*     Generates dialplan for ringgroups
24     We call this with retrieve_conf
25 */
26 function ringgroups_get_config($engine) {
27     global $ext// is this the best way to pass this?
28     switch($engine) {
29         case "asterisk":
30             $ext->addInclude('from-internal-additional','ext-group');
31             $contextname = 'ext-group';
32             $ringlist = ringgroups_list();
33             if (is_array($ringlist)) {
34                 foreach($ringlist as $item) {
35                     $grpnum = ltrim($item['0']);
36                     $grp = ringgroups_get($grpnum);
37                     
38                     $strategy = $grp['strategy'];
39                     $grptime = $grp['grptime'];
40                     $grplist = $grp['grplist'];
41                     $postdest = $grp['postdest'];
42                     $grppre = (isset($grp['grppre'])?$grp['grppre']:'');
43                     $annmsg = (isset($grp['annmsg'])?$grp['annmsg']:'');
44                     $alertinfo = $grp['alertinfo'];
45                     $needsconf = $grp['needsconf'];
46                     $remotealert = $grp['remotealert'];
47                     $toolate = $grp['toolate'];
48                     $ringing = $grp['ringing'];
49
50                     if($ringing == 'Ring' || empty($ringing) ) {
51                         $dialopts = '${DIAL_OPTIONS}';
52                     } else {
53                         // We need the DIAL_OPTIONS variable
54                         $sops = sql("SELECT value from globals where variable='DIAL_OPTIONS'", "getRow");
55                         $dialopts = "m(${ringing})".str_replace('r', '', $sops[0]);
56                     }
57                         
58
59                     $ext->add($contextname, $grpnum, '', new ext_macro('user-callerid'));
60
61                     // Remember if we should go to our own destination (in case we are a child) and then tell all our
62                     // children not to go to their destinations
63                     //
64                     $ext->add($contextname, $grpnum, '', new ext_setvar('RRNODEST', '${NODEST}'));
65                     $ext->add($contextname, $grpnum, '', new ext_setvar('NODEST', '${EXTEN}'));
66                     
67                     // deal with group CID prefix
68                     $ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RGPREFIX}" = "foo"]', 'REPCID'));
69                     $ext->add($contextname, $grpnum, '', new ext_noop('Current RGPREFIX is ${RGPREFIX}....stripping from Caller ID'));
70                     $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)', '${CALLERID(name):${LEN(${RGPREFIX})}}'));
71                     $ext->add($contextname, $grpnum, '', new ext_setvar('RGPREFIX', ''));
72                     $ext->add($contextname, $grpnum, 'REPCID', new ext_noop('CALLERID(name) is ${CALLERID(name)}'));
73                     if ($grppre != '') {
74                         $ext->add($contextname, $grpnum, '', new ext_setvar('RGPREFIX', $grppre));
75                         $ext->add($contextname, $grpnum, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
76                     }
77                     
78                     // Set Alert_Info
79                     if ($alertinfo != '') {
80                         $ext->add($contextname, $grpnum, '', new ext_setvar('_ALERT_INFO', str_replace(';', '\;', $alertinfo)));
81                     }
82
83                     // recording stuff
84                     $ext->add($contextname, $grpnum, '', new ext_setvar('RecordMethod','Group'));
85                     $ext->add($contextname, $grpnum, '', new ext_macro('record-enable',$grplist.',${RecordMethod}'));
86
87                     // group dial
88                     $ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',$strategy));
89                     if ($annmsg != '') {
90                         $ext->add($contextname, $grpnum, '', new ext_answer(''));
91                         $ext->add($contextname, $grpnum, '', new ext_wait(1));
92                         $ext->add($contextname, $grpnum, '', new ext_playback($annmsg));
93                     }
94                     if ($needsconf == "CHECKED") {
95                         $len=strlen($grpnum)+4;
96                         $ext->add("grps", "_RG-${grpnum}-.", '', new ext_macro('dial',$grptime.
97                             ",M(confirm^${remotealert}^${toolate}^${grpnum})$dialopts".',${EXTEN:'.$len.'}'));
98                         $ext->add($contextname, $grpnum, 'DIALGRP', new ext_macro('dial-confirm',"$grptime,$dialopts,$grplist,$grpnum"));
99                     } else {
100                         $ext->add($contextname, $grpnum, 'DIALGRP', new ext_macro('dial',$grptime.",$dialopts,".$grplist));
101                     }
102                     $ext->add($contextname, $grpnum, '', new ext_setvar('RingGroupMethod',''));
103
104
105                     // Now if we were told to skip the destination, do so now. Otherwise reset NODEST and proceed to our destination.
106                     //
107                     $ext->add($contextname, $grpnum, '', new ext_gotoif('$["foo${RRNODEST}" != "foo"]', 'nodest'));
108                     $ext->add($contextname, $grpnum, '', new ext_setvar('_NODEST', ''));
109
110                     // where next?
111                     if ((isset($postdest) ? $postdest : '') != '') {
112                         $ext->add($contextname, $grpnum, '', new ext_goto($postdest));
113                     } else {
114                         $ext->add($contextname, $grpnum, '', new ext_hangup(''));
115                     }
116                     $ext->add($contextname, $grpnum, 'nodest', new ext_noop('SKIPPING DEST, CALL CAME FROM Q/RG: ${RRNODEST}'));
117                 }
118             }
119         break;
120     }
121 }
122
123 function ringgroups_add($grpnum,$strategy,$grptime,$grplist,$postdest,$desc,$grppre='',$annmsg='',$alertinfo,$needsconf,$remotealert,$toolate,$ringing) {
124     $sql = "INSERT INTO ringgroups (grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo, needsconf, remotealert, toolate, ringing) VALUES (".$grpnum.", '".str_replace("'", "''", $strategy)."', ".str_replace("'", "''", $grptime).", '".str_replace("'", "''", $grppre)."', '".str_replace("'", "''", $grplist)."', '".str_replace("'", "''", $annmsg)."', '".str_replace("'", "''", $postdest)."', '".str_replace("'", "''", $desc)."', '".str_replace("'", "''", $alertinfo)."', '$needsconf', '$remotealert', '$toolate', '$ringing')";
125     $results = sql($sql);
126 }
127
128 function ringgroups_del($grpnum) {
129     $results = sql("DELETE FROM ringgroups WHERE grpnum = $grpnum","query");
130 }
131
132 function ringgroups_list() {
133     $results = sql("SELECT grpnum, description FROM ringgroups ORDER BY grpnum","getAll",DB_FETCHMODE_ASSOC);
134     foreach ($results as $result) {
135         if (isset($result['grpnum']) && checkRange($result['grpnum'])) {
136             $grps[] = array($result['grpnum'], $result['description']);
137         }
138     }
139     if (isset($grps))
140         return $grps;
141     else
142         return null;
143 }
144
145 function ringgroups_get($grpnum) {
146     $results = sql("SELECT grpnum, strategy, grptime, grppre, grplist, annmsg, postdest, description, alertinfo, needsconf, remotealert, toolate, ringing FROM ringgroups WHERE grpnum = $grpnum","getRow",DB_FETCHMODE_ASSOC);
147     return $results;
148 }
149 ?>
150
Note: See TracBrowser for help on using the browser.