From aef4925a67e05823f1578cac9daa3646b4bf6e74 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 16:44:59 +0200 Subject: [PATCH 1/6] update changelog --- src/EventListener/DataContainerListener.php | 51 +++++++++++++++---- .../contao/dca/tl_vehicle_account.php | 9 ++-- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/EventListener/DataContainerListener.php b/src/EventListener/DataContainerListener.php index 049ef4f..0516d5d 100644 --- a/src/EventListener/DataContainerListener.php +++ b/src/EventListener/DataContainerListener.php @@ -19,9 +19,12 @@ use Contao\BackendTemplate; use Contao\BackendUser; use Contao\Controller; +use Contao\CoreBundle\Security\ContaoCorePermissions; use Contao\CoreBundle\ServiceAnnotation\Callback; +use Contao\Database; use Contao\DataContainer; use Contao\Image; +use Contao\Input; use Contao\StringUtil; use Contao\System; use Pdir\MobileDeBundle\Module\MobileDeSetup; @@ -120,21 +123,47 @@ public function getVehicleVehicleAccountOptions(DataContainer $dc) */ public function visibleButtonCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string { - // disable the button if the user is not admin or apiType = man - if (!$this->user->isAdmin || 'man' === $row['apiType']) { - $title = !$this->user->isAdmin ? $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackAdminOnly'] : $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackUnused']; + $security = System::getContainer()->get('security.helper'); + + // disable the button if the user has no access or apiType = man + if (!$security->isGranted(ContaoCorePermissions::USER_CAN_EDIT_FIELD_OF_TABLE, 'tl_vehicle_account::enabled') || + 'man' === $row['apiType'] + ) { + $title = 'man' === $row['apiType'] ? $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackUnused']: $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackAdminOnly']; return ''.Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).''; } - // build variables - $published = $row['enabled'] ? 1 : 0; - $unpublished = $row['enabled'] ? 0 : 1; - $url = Controller::addToUrl("&tid={$row['id']}&state=$published"); - $icon = 0 === $row['enabled'] ? 'invisible.svg' : $icon; - $_title = StringUtil::specialchars($title); - $image = Image::getHtml($icon, $label, "data-state='$unpublished'"); + // toggle visibility + if (strlen(Input::get('state'))) { + $this->toggleVisibility($row['id'], (Input::get('state'))); + Controller::redirect(Controller::getReferer()); + } + + $href .= '&state=' . ($row['enabled'] ? 1 : 0) . '&id=' . $row['id'] . '&rt=' . REQUEST_TOKEN; + + if (!$row['enabled']) + { + $icon = 'invisible.svg'; + } + + return '' . Image::getHtml($icon, $label, 'data-icon="' . Image::getPath('visible.svg') . '" data-icon-disabled="' . Image::getPath('invisible.svg') . '" data-state="' . ($row['enabled'] ? 1 : 0) . '"') . ' '; + } + + /** + * Disable/enable a vehicle account + * + * @param integer $intId + * @param boolean $blnVisible + * @param DataContainer $dc + */ + public function toggleVisibility(int $intId, bool $blnVisible) + { + Input::setGet('id', $intId); + Input::setGet('act', 'toggle'); - return "$image"; + // Update the database + Database::getInstance()->prepare("UPDATE tl_vehicle_account SET tstamp=". time() .", enabled='" . ($blnVisible ? '' : 1) . "' WHERE id=?") + ->execute($intId); } } diff --git a/src/Resources/contao/dca/tl_vehicle_account.php b/src/Resources/contao/dca/tl_vehicle_account.php index 316461a..f745f3a 100644 --- a/src/Resources/contao/dca/tl_vehicle_account.php +++ b/src/Resources/contao/dca/tl_vehicle_account.php @@ -57,6 +57,7 @@ 'icon' => 'delete.svg', ], 'toggle' => [ + 'href' => 'act=toggle&field=enabled', 'label' => &$GLOBALS['TL_LANG'][$strTable]['enable'], 'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"', 'icon' => 'visible.svg', @@ -148,11 +149,11 @@ 'sql' => "varchar(64) NOT NULL default ''", ], 'enabled' => [ - 'exclude' => true, - 'default' => false, + 'toggle' => true, + 'filter' => true, 'inputType' => 'checkbox', - 'eval' => ['doNotCopy'=>true], - 'sql' => ['type' => 'boolean', 'default' => false], + 'eval' => ['doNotCopy' => true], + 'sql' => ['type' => 'boolean', 'default' => false] ], ], ]; From 36cf24e8ce46932f3fe8a95b90a71e7fbaa54598 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 16:55:51 +0200 Subject: [PATCH 2/6] add eval submitOnChange --- src/Resources/contao/dca/tl_vehicle_account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/contao/dca/tl_vehicle_account.php b/src/Resources/contao/dca/tl_vehicle_account.php index f745f3a..1b2db32 100644 --- a/src/Resources/contao/dca/tl_vehicle_account.php +++ b/src/Resources/contao/dca/tl_vehicle_account.php @@ -109,7 +109,7 @@ 'exclude' => true, 'inputType' => 'select', 'options' => &$GLOBALS['TL_LANG'][$strTable]['apiTypeOptions'], - 'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'], + 'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50', 'submitOnChange' => true], 'sql' => "varchar(64) NOT NULL default ''", ], 'api_explanation' => [ From e8ec4290611e182d1d50d969b7b2c224b7a678f4 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 17:45:20 +0200 Subject: [PATCH 3/6] update version --- src/Module/MobileDeSetup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/MobileDeSetup.php b/src/Module/MobileDeSetup.php index 513636b..8898419 100644 --- a/src/Module/MobileDeSetup.php +++ b/src/Module/MobileDeSetup.php @@ -24,7 +24,7 @@ class MobileDeSetup extends \BackendModule /** * mobilede version. */ - const VERSION = '3.3.0'; + const VERSION = '3.3.1'; /** * Extension mode. From 3e7a9339742fbd163831981e6ba23dcdb9d56282 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 17:47:44 +0200 Subject: [PATCH 4/6] update version and changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b83d1f2..0bf5f04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,12 @@ Types of changes Security in case of vulnerabilities. ) -## [3.3.1](https://github.com/pdir/mobilede-bundle/tree/3.3.1) – 2022-08-02 +## [3.3.2](https://github.com/pdir/mobilede-bundle/tree/3.3.2) – 2022-08-09 + +- [Fixed] account creation +- [Fixed] fix enabled button + +## [3.3.1](https://github.com/pdir/mobilede-bundle/tree/3.3.2) – 2022-08-02 - [Fixed] fix demo data for Contao 4.13 From a9a92676a372199c862d66992ef034821e37702a Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 17:47:55 +0200 Subject: [PATCH 5/6] update version and changelog --- src/Module/MobileDeSetup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/MobileDeSetup.php b/src/Module/MobileDeSetup.php index 8898419..c90195e 100644 --- a/src/Module/MobileDeSetup.php +++ b/src/Module/MobileDeSetup.php @@ -24,7 +24,7 @@ class MobileDeSetup extends \BackendModule /** * mobilede version. */ - const VERSION = '3.3.1'; + const VERSION = '3.3.2'; /** * Extension mode. From a505eb7c7430820aba327d42ea2d27ab5ba8f147 Mon Sep 17 00:00:00 2001 From: Mathias Arzberger Date: Tue, 9 Aug 2022 17:48:55 +0200 Subject: [PATCH 6/6] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bf5f04..48f3763 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ Types of changes - [Fixed] account creation - [Fixed] fix enabled button -## [3.3.1](https://github.com/pdir/mobilede-bundle/tree/3.3.2) – 2022-08-02 +## [3.3.1](https://github.com/pdir/mobilede-bundle/tree/3.3.1) – 2022-08-02 - [Fixed] fix demo data for Contao 4.13