root/modules/branches/2.5/core/page.trunks.php

Revision 7409, 37.6 kB (checked in by p_lindheimer, 4 years ago)

fixes #3463 missing _() enclosure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 // routing.php Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca)
3 // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License
7 //as published by the Free Software Foundation; either version 2
8 //of the License, or (at your option) any later version.
9 //
10 //This program is distributed in the hope that it will be useful,
11 //but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //GNU General Public License for more details.
14
15
16 $display='trunks';
17 $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'';
18 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
19 $tech = strtolower(isset($_REQUEST['tech'])?$_REQUEST['tech']:'');
20
21 $trunknum = ltrim($extdisplay,'OUT_');
22
23
24 // populate some global variables from the request string
25 $set_globals = array("outcid","maxchans","dialoutprefix","channelid","peerdetails","usercontext","userconfig","register","keepcid","failtrunk","disabletrunk");
26 foreach ($set_globals as $var) {
27     if (isset($_REQUEST[$var])) {
28         $$var = stripslashes( $_REQUEST[$var] );
29     }
30 }
31
32 // ensure that keepcid is set to something:
33 if (!isset($keepcid)) {
34     $keepcid = "off";
35 }
36 // ensure that failtrunk is set to something:
37 if (!isset($failtrunk)) {
38     $failtrunk = "";
39 }
40 $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
41
42 if (!isset($disabletrunk)) {
43     $disabletrunk = "off";
44 }
45
46 if (isset($_REQUEST["dialrules"])) {
47     //$dialpattern = $_REQUEST["dialpattern"];
48     $dialrules = explode("\n",$_REQUEST["dialrules"]);
49
50     if (is_array($dialrules))
51         foreach (array_keys($dialrules) as $key) {
52             //trim it
53             $dialrules[$key] = trim($dialrules[$key]);
54             
55             // remove blanks
56             if ($dialrules[$key] == "") unset($dialrules[$key]);
57             
58             // remove leading underscores (we do that on backend)
59             if ($dialrules[$key][0] == "_") $dialrules[$key] = substr($dialrules[$key],1);
60         }
61     
62     // check for duplicates, and re-sequence
63     $dialrules = array_values(array_unique($dialrules));
64 } else {
65     $dialrules = array();
66 }
67
68 //if submitting form, update database
69 switch ($action) {
70     case "addtrunk":
71         if (!isset($failtrunk))
72             $failtrunk="";
73         $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk),$disabletrunk);
74         
75         core_trunks_addDialRules($trunknum, $dialrules);
76         needreload();
77         redirect_standard();
78     break;
79     case "edittrunk":
80         if (!isset($failtrunk))
81             $failtrunk="";
82         core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk);
83         
84         /* //DIALRULES
85         deleteTrunkRules($channelid);
86         addTrunkRules($channelid, $dialrules);
87         */
88         
89         // this can rewrite too, so edit is the same
90         core_trunks_addDialRules($trunknum, $dialrules);
91         needreload();
92         redirect_standard('extdisplay');
93     break;
94     case "deltrunk":
95     
96         core_trunks_del($trunknum);
97         
98         /* //DIALRULES
99         deleteTrunkRules($channelid);
100         */
101         core_trunks_deleteDialRules($trunknum);
102         needreload();
103         redirect_standard();
104     break;
105     case "populatenpanxx7":
106     case "populatenpanxx10":
107         if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {
108             // first thing we do is grab the exch:
109             $ch = curl_init();
110             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
111             curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
112             curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)");
113             $str = curl_exec($ch);
114             curl_close($ch);
115
116             // quick 'n dirty - nabbed from PEAR
117             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php');
118             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php');
119
120             $xml = new xml_unserializer;
121             $xml->unserialize($str);
122             $xmldata = $xml->getUnserializedData();
123
124             if (isset($xmldata['lca-data']['prefix'])) {
125                 
126                 if ($action == 'populatenpanxx10') {
127                     // 10 digit dialing
128                     // - add area code to 7 digits
129                     // - match local 10 digits
130                     // - add 1 to anything else
131                     $dialrules[] = $matches[1].'NXXXXXX';
132                     // add NPA to 7-digits
133                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
134                         $dialrules[] = $prefix['npa'].'+'.$prefix['nxx'].'XXXX';
135                     }
136                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
137                         $dialrules[] = $prefix['npa'].$prefix['nxx'].'XXXX';
138                     }
139                     // if a number was not matched as local, dial it with '1' prefix
140                     $dialrules[] = '1+NXXNXXXXXX';
141                 } else {
142                     // 7 digit dialing
143                     // - drop area code from local numbers
144                     // - match local 7 digit numbers
145                     // - add 1 to everything else
146                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
147                         $dialrules[] = $prefix['npa'].'|'.$prefix['nxx'].'XXXX';
148                     }
149                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
150                         $dialrules[] = $prefix['nxx'].'XXXX';
151                     }
152                     $dialrules[] = '1+NXXNXXXXXX';
153                     $dialrules[] = '1'.$matches[1].'+NXXXXXX';
154                 }
155
156                 // check for duplicates, and re-sequence
157                 $dialrules = array_values(array_unique($dialrules));
158             } else {
159                 $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];
160             }
161
162         } else {
163             // what a horrible error message... :p
164             $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");
165         }
166         
167         if (isset($errormsg)) {
168             echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";
169             unset($errormsg);
170         }
171     break;
172 }
173     
174 //get all rows from globals
175 $sql = "SELECT * FROM globals";
176 $globals = $db->getAll($sql);
177 if(DB::IsError($globals)) {
178     die_freepbx($globals->getMessage());
179 }
180
181 //create a set of variables that match the items in global[0]
182 foreach ($globals as $global) {
183     ${trim($global[0])} = htmlentities($global[1]);
184 }
185
186 ?>
187 </div>
188
189 <div class="rnav">
190 <ul>
191     <li><a <?php  echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Trunk")?></a></li>
192 <?php
193 //get existing trunk info
194 $tresults = core_trunks_list();
195
196 foreach ($tresults as $tresult) {
197     $background = ($tresult[2] == 'on')?'#DDD':'';
198     echo "\t<li><a ".($extdisplay==$tresult[0] ? 'class="current"':'')." href=\"config.php?display=".urlencode($display)."&amp;extdisplay=".urlencode($tresult[0])."\" title=\"".urlencode($tresult[1])."\" style=\"background: $background;\" >"._("Trunk")." ".substr(str_replace('AMP:', '', $tresult[1]),0,15)."</a></li>\n";
199 }
200
201 ?>
202 </ul>
203 </div>
204
205 <div class="content">
206
207 <?php
208 if (!$tech && !$extdisplay) {
209 ?>
210     <h2><?php echo _("Add a Trunk")?></h2>
211 <?php
212     $baseURL   = $_SERVER['PHP_SELF'].'?display='.urlencode($display).'&';
213     $trunks = array(
214         array('url'=> $baseURL.'tech=ZAP', 'tlabel' =>  _("Add Zap Trunk").(ast_with_dahdi()?" ("._("DAHDI compatibility mode").")":"" )),
215         array('url'=> $baseURL.'tech=IAX2', 'tlabel' =>  _("Add IAX2 Trunk")),
216         array('url'=> $baseURL.'tech=SIP', 'tlabel' =>  _("Add SIP Trunk")),
217         array('url'=> $baseURL.'tech=ENUM', 'tlabel' =>  _("Add ENUM Trunk")),
218         array('url'=> $baseURL.'tech=DUNDI', 'tlabel' =>  _("Add DUNDi Trunk")),
219         array('url'=> $baseURL.'tech=CUSTOM', 'tlabel' =>  _("Add Custom Trunk")),
220     );
221     foreach ($trunks as $trunk) {
222         $label = '<span><img width="16" height="16" border="0" title="'.$trunk['tlabel'].'" alt="" src="images/core_add.png"/>&nbsp;'.$trunk['tlabel'].'</span>';
223         echo "<a href=".$trunk['url'].">".$label."</a><br /><br />";
224     }
225 } else {
226     if ($extdisplay) {
227         //list($trunk_tech, $trunk_name) = explode("/",$tname);
228         //if ($trunk_tech == "IAX2") $trunk_tech = "IAX"; // same thing
229         $tech = core_trunks_getTrunkTech($trunknum);
230
231         $outcid = ${"OUTCID_".$trunknum};
232         $maxchans = ${"OUTMAXCHANS_".$trunknum};
233         $dialoutprefix = ${"OUTPREFIX_".$trunknum};
234         $keepcid = isset(${"OUTKEEPCID_".$trunknum})?${"OUTKEEPCID_".$trunknum}:'';
235         $failtrunk = isset(${"OUTFAIL_".$trunknum})?${"OUTFAIL_".$trunknum}:'';
236         $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
237         $disabletrunk = isset(${"OUTDISABLE_".$trunknum})?${"OUTDISABLE_".$trunknum}:'';
238
239         
240         if ($tech!="enum") {
241     
242             if (!isset($channelid)) {
243                 $channelid = core_trunks_getTrunkTrunkName($trunknum);
244             }
245
246             if ($tech!="custom" && $tech!="dundi") {  // custom trunks will not have user/peer details in database table
247                 // load from db
248                 if (!isset($peerdetails)) {   
249                     $peerdetails = core_trunks_getTrunkPeerDetails($trunknum);
250                 }
251     
252                 if (!isset($usercontext)) {   
253                     $usercontext = core_trunks_getTrunkUserContext($trunknum);
254                 }
255     
256                 if (!isset($userconfig)) {   
257                     $userconfig = core_trunks_getTrunkUserConfig($trunknum);
258                 }
259                     
260                 if (!isset($register)) {   
261                     $register = core_trunks_getTrunkRegister($trunknum);
262                 }
263             }
264         }
265         
266         if (count($dialrules) == 0) {
267             if ($temp = core_trunks_getDialRules($trunknum)) {
268                 foreach ($temp as $key=>$val) {
269                     // extract all ruleXX keys
270                     if (preg_match("/^rule\d+$/",$key)) {
271                         $dialrules[] = $val;
272                     }
273                 }
274             }
275             unset($temp);
276         }
277
278
279         $upper_tech = strtoupper($tech);
280         echo "<h2>".sprintf(_("Edit %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDI compatibility Mode").")":"")."</h2>";
281         $tlabel = sprintf(_("Delete Trunk %s"),substr($channelid,0,20));
282         $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>';
283 ?>
284         <p><a href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=deltrunk"><?php echo $label ?></a></p>
285 <?php
286
287         // find which routes use this trunk
288         $routes = core_trunks_gettrunkroutes($trunknum);
289         $num_routes = count($routes);
290         if ($num_routes > 0) {
291             echo "<a href=# class=\"info\">&nbsp;"._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes"))."<span>";
292             foreach($routes as $route=>$priority) {
293                 echo _("Route")." <b>".$route."</b>: "._("Sequence")." <b>".$priority."</b><br>";
294             }
295             echo "</span></a>";
296         } else {
297             echo "&nbsp;<b>"._("WARNING:")."</b> <a href=# class=\"info\">"._("This trunk is not used by any routes!")."<span>";
298             echo _("This trunk will not be able to be used for outbound calls until a route is setup that uses it. Click on <b>Outbound Routes</b> to setup routing.");
299             echo "</span></a>";
300         }
301
302     } else {
303         // set defaults
304         $outcid = "";
305         $maxchans = "";
306         $dialoutprefix = "";
307         
308         if ($tech == "zap") {
309             $channelid = "g0";
310         } else {
311             $channelid = "";
312         }
313         
314         // only for iax2/sip
315         $peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer";
316         $usercontext = "";
317         $userconfig = "secret=***password***\ntype=user\ncontext=from-trunk";
318         $register = "";
319         
320         $localpattern = "NXXXXXX";
321         $lddialprefix = "1";
322         $areacode = "";
323     
324         $upper_tech = strtoupper($tech);
325         echo "<h2>".sprintf(_("Add %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDI compatibility mode").")":"")."</h2>";
326     }
327 switch ($tech) {
328     case 'dundi':
329         $helptext = _('FreePBX offers limited support for DUNDi trunks and additional manual configuration is required. The trunk name should correspond to the [mappings] section of the remote dundi.conf systems. For example, you may have a mapping on the remote system, and corresponding configurations in dundi.conf locally, that looks as follows:<br /><br />[mappings]<br />priv => dundi-extens,0,IAX2,priv:${SECRET}@218.23.42.26/${NUMBER},noparital<br /><br />In this example, you would create this trunk and name it priv. You would then create the corresponding IAX2 trunk with proper settings to work with DUNDi. This can be done by making an IAX2 trunk in FreePBX or by using the iax_custom.conf file.<br />The dundi-extens context in this example must be created in extensions_custom.conf. This can simply include contexts such as ext-local, ext-intercom-users, ext-paging and so forth to provide access to the corresponding extensions and features provided by these various contexts and generated by FreePBX.');
330         break;
331     default:
332         $helptext = '';
333 }
334 if ($helptext != '') {
335     if ($extdisplay) {
336         echo "<br /><br />";
337     }
338     echo $helptext;
339 }
340         
341 ?>
342    
343         <form name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');">
344             <input type="hidden" name="display" value="<?php echo $display?>"/>
345             <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
346             <input type="hidden" name="action" value=""/>
347             <input type="hidden" name="tech" value="<?php echo $tech?>"/>
348             <table>
349             <tr>
350                 <td colspan="2">
351                     <h4><?php echo _("General Settings")?></h4>
352                 </td>
353             </tr>
354             <tr>
355                 <td>
356                     <a href=# class="info"><?php echo _("Outbound Caller ID")?><span><br><?php echo _("Caller ID for calls placed out on this trunk<br><br>Format: <b>\"caller name\" &lt;#######&gt;</b>. You can also use the magic string 'hidden' to hide the CallerID sent out over Digital lines ONLY (E1/T1/J1/BRI/SIP/IAX)")?><br><br></span></a>:
357                 </td><td>
358                     <input type="text" size="20" name="outcid" value="<?php echo $outcid;?>" tabindex="<?php echo ++$tabindex;?>"/>
359                 </td>
360             </tr>
361             <tr>
362                 <td>
363                     <a href="#" class="info"><?php echo _("Never Override CallerID")?><span><br><?php echo _("Some VoIP providers will drop the call if you try to send an invalid CallerID (one you don't 'own.' Use this to never send a CallerID that you haven't explicitly specified in this trunk or in the outbound callerid field of an extension/user. You might notice this problem if you discover that Follow-Me or RingGroups with external numbers don't work properly. Checking this box has the effect of disabling 'foreign' callerids from going out this trunk. You must define an Outbound Caller ID on the this trunk when checking this.");?><br /><br /></span></a>:
364                 </td><td>
365                     <input type="checkbox" name="keepcid" <?php if ($keepcid=="on") {echo "checked";}?> tabindex="<?php echo ++$tabindex;?>"/>
366                 </td>
367             <tr>
368                 <td>
369 <?php
370     if ($tech == "sip" || substr($tech,0,3) == "iax") {
371         $pr_tech = ($tech == "iax") ? "iax2":$tech;
372 ?>
373                     <a href=# class="info"><?php echo _("Maximum Channels")?><span><?php echo sprintf(_("Controls the maximum number of outbound channels (simultaneous calls) that can be used on this trunk. To count inbound calls against this maximum, use the auto-generated context: %s as the inbound trunk's context. (see extensions_additional.conf) Leave blank to specify no maximum."),((isset($channelid) && trim($channelid)!="")?"from-trunk-$pr_tech-$channelid":"from-trunk-[trunkname]"))?></span></a>:
374 <?php
375     } else {
376 ?>
377                     <a href=# class="info"><?php echo _("Maximum Channels")?><span><?php echo _("Controls the maximum number of outbound channels (simultaneous calls) that can be used on this trunk. Inbound calls are not counted against the maximum. Leave blank to specify no maximum.")?></span></a>:
378 <?php
379     }
380 ?>
381                 </td><td>
382                     <input type="text" size="3" name="maxchans" value="<?php echo htmlspecialchars($maxchans); ?>" tabindex="<?php echo ++$tabindex;?>"/>
383                 </td>
384             </tr>
385
386             <tr>
387                 <td><a class="info" href="#"><?php echo _("Disable Trunk")?><span><?php echo _("Check this to disable this trunk in all routes where it is used.")?></span></a>:
388                 </td>
389                 <td>
390                 <input type='checkbox'  tabindex="<?php echo ++$tabindex;?>"name='disabletrunk' id="disabletrunk" <?php if ($disabletrunk=="on") { echo 'CHECKED'; }?> OnClick='disable_verify(disabletrunk); return true;'><small><?php echo _("Disable")?></small>
391                 </td>
392             </tr>
393
394             <tr>
395                 <td><a class="info" href="#"><?php echo _("Monitor Trunk Failures")?><span><?php echo _("If checked, supply the name of a custom AGI Script that will be called to report, log, email or otherwise take some action on trunk failures that are not caused by either NOANSWER or CANCEL.")?></span></a>:
396                 </td>
397                 <td>
398                 <input <?php if (!$failtrunk_enable) echo "disabled style='background: #DDD;'"?> type="text" size="20" name="failtrunk" value="<?php echo htmlspecialchars($failtrunk)?>"/>
399                 <input type='checkbox' tabindex="<?php echo ++$tabindex;?>" name='failtrunk_enable' id="failtrunk_enable" value='1' <?php if ($failtrunk_enable) { echo 'CHECKED'; }?> OnClick='disable_field(failtrunk,failtrunk_enable); return true;'><small><?php echo _("Enable")?></small>
400                 </td>
401             </tr>
402
403             <tr>
404                 <td colspan="2">
405                     <h4><?php echo _("Outgoing Dial Rules")?></h4>
406                 </td>
407             </tr>
408             <tr>
409                 <td valign="top">
410                     <a href=# class="info"><?php echo _("Dial Rules")?><span><?php echo _("A Dial Rule controls how calls will be dialed on this trunk. It can be used to add or remove prefixes. Numbers that don't match any patterns defined here will be dialed as-is. Note that a pattern without a + or | (to add or remove a prefix) will not make any changes but will create a match. Only the first matched rule will be executed and the remaining rules will not be acted on.")?><br /><br /><b><?php echo _("Rules:")?></b><br />
411     <strong>X</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br />
412     <strong>Z</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br />
413     <strong>N</strong>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br />
414     <strong>[1237-9]</strong>&nbsp;   <?php echo _("matches any digit or letter in the brackets (in this example, 1,2,3,7,8,9)")?><br />
415     <strong>.</strong>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more characters (not allowed before a | or +)")?><br />
416     <strong>|</strong>&nbsp;&nbsp;&nbsp; <?php echo _("removes a dialing prefix from the number (for example, 613|NXXXXXX would match when some dialed \"6135551234\" but would only pass \"5551234\" to the trunk)")?>
417     <strong>+</strong>&nbsp;&nbsp;&nbsp; <?php echo _("adds a dialing prefix from the number (for example, 1613+NXXXXXX would match when some dialed \"5551234\" and would pass \"16135551234\" to the trunk)")?><br /><br />
418     <?php echo _("You can also use both + and |, for example: 01+0|1ZXXXXXXXXX would match \"016065551234\" and dial it as \"0116065551234\" Note that the order does not matter, eg. 0|01+1ZXXXXXXXXX does the same thing."); ?>
419                     </span></a>:
420                 </td><td valign="top">
421                     <textarea id="dialrules" cols="20"  tabindex="<?php echo ++$tabindex;?>" rows="<?php 
422                         if (is_array($dialrules)) {
423                             $rows = count($dialrules)+1;
424                             echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) );
425                         } else {
426                             echo "5";
427                         } ?>" name="dialrules"><?php if(is_array($dialrules)) { echo implode("\n",$dialrules); } ?></textarea><br>
428                    
429                     <input type="submit" style="font-size:10px;" value="<?php echo _("Clean & Remove duplicates")?>"  tabindex="<?php echo ++$tabindex;?>"/>
430                 </td>
431             </tr>
432             <tr>
433                 <td>
434                     <a href=# class="info"><?php echo _("Dial Rules Wizards")?><span>
435                     <strong><?php echo _("Always dial with prefix")?></strong> <?php echo _("is useful for VoIP trunks, where if a number is dialed as \"5551234\", it can be converted to \"16135551234\".")?><br>
436                     <strong><?php echo _("Remove prefix from local numbers")?></strong> <?php echo _("is useful for ZAP trunks, where if a local number is dialed as \"6135551234\", it can be converted to \"555-1234\".")?><br>
437                     <strong><?php echo _("Lookup numbers for local trunk")?></strong> <?php echo _("This looks up your local number on www.localcallingguide.com (NA-only), and sets up so you can dial either 7 or 10 digits (regardless of what your PSTN is) on a local trunk (where you have to dial 1+area code for long distance, but only 5551234 (7-digit dialing) or 6135551234 (10-digit dialing) for local calls")?><br>
438                     </span></a>:
439                 </td><td valign="top"><select id="autopop"  tabindex="<?php echo ++$tabindex;?>" name="autopop" onChange="changeAutoPop(); ">
440                         <option value="" SELECTED><?php echo _("(pick one)")?></option>
441                         <option value="always"><?php echo _("Always dial with prefix")?></option>
442                         <option value="remove"><?php echo _("Remove prefix from local numbers")?></option>
443                         <option value="lookup7"><?php echo _("Lookup numbers for local trunk (7-digit dialing)")?></option>
444                         <option value="lookup10"><?php echo _("Lookup numbers for local trunk (10-digit dialing)")?></option>
445                     </select>
446                 </td>
447             </tr>
448             <input id="npanxx" name="npanxx" type="hidden" />
449             <script language="javascript">
450            
451             function disable_field(field, field_enable) {
452                 if (field_enable.checked) {
453                 field.style.backgroundColor = '#FFF';
454                 field.disabled = false;
455                 }
456                 else {
457                 field.style.backgroundColor = '#DDD';
458                 field.disabled = true;
459                 }
460             }
461
462             function disable_verify(field) {
463                 if (field.checked) {
464                     var answer=confirm("<?php echo _("Are you sure you want to disable this trunk in all routes it is used?") ?>");
465                     if (!answer) {
466                         field.checked = false;
467                     }
468                 } else {
469                     alert("<?php echo _("You have enabled this trunk in all routes it is used") ?>");
470                 }
471             }
472
473             function populateLookup(digits) {
474 <?php
475     if (function_exists("curl_init")) { // curl is installed
476 ?>                
477                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
478                 do {
479                     var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?\\n\\n(Note: this database contains North American numbers only, and is not guaranteed to be 100% accurate. You will still have the option of modifying results.)\\n\\nThis may take a few seconds.".'")')?>;
480                     if (npanxx == null) return;
481                 } while (!npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$") && <?php echo '!alert("'._("Invalid NPA-NXX. Must be of the format \'NXX-NXX\'").'")'?>);
482                
483                 document.getElementById('npanxx').value = npanxx;
484                 if (digits == 10) {
485                     document.trunkEdit.action.value = "populatenpanxx10";
486                 } else {
487                     document.trunkEdit.action.value = "populatenpanxx7";
488                 }
489                 document.trunkEdit.submit();
490 <?php 
491     } else { // curl is not installed
492 ?>
493                 <?php echo 'alert("'._("Error: Cannot continue!\\n\\nPrefix lookup requires cURL support in PHP on the server. Please install or enable cURL support in your PHP installation to use this function. See http://www.php.net/curl for more information.").'")'?>;
494 <?php
495     }
496 ?>
497             }
498            
499             function populateAlwaysAdd() {
500                 do {
501                     var localpattern = <?php echo 'prompt("'._("What is the local dialing pattern?\\n\\n(ie. NXXNXXXXXX for US/CAN 10-digit dialing, NXXXXXX for 7-digit)").'"'?>,"NXXXXXX");
502                     if (localpattern == null) return;
503                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
504                
505                 do {
506                     var localprefix = <?php echo 'prompt("'._("What prefix should be added to the dialing pattern?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')?").'")'?>;
507                     if (localprefix == null) return;
508                 } while (!localprefix.match('^[0-9#*]+$') && <?php echo '!alert("'._("Invalid prefix. Only dialable characters (0-9, #, and *) are allowed.").'")'?>);
509
510                 dialrules = document.getElementById('dialrules');
511                 if (dialrules.value[dialrules.value.length-1] != '\n') {
512                     dialrules.value = dialrules.value + '\n';
513                 }
514                 dialrules.value = dialrules.value + localprefix + '+' + localpattern + '\n';
515             }
516            
517             function populateRemove() {
518                 do {
519                     var localprefix = <?php echo 'prompt("'._("What prefix should be removed from the number?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')").'")'?>;
520                     if (localprefix == null) return;
521                 } while (!localprefix.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._('Invalid prefix. Only 0-9, #, *, Z, N, and X are allowed.').'")'?>);
522                
523                 do {
524                     var localpattern = <?php echo 'prompt("'._("What is the dialing pattern for local numbers after")?> "+localprefix+"? \n\n<?php echo _("(ie. NXXNXXXXXX for US/CAN 10-digit dialing, NXXXXXX for 7-digit)").'"'?>,"NXXXXXX");
525                     if (localpattern == null) return;
526                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
527                
528                 dialrules = document.getElementById('dialrules');
529                 if (dialrules.value[dialrules.value.length-1] != '\n') {
530                     dialrules.value = dialrules.value + '\n';
531                 }
532                 dialrules.value = dialrules.value + localprefix + '|' + localpattern + '\n';
533             }
534            
535             function changeAutoPop() {
536                 switch(document.getElementById('autopop').value) {
537                     case "always":
538                         populateAlwaysAdd();
539                     break;
540                     case "remove":
541                         populateRemove();
542                     break;
543                     case "lookup7":
544                         populateLookup(7);
545                     break;
546                     case "lookup10":
547                         populateLookup(10);
548                     break;
549                 }
550                 document.getElementById('autopop').value = '';
551             }
552             </script>
553 <?php /* //DIALRULES
554             <tr>
555                 <td>
556                     <a href=# class="info">Dial rules<span>The area code this trunk is in.</span></a>:
557                 </td><td>&nbsp;
558                     <select id="dialrulestype" name="dialrulestype" onChange="changeRulesType();">
559 <?php
560                     $rules = array( "asis" => "Don't change number",
561                             "always" => "Always dial prefix+areacode",
562                             "local" => "Local 7-digit dialing",
563                             "local10" => "Local 10-digit dialing");
564
565                     foreach ($rules as $value=>$display) {
566                         echo "<option value=\"".$value."\" ".(($value == $dialrulestype) ? "SELECTED" : "").">".$display."</option>";
567                     }
568 ?>
569                     </select>
570                     
571                 </td>
572             </tr>
573             <tr>
574                 <td>
575                     <a href=# class="info"><?php echo _("Local dialing pattern<span>The dialing pattern to make a 'local' call.</span>")</a>:
576                 </td><td>
577                     <input id="localpattern" type="text" size="10" maxlength="20" name="localpattern" value="<?php echo $localpattern ?>"/>
578                     
579                 </td>
580             </tr>
581             <tr>
582                 <td>
583                     <a href=# class="info"><?php echo _("Long-distance dial prefix<span>The prefix for dialing long-distance numbers. In north america, this should be \"1\".</span>")?></a>:
584                 </td><td>
585                     <input id="lddialprefix" type="text" size="3" maxlength="6" name="lddialprefix" value="<?php echo $lddialprefix ?>"/>
586                     
587                 </td>
588             </tr>
589             <tr>
590                 <td>
591                     <a href=# class="info"><?php echo _("Local LD prefix<span>The area code this trunk is in. Any 7-digit numbers that don't match a number in the below list will have dialprefix+areacode added to them. </span>")?></a>:
592                 </td><td>
593                     <input id="areacode" type="text" size="3" maxlength="6" name="areacode" value="<?php echo $areacode ?>"/>
594                     
595                 </td>
596             </tr>
597             <tr>
598                 <td valign="top">
599                     <a href=# class="info"><?php echo _("Local prefixes<span>This should be a list of local areacodes + prefixes to use for local dialing.</span>")?></a>:
600                 </td><td valign="top">&nbsp;
601                     <textarea id="localprefixes" cols="8" rows="<?php  $rows = count($localprefixes)+1; echo (($rows < 5) ? 5 : (($rows > 20) ? 20 : $rows) ); ?>" name="localprefixes"><?php echo  implode("\n",$localprefixes);?></textarea><br>
602                     
603                     <input id="npanxx" name="npanxx" type="hidden" /><br>
604                     <a href=# class="info"><?php echo _("Populate with local rules<span>Do a lookup from http://members.dandy.net/~czg/search.html to find all local-reachable area codes and phone numbers.</span>")?></a>: <input type="button" value="Go" onClick="checkPopulate();" />
605                     <br><br>
606                 </td>
607             </tr>
608             <script language="javascript">
609             
610             function checkPopulate() {
611                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
612                 var npanxx = <?php echo 'prompt("'._("What is your areacode + prefix (NPA-NXX)?").'")'?>;
613                 
614                 if (npanxx.match("^[2-9][0-9][0-9][-]?[2-9][0-9][0-9]$")) {
615                     document.getElementById('npanxx').value = npanxx;
616                     trunkEdit.action.value = "populatenpanxx";
617                     trunkEdit.submit();
618                 } else if (npanxx != null) {
619                     <?php echo 'alert("'._("Invalid format for NPA-NXX code (must be format: NXXNXX)").'")'?>;
620                 }
621             }
622             
623             function changeRulesType() {
624                 switch(document.getElementById('dialrulestype').value) {
625                     case "always":
626                         document.getElementById('lddialprefix').disabled = false;
627                         document.getElementById('areacode').disabled = false;
628                         document.getElementById('localprefixes').disabled = true;
629                     break;
630                     case "local":
631                     case "local10":
632                         document.getElementById('lddialprefix').disabled = false;
633                         document.getElementById('areacode').disabled = false;
634                         document.getElementById('localprefixes').disabled = false;
635                     break;
636                     case "asis":
637                     default:
638                         document.getElementById('lddialprefix').disabled = true;
639                         document.getElementById('areacode').disabled = true;
640                         document.getElementById('localprefixes').disabled = true;
641                     break;
642                 }
643             }
644             changeRulesType();
645             </script>
646 */?>
647             <tr>
648                 <td>
649                     <a href=# class="info"><?php echo _("Outbound Dial Prefix")?><span><?php echo _("The outbound dialing prefix is used to prefix a dialing string to all outbound calls placed on this trunk. For example, if this trunk is behind another PBX or is a Centrex line, then you would put 9 here to access an outbound line. Another common use is to prefix calls with 'w' on a POTS line that need time to obtain dial tone to avoid eating digits.<br><br>Most users should leave this option blank.")?></span></a>:
650                 </td><td>
651                     <input type="text" size="8" name="dialoutprefix" value="<?php echo htmlspecialchars($dialoutprefix) ?>" tabindex="<?php echo ++$tabindex;?>"/>
652                 </td>
653             </tr>
654             <?php if ($tech != "enum") { ?>
655             <tr>
656                 <td colspan="2">
657                     <h4><?php echo _("Outgoing Settings")?></h4>
658                 </td>
659             </tr>
660             <?php } ?>
661
662     <?php
663     switch ($tech) {
664         case "zap":
665     ?>
666                 <tr>
667                     <td>
668                         <a href=# class="info"><?php echo _("Zap Identifier (trunk name)")?><span><br><?php echo _("ZAP channels are referenced either by a group number or channel number (which is defined in zapata.conf).  <br><br>The default setting is <b>g0</b> (group zero).")?><br><br></span></a>:
669                     </td><td>
670                         <input type="text" size="8" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
671                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
672                     </td>
673                 </tr>
674     <?php
675         break;
676         case "enum":
677         break;
678         case "custom":
679     ?>
680                 <tr>
681                     <td>
682                         <a href=# class="info"><?php echo _("Custom Dial String")?><span><?php echo _("Define the custom Dial String.  Include the token")?> $OUTNUM$ <?php echo _("wherever the number to dial should go.<br><br><b>examples:</b><br>")?>CAPI/XXXXXXXX/$OUTNUM$<br>H323/$OUTNUM$@XX.XX.XX.XX<br>OH323/$OUTNUM$@XX.XX.XX.XX:XXXX<br>vpb/1-1/$OUTNUM$</span></a>:
683                     </td><td>
684                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
685                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
686                     </td>
687                 </tr>   
688     <?php
689         break;
690         case "dundi":
691     ?>
692                 <tr>
693                     <td>
694                         <a href=# class="info"><?php echo _("DUNDi Mapping")?><span><?php echo _("This is the name of the DUNDi mapping as defined in the [mappings] section of remote dundi.conf peers. This corresponds to the 'include' section of the peer details in the local dundi.conf file. This requires manual configuration of DUNDi to use this trunk.")?></span></a>:
695                     </td><td>
696                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
697                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
698                     </td>
699                 </tr>   
700     <?php
701         break;
702         default:
703     ?>
704                 <tr>
705                     <td>
706                         <a href=# class="info"><?php echo _("Trunk Name")?><span><br><?php echo _("Give this trunk a unique name.  Example: myiaxtel")?><br><br></span></a>:
707                     </td><td>
708                         <input type="text" size="14" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
709                     </td>
710                 </tr>
711                 <tr>
712                     <td colspan="2">
713                     <a href=# class="info"><?php echo _("PEER Details")?><span><br><?php echo _("Modify the default PEER connection parameters for your VoIP provider.<br><br>You may need to add to the default lines listed below, depending on your provider.<br /><br />WARNING: Order is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny comes first.")?><br><br></span></a>:
714                     </td>
715                 </tr>
716                 <tr>
717                     <td colspan="2">
718                         <textarea rows="10" cols="40" name="peerdetails" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($peerdetails) ?></textarea>
719                     </td>
720                 </tr>
721                 <tr>
722                     <td colspan="2">
723                         <h4><?php echo _("Incoming Settings")?></h4>
724                     </td>
725                 </tr>
726                 <tr>
727                     <td>
728                         <a href=# class="info"><?php echo _("USER Context")?><span><br><?php echo _("This is most often the account name or number your provider expects.<br><br>This USER Context will be used to define the below user details.")?></span></a>:
729                     </td><td>
730                         <input type="text" size="14" name="usercontext" value="<?php echo htmlspecialchars($usercontext?>" tabindex="<?php echo ++$tabindex;?>"/>
731                     </td>
732                 </tr>
733                 <tr>
734                     <td colspan="2">
735                     <a href=# class="info"><?php echo _("USER Details")?><span><br><?php echo _("Modify the default USER connection parameters for your VoIP provider.")?><br><br><?php echo _("You may need to add to the default lines listed below, depending on your provider..<br /><br />WARNING: Order is important as it will be retained. For example, if you use the \"allow/deny\" directives make sure deny
736                 comes first.")?><br><br></span></a>:
737                     </td>
738                 </tr>
739                 <tr>
740                     <td colspan="2">
741                         <textarea rows="10" cols="40" name="userconfig" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($userconfig); ?></textarea>
742                     </td>
743                 </tr>
744                 <tr>
745                     <td colspan="2">
746                         <h4><?php echo _("Registration")?></h4>
747                     </td>
748                 </tr>
749                 <tr>
750                     <td colspan="2">
751                         <a href=# class="info"><?php echo _("Register String")?><span><br><?php echo _("Most VoIP providers require your system to REGISTER with theirs. Enter the registration line here.<br><br>example:<br><br>username:password@switch.voipprovider.com.<br><br>Many providers will require you to provide a DID number, ex: username:password@switch.voipprovider.com/didnumber in order for any DID matching to work.")?><br><br></span></a>:
752                     </td>
753                 </tr>
754                 <tr>
755                     <td colspan="2">
756                         <input type="text" size="40" name="register" value="<?php echo htmlspecialchars($register) ?>" tabindex="<?php echo ++$tabindex;?>" />
757                     </td>
758                 </tr>
759     <?php
760         break;
761     }
762     ?>
763                
764             <tr>
765                 <td colspan="2">
766                     <h6><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>" tabindex="<?php echo ++$tabindex;?>"></h6>
767                 </td>
768             </tr>
769             </table>
770
771 <script language="javascript">
772 <!--
773
774 var theForm = document.trunkEdit;
775
776 theForm.outcid.focus();
777
778 function trunkEdit_onsubmit(act) {
779     var msgInvalidOutboundCID = "<?php echo _('Invalid Outbound Caller ID'); ?>";
780     var msgInvalidMaxChans = "<?php echo _('Invalid Maximum Channels'); ?>";
781     var msgInvalidDialRules = "<?php echo _('Invalid Dial Rules'); ?>";
782     var msgInvalidOutboundDialPrefix = "<?php echo _('Invalid Outbound Dial Prefix'); ?>";
783     var msgInvalidTrunkName = "<?php echo _('Invalid Trunk Name entered'); ?>";
784     var msgInvalidChannelName = "<?php echo _('Invalid Custom Dial String entered'); ?>";
785     var msgInvalidTrunkAndUserSame = "<?php echo _('Trunk Name and User Context cannot be set to the same value'); ?>";
786     var msgConfirmBlankContext = "<?php echo _('User Context was left blank and User Details will not be saved!'); ?>";
787     var msgNeverOverrideCIDValue = "<?php echo _('You must define an Outbound Caller ID when Choosing Never Override CallerID'); ?>";
788
789     defaultEmptyOK = true;
790
791     if (theForm.keepcid.checked && isEmpty($.trim(theForm.outcid.value)))
792         return warnInvalid(theForm.outcid, msgNeverOverrideCIDValue);
793
794     if (!isCallerID(theForm.outcid.value))
795         return warnInvalid(theForm.outcid, msgInvalidOutboundCID);
796    
797     if (!isInteger(theForm.maxchans.value))
798         return warnInvalid(theForm.maxchans, msgInvalidMaxChans);
799    
800     if (!isDialrule(theForm.dialrules.value))
801         return warnInvalid(theForm.dialrules, msgInvalidDialRules);
802    
803     if (!isDialIdentifierSpecial(theForm.dialoutprefix.value))
804         return warnInvalid(theForm.dialoutprefix, msgInvalidOutboundDialPrefix);
805    
806     <?php if ($tech != "enum" && $tech != "custom" && $tech != "dundi") { ?>
807     defaultEmptyOK = true;
808     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
809         return warnInvalid(theForm.channelid, msgInvalidTrunkName);
810    
811     if (theForm.channelid.value == theForm.usercontext.value)
812         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
813     <?php } else if ($tech == "custom" || $tech == "dundi") { ?>
814     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
815         return warnInvalid(theForm.channelid, msgInvalidChannelName);
816
817     if (theForm.channelid.value == theForm.usercontext.value)
818         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
819     <?php } ?>
820
821     <?php if ($tech == "sip" || substr($tech,0,3) == "iax") { ?>
822     if ((isEmpty(theForm.usercontext.value) || isWhitespace(theForm.usercontext.value)) &&
823         (!isEmpty(theForm.userconfig.value) && !isWhitespace(theForm.userconfig.value)) &&
824             (theForm.userconfig.value != "secret=***password***\ntype=user\ncontext=from-trunk")) {
825                 if (confirm(msgConfirmBlankContext) == false)
826                 return false;
827             }
828     <?php } ?>
829
830     theForm.action.value = act;
831     return true;
832 }
833
834 function isDialIdentifierSpecial(s) { // special chars allowed in dial prefix (e.g. fwdOUT)
835     var i;
836
837     if (isEmpty(s))
838        if (isDialIdentifierSpecial.arguments.length == 1) return defaultEmptyOK;
839        else return (isDialIdentifierSpecial.arguments[1] == true);
840
841     for (i = 0; i < s.length; i++)
842     {   
843         var c = s.charAt(i);
844
845         if ( !isDialDigitChar(c) && (c != "w") && (c != "W") && (c != "q") && (c != "Q") && (c != "+") ) return false;
846     }
847
848     return true;
849 }
850 //-->
851 </script>
852
853         </form>
854 <?php 
855 }
856 ?>
857
858
859
Note: See TracBrowser for help on using the browser.