Open Source Training Seminar FreePBX Paid Support

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

Revision 6364, 189.2 kB (checked in by p_lindheimer, 2 weeks ago)

Merged revisions 6363 via svnmerge from re #3040
http://svn.freepbx.org/modules/branches/2.5

........

r6363 | p_lindheimer | 2008-08-12 14:23:58 -0700 (Tue, 12 Aug 2008) | 1 line


fixes #3040 use OUTBOUND_GROUP instead of GROUP() to count outbound calls so the count is attached to the outboudn channel, otherwise features like a subsequently parked call loses the count

........

  • 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 class core_conf {
4         var $_sip_general    = array();
5         var $_iax_general    = array();
6         var $_featuregeneral = array();
7         var $_featuremap     = array();
8         var $_applicationmap = array();
9         // return an array of filenames to write
10         function get_filename() {
11                 $files = array(
12                         'sip_additional.conf',
13                         'sip_registrations.conf',
14                         'iax_additional.conf',
15                         'iax_registrations.conf',
16                         'zapata_additional.conf',
17                         'sip_general_additional.conf',
18                         'iax_general_additional.conf',
19                         'features_general_additional.conf',
20                         'features_applicationmap_additional.conf',
21                         'features_featuremap_additional.conf',
22                         );
23                 return $files;
24         }
25        
26         // return the output that goes in each of the files
27         function generateConf($file) {
28                 global $version;
29
30                 switch ($file) {
31                         case 'sip_general_additional.conf':
32                                 return $this->generate_sip_general_additional($version);
33                                 break;
34                         case 'sip_additional.conf':
35                                 return $this->generate_sip_additional($version);
36                                 break;
37                         case 'sip_registrations.conf':
38                                 return $this->generate_sip_registrations($version);
39                                 break;
40                         case 'iax_general_additional.conf':
41                                 return $this->generate_iax_general_additional($version);
42                                 break;
43                         case 'iax_additional.conf':
44                                 return $this->generate_iax_additional($version);
45                                 break;
46                         case 'iax_registrations.conf':
47                                 return $this->generate_iax_registrations($version);
48                                 break;
49                         case 'zapata_additional.conf':
50                                 return $this->generate_zapata_additional($version);
51                                 break;
52                         case 'features_general_additional.conf':
53                                 return $this->generate_featuregeneral_additional($version);
54                                 break;
55                         case 'features_applicationmap_additional.conf':
56                                 return $this->generate_applicationmap_additional($version);
57                                 break;
58                         case 'features_featuremap_additional.conf':
59                                 return $this->generate_featuremap_additional($version);
60                                 break;
61                 }
62         }
63
64         function addSipGeneral($key, $value) {
65                 $this->_sip_general[] = array('key' => $key, 'value' => $value);
66         }
67
68         function generate_sip_general_additional($ast_version) {
69                 $output = '';
70
71                 if (isset($this->_sip_general) && is_array($this->_sip_general)) {
72                         foreach ($this->_sip_general as $values) {
73                                 $output .= $values['key']."=".$values['value']."\n";
74                         }
75                 }
76                 return $output;
77         }
78
79         function addIaxGeneral($key, $value) {
80                 $this->_iax_general[] = array('key' => $key, 'value' => $value);
81         }
82
83         function generate_iax_general_additional($ast_version) {
84                 $output = '';
85
86                 if (isset($this->_iax_general) && is_array($this->_iax_general)) {
87                         foreach ($this->_iax_general as $values) {
88                                 $output .= $values['key']."=".$values['value']."\n";
89                         }
90                 }
91                 return $output;
92         }
93
94         function addFeatureGeneral($key, $value) {
95                 $this->_featuregeneral[] = array('key' => $key, 'value' => $value);
96         }
97
98         function generate_featuregeneral_additional($ast_version) {
99                 $output = '';
100
101                 if (isset($this->_featuregeneral) && is_array($this->_featuregeneral)) {
102                         foreach ($this->_featuregeneral as $values) {
103                                 $output .= $values['key']."=".$values['value']."\n";
104                         }
105                 }
106                 return $output;
107         }
108
109         function addFeatureMap($key, $value) {
110                 $this->_featuremap[] = array('key' => $key, 'value' => $value);
111         }
112
113         function generate_featuremap_additional($ast_version) {
114                 $output = '';
115
116                 if (isset($this->_featuremap) && is_array($this->_featuremap)) {
117                         foreach ($this->_featuremap as $values) {
118                                 $output .= $values['key']."=".$values['value']."\n";
119                         }
120                 }
121                 return $output;
122         }
123
124         function addApplicationMap($key, $value) {
125                 $this->_applicationmap[] = array('key' => $key, 'value' => $value);
126         }
127
128         function generate_applicationmap_additional($ast_version) {
129                 $output = '';
130
131                 if (isset($this->_applicationmap) && is_array($this->_applicationmap)) {
132                         foreach ($this->_applicationmap as $values) {
133                                 $output .= $values['key']."=".$values['value']."\n";
134                         }
135                 }
136                 return $output;
137         }
138
139         function generate_sip_additional($ast_version) {
140                 global $db;
141
142                 $table_name = "sip";
143                 $additional = "";
144                 $output = "";
145
146                 // Asterisk 1.4 requires call-limit be set for hints to work properly
147                 //
148                 if (version_compare($ast_version, "1.4", "ge")) {
149                         $call_limit = "call-limit=50\n";
150                         $ver12 = false;
151                 } else {
152                         $call_limit = "";
153                         $ver12 = true;
154                 }
155
156                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
157                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
158                 if(DB::IsError($results)) {
159                 die($results->getMessage());
160                 }
161                 foreach ($results as $result) {
162                         if ($ver12) {
163                                 $additional .= $result['keyword']."=".$result['data']."\n";
164                         } else {
165                                 $option = $result['data'];
166                                 switch (strtolower($result['keyword'])) {
167                                         case 'insecure':
168                                                 if ($option == 'very')
169                                                         $additional .= "insecure=port,invite\n";
170                                                 else if ($option == 'yes')
171                                                         $additional .= "insecure=port\n";
172                                                 else
173                                                         $additional .= $result['keyword']."=$option\n";
174                                                 break;
175                                         case 'allow':
176                                         case 'disallow':
177                                                 if ($option != '')
178                                                         $additional .= $result['keyword']."=$option\n";
179                                                 break;
180                                         default:
181                                                 $additional .= $result['keyword']."=$option\n";
182                                 }
183                         }
184                 }
185
186                 $sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
187                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
188                 if(DB::IsError($results)) {
189                 die($results->getMessage());
190                 }
191
192                 foreach ($results as $result) {
193                         $account = $result['data'];
194                         $id = $result['id'];
195                         $output .= "[$account]\n";
196        
197                         $sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
198                         $results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
199                         if(DB::IsError($results2)) {
200                         die($results2->getMessage());
201                         }
202                         foreach ($results2 as $result2) {
203                                 $options = explode("&", $result2['data']);
204                                 if ($ver12) {
205                                         foreach ($options as $option) {
206                                                 $output .= $result2['keyword']."=$option\n";
207                                         }
208                                 } else {
209                                         foreach ($options as $option) {
210                                                 switch (strtolower($result2['keyword'])) {
211                                                         case 'insecure':
212                                                                 if ($option == 'very')
213                                                                         $output .= "insecure=port,invite\n";
214                                                                 else if ($option == 'yes')
215                                                                         $output .= "insecure=port\n";
216                                                                 else
217                                                                         $output .= $result2['keyword']."=$option\n";
218                                                                 break;
219                                                         case 'allow':
220                                                         case 'disallow':
221                                                                 if ($option != '')
222                                                                         $output .= $result2['keyword']."=$option\n";
223                                                                 break;
224                                                         default:
225                                                                 $output .= $result2['keyword']."=$option\n";
226                                                 }
227                                         }
228                                 }
229                         }
230                         if ($call_limit && (substr($id,0,4) != "9999" | $id < 99990)) {
231
232                                 $output .= $call_limit;
233                         }
234                         $output .= $additional."\n";
235                 }
236                 return $output;
237         }
238
239         function generate_sip_registrations($ast_version) {
240                 global $db;
241
242                 $table_name = "sip";
243                 $output = "";
244
245                 // items with id like 9999999% get put in registrations file
246                 //
247                 $sql = "SELECT keyword,data from $table_name where id LIKE '9999999%' and keyword <> 'account' and flags <> 1";
248                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
249                 if(DB::IsError($results)) {
250                 die($results->getMessage());
251                 }
252
253                 foreach ($results as $result) {
254                         $output .= $result['keyword']."=".$result['data']."\n";
255                 }
256
257                 return $output;
258         }
259
260         function generate_iax_additional($ast_version) {
261                 global $db;
262
263                 $table_name = "iax";
264                 $additional = "";
265                 $output = "";
266
267                 $ver12 = version_compare($ast_version, '1.4', 'lt');
268
269                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
270                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
271                 if(DB::IsError($results)) {
272                 die($results->getMessage());
273                 }
274                 foreach ($results as $result) {
275                         if ($ver12) {
276                                 $additional .= $result['keyword']."=".$result['data']."\n";
277                         } else {
278                                 $option = $result['data'];
279                                 switch ($result['keyword']) {
280                                         case 'notransfer':
281                                                 if (strtolower($option) == 'yes') {
282                                                         $additional .= "transfer=no\n";
283                                                 } else if (strtolower($option) == 'no') {
284                                                         $additional .= "transfer=yes\n";
285                                                 } else if (strtolower($option) == 'mediaonly') {
286                                                         $additional .= "transfer=mediaonly\n";
287                                                 } else {
288                                                         $additional .= $result['keyword']."=$option\n";
289                                                 }
290                                                 break;
291                                         case 'allow':
292                                         case 'disallow':
293                                                 if ($option != '')
294                                                         $additional .= $result['keyword']."=$option\n";
295                                                 break;
296                                         default:
297                                                 $additional .= $result['keyword']."=$option\n";
298                                 }
299                         }
300                 }
301
302                 $sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
303                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
304                 if(DB::IsError($results)) {
305                 die($results->getMessage());
306                 }
307                
308                 foreach ($results as $result) {
309                         $account = $result['data'];
310                         $id = $result['id'];
311                         $output .= "[$account]\n";
312        
313                         $sql = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and flags <> 1 order by flags, keyword DESC";
314                         $results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
315                         if(DB::IsError($results2)) {
316                         die($results2->getMessage());
317                         }       
318                         foreach ($results2 as $result2) {
319                                 $options = explode("&", $result2['data']);
320                                 if ($ver12) {
321                                         foreach ($options as $option) {
322                                                 $output .= $result2['keyword']."=$option\n";
323                                         }
324                                 } else {
325                                         foreach ($options as $option) {
326                                                 switch ($result2['keyword']) {
327                                                         case 'notransfer':
328                                                                 if (strtolower($option) == 'yes') {
329                                                                         $output .= "transfer=no\n";
330                                                                 } else if (strtolower($option) == 'no') {
331                                                                         $output .= "transfer=yes\n";
332                                                                 } else if (strtolower($option) == 'mediaonly') {
333                                                                         $output .= "transfer=mediaonly\n";
334                                                                 } else {
335                                                                         $output .= $result2['keyword']."=$option\n";
336                                                                 }
337                                                                 break;
338                                                         case 'allow':
339                                                         case 'disallow':
340                                                                 if ($option != '')
341                                                                         $output .= $result2['keyword']."=$option\n";
342                                                                 break;
343                                                         default:
344                                                                 $output .= $result2['keyword']."=$option\n";
345                                                 }
346                                         }
347                                 }
348                         }
349                         $output .= $additional."\n";
350                 }
351                 return $output;
352         }
353
354         function generate_iax_registrations($ast_version) {
355                 global $db;
356
357                 $table_name = "iax";
358                 $output = "";
359
360                 // items with id like 9999999% get put in the registration file
361                 //
362                 $sql = "SELECT keyword,data from $table_name where id LIKE '9999999%' and keyword <> 'account' and flags <> 1";
363                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
364                 if(DB::IsError($results)) {
365                 die($results->getMessage());
366                 }
367
368                 foreach ($results as $result) {
369                         $output .= $result['keyword']."=".$result['data']."\n";
370                 }
371
372                 return $output;
373         }
374
375         function generate_zapata_additional($ast_version) {
376                 global $db;
377
378                 $table_name = "zap";
379
380                 $additional = "";
381                 $output = '';
382
383                 $sql = "SELECT keyword,data from $table_name where id=-1 and keyword <> 'account' and flags <> 1";
384                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
385                 if(DB::IsError($results)) {
386                 die($results->getMessage());
387                 }
388                 foreach ($results as $result) {
389                         $additional .= $result['keyword']."=".$result['data']."\n";
390                 }
391
392                 $sql = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
393                 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
394                 if(DB::IsError($results)) {
395                 die($results->getMessage());
396                 }
397
398                 foreach ($results as $result) {
399                         $account = $result['data'];
400                         $id = $result['id'];
401                         $output .= ";;;;;;[$account]\n";
402        
403                         $sql = "SELECT keyword,data from $table_name where id=$id and keyword <> 'account' and flags <> 1 order by keyword DESC";
404                         $results2 = $db->getAll($sql, DB_FETCHMODE_ASSOC);
405                         if(DB::IsError($results2)) {
406                         die($results2->getMessage());
407                         }
408                         $zapchannel="";
409                         foreach ($results2 as $result2) {
410                                 if ($result2['keyword'] == 'channel') {
411                                         $zapchannel = $result2['data'];
412                                 } else {
413                                         $output .= $result2['keyword']."=".$result2['data']."\n";
414                                 }
415                         }
416                         $output .= "channel=>$zapchannel\n";
417                         $output .= $additional."\n";
418                 }
419                 return $output;
420         }
421 }
422
423 // The destinations this module provides
424 // returns a associative arrays with keys 'destination' and 'description'
425 function core_destinations() {
426         //static destinations
427         $extens = array();
428         $category = 'Terminate Call';
429         $extens[] = array('destination' => 'app-blackhole,hangup,1', 'description' => 'Hangup', 'category' => $category);
430         $extens[] = array('destination' => 'app-blackhole,congestion,1', 'description' => 'Congestion', 'category' => $category);
431         $extens[] = array('destination' => 'app-blackhole,busy,1', 'description' => 'Busy', 'category' => $category);
432         $extens[] = array('destination' => 'app-blackhole,zapateller,1', 'description' => 'Play SIT Tone (Zapateller)', 'category' => $category);
433         $extens[] = array('destination' => 'app-blackhole,musiconhold,1', 'description' => 'Put caller on hold forever', 'category' => $category);
434         $extens[] = array('destination' => 'app-blackhole,ring,1', 'description' => 'Play ringtones to caller until they hangup', 'category' => $category);
435        
436         //get the list of meetmes
437         $results = core_users_list();
438        
439         if (isset($results) && function_exists('voicemail_getVoicemail')) {
440                 //get voicemail
441                 $uservm = voicemail_getVoicemail();
442                 $vmcontexts = array_keys($uservm);
443                 foreach ($results as $thisext) {
444                         $extnum = $thisext[0];
445                         // search vm contexts for this extensions mailbox
446                         foreach ($vmcontexts as $vmcontext) {
447                                 if(isset($uservm[$vmcontext][$extnum])){
448                                         //$vmname = $uservm[$vmcontext][$extnum]['name'];
449                                         //$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>');
450                                         $vmboxes[$extnum] = true;
451                                 }
452                         }
453                 }
454         }
455        
456         // return an associative array with destination and description
457         // core provides both users and voicemail boxes as destinations
458         if (isset($results)) {
459                 foreach($results as $result) {
460                         $extens[] = array('destination' => 'from-did-direct,'.$result['0'].',1', 'description' => ' <'.$result['0'].'> '.$result['1'], 'category' => 'Extensions');
461                         if(isset($vmboxes[$result['0']])) {
462                                 $extens[] = array('destination' => 'ext-local,vmb'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (busy)', 'category' => 'Voicemail');
463                                 $extens[] = array('destination' => 'ext-local,vmu'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (unavail)', 'category' => 'Voicemail');
464                                 $extens[] = array('destination' => 'ext-local,vms'.$result['0'].',1', 'description' => '<'.$result[0].'> '.$result[1].' (no-msg)', 'category' => 'Voicemail');
465                         }
466                 }
467         }
468        
469         if (isset($extens))
470                 return $extens;
471         else
472                 return null;
473 }
474
475 function core_getdest($exten) {
476         $dests[] = 'from-did-direct,'.$exten.',1';
477         if (!function_exists('voicemail_mailbox_get')) {
478                 return $dests;
479         }
480         $box = voicemail_mailbox_get($exten);
481         if ($box == null) {
482                 return $dests;
483         }
484         $dests[] = 'ext-local,vmb'.$exten.',1';
485         $dests[] = 'ext-local,vmu'.$exten.',1';
486         $dests[] = 'ext-local,vms'.$exten.',1';
487
488         return $dests;
489 }
490
491 function core_getdestinfo($dest) {
492         global $active_modules;
493
494         // Check for Extension Number Destinations
495         //
496         if (substr(trim($dest),0,16) == 'from-did-direct,') {
497                 $exten = explode(',',$dest);
498                 $exten = $exten[1];
499                 $thisexten = core_users_get($exten);
500                 if (empty($thisexten)) {
501                         return array();
502                 } else {
503                         //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
504                         $display = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'users':'extensions';
505                         return array('description' => 'User Extension '.$exten.': '.$thisexten['name'],
506                                      'edit_url' => "config.php?type=setup&display=$display&extdisplay=".urlencode($exten)."&skip=0",
507                                                                   );
508                 }
509
510         // Check for voicemail box destinations
511         //
512         } else if (substr(trim($dest),0,12) == 'ext-local,vm') {
513                 $exten = explode(',',$dest);
514                 $exten = substr($exten[1],3);
515                 if (!function_exists('voicemail_mailbox_get')) {
516                         return array();
517                 }
518                 $thisexten = core_users_get($exten);
519                 if (empty($thisexten)) {
520                         return array();
521                 }
522                 $box = voicemail_mailbox_get($exten);
523                 if ($box == null) {
524                         return array();
525                 }
526                 $display = ($amp_conf['AMPEXTENSIONS'] == "deviceanduser")?'users':'extensions';
527                 return array('description' => 'User Extension '.$exten.': '.$thisexten['name'],
528                              'edit_url' => "config.php?type=setup&display=$display&extdisplay=".urlencode($exten)."&skip=0",
529                                                           );
530
531         // Check for blackhole Termination Destinations
532         //
533         } else if (substr(trim($dest),0,14) == 'app-blackhole,') {
534                 $exten = explode(',',$dest);
535                 $exten = $exten[1];
536
537                 switch ($exten) {
538                         case 'hangup':
539                                 $description = 'Hangup';
540                                 break;
541                         case 'congestion':
542                                 $description = 'Congestion';
543                                 break;
544                         case 'busy':
545                                 $description = 'Busy';
546                                 break;
547                         case 'zapateller':
548                                 $description = 'Play SIT Tone (Zapateller)';
549                                 break;
550                         case 'musiconhold':
551                                 $description = 'Put caller on hold forever';
552                                 break;
553                         case 'ring':
554                                 $description = 'Play ringtones to caller';
555                                 break;
556                         default:
557                                 $description = false;
558                 }
559                 if ($description) {
560                         return array('description' => 'Core: '.$description,
561                                  'edit_url' => false,
562                                                                  );
563                 } else {
564                         return array();
565                 }
566
567         // None of the above, so not one of ours
568         //
569         } else {
570                 return false;
571         }
572 }
573 /*      Generates dialplan for "core" components (extensions & inbound routing)
574         We call this with retrieve_conf
575 */
576 function core_get_config($engine) {
577         global $ext;  // is this the best way to pass this?
578         global $version;  // this is not the best way to pass this, this should be passetd together with $engine
579         global $amp_conf;
580         global $core_conf;
581
582         $modulename = "core";
583        
584         switch($engine) {
585                 case "asterisk":
586
587                         // Now add to sip_general_addtional.conf
588                         //
589                         if (isset($core_conf) && is_a($core_conf, "core_conf")) {
590                                 $core_conf->addSipGeneral('disallow','all');
591                                 $core_conf->addSipGeneral('allow','ulaw');
592                                 $core_conf->addSipGeneral('allow','alaw');
593                                 $core_conf->addSipGeneral('context','from-sip-external');
594                                 $core_conf->addSipGeneral('callerid','Unknown');
595                                 $core_conf->addSipGeneral('notifyringing','yes');
596                                 if (version_compare($version, '1.4', 'ge')) {
597                                         $core_conf->addSipGeneral('notifyhold','yes');
598                                         $core_conf->addSipGeneral('limitonpeers','yes');
599                                         $core_conf->addSipGeneral('tos_sip','cs3');    // Recommended setting from doc/ip-tos.txt
600                                         $core_conf->addSipGeneral('tos_audio','ef');   // Recommended setting from doc/ip-tos.txt
601                                         $core_conf->addSipGeneral('tos_video','af41'); // Recommended setting from doc/ip-tos.txt
602                                 } else {
603                                         $core_conf->addSipGeneral('tos','0x68'); // This really doesn't do anything with astersk not running as root
604                                 }
605                                 $core_conf->addIaxGeneral('disallow','all');
606                                 $core_conf->addIaxGeneral('allow','ulaw');
607                                 $core_conf->addIaxGeneral('allow','alaw');
608                                 $core_conf->addIaxGeneral('allow','gsm');
609                                 $core_conf->addIaxGeneral('mailboxdetail','yes');
610                                 if (version_compare($version, '1.4', 'ge')) {
611                                         $core_conf->addIaxGeneral('tos','ef'); // Recommended setting from doc/ip-tos.txt
612                                 }
613
614                                 $fcc = new featurecode($modulename, 'blindxfer');
615                                 $code = $fcc->getCodeActive();
616                                 unset($fcc);
617                                 if ($code != '') {
618                                         $core_conf->addFeatureMap('blindxfer',$code);
619                                 }
620
621                                 $fcc = new featurecode($modulename, 'atxfer');
622                                 $code = $fcc->getCodeActive();
623                                 unset($fcc);
624                                 if ($code != '') {
625                                         $core_conf->addFeatureMap('atxfer',$code);
626                                 }
627
628                                 $fcc = new featurecode($modulename, 'automon');
629                                 $code = $fcc->getCodeActive();
630                                 unset($fcc);
631                                 if ($code != '') {
632                                         $core_conf->addFeatureMap('automon',$code);
633                                 }
634
635                                 $core_conf->addFeatureMap('disconnect','**');
636                         }
637
638                         // FeatureCodes
639                         $fcc = new featurecode($modulename, 'userlogon');
640                         $fc_userlogon = $fcc->getCodeActive();
641                         unset($fcc);
642
643                         $fcc = new featurecode($modulename, 'userlogoff');
644                         $fc_userlogoff = $fcc->getCodeActive();
645                         unset($fcc);
646
647                         $fcc = new featurecode($modulename, 'zapbarge');
648                         $fc_zapbarge = $fcc->getCodeActive();
649                         unset($fcc);
650
651                         $fcc = new featurecode($modulename, 'chanspy');
652                         $fc_chanspy = $fcc->getCodeActive();
653                         unset($fcc);
654
655                         $fcc = new featurecode($modulename, 'simu_pstn');
656                         $fc_simu_pstn = $fcc->getCodeActive();
657                         unset($fcc);
658
659                         $fcc = new featurecode($modulename, 'simu_fax');
660                         $fc_simu_fax = $fcc->getCodeActive();
661                         unset($fcc);
662
663                         $fcc = new featurecode($modulename, 'pickup');
664                         $fc_pickup = $fcc->getCodeActive();
665                         unset($fcc);
666
667                         // Log on / off -- all in one context
668                         if ($fc_userlogoff != '' || $fc_userlogon != '') {
669                                 $ext->addInclude('from-internal-additional', 'app-userlogonoff'); // Add the include from from-internal
670                                
671                                 if ($fc_userlogoff != '') {
672                                         $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_macro('user-logoff'));
673                                         $ext->add('app-userlogonoff', $fc_userlogoff, '', new ext_hangup(''));
674                                 }
675        
676                                 if ($fc_userlogon != '') {
677                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon'));
678                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup(''));
679                                        
680                                         $clen = strlen($fc_userlogon);
681                                         $fc_userlogon = "_$fc_userlogon.";
682                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_macro('user-logon,${EXTEN:'.$clen.'}'));
683                                         $ext->add('app-userlogonoff', $fc_userlogon, '', new ext_hangup(''));
684                                 }
685                         }
686
687                         // Call pickup using app_pickup - Note that '**xtn' is hard-coded into the GXPs and SNOMs as a number to dial
688                         // when a user pushes a flashing BLF.
689                         if ($fc_pickup != '') {
690                                 $ext->addInclude('from-internal-additional', 'app-pickup');
691                                 $fclen = strlen($fc_pickup);
692                                 $ext->add('app-pickup', "_$fc_pickup.", '', new ext_NoOp('Attempt to Pickup ${EXTEN:'.$fclen.'} by ${CALLERID(num)}'));
693                                 if (strstr($version, 'BRI'))
694                                         $ext->add('app-pickup', "_$fc_pickup.", '', new ext_dpickup('${EXTEN:'.$fclen.'}'));
695                                 else
696                                         $ext->add('app-pickup', "_$fc_pickup.", '', new ext_pickup('${EXTEN:'.$fclen.'}'));
697                         }
698                        
699                        
700                         // zap barge
701                         if ($fc_zapbarge != '') {
702                                 $ext->addInclude('from-internal-additional', 'app-zapbarge'); // Add the include from from-internal
703                                
704                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_macro('user-callerid'));
705                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_setvar('GROUP()','${CALLERID(number)}'));
706                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_answer(''));
707                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_wait(1));
708                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_zapbarge(''));
709                                 $ext->add('app-zapbarge', $fc_zapbarge, '', new ext_hangup(''));
710                         }
711
712                         // chan spy
713                         if ($fc_chanspy != '') {
714                                 $ext->addInclude('from-internal-additional', 'app-chanspy'); // Add the include from from-internal
715                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_macro('user-callerid'));
716                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_answer(''));
717                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_wait(1));
718                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_chanspy(''));
719                                 $ext->add('app-chanspy', $fc_chanspy, '', new ext_hangup(''));
720                         }
721                        
722                         // Simulate options (ext-test)
723                         if ($fc_simu_pstn != '' || $fc_simu_fax != '') {
724                                 $ext->addInclude('from-internal-additional', 'ext-test'); // Add the include from from-internal
725                                
726                   &n