diff --git a/app/operator_panel/autocomplete.php b/app/operator_panel/autocomplete.php new file mode 100644 index 0000000000..4d9f60402e --- /dev/null +++ b/app/operator_panel/autocomplete.php @@ -0,0 +1,122 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2015 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +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 "
"; }
+		echo $resp;
+		if (isset($_GET['debug'])) { echo "
"; } + } + +?> \ No newline at end of file diff --git a/app/operator_panel/index.php b/app/operator_panel/index.php index d2b52d28c0..aaee3786a7 100644 --- a/app/operator_panel/index.php +++ b/app/operator_panel/index.php @@ -75,6 +75,47 @@ require_once "resources/header.php"; + + + + +