Skip to content

Commit

Permalink
System Admin: add an option to Upload Photos & Files to not delete ex…
Browse files Browse the repository at this point in the history
…isting files
  • Loading branch information
SKuipers committed May 6, 2024
1 parent 9c8bfa7 commit 6e1a271
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ v27.0.00
User Admin: added an option to disable the display of privacy options, so they can be managed internally
User Admin: increased the field length for Departure Reason to 100 characters
System Admin: enabled Generic OAuth to specify the scopes and username field requested
System Admin: added an option to Upload Photos & Files to not delete existing files
System Admin: added an importer for Behaviour Records

Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion modules/System Admin/file_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Gibbon\Domain\User\PersonalDocumentTypeGateway;
use Gibbon\Services\Format;

if (isActionAccessible($guid, $connection2, '/modules/System Admin/import_manage.php') == false) {
if (isActionAccessible($guid, $connection2, '/modules/System Admin/file_upload.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
Expand Down
6 changes: 5 additions & 1 deletion modules/System Admin/file_uploadPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Gibbon\Domain\User\PersonalDocumentGateway;
use Gibbon\Domain\User\PersonalDocumentTypeGateway;

if (isActionAccessible($guid, $connection2, '/modules/System Admin/import_manage.php') == false) {
if (isActionAccessible($guid, $connection2, '/modules/System Admin/file_upload.php') == false) {
// Access denied
$page->addError(__('You do not have access to this action.'));
} else {
Expand Down Expand Up @@ -195,6 +195,10 @@
$row = $form->addRow();
$row->addLabel('overwrite', __('Overwrite'))->description(__('Should uploaded files overwrite any existing files?'));
$row->addYesNo('overwrite')->selected('Y');

$row = $form->addRow();
$row->addLabel('deleteFiles', __('Delete'))->description(__('Should original files be deleted from the server when overwriting files?'));
$row->addYesNo('deleteFiles')->selected('N');
}

// DATA TABLE
Expand Down
12 changes: 8 additions & 4 deletions modules/System Admin/file_uploadProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

$URL = $session->get('absoluteURL').'/index.php?q=/modules/System Admin/file_upload.php&step=3';

if (isActionAccessible($guid, $connection2, '/modules/System Admin/import_manage.php') == false) {
if (isActionAccessible($guid, $connection2, '/modules/System Admin/file_upload.php') == false) {
$URL .= '&return=error0';
header("Location: {$URL}");
exit;
Expand All @@ -45,6 +45,7 @@
$gibbonPersonalDocumentTypeID = $_POST['gibbonPersonalDocumentTypeID'] ?? '';
$gibbonCustomFieldID = $_POST['gibbonCustomFieldID'] ?? '';
$overwrite = $_POST['overwrite'] ?? 'N';
$deleteFiles = $_POST['deleteFiles'] ?? 'N';
$zoom = $_POST['zoom'] ?? '100';
$focalX = $_POST['focalX'] ?? '50';
$focalY = $_POST['focalY'] ?? '50';
Expand Down Expand Up @@ -116,10 +117,13 @@
$existingFile = $userData['image_240'];
}

// Optionally overwrite exiting files or skip them
if (!empty($existingFile) && $overwrite == 'Y') {
// Optionally overwrite and delete exiting files
if (!empty($existingFile) && $overwrite == 'Y' && $deleteFiles == 'Y') {
unlink($absolutePath.'/'.$existingFile);
} elseif (!empty($existingFile) && is_file($absolutePath.'/'.$existingFile) && $overwrite == 'N') {
}

// Skip uploading files if the file exists and overwrite is not on
if (!empty($existingFile) && is_file($absolutePath.'/'.$existingFile) && $overwrite == 'N') {
unlink($file['absolutePath']);
continue;
}
Expand Down

0 comments on commit 6e1a271

Please sign in to comment.