root/contributed_modules/modules/isymphony/install.php

Revision 7772, 7.2 kB (checked in by seanmh, 3 years ago)

1.0.0 Added backward compatibility support for 2.0 rev 1104.

Fixed bug in which a flawed context would prevent orphaned parked calls from ringing back to the parking extension if parked via the panel.
Made debug menu always visible.
Added server debug menu.
Debug logs now show on main module page.
Multiple debug options can now be set at once.
Added database column checks in installation script to handle module upgrades.
Added default FreePBX page context to configuration.
Added admin username and password fields to the main module page.
Added originate timeout field to main module page.
Added auto reload and enable page status checkboxes to main module page.
Added global Jabber connection configuration fields on main module page.
Added email and cell phone fields to extension page.
Added Jabber connection configuration override fields to extension page.
Added Jabber username and password fields to extension page.
Added auto answer checkbox to extension page.
Modified database debug tables to account for new tables and columns.

Line 
1 <?php
2 /*
3  *Name         : install.php
4  *Author       : Michael Yara
5  *Created      : August 15, 2008
6  *Last Updated : May 26, 2009
7  *History      : 0.3
8  *Purpose      : Create and populate isymphony tables
9  *Copyright    : 2008 HEHE Enterprises, LLC
10  */
11
12 global $db;
13
14 //Create location table
15 $query = "  CREATE TABLE IF NOT EXISTS
16       isymphony_location( admin_user_name VARCHAR(100),
17                 admin_password VARCHAR(100),
18                 originate_timeout INTEGER(10),
19                 auto_reload INTEGER(1),
20                 page_status_enabled INTEGER(1),
21                 jabber_host VARCHAR(100),
22                 jabber_domain VARCHAR(100),
23                 jabber_resource VARCHAR(100),
24                 jabber_port INTEGER(10))";
25                
26 echo "Creating \"isymphony_location\" Table....<br>";               
27 $results = $db->query($query);
28 if(DB::IsError($results) && ($results->getCode() != DB_ERROR_ALREADY_EXISTS)) {
29   echo "ERROR: could not create table.<br>";
30 } else {
31  
32   //Check to see if table already contains location information if not insert row of default values
33   $result = $db->query("SELECT * FROM isymphony_location");
34   if($result->numRows() == 0) {
35    
36     //Populate with default values
37     echo "Populating table.....<br>";
38     $prepStatement = $db->prepare("INSERT INTO isymphony_location (admin_user_name, admin_password, originate_timeout, auto_reload, page_status_enabled, jabber_port, jabber_resource) VALUES (?, ?, ?, ?, ?, ?, ?)");
39     $values = array("admin", "secret", "30000", 1, 1, 5222, "iSymphony");
40     $db->execute($prepStatement, $values);
41   }
42 }              
43 echo "Done<br>";               
44
45 //Create users table
46 $query = "  CREATE TABLE IF NOT EXISTS
47       isymphony_users(isymphony_user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
48               user_id VARCHAR(100) UNIQUE NOT NULL,
49               add_extension INTEGER(1),
50               add_profile INTEGER(1),
51               password VARCHAR(100),
52               display_name VARCHAR(100),
53               peer VARCHAR(100),
54               email VARCHAR(100),
55               cell_phone VARCHAR(100),
56               auto_answer INTEGER(1),
57               jabber_host VARCHAR(100),
58               jabber_domain VARCHAR(100),
59               jabber_resource VARCHAR(100),
60               jabber_port INTEGER(10),
61               jabber_user_name VARCHAR(100),
62               jabber_password VARCHAR(100))";
63
64 echo "Creating \"isymphony_users\" Table....<br>";
65 $results = $db->query($query);
66 if(DB::IsError($results) && ($results->getCode() != DB_ERROR_ALREADY_EXISTS)) {
67   echo "ERROR: could not create table.<br>";
68 } else {
69
70
71   //If updating check if proper column entries exist. If not create them. Used for module upgrade purposes.
72   $iSymphonyUserTableStringColumns = array("email", "cell_phone", "jabber_host", "jabber_domain", "jabber_resource", "jabber_user_name", "jabber_password");
73   $iSymphonyUserTableIntegerColumns = array("jabber_port");
74   $iSymphonyUserTableBooleanColumns= array("auto_answer");
75
76   foreach($iSymphonyUserTableStringColumns as $stringColumn) {
77     $sql = "SELECT $stringColumn FROM isymphony_users";
78     $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
79     if(DB::IsError($check)) {
80         $sql = "ALTER TABLE isymphony_users ADD $stringColumn VARCHAR(200);";
81         $result = $db->query($sql);
82         if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
83     }
84   }
85  
86   foreach($iSymphonyUserTableIntegerColumns as $integerColumn) {
87     $sql = "SELECT $integerColumn FROM isymphony_users";
88     $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
89     if(DB::IsError($check)) {
90         $sql = "ALTER TABLE isymphony_users ADD $integerColumn INTEGER(10);";
91         $result = $db->query($sql);
92         if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
93     }
94   }
95  
96   foreach($iSymphonyUserTableBooleanColumns as $booleanColumn) {
97     $sql = "SELECT $booleanColumn FROM isymphony_users";
98     $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
99     if(DB::IsError($check)) {
100         $sql = "ALTER TABLE isymphony_users ADD $booleanColumn INTEGER(1);";
101         $result = $db->query($sql);
102         if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
103     }
104   }
105
106   //Add users to table
107   echo "Populating table.....<br>";
108   if((function_exists("core_users_list")) && (($freePBXUsers = core_users_list()) !== null)){
109     foreach($freePBXUsers as $freePBXUser) {
110       if(function_exists("core_devices_get")) {
111         $freePBXDeviceInfo = core_devices_get($freePBXUser[0]);
112        
113         $userId = $freePBXUser[0];
114         $extensionDisplayName = $freePBXUser[1] == "" ? $freePBXUser[0] : $freePBXUser[1];
115         $extensionPeer = ($freePBXDeviceInfo['dial'] != "") ? $freePBXDeviceInfo['dial'] : "SIP/$userId";
116        
117         $prepStatement = $db->prepare("INSERT INTO isymphony_users (user_id, add_extension, add_profile, password, display_name, peer, auto_answer, jabber_resource) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
118         $values = array($userId, 1, 1, "secret", $extensionDisplayName, $extensionPeer, 0, "iSymphony");
119         $db->execute($prepStatement, $values);
120       }
121     }
122   }
123 }
124 echo "Done<br>";
125
126 //Create queues table
127 $query = "  CREATE TABLE IF NOT EXISTS
128       isymphony_queues( isymphony_queue_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
129                 queue_id VARCHAR(100) UNIQUE NOT NULL,
130                 add_queue INTEGER(1),
131                 display_name VARCHAR(100))";
132    
133 echo "Creating \"isymphony_queues\" Table....<br>";     
134 $results = $db->query($query);         
135 if(DB::IsError($results) && ($results->getCode() != DB_ERROR_ALREADY_EXISTS)) {
136   echo "ERROR: could not create table.<br>";
137 } else {
138   //Add queues to table
139   echo "Populating table.....<br>";
140   if((function_exists("queues_list")) && (($freePBXQueues = queues_list()) !== null)) {
141     foreach($freePBXQueues as $freePBXQueue) {
142      
143       $queueId = $freePBXQueue[0];
144       $queueDispalyName = $freePBXQueue[1] == "" ? $freePBXQueue[0] : $freePBXQueue[1];
145      
146       $prepStatement = $db->prepare("INSERT INTO isymphony_queues (queue_id, add_queue, display_name) VALUES (?, ?, ?)");
147       $values = array($queueId, 1, $queueDispalyName);
148       $db->execute($prepStatement, $values);
149     }
150   }
151 }              
152 echo "Done<br>";
153
154 //Create conference rooms table
155 $query = "  CREATE TABLE IF NOT EXISTS
156       isymphony_conference_rooms( isymphony_conference_room_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
157                     conference_room_id VARCHAR(100) UNIQUE NOT NULL,
158                     add_conference_room INTEGER(1),
159                     display_name VARCHAR(100))";
160    
161 echo "Creating \"isymphony_conference_rooms\" Table....<br>";     
162 $results = $db->query($query);         
163 if(DB::IsError($results) && ($results->getCode() != DB_ERROR_ALREADY_EXISTS)) {
164   echo "ERROR: could not create table.<br>";
165 } else {
166   //Add rooms to table
167   echo "Populating table.....<br>";
168   if((function_exists("conferences_list")) && (($freePBXConferenceRooms = conferences_list()) !== null)) {
169     foreach($freePBXConferenceRooms as $freePBXConferenceRoom) {
170      
171       $conferenceRoomId = $freePBXConferenceRoom[0];
172       $conferenceRoomsDispalyName = $freePBXConferenceRoom[1] == "" ? $freePBXConferenceRoom[0] : $freePBXConferenceRoom[1];
173      
174       $prepStatement = $db->prepare("INSERT INTO isymphony_conference_rooms (conference_room_id, add_conference_room, display_name) VALUES (?, ?, ?)");
175       $values = array($conferenceRoomId, 1, $conferenceRoomsDispalyName);
176       $db->execute($prepStatement, $values);
177     }
178   }
179 }              
180 echo "Done<br>";
181 ?>
Note: See TracBrowser for help on using the browser.