adm_program/modules/photos/photo_album_new.php
<?php
/**
***********************************************************************************************
* Create and edit photo alben
*
* @copyright The Admidio Team
* @see https://www.admidio.org/
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2.0 only
*
* Parameters:
* photo_uuid : UUID of the album that should be edited
* parent_photo_uuid : UUID of the parent album in which the new album should be created
***********************************************************************************************
*/
use Admidio\Exception;
use Admidio\UserInterface\Form;
try {
require_once(__DIR__ . '/../../system/common.php');
require(__DIR__ . '/../../system/login_valid.php');
// Initialize and check the parameters
$getPhotoUuid = admFuncVariableIsValid($_GET, 'photo_uuid', 'uuid');
$getParentPhotoUuid = admFuncVariableIsValid($_GET, 'parent_photo_uuid', 'uuid');
$photoAlbumsArray = array('ALL' => $gL10n->get('SYS_PHOTO_ALBUMS'));
// check if the module is enabled and disallow access if it's disabled
if ((int)$gSettingsManager->get('photo_module_enabled') === 0) {
throw new Exception('SYS_MODULE_DISABLED');
}
// create photo album object
$photoAlbum = new TablePhotos($gDb);
if ($getPhotoUuid === '') {
$headline = $gL10n->get('SYS_CREATE_ALBUM');
} else {
$headline = $gL10n->get('SYS_EDIT_ALBUM');
$photoAlbum->readDataByUuid($getPhotoUuid);
$parentAlbum = new TablePhotos($gDb, (int)$photoAlbum->getValue('pho_pho_id_parent'));
$getParentPhotoUuid = $parentAlbum->getValue('pho_uuid');
}
$gNavigation->addUrl(CURRENT_URL, $headline);
// check if the user is allowed to edit this photo album
if (!$photoAlbum->isEditable()) {
throw new Exception('SYS_NO_RIGHTS');
}
/**
* Read the album structure to an array that could be used for a select box.
* @param int $parentId
* @param string $vorschub
* @param int $currentAlbumPhoId
*/
function subfolder(int $parentId, string $vorschub, int $currentAlbumPhoId)
{
global $gDb, $gCurrentOrgId, $photoAlbumsArray;
$vorschub .= ' ';
$sqlConditionParentId = '';
$parentPhotoAlbum = new TablePhotos($gDb);
$queryParams = array($currentAlbumPhoId, $gCurrentOrgId);
// read all sub albums of the parent album
if ($parentId > 0) {
$sqlConditionParentId .= ' AND pho_pho_id_parent = ? -- $parentId';
$queryParams[] = $parentId;
} else {
$sqlConditionParentId .= ' AND pho_pho_id_parent IS NULL';
}
$sql = 'SELECT *
FROM ' . TBL_PHOTOS . '
WHERE pho_id <> ? -- $photoAlbum->getValue(\'pho_id\')
AND pho_org_id = ? -- $gCurrentOrgId
' . $sqlConditionParentId;
$childStatement = $gDb->queryPrepared($sql, $queryParams);
while ($admPhotoChild = $childStatement->fetch()) {
$parentPhotoAlbum->clear();
$parentPhotoAlbum->setArray($admPhotoChild);
// add entry to array of all photo albums
$photoAlbumsArray[$parentPhotoAlbum->getValue('pho_uuid')] =
$vorschub . '— ' . $parentPhotoAlbum->getValue('pho_name') . ' (' . $parentPhotoAlbum->getValue('pho_begin', 'Y') . ')';
subfolder((int)$parentPhotoAlbum->getValue('pho_id'), $vorschub, $currentAlbumPhoId);
}//while
}//function
// create html page object
$page = new HtmlPage('admidio-photo-album-edit', $headline);
// show form
$form = new Form(
'photos_edit_form',
'modules/photos.album.edit.tpl',
SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/photos/photo_album_function.php', array('photo_uuid' => $getPhotoUuid, 'mode' => 'edit')),
$page
);
$form->addInput(
'pho_name',
$gL10n->get('SYS_ALBUM'),
$photoAlbum->getValue('pho_name'),
array('property' => Form::FIELD_REQUIRED, 'maxLength' => 50)
);
subfolder(0, '', $photoAlbum->getValue('pho_id'));
$form->addSelectBox(
'parent_album_uuid',
$gL10n->get('SYS_PARENT_ALBUM'),
$photoAlbumsArray,
array(
'property' => Form::FIELD_REQUIRED,
'defaultValue' => $getParentPhotoUuid,
'showContextDependentFirstEntry' => false,
'helpTextId' => $gL10n->get('SYS_PARENT_ALBUM_DESC', array('SYS_PHOTO_ALBUMS'))
)
);
$form->addInput(
'pho_begin',
$gL10n->get('SYS_START'),
$photoAlbum->getValue('pho_begin'),
array('property' => Form::FIELD_REQUIRED, 'type' => 'date', 'maxLength' => 10)
);
$form->addInput(
'pho_end',
$gL10n->get('SYS_END'),
$photoAlbum->getValue('pho_end'),
array('type' => 'date', 'maxLength' => 10)
);
$form->addInput(
'pho_photographers',
$gL10n->get('SYS_PHOTOS_BY'),
$photoAlbum->getValue('pho_photographers'),
array('maxLength' => 100)
);
$form->addMultilineTextInput(
'pho_description',
$gL10n->get('SYS_DESCRIPTION'),
$photoAlbum->getValue('pho_description'),
6,
array('maxLength' => 4000)
);
$form->addCheckbox(
'pho_locked',
$gL10n->get('SYS_LOCK_ALBUM'),
(bool)$photoAlbum->getValue('pho_locked'),
array('helpTextId' => 'SYS_LOCK_ALBUM_DESC')
);
$form->addSubmitButton(
'btn_save',
$gL10n->get('SYS_SAVE'),
array('icon' => 'bi-check-lg', 'class' => 'offset-sm-3')
);
$page->assignSmartyVariable('nameUserCreated', $photoAlbum->getNameOfCreatingUser());
$page->assignSmartyVariable('timestampUserCreated', $photoAlbum->getValue('ann_timestamp_create'));
$page->assignSmartyVariable('nameLastUserEdited', $photoAlbum->getNameOfLastEditingUser());
$page->assignSmartyVariable('timestampLastUserEdited', $photoAlbum->getValue('ann_timestamp_change'));
$form->addToHtmlPage();
$gCurrentSession->addFormObject($form);
$page->show();
} catch (Exception $e) {
$gMessage->show($e->getMessage());
}