root/contributed_modules/modules/dynroute/page.dynroute.php

Revision 15767, 16.2 kB (checked in by john@erba.tv, 6 days ago)

updates to strings

Line 
1 <?php
2 // Dynamic routing modules
3 // Copied from ivr and calleridlookup modules
4 // John Fawcett Sept 2009
5
6 if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
7
8
9 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
10 $id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
11 $nbroptions = isset($_REQUEST['nbroptions'])?$_REQUEST['nbroptions']:'3';
12 $tabindex = 0;
13
14 switch ($action) {
15     case "add":
16         $id = dynroute_get_dynroute_id('Unnamed');
17         // Set the defaults
18         $def['timeout']=5;
19         dynroute_sidebar($id);
20         dynroute_show_edit($id, $nbroptions$def);
21         break;
22     case "edit":
23         dynroute_sidebar($id);
24         dynroute_show_edit($id, $nbroptions, $_POST);
25         break;
26     case "edited":
27         if (isset($_REQUEST['delete'])) {
28             sql("DELETE from dynroute where dynroute_id='$id'");
29             sql("DELETE FROM dynroute_dests where dynroute_id='$id'");
30             needreload();
31             redirect_standard();
32         } else {
33             dynroute_do_edit($id, $_POST);
34             needreload();
35             $_REQUEST['id']=$id;
36             if (isset($_REQUEST['increase']) || isset($_REQUEST['decrease'])) {
37
38                 if (isset($_REQUEST['increase']))
39                     $nbroptions++;
40                 if (isset($_REQUEST['decrease'])) {
41                     $nbroptions--;
42                 }
43                 if ($nbroptions < 1)
44                     $nbroptions = 1;
45                 $_REQUEST['action']='edit';
46                 $_REQUEST['nbroptions']=$nbroptions;
47                 redirect_standard('id','action','nbroptions');
48             }
49             else  {
50                 redirect_standard('id');
51             }
52         }
53         break;
54     default:
55         dynroute_sidebar($id);
56 ?>
57 <div class="content">
58 <h2><?php echo _("Dynamic Routing"); ?></h2>
59 <h3><?php
60 echo _("Instructions")."</h3>";
61 echo _("You use the Dynamic Routing module to route calls based on sql lookup.")."\n";
62 echo _("For configuration instructions see").' <a href="http://www.voipsupport.it/pmwiki/pmwiki.php?n=Freepbx.DynamicRouting" target="_blank">www.voipsupport.it</a>'."\n"; ?>
63 </div>
64
65 <?php
66 }
67
68
69 function dynroute_sidebar($id)  {
70 ?>
71         <div class="rnav"><ul>
72         <li><a id="<?php echo empty($id)?'current':'nul' ?>" href="config.php?display=dynroute&amp;action=add"><?php echo _("Add Route")?></a></li>
73 <?php
74
75         $dynroute_results = dynroute_list();
76         if (isset($dynroute_results)){
77                 foreach ($dynroute_results as $tresult) {
78                         echo "<li><a id=\"".($id==$tresult['dynroute_id'] ? 'current':'nul')."\" href=\"config.php?display=dynroute";
79                         echo "&amp;action=edit&amp;id={$tresult['dynroute_id']}\">{$tresult['displayname']}</a></li>\n";
80                 }
81         }
82         echo "</ul></div>\n";
83 }
84
85 function dynroute_show_edit($id, $nbroptions, $post) {
86     global $db;
87     global $tabindex;
88
89     $dynroute_details = dynroute_get_details($id);
90 ?>
91     <div class="content">
92     <h2><?php echo _("Dynamic Routing"); ?></h2>
93     <h3><?php echo _("Edit Menu")." ".$dynroute_details['displayname']; ?></h3>
94 <?php
95 ?>
96     <form name="prompt" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return prompt_onsubmit();">
97     <input type="hidden" name="action" value="edited" />
98     <input type="hidden" name="display" value="dynroute" />
99     <input type="hidden" name="id" value="<?php echo $id ?>" />
100     <input name="Submit" type="submit" style="display:none;" value="save" />
101     <input name="delete" type="submit" value="<?php echo _("Delete")." "._("Route")." {$dynroute_details['displayname']}"; ?>" />
102 <?php
103     if ($id) {
104         $usage_list = framework_display_destination_usage(dynroute_getdest($id));
105         if (!empty($usage_list)) {
106         ?>
107             <br /><a href="#" class="info"><?php echo $usage_list['text']?>:<span><?php echo $usage_list['tooltip']?></span></a>
108         <?php
109         }
110     }
111     ?>
112     <table>
113         <tr><td colspan=2><hr /></td></tr>
114         <tr>
115             <td><a href="#" class="info"><?php echo _("Change Name"); ?><span><?php echo _("This changes the short name, visible on the right, of this Route");?></span></a></td>
116             <td><input type="text" name="displayname" value="<?php echo $dynroute_details['displayname'] ?>" tabindex="<?php echo ++$tabindex;?>"></td>
117         </tr>
118                 <tr>
119                         <td><a href="#" class="info"><?php echo _("Get DTMF input");?><span><?php echo _("If checked reads in DTMF digis, the value is available in the sql query with special name of [INPUT].");?></span></a></td>
120                         <td><input type="checkbox" name="enable_dtmf_input" <?php echo $dynroute_details['enable_dtmf_input'] ?> tabindex="<?php echo ++$tabindex;?>"></td>
121                 </tr>
122                 <tr>
123                         <td><a href="#" class="info"><?php echo _("Timeout");?><span><?php echo _("The amount of time (in seconds) to wait for input");?></span></a></td>
124                         <td><input type="text" name="timeout" value="<?php echo $dynroute_details['timeout'] ?>" tabindex="<?php echo ++$tabindex;?>"></td>
125                 </tr>
126                 <tr>
127                         <td><a href="#" class="info"><?php echo _("Input Variable");?><span><?php echo _("Optional variable name if you want the dmtf input to be available later in the call (e.g. futher dynamic route query or to pass to agi script)");?></span></a></td>
128                         <td><input type="text" name="chan_var_name" value="<?php echo $dynroute_details['chan_var_name'] ?>" tabindex="<?php echo ++$tabindex;?>"></td>
129                 </tr>
130                 <tr>
131                         <td><a href="#" class="info"><?php echo _("Result Variable");?><span><?php echo _("Optional variable name if you want the query result to be available later in the call (e.g. futher dynamic route query or to pass to agi script)");?></span></a></td>
132                         <td><input type="text" name="chan_var_name_res" value="<?php echo $dynroute_details['chan_var_name_res'] ?>" tabindex="<?php echo ++$tabindex;?>"></td>
133                 </tr>
134  
135 <?php
136         $annmsg_id = isset($dynroute_details['announcement_id'])?$dynroute_details['announcement_id']:'';
137
138         if(function_exists('recordings_list')) { //only include if recordings is enabled ?>
139                 <tr>
140                         <td><a href="#" class="info"><?php echo _("Announcement")?><span><?php echo _("Message to be played to the caller. To add additional recordings please use the \"System Recordings\" MENU above")?></span></a></td>
141                         <td>
142                                 <select name="annmsg_id" tabindex="<?php echo ++$tabindex;?>">
143                                 <?php
144                                         $tresults = recordings_list();
145                                         echo '<option value="">'._("None")."</option>";
146                                         if (isset($tresults[0])) {
147                                                 foreach ($tresults as $tresult) {
148                                                         echo '<option value="'.$tresult['id'].'"'.($tresult['id'] == $annmsg_id ? ' SELECTED' : '').'>'.$tresult['displayname']."</option>\n";
149                                                 }
150                                         }
151                                 ?>
152                                 </select>
153                         </td>
154                 </tr>
155
156 <?php
157         } else {
158 ?>
159                 <tr>
160                         <td><a href="#" class="info"><?php echo _("Announcement")?><span><?php echo _("Message to be played to the caller.<br><br>You must install and enable the \"Systems Recordings\" Module to edit this option")?></span></a></td>
161                         <td>
162                         <?php
163                                 $default = (isset($annmsg_id) ? $annmsg_id : '');
164                         ?>
165                                 <input type="hidden" name="annmsg_id" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
166                         </td>
167                 </tr>
168 <?php
169         }
170 ?>
171         <tr>
172                     <td><a href="#" class="info"><?php echo _("Source type")?><span><?php echo _("Select the source type, you can choose between:<ul><li>MySQL: It queries a MySQL database to retrieve the routing information</li><li>ODBC: It queries an ODBC data source to retrieve the routing information</li></ul>")?></span></a></td>
173
174             <td>
175                         <select id="sourcetype" name="sourcetype" onChange="javascript:displaySourceParameters(this, this.selectedIndex)" tabindex="<?php echo ++$tabindex;?>">
176                                 <option value="none" <?php echo ($dynroute_details['sourcetype'] == 'none' ? 'selected' : '')?>>choose...</option>
177                                 <option value="mysql" <?php echo ($dynroute_details['sourcetype'] == 'mysql' ? 'selected' : '')?>>MySQL</option>
178                                 <option value="odbc" <?php echo ($dynroute_details['sourcetype'] == 'odbc' ? 'selected' : '')?>>ODBC</option>
179                         </select>
180             </td>
181         </tr>
182         <tr>
183                    <td colspan="2">
184                        <div id="odbc" <?php if ($dynroute_details['sourcetype'] != 'odbc') echo 'style="display: none"';?>>
185                                 <table cellpadding="2" cellspacing="0" width="100%">
186                                         <tr><td colspan="2"><h5><?php echo _("ODBC") ?><hr></h5></div></td></tr>
187                                         <tr>
188                                                 <td><a href="#" class="info"><?php echo _("Function")?><span><?php echo _("Name of the odbc function (excluding ODBC prefix) in /etc/asterisk/func_odbc.conf")?></span></a></td>
189                                                 <td><input type="text" name="odbc_func" value="<?php echo (isset($dynroute_details['odbc_func']) ? htmlentities($dynroute_details['odbc_func']) : ''); ?>" tabindex="<?php echo ++$tabindex;?>"></td>
190                                         <tr>
191                                         </tr>
192                                                 <td><a href="#" class="info"><?php echo _("Query")?><span><?php echo _("The query which gets the result out of the database")?></span></a></td>
193                                                 <td><input type="text" name="odbc_query" size="50" value="<?php echo (isset($dynroute_details['odbc_query']) ? htmlentities($dynroute_details['odbc_query']) : ''); ?>" tabindex="<?php echo ++$tabindex;?>"></td>
194                                         </tr>
195                 </table>
196             </div>
197             </td>
198         </tr>
199
200
201
202         <tr>
203                    <td colspan="2">
204                        <div id="mysql" <?php if ($dynroute_details['sourcetype'] != 'mysql') echo 'style="display: none"';?>>
205                                 <table cellpadding="2" cellspacing="0" width="100%">
206                                         <tr><td colspan="2"><h5><?php echo _("MySQL") ?><hr></h5></div></td></tr>
207                                         <tr>
208                         <td><a href="#" class="info"><?php echo _("Host");?><span><?php echo _("Hostname or IP address of the server running the MySQL database");?></span></a></td>
209                         <td><input type="text" name="mysql_host" value="<?php echo (isset($dynroute_details['mysql_host']) ? $dynroute_details['mysql_host'] : '') ?>" tabindex="<?php echo ++$tabindex;?>"></td>
210                     </tr>
211                     <tr>
212                         <td><a href="#" class="info"><?php echo _("Database");?><span><?php echo _("The name of the database out of wich the information is being queried");?></span></a></td>
213                         <td><input type="text" name="mysql_dbname" value="<?php echo (isset($dynroute_details['mysql_dbname']) ? $dynroute_details['mysql_dbname'] : '') ?>" tabindex="<?php echo ++$tabindex;?>"></td>
214                     </tr>
215                     <tr>
216                         <td><a href="#" class="info"><?php echo _("Username");?><span><?php echo _("The user/login name for accessing the database");?></span></a></td>
217                         <td><input type="text" name="mysql_username" value="<?php echo (isset($dynroute_details['mysql_username']) ? $dynroute_details['mysql_username'] : '') ?>" tabindex="<?php echo ++$tabindex;?>"></td>
218                     </tr>
219                     <tr>
220                         <td><a href="#" class="info"><?php echo _("Password");?><span><?php echo _("The password wich is needed to access the database");?></span></a></td>
221                         <td><input type="text" name="mysql_password" value="<?php echo (isset($dynroute_details['mysql_password']) ? htmlentities($dynroute_details['mysql_password']) : '') ?>" tabindex="<?php echo ++$tabindex;?>"></td>
222                     </tr>
223                     <tr>
224                         <td><a href="#" class="info"><?php echo _("Query");?><span><?php echo _("The query wich gets the result out of the database");?></span></a></td>
225                         <td><input type="text" name="mysql_query" size="50" value="<?php echo (isset($dynroute_details['mysql_query']) ? htmlentities($dynroute_details['mysql_query']) : '') ?>" tabindex="<?php echo ++$tabindex;?>"></td>
226                                         </tr>
227                 </table>
228             </div>
229             </td>
230         </tr>
231         <tr><td colspan=2><hr /></td></tr>
232         <tr><td colspan=2>
233
234             <input name="increase" type="submit" value="<?php echo _("Increase Destinations")?>">
235             &nbsp;
236             <input name="Submit" type="submit" value="<?php echo _("Save")?>" tabindex="<?php echo ++$tabindex;?>">
237             &nbsp;
238             <?php if ($nbroptions > 1) { ?>
239             <input name="decrease" type="submit" value="<?php echo _("Decrease Destinations")?>">
240             <?php } ?>
241         </td>
242     </tr>
243     <tr><td colspan=2><hr /></td></tr>
244     <tr><th><?php echo _("Match")?></th><?php echo _("Destination")?><th></th></tr>
245 <?php
246
247     // Draw the destinations
248
249     $default_dest_row = dynroute_get_dests($id,'y');
250     if (!empty($default_dest_row)) $default_dest=$default_dest_row[0]['dest']; else $default_dest='';
251     $count = 0;
252 ?>
253     <tr>
254     <td style="text-align:right;"><?php echo _("Default destination")?></td>
255     <td> <table> <?php echo drawselects($default_dest,$count++); ?> </table> </td>
256
257     </tr>   
258 <?php
259     $dests = dynroute_get_dests($id,'n');
260     if (!empty($dests)) {
261         foreach ($dests as $dest) {
262             drawdestinations($count++, $dest['selection'], $dest['dest']);
263         }
264     }
265     while ($count < $nbroptions) {
266         drawdestinations($count++, null, null);
267     }
268 ?>
269    
270 </table>
271 <?php
272     if ($nbroptions < $count) {
273         echo "<input type='hidden' name='nbroptions' value=$count />\n";
274     } else {
275         echo "<input type='hidden' name='nbroptions' value=$nbroptions />\n";
276     }
277
278     global $module_hook;
279     echo $module_hook->hookHtml;
280 ?>
281     <input name="increase" type="submit" value="<?php echo _("Increase Destinations")?>">
282     &nbsp;
283     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
284     &nbsp;
285     <?php if ($nbroptions > 1) { ?>
286     <input name="decrease" type="submit" value="<?php echo _("Decrease Destinations")?>">
287     <?php } ?>
288    
289     <script language="javascript">
290     <!--
291
292 var theForm = document.prompt;
293 theForm.displayname.focus();
294
295     function prompt_onsubmit() {
296         var msgInvalidOption = "<?php echo _("Invalid destination"); ?>";
297        
298         defaultEmptyOK = true;
299
300         // go thru the form looking for options
301         // where the option isn't blank (as that will be removed) do the validation
302         var allelems = theForm.elements;
303         if (allelems != null)
304         {
305             var i, elem;
306             for (i = 0; elem = allelems[i]; i++)
307             {
308                 if (elem.type == 'text' && elem.name.indexOf('option') == 0)
309                 {
310                     if (elem.value != '') {
311                         if (!isRouteOption(elem.value))
312                             return warnInvalid(elem, msgInvalidOption);
313                        
314                         var gotoNum = elem.name.charAt(6);
315                         var isok = validateSingleDestination(theForm,gotoNum,true);
316                         if (!isok)
317                             return false;
318                     }
319                  }
320               }
321         }
322                                  
323         return true;
324     }
325    
326     //-->
327     </script>
328         </form>
329         </div>
330
331
332 <?php
333 }
334
335 function drawdestinations($count, $sel$dest) {
336     global $tabindex
337 ?>
338     <tr> <td style="text-align:right;">
339
340         <input size="10" type="text" name="option<?php echo $count ?>" value="<?php echo $sel ?>" tabindex="<?php echo ++$tabindex;?>"><br />
341 <?php if (strlen($sel)) {  ?>
342         <i style='font-size: x-small'><?php echo _("Leave blank to remove");?></i>
343 <?php ?>
344     </td>
345         <td> <table> <?php echo drawselects($dest,$count); ?> </table> </td>
346     </tr>
347     <tr><td colspan=2><hr /></td></tr>
348 <script language="javascript">
349 <!--
350 function displaySourceParameters(sourcetypeSelect, key) {
351         if (sourcetypeSelect.options[key].value == 'odbc') {
352                 document.getElementById('odbc').style.display = '';
353                 document.getElementById('mysql').style.display = 'none';
354         } else if (sourcetypeSelect.options[key].value == 'mysql') {
355                 document.getElementById('odbc').style.display = 'none';
356                 document.getElementById('mysql').style.display = '';
357         }
358 }
359 -->
360 </script>
361
362 <?php
363 }
364
Note: See TracBrowser for help on using the browser.