2012-06-04 16:58:40 +02:00
|
|
|
<?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>
|
2013-09-19 13:47:09 +02:00
|
|
|
Portions created by the Initial Developer are Copyright (C) 2008-2013
|
2012-06-04 16:58:40 +02:00
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
|
|
|
|
require_once "root.php";
|
2013-07-06 08:03:27 +02:00
|
|
|
require_once "resources/require.php";
|
2013-07-06 07:50:55 +02:00
|
|
|
require_once "resources/check_auth.php";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('contact_view')) {
|
2012-06-04 16:58:40 +02:00
|
|
|
//access granted
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo "access denied";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2013-05-10 02:40:24 +02:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
|
|
|
|
require_once "app_languages.php";
|
|
|
|
|
foreach($text as $key => $value) {
|
|
|
|
|
$text[$key] = $value[$_SESSION['domain']['language']['code']];
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/header.php";
|
2014-07-10 02:32:50 +02:00
|
|
|
$document['title'] = $text['title-contacts'];
|
2013-05-10 02:40:24 +02:00
|
|
|
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/paging.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//get the search criteria
|
2013-07-10 01:44:44 +02:00
|
|
|
$search_all = strtolower(check_str($_GET["search_all"]));
|
2013-04-25 21:33:15 +02:00
|
|
|
$phone_number = check_str($_GET["phone_number"]);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//get variables used to control the order
|
2013-04-25 21:33:15 +02:00
|
|
|
$order_by = check_str($_GET["order_by"]);
|
|
|
|
|
$order = check_str($_GET["order"]);
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
//show the content
|
2014-10-18 08:49:34 +02:00
|
|
|
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <tr>\n";
|
2013-09-19 13:47:09 +02:00
|
|
|
echo " <td align=\"left\" valign=\"top\">\n";
|
2014-11-19 04:44:41 +01:00
|
|
|
echo " <b>".$text['header-contacts']."</b><br>\n";
|
2013-09-19 13:47:09 +02:00
|
|
|
echo " ".$text['description-contacts']."<br /><br />\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </td>\n";
|
2014-10-18 08:49:34 +02:00
|
|
|
echo " <td align=\"right\" valign=\"top\">\n";
|
2014-02-26 05:47:41 +01:00
|
|
|
echo " <form method=\"GET\" name=\"frm_search\" action=\"\">\n";
|
2014-10-18 08:49:34 +02:00
|
|
|
echo " <input class=\"formfld\" style='text-align: right;' type=\"text\" name=\"search_all\" value=\"$search_all\">\n";
|
2013-05-10 02:40:24 +02:00
|
|
|
echo " <input class=\"btn\" type=\"submit\" name=\"submit\" value=\"".$text['button-search']."\">\n";
|
2013-09-21 23:45:35 +02:00
|
|
|
if (permission_exists('contact_add')) {
|
2014-11-25 01:49:04 +01:00
|
|
|
echo "<input type='button' class='btn' alt='".$text['button-import']."' onclick=\"window.location='contact_import.php'\" value='".$text['button-import']."'>\n";
|
2012-09-10 19:51:59 +02:00
|
|
|
}
|
2014-02-26 05:47:41 +01:00
|
|
|
echo " </form>\n";
|
|
|
|
|
echo " </td>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </tr>\n";
|
|
|
|
|
echo "</table>\n";
|
2014-10-18 08:49:34 +02:00
|
|
|
echo "<br />\n";
|
|
|
|
|
|
|
|
|
|
//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
|
2014-10-18 09:14:41 +02:00
|
|
|
$user_group_uuids[] = $_SESSION["user_uuid"];
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2014-11-25 09:35:53 +01:00
|
|
|
//get contact sync sources
|
|
|
|
|
$sql = "select ";
|
|
|
|
|
$sql .= "contact_uuid, ";
|
|
|
|
|
$sql .= "contact_setting_value ";
|
|
|
|
|
$sql .= "from ";
|
|
|
|
|
$sql .= "v_contact_settings ";
|
|
|
|
|
$sql .= "where ";
|
|
|
|
|
$sql .= "domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
|
|
|
|
$sql .= "and contact_setting_category = 'sync' ";
|
|
|
|
|
$sql .= "and contact_setting_subcategory = 'source' ";
|
|
|
|
|
$sql .= "and contact_setting_name = 'array' ";
|
|
|
|
|
$sql .= "and contact_setting_value <> '' ";
|
|
|
|
|
$sql .= "and contact_setting_value is not null ";
|
|
|
|
|
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 .= " 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 .= " contact_uuid not in ( \n";
|
|
|
|
|
$sql .= " select contact_uuid from v_contact_groups ";
|
|
|
|
|
$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
|
|
|
|
$sql .= " ) \n";
|
|
|
|
|
$sql .= ") \n";
|
|
|
|
|
}
|
|
|
|
|
$prep_statement = $db->prepare(check_sql($sql));
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
|
|
|
|
if (count($result) > 0) {
|
|
|
|
|
foreach($result as $row) {
|
|
|
|
|
$contact_sync_sources[$row['contact_uuid']][] = $row['contact_setting_value'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unset ($sql, $prep_statement, $result);
|
|
|
|
|
|
|
|
|
|
//build query for paging and list
|
|
|
|
|
$sql = "select count(*) as num_rows ";
|
|
|
|
|
$sql .= "from v_contacts as c ";
|
2013-07-10 01:44:44 +02:00
|
|
|
$sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
2014-10-18 08:49:34 +02:00
|
|
|
if (sizeof($user_group_uuids) > 0) {
|
2014-11-25 09:35:53 +01:00
|
|
|
$sql .= "and ( \n"; //only contacts assigned to current user's group(s) and those not assigned to any group
|
2014-10-18 08:49:34 +02:00
|
|
|
$sql .= " 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 .= " contact_uuid not in ( \n";
|
|
|
|
|
$sql .= " select contact_uuid from v_contact_groups ";
|
|
|
|
|
$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' ";
|
|
|
|
|
$sql .= " ) \n";
|
|
|
|
|
$sql .= ") \n";
|
|
|
|
|
}
|
2013-04-25 21:33:15 +02:00
|
|
|
if (strlen($phone_number) > 0) {
|
|
|
|
|
$phone_number = preg_replace('{\D}', '', $phone_number);
|
2014-10-18 08:49:34 +02:00
|
|
|
$sql .= "and contact_uuid in ( ";
|
|
|
|
|
$sql .= " select contact_uuid from v_contact_phones ";
|
|
|
|
|
$sql .= " where phone_number like '%".$phone_number."%' ";
|
|
|
|
|
$sql .= ") \n";
|
2013-04-25 21:33:15 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (strlen($search_all) > 0) {
|
|
|
|
|
if (is_numeric($search_all)) {
|
2014-10-18 08:49:34 +02:00
|
|
|
$sql .= "and contact_uuid in ( \n";
|
|
|
|
|
$sql .= " select contact_uuid from v_contact_phones ";
|
|
|
|
|
$sql .= " where phone_number like '%".$search_all."%' ";
|
|
|
|
|
$sql .= ") \n";
|
2013-04-25 21:33:15 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2014-10-18 08:49:34 +02:00
|
|
|
$sql .= "and contact_uuid in ( \n";
|
2013-04-25 21:33:15 +02:00
|
|
|
$sql .= " select contact_uuid from v_contacts ";
|
|
|
|
|
$sql .= " where domain_uuid = '".$_SESSION['domain_uuid']."' \n";
|
2014-10-18 08:49:34 +02:00
|
|
|
$sql .= " and ( \n";
|
|
|
|
|
$sql .= " lower(contact_organization) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_name_given) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_name_family) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_nickname) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_title) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_category) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_role) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_email) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_url) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_time_zone) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_note) like '%".$search_all."%' or \n";
|
|
|
|
|
$sql .= " lower(contact_type) like '%".$search_all."%' \n";
|
|
|
|
|
$sql .= " ) \n";
|
|
|
|
|
$sql .= ") \n";
|
2013-04-25 21:33:15 +02:00
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-18 08:49:34 +02:00
|
|
|
if (strlen($order_by) > 0) {
|
|
|
|
|
$sql .= "order by ".$order_by." ".$order." ";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sql .= "order by contact_organization asc, contact_name_given asc, contact_name_family asc ";
|
|
|
|
|
}
|
2012-06-04 16:58:40 +02:00
|
|
|
$prep_statement = $db->prepare($sql);
|
|
|
|
|
if ($prep_statement) {
|
|
|
|
|
$prep_statement->execute();
|
|
|
|
|
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
if ($row['num_rows'] > 0) {
|
|
|
|
|
$num_rows = $row['num_rows'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$num_rows = '0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//prepare to page the results
|
2013-02-07 10:57:03 +01:00
|
|
|
$rows_per_page = 150;
|
2012-06-04 16:58:40 +02:00
|
|
|
$param = "";
|
|
|
|
|
$page = $_GET['page'];
|
2013-05-10 02:40:24 +02:00
|
|
|
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
|
|
|
|
|
list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
|
|
|
|
|
$offset = $rows_per_page * $page;
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2014-10-18 08:49:34 +02:00
|
|
|
//get the list
|
|
|
|
|
$sql = str_replace('count(*) as num_rows', '*', $sql); // modify query created above
|
|
|
|
|
$sql .= "limit ".$rows_per_page." offset ".$offset." ";
|
2012-06-04 16:58:40 +02:00
|
|
|
$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);
|
|
|
|
|
|
|
|
|
|
$c = 0;
|
|
|
|
|
$row_style["0"] = "row_style0";
|
|
|
|
|
$row_style["1"] = "row_style1";
|
|
|
|
|
|
2014-06-22 05:24:36 +02:00
|
|
|
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "<tr>\n";
|
2013-05-10 02:40:24 +02:00
|
|
|
echo th_order_by('contact_type', $text['label-contact_type'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_organization', $text['label-contact_organization'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_name_given', $text['label-contact_name_given'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_name_family', $text['label-contact_name_family'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_nickname', $text['label-contact_nickname'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_title', $text['label-contact_title'], $order_by, $order);
|
|
|
|
|
echo th_order_by('contact_role', $text['label-contact_role'], $order_by, $order);
|
2014-11-25 09:35:53 +01:00
|
|
|
echo "<th style='padding: 0px;'> </th>\n";
|
2014-02-26 05:47:41 +01:00
|
|
|
echo "<td class='list_control_icons'>";
|
|
|
|
|
echo "<a href='contact_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo "</td>\n";
|
2014-06-22 05:24:36 +02:00
|
|
|
echo "</tr>\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
|
|
|
|
if ($result_count > 0) {
|
|
|
|
|
foreach($result as $row) {
|
2014-06-22 05:24:36 +02:00
|
|
|
$tr_link = "href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'";
|
|
|
|
|
echo "<tr ".$tr_link.">\n";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " <td valign='top' class='".$row_style[$c]."'>".ucwords($row['contact_type'])." </td>\n";
|
2014-11-25 09:35:53 +01:00
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='width: 35%; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_organization']."</a> </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_given']."</a> </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'><a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'>".$row['contact_name_family']."</a> </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='white-space: nowrap;'>".$row['contact_nickname']." </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='width: 10%; max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['contact_title']." </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='width: 10%; max-width: 40px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'>".$row['contact_role']." </td>\n";
|
|
|
|
|
echo " <td valign='top' class='".$row_style[$c]."' style='padding: 2px 2px; text-align: center; width: 25px;'>";
|
|
|
|
|
if (sizeof($contact_sync_sources[$row['contact_uuid']]) > 0) {
|
|
|
|
|
foreach ($contact_sync_sources[$row['contact_uuid']] as $contact_sync_source) {
|
|
|
|
|
switch ($contact_sync_source) {
|
|
|
|
|
case 'google': echo "<img src='resources/images/icon_gcontacts.png' style='width: 21px; height: 21px; border: none; padding-left: 2px;' alt='".$text['label-contact_google']."'>"; break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { echo " "; }
|
|
|
|
|
echo " </td>\n";
|
2014-02-26 05:47:41 +01:00
|
|
|
echo " <td class='list_control_icons'>";
|
|
|
|
|
echo "<a href='contact_edit.php?id=".$row['contact_uuid']."&query_string=".urlencode($_SERVER["QUERY_STRING"])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
|
|
|
|
|
echo "<a href='contact_delete.php?id=".$row['contact_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
if ($c==0) { $c=1; } else { $c=0; }
|
|
|
|
|
} //end foreach
|
|
|
|
|
unset($sql, $result, $row_count);
|
|
|
|
|
} //end if results
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
|
|
|
|
echo "<td colspan='15' align='left'>\n";
|
|
|
|
|
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
|
|
|
|
|
echo " <tr>\n";
|
|
|
|
|
echo " <td width='33.3%' nowrap> </td>\n";
|
|
|
|
|
echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
|
2014-02-26 05:47:41 +01:00
|
|
|
echo " <td class='list_control_icons'>";
|
|
|
|
|
echo "<a href='contact_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
|
2012-06-04 16:58:40 +02:00
|
|
|
echo " </td>\n";
|
|
|
|
|
echo " </tr>\n";
|
|
|
|
|
echo " </table>\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
|
|
|
|
|
//include the footer
|
2013-07-06 08:29:50 +02:00
|
|
|
require_once "resources/footer.php";
|
2012-06-04 16:58:40 +02:00
|
|
|
?>
|