Add Primary Location / Contact if missing link modals

This commit is contained in:
johnnyq
2026-08-28 00:26:40 -04:00
parent 6d13237a17
commit 097891ed96
4 changed files with 51 additions and 5 deletions

View File

@@ -458,7 +458,15 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
</td>
<td>
<?php
if (empty($contact_name) && empty($contact_phone) && empty($contact_mobile) && empty($client_email)) {
/* contact_id is the LEFT JOIN on contact_primary = 1, so empty
means no primary contact at all. The wider test below stays as
it was: it also covers a primary contact that exists but has
nothing worth printing. */
if (empty($contact_id) && lookupUserPermission("module_client") >= 2) { ?>
<a class="ajax-modal" href="#" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1">
Add Primary Contact
</a>
<?php } elseif (empty($contact_name) && empty($contact_phone) && empty($contact_mobile) && empty($client_email)) {
echo "-";
}
@@ -491,7 +499,15 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
</div>
<?php } ?>
</td>
<td><?= $full_address ?></td>
<td>
<?php if (empty($location_id) && lookupUserPermission("module_client") >= 2) { ?>
<a class="ajax-modal" href="#" data-modal-url="modals/location/location_add.php?client_id=<?= $client_id ?>&primary=1">
Add Primary Location
</a>
<?php } else {
echo $full_address;
} ?>
</td>
<!-- Show Billing if perms & if accounting module is enabled -->
<?php if ((lookupUserPermission("module_financial") >= 1) && $config_module_enable_accounting == 1) { ?>
<td class="text-end">

View File

@@ -69,7 +69,21 @@
<div class="card-group mb-3">
<div class="card card-body px-3 py-2">
<h5>Primary Location</h5>
<?php if (!empty($location_address)) { ?>
<?php /* location_id comes from inc_all_client.php's LEFT JOIN on
location_primary = 1, so empty means there is genuinely no
primary location - not merely a primary location with no
street address filled in. Gated at module_client >= 2 to
match enforceUserPermission() in agent/post/location.php;
without that a read-only user would get a link that 403s. */ ?>
<?php if (empty($location_id) && lookupUserPermission("module_client") >= 2) { ?>
<div>
<a class="ajax-modal" href="#" data-modal-url="modals/location/location_add.php?client_id=<?= $client_id ?>&primary=1">
Add Primary Location
</a>
</div>
<?php }
if (!empty($location_address)) { ?>
<div>
<a href="//maps.<?= $session_map_source ?>.com/?q=<?= "$location_address $location_zip" ?>" target="_blank">
<i class="fa fa-fw fa-map-marker-alt text-secondary ms-1 me-2"></i><?= $location_address ?>
@@ -101,6 +115,14 @@
<h5>Primary Contact</h5>
<?php
if (empty($contact_id) && lookupUserPermission("module_client") >= 2) { ?>
<div>
<a class="ajax-modal" href="#" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1">
Add Primary Contact
</a>
</div>
<?php }
if (!empty($contact_name)) { ?>
<div>
<i class="fa fa-fw fa-user text-secondary ms-1 me-2"></i><?= $contact_name ?>

View File

@@ -4,6 +4,10 @@ require_once '../../../includes/modal_header.php';
$client_id = intval($_GET['client_id'] ?? 0);
// Opened from an "Add Primary Contact" link, so the box below starts ticked.
// A default, not a lock - it is still a normal checkbox.
$contact_primary_default = !empty($_GET['primary']);
if ($client_id) {
$sql_location_select = mysqli_query($mysqli, "SELECT location_id, location_name FROM locations WHERE location_archived_at IS NULL AND location_client_id = $client_id ORDER BY location_name ASC");
} else {
@@ -91,7 +95,7 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="name" placeholder="Full Name" maxlength="200" required autofocus>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="contact_primary" value="1">
<input class="form-check-input" type="checkbox" name="contact_primary" value="1"<?= $contact_primary_default ? ' checked' : '' ?>>
</div>
</div>
</div>

View File

@@ -4,6 +4,10 @@ require_once '../../../includes/modal_header.php';
$client_id = intval($_GET['client_id'] ?? 0);
// Opened from an "Add Primary Location" link, so the box below starts ticked.
// A default, not a lock - it is still a normal checkbox.
$location_primary_default = !empty($_GET['primary']);
ob_start();
?>
@@ -70,7 +74,7 @@ ob_start();
<span class="input-group-text"><i class="fa fa-fw fa-map-marker"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name of location" maxlength="200" required autofocus>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="location_primary" value="1">
<input class="form-check-input" type="checkbox" name="location_primary" value="1"<?= $location_primary_default ? ' checked' : '' ?>>
</div>
</div>
</div>