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

Revision 6164, 5.5 kB (checked in by p_lindheimer, 5 years ago)

#1568 callgroup, callpicup added to zap

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2
3 if (! function_exists("out")) {
4   function out($text) {
5     echo $text."<br />";
6   }
7 }
8
9 if (! function_exists("outn")) {
10   function outn($text) {
11     echo $text;
12   }
13 }
14
15 function did_migrate($incoming){
16   global $db;
17
18   foreach ($incoming as $key => $val) {
19     ${$key} = addslashes($val);
20   }
21
22   // Check to make sure the did is not being used elsewhere
23   //
24   $sql = "SELECT * FROM incoming WHERE cidnum = '' AND extension = '$extension'";
25   $existing = $db->getAll($sql, DB_FETCHMODE_ASSOC);
26   if(DB::IsError($existing)) {
27     outn(sprintf(_("ERROR: trying to check if %s already in use"),$extension));
28     return false;
29   }
30   if (empty($existing)) {
31     $sql="INSERT INTO incoming (cidnum,extension,destination,faxexten,faxemail,answer,wait,privacyman,alertinfo, ringing, mohclass, description, grppre) values ('$cidnum','$extension','$destination','$faxexten','$faxemail','$answer','$wait','$privacyman','$alertinfo', '$ringing', '$mohclass', '$description', '$grppre')";
32     sql($sql);
33     return true;
34   } else {
35     return false;
36   }
37 }
38
39 $fcc = new featurecode('core', 'userlogon');
40 $fcc->setDescription('User Logon');
41 $fcc->setDefault('*11');
42 $fcc->update();
43 unset($fcc);
44
45 $fcc = new featurecode('core', 'userlogoff');
46 $fcc->setDescription('User Logoff');
47 $fcc->setDefault('*12');
48 $fcc->update();
49 unset($fcc);
50
51 $fcc = new featurecode('core', 'zapbarge');
52 $fcc->setDescription('ZapBarge');
53 $fcc->setDefault('888');
54 $fcc->update();
55 unset($fcc);
56
57 $fcc = new featurecode('core', 'chanspy');
58 $fcc->setDescription('ChanSpy');
59 $fcc->setDefault('555');
60 $fcc->update();
61 unset($fcc);
62
63 $fcc = new featurecode('core', 'simu_pstn');
64 $fcc->setDescription('Simulate Incoming Call');
65 $fcc->setDefault('7777');
66 $fcc->update();
67 unset($fcc);
68
69 $fcc = new featurecode('core', 'simu_fax');
70 $fcc->setDescription('Dial System FAX');
71 $fcc->setDefault('666');
72 $fcc->update();
73 unset($fcc);
74
75 $fcc = new featurecode('core', 'pickup');
76 $fcc->setDescription('Call Pickup (Can be used with GXP-2000)');
77 $fcc->setDefault('**');
78 $fcc->update();
79 unset($fcc);
80
81 $fcc = new featurecode('core', 'blindxfer');
82 $fcc->setDescription('In-Call Asterisk Blind Transfer');
83 $fcc->setDefault('##');
84 $fcc->update();
85 unset($fcc);
86
87 $fcc = new featurecode('core', 'atxfer');
88 $fcc->setDescription('In-Call Asterisk Attended Transfer');
89 $fcc->setDefault('*2');
90 $fcc->update();
91 unset($fcc);
92
93 $fcc = new featurecode('core', 'automon');
94 $fcc->setDescription('In-Call Asterisk Toggle Call Recording');
95 $fcc->setDefault('*1');
96 $fcc->update();
97 unset($fcc);
98
99
100 // Version 2.5 Upgrade needs to migrate directdid user info to incoming table
101 //
102 outn(_("Checking if directdids need migrating.."));
103 $sql = "SELECT `directdid` FROM `users`";
104 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
105 if(!DB::IsError($check)) {
106   out(_("starting migration"));
107   $errors = 0;
108   $sql = "SELECT * FROM `users` WHERE `directdid` != '' AND `directdid` IS NOT NULL";
109   $direct_dids_arr = $db->getAll($sql, DB_FETCHMODE_ASSOC);
110   if(!DB::IsError($direct_dids_arr)) {
111     foreach ($direct_dids_arr as $direct_dids) {
112       $did_vars['destination'] = 'from-did-direct,'.$direct_dids['extension'].',1';
113       $did_vars['extension']   = $direct_dids['directdid'];
114       $did_vars['cidnum']      = '';
115       $did_vars['faxexten']    = $direct_dids['faxexten'];
116       $did_vars['faxemail']    = $direct_dids['faxemail'];
117       $did_vars['answer']      = $direct_dids['answer'];
118       $did_vars['wait']        = $direct_dids['wait'];
119       $did_vars['privacyman']  = $direct_dids['privacyman'];
120       $did_vars['alertinfo']   = $direct_dids['didalert'];
121       $did_vars['ringing']     = '';
122       $did_vars['mohclass']    = $direct_dids['mohclass'];
123       $did_vars['description'] = _("User: ").$direct_dids['extension'];
124       $did_vars['grppre']      = '';
125       if (!did_migrate($did_vars)) {
126         out(sprintf(_("ERROR: failed to insert %s for user %s"),$direct_dids['directdid'],$direct_dids['extension']));
127         $errors++;
128       }
129     }
130     if ($errors) {
131       out(sprintf(_("There were %s failures migrating directdids, users table not being changed"),$errors));
132     } else {
133       $migrate_array = array('directdid', 'didalert', 'mohclass', 'faxexten', 'faxemail', 'answer', 'wait', 'privacyman');
134       foreach ($migrate_array as $field) {
135         outn(sprintf(_("Removing field %s from users table.."),$field));
136         $sql = "ALTER TABLE `users` DROP `".$field."`";
137         $results = $db->query($sql);
138         if (DB::IsError($results)) {
139           out(_("not present"));
140         } else {
141           out(_("removed"));
142         }
143       }
144     }
145   } else {
146     out(_("ERROR: could not access user table to migrate directdids to incoming table, aborting"));
147   }
148 } else {
149   out(_("already done"));
150 }
151
152 // Add callgroup, pickupgroup to zap
153
154 outn(_("updating zap callgroup, pickupgroup.."));
155 $sql = "SELECT `id` FROM `devices` WHERE `tech` = 'zap'";
156 $results = $db->getCol($sql);
157 if(DB::IsError($results)) {
158   $results = null;
159 }
160 $count_pickup = 0;
161 $count_callgroup = 0;
162 if (isset($results) && !empty($results)) {
163   foreach ($results as $device) {
164     // if the insert fails then it is already there since it will violate the primary key but that is ok
165     //
166     $sql = "INSERT INTO `zap` (`id`, `keyword`, `data`, `flags`) VALUES ('$device', 'callgroup', '', '0')";
167     $try = $db->query($sql);
168     if(!DB::IsError($try)) {
169       $count_pickup++;
170     }
171     $sql = "INSERT INTO `zap` (`id`, `keyword`, `data`, `flags`) VALUES ('$device', 'pickupgroup', '', '0')";
172     $try = $db->query($sql);
173     if(!DB::IsError($try)) {
174       $count_callgroup++;
175     }
176   }
177 }
178 if ($count_callgroup || $count_pickup) {
179   out(sprintf(_("updated %s callgroups, %s pickupgroups"),$count_callgroup,$count_pickup));
180 } else {
181   out(_("not needed"));
182 }
183
184 ?>
Note: See TracBrowser for help on using the browser.