diff --git a/app/contacts/contacts.php b/app/contacts/contacts.php index 938db50b15..453a61157c 100644 --- a/app/contacts/contacts.php +++ b/app/contacts/contacts.php @@ -43,17 +43,24 @@ $language = new text; $text = $language->get(); -//includes and title - $document['title'] = $text['title-contacts']; - require_once "resources/header.php"; +//get posted data + if (is_array($_POST['contacts'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $contacts = $_POST['contacts']; + } -//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"]; +//delete the contacts + if (permission_exists('contact_delete')) { + if ($action == 'delete' && is_array($contacts) && @sizeof($contacts) != 0) { + //delete + $obj = new contacts; + $obj->delete($contacts); + //redirect + header('Location: contacts.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } //retrieve current user's assigned groups (uuids) foreach ($_SESSION['groups'] as $group_data) { @@ -114,6 +121,41 @@ } unset($sql, $parameters, $result); +//get variables used to control the order + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//add the search term + $search = strtolower($_GET["search"]); + if (strlen($search) > 0) { + if (is_numeric($search)) { + $sql_search .= "and contact_uuid in ( "; + $sql_search .= " select contact_uuid from v_contact_phones "; + $sql_search .= " where phone_number like :search "; + $sql_search .= ") "; + } + else { + $sql_search .= "and contact_uuid in ( "; + $sql_search .= " select contact_uuid from v_contacts "; + $sql_search .= " where domain_uuid = :domain_uuid "; + $sql_search .= " and ( "; + $sql_search .= " lower(contact_organization) like :search or "; + $sql_search .= " lower(contact_name_given) like :search or "; + $sql_search .= " lower(contact_name_family) like :search or "; + $sql_search .= " lower(contact_nickname) like :search or "; + $sql_search .= " lower(contact_title) like :search or "; + $sql_search .= " lower(contact_category) like :search or "; + $sql_search .= " lower(contact_role) like :search or "; + $sql_search .= " lower(contact_url) like :search or "; + $sql_search .= " lower(contact_time_zone) like :search or "; + $sql_search .= " lower(contact_note) like :search or "; + $sql_search .= " lower(contact_type) like :search "; + $sql_search .= " ) "; + $sql_search .= ") "; + } + $parameters['search'] = '%'.$search.'%'; + } + //build query for paging and list $sql = "select count(*) "; $sql .= "from v_contacts as c "; @@ -146,55 +188,18 @@ $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.'%'; - } - } + $sql .= $sql_search; $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 = ""; + $param = "&search=".$search; $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 + list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); //bottom + list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); //top $offset = $rows_per_page * $page; //get the list @@ -217,9 +222,16 @@ $contacts = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); -//styles - echo "\n"; - -//ticket attachment layer echo "
\n"; //show the content - echo "| \n";
- echo " ".$text['header-contacts']." (".$num_rows.")\n";
- echo " "; - echo " | \n";
- echo " \n"; - echo " | \n"; + if (permission_exists('contact_delete') && $contacts) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo "|
| \n";
- echo " ".$text['description-contacts']." \n"; - echo " | \n";
- echo " ||