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

Revision 12852, 55.0 kB (checked in by p_lindheimer, 2 years ago)

update for publish

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php /* $Id$ */
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17 //    Copyright (C) 2004 Greg MacLellan (greg@mtechsolutions.ca)
18 //    Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
19 //
20 if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
21
22 $display='trunks';
23 $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:'';
24 $trunknum = ltrim($extdisplay,'OUT_');
25
26 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
27 // Now check if the Copy Trunks submit button was pressed, in which case we duplicate the trunk
28 //
29 if (isset($_REQUEST['copytrunk'])) {
30   $action = 'copytrunk';
31 }
32
33 $tech         = strtolower(isset($_REQUEST['tech'])?htmlentities($_REQUEST['tech']):'');
34 $outcid       = isset($_REQUEST['outcid'])?$_REQUEST['outcid']:'';
35 $maxchans     = isset($_REQUEST['maxchans'])?$_REQUEST['maxchans']:'';
36 $dialoutprefix= isset($_REQUEST['dialoutprefix'])?$_REQUEST['dialoutprefix']:'';
37 $channelid    = isset($_REQUEST['channelid'])?$_REQUEST['channelid']:'';
38 $peerdetails  = isset($_REQUEST['peerdetails'])?$_REQUEST['peerdetails']:'';
39 $usercontext  = isset($_REQUEST['usercontext'])?$_REQUEST['usercontext']:'';
40 $userconfig   = isset($_REQUEST['userconfig'])?$_REQUEST['userconfig']:'';
41 $register     = isset($_REQUEST['register'])?$_REQUEST['register']:'';
42 $keepcid      = isset($_REQUEST['keepcid'])?$_REQUEST['keepcid']:'off';
43 $disabletrunk = isset($_REQUEST['disabletrunk'])?$_REQUEST['disabletrunk']:'off';
44 $provider     = isset($_REQUEST['provider'])?$_REQUEST['provider']:'';
45 $trunk_name   = isset($_REQUEST['trunk_name'])?$_REQUEST['trunk_name']:'';
46
47 $failtrunk    = isset($_REQUEST['failtrunk'])?$_REQUEST['failtrunk']:'';
48 $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
49
50 // Check if they uploaded a CSV file for their route patterns
51 //
52 if (isset($_FILES['pattern_file']) && $_FILES['pattern_file']['tmp_name'] != '') {
53   $fh = fopen($_FILES['pattern_file']['tmp_name'], 'r');
54   if ($fh !== false) {
55     $csv_file = array();
56     $index = array();
57
58     // Check first row, ingoring empty rows and get indices setup
59     //
60     while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) {
61       if (count($row) == 1 && $row[0] == '') {
62         continue;
63       } else {
64         $count = count($row) > 3 ? 3 : count($row);
65         for ($i=0;$i<$count;$i++) {
66           switch (strtolower($row[$i])) {
67           case 'prepend':
68           case 'prefix':
69           case 'match pattern':
70             $index[strtolower($row[$i])] = $i;
71           break;
72           default:
73           break;
74           }
75         }
76         // If no headers then assume standard order
77         if (count($index) == 0) {
78           $index['prepend'] = 0;
79           $index['prefix'] = 1;
80           $index['match pattern'] = 2;
81           if ($count == 3) {
82             $csv_file[] = $row;
83           }
84         }
85         break;
86       }
87     }
88     $row_count = count($index);
89     while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) {
90       if (count($row) == $row_count) {
91         $csv_file[] = $row;
92       }
93     }
94   }
95 }
96
97 //
98 // Use a hash of the value inserted to get rid of duplicates
99 $dialpattern_insert = array();
100 $p_idx = 0;
101 $n_idx = 0;
102
103 // If we have a CSV file it replaces any existing patterns
104 //
105 if (!empty($csv_file)) {
106   foreach ($csv_file as $row) {
107     $this_prepend = isset($index['prepend']) ? htmlspecialchars(trim($row[$index['prepend']])) : '';
108     $this_prefix = isset($index['prefix']) ? htmlspecialchars(trim($row[$index['prefix']])) : '';
109     $this_match_pattern = isset($index['match pattern']) ? htmlspecialchars(trim($row[$index['match pattern']])) : '';
110
111     if ($this_prepend != '' || $this_prefix  != '' || $this_match_pattern != '') {
112       $dialpattern_insert[] = array(
113         'prepend_digits' => $this_prepend,
114         'match_pattern_prefix' => $this_prefix,
115         'match_pattern_pass' => $this_match_pattern,
116       );
117     }
118   }
119 } else if (isset($_POST["prepend_digit"])) {
120   $prepend_digit = $_POST["prepend_digit"];
121   $pattern_prefix = $_POST["pattern_prefix"];
122   $pattern_pass = $_POST["pattern_pass"];
123
124   foreach (array_keys($prepend_digit) as $key) {
125     if ($prepend_digit[$key]!='' || $pattern_prefix[$key]!='' || $pattern_pass[$key]!='') {
126
127       $dialpattern_insert[] = array(
128         'prepend_digits' => htmlspecialchars(trim($prepend_digit[$key])),
129         'match_pattern_prefix' => htmlspecialchars(trim($pattern_prefix[$key])),
130         'match_pattern_pass' => htmlspecialchars(trim($pattern_pass[$key])),
131       );
132     }
133   }
134 }
135
136
137 // TODO: remember old name, if new one is different the don't rename
138 //
139 //if submitting form, update database
140 switch ($action) {
141   case "copytrunk":
142
143     $sv_channelid    = isset($_REQUEST['sv_channelid'])?$_REQUEST['sv_channelid']:'';
144     $sv_trunk_name    = isset($_REQUEST['sv_trunk_name'])?$_REQUEST['sv_trunk_name']:'';
145     $sv_usercontext    = isset($_REQUEST['sv_usercontext'])?$_REQUEST['sv_usercontext']:'';
146
147     if ($trunk_name == $sv_trunk_name) {
148       $trunk_name .= ($trunk_name == '' ? '' : '_') . "copy_$trunknum";
149     }
150     if ($channelid == $sv_channelid) {
151       $channelid .= '_copy_' . $trunknum;
152     }
153     if ($usercontext != '' && $usercontext == $sv_usercontext) {
154       $usercontext .= '_copy_' . $trunknum;
155     }
156     $disabletrunk = 'on';
157     $trunknum = '';
158     $extdisplay='';
159   // Fallthrough to addtrunk now...
160   //
161     case "addtrunk":
162         $trunknum = core_trunks_add($tech, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider);
163         
164     core_trunks_update_dialrules($trunknum, $dialpattern_insert);
165         needreload();
166         redirect_standard();
167     break;
168     case "edittrunk":
169         core_trunks_edit($trunknum, $channelid, $dialoutprefix, $maxchans, $outcid, $peerdetails, $usercontext, $userconfig, $register, $keepcid, trim($failtrunk), $disabletrunk, $trunk_name, $provider);
170         
171         // this can rewrite too, so edit is the same
172     core_trunks_update_dialrules($trunknum, $dialpattern_insert, true);
173         needreload();
174         redirect_standard('extdisplay');
175     break;
176     case "deltrunk":
177     
178         core_trunks_del($trunknum);
179     core_trunks_delete_dialrules($trunknum);
180     core_routing_trunk_delbyid($trunknum);
181         needreload();
182         redirect_standard();
183     break;
184     case "populatenpanxx7":
185     case "populatenpanxx10":
186     $dialpattern_array = $dialpattern_insert;
187         if (preg_match("/^([2-9]\d\d)-?([2-9]\d\d)$/", $_REQUEST["npanxx"], $matches)) {
188             // first thing we do is grab the exch:
189             $ch = curl_init();
190             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
191             curl_setopt($ch, CURLOPT_URL, "http://www.localcallingguide.com/xmllocalprefix.php?npa=".$matches[1]."&nxx=".$matches[2]);
192             curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; FreePBX Local Trunks Configuration)");
193             $str = curl_exec($ch);
194             curl_close($ch);
195
196             // quick 'n dirty - nabbed from PEAR
197             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Parser.php');
198             require_once($amp_conf['AMPWEBROOT'] . '/admin/modules/core/XML_Unserializer.php');
199
200             $xml = new xml_unserializer;
201             $xml->unserialize($str);
202             $xmldata = $xml->getUnserializedData();
203
204             if (isset($xmldata['lca-data']['prefix'])) {
205         $hash_filter = array(); //avoid duplicates
206                 if ($action == 'populatenpanxx10') {
207                     // 10 digit dialing
208                     // - add area code to 7 digits
209                     // - match local 10 digits
210                     // - add 1 to anything else
211           $dialpattern_array[] = array(
212             'prepend_digits' => '',
213             'match_pattern_prefix' => '',
214             'match_pattern_pass' => htmlspecialchars($matches[1].'NXXXXXX'),
215           );
216                     // add NPA to 7-digits
217                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
218             if (isset($hash_filter[$prefix['npa'].'+'.$prefix['nxx']])) {
219               continue;
220             } else {
221               $hash_filter[$prefix['npa'].'+'.$prefix['nxx']] = true;
222             }
223             $dialpattern_array[] = array(
224               'prepend_digits' =>  htmlspecialchars($prefix['npa']),
225               'match_pattern_prefix' => '',
226               'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
227             );
228                     }
229                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
230             if (isset($hash_filter[$prefix['npa'].$prefix['nxx']])) {
231               continue;
232             } else {
233               $hash_filter[$prefix['npa'].$prefix['nxx']] = true;
234             }
235             $dialpattern_array[] = array(
236               'prepend_digits' =>  '',
237               'match_pattern_prefix' => '',
238               'match_pattern_pass' => htmlspecialchars($prefix['npa'].$prefix['nxx'].'XXXX'),
239             );
240                     }
241                     // if a number was not matched as local, dial it with '1' prefix
242           $dialpattern_array[] = array(
243             'prepend_digits' =>  '',
244             'match_pattern_prefix' => '',
245             'match_pattern_pass' => '1+NXXNXXXXXX',
246           );
247                 } else {
248                     // 7 digit dialing
249                     // - drop area code from local numbers
250                     // - match local 7 digit numbers
251                     // - add 1 to everything else
252                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
253             if (isset($hash_filter[$prefix['npa'].'|'.$prefix['nxx']])) {
254               continue;
255             } else {
256               $hash_filter[$prefix['npa'].'|'.$prefix['nxx']] = true;
257             }
258             $dialpattern_array[] = array(
259               'prepend_digits' =>  '',
260               'match_pattern_prefix' => htmlspecialchars( $prefix['npa']),
261               'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
262             );
263                     }
264                     foreach ($xmldata['lca-data']['prefix'] as $prefix) {
265             if (isset($hash_filter[$prefix['nxx']])) {
266               continue;
267             } else {
268               $hash_filter[$prefix['nxx']] = true;
269             }
270             $dialpattern_array[] = array(
271               'prepend_digits' =>  '',
272               'match_pattern_prefix' => '',
273               'match_pattern_pass' => htmlspecialchars($prefix['nxx'].'XXXX'),
274             );
275                     }
276           $dialpattern_array[] = array(
277             'prepend_digits' =>  '1',
278             'match_pattern_prefix' => '',
279             'match_pattern_pass' => 'NXXNXXXXXX',
280           );
281           $dialpattern_array[] = array(
282             'prepend_digits' => htmlspecialchars('1'.$matches[1]),
283             'match_pattern_prefix' => '',
284             'match_pattern_pass' => 'NXXXXXX',
285           );
286                 }
287
288                 // check for duplicates, and re-sequence
289         unset($hash_filter);
290             } else {
291                 $errormsg = _("Error fetching prefix list for: "). $_REQUEST["npanxx"];
292             }
293
294         } else {
295             // what a horrible error message... :p
296             $errormsg = _("Invalid format for NPA-NXX code (must be format: NXXNXX)");
297         }
298         
299         if (isset($errormsg)) {
300             echo "<script language=\"javascript\">alert('".addslashes($errormsg)."');</script>";
301             unset($errormsg);
302         }
303     break;
304 }
305     
306 ?>
307
308 <div class="rnav">
309 <ul>
310     <li><a <?php  echo ($extdisplay=='' ? 'class="current"':'') ?> href="config.php?display=<?php echo urlencode($display)?>"><?php echo _("Add Trunk")?></a></li>
311 <?php
312 //get existing trunk info
313 $tresults = core_trunks_getDetails();
314 //$tresults = core_trunks_list();
315
316 foreach ($tresults as $tresult) {
317     $background = ($tresult['disabled'] == 'on')?'#DDD':'';
318     switch ($tresult['tech']) {
319         case 'enum':
320             $label = substr($tresult['name'],0,15)." ENUM";
321             break;
322         case 'dundi':
323             $label = substr($tresult['name'],0,15)." (DUNDi)";
324             break;
325         case 'iax2':
326             $tresult['tech'] = 'iax';
327         case 'zap':
328         case 'dahdi':
329             $label = substr($tresult['name'],0,15);
330       if (trim($label) == '') {
331         $label = sprintf(_('Channel %s'),substr($tresult['channelid'],0,15));
332       }
333             $label .= " (".$tresult['tech'].")";
334             break;
335         case 'sip':
336         case 'iax':
337         case 'custom':
338         default:
339             $label = substr($tresult['name'],0,15);
340       if (trim($label) == '') {
341         $label = substr($tresult['channelid'],0,15);
342       }
343             $label .= " (".$tresult['tech'].")";
344             break;
345     }
346     echo "\t<li><a ".($trunknum==$tresult['trunkid'] ? 'class="current"':'')." href=\"config.php?display=".urlencode($display)."&amp;extdisplay=OUT_".urlencode($tresult['trunkid'])."\" title=\"".urlencode($tresult['name'])."\" style=\"background: $background;\" >".$label."</a></li>\n";
347 }
348
349 ?>
350 </ul>
351 </div>
352
353
354 <?php
355 if (!$tech && !$extdisplay) {
356 ?>
357     <h2><?php echo _("Add a Trunk")?></h2>
358 <?php
359     $baseURL   = $_SERVER['PHP_SELF'].'?display='.urlencode($display).'&';
360   $trunks[] = array('url'=> $baseURL.'tech=SIP', 'tlabel' =>  _("Add SIP Trunk"));
361   if (ast_with_dahdi()) {
362     $trunks[] = array('url'=> $baseURL.'tech=DAHDI', 'tlabel' =>  _("Add DAHDi Trunk"));
363   }
364   $trunks[] = array('url'=> $baseURL.'tech=ZAP', 'tlabel' =>  _("Add Zap Trunk").(ast_with_dahdi()?" ("._("DAHDi compatibility mode").")":"" ));
365   $trunks[] = array('url'=> $baseURL.'tech=IAX2', 'tlabel' =>  _("Add IAX2 Trunk"));
366   //--------------------------------------------------------------------------------------
367   // Added to enable the unsupported misdn module
368   if (function_exists('misdn_ports_list_trunks') && count(misdn_ports_list_trunks())) {
369     $trunks[] = array('url'=> $baseURL.'tech=MISDN', 'tlabel' =>  _("Add mISDN Trunk"));
370   }
371   //--------------------------------------------------------------------------------------
372   $trunks[] = array('url'=> $baseURL.'tech=ENUM', 'tlabel' =>  _("Add ENUM Trunk"));
373   $trunks[] = array('url'=> $baseURL.'tech=DUNDI', 'tlabel' =>  _("Add DUNDi Trunk"));
374   $trunks[] = array('url'=> $baseURL.'tech=CUSTOM', 'tlabel' =>  _("Add Custom Trunk"));
375     foreach ($trunks as $trunk) {
376         $label = '<span><img width="16" height="16" border="0" title="'.$trunk['tlabel'].'" alt="" src="images/core_add.png"/>&nbsp;'.$trunk['tlabel'].'</span>';
377         echo "<a href=".$trunk['url'].">".$label."</a><br /><br />";
378     }
379 } else {
380     if ($extdisplay) {
381
382         $trunk_details = core_trunks_getDetails($trunknum);
383
384         $tech = htmlentities($trunk_details['tech']);
385         $outcid = htmlentities($trunk_details['outcid']);
386         $maxchans = htmlentities($trunk_details['maxchans']);
387         $dialoutprefix = htmlentities($trunk_details['dialoutprefix']);
388         $keepcid = htmlentities($trunk_details['keepcid']);
389         $failtrunk = htmlentities($trunk_details['failscript']);
390         $failtrunk_enable = ($failtrunk == "")?'':'CHECKED';
391         $disabletrunk = htmlentities($trunk_details['disabled']);
392         $provider = $trunk_details['provider'];
393         $trunk_name = htmlentities($trunk_details['name']);
394
395         if ($tech!="enum") {
396     
397             $channelid = htmlentities($trunk_details['channelid']);
398
399             if ($tech!="custom" && $tech!="dundi") {  // custom trunks will not have user/peer details in database table
400                 // load from db
401                 if (empty($peerdetails)) {   
402                     $peerdetails = core_trunks_getTrunkPeerDetails($trunknum);
403                 }
404                 if (empty($usercontext)) {   
405                     $usercontext = htmlentities($trunk_details['usercontext']);
406                 }
407     
408                 if (empty($userconfig)) {   
409                     $userconfig = core_trunks_getTrunkUserConfig($trunknum);
410                 }
411                     
412                 if (empty($register)) {   
413                     $register = core_trunks_getTrunkRegister($trunknum);
414                 }
415             }
416         }
417     if (count($dialpattern_array) == 0) {
418       $dialpattern_array = core_trunks_get_dialrules($trunknum);
419     }
420         $upper_tech = strtoupper($tech);
421     if (trim($trunk_name) == '') {
422           $trunk_name = ($upper_tech == 'ZAP'|$upper_tech == 'DAHDI'?sprintf(_('%s Channel %s'),$upper_tech,$channelid):$channelid);
423     }
424         echo "<h2>".sprintf(_("Edit %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDi compatibility Mode").")":"")."</h2>";
425         $tlabel = sprintf(_("Delete Trunk %s"),substr($trunk_name,0,20));
426         $label = '<span><img width="16" height="16" border="0" title="'.$tlabel.'" alt="" src="images/core_delete.png"/>&nbsp;'.$tlabel.'</span>';
427 ?>
428         <p><a href="config.php?display=<?php echo urlencode($display) ?>&extdisplay=<?php echo urlencode($extdisplay) ?>&action=deltrunk"><?php echo $label ?></a></p>
429 <?php
430
431         // find which routes use this trunk
432         $routes = core_trunks_gettrunkroutes($trunknum);
433         $num_routes = count($routes);
434         if ($num_routes > 0) {
435             echo "<a href=# class=\"info\">&nbsp;"._("In use by")." ".$num_routes." ".($num_routes == 1 ? _("route") : _("routes"))."<span>";
436             foreach($routes as $route=>$priority) {
437                 echo _("Route")." <b>".$route."</b>: "._("Sequence")." <b>".$priority."</b><br>";
438             }
439             echo "</span></a>";
440         } else {
441             echo "&nbsp;<b>"._("WARNING:")."</b> <a href=# class=\"info\">"._("This trunk is not used by any routes!")."<span>";
442             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.");
443             echo "</span></a>";
444         }
445         $usage_list = framework_display_destination_usage(core_getdest(ltrim($extdisplay,'OUT_')));
446         if (!empty($usage_list)) {
447         ?>
448             <a href="#" class="info"><?php echo $usage_list['text']?><span><?php echo $usage_list['tooltip']?></span></a>
449         <?php
450         }
451
452
453     } else {
454         // set defaults
455         $outcid = "";
456         $maxchans = "";
457         $dialoutprefix = "";
458         
459         if ($tech == 'zap' || $tech == 'dahdi') {
460             $channelid = 'g0';
461         } else {
462             $channelid = '';
463         }
464         
465         // only for iax2/sip
466         $peerdetails = "host=***provider ip address***\nusername=***userid***\nsecret=***password***\ntype=peer";
467         $usercontext = "";
468         $userconfig = "secret=***password***\ntype=user\ncontext=from-trunk";
469         $register = "";
470         
471         $localpattern = "NXXXXXX";
472         $lddialprefix = "1";
473         $areacode = "";
474     
475         $upper_tech = strtoupper($tech);
476         echo "<h2>".sprintf(_("Add %s Trunk"),$upper_tech).($upper_tech == 'ZAP' && ast_with_dahdi()?" ("._("DAHDi compatibility mode").")":"")."</h2>";
477     }
478   if (!isset($dialpattern_array)) {
479     $dialpattern_array = array();
480   }
481         
482 switch ($tech) {
483     case 'dundi':
484         $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},nopartial<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.');
485         break;
486     case 'sip':
487         break;
488     default:
489         $helptext = '';
490 }
491 if ($helptext != '') {
492     if ($extdisplay) {
493         echo "<br /><br />";
494     }
495     echo $helptext;
496 }
497         
498 ?>
499    
500         <form enctype="multipart/form-data" name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');">
501             <input type="hidden" name="display" value="<?php echo $display?>"/>
502             <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/>
503             <input type="hidden" name="action" value=""/>
504             <input type="hidden" name="tech" value="<?php echo $tech?>"/>
505             <input type="hidden" name="provider" value="<?php echo $provider?>"/>
506             <input type="hidden" name="sv_trunk_name" value="<?php echo $trunkname?>"/>
507             <input type="hidden" name="sv_usercontext" value="<?php echo $usercontext?>"/>
508             <input type="hidden" name="sv_channelid" value="<?php echo $channelid?>"/>
509             <input id="npanxx" name="npanxx" type="hidden" />
510             <table>
511             <tr>
512                 <td colspan="2">
513                     <h4><?php echo _("General Settings")?><hr></h4>
514                 </td>
515             </tr>
516             <tr>
517                 <td>
518                     <a href=# class="info"><?php echo _("Trunk Name")?><span><?php echo _("Descriptive Name for this Trunk")?></span></a>:
519                 </td><td>
520                     <input type="text" size="30" name="trunk_name" value="<?php echo $trunk_name;?>" tabindex="<?php echo ++$tabindex;?>"/>
521                 </td>
522             </tr>
523             <tr>
524                 <td>
525                     <a href=# class="info"><?php echo _("Outbound CallerID")?><span><?php echo _("CallerID for calls placed out on this trunk<br><br>Format: <b>&lt;#######&gt;</b>. You can also use the format: \"hidden\" <b>&lt;#######&gt;</b> to hide the CallerID sent out over Digital lines if supported (E1/T1/J1/BRI/SIP/IAX).")?></span></a>:
526                 </td><td>
527                     <input type="text" size="30" name="outcid" value="<?php echo $outcid;?>" tabindex="<?php echo ++$tabindex;?>"/>
528                 </td>
529             </tr>
530             <tr>
531
532         <tr>
533                 <td>
534                     <a href="#" class="info"><?php echo _("CID Options")?><span><?php echo _("Determines what CIDs will be allowed out this trunk. IMPORTANT: EMERGENCY CIDs defined on an extension/device will ALWAYS be used if this trunk is part of an EMERGENCY Route regardless of these settings.<br />Allow Any CID: all CIDs including foreign CIDS from forwarded external calls will be transmitted.<br />Block Foreign CIDs: blocks any CID that is the result of a forwarded call from off the system. CIDs defined for extensions/users are transmitted.<br />Remove CNAM: this will remove CNAM from any CID sent out this trunk<br />Force Trunk CID: Always use the CID defined for this trunk except if part of any EMERGENCY Route with an EMERGENCY CID defined for the extension/device.");?></span></a>:
535                 </td><td>
536
537                 <select name="keepcid" tabindex="<?php echo ++$tabindex;?>">
538                 <?php
539                     $default = (isset($keepcid) ? $keepcid : 'off');
540                     echo '<option value="off"' . ($default == 'off'  ? ' SELECTED' : '').'>'._("Allow Any CID")."\n";
541                     echo '<option value="on"'  . ($default == 'on'   ? ' SELECTED' : '').'>'._("Block Foreign CIDs")."\n";
542                     echo '<option value="cnum"'. ($default == 'cnum' ? ' SELECTED' : '').'>'._("Remove CNAM")."\n";
543                     echo '<option value="all"' . ($default == 'all'  ? ' SELECTED' : '').'>'._("Force Trunk CID")."\n";
544                 ?>
545                 </select>
546                 </td>
547       </tr>
548
549             <tr>
550                 <td>
551 <?php
552     if ($tech == "sip" || substr($tech,0,3) == "iax") {
553         $pr_tech = ($tech == "iax") ? "iax2":$tech;
554 ?>
555                     <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>:
556 <?php
557     } else {
558 ?>
559                     <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>:
560 <?php
561     }
562 ?>
563                 </td><td>
564                     <input type="text" size="3" name="maxchans" value="<?php echo htmlspecialchars($maxchans); ?>" tabindex="<?php echo ++$tabindex;?>"/>
565                 </td>
566             </tr>
567
568             <tr>
569                 <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>:
570                 </td>
571                 <td>
572                 <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>
573                 </td>
574             </tr>
575             <tr>
576                 <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>:
577                 </td>
578                 <td>
579                 <input <?php if (!$failtrunk_enable) echo "disabled style='background: #DDD;'"?> type="text" size="20" name="failtrunk" value="<?php echo htmlspecialchars($failtrunk)?>"/>
580                 <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>
581                 </td>
582             </tr>
583
584     <tr>
585       <td colspan="2"><h4>
586       <a href=# class="info"><?php echo _("Dialed Number Manipulation Rules")?><span>
587       <?php echo _("These rules can manipulate the dialed number before sending it out this trunk. If no rule applies, the number is not changed. The original dialed number is passed down from the route where some manipulation may have already occurred. This trunk has the option to further manipulate the number. If the number matches the combined values in the <b>prefix</b> plus the <b>match pattern</b> boxes, the rule will be applied and all subsequent rules ignored.<br/> Upon a match, the <b>prefix</b>, if defined, will be stripped. Next the <b>prepend</b> will be inserted in front of the <b>match pattern</b> and the resulting number will be sent to the trunk. All fields are optional.")?><br /><br /><b><?php echo _("Rules:")?></b><br />
588       <b>X</b>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 0-9")?><br />
589       <b>Z</b>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 1-9")?><br />
590       <b>N</b>&nbsp;&nbsp;&nbsp; <?php echo _("matches any digit from 2-9")?><br />
591       <b>[1237-9]</b>&nbsp;   <?php echo _("matches any digit in the brackets (example: 1,2,3,7,8,9)")?><br />
592       <b>.</b>&nbsp;&nbsp;&nbsp; <?php echo _("wildcard, matches one or more dialed digits")?> <br />
593       <b><?php echo _("prepend:")?></b>&nbsp;&nbsp;&nbsp; <?php echo _("Digits to prepend upon a successful match. If the dialed number matches the patterns in the <b>prefix</b> and <b>match pattern</b> boxes, this will be prepended before sending to the trunk.")?><br />
594       <b><?php echo _("prefix:")?></b>&nbsp;&nbsp;&nbsp; <?php echo _("Prefix to remove upon a successful match. If the dialed number matches this plus the <b>match pattern</b> box, this prefix is removed before adding the optional <b>prepend</b> box and sending the results to the trunk.")?><br />
595       <b><?php echo _("match pattern:")?></b>&nbsp;&nbsp;&nbsp; <?php echo _("The dialed number will be compared against the <b>prefix</b> plus this pattern. Upon a match, this portion of the number will be sent to the trunks after removing the <b>prefix</b> and appending the <b>prepend</b> digits")?><br />
596         <?php echo _("You can completely replace a number by matching on the <b>prefix</b> only, replacing it with a <b>prepend</b> and leaving the <b>match pattern</b> blank."); ?>
597       </span></a>
598       <hr></h4></td>
599     </tr>
600
601     <tr><td colspan="2"><div class="dialpatterns"><table>
602 <?php
603   $pp_tit = _("prepend");
604   $pf_tit = _("prefix");
605   $mp_tit = _("match pattern");
606   $dpt_title_class = 'dpt-title dpt-display';
607   foreach ($dialpattern_array as $idx => $pattern) {
608     $tabindex++;
609     if ($idx == 50) {
610       $dpt_title_class = 'dpt-title dpt-nodisplay';
611     }
612     $dpt_class = $pattern['prepend_digits'] == '' ? $dpt_title_class : 'dpt-value';
613     echo <<< END
614     <tr>
615       <td colspan="2">
616         (<input title="$pp_tit" type="text" size="10" id="prepend_digit_$idx" name="prepend_digit[$idx]" class="dial-pattern dp-prepend $dpt_class" value="{$pattern['prepend_digits']}" tabindex="$tabindex">) +
617 END;
618     $tabindex++;
619     $dpt_class = $pattern['match_pattern_prefix'] == '' ? $dpt_title_class : 'dpt-value';
620     echo <<< END
621         <input title="$pf_tit" type="text" size="6" id="pattern_prefix_$idx" name="pattern_prefix[$idx]" class="dp-prefix $dpt_class" value="{$pattern['match_pattern_prefix']}" tabindex="$tabindex"> |
622 END;
623     $tabindex++;
624     $dpt_class = $pattern['match_pattern_pass'] == '' ? $dpt_title_class : 'dpt-value';
625     echo <<< END
626         <input title="$mp_tit" type="text" size="16" id="pattern_pass_$idx" name="pattern_pass[$idx]" class="dp-match $dpt_class" value="{$pattern['match_pattern_pass']}" tabindex="$tabindex">
627 END;
628 ?>
629         <img src="images/core_add.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("insert")?>" title="<?php echo _('Click here to insert a new pattern')?>" onclick="addCustomField('','','',$('#prepend_digit_<?php echo $idx?>').parent().parent())">
630         <img src="images/trash.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("remove")?>" title="<?php echo _('Click here to remove this pattern')?>" onclick="patternsRemove(<?php echo "$idx" ?>)">
631       </td>
632     </tr>
633 <?php
634   }
635   $next_idx = count($dialpattern_array);
636 ?>
637     <tr>
638       <td colspan="2">
639         (<input title="<?php echo $pp_tit?>" type="text" size="10" id="prepend_digit_<?php echo $next_idx?>" name="prepend_digit[<?php echo $next_idx?>]" class="dp-prepend dial-pattern dpt-title dpt-display" value="" tabindex="<?php echo ++$tabindex;?>">) +
640         <input title="<?php echo $pf_tit?>" type="text" size="6" id="pattern_prefix_<?php echo $next_idx?>" name="pattern_prefix[<?php echo $next_idx?>]" class="dp-prefix dpt-title dpt-display" value="" tabindex="<?php echo ++$tabindex;?>"> |
641         <input title="<?php echo $mp_tit?>" type="text" size="16" id="pattern_pass_<?php echo $next_idx?>" name="pattern_pass[<?php echo $next_idx?>]" class="dp-match dpt-title dpt-display" value="" tabindex="<?php echo ++$tabindex;?>">
642         <img src="images/core_add.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("insert")?>" title="<?php echo _('Click here to insert a new pattern')?>" onclick="addCustomField('','','',$('#prepend_digit_<?php echo $idx?>').parent().parent())">
643         <img src="images/trash.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("remove")?>" title="<?php echo _("Click here to remove this pattern")?>" onclick="patternsRemove(<?php echo "$next_idx" ?>)">
644
645       </td>
646     </tr>
647     <tr id="last_row"></tr>
648     </table></div></tr>
649 <?php
650   $tabindex += 2000; // make room for dynamic insertion of new fields
651 ?>
652     <tr><td colspan="2">
653       <input type="button" id="dial-pattern-add"  value="<?php echo _("+ Add More Dial Pattern Fields")?>" />
654       <input type="button" id="dial-pattern-clear"  value="<?php echo _("Clear all Fields")?>" />
655     </td></tr>
656             <tr>
657                 <td>
658                     <a href=# class="info"><?php echo _("Dial Rules Wizards")?><span>
659                     <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>
660                     <strong><?php echo _("Remove prefix from local numbers")?></strong> <?php echo _("is useful for ZAP and DAHDi trunks, where if a local number is dialed as \"6135551234\", it can be converted to \"555-1234\".")?><br>
661                     <strong><?php echo _("Setup directory assistance")?></strong> <?php echo _("is useful to translate a call to directory assistance")?><br>
662                     <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>
663                     <strong><?php echo _("Upload from CSV")?></strong> <?php echo sprintf(_("Upload patterns from a CSV file replacing existing entries. If there are no headers then the file must have 3 columns of patterns in the same order as in the GUI. You can also supply headers: %s, %s and %s in the first row. If there are less then 3 recognized headers then the remaining columns will be blank"),'<strong>prepend</strong>','<strong>prefix</strong>','<strong>match pattern</strong>')?><br>
664                     </span></a>:
665                 </td><td valign="top"><select id="autopop"  tabindex="<?php echo ++$tabindex;?>" name="autopop" onChange="changeAutoPop(); ">
666                         <option value="" SELECTED><?php echo _("(pick one)")?></option>
667                         <option value="always"><?php echo _("Always dial with prefix")?></option>
668                         <option value="remove"><?php echo _("Remove prefix from local numbers")?></option>
669                         <option value="directory"><?php echo _("Setup directory assistance")?></option>
670                         <option value="lookup7"><?php echo _("Lookup numbers for local trunk (7-digit dialing)")?></option>
671                         <option value="lookup10"><?php echo _("Lookup numbers for local trunk (10-digit dialing)")?></option>
672             <option value="csv"><?php echo _("Upload from CSV")?></option>
673                     </select>
674           <input type="file" name="pattern_file" id="pattern_file" tabindex="<?php echo ++$tabindex;?>"/>
675                 </td>
676             </tr>
677             <script language="javascript">
678            
679             function disable_field(field, field_enable) {
680                 if (field_enable.checked) {
681                 field.style.backgroundColor = '#FFF';
682                 field.disabled = false;
683                 }
684                 else {
685                 field.style.backgroundColor = '#DDD';
686                 field.disabled = true;
687                 }
688             }
689
690             function disable_verify(field) {
691                 if (field.checked) {
692                     var answer=confirm("<?php echo _("Are you sure you want to disable this trunk in all routes it is used?") ?>");
693                     if (!answer) {
694                         field.checked = false;
695                     }
696                 } else {
697                     alert("<?php echo _("You have enabled this trunk in all routes it is used") ?>");
698                 }
699             }
700
701             function populateLookup(digits) {
702 <?php
703     if (function_exists("curl_init")) { // curl is installed
704 ?>                
705                 //var npanxx = prompt("What is your areacode + prefix (NPA-NXX)?", document.getElementById('areacode').value);
706                 do {
707                     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.".'")')?>;
708                     if (npanxx == null) return;
709                 } 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\'").'")'?>);
710                
711                 document.getElementById('npanxx').value = npanxx;
712                 if (digits == 10) {
713                     document.trunkEdit.action.value = "populatenpanxx10";
714                 } else {
715                     document.trunkEdit.action.value = "populatenpanxx7";
716                 }
717         clearPatterns();
718                 document.trunkEdit.submit();
719 <?php 
720     } else { // curl is not installed
721 ?>
722                 <?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.").'")'?>;
723 <?php
724     }
725 ?>
726             }
727            
728             function populateAlwaysAdd() {
729                 do {
730           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)").'"'?>,"<?php echo _("NXXXXXX")?>");
731                     if (localpattern == null) return;
732                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
733                
734                 do {
735                     var localprefix = <?php echo 'prompt("'._("What prefix should be added to the dialing pattern?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')?").'")'?>;
736                     if (localprefix == null) return;
737                 } while (!localprefix.match('^[0-9#*]+$') && <?php echo '!alert("'._("Invalid prefix. Only dialable characters (0-9, #, and *) are allowed.").'")'?>);
738
739         return addCustomField(localprefix,'',localpattern,$("#last_row"));
740             }
741            
742             function populateRemove() {
743                 do {
744                     var localprefix = <?php echo 'prompt("'._("What prefix should be removed from the number?\\n\\n(ie. for US/CAN, 1+areacode, ie, \'1613\')").'")'?>;
745                     if (localprefix == null) return;
746                 } while (!localprefix.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._('Invalid prefix. Only 0-9, #, *, Z, N, and X are allowed.').'")'?>);
747                
748                 do {
749           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)").'"'?>,"<?php echo _("NXXXXXX")?>");
750                     if (localpattern == null) return;
751                 } while (!localpattern.match('^[0-9#*ZXN\.]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *, Z, N, X and . are allowed.").'")'?>);
752                
753         return addCustomField('',localprefix,localpattern,$("#last_row"));
754             }
755
756             function populatedirectory() {
757                 do {
758         var localprefix = <?php echo 'prompt("'._("What is the directory assistance number you will dial locally in the format that is passed to this trunk?").'"'?>,"<?php echo ""?>");
759                     if (localprefix == null) return;
760                 } while (!localprefix.match('^[0-9#*]+$') && <?php echo '!alert("'._("Invalid pattern. Only 0-9, #, *").'")'?>);
761                 do {
762
763         var localprepend = <?php echo 'prompt("'._("Number to dial when calling directory assistance on this trunk").'"'?>,"<?php echo '' ?>");
764                     if (localprepend == null) return;
765                 } while (!localprepend.match('^[0-9#*]+$') && <?php echo '!alert("'._('Invalid number. Only 0-9, #,  and * are allowed.').'")'?>);
766                
767         return addCustomField(localprepend,localprefix,'',$("#last_row"));
768             }
769            
770             function changeAutoPop() {
771         var idx = false;
772         // hide the file box if nothing was set
773         if ($('#pattern_file').val() == '') {
774           $('#pattern_file').hide();
775         }
776                 switch(document.getElementById('autopop').value) {
777                     case "always":
778                         idx = populateAlwaysAdd();
779             if (idx) {
780               $('#pattern_prefix_'+idx).focus();
781             }
782                     break;
783                     case "remove":
784                         idx = populateRemove();
785             if (idx) {
786               $('#prepend_digit_'+idx).focus();
787             }
788                     break;
789                     case "directory":
790                         idx = populatedirectory();
791             if (idx) {
792               $('#pattern_pass_'+idx).focus();
793             }
794                     break;
795                     case "lookup7":
796                         populateLookup(7);
797                     break;
798                     case "lookup10":
799                         populateLookup(10);
800                     break;
801                     case 'csv':
802             $('#pattern_file').show().click();
803             return true;
804                     break;
805                 }
806                 document.getElementById('autopop').value = '';
807             }
808             </script>
809
810             <tr>
811                 <td>
812                     <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>:
813                 </td><td>
814                     <input type="text" size="8" name="dialoutprefix" id="dialoutprefix" value="<?php echo htmlspecialchars($dialoutprefix) ?>" tabindex="<?php echo ++$tabindex;?>"/>
815                 </td>
816             </tr>
817             <?php if ($tech != "enum") { ?>
818             <tr>
819                 <td colspan="2">
820         <h4><?php echo _("Outgoing Settings")?><hr></h4>
821                 </td>
822             </tr>
823             <?php } ?>
824
825     <?php
826     switch ($tech) {
827         case "zap":
828     ?>
829                 <tr>
830                     <td>
831                         <a href=# class="info"><?php echo _("Zap Identifier")?><span><?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).")?></span></a>:
832                     </td><td>
833                         <input type="text" size="8" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
834                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
835                     </td>
836                 </tr>
837     <?php
838         break;
839         case "dahdi":
840     ?>
841                 <tr>
842                     <td>
843                         <a href=# class="info"><?php echo _("DAHDi Identifier")?><span><?php echo _("DAHDi channels are referenced either by a group number or channel number (which is defined in chan_dahdi.conf).  <br><br>The default setting is <b>g0</b> (group zero).")?></span></a>:
844                     </td><td>
845                         <input type="text" size="8" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
846                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
847                     </td>
848                 </tr>
849     <?php
850         break;
851         case "enum":
852         break;
853     //--------------------------------------------------------------------------------------
854     // Added to enable the unsupported misdn module
855         case "misdn":
856       if (function_exists('misdn_groups_ports')) {
857   ?>
858         <tr>
859           <td>
860             <a href=# class="info"><?php echo _("mISDN Group/Port")?><span><br><?php echo _("mISDN channels are referenced either by a group name or channel number (use <i>mISDN Port Groups</i> to configure).")?><br><br></span></a>: 
861           </td>
862           <td>
863             <select name="channelid">
864   <?php
865         $gps = misdn_groups_ports();
866         foreach($gps as $gp) {
867           echo "<option value='$gp'";
868           if ($gp == $channelid)
869             echo ' selected="1"';
870             echo ">$gp</option>\n";
871           }
872   ?>
873             </select>
874             <input type="hidden" size="14" name="usercontext" value="notneeded"/>
875           </td>
876         </tr>
877   <?php 
878       }
879     break;
880     //--------------------------------------------------------------------------------------
881         case "custom":
882     ?>
883                 <tr>
884                     <td>
885                         <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>:
886                     </td><td>
887                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
888                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
889                     </td>
890                 </tr>   
891     <?php
892         break;
893         case "dundi":
894     ?>
895                 <tr>
896                     <td>
897                         <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>:
898                     </td><td>
899                         <input type="text" size="35" maxlength="46" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
900                         <input type="hidden" size="14" name="usercontext" value="notneeded"/>
901                     </td>
902                 </tr>   
903     <?php
904         break;
905         default:
906     ?>
907                 <tr>
908                     <td>
909                         <a href=# class="info"><?php echo _("Trunk Name")?><span><?php echo _("Give this trunk a unique name.  Example: myiaxtel")?></span></a>:
910                     </td><td>
911                         <input type="text" size="14" name="channelid" value="<?php echo htmlspecialchars($channelid) ?>" tabindex="<?php echo ++$tabindex;?>"/>
912                     </td>
913                 </tr>
914                 <tr>
915                     <td colspan="2">
916                     <a href=# class="info"><?php echo _("PEER Details")?><span><?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.")?></span></a>:
917                     </td>
918                 </tr>
919                 <tr>
920                     <td colspan="2">
921                         <textarea rows="10" cols="40" name="peerdetails" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($peerdetails) ?></textarea>
922                     </td>
923                 </tr>
924                 <tr>
925                     <td colspan="2">
926                         <h4><?php echo _("Incoming Settings")?></h4>
927                     </td>
928                 </tr>
929                 <tr>
930                     <td>
931                         <a href=# class="info"><?php echo _("USER Context")?><span><?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>:
932                     </td><td>
933                         <input type="text" size="14" name="usercontext" value="<?php echo htmlspecialchars($usercontext?>" tabindex="<?php echo ++$tabindex;?>"/>
934                     </td>
935                 </tr>
936                 <tr>
937                     <td colspan="2">
938                     <a href=# class="info"><?php echo _("USER Details")?><span><?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
939                 comes first.")?></span></a>:
940                     </td>
941                 </tr>
942                 <tr>
943                     <td colspan="2">
944                         <textarea rows="10" cols="40" name="userconfig" tabindex="<?php echo ++$tabindex;?>"><?php echo htmlspecialchars($userconfig); ?></textarea>
945                     </td>
946                 </tr>
947                 <tr>
948                     <td colspan="2">
949                         <h4><?php echo _("Registration")?></h4>
950                     </td>
951                 </tr>
952                 <tr>
953                     <td colspan="2">
954                         <a href=# class="info"><?php echo _("Register String")?><span><?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.")?></span></a>:
955                     </td>
956                 </tr>
957                 <tr>
958                     <td colspan="2">
959                         <input type="text" size="40" name="register" value="<?php echo htmlspecialchars($register) ?>" tabindex="<?php echo ++$tabindex;?>" />
960                     </td>
961                 </tr>
962     <?php
963         break;
964     }
965   // implementation of module hook
966   // object was initialized in config.php
967   echo $module_hook->hookHtml;
968   ?>
969             <tr>
970                 <td colspan="2">
971           <h6>
972             <input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>" tabindex="<?php echo ++$tabindex;?>">
973             <input name="copytrunk" type="submit" value="<?php echo _("Duplicate Trunk");?>"/>
974             <!--input type="button" id="page_reload" value="<?php echo _("Refresh Page");?>"/-->
975           </h6>
976                 </td>
977             </tr>
978             </table>
979
980 <script language="javascript">
981 <!--
982
983 $(document).ready(function(){
984   /* Add a Custom Var / Val textbox */
985   $("#dial-pattern-add").click(function(){
986     addCustomField('','','',$("#last_row"));
987   });
988   $('#pattern_file').hide();
989   $("#dial-pattern-clear").click(function(){
990     clearAllPatterns();
991   });
992   $(".dpt-display").toggleVal({
993     populateFrom: "title",
994     changedClass: "text-normal",
995     focusClass: "text-normal"
996   });
997   $(".dpt-nodisplay").mouseover(function(){
998     $(this).toggleVal({
999       populateFrom: "title",
1000       changedClass: "text-normal",
1001       focusClass: "text-normal"
1002     }).removeClass('dpt-nodisplay').addClass('dpt-display').unbind('mouseover');
1003   });
1004 });
1005
1006 function patternsRemove(idx) {
1007   $("#prepend_digit_"+idx).parent().parent().remove();
1008 }
1009
1010 function addCustomField(prepend_digit, pattern_prefix, pattern_pass, start_loc) {
1011   var idx = $(".dial-pattern").size();
1012   var idxp = idx - 1;
1013   var tabindex = parseInt($("#pattern_pass_"+idxp).attr('tabindex')) + 1;
1014   var tabindex1 = tabindex + 2;
1015   var tabindex2 = tabindex + 3;
1016   var dpt_title = 'dpt-title dpt-display';
1017   var dpt_prepend_digit = prepend_digit == '' ? dpt_title : 'dpt-value';
1018   var dpt_pattern_prefix = pattern_prefix == '' ? dpt_title : 'dpt-value';
1019   var dpt_pattern_pass = pattern_pass == '' ? dpt_title : 'dpt-value';
1020
1021   var new_insert = start_loc.before('\
1022   <tr>\
1023     <td colspan="2">\
1024     (<input title="<?php echo $pp_tit?>" type="text" size="10" id="prepend_digit_'+idx+'" name="prepend_digit['+idx+']" class="dp-prepend dial-pattern '+dpt_prepend_digit+'" value="'+prepend_digit+'" tabindex="'+tabindex+'">) +\
1025     <input title="<?php echo $pf_tit?>" type="text" size="6" id="pattern_prefix_'+idx+'" name="pattern_prefix['+idx+']" class="dp-prefix '+dpt_pattern_prefix+'" value="'+pattern_prefix+'" tabindex="'+tabindex1+'"> |\
1026     <input title="<?php echo $mp_tit?>" type="text" size="16" id="pattern_pass_'+idx+'" name="pattern_pass['+idx+']" class="dp-match '+dpt_pattern_pass+'" value="'+pattern_pass+'" tabindex="'+tabindex2+'">\
1027       <img src="images/core_add.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("insert")?>" title="<?php echo _("Click here to insert a new pattern")?>" onclick="addCustomField(\'\',\'\',\'\',$(\'#prepend_digit_'+idx+'\').parent().parent())">\
1028       <img src="images/trash.png" style="cursor:pointer; float:none; margin-left:0px; margin-bottom:-3px;" alt="<?php echo _("remove")?>" title="<?php echo _("Click here to remove this pattern")?>" onclick="patternsRemove('+idx+')">\
1029     </td>\
1030   </tr>\
1031   ').prev();
1032
1033   new_insert.find(".dpt-title").toggleVal({
1034     populateFrom: "title",
1035     changedClass: "text-normal",
1036     focusClass: "text-normal"
1037   });
1038
1039   return idx;
1040 }
1041
1042 function clearPatterns() {
1043   $(".dpt-display").each(function() {
1044     if($(this).val() == $(this).data("defText")) {
1045       $(this).val("");
1046     }
1047   });
1048   return true;
1049 }
1050
1051 function clearAllPatterns() {
1052
1053   $(".dpt-value").addClass('dpt-title dpt-nodisplay').removeClass('dpt-value').mouseover(function(){
1054     $(this).toggleVal({
1055       populateFrom: "title",
1056       changedClass: "text-normal",
1057       focusClass: "text-normal"
1058     }).removeClass('dpt-nodisplay').addClass('dpt-display').unbind('mouseover');
1059   }).each(function(){
1060     $(this).val("");
1061   });
1062
1063   return true;
1064 }
1065
1066 // all blanks are ok
1067 function validatePatterns() {
1068   var culprit;
1069   var msgInvalidDialPattern;
1070   defaultEmptyOK = true;
1071
1072   // TODO: need to validate differently for prepend, prefix and match fields. The prepend
1073   //      must be a dialable digit. The prefix can be any pattern but not contain "." and
1074   //      the pattern can contain a "." also
1075   //$filter_prepend = '/[^0-9\+\*\#/';
1076   //$filter_match = '/[^0-9\-\+\*\#\.\[\]xXnNzZ]/';
1077   //$filter_prefix = '/[^0-9\-\+\*\#\[\]xXnNzZ]/';
1078     //defaultEmptyOK = false;
1079   /* TODO: get some sort of check in for dialpatterns
1080     if (!isDialpattern(theForm.dialpattern.value))
1081         return warnInvalid(theForm.dialpattern, msgInvalidDialPattern);
1082     */
1083
1084   $(".dp-prepend").each(function() {
1085     if ($.trim(this.value) == '') {
1086     } else if (this.value.search('[^0-9*#+wW\s]+') >= 0) {
1087       culprit = this;
1088       return false;
1089     }
1090   });
1091   if (!culprit) {
1092     $(".dp-prefix").each(function() {
1093       if ($.trim($(this).val()) == '') {
1094       } else if (!isDialpattern(this.value) || this.value.search('[._]+') >= 0) {
1095         culprit = this;
1096         return false;
1097       }
1098     });
1099   }
1100   if (!culprit) {
1101     $(".dp-match").each(function() {
1102       if ($.trim(this.value) == '') {
1103       } else if (!isDialpattern(this.value) || this.value.search('[_]+') >= 0) {
1104         culprit = this;
1105         return false;
1106       }
1107     });
1108   }
1109
1110   if (culprit != undefined) {
1111       msgInvalidDialPattern = "<?php echo _('Dial pattern is invalid'); ?>";
1112     // now we have to put it back...
1113     // do I have to turn it off first though?
1114     $(".dpt-display").each(function() {
1115       if ($.trim($(this).val()) == '') {
1116         $(this).toggleVal({
1117           populateFrom: "title",
1118           changedClass: "text-normal",
1119           focusClass: "text-normal"
1120         });
1121       }
1122     });
1123     return warnInvalid(culprit, msgInvalidDialPattern);
1124   } else {
1125     return true;
1126   }
1127 }
1128
1129 document.trunkEdit.trunk_name.focus();
1130
1131 function trunkEdit_onsubmit(act) {
1132   var theForm = document.trunkEdit;
1133
1134     var msgInvalidOutboundCID = "<?php echo _('Invalid Outbound CallerID'); ?>";
1135     var msgInvalidMaxChans = "<?php echo _('Invalid Maximum Channels'); ?>";
1136     var msgInvalidDialRules = "<?php echo _('Invalid Dial Rules'); ?>";
1137     var msgInvalidOutboundDialPrefix = "<?php echo _('The Outbound Dial Prefix contains non-standard characters. If these are intentional the press OK to continue.'); ?>";
1138     var msgInvalidTrunkName = "<?php echo _('Invalid Trunk Name entered'); ?>";
1139     var msgInvalidChannelName = "<?php echo _('Invalid Custom Dial String entered'); ?>";
1140     var msgInvalidTrunkAndUserSame = "<?php echo _('Trunk Name and User Context cannot be set to the same value'); ?>";
1141     var msgConfirmBlankContext = "<?php echo _('User Context was left blank and User Details will not be saved!'); ?>";
1142     var msgCIDValueRequired = "<?php echo _('You must define an Outbound CallerID when Choosing this CID Options value'); ?>";
1143     var msgCIDValueEmpty = "<?php echo _('It is highly recommended that you define an Outbound CallerID on all trunks, undefined behavior can result when nothing is specified. The CID Options can control when this CID is used. Do you still want to continue?'); ?>";
1144
1145     defaultEmptyOK = true;
1146
1147     if (isEmpty($.trim(theForm.outcid.value))) {
1148       if (theForm.keepcid.value == 'on' || theForm.keepcid.value == 'all') {
1149           return warnInvalid(theForm.outcid, msgCIDValueRequired);
1150       } else {
1151                 if (confirm(msgCIDValueEmpty) == false) {
1152                   return false;
1153       }
1154     }
1155   }
1156
1157     if (!isCallerID(theForm.outcid.value))
1158         return warnInvalid(theForm.outcid, msgInvalidOutboundCID);
1159    
1160     if (!isInteger(theForm.maxchans.value))
1161         return warnInvalid(theForm.maxchans, msgInvalidMaxChans);
1162    
1163     if (!isDialIdentifierSpecial(theForm.dialoutprefix.value)) {
1164     if (confirm(msgInvalidOutboundDialPrefix) == false) {
1165       $('#dialoutprefix').focus();
1166       return false;
1167     }
1168   }
1169    
1170     <?php if ($tech != "enum" && $tech != "custom" && $tech != "dundi") { ?>
1171     defaultEmptyOK = true;
1172     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
1173         return warnInvalid(theForm.channelid, msgInvalidTrunkName);
1174    
1175     if (theForm.channelid.value == theForm.usercontext.value)
1176         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
1177     <?php } else if ($tech == "custom" || $tech == "dundi") { ?>
1178     if (isEmpty(theForm.channelid.value) || isWhitespace(theForm.channelid.value))
1179         return warnInvalid(theForm.channelid, msgInvalidChannelName);
1180
1181     if (theForm.channelid.value == theForm.usercontext.value)
1182         return warnInvalid(theForm.usercontext, msgInvalidTrunkAndUserSame);
1183     <?php } ?>
1184
1185     <?php if ($tech == "sip" || substr($tech,0,3) == "iax") { ?>
1186     if ((isEmpty(theForm.usercontext.value) || isWhitespace(theForm.usercontext.value)) &&
1187         (!isEmpty(theForm.userconfig.value) && !isWhitespace(theForm.userconfig.value)) &&
1188             (theForm.userconfig.value != "secret=***password***\ntype=user\ncontext=from-trunk")) {
1189                 if (confirm(msgConfirmBlankContext) == false)
1190                 return false;
1191             }
1192     <?php } ?>
1193
1194   clearPatterns();
1195   if (validatePatterns()) {
1196       theForm.action.value = act;
1197       return true;
1198   } else {
1199     return false;
1200   }
1201 }
1202
1203 function isDialIdentifierSpecial(s) { // special chars allowed in dial prefix (e.g. fwdOUT)
1204     var i;
1205
1206     if (isEmpty(s))
1207        if (isDialIdentifierSpecial.arguments.length == 1) return defaultEmptyOK;
1208        else return (isDialIdentifierSpecial.arguments[1] == true);
1209
1210     for (i = 0; i < s.length; i++)
1211     {   
1212         var c = s.charAt(i);
1213
1214         if ( !isDialDigitChar(c) && (c != "w") && (c != "W") && (c != "q") && (c != "Q") && (c != "+") ) return false;
1215     }
1216
1217     return true;
1218 }
1219 //-->
1220 </script>
1221
1222         </form>
1223 <?php 
1224 }
1225 ?>
1226
1227
1228
Note: See TracBrowser for help on using the browser.