Operator Panel: Added Contact search/auto-complete.
This commit is contained in:
parent
005815f5c4
commit
b2e6a83829
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
/*
|
||||
FusionPBX
|
||||
Version: MPL 1.1
|
||||
|
||||
The contents of this file are subject to the Mozilla Public License Version
|
||||
1.1 (the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
http://www.mozilla.org/MPL/
|
||||
|
||||
Software distributed under the License is distributed on an "AS IS" basis,
|
||||
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
for the specific language governing rights and limitations under the
|
||||
License.
|
||||
|
||||
The Original Code is FusionPBX
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2015
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
require_once "root.php";
|
||||
require_once "resources/require.php";
|
||||
require_once "resources/check_auth.php";
|
||||
if (permission_exists('contact_view')) {
|
||||
//access granted
|
||||
}
|
||||
else {
|
||||
exit;
|
||||
}
|
||||
|
||||
$term = check_str($_GET['term']);
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//retrieve current user's assigned groups (uuids)
|
||||
foreach ($_SESSION['groups'] as $group_data) {
|
||||
$user_group_uuids[] = $group_data['group_uuid'];
|
||||
}
|
||||
//add user's uuid to group uuid list to include private (non-shared) contacts
|
||||
$user_group_uuids[] = $_SESSION["user_uuid"];
|
||||
|
||||
//build query for suggestion list
|
||||
$sql = "select ";
|
||||
$sql .= "c.contact_organization, ";
|
||||
$sql .= "c.contact_name_given, ";
|
||||
$sql .= "c.contact_name_middle, ";
|
||||
$sql .= "c.contact_name_family, ";
|
||||
$sql .= "c.contact_nickname, ";
|
||||
$sql .= "p.phone_number, ";
|
||||
$sql .= "p.phone_label ";
|
||||
$sql .= "from ";
|
||||
$sql .= "v_contacts as c, ";
|
||||
$sql .= "v_contact_phones as p ";
|
||||
$sql .= "where ";
|
||||
$sql .= "( ";
|
||||
$sql .= " lower(c.contact_organization) like lower('%".$term."%') or ";
|
||||
$sql .= " lower(c.contact_name_given) like lower('%".$term."%') or ";
|
||||
$sql .= " lower(c.contact_name_middle) like lower('%".$term."%') or ";
|
||||
$sql .= " lower(c.contact_name_family) like lower('%".$term."%') or ";
|
||||
$sql .= " lower(c.contact_nickname) like lower('%".$term."%') or ";
|
||||
$sql .= " p.phone_number like '%".$term."%' ";
|
||||
$sql .= ") ";
|
||||
$sql .= "and c.contact_uuid = p.contact_uuid ";
|
||||
$sql .= "and c.domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
if (sizeof($user_group_uuids) > 0) {
|
||||
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
|
||||
$sql .= " c.contact_uuid in ( \n";
|
||||
$sql .= " select contact_uuid from v_contact_groups ";
|
||||
$sql .= " where group_uuid in ('".implode("','", $user_group_uuids)."') ";
|
||||
$sql .= " and domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= " ) \n";
|
||||
$sql .= " or \n";
|
||||
$sql .= " c.contact_uuid not in ( \n";
|
||||
$sql .= " select contact_uuid from v_contact_groups ";
|
||||
$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
||||
$sql .= " ) \n";
|
||||
$sql .= ") \n";
|
||||
}
|
||||
$sql .= "and p.phone_type_voice = 1 ";
|
||||
$sql .= "order by contact_organization desc, contact_name_given asc, contact_name_family asc ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
$result_count = count($result);
|
||||
unset($prep_statement, $sql);
|
||||
|
||||
if ($result_count > 0) {
|
||||
$resp .= "[\n";
|
||||
|
||||
foreach($result as $row) {
|
||||
|
||||
//build suggestions
|
||||
if ($row['contact_organization'] != '') { $values[] = $row['contact_organization']; }
|
||||
|
||||
if ($row['contact_name_given'] != '') { $names = $row['contact_name_given']; }
|
||||
if ($row['contact_name_middle'] != '') { $names .= " ".$row['contact_name_middle']; }
|
||||
if ($row['contact_name_family'] != '') { $names .= " ".$row['contact_name_family']; }
|
||||
if ($names != '') { $values[] = $names; }
|
||||
|
||||
if ($row['contact_nickname'] != '') { $values[] = $row['contact_nickname']; }
|
||||
|
||||
$suggestions[] = "{ \"label\": \"".(implode(', ', $values)." - ".format_phone($row['phone_number']).(($row['phone_label'] != '') ? " (".$row['phone_label'].")" : null))."\", \"value\": \"".$row['phone_number']."\" }";
|
||||
unset($values, $names);
|
||||
}
|
||||
unset($sql, $result, $row_count);
|
||||
|
||||
$resp .= implode(",\n", $suggestions)."\n";
|
||||
$resp .= "]";
|
||||
|
||||
if (isset($_GET['debug'])) { echo "<pre>"; }
|
||||
echo $resp;
|
||||
if (isset($_GET['debug'])) { echo "</pre>"; }
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -75,6 +75,47 @@ require_once "resources/header.php";
|
|||
<input type='hidden' class='formfld' id='vd_ext_from' value=''>
|
||||
<input type='hidden' class='formfld' id='vd_ext_to' value=''>
|
||||
|
||||
<!-- autocomplete for contact lookup -->
|
||||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
|
||||
<script language="JavaScript" type="text/javascript" src="<?php echo PROJECT_PATH; ?>/resources/jquery/jquery-ui-1.9.2.min.js"></script>
|
||||
<style>
|
||||
.ui-widget {
|
||||
font-family: arial;
|
||||
font-size: 12px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.ui-autocomplete {
|
||||
cursor: default;
|
||||
position: absolute;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
white-space: nowrap;
|
||||
width: auto;
|
||||
border: 1px solid #c0c0c0;
|
||||
}
|
||||
|
||||
.ui-menu .ui-menu-item a {
|
||||
padding-right: 25px;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
border-color: #fff;
|
||||
background-image: none;
|
||||
background-color: #fff;
|
||||
color: #444;
|
||||
}
|
||||
|
||||
.ui-menu .ui-menu-item a:hover {
|
||||
padding-right: 25px;
|
||||
color: #5082ca;
|
||||
border: 1px solid white;
|
||||
background-image: none;
|
||||
background-color: #fff;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
//ajax refresh
|
||||
var refresh = 1950;
|
||||
|
|
@ -217,12 +258,20 @@ require_once "resources/header.php";
|
|||
//call destination
|
||||
function call_destination(from_ext, destination) {
|
||||
if (destination != '') {
|
||||
cmd = get_originate_cmd(from_ext+'@<?php echo $_SESSION["domain_name"]?>', destination); //make a call
|
||||
if (!isNaN(parseFloat(destination)) && isFinite(destination)) {
|
||||
cmd = get_originate_cmd(from_ext+'@<?php echo $_SESSION["domain_name"]?>', destination); //make a call
|
||||
if (cmd != '') {
|
||||
send_cmd('exec.php?cmd='+escape(cmd));
|
||||
$('#destination_'+from_ext).autocomplete("destroy");
|
||||
$('#destination_'+from_ext).removeAttr('onblur');
|
||||
toggle_destination(from_ext);
|
||||
refresh_start();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cmd != '') {
|
||||
send_cmd('exec.php?cmd='+escape(cmd));
|
||||
else {
|
||||
toggle_destination(from_ext);
|
||||
}
|
||||
refresh_start();
|
||||
}
|
||||
|
||||
//kill call
|
||||
|
|
@ -269,12 +318,22 @@ require_once "resources/header.php";
|
|||
//hide/show destination input field
|
||||
function toggle_destination(ext) {
|
||||
refresh_stop();
|
||||
$('#destination_control_'+ext).fadeToggle(200);
|
||||
$('#destination_'+ext).fadeToggle(200, function(){
|
||||
if ($('#destination_'+ext).is(':visible')) {
|
||||
$('#destination_'+ext).focus();
|
||||
$('#destination_'+ext).autocomplete({
|
||||
source: "autocomplete.php",
|
||||
minLength: 3,
|
||||
select: function(event, ui) {
|
||||
$('#destination_'+ext).val(ui.item.value);
|
||||
$('#frm_destination_'+ext).submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
$('#destination_'+ext).val('');
|
||||
$('#destination_'+ext).autocomplete('destroy');
|
||||
refresh_start();
|
||||
}
|
||||
});
|
||||
|
|
@ -379,4 +438,4 @@ foreach ($_SESSION['user']['extension'] as $assigned_extensions) {
|
|||
|
||||
<?php
|
||||
require_once "resources/footer.php";
|
||||
?>
|
||||
?>
|
||||
|
|
@ -27,7 +27,6 @@ include "root.php";
|
|||
require_once "resources/require.php";
|
||||
require_once "resources/check_auth.php";
|
||||
require_once "./resources/functions/get_call_activity.php";
|
||||
|
||||
if (permission_exists('operator_panel_view')) {
|
||||
//access granted
|
||||
}
|
||||
|
|
@ -179,6 +178,21 @@ foreach ($activity as $extension => $ext) {
|
|||
}
|
||||
$dir_icon = 'outbound';
|
||||
}
|
||||
else if ($ext['state'] == 'CS_HIBERNATE') {
|
||||
if ($ext['callstate'] == 'ACTIVE') {
|
||||
$ext_state = 'active';
|
||||
if ($ext['direction'] == 'inbound') {
|
||||
$call_name = $activity[(int) $ext['dest']]['effective_caller_id_name'];
|
||||
$call_number = format_phone((int) $ext['dest']);
|
||||
$dir_icon = 'outbound';
|
||||
}
|
||||
else if ($ext['direction'] == 'outbound') {
|
||||
$call_name = $activity[(int) $ext['cid_num']]['effective_caller_id_name'];
|
||||
$call_number = format_phone((int) $ext['cid_num']);
|
||||
$dir_icon = 'inbound';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($ext['state'] == 'CS_CONSUME_MEDIA' || $ext['state'] == 'CS_EXCHANGE_MEDIA') {
|
||||
if ($ext['state'] == 'CS_CONSUME_MEDIA' && $ext['callstate'] == 'RINGING' && $ext['direction'] == 'outbound') {
|
||||
$ext_state = 'ringing';
|
||||
|
|
@ -333,10 +347,10 @@ foreach ($activity as $extension => $ext) {
|
|||
}
|
||||
else {
|
||||
if (in_array($extension, $_SESSION['user']['extensions'])) {
|
||||
$block .= " <img src='resources/images/keypad.png' style='width: 12px; height: 12px; border: none; margin-top: 26px; cursor: pointer;' align='right' onclick=\"toggle_destination('".$extension."');\">";
|
||||
$block .= " <form onsubmit=\"call_destination('".$extension."', document.getElementById('destination_".$extension."').value); return false;\">";
|
||||
$block .= " <input type='text' class='formfld' name='destination' id='destination_".$extension."' style='width: 110px; min-width: 110px; max-width: 110px; margin-top: 10px; text-align: center; display: none;' onblur=\"if (this.value == '') { refresh_start(); }\">";
|
||||
$block .= " </form>";
|
||||
$block .= " <img id='destination_control_".$extension."' src='resources/images/keypad.png' style='width: 12px; height: 12px; border: none; margin-top: 26px; cursor: pointer;' align='right' onclick=\"toggle_destination('".$extension."');\">";
|
||||
$block .= " <form id='frm_destination_".$extension."' onsubmit=\"call_destination('".$extension."', document.getElementById('destination_".$extension."').value); return false;\">";
|
||||
$block .= " <input type='text' class='formfld' name='destination' id='destination_".$extension."' style='width: 110px; min-width: 110px; max-width: 110px; margin-top: 10px; text-align: center; display: none;' onblur=\"toggle_destination('".$extension."');\">";
|
||||
$block .= " </form>\n";
|
||||
}
|
||||
}
|
||||
$block .= " </td>";
|
||||
|
|
@ -402,12 +416,13 @@ else {
|
|||
echo "<br><br>";
|
||||
|
||||
if (isset($_GET['debug'])) {
|
||||
echo '$activity<br>';
|
||||
echo "<textarea style='width: 100%; height: 600px; overflow: scroll;' onfocus='refresh_stop();' onblur='refresh_start();'>";
|
||||
print_r($activity);
|
||||
echo "</textarea>";
|
||||
echo "<br><br>";
|
||||
|
||||
echo '$_SESSION...';
|
||||
echo '$_SESSION<br>';
|
||||
echo "<textarea style='width: 100%; height: 600px; overflow: scroll;' onfocus='refresh_stop();' onblur='refresh_start();'>";
|
||||
print_r($_SESSION);
|
||||
echo "</textarea>";
|
||||
|
|
|
|||
Loading…
Reference in New Issue