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

Revision 13091, 7.7 kB (checked in by p_lindheimer, 1 year ago)

adds FREEPBX_IS_AUTH checking to most module files re #5478

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