root/modules/branches/2.3/cidlookup/page.cidlookup.php

Revision 3204, 12.1 kB (checked in by gregmac, 5 years ago)

Updated for changes in r3203: only pass identifying variable on edit, and explicitly pass extdisplay if needed (as it is no longer included by default)

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php /* $Id */
2 //Copyright (C) 2006 WeBRainstorm S.r.l. (ask@webrainstorm.it)
3 //
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 isset($_REQUEST['action'])?$action = $_REQUEST['action']:$action='';
15
16 //the item we are currently displaying
17 isset($_REQUEST['itemid'])?$itemid=$_REQUEST['itemid']:$itemid='';
18
19 $dispnum = "cidlookup"; //used for switch on config.php
20
21 //if submitting form, update database
22 if(isset($_POST['action'])) {
23   switch ($action) {
24     case "add":
25       cidlookup_add($_POST);
26       needreload();
27       redirect_standard();
28     break;
29     case "delete":
30       cidlookup_del($itemid);
31       needreload();
32       redirect_standard();
33     break;
34     case "edit":
35       cidlookup_edit($itemid,$_POST);
36       needreload();
37       redirect_standard('itemid');
38     break;
39   }
40 }
41
42 //get list of callerid lookup sources
43 $cidsources = cidlookup_list();
44 ?>
45
46 </div> <!-- end content div so we can display rnav properly-->
47
48 <!-- right side menu -->
49 <div class="rnav"><ul>
50     <li><a id="<?php echo ($itemid=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add CID Lookup Source")?></a></li>
51 <?php
52 if (isset($cidsources)) {
53   foreach ($cidsources as $cidsource) {
54     if ($cidsource['cidlookup_id'] != 0)
55       echo "<li><a id=\"".($itemid==$cidsource['cidlookup_id'] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&itemid=".urlencode($cidsource['cidlookup_id'])."\">{$cidsource['description']}</a></li>";
56   }
57 }
58 ?>
59 </ul></div>
60
61 <div class="content">
62 <?php
63 if ($action == 'delete') {
64   echo '<br><h3>'._("CID Lookup source").' '.$itemid.' '._("deleted").'!</h3>';
65 } else {
66   if ($itemid){
67     //get details for this source
68     $thisItem = cidlookup_get($itemid);
69   } else {
70     $thisItem = Array( 'description' => null, 'sourcetype' => null, 'cache' => null);
71   }
72
73   $delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=delete';
74   $delButton = "
75       <form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST>
76         <input type=\"hidden\" name=\"display\" value=\"{$dispnum}\">
77         <input type=\"hidden\" name=\"itemid\" value=\"{$itemid}\">
78         <input type=\"hidden\" name=\"action\" value=\"delete\">
79         <input type=submit value=\""._("Delete CID Lookup source")."\">
80       </form>";
81  
82 ?>
83
84   <h2><?php echo ($itemid ? _("Source:")." ". $itemid : _("Add Source")); ?></h2>
85  
86   <p style="width: 80%"><?php echo ($itemid ? '' : _("A Lookup Source let you specify a source for resolving numeric caller IDs of incoming calls, you can then link an Inbound route to a specific CID source. This way you will have more detailed CDR reports with informations taken directly from your CRM. You can also install the phonebook module to have a small number <-> name association. Pay attention, name lookup may slow down your PBX")); ?></p>
87
88 <?php   if ($itemid){  echo $delButton;   } ?>
89
90 <form autocomplete="off" name="edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return edit_onsubmit();">
91   <input type="hidden" name="display" value="<?php echo $dispnum?>">
92   <input type="hidden" name="action" value="<?php echo ($itemid ? 'edit' : 'add') ?>">
93   <input type="hidden" name="deptname" value="<?php echo $_SESSION["AMP_user"]->_deptname ?>">
94   <table>
95   <tr><td colspan="2"><h5><?php echo ($itemid ? _("Edit Source") : _("Add Source")) ?><hr></h5></td></tr>
96
97 <?php   if ($itemid){ ?>
98     <input type="hidden" name="itemid" value="<?php echo $itemid; ?>">
99 <?php   }?>
100
101   <tr>
102     <td><a href="#" class="info"><?php echo _("Source Description:")?><span><?php echo _("Enter a description for this source.")?></span></a></td>
103     <td><input type="text" name="description" value="<?php echo (isset($thisItem['description']) ? $thisItem['description'] : ''); ?>"></td>
104   </tr>
105   <tr>
106     <td><a href="#" class="info"><?php echo _("Source type:")?><span><?php echo _("Enter the source type, you can choose beetwen:<ul><li>Internal: use astdb as lookup source, use phonebook module to populate it</li><li>ENUM: Use DNS to lookup caller names, it uses ENUM lookup zones as configured in enum.conf</li><li>HTTP: It executes an HTTP GET passing the caller number as argument to retrieve the correct name</li><li>MySQL: It queryes a MySQL database to retrieve caller name</li></ul>")?></span></a></td>
107     <td>
108       <select id="sourcetype" name="sourcetype" onChange="javascript:displaySourceParameters(this, this.selectedIndex)">
109         <option value="internal" <?php echo ($thisItem['sourcetype'] == 'internal' ? 'selected' : '')?>>Internal</option>
110         <option value="enum" <?php echo ($thisItem['sourcetype'] == 'enum' ? 'selected' : '')?>>ENUM</option>
111         <option value="http" <?php echo ($thisItem['sourcetype'] == 'http' ? 'selected' : '')?>>HTTP</option>
112         <option value="mysql" <?php echo ($thisItem['sourcetype'] == 'mysql' ? 'selected' : '')?>>MySQL</option>
113         <option value="sugarcrm" <?php echo ($thisItem['sourcetype'] == 'sugarcrm' ? 'selected' : '')?>>SugarCRM</option>
114       </select>
115     </td>
116   </tr>
117   <tr>
118     <td><a href="#" class="info"><?php echo _("Cache results:")?><span><?php echo _("Decide wether or not cache the results to astDB; it will overwrite present values. It does not affect Internal source behaviour")?></span></a></td>
119     <td><input type="checkbox" name="cache" value="1" <?php echo ($thisItem['cache'] == 1 ? 'checked' : ''); ?>"></td>
120   </tr>
121   <tr>
122     <td colspan="2">
123       <div id="http" style="display: none">
124         <table cellpadding="2" cellspacing="0" width="100%">
125
126           <tr><td colspan="2"><h5><?php echo _("HTTP") ?><hr></h5></div></td></tr>
127  
128           <tr>
129             <td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("Host name or IP address")?></span></a></td>
130             <td><input type="text" name="http_host" value="<?php echo (isset($thisItem['http_host']) ? $thisItem['http_host'] : ''); ?>"></td>
131           </tr>
132  
133           <tr>
134             <td><a href="#" class="info"><?php echo _("Port:")?><span><?php echo _("Port HTTP server is listening at (default 80)")?></span></a></td>
135             <td><input type="text" name="http_port" value="<?php echo (isset($thisItem['http_port']) ? $thisItem['http_port'] : ''); ?>"></td>
136           </tr>
137          
138           <tr>
139             <td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("Username to use in HTTP authentication")?></span></a></td>
140             <td><input type="text" name="http_username" value="<?php echo (isset($thisItem['http_username']) ? $thisItem['http_username'] : ''); ?>"></td>
141           </tr>
142        
143           <tr>
144             <td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("Password to use in HTTP authentication")?></span></a></td>
145             <td><input type="text" name="http_password" value="<?php echo (isset($thisItem['http_password']) ? $thisItem['http_password'] : ''); ?>"></td>
146           </tr>
147        
148           <tr>
149             <td><a href="#" class="info"><?php echo _("Path:")?><span><?php echo _("Path of the file to GET<br/>e.g.: /cidlookup.php")?></span></a></td>
150             <td><input type="text" name="http_path" value="<?php echo (isset($thisItem['http_path']) ? $thisItem['http_path'] : ''); ?>"></td>
151           </tr>
152        
153           <tr>
154             <td><a href="#" class="info"><?php echo _("Query:")?><span><?php echo _("Query string, special token '[NUMBER]' will be replaced with caller number<br/>e.g.: number=[NUMBER]&source=crm")?></span></a></td>
155             <td><input type="text" name="http_query" value="<?php echo (isset($thisItem['http_query']) ? $thisItem['http_query'] : ''); ?>"></td>
156           </tr>
157         </table>
158       </div>
159     </td>
160   </tr>
161   <tr>
162     <td colspan="2">
163       <div id="mysql" style="display: none">
164         <table cellpadding="2" cellspacing="0" width="100%">
165           <tr><td colspan="2"><h5><?php echo _("MySQL") ?><hr></h5></td></tr>
166        
167           <tr>
168             <td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("MySQL Host")?></span></a></td>
169             <td><input type="text" name="mysql_host" value="<?php echo (isset($thisItem['mysql_host']) ? $thisItem['mysql_host'] : ''); ?>"></td>
170           </tr>
171           <tr>
172             <td><a href="#" class="info"><?php echo _("Database:")?><span><?php echo _("Database name")?></span></a></td>
173             <td><input type="text" name="mysql_dbname" value="<?php echo (isset($thisItem['mysql_dbname']) ? $thisItem['mysql_dbname'] : ''); ?>"></td>
174           </tr>
175           <tr>
176             <td><a href="#" class="info"><?php echo _("Query:")?><span><?php echo _("Query, special token '[NUMBER]' will be replaced with caller number<br/>e.g.: SELECT name FROM phonebook WHERE number LIKE '%[NUMBER]%'")?></span></a></td>
177             <td><input type="text" name="mysql_query" value="<?php echo (isset($thisItem['mysql_query']) ? $thisItem['mysql_query'] : ''); ?>"></td>
178           </tr>
179        
180           <tr>
181             <td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("MySQL Username")?></span></a></td>
182             <td><input type="text" name="mysql_username" value="<?php echo (isset($thisItem['mysql_username']) ? $thisItem['mysql_username'] : ''); ?>"></td>
183           </tr>
184           <tr>
185             <td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("MySQL Password")?></span></a></td>
186             <td><input type="text" name="mysql_password" value="<?php echo (isset($thisItem['mysql_password']) ? $thisItem['mysql_password'] : ''); ?>"></td>
187           </tr>
188         </table>
189       </div>
190     </td>
191   </tr>
192   <tr>
193     <td colspan="2">
194       <div id="sugarcrm" style="display: none">
195         <table cellpadding="2" cellspacing="0" width="100%">
196           <tr><td colspan="2"><h5><?php echo _("SugarCRM") ?><hr></h5></td></tr>
197           <tr><td colspan="2">Not yet implemented</td></tr>
198         </table>
199       </div>
200     </td>
201   </tr>
202
203   <tr>
204     <td colspan="2"><br><h6><input name="submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
205   </tr>
206   </table>
207
208
209 <script language="javascript">
210 <!--
211
212 /* TODO: improve client side checking for different values of sourcetype */
213
214 var theForm = document.edit;
215 theForm.description.focus();
216
217 displaySourceParameters(document.getElementById('sourcetype'), document.getElementById('sourcetype').selectedIndex);
218
219 function edit_onsubmit() {
220    
221   defaultEmptyOK = false;
222   if (!isAlphanumeric(theForm.description.value))
223     return warnInvalid(theForm.description, "Please enter a valid Description");
224
225   if (theForm.sourcetype.value == 'http') {
226     if (isEmpty(theForm.http_host.value))
227       return warnInvalid(theForm.http_host, "Please enter a valid HTTP Host name");
228   }
229
230   if (theForm.sourcetype.value == 'mysql')  {
231     if (isEmpty(theForm.mysql_host.value))
232       return warnInvalid(theForm.mysql_host, "Please enter a valid MySQL Host name");
233
234     if (isEmpty(theForm.mysql_dbname.value))
235       return warnInvalid(theForm.mysql_dbname, "Please enter a valid MySQL Database name");
236      
237     if (isEmpty(theForm.mysql_query.value))
238       return warnInvalid(theForm.mysql_query, "Please enter a valid MySQL Query string");
239
240     if (isEmpty(theForm.mysql_username.value))
241       return warnInvalid(theForm.mysql_username, "Please enter a valid MySQL Username");
242
243   }
244      
245   return true;
246 }
247
248 function displaySourceParameters(sourcetypeSelect, key) {
249   if (sourcetypeSelect.options[key].value == 'http') {
250     document.getElementById('http').style.display = '';
251     document.getElementById('mysql').style.display = 'none';
252     document.getElementById('sugarcrm').style.display = 'none';
253   } else if (sourcetypeSelect.options[key].value == 'mysql') {
254     document.getElementById('http').style.display = 'none';
255     document.getElementById('mysql').style.display = '';
256     document.getElementById('sugarcrm').style.display = 'none';
257   } else if (sourcetypeSelect.options[key].value == 'sugarcrm') {
258     document.getElementById('http').style.display = 'none';
259     document.getElementById('mysql').style.display = 'none';
260     document.getElementById('sugarcrm').style.display = '';
261   } else {
262     document.getElementById('http').style.display = 'none';
263     document.getElementById('mysql').style.display = 'none';
264     document.getElementById('sugarcrm').style.display = 'none';
265   }
266 }
267 -->
268 </script>
269
270
271   </form>
272 <?php   
273 } //end if action == delete
274 ?>
Note: See TracBrowser for help on using the browser.