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

Revision 5400, 5.4 kB (checked in by p_lindheimer, 4 years ago)

add dest registry support to gabcast

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to LF
Line 
1 <?php
2  /* $Id:$ */
3
4 function gabcast_configpageinit($dispnum) {
5   global $currentcomponent;
6
7   if ( $dispnum == 'users' || $dispnum == 'extensions' ) {
8     $currentcomponent->addguifunc('gabcast_configpageload');
9   }
10 }
11
12 function gabcast_configpageload() {
13   global $currentcomponent;
14
15   $viewing_itemid = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
16   $action =  isset($_REQUEST['action'])?$_REQUEST['action']:null;
17   if ( $viewing_itemid != '' && $action != 'del') {
18     $list = gabcast_get($viewing_itemid);
19     if (is_array($list)) {
20       $res = $_SERVER['PHP_SELF']."?display=gabcast&type=tool&ext=$viewing_itemid&action=edit";
21       $currentcomponent->addguielem('_top', new gui_link('gabcastlink', 'Edit Gabcast Settings', $res));
22     } else {
23       $res = $_SERVER['PHP_SELF']."?display=gabcast&type=tool&ext=$viewing_itemid&action=add";
24       $currentcomponent->addguielem('_top', new gui_link('gabcastlink', 'Add Gabcast Settings', $res));
25     }
26   }
27 }
28
29 // returns a associative arrays with keys 'destination' and 'description'
30 function gabcast_destinations() {
31   //get the list of meetmes
32   $results = gabcast_list();
33
34   // return an associative array with destination and description
35   if (isset($results)) {
36     foreach($results as $result){
37         $extens[] = array('destination' => 'gabcast,'.$result['0'].',1', 'description' => 'gabcast channel '. $result['1'].' <'.$result[0].'>');
38     }
39   return isset($extens)?$extens:null;
40   } else {
41     return null;
42   }
43 }
44
45 function gabcast_getdest($exten) {
46   return array('gabcast,'.$exten.',1');
47 }
48
49 function gabcast_getdestinfo($dest) {
50   global $active_modules;
51
52   if (substr(trim($dest),0,8) == 'gabcast,') {
53     $exten = explode(',',$dest);
54     $exten = $exten[1];
55     $thisexten = gabcast_get($exten);
56     if (empty($thisexten)) {
57       return array();
58     } else {
59       $type = isset($active_modules['gabcast']['type'])?$active_modules['gabcast']['type']:'tool';
60       return array('description' => 'Gabcast : Ext'.$thisexten[0].' -> channel '.$thisexten[1],
61                    'edit_url' => 'config.php?display=gabcast&action=edit&type='.$type.'&ext='.urlencode($exten),
62                   );
63     }
64   } else {
65     return false;
66   }
67 }
68
69 function gabcast_get_config($engine) {
70         $modulename = 'gabcast';
71
72         // This generates the dialplan
73         global $ext;
74         switch($engine) {
75       case "asterisk":
76           if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
77               foreach($featurelist as $item) {
78                   $featurename = $item['featurename'];
79                   $fname = $modulename.'_'.$featurename;
80                   if (function_exists($fname)) {
81                       $fcc = new featurecode($modulename, $featurename);
82                       $fc = $fcc->getCodeActive();
83                       unset($fcc);
84
85                       if ($fc != '')
86                           $fname($fc);
87                   } else {
88                       $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
89                       var_dump($item);
90                   }
91               }
92            } else {
93             $ext->add('from-internal-additional', 'debug', new ext_noop($modulename.": No modules??"));
94            }
95           
96            $context = "gabcast";
97            $ext->add($context, '_X.', '', new ext_dial('IAX2/iax.gabcast.com/422,120'));
98            $ext->add($context, 's', '', new ext_dial('IAX2/iax.gabcast.com/422,120'));
99           
100            $gablist = gabcast_list();
101            if($gablist) {
102              foreach ($gablist as $gab) {
103                $extension = $gab[0];
104                $channbr = $gab[1];
105                $pin = $gab[2];
106               
107                $ext->add($context, $extension, '', new ext_dial('IAX2/iax.gabcast.com/'.$channbr.'*'.$pin.',120'));
108              }
109            }
110       break;
111         }
112 }
113
114 function gabcast_list() {
115         global $db;
116
117         $sql = "SELECT * FROM gabcast ORDER BY channbr";
118         $results = $db->getAll($sql);
119         if(DB::IsError($results)) {
120                 $results = null;
121         }
122         return $results;
123 }
124
125 function gabcast_get($xtn) {
126         global $db;
127
128         $sql = "SELECT * FROM gabcast where ext='$xtn'";
129         $results = $db->getRow($sql);
130         if(DB::IsError($results)) {
131                 $results = null;
132         }
133         return $results;
134 }
135
136 function gabcast_add($xtn, $channbr, $pin) {
137     // fail if this exten already exists in DB
138     if(is_array(gabcast_get($xtn))) {
139       echo "<div class=error>An error occured when writing to database</div>";
140       return;
141     }
142         sql("INSERT INTO gabcast (ext, channbr, pin) values ('{$xtn}','{$channbr}','{$pin}')");
143 }
144
145 function gabcast_del($xtn) {
146   sql("DELETE FROM gabcast WHERE ext = '{$xtn}'");
147 }
148
149 function gabcast_edit($xtn, $channbr, $pin) {
150   gabcast_del($xtn);
151   sql("INSERT INTO gabcast (ext, channbr, pin) values ('{$xtn}','{$channbr}','{$pin}')");
152 }
153
154 function gabcast_gabdial($c) {
155         global $ext;
156
157         $id = "app-gabcast"; // The context to be included
158     $ext->addInclude('from-internal-additional', $id);
159     $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
160     $ext->add($id, $c, '', new ext_goto('1','${AMPUSER}','gabcast'));
161 /*   
162         $ext->add($id, $c, '', new ext_macro('user-callerid'));
163         $ext->add($id, $c, '', new ext_noop('Checking for ${CALLERID(num)}'));
164   $ext->add($id, $c, '', new ext_gotoif('$[ ${DB_EXISTS(GABCAST/${CALLERID(num)} = 1 ]', 'hasgabcast:nogabcast'));
165   $ext->add($id, $c, 'hasgabcast', new ext_setvar('DIALSTRING', 'IAX2/iax.gabcast.com/${DB_RESULT}'));
166   $ext->add($id, $c, '', new ext_goto('dodial'));
167   $ext->add($id, $c, 'nogabcast', new ext_setvar('DIALSTRING', 'IAX2/iax.gabcast.com/gab'));
168   $ext->add($id, $c, 'dodial', new ext_dial('${DIALSTRING},120'));
169 */
170 }
171
172 ?>
Note: See TracBrowser for help on using the browser.