| ... | ... |
@@ -35,7 +35,7 @@ |
| 35 | 35 |
|
| 36 | 36 |
<div class="frame__body"> |
| 37 | 37 |
<h3>Reservierung ändern</h3> |
| 38 |
- <form hx-post="/_ajax/vr_wa/v1/slot?do=updateReservation"> |
|
| 38 |
+ <form hx-post="/_ajax/vr_wa/v1/slot?do=updateReservation" enctype="multipart/form-data"> |
|
| 39 | 39 |
<input type="hidden" name="id" value="{{ id }}">
|
| 40 | 40 |
<fieldset> |
| 41 | 41 |
<label for="res-behaelter">Liefernde Behältermenge</label> |
| ... | ... |
@@ -52,6 +52,19 @@ |
| 52 | 52 |
<label><input type="checkbox" name="sorten[]" value="{{ value }}"{{ value in buchung.sorten|keys ? ' checked' : '' }}> <span class="checkable">{{ label }}</span></label><br>
|
| 53 | 53 |
{% endfor %}
|
| 54 | 54 |
</fieldset> |
| 55 |
+ {% if file is defined %}
|
|
| 56 |
+ <fieldset> |
|
| 57 |
+ <div class="t-label">Aktuelle Datei</div> |
|
| 58 |
+ <div class="u-flex u-items-center u-gap-1"><a href="{{ file.link }}">{{ file.name }}</a> <a href="javascript:;" hx-get="/_ajax/vr_wa/v1/slot?do=booking&id={{ id }}&modal=false&deleteFile=true" hx-target="closest .frame" hx-swap="outerHTML" class="tag tag__close-btn tag--danger tag--xs"></a></div>
|
|
| 59 |
+ </fieldset> |
|
| 60 |
+ <fieldset> |
|
| 61 |
+ <label for="res-upload">Datei überschreiben</label> |
|
| 62 |
+ {% else %}
|
|
| 63 |
+ <fieldset> |
|
| 64 |
+ <label for="res-upload">Datei hochladen</label> |
|
| 65 |
+ {% endif %}
|
|
| 66 |
+ <input type="file" id="res-upload" name="upload"> |
|
| 67 |
+ </fieldset> |
|
| 55 | 68 |
<fieldset> |
| 56 | 69 |
<button type="submit">Speichern</button> |
| 57 | 70 |
</fieldset> |
| ... | ... |
@@ -14,8 +14,12 @@ namespace vonRotenberg\WeinanlieferungBundle\Controller\Frontend\Ajax; |
| 14 | 14 |
|
| 15 | 15 |
use Contao\Controller; |
| 16 | 16 |
use Contao\CoreBundle\Controller\AbstractController; |
| 17 |
+use Contao\CoreBundle\Exception\PageNotFoundException; |
|
| 17 | 18 |
use Contao\CoreBundle\Framework\ContaoFramework; |
| 18 | 19 |
use Contao\CoreBundle\Security\Authentication\Token\TokenChecker; |
| 20 |
+use Contao\Environment; |
|
| 21 |
+use Contao\File; |
|
| 22 |
+use Contao\FilesModel; |
|
| 19 | 23 |
use Contao\FormFileUpload; |
| 20 | 24 |
use Contao\Frontend; |
| 21 | 25 |
use Contao\FrontendUser; |
| ... | ... |
@@ -170,6 +174,8 @@ class SlotAjaxController extends AbstractController |
| 170 | 174 |
|
| 171 | 175 |
protected function renderBooking(bool $blnModal=true) |
| 172 | 176 |
{
|
| 177 |
+ $arrData = []; |
|
| 178 |
+ |
|
| 173 | 179 |
if (empty($_REQUEST['id'])) |
| 174 | 180 |
{
|
| 175 | 181 |
return new Response('Required parameter missing',412);
|
| ... | ... |
@@ -181,6 +187,49 @@ class SlotAjaxController extends AbstractController |
| 181 | 187 |
return new Response('Could not load booking data',500);
|
| 182 | 188 |
} |
| 183 | 189 |
|
| 190 |
+ $objFile = FilesModel::findByUuid($Booking->upload); |
|
| 191 |
+ |
|
| 192 |
+ if (!empty($_REQUEST['deleteFile']) && $_REQUEST['deleteFile'] && $objFile !== null) |
|
| 193 |
+ {
|
|
| 194 |
+ $File = new File($objFile->path); |
|
| 195 |
+ if ($File->delete()) |
|
| 196 |
+ {
|
|
| 197 |
+ $objFile->delete(); |
|
| 198 |
+ $objFile = null; |
|
| 199 |
+ } |
|
| 200 |
+ } |
|
| 201 |
+ |
|
| 202 |
+ if (!empty($Booking->upload) && $objFile !== null) |
|
| 203 |
+ {
|
|
| 204 |
+ $File = new File($objFile->path); |
|
| 205 |
+ $strHref = Environment::get('request');
|
|
| 206 |
+ |
|
| 207 |
+ // Remove an existing file parameter (see #5683) |
|
| 208 |
+ if (isset($_GET['file'])) |
|
| 209 |
+ {
|
|
| 210 |
+ $strHref = preg_replace('/(&(amp;)?|\?)file=[^&]+/', '', $strHref);
|
|
| 211 |
+ } |
|
| 212 |
+ |
|
| 213 |
+ $strHref .= (strpos($strHref, '?') !== false ? '&' : '?') . 'file=' . System::urlEncode($File->value); |
|
| 214 |
+ |
|
| 215 |
+ $arrData['file'] = [ |
|
| 216 |
+ 'link' => $strHref, |
|
| 217 |
+ 'filename' => $File->filename, |
|
| 218 |
+ 'extension' => $File->extension, |
|
| 219 |
+ 'name' => $File->name, |
|
| 220 |
+ 'path' => $File->dirname |
|
| 221 |
+ ]; |
|
| 222 |
+ } |
|
| 223 |
+ |
|
| 224 |
+ // Send the file to the browser (see #4632 and #8375) |
|
| 225 |
+ if ($objFile !== null && ($file = Input::get('file', true)))
|
|
| 226 |
+ {
|
|
| 227 |
+ if ($file == $objFile->path) |
|
| 228 |
+ {
|
|
| 229 |
+ Controller::sendFileToBrowser($file); |
|
| 230 |
+ } |
|
| 231 |
+ } |
|
| 232 |
+ |
|
| 184 | 233 |
$arrSortenAvailable = []; |
| 185 | 234 |
$Sorten = StringUtil::deserialize($Slot->sorten,true); |
| 186 | 235 |
foreach($Sorten as $sorte) |
| ... | ... |
@@ -201,7 +250,7 @@ class SlotAjaxController extends AbstractController |
| 201 | 250 |
|
| 202 | 251 |
$intAvailableBehaelter = $Slot->getAvailableBehaelter(); |
| 203 | 252 |
|
| 204 |
- $arrData = [ |
|
| 253 |
+ $arrData = array_merge($arrData,[ |
|
| 205 | 254 |
'modal' => $blnModal, |
| 206 | 255 |
'id' => $Booking->id, |
| 207 | 256 |
'slot' => array_merge($Slot->row(),[ |
| ... | ... |
@@ -217,7 +266,7 @@ class SlotAjaxController extends AbstractController |
| 217 | 266 |
'behaelter' => range(min($intAvailableBehaelter,1),$intAvailableBehaelter+$Booking->behaelter), |
| 218 | 267 |
'sorten' => $arrSortenAvailable |
| 219 | 268 |
] |
| 220 |
- ]; |
|
| 269 |
+ ]); |
|
| 221 | 270 |
|
| 222 | 271 |
return $this->render('@Contao/modal_booking_details.html.twig',$arrData);
|
| 223 | 272 |
} |
| ... | ... |
@@ -277,6 +326,8 @@ class SlotAjaxController extends AbstractController |
| 277 | 326 |
|
| 278 | 327 |
protected function updateReservation() |
| 279 | 328 |
{
|
| 329 |
+ Controller::loadDataContainer('tl_vr_wa_reservation');
|
|
| 330 |
+ |
|
| 280 | 331 |
if (empty($_REQUEST['id']) || empty(Input::post('behaelter')) || empty(Input::post('sorten')))
|
| 281 | 332 |
{
|
| 282 | 333 |
return new Response('Missing parameter',412);
|
| ... | ... |
@@ -287,6 +338,24 @@ class SlotAjaxController extends AbstractController |
| 287 | 338 |
return new Response('Could not load booking data',500);
|
| 288 | 339 |
} |
| 289 | 340 |
|
| 341 |
+ if (($rootPage = Frontend::getRootPageFromUrl()) !== null && !empty($rootPage->vr_wa_uploadFolderSRC)) |
|
| 342 |
+ {
|
|
| 343 |
+ $File = new FormFileUpload(\Contao\Widget::getAttributesFromDca($GLOBALS['TL_DCA']['tl_vr_wa_reservation']['fields']['upload'], 'upload')); |
|
| 344 |
+ $File->storeFile = true; |
|
| 345 |
+ $File->doNotOverwrite = true; |
|
| 346 |
+ $File->uploadFolder = $rootPage->vr_wa_uploadFolderSRC; |
|
| 347 |
+ |
|
| 348 |
+ $File->validate(); |
|
| 349 |
+ |
|
| 350 |
+ if ($File->hasErrors()) |
|
| 351 |
+ {
|
|
| 352 |
+ return $this->renderDetails(false,'<div class="toast toast--danger mx-0">' . $File->getErrorAsHTML() . '</div>'); |
|
| 353 |
+ } |
|
| 354 |
+ |
|
| 355 |
+ $Reservation->filename = $_SESSION['FILES'][$File->name]['name'] ?? ''; |
|
| 356 |
+ $Reservation->upload = $_SESSION['FILES'][$File->name]['uuid'] ? StringUtil::uuidToBin($_SESSION['FILES'][$File->name]['uuid']) : null; |
|
| 357 |
+ } |
|
| 358 |
+ |
|
| 290 | 359 |
$arrSorten = []; |
| 291 | 360 |
if (!is_array(Input::post('sorten')))
|
| 292 | 361 |
{
|