root/modules/branches/2.10/paging/install.php

Revision 14120, 5.0 kB (checked in by mbrevda, 1 year ago)

remove directory feature code (was for legacy directory); fix/improve sip notify; fix undefined var

Line 
1 <?php
2 if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
3 //for translation only
4 if (false) {
5 _("Intercom prefix");
6 _("User Intercom Allow");
7 _("User Intercom Disallow");
8 }
9
10 global $amp_conf;
11 // Enable intercom as a feature code
12 $fcc = new featurecode('paging', 'intercom-prefix');
13 $fcc->setDescription('Intercom prefix');
14 $fcc->setDefault('*80');
15 $fcc->update();
16 unset($fcc);
17
18 // User intercom enable code
19 $fcc = new featurecode('paging', 'intercom-on');
20 $fcc->setDescription('User Intercom Allow');
21 $fcc->setDefault('*54');
22 $fcc->update();
23 unset($fcc);
24
25 // User intercom disable
26 $fcc = new featurecode('paging', 'intercom-off');
27 $fcc->setDescription('User Intercom Disallow');
28 $fcc->setDefault('*55');
29 $fcc->update();
30 unset($fcc);   
31
32 // Remove old tables that were never used
33 //
34 $sql = "DROP TABLE IF EXISTS paging_phones";
35 $result = $db->query($sql);
36 if(DB::IsError($result)) {
37     die_freepbx($result->getDebugInfo());
38 }
39 $sql = "DROP TABLE IF EXISTS paging_overview";
40 $result = $db->query($sql);
41 if(DB::IsError($result)) {
42     die_freepbx($result->getDebugInfo());
43 }
44
45 $sql = "CREATE TABLE IF NOT EXISTS paging_groups
46     ( page_number VARCHAR(50),
47       ext VARCHAR(25),
48         PRIMARY KEY (page_number, ext)
49     )";
50 $result = $db->query($sql);
51 if(DB::IsError($result)) {
52     die_freepbx($result->getDebugInfo());
53 }
54
55 // Create table used to change defaults and customize
56 // for certain phone types
57 //
58 $sql = "
59 CREATE TABLE IF NOT EXISTS `paging_autoanswer` (
60     `useragent` VARCHAR( 255 ) NOT NULL ,
61     `var` VARCHAR( 20 ) NOT NULL ,
62     `setting` VARCHAR( 255 ) NOT NULL ,
63     PRIMARY KEY ( `useragent` , `var` )
64 );";
65 $result = $db->query($sql);
66 if(DB::IsError($result)) {
67     die_freepbx($result->getDebugInfo());
68 }
69
70 // version 1.6 upgrade
71 $sql = "SELECT page_group FROM paging_config";
72 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
73 if(DB::IsError($check)) {
74     // this table wasn't used up to this point, replace it with the new one
75     $sql = "DROP TABLE IF EXISTS paging_config;";
76     $result = $db->query($sql);
77     if(DB::IsError($result)) {
78         die_freepbx($result->getDebugInfo());
79     }
80     
81     $sql = "CREATE TABLE IF NOT EXISTS paging_config
82         ( page_group VARCHAR(255),
83           force_page INTEGER(1) NOT NULL,
84             duplex     INTEGER(1) NOT NULL default '0',
85             description VARCHAR(255) NOT NULL default '',
86             PRIMARY KEY (page_group)
87         )";
88     $result = $db->query($sql);
89     if(DB::IsError($result)) {
90         die_freepbx($result->getDebugInfo());
91     }
92
93     // insert default values
94     $sql = "INSERT INTO paging_config (page_group, force_page, duplex, description)  SELECT DISTINCT page_number, 0, 0, '' FROM paging_groups";
95     $result = $db->query($sql);
96     if(DB::IsError($result)) {
97         die_freepbx($result->getDebugInfo());
98     }
99 }
100
101 // Set the initial default values, if already
102
103 // These are the three most common ways of auto answering.
104 // If the table is already populated then error will be ignored and user data will not get altered
105 //
106 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('default', 'CALLINFO', 'Call-Info: <uri>\\\\;answer-after=0')";
107 $result = $db->query($sql);
108 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('default', 'ALERTINFO', 'Alert-Info: Ring Answer')";
109 $result = $db->query($sql);
110 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('default', 'SIPURI', 'intercom=true')";
111 $result = $db->query($sql);
112 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('Mitel', 'CALLINFO', 'Call-Info: <sip:broadworks.net>\\\\;answer-after=0')";
113 $result = $db->query($sql);
114 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('Panasonic', 'ALERTINFO', 'Alert-Info: Intercom')";
115 $result = $db->query($sql);
116 $sql = "INSERT INTO paging_autoanswer (useragent, var, setting) VALUES ('Polycom', 'ALERTINFO', 'Alert-Info: info-Auto Answer')";
117 $result = $db->query($sql);
118
119 // Add dulex field
120 //
121 $sql = "SELECT duplex FROM paging_config";
122 $result = $db->getRow($sql, DB_FETCHMODE_ASSOC);
123 if (DB::IsError($result)) {
124     $sql = "ALTER TABLE paging_config ADD duplex INTEGER(1) NOT NULL default '0'";
125     $results = $db->query($sql);
126     if(DB::IsError($results)) {
127             die_freepbx($results->getMessage());
128     }
129 }
130
131 // Add description field
132 //
133 $sql = "SELECT description FROM paging_config";
134 $result = $db->getRow($sql, DB_FETCHMODE_ASSOC);
135 if (DB::IsError($result)) {
136     $sql = "ALTER TABLE paging_config ADD description VARCHAR(255) NOT NULL default ''";
137     $results = $db->query($sql);
138     if(DB::IsError($results)) {
139             die_freepbx($results->getMessage());
140     }
141 }
142 // Make sure primary keys are set, they were not originally. Don't check for error,
143 // if they exist it will give an error
144 // sqlite3 does not support adding keys after the fact with ALTER.
145 // These keys are setup in the CREATE TABLE as of 2.5 anyway, so
146 // just ignore these queries for sqlite3
147 if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
148     $sql = "ALTER TABLE `paging_groups` ADD PRIMARY KEY ( `page_number` , `ext` )";
149     $result = $db->query($sql);
150
151     $sql = "ALTER TABLE `paging_config` ADD PRIMARY KEY ( `page_group` )";
152     $result = $db->query($sql);
153 }
154 ?>
155
Note: See TracBrowser for help on using the browser.