root/modules/branches/2.4/core/page.zapchandids.php

Revision 5452, 5.9 kB (checked in by p_lindheimer, 4 years ago)

fixes to Zap Channel DIDs validation

Line 
1 <?php 
2 /** Zap Channel DIDs display for FreePBX 2.4
3  * Copyright 2006 Philippe Lindheimer - Astrogen LLC
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program 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
15 $display = 'zapchandids';
16 $type = isset($_REQUEST['type']) ? $_REQUEST['type'] :  'setup';
17 $action = isset($_REQUEST['action']) ? $_REQUEST['action'] :  '';
18 if (isset($_REQUEST['delete'])) $action = 'delete';
19
20
21 $extdisplay  = isset($_REQUEST['extdisplay']) ? $_REQUEST['extdisplay'] : '';
22 $channel     = isset($_REQUEST['channel']) ? $_REQUEST['channel'] :  false;
23 $description = isset($_REQUEST['description']) ? $_REQUEST['description'] :  '';
24 $did         = isset($_REQUEST['did']) ? $_REQUEST['did'] :  '';
25
26 switch ($action) {
27   case 'add':
28     if (core_zapchandids_add($description, $channel, $did)) {
29       needreload();
30       redirect_standard();
31     }
32   break;
33   case 'edit':
34     if (core_zapchandids_edit($description, $channel, $did)) {
35       needreload();
36       redirect_standard('extdisplay');
37     }
38   break;
39   case 'delete':
40     core_zapchandids_delete($channel);
41     needreload();
42     redirect_standard();
43   break;
44 }
45
46
47 ?> 
48 </div>
49
50 <div class="rnav"><ul>
51 <?php 
52
53 echo '<li><a href="config.php?display='.$display.'&type='.$type.'">'._('Add Channel').'</a></li>';
54
55 foreach (core_zapchandids_list() as $row) {
56   echo '<li><a href="config.php?display='.$display.'&type='.$type.'&extdisplay='.$row['channel'].'" class="">'.$row['channel'].': '.$row['description'].'</a></li>';
57 }
58
59 ?>
60 </ul></div>
61
62 <div class="content">
63
64 <?php
65
66 if ($extdisplay != '') {
67   // load
68   $row = core_zapchandids_get($extdisplay);
69  
70   $description = $row['description'];
71   $channel     = $row['channel'];
72   $did         = $row['did'];
73
74   echo "<h2>"._("Edit Zap Channel: ").$channel."</h2>";
75 } else {
76   echo "<h2>"._("Add Zap Channel")."</h2>";
77 }
78
79 $helptext = _("Zap Channel DIDs allow you to assign a DID to specific Zap Channels. You can supply the same DID to multiple channels. This would be a common scenario if you have multiple POTS lines that are on a hunt group from your provider. You MUST assign the channel's context to from-zaptel for these settings to have effect. It will be a line that looks like:<br /><br />context = from-zaptel<br /><br />in your zapata.conf configuration effecting the specified channel(s). Once you have assigned DIDs you can use standard Inbound Routes with the specified DIDs to route your calls.");
80 echo "<p>".$helptext."</p>\n";
81 ?>
82 <form name="editZapchandid" action="<?php  $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return checkZapchandid(editZapchandid);">
83   <input type="hidden" name="extdisplay" value="<?php echo $extdisplay; ?>">
84   <input type="hidden" name="channel" value="<?php echo $extdisplay; ?>">
85   <input type="hidden" name="action" value="<?php echo ($extdisplay != '' ? 'edit' : 'add'); ?>">
86   <table>
87   <tr><td colspan="2"><h5><?php  echo ($extdisplay != '' ? _("Edit Channel").": ".$extdisplay : _("Add Channel")) ?><hr></h5></td></tr>
88 <?php
89   if ($extdisplay == '') {
90 ?>
91   <tr>
92     <td><a href="#" class="info"><?php echo _("Channel")?>:<span><?php echo _("The Zap Channel number to map to a DID")?></span></a></td>
93     <td><input size="5" type="text" name="channel" value="<?php  echo $channel; ?>"></td>
94   </tr>
95 <?php
96   }
97 ?>
98   <tr>
99     <td><a href="#" class="info"><?php echo _("Description")?>:<span><?php echo _("A useful description describing this channel")?></span></a></td>
100     <td><input size="40" type="text" name="description" value="<?php  echo $description; ?>"></td>
101   </tr>
102   <tr>
103     <td><a href="#" class="info"><?php echo _("DID")?>:<span><?php echo _("The DID that this channel represents. The incoming call on this channel will be treated as if it came in with this DID and can be managed with Inbound Routing on DIDs")?></span></a></td>
104     <td><input size="40" type="text" name="did" value="<?php echo $did; ?>" /></td>
105   </tr>
106
107   <tr>
108     <td colspan="2"><br><input name="Submit" type="submit" value="<?php echo _("Submit Changes")?>">
109       <?php if ($extdisplay != '') { echo '&nbsp;<input name="delete" type="submit" onclick="actionDelete=true;" value="'._("Delete").'">'; } ?>
110     </td>   
111
112   </tr>
113   </table>
114 </form>
115       
116       
117 <script language="javascript">
118 <!--
119
120 var actionDelete = false;
121
122 function checkZapchandid(theForm) {
123   var msgInvalidChannel = "<?php echo _('Invalid Channel Number, must be numeric and not blank'); ?>";
124   var msgInvalidDID = "<?php echo _('Invalid DID, must be a non-blank DID'); ?>";
125   var msgConfirmDIDNonStd = "<?php echo _('DID information is normally just an incoming telephone number.\n\nYou have entered a non standard DID pattern.\n\nAre you sure this is correct?'); ?>";
126   var msgConfirmConvertDID = "<?php echo _('You appear to be using a converted DID in the form of zapchanNN that was automatically generated during an upgrade. You should consider assigning the DID that is normally associated with this channel to take full advantage of the inbound routing abilities. Changing the DID here will require you to make changes in the Inbound Routes tab. Do you want to continue?'); ?>";
127
128
129   // If deleting we don't care what is in the elements
130   if (actionDelete) {
131     actionDelete = false;
132     return true;
133   }
134   // form validation
135
136   defaultEmptyOK = false;
137   if (!isInteger(theForm.channel.value)) {
138     return warnInvalid(theForm.channel, msgInvalidChannel);
139   }
140   if (isEmpty(theForm.did.value)) {
141     return warnInvalid(theForm.did, msgInvalidDID);
142   }
143   if (theForm.did.value.substring(0,7) == "zapchan") {
144     if (!confirm(msgConfirmConvertDID)) {
145       return false;
146     }
147
148   } else if (!isDialpattern(theForm.did.value)) {
149     if (!confirm(msgConfirmDIDNonStd)) {
150       return false;
151     }
152   }
153
154   return true;
155 }
156 //-->
157 </script>
Note: See TracBrowser for help on using the browser.