diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-06-19 14:05:07 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-06-19 14:05:07 +0100 |
| commit | 5d3e672dd7f35c348a98fd149c02c5c9d79cb520 (patch) | |
| tree | aeb54fdb20f2e5c60cf2ee1f1952f6f604248909 | |
| parent | 53bb19704b1e99245b755caf2d573a4406066902 (diff) | |
| download | contact-5d3e672dd7f35c348a98fd149c02c5c9d79cb520.tar.gz contact-5d3e672dd7f35c348a98fd149c02c5c9d79cb520.tar.bz2 contact-5d3e672dd7f35c348a98fd149c02c5c9d79cb520.zip | |
Map contact persons to registered users via contact.role_id
contact.role_id stores the user_id of the linked registered user (NULL = no
account). load() joins users_users on role_id to expose linked_user_login and
linked_user_name. verify() accepts user_id from the edit form and writes it to
contact_store['role_id']. getList() now filters by user_id key (was role_id).
Edit form shows the user_id field to admins with current login shown inline;
display template shows the linked user when set.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | includes/classes/Contact.php | 17 | ||||
| -rwxr-xr-x | templates/display_contact.tpl | 9 | ||||
| -rwxr-xr-x | templates/edit_contact.tpl | 12 |
3 files changed, 32 insertions, 6 deletions
diff --git a/includes/classes/Contact.php b/includes/classes/Contact.php index 3423c0d..a9bab4b 100755 --- a/includes/classes/Contact.php +++ b/includes/classes/Contact.php @@ -130,11 +130,13 @@ class Contact extends LibertyContent { x00.`xkey_ext` as name, lc.`title` as organisation, xhL.`xkey` as x_coordinate, xhL.`xkey_ext` as y_coordinate, uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name, - uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name + uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name, + uu.`login` AS linked_user_login, uu.`real_name` AS linked_user_name FROM `".BIT_DB_PREFIX."contact` con LEFT JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.content_id = con.content_id LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`) LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON (uuc.`user_id` = lc.`user_id`) + LEFT JOIN `".BIT_DB_PREFIX."users_users` uu ON uu.`user_id` = con.`role_id` LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` img ON img.`content_id` = con.`content_id` AND img.`item` = 'IMG' LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` x00 ON x00.`content_id` = con.`content_id` AND x00.`item` = 'P01' LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` xhA ON xhA.`content_id` = con.`content_id` AND xhA.`item` = '#S' AND ( xhA.`end_date` IS NULL OR xhA.`end_date` > CURRENT_TIMESTAMP ) @@ -222,6 +224,9 @@ class Contact extends LibertyContent { } $pParamHash['title'] = trim( $pParamHash['title'] ); $pParamHash['contact_store']['xkey'] = $pParamHash['xkey']; + if( array_key_exists( 'user_id', $pParamHash ) ) { + $pParamHash['contact_store']['role_id'] = $pParamHash['user_id'] ? (int)$pParamHash['user_id'] : null; + } return count( $this->mErrors ) == 0; } @@ -378,7 +383,7 @@ class Contact extends LibertyContent { /** * Return a paged list of contacts matching filter criteria. * - * Recognised keys in $pParamHash: role_id, contact_type_guid, find_xref, + * Recognised keys in $pParamHash: user_id (filters by linked user; stored in con.role_id), contact_type_guid, find_xref, * find_title, find_location, find_postcode, active, sort_mode, max_records, offset. * Sets $pParamHash['cant'] and $pParamHash['listInfo'] on return. * @@ -396,11 +401,11 @@ class Contact extends LibertyContent { $whereSql = ''; $bindVars = []; - if ( isset( $pParamHash['role_id'] ) ) { + if ( isset( $pParamHash['user_id'] ) ) { array_push( $bindVars, $this->mContentTypeGuid ); - if ( $pParamHash['role_id'] > 0 ) { + if ( $pParamHash['user_id'] > 0 ) { $whereSql .= " AND con.`role_id` = ? "; - $bindVars[] = $pParamHash['role_id']; + $bindVars[] = (int)$pParamHash['user_id']; } } elseif ( isset( $pParamHash['contact_type_guid'][0] ) ) { @@ -417,7 +422,7 @@ class Contact extends LibertyContent { $pParamHash["listInfo"]["ihash"]["find_xref"] = $find_xref; } - if ( !isset( $pParamHash['role_id'] ) ) { + if ( !isset( $pParamHash['user_id'] ) ) { array_push( $bindVars, $this->mContentTypeGuid ); } diff --git a/templates/display_contact.tpl b/templates/display_contact.tpl index 2a3ba39..aa4bf93 100755 --- a/templates/display_contact.tpl +++ b/templates/display_contact.tpl @@ -44,6 +44,15 @@ <div class="clear"></div> </div> {/if} + {if $gContent->mInfo.linked_user_login} + <div class="form-group"> + {formlabel label="Registered User"} + {forminput} + {$gContent->mInfo.linked_user_name|escape} ({$gContent->mInfo.linked_user_login|escape}) + {/forminput} + <div class="clear"></div> + </div> + {/if} {if $gContent->mInfo.data} <div class="form-group"> {formlabel label="Note"} diff --git a/templates/edit_contact.tpl b/templates/edit_contact.tpl index 80a468b..611a43e 100755 --- a/templates/edit_contact.tpl +++ b/templates/edit_contact.tpl @@ -80,6 +80,18 @@ <div class="clear"></div> </div> *} + {if $gBitUser->hasPermission('p_contact_admin')} + <div class="form-group"> + {formlabel label="Linked User ID" for="user_id"} + {forminput} + <input size="10" type="text" name="user_id" id="user_id" value="{$gContent->mInfo.role_id|escape}" /> + {if $gContent->mInfo.linked_user_login} + <span class="help-block">{$gContent->mInfo.linked_user_name|escape} ({$gContent->mInfo.linked_user_login|escape})</span> + {/if} + {/forminput} + <div class="clear"></div> + </div> + {/if} <div class="form-group"> {formlabel label="Note" for="description"} {forminput} |
