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

Revision 5283, 3.2 kB (checked in by p_lindheimer, 5 years ago)

added miscdests_getdest() and miscdests_getdestinfo() and feedback on destination usage

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id: $ */
2
3 // returns a associative arrays with keys 'destination' and 'description'
4 function miscdests_destinations() {
5   $results = miscdests_list();
6
7   // return an associative array with destination and description
8   if (isset($results)) {
9     foreach($results as $result){
10         $extens[] = array('destination' => 'ext-miscdests,'.$result['0'].',1', 'description' => $result['1']);
11     }
12     return $extens;
13   } else {
14     return null;
15   }
16 }
17
18 function miscdests_getdest($exten) {
19   return array('ext-miscdests,'.$exten.',1');
20 }
21
22 function miscdests_getdestinfo($dest) {
23   global $active_modules;
24
25   if (substr(trim($dest),0,14) == 'ext-miscdests,') {
26     $exten = explode(',',$dest);
27     $exten = $exten[1];
28     $thisexten = miscdests_get($exten);
29     if (empty($thisexten)) {
30       return array();
31     } else {
32       //$type = isset($active_modules['announcement']['type'])?$active_modules['announcement']['type']:'setup';
33       return array('description' => 'Misc Destination : '.$thisexten['description'],
34                    'edit_url' => 'config.php?display=miscdests&id='.urlencode($exten),
35                   );
36     }
37   } else {
38     return false;
39   }
40 }
41
42 /*  Generates dialplan for conferences
43   We call this with retrieve_conf
44 */
45 function miscdests_get_config($engine) {
46   global $ext;  // is this the best way to pass this?
47
48   switch($engine) {
49     case "asterisk":
50       $contextname = 'ext-miscdests';
51       $fctemplate = '/\{(.+)\:(.+)\}/';
52       
53       if(is_array($destlist = miscdests_list())) {
54         
55         foreach($destlist as $item) {
56           $miscdest = miscdests_get($item['0']);
57           
58           $miscid = $miscdest['id'];
59           $miscdescription = $miscdest['description'];
60           $miscdialdest = $miscdest['destdial'];
61
62           // exchange {mod:fc} for the relevent feature codes in $miscdialdest
63           $miscdialdest = preg_replace_callback($fctemplate, "miscdests_lookupfc", $miscdialdest);
64
65           // write out the dialplan details
66           $ext->add($contextname, $miscid, '', new ext_noop('MiscDest: '.$miscdescription));
67           $ext->add($contextname, $miscid, '', new ext_goto('from-internal,'.$miscdialdest.',1', ''));
68           
69         }
70       }
71
72     break;
73   }
74 }
75
76 function miscdests_list() {
77   $results = sql("SELECT id, description FROM miscdests ORDER BY description","getAll",DB_FETCHMODE_ASSOC);
78   foreach($results as $result){
79     $extens[] = array($result['id'],$result['description']);
80   }
81
82   if (isset($extens)) {
83     return $extens;
84   } else {
85     return null;
86   }
87 }
88
89 function miscdests_get($id){
90   $results = sql("SELECT id, description, destdial FROM miscdests WHERE id = $id","getRow",DB_FETCHMODE_ASSOC);
91   return $results;
92 }
93
94 function miscdests_del($id){
95   $results = sql("DELETE FROM miscdests WHERE id = $id","query");
96 }
97
98 function miscdests_add($description, $destdial){
99   $results = sql("INSERT INTO miscdests (description, destdial) VALUES (".sql_formattext($description).",".sql_formattext($destdial).")");
100 }
101
102 function miscdests_update($id, $description, $destdial){
103   $results = sql("UPDATE miscdests SET description = ".sql_formattext($description).", destdial = ".sql_formattext($destdial)." WHERE id = ".$id);
104 }
105
106 function miscdests_lookupfc($matches) {
107   $modulename = $matches[1];
108   $featurename = $matches[2];
109
110   $fcc = new featurecode($modulename, $featurename);
111   $fc = $fcc->getCodeActive();
112   return $fc;
113 }
114 ?>
Note: See TracBrowser for help on using the browser.