diff options
| author | Lester Caine <lester@lsces.co.uk> | 2026-05-25 15:39:34 +0100 |
|---|---|---|
| committer | Lester Caine <lester@lsces.co.uk> | 2026-05-25 15:39:34 +0100 |
| commit | fb30cd3317e01ebe8e748e4bcf1482e4c324b9b9 (patch) | |
| tree | 2a263ad27d6a78b4fe5f78e30134b5edc5aa618b | |
| parent | 80d56ac6a0b704c1b480157422227626f63df67d (diff) | |
| download | liberty-fb30cd3317e01ebe8e748e4bcf1482e4c324b9b9.tar.gz liberty-fb30cd3317e01ebe8e748e4bcf1482e4c324b9b9.tar.bz2 liberty-fb30cd3317e01ebe8e748e4bcf1482e4c324b9b9.zip | |
Add generic xref controllers and templates to liberty
Moves add/edit xref pages out of stock into liberty so any content type
can use them. list_xref.tpl uses hasUpdatePermission() instead of a
stock-specific permission check.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | add_xref.php | 45 | ||||
| -rw-r--r-- | edit_xref.php | 49 | ||||
| -rw-r--r-- | templates/add_xref.tpl | 44 | ||||
| -rw-r--r-- | templates/edit_xref.tpl | 45 | ||||
| -rw-r--r-- | templates/list_xref.tpl | 56 |
5 files changed, 239 insertions, 0 deletions
diff --git a/add_xref.php b/add_xref.php new file mode 100644 index 0000000..56ba6d5 --- /dev/null +++ b/add_xref.php @@ -0,0 +1,45 @@ +<?php +/** + * @package liberty + * @subpackage functions + */ + +namespace Bitweaver\Liberty; + +require_once '../kernel/includes/setup_inc.php'; + +global $gBitSystem, $gBitSmarty, $gBitUser, $gContent; + +if( empty( $_REQUEST['content_id'] ) || !is_numeric( $_REQUEST['content_id'] ) ) { + $gBitSystem->fatalError( 'No content ID specified.' ); +} + +$gContent = LibertyContent::getLibertyObject( (int)$_REQUEST['content_id'] ); + +if( !$gContent || !$gContent->isValid() ) { + $gBitSystem->fatalError( 'Content not found.' ); +} + +$gContent->verifyUpdatePermission(); + +if( !empty( $_REQUEST['fCancel'] ) ) { + header( 'Location: '.$gContent->getDisplayUrl() ); + die; +} + +if( !empty( $_REQUEST['fAddXref'] ) ) { + if( $gContent->storeXref( $_REQUEST ) ) { + header( 'Location: '.$gContent->getDisplayUrl() ); + die; + } +} + +$xref_type = (int)( $_REQUEST['xref_type'] ?? 1 ); +$xrefTypeList = $gContent->getXrefTypeList( $xref_type ); + +$gBitSmarty->assign( 'gContent', $gContent ); +$gBitSmarty->assign( 'xref_type', $xref_type ); +$gBitSmarty->assign( 'xrefTypeList', $xrefTypeList ); +$gBitSmarty->assign( 'errors', $gContent->mErrors ); + +$gBitSystem->display( 'bitpackage:liberty/add_xref.tpl', 'Add Detail', [ 'display_mode' => 'edit' ] ); diff --git a/edit_xref.php b/edit_xref.php new file mode 100644 index 0000000..323b4db --- /dev/null +++ b/edit_xref.php @@ -0,0 +1,49 @@ +<?php +/** + * @package liberty + * @subpackage functions + */ + +namespace Bitweaver\Liberty; + +require_once '../kernel/includes/setup_inc.php'; + +global $gBitSystem, $gBitSmarty, $gBitUser, $gContent; + +if( empty( $_REQUEST['content_id'] ) || !is_numeric( $_REQUEST['content_id'] ) ) { + $gBitSystem->fatalError( 'No content ID specified.' ); +} + +$gContent = LibertyContent::getLibertyObject( (int)$_REQUEST['content_id'] ); + +if( !$gContent || !$gContent->isValid() ) { + $gBitSystem->fatalError( 'Content not found.' ); +} + +if( !empty( $_REQUEST['xref_id'] ) ) { + $gContent->loadXref( $_REQUEST['xref_id'] ); +} + +$gContent->verifyUpdatePermission(); + +if( !empty( $_REQUEST['fCancel'] ) ) { + header( 'Location: '.$gContent->getDisplayUrl() ); + die; +} + +if( !empty( $_REQUEST['fSaveXref'] ) ) { + if( $gContent->storeXref( $_REQUEST ) ) { + header( 'Location: '.$gContent->getDisplayUrl() ); + die; + } + $xrefInfo = $_REQUEST; + $xrefInfo['data'] = $_REQUEST['edit'] ?? ''; +} else { + $xrefInfo = $gContent->mInfo['xref_store']['data'] ?? []; +} + +$gBitSmarty->assign( 'gContent', $gContent ); +$gBitSmarty->assign( 'xrefInfo', $xrefInfo ); +$gBitSmarty->assign( 'errors', $gContent->mErrors ); + +$gBitSystem->display( 'bitpackage:liberty/edit_xref.tpl', 'Edit Detail', [ 'display_mode' => 'edit' ] ); diff --git a/templates/add_xref.tpl b/templates/add_xref.tpl new file mode 100644 index 0000000..3be770f --- /dev/null +++ b/templates/add_xref.tpl @@ -0,0 +1,44 @@ +{strip} +<div class="edit liberty"> + <div class="header"> + <h1>{tr}Add Detail{/tr}: {$gContent->getTitle()|escape}</h1> + </div> + + <div class="body"> + {formfeedback error=$errors} + + {form id="addXrefForm"} + <input type="hidden" name="content_id" value="{$gContent->mContentId}" /> + <input type="hidden" name="xref_type" value="{$xref_type}" /> + + <div class="form-group"> + {formlabel label="Type" for="source"} + {forminput} + {html_options name="source" id="source" options=$xrefTypeList.list} + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Value" for="edit"} + {forminput} + <input type="text" class="form-control" name="edit" id="edit" value="" /> + {formhelp note="Enter the value for this detail record."} + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Linked Content ID" for="xref"} + {forminput} + <input type="text" class="form-control input-small" name="xref" id="xref" value="" /> + {formhelp note="For supplier links: enter the contact content_id. Leave blank for all other types."} + {/forminput} + </div> + + <div class="form-group submit"> + <input type="submit" class="btn btn-default" name="fCancel" value="{tr}Cancel{/tr}" /> + <input type="submit" class="btn btn-primary" name="fAddXref" value="{tr}Save{/tr}" /> + </div> + {/form} + </div><!-- end .body --> +</div><!-- end .liberty --> +{/strip} diff --git a/templates/edit_xref.tpl b/templates/edit_xref.tpl new file mode 100644 index 0000000..9dbb0d8 --- /dev/null +++ b/templates/edit_xref.tpl @@ -0,0 +1,45 @@ +{strip} +<div class="edit liberty"> + <div class="header"> + <h1>{tr}Edit Detail{/tr}: {$gContent->getTitle()|escape}</h1> + </div> + + <div class="body"> + {formfeedback error=$errors} + + {form id="editXrefForm"} + <input type="hidden" name="content_id" value="{$xrefInfo.content_id}" /> + <input type="hidden" name="xref_id" value="{$xrefInfo.xref_id}" /> + <input type="hidden" name="source" value="{$xrefInfo.source|escape}" /> + + <div class="form-group"> + {formlabel label="Type"} + {forminput} + <p class="form-control-static">{$xrefInfo.template_title|escape}</p> + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Value" for="edit"} + {forminput} + <input type="text" class="form-control" name="edit" id="edit" value="{$xrefInfo.data|escape}" /> + {formhelp note="Enter the value for this detail record."} + {/forminput} + </div> + + <div class="form-group"> + {formlabel label="Linked Content ID" for="xref"} + {forminput} + <input type="text" class="form-control input-small" name="xref" id="xref" value="{$xrefInfo.xref|escape}" /> + {formhelp note="For supplier links: enter the contact content_id. Leave blank for all other types."} + {/forminput} + </div> + + <div class="form-group submit"> + <input type="submit" class="btn btn-default" name="fCancel" value="{tr}Cancel{/tr}" /> + <input type="submit" class="btn btn-primary" name="fSaveXref" value="{tr}Save{/tr}" /> + </div> + {/form} + </div><!-- end .body --> +</div><!-- end .liberty --> +{/strip} diff --git a/templates/list_xref.tpl b/templates/list_xref.tpl new file mode 100644 index 0000000..b234e68 --- /dev/null +++ b/templates/list_xref.tpl @@ -0,0 +1,56 @@ + {assign var=xrefcnt value=$gContent->mInfo.$source|default:[]|@count} + {jstab title="$source_title ($xrefcnt)"} + {legend legend=$source_title} + <div class="form-group table-responsive"> + <table> + <thead> + <tr> + <th>{tr}Source{/tr}</th> + <th>{tr}Data{/tr}</th> + {if $source ne 'history'} + <th>{tr}Started{/tr}</th> + {else} + <th>{tr}Ended{/tr}</th> + {/if} + <th>{tr}Updated{/tr}</th> + <th>{tr}Edit{/tr}</th> + </tr> + </thead> + <tbody> + {section name=xref loop=$gContent->mInfo.$source} + <tr class="{cycle values="even,odd"}"> + <td>{$gContent->mInfo.$source[xref].source_title|escape}</td> + <td> + {if $gContent->mInfo.$source[xref].xref} + <a href="{$smarty.const.CONTACT_PKG_URL}?content_id={$gContent->mInfo.$source[xref].xref}">{$gContent->mInfo.$source[xref].data|escape}</a> + {else} + {$gContent->mInfo.$source[xref].data|escape} + {/if} + </td> + {if $source ne 'history'} + <td>{$gContent->mInfo.$source[xref].start_date|bit_short_date}</td> + {else} + <td>{$gContent->mInfo.$source[xref].end_date|bit_short_date}</td> + {/if} + <td>{$gContent->mInfo.$source[xref].last_update_date|bit_short_date}</td> + <td> + {if $gContent->hasUpdatePermission()} + {smartlink ititle="Edit" ipackage="liberty" ifile="edit_xref.php" booticon="fa-pen-to-square" content_id=$gContent->mInfo.content_id xref_id=$gContent->mInfo.$source[xref].xref_id} + {/if} + </td> + </tr> + {sectionelse} + <tr class="norecords"> + <td colspan="5">{tr}No {$source_title} records found{/tr}</td> + </tr> + {/section} + </tbody> + </table> + </div> + {if $gContent->hasUpdatePermission() && $source ne 'history'} + <div> + {smartlink ititle="Add record" ipackage="liberty" ifile="add_xref.php" booticon="fa-plus" content_id=$gContent->mInfo.content_id xref_type=$xref_type} + </div> + {/if} + {/legend} + {/jstab} |
