root/freepbx/tags/2.10.0beta2/amp_conf/htdocs/admin/modules/customappsreg/functions.inc.php

Revision 11663, 7.7 kB (checked in by p_lindheimer, 2 years ago)

remove most ereg() re #4001

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