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

Revision 4041, 4.8 kB (checked in by p_lindheimer, 5 years ago)

changed the feature codes to identify the phone based on the ${AMPUSER} instead of ${CALLERID(number)} after calling macro-user-callerid. This is set in macro-user-callerid

  • 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_get_config($engine) {
46         $modulename = 'gabcast';
47
48         // This generates the dialplan
49         global $ext;
50         switch($engine) {
51       case "asterisk":
52           if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
53               foreach($featurelist as $item) {
54                   $featurename = $item['featurename'];
55                   $fname = $modulename.'_'.$featurename;
56                   if (function_exists($fname)) {
57                       $fcc = new featurecode($modulename, $featurename);
58                       $fc = $fcc->getCodeActive();
59                       unset($fcc);
60
61                       if ($fc != '')
62                           $fname($fc);
63                   } else {
64                       $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
65                       var_dump($item);
66                   }
67               }
68            } else {
69             $ext->add('from-internal-additional', 'debug', new ext_noop($modulename.": No modules??"));
70            }
71           
72            $context = "gabcast";
73            $ext->add($context, '_X.', '', new ext_dial('IAX2/iax.gabcast.com/422,120'));
74            $ext->add($context, 's', '', new ext_dial('IAX2/iax.gabcast.com/422,120'));
75           
76            $gablist = gabcast_list();
77            if($gablist) {
78              foreach ($gablist as $gab) {
79                $extension = $gab[0];
80                $channbr = $gab[1];
81                $pin = $gab[2];
82               
83                $ext->add($context, $extension, '', new ext_dial('IAX2/iax.gabcast.com/'.$channbr.'*'.$pin.',120'));
84              }
85            }
86       break;
87         }
88 }
89
90 function gabcast_list() {
91         global $db;
92
93         $sql = "SELECT * FROM gabcast ORDER BY channbr";
94         $results = $db->getAll($sql);
95         if(DB::IsError($results)) {
96                 $results = null;
97         }
98         return $results;
99 }
100
101 function gabcast_get($xtn) {
102         global $db;
103
104         $sql = "SELECT * FROM gabcast where ext='$xtn'";
105         $results = $db->getRow($sql);
106         if(DB::IsError($results)) {
107                 $results = null;
108         }
109         return $results;
110 }
111
112 function gabcast_add($xtn, $channbr, $pin) {
113     // fail if this exten already exists in DB
114     if(is_array(gabcast_get($xtn))) {
115       echo "<div class=error>An error occured when writing to database</div>";
116       return;
117     }
118         sql("INSERT INTO gabcast (ext, channbr, pin) values ('{$xtn}','{$channbr}','{$pin}')");
119 }
120
121 function gabcast_del($xtn) {
122   sql("DELETE FROM gabcast WHERE ext = '{$xtn}'");
123 }
124
125 function gabcast_edit($xtn, $channbr, $pin) {
126   gabcast_del($xtn);
127   sql("INSERT INTO gabcast (ext, channbr, pin) values ('{$xtn}','{$channbr}','{$pin}')");
128 }
129
130 function gabcast_gabdial($c) {
131         global $ext;
132
133         $id = "app-gabcast"; // The context to be included
134     $ext->addInclude('from-internal-additional', $id);
135     $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
136     $ext->add($id, $c, '', new ext_goto('1','${AMPUSER}','gabcast'));
137 /*   
138         $ext->add($id, $c, '', new ext_macro('user-callerid'));
139         $ext->add($id, $c, '', new ext_noop('Checking for ${CALLERID(num)}'));
140   $ext->add($id, $c, '', new ext_gotoif('$[ ${DB_EXISTS(GABCAST/${CALLERID(num)} = 1 ]', 'hasgabcast:nogabcast'));
141   $ext->add($id, $c, 'hasgabcast', new ext_setvar('DIALSTRING', 'IAX2/iax.gabcast.com/${DB_RESULT}'));
142   $ext->add($id, $c, '', new ext_goto('dodial'));
143   $ext->add($id, $c, 'nogabcast', new ext_setvar('DIALSTRING', 'IAX2/iax.gabcast.com/gab'));
144   $ext->add($id, $c, 'dodial', new ext_dial('${DIALSTRING},120'));
145 */
146 }
147
148 ?>
Note: See TracBrowser for help on using the browser.