Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists('contact_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //includes and title $document['title'] = $text['title-contacts']; require_once "resources/header.php"; //get the search criteria $search_all = strtolower($_GET["search_all"]); $phone_number = $_GET["phone_number"]; //get variables used to control the order $order_by = $_GET["order_by"]; $order = $_GET["order"]; //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"]; //get contact settings - sync sources $sql = "select "; $sql .= "contact_uuid, "; $sql .= "contact_setting_value "; $sql .= "from "; $sql .= "v_contact_settings "; $sql .= "where "; $sql .= "domain_uuid = :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 (!(if_group("superadmin") || if_group("admin"))) { $sql .= "and ( "; //only contacts assigned to current user's group(s) and those not assigned to any group $sql .= " contact_uuid in ( "; $sql .= " select contact_uuid from v_contact_groups "; $sql .= " where "; if (is_array($user_group_uuids) && @sizeof($user_group_uuids) != 0) { foreach ($user_group_uuids as $index => $user_group_uuid) { if (is_uuid($user_group_uuid)) { $sql_where_or[] = "group_uuid = :group_uuid_".$index; $parameters['group_uuid_'.$index] = $user_group_uuid; } } if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) { $sql .= " ( ".implode(' or ', $sql_where_or)." ) "; } unset($sql_where_or, $index, $user_group_uuid); } $sql .= " and domain_uuid = :domain_uuid "; $sql .= " ) "; $sql .= " or "; $sql .= " contact_uuid not in ( "; $sql .= " select contact_uuid from v_contact_groups "; $sql .= " where group_uuid = :group_uuid "; $sql .= " and domain_uuid = :domain_uuid "; $sql .= " ) "; $sql .= ") "; } $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['group_uuid'] = $_SESSION['group_uuid']; $database = new database; $result = $database->select($sql, $parameters, 'all'); if (is_array($result) && @sizeof($result) != 0) { foreach($result as $row) { $contact_sync_sources[$row['contact_uuid']][] = $row['contact_setting_value']; } } unset($sql, $parameters, $result); //build query for paging and list $sql = "select count(*) "; $sql .= "from v_contacts as c "; $sql .= "where domain_uuid = :domain_uuid "; if (!(if_group("superadmin") || if_group("admin"))) { $sql .= "and ( "; //only contacts assigned to current user's group(s) and those not assigned to any group $sql .= " contact_uuid in ( "; $sql .= " select contact_uuid from v_contact_groups "; $sql .= " where "; if (is_array($user_group_uuids) && @sizeof($user_group_uuids) != 0) { foreach ($user_group_uuids as $index => $user_group_uuid) { if (is_uuid($user_group_uuid)) { $sql_where_or[] = "group_uuid = :group_uuid_".$index; $parameters['group_uuid_'.$index] = $user_group_uuid; } } if (is_array($sql_where_or) && @sizeof($sql_where_or) != 0) { $sql .= " ( ".implode(' or ', $sql_where_or)." ) "; } unset($sql_where_or, $index, $user_group_uuid); } $sql .= " and domain_uuid = :domain_uuid "; $sql .= " ) "; $sql .= " or contact_uuid in ( "; $sql .= " select contact_uuid from v_contact_users "; $sql .= " where user_uuid = :user_uuid "; $sql .= " and domain_uuid = :domain_uuid "; $sql .= ""; $sql .= " ) "; $sql .= ") "; $parameters['user_uuid'] = $_SESSION['user_uuid']; } if (strlen($phone_number) > 0) { $phone_number = preg_replace('{\D}', '', $phone_number); $sql .= "and contact_uuid in ( "; $sql .= " select contact_uuid from v_contact_phones "; $sql .= " where phone_number like :phone_number "; $sql .= ") "; $parameters['phone_number'] = '%'.$phone_number.'%'; } else { if (strlen($search_all) > 0) { if (is_numeric($search_all)) { $sql .= "and contact_uuid in ( "; $sql .= " select contact_uuid from v_contact_phones "; $sql .= " where phone_number like :search_all "; $sql .= ") "; } else { $sql .= "and contact_uuid in ( "; $sql .= " select contact_uuid from v_contacts "; $sql .= " where domain_uuid = :domain_uuid "; $sql .= " and ( "; $sql .= " lower(contact_organization) like :search_all or "; $sql .= " lower(contact_name_given) like :search_all or "; $sql .= " lower(contact_name_family) like :search_all or "; $sql .= " lower(contact_nickname) like :search_all or "; $sql .= " lower(contact_title) like :search_all or "; $sql .= " lower(contact_category) like :search_all or "; $sql .= " lower(contact_role) like :search_all or "; $sql .= " lower(contact_url) like :search_all or "; $sql .= " lower(contact_time_zone) like :search_all or "; $sql .= " lower(contact_note) like :search_all or "; $sql .= " lower(contact_type) like :search_all "; $sql .= " ) "; $sql .= ") "; } $parameters['search_all'] = '%'.$search_all.'%'; } } $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $param = ""; $page = $_GET['page']; if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } list($paging_controls_mini, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page, true); //top list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); //bottom $offset = $rows_per_page * $page; //get the list $sql = str_replace('count(*)', '*, (select a.contact_attachment_uuid from v_contact_attachments as a where a.contact_uuid = c.contact_uuid and a.attachment_primary = 1) as contact_attachment_uuid', $sql); if ($order_by != '') { $sql .= order_by($order_by, $order); $sql .= ", contact_organization asc "; } else { $contact_default_sort_column = $_SESSION['contacts']['default_sort_column']['text'] != '' ? $_SESSION['contacts']['default_sort_column']['text'] : "last_mod_date"; $contact_default_sort_order = $_SESSION['contacts']['default_sort_order']['text'] != '' ? $_SESSION['contacts']['default_sort_order']['text'] : "desc"; $sql .= order_by($contact_default_sort_column, $contact_default_sort_order); if ($db_type == "pgsql") { $sql .= " nulls last "; } } $sql .= limit_offset($rows_per_page, $offset); $database = new database; $contacts = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //styles echo "\n"; //ticket attachment layer echo "\n"; //show the content echo "\n"; echo " \n"; echo " \n"; echo " \n"; if ($paging_controls_mini != '') { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['header-contacts']." (".$num_rows.")\n"; echo "

