summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLester Caine <lester@lsces.co.uk>2026-06-18 21:25:38 +0100
committerLester Caine <lester@lsces.co.uk>2026-06-18 21:25:38 +0100
commit53bb19704b1e99245b755caf2d573a4406066902 (patch)
treeb774b221b580c8edb090390ba1d443f145c8fdc7
parentc6775b6deb8a44d5b500dcb52fadb5667e61df46 (diff)
downloadcontact-53bb19704b1e99245b755caf2d573a4406066902.tar.gz
contact-53bb19704b1e99245b755caf2d573a4406066902.tar.bz2
contact-53bb19704b1e99245b755caf2d573a4406066902.zip
Fix P01 name xref being wiped when saving type checkboxes
The bulk DELETE of P*/B* xrefs was removing P01 (which carries the pipe-encoded name) whenever contact_types were saved. P01 is implied for all persons and never submitted as a checkbox, so it was never re-inserted. Fix handles P01 separately — always delete/rewrite it from pParamHash['name'] — and excludes it from the checkbox cycle. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rwxr-xr-xincludes/classes/Contact.php28
1 files changed, 19 insertions, 9 deletions
diff --git a/includes/classes/Contact.php b/includes/classes/Contact.php
index 43ae07f..3423c0d 100755
--- a/includes/classes/Contact.php
+++ b/includes/classes/Contact.php
@@ -262,15 +262,25 @@ class Contact extends LibertyContent {
$result = $this->mDb->associateInsert( $atable, $pParamHash['contact_store'] );
}
if( !empty( $pParamHash['contact_types'] ) ) {
- $query = "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND (`item` STARTING WITH 'P' OR `item` STARTING WITH 'B')";
- $result = $this->mDb->query($query, [ $this->mContentId ] );
- foreach ( $pParamHash['contact_types'] as $key => $source ) {
- if ( $source === 'P01' ) {
- $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `xkey_ext`, `last_update_date`) VALUES ( ?, ?, ?, ?, NULL )";
- $result = $this->mDb->query($query, [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source, $pParamHash['name'] ] );
- } else {
- $query = "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `last_update_date`) VALUES ( ?, ?, ?, NULL )";
- $result = $this->mDb->query($query, [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source ] );
+ // P01 carries the pipe-encoded name — always rewrite it independently of the checkbox set
+ $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND `item` = 'P01'", [ $this->mContentId ] );
+ if( !empty( $pParamHash['name'] ) ) {
+ $this->mDb->query(
+ "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `xkey_ext`, `last_update_date`) VALUES (?, ?, 'P01', ?, NULL)",
+ [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $pParamHash['name'] ]
+ );
+ }
+ // Optional type tags (P02+, B01+) come from the form checkboxes
+ $this->mDb->query(
+ "DELETE FROM `".BIT_DB_PREFIX."liberty_xref` WHERE `content_id` = ? AND (`item` STARTING WITH 'P' OR `item` STARTING WITH 'B') AND `item` <> 'P01'",
+ [ $this->mContentId ]
+ );
+ foreach ( $pParamHash['contact_types'] as $source ) {
+ if ( $source !== 'P01' ) {
+ $this->mDb->query(
+ "INSERT INTO `".BIT_DB_PREFIX."liberty_xref` (`xref_id`, `content_id`, `item`, `last_update_date`) VALUES (?, ?, ?, NULL)",
+ [ $this->mDb->GenID('liberty_xref_seq'), $this->mContentId, $source ]
+ );
}
}
}