Portions created by the Initial Developer are Copyright (C) 2024 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('contact_view')) { //access granted } else { echo "access denied"; exit; } //find the location of the contact application $contact_array[] = 'core/contacts'; $contact_array[] = 'app/contacts'; $contact_path = ''; foreach($contact_array as $path) { if (file_exists($_SERVER["PROJECT_ROOT"]."/".$path."/app_config.php")) { $contact_path = $path; } } //add multi-lingual support $language = new text; $text = $language->get(null, $contact_path); //connect to the database $database = database::new(); //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) { $contact_uuid = $_REQUEST["id"]; } elseif (!empty($_REQUEST["destination"]) ) { $destination = $_REQUEST["destination"]; } else { echo '  '; exit; } //main contact details $sql = "select * from v_contacts as c \n"; $sql .= "where domain_uuid = :domain_uuid \n"; if (!empty($destination)) { $sql .= "and contact_uuid in ( \n"; $sql .= " select contact_uuid from v_contact_phones \n"; $sql .= " where domain_uuid = :domain_uuid \n"; $sql .= " and ( \n"; $sql .= " concat('+',phone_country_code, phone_number) = :destination \n"; $sql .= " or concat(phone_country_code, phone_number) = :destination \n"; $sql .= " or phone_number = :destination \n"; $sql .= " ) \n"; $sql .= ") \n"; $parameters['destination'] = $destination; } if (!empty($contact_uuid)) { $sql .= "and contact_uuid = :contact_uuid "; $parameters['contact_uuid'] = $contact_uuid; } $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $row = $database->select($sql, $parameters, 'row'); if (!empty($row)) { $contact_uuid = $row["contact_uuid"]; $contact_type = $row["contact_type"]; $contact_organization = $row["contact_organization"]; $contact_name_prefix = $row["contact_name_prefix"]; $contact_name_given = $row["contact_name_given"]; $contact_name_middle = $row["contact_name_middle"]; $contact_name_family = $row["contact_name_family"]; $contact_name_suffix = $row["contact_name_suffix"]; $contact_nickname = $row["contact_nickname"]; $contact_title = $row["contact_title"]; $contact_category = $row["contact_category"]; $contact_role = $row["contact_role"]; $contact_time_zone = $row["contact_time_zone"]; $contact_note = $row["contact_note"]; } unset($sql, $parameters, $row); //check contact permisions if this is set to enabled. default is false if ($_SESSION['contact']['permissions']['boolean'] == "true") { //get the available users for this contact $sql = "select * from v_users "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by username asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $users = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); //determine if contact assigned to a user if (!empty($users)) { foreach ($users as $user) { if ($user['contact_uuid'] == $contact_uuid) { $contact_user_uuid = $user['user_uuid']; break; } } } //get the assigned users that can view this contact $sql = "select u.username, u.user_uuid, a.contact_user_uuid from v_contacts as c, v_users as u, v_contact_users as a "; $sql .= "where c.contact_uuid = :contact_uuid "; $sql .= "and c.domain_uuid = :domain_uuid "; $sql .= "and u.user_uuid = a.user_uuid "; $sql .= "and c.contact_uuid = a.contact_uuid "; $sql .= "order by u.username asc "; $parameters['contact_uuid'] = $contact_uuid; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $contact_users_assigned = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //get the assigned groups that can view this contact $sql = "select g.*, cg.contact_group_uuid "; $sql .= "from v_groups as g, v_contact_groups as cg "; $sql .= "where cg.group_uuid = g.group_uuid "; $sql .= "and cg.domain_uuid = :domain_uuid "; $sql .= "and cg.contact_uuid = :contact_uuid "; $sql .= "and cg.group_uuid <> :group_uuid "; $sql .= "order by g.group_name asc "; $parameters['domain_uuid'] = $domain_uuid; $parameters['contact_uuid'] = $contact_uuid; $parameters['group_uuid'] = $_SESSION["user_uuid"]; $contact_groups_assigned = $database->select($sql, $parameters, 'all'); if (!empty($contact_groups_assigned)) { foreach ($contact_groups_assigned as $field) { $contact_groups[] = "'".$field['group_uuid']."'"; } } unset($sql, $parameters); //get the available groups for this contact $sql = "select group_uuid, group_name from v_groups "; $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) "; if (!empty($contact_groups)) { $sql .= "and group_uuid not in (".implode(',', $contact_groups).") "; } $sql .= "order by group_name asc "; $parameters['domain_uuid'] = $domain_uuid; $contact_groups_available = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $contact_groups); } //determine title name if ($contact_name_given || $contact_name_family) { $contact_name = $contact_name_prefix ? escape($contact_name_prefix).' ' : null; $contact_name .= $contact_name_given ? escape($contact_name_given).' ' : null; $contact_name .= $contact_name_middle ? escape($contact_name_middle).' ' : null; $contact_name .= $contact_name_family ? escape($contact_name_family).' ' : null; $contact_name .= $contact_name_suffix ? escape($contact_name_suffix).' ' : null; } else { $contact_name = $contact_organization; } //show the content echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // echo "\n"; echo "\n"; //css echo "\n"; echo "\n"; //end the header and start the body echo "\n"; echo "\n"; echo "
\n"; //show the content echo "
\n"; echo "
".($contact_name ? $contact_name : $text['header-contact-edit'])."
\n"; echo "
\n"; if (!empty($contact_user_uuid) && permission_exists('user_edit') && is_uuid($contact_user_uuid)) { echo button::create(['type'=>'button','label'=>$text['button-user'],'icon'=>'user','collapse'=>'hide-sm-dn','link'=>'../../core/users/user_edit.php?id='.urlencode($contact_user_uuid)]); } if (permission_exists('contact_edit')) { if (empty($contact_uuid)) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','style'=>'margin-left: 15px; margin-right: 0;','onclick'=>"window.open('".PROJECT_PATH."/".$contact_path."/contact_edit.php');"]); } else { echo button::create(['type'=>'button','label'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'id'=>'btn_edit','style'=>'margin-left: 15px; margin-right: 0;','onclick'=>"window.open('".PROJECT_PATH."/".$contact_path."/contact_edit.php?id=".urlencode($contact_uuid)."');"]); } } echo "
\n"; echo "
\n"; echo "
\n"; if ($contact_title || $contact_organization) { echo ($contact_title ? ''.$contact_title.'' : null).($contact_title && $contact_organization ? ', ' : null).($contact_organization ? ''.$contact_organization.'' : null)."\n"; } else { echo $contact_note."\n"; } echo "
\n"; //general info echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; //nickname if ($contact_nickname) { echo "
".$text['label-contact_nickname']."
\n"; echo "
\"".escape($contact_nickname)."\"
\n"; } //name if ($contact_name_given) { echo "
".$text['label-name']."
\n"; echo "
".escape($contact_name_given).(!empty($contact_name_family) ? ' '.escape($contact_name_family) : null)."
\n"; } //contact type if ($contact_type) { echo "
".$text['label-contact_type']."
\n"; echo "
"; if (!empty($_SESSION["contact"]["type"])) { sort($_SESSION["contact"]["type"]); foreach ($_SESSION["contact"]["type"] as $type) { if ($contact_type == $type) { echo escape($type); } } } else if ($text['option-contact_type_'.$contact_type]) { echo $text['option-contact_type_'.$contact_type]; } else { echo escape($contact_type); } echo "
\n"; } //category if ($contact_category) { echo "
".$text['label-contact_category']."
\n"; echo "
"; if (!empty($_SESSION["contact"]["category"])) { sort($_SESSION["contact"]["category"]); foreach ($_SESSION["contact"]["category"] as $category) { if ($contact_category == $category) { echo escape($category); break; } } } else { echo escape($contact_category); } echo "
\n"; } //role if ($contact_role) { echo "
".$text['label-contact_role']."
\n"; echo "
"; if (!empty($_SESSION["contact"]["role"])) { sort($_SESSION["contact"]["role"]); foreach ($_SESSION["contact"]["role"] as $role) { if ($contact_role == $role) { echo escape($role); break; } } } else { echo escape($contact_role); } echo "
\n"; } //time_zone if ($contact_time_zone) { echo "
".$text['label-contact_time_zone']."
\n"; echo "
"; echo $contact_time_zone."
\n"; echo "
\n"; } //users (viewing contact) if (permission_exists('contact_user_view') && !empty($contact_users_assigned)) { echo "
".$text['label-users']."
\n"; echo "
"; foreach ($contact_users_assigned as $field) { echo escape($field['username'])."
\n"; } echo "
\n"; } //groups (viewing contact) if (permission_exists('contact_group_view') && !empty($contact_groups_assigned)) { echo "
".$text['label-groups']."
\n"; echo "
"; foreach ($contact_groups_assigned as $field) { echo escape($field['group_name'])."
\n"; } echo "
\n"; } echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; //numbers if (permission_exists('contact_phone_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_phones_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //emails if (permission_exists('contact_email_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_emails_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //addresses if (permission_exists('contact_address_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_addresses_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //urls if (permission_exists('contact_url_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_urls_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //relations if (permission_exists('contact_relation_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_relations_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //attachments if (permission_exists('contact_attachment_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_attachments_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //times if (permission_exists('contact_time_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_times_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //extensions if (permission_exists('contact_extension_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_extensions_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } //notes if (permission_exists('contact_note_view')) { echo "
\n"; echo "
\n"; echo "
\n"; echo "
\n"; require $contact_path."/contact_notes_view.php"; echo "
\n"; echo "
\n"; echo "
\n"; } echo "
\n"; echo "\n"; echo "\n"; ?>