root/modules/branches/2.4/customappsreg/functions.inc.php

Revision 10521, 7.6 kB (checked in by p_lindheimer, 2 years ago)

Merged revisions 10520 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.5

................

r10520 | p_lindheimer | 2010-11-02 12:18:43 -0700 (Tue, 02 Nov 2010) | 30 lines


Merged revisions 10519 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.6


................

r10519 | p_lindheimer | 2010-11-02 12:16:31 -0700 (Tue, 02 Nov 2010) | 23 lines


Merged revisions 10518 via svnmerge from
http://www.freepbx.org/v2/svn/modules/branches/2.7


................

r10518 | p_lindheimer | 2010-11-02 12:14:32 -0700 (Tue, 02 Nov 2010) | 16 lines


Merged revisions 10517 via svnmerge from
http://svn.freepbx.org/modules/branches/2.8


................

r10517 | p_lindheimer | 2010-11-02 12:12:08 -0700 (Tue, 02 Nov 2010) | 9 lines


Merged revisions 10516 via svnmerge from
http://svn.freepbx.org/modules/branches/2.9


........

r10516 | p_lindheimer | 2010-11-02 12:10:23 -0700 (Tue, 02 Nov 2010) | 1 line


fixes #4618 xss security issue and some other precations unreported

........

................

................

................

................