"; echo "
\n"; echo "
\n"; echo " \n"; echo " \n"; if (permission_exists('contact_add')) { echo "\n"; } echo "
\n"; echo "
".$paging_controls_mini."
\n"; echo " ".$text['description-contacts']."

\n"; echo "
\n"; echo "
\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "\n"; echo "\n"; 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 "\n"; 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); echo "\n"; echo "\n"; echo "\n"; if (is_array($contacts) && @sizeof($contacts) != 0) { foreach($contacts as $row) { $tr_link = "href='contact_edit.php?id=".escape($row['contact_uuid'])."&query_string=".urlencode($_SERVER["QUERY_STRING"])."'"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } //end foreach unset($contacts, $row); } //end if results echo "\n"; echo "\n"; echo "\n"; echo "
  "; echo "$v_link_label_add"; echo "
".ucwords(escape($row['contact_type']))." ".escape($row['contact_organization'])." ".escape($row['contact_name_given'])." ".escape($row['contact_name_family'])." ".escape($row['contact_nickname'])." ".escape($row['contact_title'])." ".escape($row['contact_role'])." "; 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 "".$text["; break; } } } else { echo " "; } echo " "; echo "$v_link_label_edit"; echo "$v_link_label_delete"; echo "
\n"; echo " $v_link_label_add"; echo "
"; echo $paging_controls; echo "

"; echo ""; //javascript echo "\n"; //include the footer require_once "resources/footer.php"; ?>