first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ActivateOrderController extends AbstractController
{
/**
* @TranslatedRoute("/#activate_order#/{type}/")
*/
public function activateOrderAction(string $type): RedirectResponse
{
// Pokud nemam modul reklamace a ani vratky, tak vratim 404
if (!findModule(\Modules::RECLAMATIONS) && !findModule(\Modules::RETURNS)) {
throw new NotFoundHttpException('Module RECLAMATIONS or RETURNS not found!');
}
switch ($type) {
case 'reclamations':
return new RedirectResponse(
path('kupshop_reclamations_reclamations_createreclamationlogin'),
301
);
case 'returns':
return new RedirectResponse(
path('kupshop_returns_returns_createreturnslogin'),
301
);
}
return new RedirectResponse('/');
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
}

View File

@@ -0,0 +1,36 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Exception\RedirectException;
use KupShop\OrderingBundle\View\IsicView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class IsicController extends AbstractController
{
/**
* @Route("/isic/")
*/
public function isicAction(Request $request, IsicView $view): Response
{
if (!findModule('isic')) {
throw new RedirectException(path('home'));
}
$view->setSession($request->getSession());
$data = $request->get('data');
if ($request->get('Submit') && !empty($data['id'])) {
$view->handleSubmit($data['id'], $data['name'] ?? null);
}
if ($request->get('cancel')) {
$view->handleCancel();
}
return $view->getResponse();
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\OrderingBundle\View\OrderRegisterView;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class OrderController extends AbstractController
{
/**
* @TranslatedRoute("/#orderView#/{id}/registrace/")
*/
public function orderRegisterAction(Request $request, OrderRegisterView $view, $id)
{
$view->setOrderId($id);
$view->setSecurityCode($request->get('cf'));
return $view->getResponse();
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\ContentBundle\View\OrderView;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\OrderingBundle\Util\Discount\DiscountGenerator;
use Query\Operator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class PDFCouponController extends AbstractController
{
/**
* @TranslatedRoute(path="/#orderView#/{id_order}/coupon/{id_coupon}", requirements={"id_order": "\d+", "id_coupon": "\d+"}, name="kupshop_orderingbundle_pdfcoupon")
*
* @return RedirectResponse
*/
public function getCouponPDF(DiscountGenerator $discountGenerator, Request $request, $id_order, $id_coupon)
{
OrderView::checkOrderOwnership($id_order, $request->get('cf'));
$id_coupon = sqlQueryBuilder()
->select('id')
->from('discounts_coupons')
->where(Operator::equals(['id' => $id_coupon, 'id_order_purchased' => $id_order]))
->execute()
->fetchColumn();
if (!$id_coupon) {
return new RedirectResponse(createScriptURL([
'URL' => 'launch.php',
's' => 'orders',
'ESCAPE' => 'NO',
]));
}
return $discountGenerator->getPDFResponse($id_coupon);
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Context\UserContext;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\OrderingBundle\Attachment\InvoicePDFAttachment;
use KupShop\OrderingBundle\Util\Invoice\PdfGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PDFInvoiceController extends AbstractController
{
/**
* @TranslatedRoute(path="/#orderView#/{id_order}/pdf/", requirements={"id_order": "\d+"}, name="kupshop_orderingbundle_pdfinvoice")
*
* @return RedirectResponse|Response
*/
public function getOrderInvoice(Request $request, PdfGenerator $pdf, $id_order)
{
// Check invoice download is enabled
if (findModule(\Modules::ORDERS, 'show_invoice', 'Y') == 'N') {
throw new NotFoundHttpException('Invoice download is disabled');
}
$userContext = Contexts::get(UserContext::class);
$allow_access = false;
$order = new \Order($id_order);
$order->createFromDB($id_order);
if (getAdminUser()) {
$allow_access = true;
} elseif ($request->query->get('cf')) {
if ($request->query->get('cf') == $order->getSecurityCode()) {
$allow_access = true;
}
} elseif ($userId = $userContext->getActiveId()) {
if ($id_order && ($order->getUser()->id ?? null) == $userId) {
$allow_access = true;
}
}
if (!$allow_access) {
return new RedirectResponse(createScriptURL([
'URL' => 'launch.php',
's' => 'orders',
'ESCAPE' => 'NO',
]));
}
if ($externalInvoiceUrl = ($order->getData('externalDocuments')[InvoicePDFAttachment::getType()] ?? null)) {
$externalPDFResponse = new Response(file_get_contents($externalInvoiceUrl));
$externalPDFResponse->headers->set('Content-Type', 'application/pdf; charset=utf8');
return $externalPDFResponse;
}
return $pdf->getResponse($order);
}
}

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace KupShop\OrderingBundle\Controller;
use KupShop\OrderingBundle\View\PPLParcelShopView;
use Symfony\Component\Routing\Annotation\Route;
class PPLParcelShopController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
/**
* @Route("/_pplparcelshop", name="pplparcelshop")
*/
public function PPLParcelShopAction(PPLParcelShopView $view)
{
return $view->getResponse();
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,103 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Util\System\PathFinder;
use KupShop\OrderingBundle\Util\UserContent\UserContent;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class UserContentController extends AbstractController
{
/** @var UserContent */
protected $userContent;
/**
* @required
*
* @return UserContentController
*/
public function setUserContent(UserContent $userContent)
{
$this->userContent = $userContent;
return $this;
}
/**
* @Route("/_upload/{type}/upload/")
*/
public function uploadAction(Request $request, string $type)
{
$uploadStatus = 'false';
/** @var File $file */
if ($file = $request->files->get('qqfile')) {
$originalFilename = $request->get('qqfilename') ?? time();
$filename = hash('sha1', hash_file('sha1', $file->getPathname()).'_'.time()).'.'.$file->guessExtension() ?? 'png';
// save file
if (move_uploaded_file($file->getPathname(), $this->getUserContentPath().$filename)) {
$uploadStatus = 'true';
if ($this->userContent->checkFileExist($type, $filename) === false) {
$this->userContent->save($type, $filename, $originalFilename, $request->get('qquuid'));
}
}
}
return $this->getResponse($uploadStatus);
}
/**
* @Route("/_upload/{type}/delete/{uid}")
*/
public function deleteAction($uid, string $type)
{
$deleteStatus = 'false';
if ($uid) {
$files = $this->userContent->getData($type);
if (!empty($files[$uid])) {
$filename = $files[$uid]['filename'];
if (file_exists($this->getUserContentPath().$filename)) {
if (unlink($this->getUserContentPath().$filename)) {
unset($files[$uid]);
$this->userContent->setData($type, $files);
$deleteStatus = 'true';
}
} else {
unset($files[$uid]);
$this->userContent->setData($type, $files);
$deleteStatus = 'true';
}
}
}
return $this->getResponse($deleteStatus);
}
/**
* @return Response
*/
private function getResponse($status)
{
$response = new Response();
$response->headers->set('Content-type', 'text/plain');
$response->setContent('{"success":'.$status.'}');
return $response;
}
/**
* @return string
*/
private function getUserContentPath()
{
$pathFinder = PathFinder::getService();
return $pathFinder->getDataDir().'files/user-content/';
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use Monolog\Logger;
use Picqer\Barcode\BarcodeGeneratorPNG;
use Query\Operator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class WpjController extends AbstractController
{
/**
* @Route("/_wpj/bounce/")
*
* @return Response
*/
public function bounceAction(Request $request)
{
$email = null;
preg_match_all('/(\s*\n)To: (.*)/', $request->getContent(), $matches);
if (!empty($matches)) {
$email = array_filter(end($matches), function ($x) { return $x != 'mail@kupshop.cz'; });
$email = reset($email);
}
if (!empty($email)) {
$this->log($email);
foreach ($this->getOrdersByEmail($email) as $order) {
sqlQueryBuilder()->update('orders')
->set('flags', 'ADD_TO_SET("NE", flags)')
->where(Operator::equals(['id' => $order['id']]))
->execute();
}
}
return new Response($request->getContent());
}
private function log($email)
{
/** @var Logger $logger */
$logger = ServiceContainer::getService('logger');
$logger->warning(
'Not able to deliver e-mail',
[
'email' => $email,
]
);
}
private function getOrdersByEmail(string $email)
{
return sqlQueryBuilder()
->select('id')
->from('orders')
->andWhere(Operator::equals(['invoice_email' => $email]))
->andWhere('DATEDIFF(NOW(), date_created) < 3')
->execute();
}
/**
* @Route("/_wpj/barcode/")
*
* @throws \Picqer\Barcode\Exceptions\BarcodeException
*/
public function barcodeAction(Request $request): Response
{
$type = 'int25';
if (!empty($_GET['type'])) {
$type = $_GET['type'];
}
if ($type == 'ean13') {
$_GET['oID'] = sprintf('%013d', intval($_GET['oID']));
}
$height = 60;
if (!empty($_GET['height'])) {
$height = $_GET['height'];
}
$size = $_GET['size'] ?? 1;
$show_value = ($_GET['showValue'] ?? '') !== 'false';
// Convert to BarcodeGenerator
$generator = new BarcodeGeneratorPNG();
switch ($type) {
case 'int25':
$type = $generator::TYPE_INTERLEAVED_2_5;
break;
case 'ean13':
$type = $generator::TYPE_EAN_13;
break;
case 'code39':
$type = $generator::TYPE_CODE_39;
break;
case 'code128':
$type = $generator::TYPE_CODE_128;
break;
}
$result = $generator->getBarcode($_GET['oID'], $type, $size + 1, $height);
$response = new Response($result);
$response->headers->set('Content-type', 'image/png');
return $response;
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace KupShop\OrderingBundle\Controller;
use KupShop\ContentBundle\View\OrderView;
use KupShop\KupShopBundle\Routing\TranslatedRoute;
use KupShop\OrderingBundle\Attachment\BaseAttachment;
use KupShop\OrderingBundle\Attachment\InvoiceXLSAttachment;
use KupShop\OrderingBundle\Exception\InvoiceException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class XLSInvoiceController extends AbstractController
{
/**
* @TranslatedRoute(path="/#orderView#/{id_order}/xls/", requirements={"id_order": "\d+"}, name="kupshop_orderingbundle_xlsinvoice")
*
* @return Response
*/
public function getOrderItems(Request $request, InvoiceXLSAttachment $invoiceXLSAttachment, $id_order)
{
OrderView::checkOrderOwnership($id_order, $request->get('cf'));
$order = $this->getOrder($id_order);
try {
$response = new Response();
$invoiceXLSAttachment->setOrder($order);
$content = $invoiceXLSAttachment->getContent();
$response->headers->set('Content-Type', $invoiceXLSAttachment->getMimeType());
$response->headers->set('Content-Disposition', 'inline; filename="'.$invoiceXLSAttachment->getFilename().'"');
if (!$content) {
throw new \UnexpectedValueException('XLS error: server returned false');
}
if ($invoiceXLSAttachment->getAttachmentType() == BaseAttachment::TYPE_PATH) {
$content = file_get_contents($content);
}
$response->setContent($content);
return $response;
} catch (\UnexpectedValueException $e) {
getRaven()->captureException($e);
return new Response('Přílohu se nepodařilo vygenerovat, zkuste to znovu.');
} catch (InvoiceException $e) {
return new Response($e->getMessage());
}
}
private function getOrder($id_order)
{
$order = new \Order($id_order);
$order->createFromDB($id_order);
return $order;
}
}