root/contributed_modules/modules/routepermissions/install.php

Revision 7596, 2.5 kB (checked in by xrobau, 3 years ago)

Relicencing under the AGPLv3

Line 
1 <?php
2 /* $Id$ */
3
4 // Original Release 2009 by Rob Thomas (xrobau@gmail.com)
5 /* 
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU Affero General Public License as
8     published by the Free Software Foundation, either version 3 of the
9     License, or (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU Affero General Public License for more details.
15
16     You should have received a copy of the GNU Affero General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22 global $db;
23 global $amp_conf;
24
25 if (! function_exists("out")) {
26   function out($text) {
27     echo $text."<br />";
28   }
29 }
30
31 if (! function_exists("outn")) {
32   function outn($text) {
33     echo $text;
34   }
35 }
36
37 // create the tables
38 $sql = "CREATE TABLE IF NOT EXISTS routepermissions (
39   exten int(11) NOT NULL,
40   routename varchar(25) NOT NULL,
41   allowed varchar(3) default 'YES',
42   faildest varchar(255),
43   KEY idx_exten (exten)
44 );";
45
46 $check = $db->query($sql);
47 if (DB::IsError($check)) {
48         die_freepbx( "Can not create `routepermissions` table: " . $check->getMessage() .  "\n");
49 }
50
51 // 0.3 - add 'faildest'
52 outn(_("Checking for faildest..."));
53 $sql = "SELECT faildest FROM routepermissions";
54 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
55 if(DB::IsError($check)) {
56   // add new field
57   $sql = "ALTER TABLE routepermissions ADD faildest varchar(255);";
58                 $result = $db->query($sql);
59                 if(DB::IsError($result)) {
60                         die_freepbx($result->getDebugInfo());
61                 }
62                 out(_("OK"));
63         } else {
64                 out(_("already exists"));
65 }
66
67 // Check to see if there's data in the table allready - if so, don't touch.
68 $sql = "SELECT COUNT(exten) FROM routepermissions";
69 $results = $db->getRow($sql);
70 if ($results[0] > 0) {
71   out("Data already exists in routepermissions. Not regenerating");
72 } else {
73 // If there's not, propogate all extensions and all trunks with YES permissions
74   $sql = "SELECT extension FROM users ORDER BY extension";
75   $extns = $db->getAll($sql);
76   $sql = "SELECT DISTINCT context FROM extensions WHERE context LIKE 'outrt%';";
77   $routes = $db->getAll($sql);
78
79   foreach($extns as $ext) {
80     foreach ($routes as $r) {
81       $rn = substr($r[0], 10);
82       $db->query("INSERT INTO routepermissions (exten, routename, allowed) VALUES ('$ext[0]', '$rn', 'YES');");
83     }
84   }
85 }      
86
87 ?>
Note: See TracBrowser for help on using the browser.