Open Source Training Seminar FreePBX Paid Support

root/modules/branches/2.3/core/functions.inc.php

Revision 5227, 137.3 kB (checked in by p_lindheimer, 1 year ago)

fix case where additional devices were being assigned to a users and the previous assignments were getting lost

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2
3 // The destinations this module provides
4 // returns a associative arrays with keys 'destination' and 'description'
5 function core_destinations() {
6         //static destinations
7         $extens = array();
8         $category = 'Terminate Call';
9         $extens[] = array('destination' => 'app-blackhole,hangup,1', 'description' => 'Hangup', 'category' => $category);
10         $extens[] = array('destination' => 'app-blackhole,congestion,1', 'description' => 'Congestion', 'category' => $category);
11         $extens[] = array('destination' => 'app-blackhole,busy,1', 'description' => 'Busy', 'category' => $category);
12         $extens[] = array('destination' => 'app-blackhole,zapateller,1', 'description' => 'Play SIT Tone (Zapateller)', 'category' => $category);
13         $extens[] = array('destination' => 'app-blackhole,musiconhold,1', 'description' => 'Put caller on hold forever', 'category' => $category);
14        
15         //get the list of meetmes
16         $results = core_users_list();
17        
18         if (isset($results) && function_exists('voicemail_getVoicemail')) {
19                 //get voicemail
20                 $uservm = voicemail_getVoicemail();
21                 $vmcontexts = array_keys($uservm);
22                 foreach ($results as $thisext) {
23                         $extnum = $thisext[0];
24                         // search vm contexts for this extensions mailbox
25                         foreach ($vmcontexts as $vmcontext) {
26                                 if(isset($uservm[$vmcontext][$extnum])){
27                                         //$vmname = $uservm[$vmcontext][$extnum]['name'];
28                                         //$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>');
29                                         $vmboxes[$extnum] = true;
30                                 }
31                         }
32                 }
33         }
34        
35         // return an associative array with destination and description
36         // core provides both users and voicemail boxes as destinations
37         if (isset($results)) {
38                 foreach($results as $result) {
39                         $extens[] = array('destination' => 'from-did-direct,'.$result['0'].',1', 'description' => ' <'.$result['0'].'> '.$result['1'], 'category' => 'Extensions');
40                         if(isset($vmboxes[$result['0']])) {
41                                 $extens[] = array('destination' => 'ext-local,vmb'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (busy)', 'category' => 'Voicemail');
42                                 $extens[] = array('destination' => 'ext-local,vmu'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (unavail)', 'category' => 'Voicemail');
43                                 $extens[] = array('destination' => 'ext-local,vms'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (no-msg)', 'category' => 'Voicemail');
44                         }
45                 }
46         }
47        
48         if (isset($extens))
49                 return $extens;
50         else
51                 return null;
52
53 }
54
55 /*      Generates dialplan for "core" components (extensions & inbound routing)
56         We call this with retrieve_conf
57 */
58 function core_get_config($engine) {
59         global $ext;  // is this the best way to pass this?
60         global $version;  // this is not the best way to pass this, this should be passetd together with $engine
61         global $amp_conf;
62
63         $modulename = "core";
64        
65         switch($engine) {
66                 case "asterisk":
67                         // FeatureCodes
68                         $fcc = new featurecode($modulename, 'userlogon');
69                         $fc_userlogon = $fcc->getCodeActive();
70                         unset($fcc);
71
72                         $fcc = new featurecode($modulename, 'userlogoff');
73                         $fc_userlogoff = $fcc->getCodeActive();
74                         unset($fcc);
75
76                         $fcc = new featurecode($modulename, 'zapbarge');
77                         $fc_zapbarge = $fcc->getCodeActive();
78                         unset($fcc);
79
80                         $fcc = new featurecode($modulename, 'chanspy');
81                         $fc_chanspy = $fcc->getCodeActive();
82                         unset($fcc);
83
84                         $fcc = new featurecode($modulename, 'simu_pstn');
85                         $fc_simu_pstn = $fcc->getCodeActive();
86                         unset($fcc);
87
88                         $fcc = new featurecode($modulename, 'simu_fax');
89                         $fc_simu_fax = $fcc->getCodeActive();
90                         unset($fcc);
91
92                         $fcc = new featurecode($modulename, 'pickup');
93                         $fc_pickup = $fcc->getCodeActive();
94                         unset($fcc);
95
96                         // Log on / off -- all in one context
97                         if ($fc_userlogoff != '' || $fc_userlogon != '') {
98                                 $ext->addInclude('from-internal-additional', 'app-userlogonoff'); // Add the include from from-internal
99                                
100                                 if ($fc_userlogoff != '') {
101                                         $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_macro('user-logoff'));
102                                         $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_hangup(''));
103                                 }
104        
105                                 if ($fc_userlogon != '') {
106                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon'));
107                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup(''));
108                                        
109                                         $clen = strlen($fc_userlogon);
110                                         $fc_userlogon = "_$fc_userlogon.";
111                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon,${EXTEN:'.$clen.'}'));
112                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup(''));
113                                 }
114                         }
115
116                         // Call pickup using app_pickup - Note that '**xtn' is hard-coded into the GXPs and SNOMs as a number to dial
117                         // when a user pushes a flashing BLF.
118                         if ($fc_pickup != '') {
119                                 $ext->addInclude('from-internal-additional', 'app-pickup');
120                                 $fclen = strlen($fc_pickup);
121                                 $ext->add('app-pickup', "_$fc_pickup.", '', new ext_NoOp('Attempt to Pickup ${EXTEN:'.$fclen.'} by ${CALLERID(num)}'));
122                                 if (strstr($version, 'BRI'))
123                                         $ext->add('app-pickup', "_$fc_pickup.", '', new ext_dpickup('${EXTEN:'.$fclen.'}'));
124                                 else
125                                         $ext->add('app-pickup', "_$fc_pickup.", '', new ext_pickup('${EXTEN:'.$fclen.'}'));
126                         }
127                        
128                        
129                         // zap barge
130                         if ($fc_zapbarge != '') {
131                                 $ext->addInclude('from-internal-additional', 'app-zapbarge'); // Add the include from from-internal
132                                
133                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_macro('user-callerid'));
134                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_setvar('GROUP()','${CALLERID(number)}'));
135                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_answer(''));
136                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_wait(1));
137                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_zapbarge(''));
138                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_hangup(''));
139                         }
140
141                         // chan spy
142                         if ($fc_chanspy != '') {
143                                 $ext->addInclude('from-internal-additional', 'app-chanspy'); // Add the include from from-internal
144                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_macro('user-callerid'));
145                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_answer(''));
146                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_wait(1));
147                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_chanspy(''));
148                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_hangup(''));
149                         }
150                        
151                         // Simulate options (ext-test)
152                         if ($fc_simu_pstn != '' || $fc_simu_fax != '') {
153                                 $ext->addInclude('from-internal-additional', 'ext-test'); // Add the include from from-internal
154                                
155                                 if ($fc_simu_pstn != '') {
156                                         $ext->add('ext-test', $fc_simu_pstn, '', new ext_goto('1', 's', 'from-pstn'));
157                                 }
158
159                                 if ($fc_simu_fax != '') {
160                                         $ext->add('ext-test', $fc_simu_fax, '', new ext_goto('1', 'in_fax', 'ext-fax'));
161                                 }
162
163                                 $ext->add('ext-test', 'h', '', new ext_macro('hangupcall'));
164                         }
165                        
166                         /* Always have Fax detection in ext-did, no matter what */
167                         $ext->add('ext-did', 'fax', '', new ext_goto('1','in_fax','ext-fax'));
168
169                         /* inbound routing extensions */
170                         $didlist = core_did_list();
171                         if(is_array($didlist)){
172                                 $catchall = false;
173                                 $catchall_context='ext-did-catchall';
174                                 foreach($didlist as $item) {
175                                         $did = core_did_get($item['extension'],$item['cidnum'],$item['channel']);
176                                         $exten = $did['extension'];
177                                         $cidnum = $did['cidnum'];
178                                         $channel = $did['channel'];
179
180                                         $exten = (empty($exten)?"s":$exten);
181                                         $exten = $exten.(empty($cidnum)?"":"/".$cidnum); //if a CID num is defined, add it
182
183                                         if (empty($channel))
184                                                 $context = "ext-did";
185                                         else {
186                                                 $context = "macro-from-zaptel-{$channel}";
187                                                 if (!isset($zapchan[$channel])) {
188                                                         // create the macro-from-zaptel-$chan context and load up the
189                                                         // startup settings
190                                                         $ext->add($context, 'fax', '', new ext_goto('1','in_fax','ext-fax'));
191                                                         $ext->add($context, 's', '', new ext_noop('Entering '.$context.' with DID = ${DID}'));
192                                                         $zapchan[$channel] = "unfinished";
193                                                 }
194                                         }
195
196                                         // Start inbound processing. Unneeded line to be possibly overridden by something in
197                                         // extensions_custom.conf
198                                         $ext->add($context, $exten, '', new ext_setvar('__FROM_DID','${EXTEN}'));
199                                         // always set callerID name
200                                         $ext->add($context, $exten, '', new ext_gotoif('$[ "${CALLERID(name)}" != "" ] ','cidok'));
201                                         $ext->add($context, $exten, '', new ext_setvar('CALLERID(name)','${CALLERID(num)}'));
202                                         $ext->add($context, $exten, 'cidok', new ext_noop('CallerID is ${CALLERID(all)}'));
203
204                                         if (!empty($item['mohclass']) && trim($item['mohclass']) != 'default') {
205                                                 $ext->add($context, $exten, '', new ext_setmusiconhold($item['mohclass']));
206                                                 $ext->add($context, $exten, '', new ext_setvar('__MOHCLASS',$item['mohclass']));
207                                         }
208
209                                         // If we require RINGING, signal it as soon as we enter.
210                                         if ($item['ringing'] === "CHECKED") {
211                                                 $ext->add($context, $exten, '', new ext_ringing(''));
212                                         }
213
214                                         if ($exten == "s" && $context == "ext-did") { 
215                                                 //if the exten is s, then also make a catchall for undefined DIDs if it's not a zaptel route
216                                                 $catchaccount = "_X.".(empty($cidnum)?"":"/".$cidnum);
217                                                 if ($catchaccount == "_X.")
218                                                         $catchall = true;
219                                                 $ext->add($catchall_context, $catchaccount, '', new ext_NoOp('Catch-All DID Match - Found ${EXTEN} - You probably want a DID for this.'));
220                                                 $ext->add($catchall_context, $catchaccount, '', new ext_goto('1','s','ext-did'));
221                                         }
222                                        
223                                         if ($item['faxexten'] != "default") {
224                                                 $ext->add($context, $exten, '', new ext_setvar('FAX_RX',$item['faxexten']));
225                                         }
226                                         if (!empty($item['faxemail'])) {
227                                                 $ext->add($context, $exten, '', new ext_setvar('FAX_RX_EMAIL',$item['faxemail']));
228                                         }
229                                         if ($item['answer'] == "1") {
230                                                 $ext->add($context, $exten, '', new ext_answer(''));
231                                                 $ext->add($context, $exten, '', new ext_wait($item['wait']));
232                                         }
233                                         if ($item['answer'] == "2") { // NVFaxDetect
234                                                 $ext->add($context, $exten, '', new ext_answer(''));
235                                                 $ext->add($context, $exten, '', new ext_playtones('ring'));
236                                                 $ext->add($context, $exten, '', new ext_nvfaxdetect($item['wait']));
237                                         }
238                                         if ($item['privacyman'] == "1") {
239                                                 $ext->add($context, $exten, '', new ext_macro('privacy-mgr'));
240                                         }
241                                         if (!empty($item['alertinfo'])) {
242                                                 $ext->add($context, $exten, '', new ext_setvar("__ALERT_INFO", str_replace(';', '\;', $item['alertinfo'])));
243                                         }
244                                         // Add CID prefix, no need to do checks for existing pre-pends, this is an incoming did so this should
245                                         // be the first time the CID is manipulated. We set _RGPREFIX which is the same used throughout the different
246                                         // modules.
247                                         //
248                                         // TODO: If/When RGPREFIX is added to trunks, then see code in ringgroups to strip prefix if added here.
249                                         //
250                                         // TODO: core FreePBX documentation about this standard. (and probably rename from RGPREFIX to CIDPREFIX)
251                                         //
252                                         if (!empty($item['grppre'])) {
253                                                 $ext->add($context, $exten, '', new ext_setvar('_RGPREFIX', $item['grppre']));
254                                                 $ext->add($context, $exten, '', new ext_setvar('CALLERID(name)','${RGPREFIX}${CALLERID(name)}'));
255                                         }
256                                        
257                                         // If we're doing a zaptel route, now we need to do the gotos ONLY IF it's the first time round.
258                                         // Except for the fact that this doesn't work. Not at all. Dial returns -1 and hangs up the
259                                         // call. This is fixed in 1.4 with TryExec(), but until then, we can't match on zap
260                                         // _and_ anything else.  When we decide to say 'Only 1.4!' then we can reenable this
261                                         // and use TryExec(Goto..) and then check ${TRYSTATUS} for FAILED or SUCCESS. I didn't
262                                         // bother actually writing that, as the syntax may change.
263                                         //if (isset($zapchan[$channel]) && $zapchan[$channel] == "unfinished") {
264                                         //      $ext->add($context, 's', '', new ext_gotoif('$[ "${DID}" = "s" ]', 'nos', 'sok'));
265                                         //      $ext->add($context, 's', 'nos', new ext_noop('Skipping ${DID} because it is s'));
266                                         //      $ext->add($context, 's', '', new ext_goto("trycid"));
267                                         //      $ext->add($context, 's', 'sok', new ext_noop('Trying ${DID}'));
268                                         //      $ext->add($context, 's', '', new ext_goto("1", '${DID}'));
269                                         //      $ext->add($context, 's', 'trycid', new ext_gotoif('$[ "${CALLERID(num)}" = "" ]', 'nocid', 'cidok'));
270                                         //      $ext->add($context, 's', 'nocid', new ext_noop('Skipping empty CallerID Num'));
271                                         //      $ext->add($context, 's', '', new ext_goto("end"));
272                                         //      $ext->add($context, 's', 'cidok', new ext_noop('Trying ${DID}/${CALLERID(num)}'));
273                                         //      $ext->add($context, 's', '', new ext_goto("1", '${DID}/${CALLERID(num)}'));
274                                         //      $ext->add($context, 's', 'end', new ext_noop('End of macro init'));
275                                                 // Now set $zapchan[$channel] so we don't do this again
276                                                 $zapchan[$channel] = "set";
277                                         //}
278                                         //the goto destination
279                                         // destination field in 'incoming' database is backwards from what ext_goto expects
280                                         $goto_context = strtok($did['destination'],',');
281                                         $goto_exten = strtok(',');
282                                         $goto_pri = strtok(',');
283                                         $ext->add($context, $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context));
284                                        
285                                 }
286                                 // If there's not a catchall, make one with an error message
287                                 if (!$catchall) {
288                                         $ext->add($catchall_context, 's', '', new ext_noop("No DID or CID Match"));
289                                         $ext->add($catchall_context, 's', '', new ext_answer(''));
290                                         $ext->add($catchall_context, 's', '', new ext_wait('2'));
291                                         $ext->add($catchall_context, 's', '', new ext_playback('ss-noservice'));
292                                         $ext->add($catchall_context, 's', '', new ext_sayalpha('${FROM_DID}'));
293                                         $ext->add($catchall_context, '_[*#X].', '', new ext_setvar('__FROM_DID', '${EXTEN}'));
294                                         $ext->add($catchall_context, '_[*#X].', '', new ext_noop('Received an unknown call with DID set to ${EXTEN}'));
295                                         $ext->add($catchall_context, '_[*#X].', '', new ext_goto('1','s','ext-did'));
296                                 }
297                                        
298                         }
299
300                         /* MODIFIED (PL)
301                          *
302                          * Add Direct DIDs
303                          *
304                          * This functions creates a new context, ext-did-direct, used to route an incoming DID directly to the specified user.
305                          * The purpose is to use when a user has a personal external DID. This keeps it clean and easy to administer.
306                          * Any conflict with those routes will depend on which of the two contexts are included first in the extensions.conf file.
307                          *
308                          * Calls are sent to context from-did-direct though this feature. You must create that context in extenions.conf or
309                          * in extensions_custom.conf and it should look something like:
310                          *
311                          * [from-did-direct]
312                          * include => ext-findmefollow
313                          * include => ext-local
314                          *
315                          * This is so that personal ring groups are used if they exist for the direct did and if not, then the local extension.
316                          * If the module is not implented, it will just go to the users extension.
317                          */
318
319                         $directdidlist = core_directdid_list();
320                         if(is_array($directdidlist)){
321                                 $context = "ext-did";
322                                 if(!is_array($didlist)){
323                                         /* if not set above, add one here */
324                                         $ext->add($context, 'fax', '', new ext_goto('1','in_fax','ext-fax'));
325                                 }
326                                 foreach($directdidlist as $item) {
327                                         $exten = $item['directdid'];
328                                         $ext->add($context, $exten, '', new ext_setvar('__FROM_DID','${EXTEN}'));
329                                         // always set callerID name
330                                         $ext->add($context, $exten, '', new ext_gotoif('$[ "${CALLERID(name)}" != "" ] ','cidok'));
331                                         $ext->add($context, $exten, '', new ext_setvar('CALLERID(name)','${CALLERID(num)}'));
332                                         $ext->add($context, $exten, 'cidok', new ext_noop('CallerID is ${CALLERID(all)}'));
333
334                                         if (!empty($item['mohclass']) && trim($item['mohclass']) != 'default') {
335                                                 $ext->add($context, $exten, '', new ext_setmusiconhold($item['mohclass']));
336                                                 $ext->add($context, $exten, '', new ext_setvar('__MOHCLASS',$item['mohclass']));
337                                         }
338                                        
339                                         if ($item['faxexten'] != "default") {
340                                                 $ext->add($context, $exten, '', new ext_setvar('FAX_RX',$item['faxexten']));
341                                         }
342                                         if (!empty($item['faxemail'])) {
343                                                 $ext->add($context, $exten, '', new ext_setvar('FAX_RX_EMAIL',$item['faxemail']));
344                                         }
345                                         if ($item['answer'] == "1") {
346                                                 $ext->add($context, $exten, '', new ext_answer(''));
347                                                 $ext->add($context, $exten, '', new ext_wait($item['wait']));
348                                         }
349                                         if ($item['answer'] == "2") { // NVFaxDetect
350                                                 $ext->add($context, $exten, '', new ext_answer(''));
351                                                 $ext->add($context, $exten, '', new ext_playtones('ring'));
352                                                 $ext->add($context, $exten, '', new ext_nvfaxdetect($item['wait']));
353                                         }
354                                         if ($item['privacyman'] == "1") {
355                                                 $ext->add($context, $exten, '', new ext_macro('privacy-mgr'));
356                                         }
357
358
359                                         if (!empty($item['didalert'])) {
360                                                 $ext->add($context, $exten, '', new ext_setvar("_ALERT_INFO", str_replace(';', '\;', $item['didalert'])));
361                                         }
362                                         $goto_context = 'from-did-direct';
363                                         $goto_exten = $item['extension'];
364                                         $goto_pri = 1;
365                                         $ext->add($context, $exten, '', new ext_goto($goto_pri,$goto_exten,$goto_context));
366
367                                 }
368                         }
369
370                        
371                         /* user extensions */
372                         $ext->addInclude('from-internal-additional','ext-local');
373                         $userlist = core_users_list();
374                         if (is_array($userlist)) {
375                                 foreach($userlist as $item) {
376                                         $exten = core_users_get($item[0]);
377                                         $vm = ((($exten['voicemail'] == "novm") || ($exten['voicemail'] == "disabled") || ($exten['voicemail'] == "")) ? "novm" : $exten['extension']);
378
379                                         if (isset($exten['ringtimer']) && $exten['ringtimer'] != 0)
380                                                 $ext->add('ext-local', $exten['extension'], '', new ext_setvar('__RINGTIMER',$exten['ringtimer']));
381                                        
382                                         $ext->add('ext-local', $exten['extension'], '', new ext_macro('exten-vm',$vm.",".$exten['extension']));
383                                         $ext->add('ext-local', $exten['extension'], '', new ext_hangup(''));
384                                        
385                                         if($vm != "novm") {
386                                                 $ext->add('ext-local', '${VM_PREFIX}'.$exten['extension'], '', new ext_macro('vm',"$vm,DIRECTDIAL"));
387                                                 $ext->add('ext-local', '${VM_PREFIX}'.$exten['extension'], '', new ext_hangup(''));
388                                                 $ext->add('ext-local', 'vmb'.$exten['extension'], '', new ext_macro('vm',"$vm,BUSY"));
389                                                 $ext->add('ext-local', 'vmb'.$exten['extension'], '', new ext_hangup(''));
390                                                 $ext->add('ext-local', 'vmu'.$exten['extension'], '', new ext_macro('vm',"$vm,NOANSWER"));
391                                                 $ext->add('ext-local', 'vmu'.$exten['extension'], '', new ext_hangup(''));
392                                                 $ext->add('ext-local', 'vms'.$exten['extension'], '', new ext_macro('vm',"$vm,NOMESSAGE"));
393                                                 $ext->add('ext-local', 'vms'.$exten['extension'], '', new ext_hangup(''));
394                                         }
395                                                
396                                         $hint = core_hint_get($exten['extension']);
397                                         if (!empty($hint))
398                                                 $ext->addHint('ext-local', $exten['extension'], $hint);
399                                         if ($exten['sipname']) {
400                                                 $ext->add('ext-local', $exten['sipname'], '', new ext_goto('1',$item[0],'from-internal'));
401                                         }
402                                 }
403                         }
404
405                         // create from-trunk context for each trunk that adds counts to channels
406                         //
407                         $trunklist = core_trunks_list(true);
408                         if (is_array($trunklist)) {
409                                 foreach ($trunklist as $trunkprops) {
410                                         if (trim($trunkprops['value']) == 'on') {
411                                                 // value of on is disabled and for zap we don't create a context
412                                                 continue;
413                                         }
414                                         switch ($trunkprops['tech']) {
415                                                 case 'IAX':
416                                                 case 'IAX2':
417                                                 case 'SIP':
418                                                         $trunkgroup = $trunkprops['globalvar'];
419                                                         $trunkcontext  = "from-trunk-".$trunkprops['name'];
420                                                         $ext->add($trunkcontext, '_.', '', new ext_setvar('GROUP()',$trunkgroup));
421                                                         $ext->add($trunkcontext, '_.', '', new ext_goto('1','${EXTEN}','from-trunk'));
422                                                         break;
423                                                 default:
424                                         }
425                                 }
426                         }
427
428                         /* dialplan globals */
429                         // modules should NOT use the globals table to store anything!
430                         // modules should use $ext->addGlobal("testvar","testval"); in their module_get_config() function instead
431                         // I'm cheating for core functionality - do as I say, not as I do ;-)           
432
433                         // Auto add these globals to give access to agi scripts and other needs, unless defined in the global table.
434                         //
435                         $amp_conf_globals = array(
436                                 "ASTETCDIR",
437                                 "ASTMODDIR",
438                                 "ASTVARLIBDIR",
439                                 "ASTAGIDIR",
440                                 "ASTSPOOLDIR",
441                                 "ASTRUNDIR",
442                                 "ASTLOGDIR",
443                                 "CWINUSEBUSY",
444                                 "AMPMGRUSER",
445                                 "AMPMGRPASS"
446                         );
447
448                         $sql = "SELECT * FROM globals";
449                         $globals = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
450                         foreach($globals as $global) {
451                                 $ext->addGlobal($global['variable'],$global['value']);
452
453                                 // now if for some reason we have a variable in the global table
454                                 // that is in our $amp_conf_globals list, then remove it so we
455                                 // don't duplicate, the sql table will take precedence
456                                 //
457                                 if (array_key_exists($global['variable'],$amp_conf_globals)) {
458                                         $rm_keys = array_keys($amp_conf_globals,$global['variable']);
459                                         foreach ($rm_keys as $index) {
460                                                 unset($amp_conf_globals[$index]);
461                                         }
462                                 }
463                         }
464                         foreach ($amp_conf_globals as $global) {
465                                 if (isset($amp_conf[$global])) {
466                                         $value = $amp_conf[$global];
467                                         if ($value === true || $value === false) {
468                                                 $value = ($value) ? 'true':'false';
469                                         }
470                                         $ext->addGlobal($global, $value);
471                                         out("Added to globals: $global = $value");
472                                 }
473                         }
474                        
475                         /* outbound routes */
476                         // modules should use their own table for storage (and module_get_config() to add dialplan)
477                         // modules should NOT use the extension table to store anything!
478                         $sql = "SELECT application FROM extensions where context = 'outbound-allroutes' ORDER BY application";
479                         $outrts = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
480                         $ext->addInclude('from-internal-additional','outbound-allroutes');
481                         $ext->add('outbound-allroutes', 'foo', '', new ext_noop('bar'));
482                         foreach($outrts as $outrt) {
483                                 $ext->addInclude('outbound-allroutes',$outrt['application']);
484                                 $sql = "SELECT * FROM extensions where context = '".$outrt['application']."' ORDER BY extension, CAST(priority AS UNSIGNED) ASC";
485                                 $thisrt = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
486                                 foreach($thisrt as $exten) {
487                                         //if emergencyroute, then set channel var
488                                         if(strpos($exten['args'],"EMERGENCYROUTE") !== false)
489                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_setvar("EMERGENCYROUTE",substr($exten['args'],15)));
490                                         if(strpos($exten['args'],"INTRACOMPANYROUTE") !== false)
491                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_setvar("INTRACOMPANYROUTE",substr($exten['args'],18)));
492                                         // Don't set MOHCLASS if already set, threre may be a feature code that overrode it
493                                         if(strpos($exten['args'],"MOHCLASS") !== false)
494                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_setvar("MOHCLASS", '${IF($["x${MOHCLASS}"="x"]?'.substr($exten['args'],9).':${MOHCLASS})}' ));
495                                         if(strpos($exten['args'],"dialout-trunk") !== false)
496                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_macro($exten['args']));
497                                         if(strpos($exten['args'],"dialout-enum") !== false)
498                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_macro($exten['args']));
499                                         if(strpos($exten['args'],"outisbusy") !== false)
500                                                 $ext->add($outrt['application'], $exten['extension'], '', new ext_macro("outisbusy"));
501                                 }
502                         }
503                         general_generate_indications();
504
505                         // "blackhole" destinations
506                         $ext->add('app-blackhole', 'hangup', '', new ext_noop('Blackhole Dest: Hangup'));
507                         $ext->add('app-blackhole', 'hangup', '', new ext_hangup());
508
509                         $ext->add('app-blackhole', 'zapateller', '', new ext_noop('Blackhole Dest: Play SIT Tone'));
510                         $ext->add('app-blackhole', 'zapateller', '', new ext_answer());
511                         $ext->add('app-blackhole', 'zapateller', '', new ext_zapateller());
512                         // Should hangup ?
513                         // $ext->add('app-blackhole', 'zapateller', '', new ext_hangup());
514                                        
515                         $ext->add('app-blackhole', 'musiconhold', '', new ext_noop('Blackhole Dest: Put caller on hold forever'));
516                         $ext->add('app-blackhole', 'musiconhold', '', new ext_answer());
517                         $ext->add('app-blackhole', 'musiconhold', '', new ext_musiconhold());
518
519                         $ext->add('app-blackhole', 'congestion', '', new ext_noop('Blackhole Dest: Congestion'));
520                         $ext->add('app-blackhole', 'congestion', '', new ext_answer());
521                         $ext->add('app-blackhole', 'congestion', '', new ext_playtones('congestion'));
522                         $ext->add('app-blackhole', 'congestion', '', new ext_congestion());
523                         $ext->add('app-blackhole', 'congestion', '', new ext_hangup());
524
525                         $ext->add('app-blackhole', 'busy', '', new ext_noop('Blackhole Dest: Busy'));
526                         $ext->add('app-blackhole', 'busy', '', new ext_answer());
527                         $ext->add('app-blackhole', 'busy', '', new ext_playtones('busy'));
528                         $ext->add('app-blackhole', 'busy', '', new ext_busy());
529                         $ext->add('app-blackhole', 'busy', '', new ext_hangup());
530
531                         if ($amp_conf['AMPBADNUMBER'] !== false) {
532                                 $context = 'bad-number';
533                                 $exten = '_X.';
534                                 $ext->add($context, $exten, '', new extension('ResetCDR()'));
535                                 $ext->add($context, $exten, '', new extension('NoCDR()'));
536                                 $ext->add($context, $exten, '', new ext_wait('1'));
537                                 $ext->add($context, $exten, '', new ext_playback('silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer'));
538                                 $ext->add($context, $exten, '', new ext_wait('1'));
539                                 $ext->add($context, $exten, '', new ext_congestion('20'));
540                                 $ext->add($context, $exten, '', new ext_hangup());
541
542                                 $exten = '_*.';
543                                 $ext->add($context, $exten, '', new extension('ResetCDR()'));
544                                 $ext->add($context, $exten, '', new extension('NoCDR()'));
545                                 $ext->add($context, $exten, '', new ext_wait('1'));
546                                 $ext->add($context, $exten, '', new ext_playback('silence/1&feature-not-avail-line&silence/1&cannot-complete-as-dialed&check-number-dial-again,noanswer'));
547                                 $ext->add($context, $exten, '', new ext_wait('1'));
548                                 $ext->add($context, $exten, '', new ext_congestion('20'));
549                                 $ext->add($context, $exten, '', new ext_hangup());
550                         }
551
552                 break;
553         }
554 }
555
556
557
558
559
560
561
562
563
564
565
566 /* begin page.ampusers.php functions */
567
568 function core_ampusers_add($username, $password, $extension_low, $extension_high, $deptname, $sections) {
569         $sql = "INSERT INTO ampusers (username, password, extension_low, extension_high, deptname, sections) VALUES (";
570         $sql .= "'".$username."',";
571         $sql .= "'".$password."',";
572         $sql .= "'".$extension_low."',";
573         $sql .= "'".$extension_high."',";
574         $sql .= "'".$deptname."',";
575         $sql .= "'".implode(";",$sections)."');";
576        
577         sql($sql,"query");
578 }
579
580 function core_ampusers_del($username) {
581         $sql = "DELETE FROM ampusers WHERE username = '".$username."'";
582         sql($sql,"query");
583 }