root/contributed_modules/modules/ldapcidlookup/page.ldapcidlookup.php

Revision 5062, 14.8 kB (checked in by p_lindheimer, 5 years ago)

#2389 add ldapcidlookup to contributed module repository

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 = "ldapcidlookup"; //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         <option value="ldap" <?php echo ($thisItem['sourcetype'] == 'ldap' ? 'selected' : '')?>>LDAP</option>
115       </select>
116     </td>
117   </tr>
118   <tr>
119     <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>
120     <td><input type="checkbox" name="cache" value="1" <?php echo ($thisItem['cache'] == 1 ? 'checked' : ''); ?>"></td>
121   </tr>
122   <tr>
123     <td colspan="2">
124       <div id="http" style="display: none">
125         <table cellpadding="2" cellspacing="0" width="100%">
126
127           <tr><td colspan="2"><h5><?php echo _("HTTP") ?><hr></h5></div></td></tr>
128  
129           <tr>
130             <td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("Host name or IP address")?></span></a></td>
131             <td><input type="text" name="http_host" value="<?php echo (isset($thisItem['http_host']) ? $thisItem['http_host'] : ''); ?>"></td>
132           </tr>
133  
134           <tr>
135             <td><a href="#" class="info"><?php echo _("Port:")?><span><?php echo _("Port HTTP server is listening at (default 80)")?></span></a></td>
136             <td><input type="text" name="http_port" value="<?php echo (isset($thisItem['http_port']) ? $thisItem['http_port'] : ''); ?>"></td>
137           </tr>
138           
139           <tr>
140             <td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("Username to use in HTTP authentication")?></span></a></td>
141             <td><input type="text" name="http_username" value="<?php echo (isset($thisItem['http_username']) ? $thisItem['http_username'] : ''); ?>"></td>
142           </tr>
143         
144           <tr>
145             <td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("Password to use in HTTP authentication")?></span></a></td>
146             <td><input type="text" name="http_password" value="<?php echo (isset($thisItem['http_password']) ? $thisItem['http_password'] : ''); ?>"></td>
147           </tr>
148         
149           <tr>
150             <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>
151             <td><input type="text" name="http_path" value="<?php echo (isset($thisItem['http_path']) ? $thisItem['http_path'] : ''); ?>"></td>
152           </tr>
153         
154           <tr>
155             <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>
156             <td><input type="text" name="http_query" value="<?php echo (isset($thisItem['http_query']) ? $thisItem['http_query'] : ''); ?>"></td>
157           </tr>
158         </table>
159       </div>
160     </td>
161   </tr>
162   <tr>
163     <td colspan="2">
164       <div id="mysql" style="display: none">
165         <table cellpadding="2" cellspacing="0" width="100%">
166           <tr><td colspan="2"><h5><?php echo _("MySQL") ?><hr></h5></td></tr>
167         
168           <tr>
169             <td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("MySQL Host")?></span></a></td>
170             <td><input type="text" name="mysql_host" value="<?php echo (isset($thisItem['mysql_host']) ? $thisItem['mysql_host'] : ''); ?>"></td>
171           </tr>
172           <tr>
173             <td><a href="#" class="info"><?php echo _("Database:")?><span><?php echo _("Database name")?></span></a></td>
174             <td><input type="text" name="mysql_dbname" value="<?php echo (isset($thisItem['mysql_dbname']) ? $thisItem['mysql_dbname'] : ''); ?>"></td>
175           </tr>
176           <tr>
177             <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>
178             <td><input type="text" name="mysql_query" value="<?php echo (isset($thisItem['mysql_query']) ? $thisItem['mysql_query'] : ''); ?>"></td>
179           </tr>
180         
181           <tr>
182             <td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("MySQL Username")?></span></a></td>
183             <td><input type="text" name="mysql_username" value="<?php echo (isset($thisItem['mysql_username']) ? $thisItem['mysql_username'] : ''); ?>"></td>
184           </tr>
185           <tr>
186             <td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("MySQL Password")?></span></a></td>
187             <td><input type="text" name="mysql_password" value="<?php echo (isset($thisItem['mysql_password']) ? $thisItem['mysql_password'] : ''); ?>"></td>
188           </tr>
189         </table>
190       </div>
191     </td>
192   </tr>
193   <tr>
194     <td colspan="2">
195       <div id="sugarcrm" style="display: none">
196         <table cellpadding="2" cellspacing="0" width="100%">
197           <tr><td colspan="2"><h5><?php echo _("SugarCRM") ?><hr></h5></td></tr>
198           <tr><td colspan="2">Not yet implemented</td></tr>
199         </table>
200       </div>
201     </td>
202   </tr>
203   <tr>
204     <td colspan="2">
205       <div id="ldap" style="display: none">
206         <table cellpadding="2" cellspacing="0" width="100%">
207           <tr><td colspan="2"><h5><?php echo _("LDAP") ?><hr></h5></td></tr>
208         
209           <tr>
210             <td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("LDAP Host")?></span></a></td>
211             <td><input type="text" name="ldap_host" value="<?php echo (isset($thisItem['ldap_host']) ? $thisItem['ldap_host'] : ''); ?>"></td>
212           </tr>
213           <tr>
214             <td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("LDAP Username")?></span></a></td>
215             <td><input type="text" name="ldap_username" value="<?php echo (isset($thisItem['ldap_username']) ? $thisItem['ldap_username'] : ''); ?>"></td>
216           </tr>
217           <tr>
218             <td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("LDAP Password")?></span></a></td>
219             <td><input type="text" name="ldap_password" value="<?php echo (isset($thisItem['ldap_password']) ? $thisItem['ldap_password'] : ''); ?>"></td>
220           </tr>
221           <tr>
222             <td><a href="#" class="info"><?php echo _("Base DN:")?><span><?php echo _("LDAP Base Distinguished Name, for example DC=freepbx,DC=com")?></span></a></td>
223             <td><input type="text" name="ldap_base" value="<?php echo (isset($thisItem['ldap_base']) ? $thisItem['ldap_base'] : ''); ?>"></td>
224           </tr>
225           <tr>
226             <td><a href="#" class="info"><?php echo _("Area Code Prefix:")?><span><?php echo _("Prefix for your local area code")?></span></a></td>
227             <td><input type="text" name="ldap_prefix" value="<?php echo (isset($thisItem['ldap_prefix']) ? $thisItem['ldap_prefix'] : ''); ?>"></td>
228           </tr>
229           <tr>
230             <td><a href="#" class="info"><?php echo _("Number Format:")?><span><?php echo _("Reformat phone number before lookup. Use 'X' for number placement.  For example (XXX) XXX-XXXX or (XX) XXXX-XXXX depending on your country, and the format of numbers in your ldap repository.")?></span></a></td>
231             <td><input type="text" name="ldap_format" value="<?php echo (isset($thisItem['ldap_format']) ? $thisItem['ldap_format'] : ''); ?>"></td>
232           </tr>
233         </table>
234       </div>
235     </td>
236   </tr>
237
238   <tr>
239     <td colspan="2"><br><h6><input name="submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td>   
240   </tr>
241   </table>
242
243
244 <script language="javascript">
245 <!--
246
247 /* TODO: improve client side checking for different values of sourcetype */
248
249 var theForm = document.edit;
250 theForm.description.focus();
251
252 displaySourceParameters(document.getElementById('sourcetype'), document.getElementById('sourcetype').selectedIndex);
253
254 function edit_onsubmit() {
255     
256   defaultEmptyOK = false;
257   if (!isAlphanumeric(theForm.description.value))
258     return warnInvalid(theForm.description, "Please enter a valid Description");
259
260   if (theForm.sourcetype.value == 'http') {
261     if (isEmpty(theForm.http_host.value))
262       return warnInvalid(theForm.http_host, "Please enter a valid HTTP Host name");
263   }
264
265   if (theForm.sourcetype.value == 'mysql')  {
266     if (isEmpty(theForm.mysql_host.value))
267       return warnInvalid(theForm.mysql_host, "Please enter a valid MySQL Host name");
268
269     if (isEmpty(theForm.mysql_dbname.value))
270       return warnInvalid(theForm.mysql_dbname, "Please enter a valid MySQL Database name");
271       
272     if (isEmpty(theForm.mysql_query.value))
273       return warnInvalid(theForm.mysql_query, "Please enter a valid MySQL Query string");
274
275     if (isEmpty(theForm.mysql_username.value))
276       return warnInvalid(theForm.mysql_username, "Please enter a valid MySQL Username");
277
278   }
279       
280   return true;
281 }
282
283 function displaySourceParameters(sourcetypeSelect, key) {
284   if (sourcetypeSelect.options[key].value == 'http') {
285     document.getElementById('http').style.display = '';
286     document.getElementById('mysql').style.display = 'none';
287     document.getElementById('sugarcrm').style.display = 'none';
288     document.getElementById('ldap').style.display = 'none';
289   } else if (sourcetypeSelect.options[key].value == 'mysql') {
290     document.getElementById('http').style.display = 'none';
291     document.getElementById('mysql').style.display = '';
292     document.getElementById('sugarcrm').style.display = 'none';
293     document.getElementById('ldap').style.display = 'none';
294   } else if (sourcetypeSelect.options[key].value == 'sugarcrm') {
295     document.getElementById('http').style.display = 'none';
296     document.getElementById('mysql').style.display = 'none';
297     document.getElementById('sugarcrm').style.display = '';
298     document.getElementById('ldap').style.display = 'none';
299   } else if (sourcetypeSelect.options[key].value == 'ldap') {
300     document.getElementById('http').style.display = 'none';
301     document.getElementById('mysql').style.display = 'none';
302     document.getElementById('sugarcrm').style.display = 'none';
303     document.getElementById('ldap').style.display = '';
304   } else {
305     document.getElementById('http').style.display = 'none';
306     document.getElementById('mysql').style.display = 'none';
307     document.getElementById('sugarcrm').style.display = 'none';
308     document.getElementById('ldap').style.display = 'none';
309   }
310 }
311 -->
312 </script>
313
314
315   </form>
316 <?php  
317 } //end if action == delete
318 ?>
Note: See TracBrowser for help on using the browser.