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

Revision 11956, 54.9 kB (checked in by mickecarlsson, 1 year ago)

core, standardize on DAHDi

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