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 >
2019-09-26 04:35:09 +02:00
Portions created by the Initial Developer are Copyright ( C ) 2008 - 2019
2012-06-04 16:58:40 +02:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
*/
2016-08-05 04:00:23 +02:00
//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 ;
}
2013-05-10 02:40:24 +02:00
//add multi-lingual support
2015-01-18 11:06:08 +01:00
$language = new text ;
$text = $language -> get ();
2013-05-10 02:40:24 +02:00
2015-01-18 11:06:08 +01:00
//includes and title
$document [ 'title' ] = $text [ 'title-contacts' ];
2015-02-25 23:46:58 +01:00
require_once " resources/header.php " ;
2012-06-04 16:58:40 +02:00
//get the search criteria
2019-07-26 17:41:41 +02:00
$search_all = strtolower ( $_GET [ " search_all " ]);
$phone_number = $_GET [ " phone_number " ];
2012-06-04 16:58:40 +02:00
//get variables used to control the order
2019-07-26 17:41:41 +02:00
$order_by = $_GET [ " order_by " ];
$order = $_GET [ " order " ];
2012-06-04 16:58:40 +02:00
2015-02-25 23:46:58 +01:00
//retrieve current user's assigned groups (uuids)
2014-10-18 08:49:34 +02:00
foreach ( $_SESSION [ 'groups' ] as $group_data ) {
$user_group_uuids [] = $group_data [ 'group_uuid' ];
}
2015-10-20 09:39:54 +02:00
//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
2018-01-10 21:37:26 +01:00
//get contact settings - sync sources
2015-02-25 23:46:58 +01:00
$sql = " select " ;
$sql .= " contact_uuid, " ;
$sql .= " contact_setting_value " ;
$sql .= " from " ;
$sql .= " v_contact_settings " ;
$sql .= " where " ;
2019-07-26 17:41:41 +02:00
$sql .= " domain_uuid = :domain_uuid " ;
2015-02-25 23:46:58 +01:00
$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 " ;
2016-01-19 05:46:49 +01:00
if ( ! ( if_group ( " superadmin " ) || if_group ( " admin " ))) {
2019-07-26 17:41:41 +02:00
$sql .= " and ( " ; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( " ;
2015-02-25 23:46:58 +01:00
$sql .= " select contact_uuid from v_contact_groups " ;
2019-07-26 17:41:41 +02:00
$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 ( " ;
2015-02-25 23:46:58 +01:00
$sql .= " select contact_uuid from v_contact_groups " ;
2019-07-26 17:41:41 +02:00
$sql .= " where group_uuid = :group_uuid " ;
$sql .= " and domain_uuid = :domain_uuid " ;
$sql .= " ) " ;
$sql .= " ) " ;
2015-02-25 23:46:58 +01:00
}
2019-07-26 17:41:41 +02:00
$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 ) {
2015-02-25 23:46:58 +01:00
foreach ( $result as $row ) {
$contact_sync_sources [ $row [ 'contact_uuid' ]][] = $row [ 'contact_setting_value' ];
2014-11-25 09:35:53 +01:00
}
2015-02-25 23:46:58 +01:00
}
2019-07-26 17:41:41 +02:00
unset ( $sql , $parameters , $result );
2014-11-25 09:35:53 +01:00
2015-02-25 23:46:58 +01:00
//build query for paging and list
2019-07-26 17:41:41 +02:00
$sql = " select count(*) " ;
2015-02-25 23:46:58 +01:00
$sql .= " from v_contacts as c " ;
2019-07-26 17:41:41 +02:00
$sql .= " where domain_uuid = :domain_uuid " ;
2016-01-19 05:46:49 +01:00
if ( ! ( if_group ( " superadmin " ) || if_group ( " admin " ))) {
2019-07-26 17:41:41 +02:00
$sql .= " and ( " ; //only contacts assigned to current user's group(s) and those not assigned to any group
$sql .= " contact_uuid in ( " ;
2015-02-25 23:46:58 +01:00
$sql .= " select contact_uuid from v_contact_groups " ;
2019-07-26 17:41:41 +02:00
$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 ( " ;
2016-01-19 05:46:49 +01:00
$sql .= " select contact_uuid from v_contact_users " ;
2019-07-26 17:41:41 +02:00
$sql .= " where user_uuid = :user_uuid " ;
$sql .= " and domain_uuid = :domain_uuid " ;
2016-01-19 05:46:49 +01:00
$sql .= " " ;
2019-07-26 17:41:41 +02:00
$sql .= " ) " ;
$sql .= " ) " ;
$parameters [ 'user_uuid' ] = $_SESSION [ 'user_uuid' ];
2015-02-25 23:46:58 +01:00
}
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 " ;
2019-07-26 17:41:41 +02:00
$sql .= " where phone_number like :phone_number " ;
$sql .= " ) " ;
$parameters [ 'phone_number' ] = '%' . $phone_number . '%' ;
2015-02-25 23:46:58 +01:00
}
else {
if ( strlen ( $search_all ) > 0 ) {
if ( is_numeric ( $search_all )) {
2019-07-26 17:41:41 +02:00
$sql .= " and contact_uuid in ( " ;
2015-02-25 23:46:58 +01:00
$sql .= " select contact_uuid from v_contact_phones " ;
2019-07-26 17:41:41 +02:00
$sql .= " where phone_number like :search_all " ;
$sql .= " ) " ;
2015-02-25 23:46:58 +01:00
}
else {
2019-07-26 17:41:41 +02:00
$sql .= " and contact_uuid in ( " ;
2015-02-25 23:46:58 +01:00
$sql .= " select contact_uuid from v_contacts " ;
2019-07-26 17:41:41 +02:00
$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 .= " ) " ;
2012-06-04 16:58:40 +02:00
}
2019-07-26 17:41:41 +02:00
$parameters [ 'search_all' ] = '%' . $search_all . '%' ;
2012-06-04 16:58:40 +02:00
}
2015-02-25 23:46:58 +01:00
}
2019-07-26 17:41:41 +02:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$database = new database ;
$num_rows = $database -> select ( $sql , $parameters , 'column' );
2012-06-04 16:58:40 +02:00
2015-02-25 23:46:58 +01:00
//prepare to page the results
2016-03-29 07:02:11 +02:00
$rows_per_page = ( $_SESSION [ 'domain' ][ 'paging' ][ 'numeric' ] != '' ) ? $_SESSION [ 'domain' ][ 'paging' ][ 'numeric' ] : 50 ;
2015-02-25 23:46:58 +01:00
$param = " " ;
$page = $_GET [ 'page' ];
if ( strlen ( $page ) == 0 ) { $page = 0 ; $_GET [ 'page' ] = 0 ; }
2015-04-01 11:00:17 +02:00
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
2015-02-25 23:46:58 +01:00
$offset = $rows_per_page * $page ;
2012-06-04 16:58:40 +02:00
2015-02-25 23:46:58 +01:00
//get the list
2019-07-26 17:41:41 +02:00
$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 " ;
2015-02-25 23:46:58 +01:00
}
else {
2019-07-26 17:41:41 +02:00
$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 );
2015-10-20 10:05:03 +02:00
if ( $db_type == " pgsql " ) {
2019-07-26 17:41:41 +02:00
$sql .= " nulls last " ;
2015-10-20 10:05:03 +02:00
}
2015-02-25 23:46:58 +01:00
}
2019-07-26 17:41:41 +02:00
$sql .= limit_offset ( $rows_per_page , $offset );
$database = new database ;
$contacts = $database -> select ( $sql , $parameters , 'all' );
unset ( $sql , $parameters );
2015-02-25 23:46:58 +01:00
2019-03-29 01:53:01 +01:00
//styles
echo " <style> \n " ;
echo " #contact_attachment_layer { \n " ;
echo " z-index: 999999; \n " ;
echo " position: absolute; \n " ;
echo " left: 0px; \n " ;
echo " top: 0px; \n " ;
echo " right: 0px; \n " ;
echo " bottom: 0px; \n " ;
echo " text-align: center; \n " ;
echo " vertical-align: middle; \n " ;
echo " } \n " ;
echo " </style> \n " ;
//ticket attachment layer
echo " <div id='contact_attachment_layer' style='display: none;'></div> \n " ;
2015-02-25 23:46:58 +01:00
//show the content
echo " <table width='100%' border='0' cellpadding='0' cellspacing='0'> \n " ;
echo " <tr> \n " ;
2016-08-05 04:00:23 +02:00
echo " <td align='left' valign='top' width='50%'> \n " ;
2019-01-25 06:32:53 +01:00
echo " <b> " . $text [ 'header-contacts' ] . " ( " . $num_rows . " )</b> \n " ;
2016-08-05 04:00:23 +02:00
echo " <br /><br /> " ;
echo " </td> \n " ;
echo " <td align='right' valign='top' width='50%' nowrap='nowrap'> \n " ;
echo " <form method='get' name='frm_search' action=''> \n " ;
2018-07-02 18:44:14 +02:00
echo " <input class='formfld' style='text-align: right;' type='text' name='search_all' id='search_all' value= \" " . escape ( $search_all ) . " \" > \n " ;
2016-08-05 04:00:23 +02:00
echo " <input class='btn' type='submit' name='submit' value= \" " . $text [ 'button-search' ] . " \" > \n " ;
2015-02-25 23:46:58 +01:00
if ( permission_exists ( 'contact_add' )) {
2015-04-01 11:00:17 +02:00
echo " <input type='button' class='btn' alt=' " . $text [ 'button-import' ] . " ' onclick= \" window.location='contact_import.php' \" value=' " . $text [ 'button-import' ] . " '> \n " ;
2015-02-25 23:46:58 +01:00
}
2016-08-05 04:00:23 +02:00
echo " </form> \n " ;
echo " </td> \n " ;
2015-04-01 11:06:02 +02:00
if ( $paging_controls_mini != '' ) {
2018-01-10 21:37:26 +01:00
echo " <td valign='top' nowrap='nowrap' style='padding-left: 15px;'> " . $paging_controls_mini . " </td> \n " ;
2015-04-01 11:06:02 +02:00
}
2016-08-05 04:00:23 +02:00
echo " </tr> \n " ;
echo " <tr> \n " ;
echo " <td colspan='3'> \n " ;
echo " " . $text [ 'description-contacts' ] . " <br /><br /> \n " ;
echo " </td> \n " ;
2015-02-25 23:46:58 +01:00
echo " </tr> \n " ;
echo " </table> \n " ;
echo " <br /> \n " ;
2012-06-04 16:58:40 +02:00
$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 );
2019-03-29 01:53:01 +01:00
echo " <th style='padding: 0px;'> </th> \n " ;
2013-05-10 02:40:24 +02:00
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
2019-07-26 17:41:41 +02:00
if ( is_array ( $contacts ) && @ sizeof ( $contacts ) != 0 ) {
2018-07-02 18:44:14 +02:00
foreach ( $contacts as $row ) {
$tr_link = " href='contact_edit.php?id= " . escape ( $row [ 'contact_uuid' ]) . " &query_string= " . urlencode ( $_SERVER [ " QUERY_STRING " ]) . " ' " ;
2014-06-22 05:24:36 +02:00
echo " <tr " . $tr_link . " > \n " ;
2018-06-06 02:23:58 +02:00
echo " <td valign='top' class=' " . $row_style [ $c ] . " '> " . ucwords ( escape ( $row [ 'contact_type' ])) . " </td> \n " ;
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= " . escape ( $row [ 'contact_uuid' ]) . " &query_string= " . urlencode ( $_SERVER [ " QUERY_STRING " ]) . " '> " . escape ( $row [ 'contact_organization' ]) . " </a> </td> \n " ;
2019-03-29 01:53:01 +01:00
echo " <td valign='top' class=' " . $row_style [ $c ] . " tr_link_void' style='cursor: pointer; width: 35px; text-align: center;'> " ;
if ( is_uuid ( $row [ 'contact_attachment_uuid' ])) {
2019-08-21 03:53:21 +02:00
echo " <i class='fas fa-portrait' onclick= \" display_attachment(' " . escape ( $row [ 'contact_attachment_uuid' ]) . " '); \" ></i> " ;
2019-03-29 01:53:01 +01:00
}
echo " </td> \n " ;
2018-06-06 02:23:58 +02:00
echo " <td valign='top' class=' " . $row_style [ $c ] . " ' style='white-space: nowrap;'><a href='contact_edit.php?id= " . escape ( $row [ 'contact_uuid' ]) . " &query_string= " . urlencode ( $_SERVER [ " QUERY_STRING " ]) . " '> " . escape ( $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= " . escape ( $row [ 'contact_uuid' ]) . " &query_string= " . urlencode ( $_SERVER [ " QUERY_STRING " ]) . " '> " . escape ( $row [ 'contact_name_family' ]) . " </a> </td> \n " ;
echo " <td valign='top' class=' " . $row_style [ $c ] . " ' style='white-space: nowrap;'> " . escape ( $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;'> " . escape ( $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;'> " . escape ( $row [ 'contact_role' ]) . " </td> \n " ;
2014-11-25 09:35:53 +01:00
echo " <td valign='top' class=' " . $row_style [ $c ] . " ' style='padding: 2px 2px; text-align: center; width: 25px;'> " ;
2019-09-26 04:35:09 +02:00
if ( is_array ( $contact_sync_sources [ $row [ 'contact_uuid' ]]) && sizeof ( $contact_sync_sources [ $row [ 'contact_uuid' ]]) > 0 ) {
2014-11-25 09:35:53 +01:00
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'> " ;
2018-06-06 02:23:58 +02:00
echo " <a href='contact_edit.php?id= " . escape ( $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= " . escape ( $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
2019-07-26 17:41:41 +02:00
unset ( $contacts , $row );
2012-06-04 16:58:40 +02:00
} //end if results
echo " <tr> \n " ;
2015-02-25 23:46:58 +01:00
echo " <td colspan='15' align='right'> \n " ;
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> " ;
2015-02-25 23:46:58 +01:00
echo $paging_controls ;
echo " <br /><br /> " ;
2012-06-04 16:58:40 +02:00
2015-03-18 06:38:35 +01:00
echo " <script>document.getElementById('search_all').focus();</script> " ;
2019-03-29 01:53:01 +01:00
//javascript
echo " <script> \n " ;
echo " function display_attachment(id) { \n " ;
echo " $ ('#contact_attachment_layer').load('contact_attachment.php?id=' + id + '&action=display', function() { \n " ;
echo " $ ('#contact_attachment_layer').fadeIn(200); \n " ;
echo " }); \n " ;
echo " } \n " ;
echo " </script> \n " ;
2012-06-04 16:58:40 +02:00
//include the footer
2013-07-06 08:29:50 +02:00
require_once " resources/footer.php " ;
2018-01-10 21:37:26 +01:00
2019-09-26 04:35:09 +02:00
?>