| 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 |
break; |
|---|
| 28 |
case "delete": |
|---|
| 29 |
cidlookup_del($itemid); |
|---|
| 30 |
needreload(); |
|---|
| 31 |
break; |
|---|
| 32 |
case "edit": |
|---|
| 33 |
cidlookup_edit($itemid,$_POST); |
|---|
| 34 |
needreload(); |
|---|
| 35 |
break; |
|---|
| 36 |
} |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
//get list of callerid lookup sources |
|---|
| 40 |
$cidsources = cidlookup_list(); |
|---|
| 41 |
?> |
|---|
| 42 |
|
|---|
| 43 |
</div> <!-- end content div so we can display rnav properly--> |
|---|
| 44 |
|
|---|
| 45 |
<!-- right side menu --> |
|---|
| 46 |
<div class="rnav"> |
|---|
| 47 |
<li><a id="<?php echo ($itemid=='' ? 'current':'') ?>" href="config.php?display=<?php echo urlencode($dispnum)?>"><?php echo _("Add CID Lookup Source")?></a></li> |
|---|
| 48 |
<?php |
|---|
| 49 |
if (isset($cidsources)) { |
|---|
| 50 |
foreach ($cidsources as $cidsource) { |
|---|
| 51 |
if ($cidsource['cidlookup_id'] != 0) |
|---|
| 52 |
echo "<li><a id=\"".($itemid==$cidsource['cidlookup_id'] ? 'current':'')."\" href=\"config.php?display=".urlencode($dispnum)."&itemid=".urlencode($cidsource['cidlookup_id'])."\">{$cidsource['description']}</a></li>"; |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
?> |
|---|
| 56 |
</div> |
|---|
| 57 |
|
|---|
| 58 |
<div class="content"> |
|---|
| 59 |
<?php |
|---|
| 60 |
if ($action == 'delete') { |
|---|
| 61 |
echo '<br><h3>'._("CID Lookup source").' '.$itemid.' '._("deleted").'!</h3>'; |
|---|
| 62 |
} else { |
|---|
| 63 |
if ($itemid){ |
|---|
| 64 |
//get details for this source |
|---|
| 65 |
$thisItem = cidlookup_get($itemid); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$delURL = $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&action=delete'; |
|---|
| 69 |
$delButton = " |
|---|
| 70 |
<form name=delete action=\"{$_SERVER['PHP_SELF']}\" method=POST> |
|---|
| 71 |
<input type=\"hidden\" name=\"display\" value=\"{$dispnum}\"> |
|---|
| 72 |
<input type=\"hidden\" name=\"itemid\" value=\"{$itemid}\"> |
|---|
| 73 |
<input type=\"hidden\" name=\"action\" value=\"delete\"> |
|---|
| 74 |
<input type=submit value=\""._("Delete CID Lookup source")."\"> |
|---|
| 75 |
</form>"; |
|---|
| 76 |
|
|---|
| 77 |
?> |
|---|
| 78 |
|
|---|
| 79 |
<h2><?php echo ($itemid ? _("Source:")." ". $itemid : _("Add Source")); ?></h2> |
|---|
| 80 |
|
|---|
| 81 |
<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> |
|---|
| 82 |
|
|---|
| 83 |
<?php if ($itemid){ echo $delButton; } ?> |
|---|
| 84 |
|
|---|
| 85 |
<form autocomplete="off" name="edit" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return edit_onsubmit();"> |
|---|
| 86 |
<input type="hidden" name="display" value="<?php echo $dispnum?>"> |
|---|
| 87 |
<input type="hidden" name="action" value="<?php echo ($itemid ? 'edit' : 'add') ?>"> |
|---|
| 88 |
<input type="hidden" name="deptname" value="<?php echo $_SESSION["AMP_user"]->_deptname ?>"> |
|---|
| 89 |
<table> |
|---|
| 90 |
<tr><td colspan="2"><h5><?php echo ($itemid ? _("Edit Source") : _("Add Source")) ?><hr></h5></td></tr> |
|---|
| 91 |
|
|---|
| 92 |
<?php if ($itemid){ ?> |
|---|
| 93 |
<input type="hidden" name="itemid" value="<?php echo $itemid; ?>"> |
|---|
| 94 |
<?php }?> |
|---|
| 95 |
|
|---|
| 96 |
<tr> |
|---|
| 97 |
<td><a href="#" class="info"><?php echo _("Source Description:")?><span><?php echo _("Enter a description for this source.")?></span></a></td> |
|---|
| 98 |
<td><input type="text" name="description" value="<?php echo (isset($thisItem['description']) ? $thisItem['description'] : ''); ?>"></td> |
|---|
| 99 |
</tr> |
|---|
| 100 |
<tr> |
|---|
| 101 |
<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> |
|---|
| 102 |
<td> |
|---|
| 103 |
<select id="sourcetype" name="sourcetype" onChange="javascript:displaySourceParameters(this, this.selectedIndex)"> |
|---|
| 104 |
<option value="internal" <?php echo ($thisItem['sourcetype'] == 'internal' ? 'selected' : '')?>>Internal</option> |
|---|
| 105 |
<option value="enum" <?php echo ($thisItem['sourcetype'] == 'enum' ? 'selected' : '')?>>ENUM</option> |
|---|
| 106 |
<option value="http" <?php echo ($thisItem['sourcetype'] == 'http' ? 'selected' : '')?>>HTTP</option> |
|---|
| 107 |
<option value="mysql" <?php echo ($thisItem['sourcetype'] == 'mysql' ? 'selected' : '')?>>MySQL</option> |
|---|
| 108 |
<option value="sugarcrm" <?php echo ($thisItem['sourcetype'] == 'sugarcrm' ? 'selected' : '')?>>SugarCRM</option> |
|---|
| 109 |
</select> |
|---|
| 110 |
</td> |
|---|
| 111 |
</tr> |
|---|
| 112 |
<tr> |
|---|
| 113 |
<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> |
|---|
| 114 |
<td><input type="checkbox" name="cache" value="1" <?php echo ($thisItem['cache'] == 1 ? 'checked' : ''); ?>"></td> |
|---|
| 115 |
</tr> |
|---|
| 116 |
<tr> |
|---|
| 117 |
<td colspan="2"> |
|---|
| 118 |
<div id="http" style="display: none"> |
|---|
| 119 |
<table cellpadding="2" cellspacing="0" width="100%"> |
|---|
| 120 |
|
|---|
| 121 |
<tr><td colspan="2"><h5><?php echo _("HTTP") ?><hr></h5></div></td></tr> |
|---|
| 122 |
|
|---|
| 123 |
<tr> |
|---|
| 124 |
<td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("Host name or IP address")?></span></a></td> |
|---|
| 125 |
<td><input type="text" name="http_host" value="<?php echo (isset($thisItem['http_host']) ? $thisItem['http_host'] : ''); ?>"></td> |
|---|
| 126 |
</tr> |
|---|
| 127 |
|
|---|
| 128 |
<tr> |
|---|
| 129 |
<td><a href="#" class="info"><?php echo _("Port:")?><span><?php echo _("Port HTTP server is listening at (default 80)")?></span></a></td> |
|---|
| 130 |
<td><input type="text" name="http_port" value="<?php echo (isset($thisItem['http_port']) ? $thisItem['http_port'] : ''); ?>"></td> |
|---|
| 131 |
</tr> |
|---|
| 132 |
|
|---|
| 133 |
<tr> |
|---|
| 134 |
<td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("Username to use in HTTP authentication")?></span></a></td> |
|---|
| 135 |
<td><input type="text" name="http_username" value="<?php echo (isset($thisItem['http_username']) ? $thisItem['http_username'] : ''); ?>"></td> |
|---|
| 136 |
</tr> |
|---|
| 137 |
|
|---|
| 138 |
<tr> |
|---|
| 139 |
<td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("Password to use in HTTP authentication")?></span></a></td> |
|---|
| 140 |
<td><input type="text" name="http_password" value="<?php echo (isset($thisItem['http_password']) ? $thisItem['http_password'] : ''); ?>"></td> |
|---|
| 141 |
</tr> |
|---|
| 142 |
|
|---|
| 143 |
<tr> |
|---|
| 144 |
<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> |
|---|
| 145 |
<td><input type="text" name="http_path" value="<?php echo (isset($thisItem['http_path']) ? $thisItem['http_path'] : ''); ?>"></td> |
|---|
| 146 |
</tr> |
|---|
| 147 |
|
|---|
| 148 |
<tr> |
|---|
| 149 |
<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> |
|---|
| 150 |
<td><input type="text" name="http_query" value="<?php echo (isset($thisItem['http_query']) ? $thisItem['http_query'] : ''); ?>"></td> |
|---|
| 151 |
</tr> |
|---|
| 152 |
</table> |
|---|
| 153 |
</div> |
|---|
| 154 |
</td> |
|---|
| 155 |
</tr> |
|---|
| 156 |
<tr> |
|---|
| 157 |
<td colspan="2"> |
|---|
| 158 |
<div id="mysql" style="display: none"> |
|---|
| 159 |
<table cellpadding="2" cellspacing="0" width="100%"> |
|---|
| 160 |
<tr><td colspan="2"><h5><?php echo _("MySQL") ?><hr></h5></td></tr> |
|---|
| 161 |
|
|---|
| 162 |
<tr> |
|---|
| 163 |
<td width="50%"><a href="#" class="info"><?php echo _("Host:")?><span><?php echo _("MySQL Host")?></span></a></td> |
|---|
| 164 |
<td><input type="text" name="mysql_host" value="<?php echo (isset($thisItem['mysql_host']) ? $thisItem['mysql_host'] : ''); ?>"></td> |
|---|
| 165 |
</tr> |
|---|
| 166 |
<tr> |
|---|
| 167 |
<td><a href="#" class="info"><?php echo _("Database:")?><span><?php echo _("Database name")?></span></a></td> |
|---|
| 168 |
<td><input type="text" name="mysql_dbname" value="<?php echo (isset($thisItem['mysql_dbname']) ? $thisItem['mysql_dbname'] : ''); ?>"></td> |
|---|
| 169 |
</tr> |
|---|
| 170 |
<tr> |
|---|
| 171 |
<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> |
|---|
| 172 |
<td><input type="text" name="mysql_query" value="<?php echo (isset($thisItem['mysql_query']) ? $thisItem['mysql_query'] : ''); ?>"></td> |
|---|
| 173 |
</tr> |
|---|
| 174 |
|
|---|
| 175 |
<tr> |
|---|
| 176 |
<td><a href="#" class="info"><?php echo _("Username:")?><span><?php echo _("MySQL Username")?></span></a></td> |
|---|
| 177 |
<td><input type="text" name="mysql_username" value="<?php echo (isset($thisItem['mysql_username']) ? $thisItem['mysql_username'] : ''); ?>"></td> |
|---|
| 178 |
</tr> |
|---|
| 179 |
<tr> |
|---|
| 180 |
<td><a href="#" class="info"><?php echo _("Password:")?><span><?php echo _("MySQL Password")?></span></a></td> |
|---|
| 181 |
<td><input type="text" name="mysql_password" value="<?php echo (isset($thisItem['mysql_password']) ? $thisItem['mysql_password'] : ''); ?>"></td> |
|---|
| 182 |
</tr> |
|---|
| 183 |
</table> |
|---|
| 184 |
</div> |
|---|
| 185 |
</td> |
|---|
| 186 |
</tr> |
|---|
| 187 |
<tr> |
|---|
| 188 |
<td colspan="2"> |
|---|
| 189 |
<div id="sugarcrm" style="display: none"> |
|---|
| 190 |
<table cellpadding="2" cellspacing="0" width="100%"> |
|---|
| 191 |
<tr><td colspan="2"><h5><?php echo _("SugarCRM") ?><hr></h5></td></tr> |
|---|
| 192 |
<tr><td colspan="2">Not yet implemented</td></tr> |
|---|
| 193 |
</table> |
|---|
| 194 |
</div> |
|---|
| 195 |
</td> |
|---|
| 196 |
</tr> |
|---|
| 197 |
|
|---|
| 198 |
<tr> |
|---|
| 199 |
<td colspan="2"><br><h6><input name="submit" type="submit" value="<?php echo _("Submit Changes")?>"></h6></td> |
|---|
| 200 |
</tr> |
|---|
| 201 |
</table> |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
<script language="javascript"> |
|---|
| 205 |
<!-- |
|---|
| 206 |
|
|---|
| 207 |
/* TODO: improve client side checking for different values of sourcetype */ |
|---|
| 208 |
|
|---|
| 209 |
var theForm = document.edit; |
|---|
| 210 |
theForm.description.focus(); |
|---|
| 211 |
|
|---|
| 212 |
displaySourceParameters(document.getElementById('sourcetype'), document.getElementById('sourcetype').selectedIndex); |
|---|
| 213 |
|
|---|
| 214 |
function edit_onsubmit() { |
|---|
| 215 |
|
|---|
| 216 |
defaultEmptyOK = false; |
|---|
| 217 |
if (!isAlphanumeric(theForm.description.value)) |
|---|
| 218 |
return warnInvalid(theForm.description, "Please enter a valid Description"); |
|---|
| 219 |
|
|---|
| 220 |
if (theForm.sourcetype.value == 'http') { |
|---|
| 221 |
if (isEmpty(theForm.http_host.value)) |
|---|
| 222 |
return warnInvalid(theForm.http_host, "Please enter a valid HTTP Host name"); |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
if (theForm.sourcetype.value == 'mysql') { |
|---|
| 226 |
if (isEmpty(theForm.mysql_host.value)) |
|---|
| 227 |
return warnInvalid(theForm.mysql_host, "Please enter a valid MySQL Host name"); |
|---|
| 228 |
|
|---|
| 229 |
if (isEmpty(theForm.mysql_dbname.value)) |
|---|
| 230 |
return warnInvalid(theForm.mysql_dbname, "Please enter a valid MySQL Database name"); |
|---|
| 231 |
|
|---|
| 232 |
if (isEmpty(theForm.mysql_query.value)) |
|---|
| 233 |
return warnInvalid(theForm.mysql_query, "Please enter a valid MySQL Query string"); |
|---|
| 234 |
|
|---|
| 235 |
if (isEmpty(theForm.mysql_username.value)) |
|---|
| 236 |
return warnInvalid(theForm.mysql_username, "Please enter a valid MySQL Username"); |
|---|
| 237 |
|
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
return true; |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
function displaySourceParameters(sourcetypeSelect, key) { |
|---|
| 244 |
if (sourcetypeSelect.options[key].value == 'http') { |
|---|
| 245 |
document.getElementById('http').style.display = ''; |
|---|
| 246 |
document.getElementById('mysql').style.display = 'none'; |
|---|
| 247 |
document.getElementById('sugarcrm').style.display = 'none'; |
|---|
| 248 |
} else if (sourcetypeSelect.options[key].value == 'mysql') { |
|---|
| 249 |
document.getElementById('http').style.display = 'none'; |
|---|
| 250 |
document.getElementById('mysql').style.display = ''; |
|---|
| 251 |
document.getElementById('sugarcrm').style.display = 'none'; |
|---|
| 252 |
} else if (sourcetypeSelect.options[key].value == 'sugarcrm') { |
|---|
| 253 |
document.getElementById('http').style.display = 'none'; |
|---|
| 254 |
document.getElementById('mysql').style.display = 'none'; |
|---|
| 255 |
document.getElementById('sugarcrm').style.display = ''; |
|---|
| 256 |
} else { |
|---|
| 257 |
document.getElementById('http').style.display = 'none'; |
|---|
| 258 |
document.getElementById('mysql').style.display = 'none'; |
|---|
| 259 |
document.getElementById('sugarcrm').style.display = 'none'; |
|---|
| 260 |
} |
|---|
| 261 |
} |
|---|
| 262 |
--> |
|---|
| 263 |
</script> |
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
</form> |
|---|
| 267 |
<?php |
|---|
| 268 |
} //end if action == delete |
|---|
| 269 |
?> |
|---|