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

Revision 6895, 4.6 kB (checked in by mickecarlsson, 5 years ago)

Reverting previous changes, add strings for localization for paging

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