Line 
1 <?php
2
3 function customappsreg_destinations() {
4   // return an associative array with destination and description
5   foreach (customappsreg_customdests_list() as $row) {
6     $extens[] = array('destination' => $row['custom_dest'], 'description' => $row['description']);
7   }
8   return $extens;
9 }
10
11 /** the 'exten' is the same as the destination for this module
12  */
13 function customappsreg_customdests_getdest($exten) {
14   return array($exten);
15 }
16
17 /** If this is ours, we return it, otherwise we return false
18  *  We use just use customappsreg and not the display because it
19  *  is a per-module routine
20  */
21 function customappsreg_getdestinfo($dest) {
22   global $active_modules;
23
24   $thisexten = customappsreg_customdests_get($dest);
25   if (empty($thisexten)) {
26     return false;
27   } else {
28     $type = isset($active_modules['customappsreg']['type'])?$active_modules['customappsreg']['type']:'tool';
29     return array('description' => 'Custom Destination: '.$thisexten['description'],
30                  'edit_url' => 'config.php?display=customdests&type='.$type.'&extdisplay='.urlencode($dest),
31                 );
32   }
33 }
34
35 function customappsreg_check_extensions($exten=true) {
36   global $active_modules;
37
38   $extenlist = array();
39   if (is_array($exten) && empty($exten)) {
40     return $extenlist;
41   }
42   $sql = "SELECT custom_exten, description FROM custom_extensions ";
43   if (is_array($exten)) {
44     $sql .= "WHERE custom_exten in ('".implode("','",$exten)."')";
45   }
46   $results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
47
48   $type = isset($active_modules['customappsreg']['type'])?$active_modules['customappsreg']['type']:'tool';
49
50   foreach ($results as $result) {
51     $thisexten = $result['custom_exten'];
52     $extenlist[$thisexten]['description'] = _("Custom Extension: ").$result['description'];
53     $extenlist[$thisexten]['status'] = 'INUSE';
54     $extenlist[$thisexten]['edit_url'] = 'config.php?display=customextens&extdisplay='.urlencode($thisexten);
55   }
56   return $extenlist;
57 }
58
59 function customappsreg_customdests_list() {
60   global $db;
61   $sql = "SELECT custom_dest, description, notes FROM custom_destinations ORDER BY description";
62   $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
63   if(DB::IsError($results)) {
64     die_freepbx($results->getMessage()."<br><br>Error selecting from custom_destinations");
65   }
66   return $results;
67 }
68
69 function customappsreg_customextens_list() {
70   global $db;
71   $sql = "SELECT custom_exten, description, notes FROM custom_extensions ORDER BY custom_exten";
72   $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
73   if(DB::IsError($results)) {
74     die_freepbx($results->getMessage()."<br><br>Error selecting from custom_extensions");
75   }
76   return $results;
77 }
78
79 function customappsreg_customdests_get($custom_dest) {
80   global $db;
81   $sql = "SELECT custom_dest, description, notes FROM custom_destinations WHERE custom_dest = ".q($custom_dest);
82   $row = $db->getRow($sql, DB_FETCHMODE_ASSOC);
83   if(DB::IsError($row)) {
84     die_freepbx($row->getMessage()."<br><br>Error selecting row from custom_destinations");
85   }
86   return $row;
87 }
88
89 function customappsreg_customextens_get($custom_exten) {
90   global $db;
91   $sql = "SELECT custom_exten, description, notes FROM custom_extensions WHERE custom_exten = ".q($custom_exten);
92   $row = $db->getRow($sql, DB_FETCHMODE_ASSOC);
93   if(DB::IsError($row)) {
94     die_freepbx($row->getMessage()."<br><br>Error selecting row from custom_extensions");
95   }
96   return $row;
97 }
98
99 function customappsreg_customdests_add($custom_dest, $description, $notes) {
100   global $db;
101
102   if (!ereg("[^,]+,[^,]+,[^,]+",$custom_dest)) {
103     echo "<script>javascript:alert('"._('Invalid Destination, must not be blank, must be formatted as: context,exten,pri')."')</script>";
104     return false;
105   }
106   if (trim($description) == '') {
107     echo "<script>javascript:alert('"._('Invalid description specified, must not be blank')."')</script>";
108     return false;
109   }
110   $usage_list = framework_identify_destinations($custom_dest, $module_hash=false);
111   if (!empty($usage_list[$custom_dest])) {
112     echo "<script>javascript:alert('"._('DUPLICATE Destination: This destination is already in use')."')</script>";
113     return false;
114   }
115
116   $custom_dest = sql_formattext($custom_dest);
117   $description = sql_formattext($description);
118   $notes       = sql_formattext($notes);
119   $sql = "INSERT INTO custom_destinations (custom_dest, description, notes) VALUES ($custom_dest, $description, $notes)";
120   $results = $db->query($sql);
121   if (DB::IsError($results)) {
122     if ($results->getCode() == DB_ERROR_ALREADY_EXISTS) {
123       echo "<script>javascript:alert('"._('DUPLICATE Destination: This destination is in use or potentially used by another module')."')</script>";
124       return false;
125     } else {
126       die_freepbx($results->getMessage()."<br><br>".$sql);
127     }
128   }
129   return true;
130 }
131
132 function customappsreg_customextens_add($custom_exten, $description, $notes) {
133   global $db;
134
135   if ($custom_exten == '') {
136     echo "<script>javascript:alert('"._('Invalid Extension, must not be blank')."')</script>";
137     return false;
138   }
139   if (trim($description) == '') {
140     echo "<script>javascript:alert('"._('Invalid description specified, must not be blank')."')</script>";
141     return false;
142   }
143
144   $custom_exten = sql_formattext($custom_exten);
145   $description  = sql_formattext($description);
146   $notes        = sql_formattext($notes);
147   $sql = "INSERT INTO custom_extensions (custom_exten, description, notes) VALUES ($custom_exten, $description, $notes)";
148   $results = $db->query($sql);
149   if (DB::IsError($results)) {
150     if ($results->getCode() == DB_ERROR_ALREADY_EXISTS) {
151       echo "<script>javascript:alert('"._('DUPLICATE Extension: This extension already in use')."')</script>";
152       return false;
153     } else {
154       die_freepbx($results->getMessage()."<br><br>".$sql);
155     }
156   }
157   return true;
158 }
159
160 function customappsreg_customdests_delete($custom_dest) {
161   global $db;
162
163   $sql = "DELETE FROM custom_destinations WHERE custom_dest = ".q($custom_dest);
164   $result = $db->query($sql);
165   if(DB::IsError($result)) {
166     die_freepbx($result->getMessage().$sql);
167   }
168 }
169
170 function customappsreg_customextens_delete($custom_exten) {
171   global $db;
172
173   $sql = "DELETE FROM custom_extensions WHERE custom_exten = ".q($custom_exten);
174   $result = $db->query($sql);
175   if(DB::IsError($result)) {
176     die_freepbx($result->getMessage().$sql);
177   }
178 }
179
180 function customappsreg_customdests_edit($old_custom_dest, $custom_dest,  $description, $notes) {
181   global $db;
182
183   if ($old_custom_dest != $custom_dest) {
184     $usage_list = framework_identify_destinations($custom_dest, $module_hash=false);
185     if (!empty($usage_list[$custom_dest])) {
186       echo "<script>javascript:alert('"._('DUPLICATE Destination: This destination is in use or potentially used by another module')."')</script>";
187       return false;
188     }
189   }
190
191   $sql = "UPDATE custom_destinations SET ".
192     "custom_dest = ".sql_formattext($custom_dest).", ".
193     "description = ".sql_formattext($description).", ".
194     "notes = ".sql_formattext($notes)." ".
195     "WHERE custom_dest = ".sql_formattext($old_custom_dest);
196   $result = $db->query($sql);
197   if(DB::IsError($result)) {
198     die_freepbx($result->getMessage().$sql);
199   }
200 }
201
202 function customappsreg_customextens_edit($old_custom_exten, $custom_exten,  $description, $notes) {
203   global $db;
204
205   $sql = "UPDATE custom_extensions SET ".
206     "custom_exten = ".sql_formattext($custom_exten).", ".
207     "description = ".sql_formattext($description).", ".
208     "notes = ".sql_formattext($notes)." ".
209     "WHERE custom_exten = ".sql_formattext($old_custom_exten);
210   $result = $db->query($sql);
211   if(DB::IsError($result)) {
212     die_freepbx($result->getMessage().$sql);
213   }
214 }
215
216 function customappsreg_customdests_getunknown() {
217
218   $results = array();
219
220   $my_probs = framework_list_problem_destinations($my_hash, false);
221
222   if (!empty($my_probs)) {
223     foreach ($my_probs as $problem) {
224       if ($problem['status'] == 'CUSTOM') {
225         $results[] = $problem['dest'];
226       }
227     }
228   }
229   return array_unique($results);
230 }
231
232 ?>
Note: See TracBrowser for help on using the browser.