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

Revision 5384, 10.5 kB (checked in by p_lindheimer, 4 years ago)

Merged revisions 5383 via svnmerge from
http://svn.freepbx.org/modules/branches/2.4

........

r5383 | p_lindheimer | 2007-12-10 10:30:48 -0800 (Mon, 10 Dec 2007) | 1 line


#2537 have paging answer the channel because paging command does not and some devices require it to get mediasream flowing, and fix a bug in the js validation that allowed empty lists to be submitted

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php 
2 /* $Id $ */
3
4 /* paging_init - Is run every time the page is loaded, checks
5    to make sure that the database is current and loaded, if not,
6    it propogates it. I expect that extra code will go here to
7    check for version upgrades, etc, of the paging database, to
8    allow for easy upgrades. */
9
10 //  Generates dialplan for paging  - is called from retrieve_conf
11
12 function paging_get_config($engine) {
13   global $db;
14   global $ext;
15   switch($engine) {
16     case "asterisk":
17       // setup for intercom
18       $fcc = new featurecode('paging', 'intercom-prefix');
19       $code = $fcc->getCodeActive();
20       unset($fcc);
21
22       // Since these are going down channel local, set ALERT_INFO and SIPADDHEADER which will be set in dialparties.agi
23       // no point in even setting the headers here they will get lost in channel local
24       //
25       if (!empty($code)) {
26         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('dialnumber', '${EXTEN:'.strlen($code).'}'));
27         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_dbget('user-intercom','AMPUSER/${dialnumber}/intercom'));
28         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_gotoif('$["${user-intercom}" = "disabled" ]', 'nointercom'));
29         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__SIPADDHEADER', 'Call-Info: \;answer-after=0'));
30         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__ALERT_INFO', 'Ring Answer'));
31         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true'));
32         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_macro('user-callerid'));
33         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_dial('Local/${dialnumber}@from-internal/n','',''));
34         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_busy());
35         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_macro('hangupcall'));
36         $ext->add('ext-intercom', '_'.$code.'.', 'nointercom', new ext_noop('Intercom disallowed by ${dialnumber}'));
37         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_playback('intercom&for&extension'));
38         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_saydigits('${dialnumber}'));
39         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_playback('is&disabled'));
40         $ext->add('ext-intercom', '_'.$code.'.', '', new ext_congestion());
41
42         $userlist = core_users_list();
43         if (is_array($userlist)) {
44           foreach($userlist as $item) {
45             $intercom_code = $code.$item[0];
46             $ext->add('ext-intercom-users', '_'.$intercom_code, '', new ext_goto('ext-intercom,${EXTEN},1'));
47           }
48         }
49         $ext->addInclude('from-internal-additional', 'ext-intercom-users');
50      
51         $fcc = new featurecode('paging', 'intercom-on');
52         $oncode = $fcc->getCodeActive();
53         unset($fcc);
54
55         if ($oncode) {
56           $ext->add('ext-intercom-users', $oncode, '', new ext_answer(''));
57           $ext->add('ext-intercom-users', $oncode, '', new ext_wait('1'));
58           $ext->add('ext-intercom-users', $oncode, '', new ext_macro('user-callerid'));
59           $ext->add('ext-intercom-users', $oncode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'enabled'));
60           $ext->add('ext-intercom-users', $oncode, '', new ext_playback('intercom&enabled'));
61           $ext->add('ext-intercom-users', $oncode, '', new ext_macro('hangupcall'));
62         }
63      
64         $fcc = new featurecode('paging', 'intercom-off');
65         $offcode = $fcc->getCodeActive();
66         unset($fcc);
67  
68         if ($offcode) {
69           $ext->add('ext-intercom-users', $offcode, '', new ext_answer(''));
70           $ext->add('ext-intercom-users', $offcode, '', new ext_wait('1'));
71           $ext->add('ext-intercom-users', $offcode, '', new ext_macro('user-callerid'));
72           $ext->add('ext-intercom-users', $offcode, '', new ext_setvar('DB(AMPUSER/${AMPUSER}/intercom)', 'disabled'));
73           $ext->add('ext-intercom-users', $offcode, '', new ext_playback('intercom&disabled'));
74           $ext->add('ext-intercom-users', $offcode, '', new ext_macro('hangupcall'));
75         }
76       }
77
78       // Get a list of all the phones used for paging
79       $sql = "SELECT DISTINCT ext FROM paging_groups";
80       $results = $db->getAll($sql);
81       if (!isset($results[0][0])) {
82         // There are no phones here, no paging support, lets give up now.
83         return 0;
84       }
85       // We have paging support.
86       $ext->addInclude('from-internal-additional','ext-paging');
87       // Lets give all the phones their PAGExxx lines.
88       // TODO: Support for specific phones configurations
89       foreach ($results as $grouparr) {
90         $skipheaders = false;
91         $xtn=trim($grouparr[0]);
92         if (strtoupper(substr($xtn,-1)) == "X") {
93           // hack for allowing no SIP headers
94           //TODO : replace this with DevicesTakeTwo stuff
95           $xtn = rtrim($xtn,"xX");
96           $skipheaders = true;
97         }
98        
99         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${AMPUSER} = '.$xtn.' ]','skipself'));
100         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_gotoif('$[ ${FORCE_PAGE} != 1 ]','AVAIL'));
101         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('AVAILSTATUS', 'not checked'));
102         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_goto('SKIPCHECK'));
103         $ext->add('ext-paging', "PAGE${xtn}", 'AVAIL', new ext_chanisavail('${DB(DEVICE/'.$xtn.'/dial)}', 'js'));
104         $ext->add('ext-paging', "PAGE${xtn}", 'SKIPCHECK', new ext_noop('Seems to be available (state = ${AVAILSTATUS}'));
105        
106         if (!$skipheaders) {
107           $ext->add('ext-paging', "PAGE${xtn}", '', new ext_sipaddheader('Call-Info','\;answer-after=0'));
108           $ext->add('ext-paging', "PAGE${xtn}", '', new ext_alertinfo('Ring Answer'));
109           $ext->add('ext-paging', "PAGE${xtn}", '', new ext_setvar('__SIP_URI_OPTIONS', 'intercom=true'));
110         }
111        
112         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_dial("\${DB(DEVICE/${xtn}/dial)}", '5, A(beep)'));
113         $ext->add('ext-paging', "PAGE${xtn}", 'skipself', new ext_noop('Not paging originator'));
114         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_hangup());
115        
116         $ext->add('ext-paging', "PAGE${xtn}", '', new ext_noop('Channel ${AVAILCHAN} is not available (state = ${AVAILSTATUS})'), 'AVAIL',101);
117       }
118       // Now get a list of all the paging groups...
119       $sql = "SELECT page_group, force_page FROM paging_config";
120       $paging_groups = $db->getAll($sql, DB_FETCHMODE_ASSOC);
121       foreach ($paging_groups as $thisgroup) {
122         $grp=trim($thisgroup['page_group']);
123         $sql = "SELECT ext FROM paging_groups WHERE page_number='$grp'";
124         $all_exts = $db->getAll($sql);
125         $dialstr='';
126         foreach($all_exts as $local_dial) {
127           if (strtoupper(substr($local_dial[0],-1)) == "X") {
128             $local_dial[0] = rtrim($local_dial[0],"xX");
129           }
130
131           $dialstr .= "LOCAL/PAGE".trim($local_dial[0])."@ext-paging&";
132         }
133         // It will always end with an &, so lets take that off.
134         $dialstr = rtrim($dialstr, "&");
135         $ext->add('ext-paging', "Debug", '', new ext_noop("dialstr is $dialstr"));
136         $ext->add('ext-paging', $grp, '', new ext_answer(''));
137         $ext->add('ext-paging', $grp, '', new ext_setvar("_FORCE_PAGE", ($thisgroup['force_page']?1:0)));
138         $ext->add('ext-paging', $grp, '', new ext_macro('user-callerid'));
139         // make AMPUSER inherited here, so we can skip the proper 'self' if using cidnum masquerading
140         $ext->add('ext-paging', $grp, '', new ext_setvar('_AMPUSER', '${AMPUSER}'));
141         $ext->add('ext-paging', $grp, '', new ext_page($dialstr));
142       }
143      
144     break;
145   }
146 }
147
148 function paging_list() {
149   global $db;
150
151   $sql = "SELECT DISTINCT page_number FROM paging_groups ORDER BY page_number";
152   $results = $db->getAll($sql);
153   if(DB::IsError($results)) {
154     $results = null;
155   }
156   // There should be a checkRange here I think, but I haven't looked into it yet.
157 //  return array('999', '998', '997');
158   return $results;
159 }
160
161 function paging_get_devs($grp) {
162   global $db;
163
164   // Just in case someone's trying to be smart with a SQL injection.
165   $grp = addslashes($grp);
166
167   $sql = "SELECT ext FROM paging_groups where page_number='$grp'";
168   $results = $db->getAll($sql);
169   if(DB::IsError($results))
170     $results = null;
171   foreach ($results as $val)
172     $tmparray[] = $val[0];
173   return $tmparray;
174 }
175
176 function paging_get_pagingconfig($grp) {
177   global $db;
178
179   // Just in case someone's trying to be smart with a SQL injection.
180   $grp = addslashes($grp);
181
182   $sql = "SELECT * FROM paging_config WHERE page_group='$grp'";
183   $results = $db->getRow($sql, DB_FETCHMODE_ASSOC);
184   if(DB::IsError($results))
185     $results = null;
186   return $results;
187 }
188
189 function paging_modify($oldxtn, $xtn, $plist, $force_page) {
190   global $db;
191
192   // Just in case someone's trying to be smart with a SQL injection.
193   $xtn = addslashes($xtn);
194
195   // Delete it if it's there.
196   paging_del($oldxtn);
197
198   // Now add it all back in.
199   paging_add($xtn, $plist, $force_page);
200
201   // Aaad we need a reload.
202   needreload();
203
204 }
205
206 function paging_del($xtn) {
207   global $db;
208   $sql = "DELETE FROM paging_groups WHERE page_number='$xtn'";
209   $res = $db->query($sql);
210   if (DB::isError($res)) {
211     var_dump($res);
212     die_freepbx("Error in paging_del(): ");
213   }
214  
215   $sql = "DELETE FROM paging_config WHERE page_group='$xtn'";
216   $res = $db->query($sql);
217   if (DB::isError($res)) {
218     var_dump($res);
219     die_freepbx("Error in paging_del(): ");
220   }
221  
222   needreload();
223 }
224
225 function paging_add($xtn, $plist, $force_page) {
226   global $db;
227
228   // $plist contains a string of extensions, with \n as a seperator.
229   // Split that up first.
230   if (is_array($plist)) {
231     $xtns = $plist;
232   } else {
233     $xtns = explode("\n",$plist);
234   }
235   foreach (array_keys($xtns) as $val) {
236     $val = addslashes(trim($xtns[$val]));
237     // Sanity check input.
238    
239     $sql = "INSERT INTO paging_groups(page_number, ext) VALUES ('$xtn', '$val')";
240     $db->query($sql);
241   }
242  
243   $sql = "INSERT INTO paging_config(page_group, force_page) VALUES ('$xtn', '$force_page')";
244   $db->query($sql);
245  
246   needreload();
247 }
248
249  
250 // this can be removed in 2.2 and put back to just runModuleSQL which is in admin/functions.inc.php
251 // I didn't want to do it in 2.1 as there's a significant user base out there, and it will break
252 // them if we do it here.
253
254 function pagingrunModuleSQL($moddir,$type){
255         global $db;
256         $data='';
257         if (is_file("modules/{$moddir}/{$type}.sql")) {
258                 // run sql script
259                 $fd = fopen("modules/{$moddir}/{$type}.sql","r");
260                 while (!feof($fd)) {
261                         $data .= fread($fd, 1024);
262                 }
263                 fclose($fd);
264
265                 preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches);
266
267                 foreach ($matches[1] as $sql) {
268                                 $result = $db->query($sql);
269                                 if(DB::IsError($result)) {
270                                         return false;
271                                 }
272                 }
273                 return true;
274         }
275                 return true;
276 }
277
278
279
280
281 ?>
Note: See TracBrowser for help on using the browser.