You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

441 lines
22KB

  1. <?php
  2. /**
  3. * Copyright La boîte à pain (2018)
  4. *
  5. * contact@souke.fr
  6. *
  7. * Ce logiciel est un programme informatique servant à aider les producteurs
  8. * à distribuer leur production en circuits courts.
  9. *
  10. * Ce logiciel est régi par la licence CeCILL soumise au droit français et
  11. * respectant les principes de diffusion des logiciels libres. Vous pouvez
  12. * utiliser, modifier et/ou redistribuer ce programme sous les conditions
  13. * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  14. * sur le site "http://www.cecill.info".
  15. *
  16. * En contrepartie de l'accessibilité au code source et des droits de copie,
  17. * de modification et de redistribution accordés par cette licence, il n'est
  18. * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  19. * seule une responsabilité restreinte pèse sur l'auteur du programme, le
  20. * titulaire des droits patrimoniaux et les concédants successifs.
  21. *
  22. * A cet égard l'attention de l'utilisateur est attirée sur les risques
  23. * associés au chargement, à l'utilisation, à la modification et/ou au
  24. * développement et à la reproduction du logiciel par l'utilisateur étant
  25. * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  26. * manipuler et qui le réserve donc à des développeurs et des professionnels
  27. * avertis possédant des connaissances informatiques approfondies. Les
  28. * utilisateurs sont donc invités à charger et tester l'adéquation du
  29. * logiciel à leurs besoins dans des conditions permettant d'assurer la
  30. * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  31. * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  32. *
  33. * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  34. * pris connaissance de la licence CeCILL, et que vous en avez accepté les
  35. * termes.
  36. */
  37. use common\helpers\Environment;
  38. use common\helpers\GlobalParam;
  39. use common\helpers\Image;
  40. use domain\Feature\Feature\Feature;
  41. use domain\Feature\Feature\FeatureModule;
  42. use domain\Order\Order\Order;
  43. use domain\Order\Order\OrderRepositoryQuery;
  44. use domain\PointSale\PointSale\PointSaleModule;
  45. use domain\Producer\Producer\ProducerModule;
  46. use domain\Product\Product\ProductModule;
  47. use domain\User\User\UserModule;
  48. use domain\User\UserProducer\UserProducer;
  49. use yii\bootstrap5\Nav;
  50. use yii\helpers\Html;
  51. \common\assets\CommonAsset::register($this);
  52. \producer\assets\AppAsset::register($this);
  53. $userModule = UserModule::getInstance();
  54. $userCurrent = GlobalParam::getCurrentUser();
  55. $producerModule = ProducerModule::getInstance();
  56. $featureModule = FeatureModule::getInstance();
  57. $productModule = ProductModule::getInstance();
  58. $pointSaleModule = PointSaleModule::getInstance();
  59. $userMessageModule = $this->getUserMessageModule();
  60. $producerUser = null;
  61. if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
  62. $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);
  63. }
  64. $producer = $this->context->getProducerCurrent();
  65. if (!Yii::$app->user->isGuest) {
  66. $userProducer = UserProducer::findOne(['id_user' => GlobalParam::getCurrentUserId(), 'id_producer' => $producer->id]);
  67. }
  68. $mainColor = $producer->option_main_color ?: '#ee6f42' ;
  69. ?>
  70. <?php $this->beginPage() ?>
  71. <!DOCTYPE html>
  72. <html lang="fr-FR">
  73. <head>
  74. <title>
  75. <?php if($this->getControllerAction() == 'site/index'): ?>
  76. <?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?>
  77. <?php else: ?>
  78. <?= $this->getPageTitle(); ?> | <?= Html::encode($producer->name); ?>
  79. <?php endif; ?>
  80. </title>
  81. <meta charset="utf-8">
  82. <meta name="viewport" content="width=device-width, initial-scale=1">
  83. <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">
  84. <meta name="slug-producer" content="<?= $producer->slug; ?>">
  85. <?= Environment::metaRobotsNoIndexBeta(); ?>
  86. <?= Html::csrfMetaTags() ?>
  87. <link rel="icon" type="image/png"
  88. href="<?php echo \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon-souke-1.png"/>
  89. <?php $this->head() ?>
  90. <?= $this->render('@common/views/matomo.php') ?>
  91. <style>
  92. #header #title h1 a.producer-name,
  93. #header #title h2 .location .bi,
  94. #content a,
  95. .credit-history #credit-user,
  96. .credit-history #content .table span.payment-positive,
  97. .order-order #main #app-order-order #steps ul li .info-step,
  98. .block-date .month,
  99. #footer-producer a {
  100. color: <?= $mainColor ?>
  101. }
  102. #header nav#main-nav ul a.active,
  103. #header nav#main-nav ul li a:hover,
  104. #header nav#main-nav ul li a span.label-success,
  105. #main .btn-primary,
  106. .order-order #main #app-order-order #steps ul li .btn.btn-primary,
  107. ul.pagination li.active a, ul.pagination li a:hover, ul.pagination li a:focus, ul.pagination li a:active,
  108. .order-order #main #app-order-order table#products tr.total .price-total span,
  109. .subscription-create .subscription-form .products tr.total .price-total span,
  110. .subscription-update .subscription-form .products tr.total .price-total span {
  111. background-color: <?= $mainColor ?>;
  112. }
  113. #main .badge.bg-primary {
  114. background-color: <?= $mainColor ?> !important;
  115. }
  116. #header nav#main-nav {
  117. border-top: solid 5px <?= $mainColor ?>;
  118. }
  119. #main form .form-control:focus {
  120. box-shadow: 0px 0px 0px 1px <?= $mainColor ?>;
  121. border: solid 1px <?= $mainColor ?>;
  122. }
  123. .order-order #main #app-order-order #steps ul li .btn.btn-primary::after {
  124. border-left: 17px solid <?= $mainColor ?>;
  125. }
  126. #header nav#main-nav ul li a span.label.label-success {
  127. border: solid 1px <?= $mainColor ?>;
  128. }
  129. .order-order #main #app-order-order table#products tr.category-open td.category-name,
  130. .order-order #main #app-order-order table#products tr.category-closed td.category-name:hover{
  131. border-left-color: <?= $mainColor ?>;
  132. }
  133. </style>
  134. </head>
  135. <body class="<?= \Yii::$app->controller->id . '-' . \Yii::$app->controller->action->id ?>">
  136. <?php $this->beginBody() ?>
  137. <?= $this->render('@common/views/nav_user_top', [
  138. 'context' => 'producer'
  139. ]); ?>
  140. <div id="main" class="container">
  141. <?php $hasLogo = strlen($producer->logo) && Image::isPhotoExist($producer->logo); ?>
  142. <div id="header" class="<?= $hasLogo ? 'with-logo' : 'without-logo'; ?>">
  143. <?php if (strlen($producer->photo) || strlen($producer->logo)): ?>
  144. <div id="banner" style="background-color: <?= $mainColor ?>;<?php if(strlen($producer->photo)): ?>background-image:url(<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= urlencode($producer->photo); ?>);<?php endif; ?>">
  145. </div>
  146. <?php endif; ?>
  147. <?php if ($hasLogo): ?>
  148. <div id="logo"<?php if (!is_null($producer->background_color_logo) && strlen($producer->background_color_logo)): ?> style="background-color:<?= Html::encode($producer->background_color_logo); ?>"<?php endif; ?>>
  149. <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
  150. <img class="img-logo"
  151. src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  152. alt="Logo <?= Html::encode($producer->name) ?>"/>
  153. </a>
  154. </div>
  155. <?php endif; ?>
  156. <div id="title">
  157. <h1>
  158. <a class="producer-name" href="<?= Yii::$app->urlManager->createUrl(['site/index']); ?>">
  159. <?= Html::encode($producer->name); ?>
  160. </a>
  161. <?php if (!Yii::$app->user->isGuest): ?>
  162. <?php if ($userProducer && $userProducer->bookmark): ?>
  163. <a class="bookmark"
  164. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'delete']); ?>"
  165. data-bs-toggle="tooltip" data-bs-placement="top" title="Supprimer de ma liste de producteurs">
  166. <i class="bi bi-bookmark-heart-fill"></i>
  167. </a>
  168. <?php else: ?>
  169. <a class="bookmark"
  170. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'add']); ?>"
  171. data-bs-toggle="tooltip" data-bs-placement="top"
  172. title="Ajouter à ma liste de producteurs">
  173. <i class="bi bi-bookmark-heart"></i>
  174. </a>
  175. <?php endif; ?>
  176. <?php endif; ?>
  177. </h1>
  178. <h2>
  179. <?= Html::encode($producer->type) ?>
  180. <span class="location">
  181. <i class="bi bi-geo-alt-fill"></i>
  182. <?= Html::encode($producer->postcode); ?> <?= Html::encode($producer->city); ?>
  183. </span>
  184. </h2>
  185. </div>
  186. <nav id="main-nav">
  187. <?php
  188. $credit = '';
  189. if (isset($userProducer) && $userProducer) {
  190. $labelType = $userProducer->credit > 0 ? 'success' : 'danger';
  191. $credit = ' <span class="label label-' . $labelType . '">' . number_format($userProducer->credit, 2, ',', ' ') . ' €</span>';
  192. }
  193. $countSubcriptions = 0;
  194. if ($userCurrent) {
  195. $countSubcriptions = $this->getSubscriptionModule()->countSubscriptionsByUser(
  196. $userCurrent
  197. );
  198. }
  199. $labelSubscription = $countSubcriptions > 0 ? 'success' : 'default';
  200. $countOrders = Order::find()
  201. ->joinWith(['distribution'])
  202. ->where([
  203. 'id_user' => GlobalParam::getCurrentUserId(),
  204. 'distribution.id_producer' => GlobalParam::getCurrentProducerId()
  205. ])
  206. ->params([':date_today' => date('Y-m-d')])
  207. ->andWhere('distribution.date >= :date_today')
  208. ->andWhere(OrderRepositoryQuery::getSqlFilterIsValid())
  209. ->count();
  210. $labelOrders = $countOrders > 0 ? 'success' : 'default';
  211. $isUserSubscribedNewsletter = $userModule->getNewsletterManager()->isUserSubscribedOneNewsletter($userCurrent);
  212. $isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']);
  213. echo Nav::widget([
  214. 'encodeLabels' => false,
  215. 'options' => ['class' => ''],
  216. 'items' => [
  217. [
  218. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  219. 'label' => '<i class="bi bi-house-door"></i> <span class="hide-desktop"> Accueil</span>',
  220. 'active' => $isHome,
  221. ],
  222. [
  223. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  224. 'url' => $this->getUrlManagerProducer()->createUrl(['order/order']),
  225. 'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
  226. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  227. ],
  228. [
  229. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  230. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $this->context->getProducerCurrent()->id, 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order', 'slug_producer' => $this->context->getProducerCurrent()->slug])]),
  231. 'visible' => !$producer->option_allow_order_guest && \Yii::$app->user->isGuest,
  232. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  233. ],
  234. [
  235. 'label' => '<i class="bi bi-folder2-open"></i> Mes commandes <span class="label label-' . $labelOrders . '">' . $countOrders . '</span>',
  236. 'url' => $this->getUrlManagerProducer()->createUrl(['order/history']),
  237. 'visible' => !Yii::$app->user->isGuest,
  238. 'active' => $this->getControllerAction() == 'order/history',
  239. ],
  240. [
  241. 'label' => '<i class="bi bi-arrow-repeat"></i> Abonnements <span class="label label-' . $labelSubscription . '">' . $countSubcriptions . '</span>',
  242. 'url' => $this->getUrlManagerProducer()->createUrl(['subscription/index']),
  243. 'visible' => !Yii::$app->user->isGuest && $producer->user_manage_subscription,
  244. 'active' => in_array($this->getControllerAction(), ['subscription/index', 'subscription/form']),
  245. ],
  246. [
  247. 'label' => '<i class="bi bi-piggy-bank"></i> Cagnotte' . $credit,
  248. 'url' => $this->getUrlManagerProducer()->createUrl(['credit/history']),
  249. 'visible' => !Yii::$app->user->isGuest && $producer->credit,
  250. 'active' => $this->getControllerAction() == 'credit/history',
  251. ],
  252. [
  253. 'label' => '<i class="bi bi-megaphone"></i> Infolettre <span class="label label-' . ($isUserSubscribedNewsletter ? 'success' : 'danger') . '">' . ($isUserSubscribedNewsletter ? 'Oui' : 'Non') . '</span>',
  254. 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
  255. 'visible' => !Yii::$app->user->isGuest,
  256. 'active' => $this->getControllerAction() == 'newsletter/index',
  257. ],
  258. [
  259. 'label' => '<i class="bi bi-envelope"></i> Contact',
  260. 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']),
  261. 'active' => $this->getControllerAction() == 'site/contact',
  262. 'visible' => $featureModule->getChecker()->isEnabled(Feature::ALIAS_CONTACT)
  263. ],
  264. ],
  265. ]);
  266. $submenuItems = null;
  267. if($isHome) {
  268. $submenuItems = [
  269. [
  270. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  271. 'label' => 'Présentation',
  272. 'active' => $this->getControllerAction() == 'site/index',
  273. ],
  274. [
  275. 'url' => $this->getUrlManagerProducer()->createUrl(['site/products']),
  276. 'label' => 'Produits <span class="label label-default">'.$productModule->getRepository()->countProducts(true).'</span>',
  277. 'active' => $this->getControllerAction() == 'site/products',
  278. ],
  279. [
  280. 'url' => $this->getUrlManagerProducer()->createUrl(['site/points-sale']),
  281. 'label' => $producerModule->getSolver()->getPointSaleWording($producer).' <span class="label label-default">'.$pointSaleModule->getRepository()->countPointSalesPublic().'</span>',
  282. 'active' => $this->getControllerAction() == 'site/points-sale',
  283. ],
  284. ];
  285. }
  286. if($submenuItems) {
  287. echo Nav::widget([
  288. 'encodeLabels' => false,
  289. 'options' => ['class' => 'submenu'],
  290. 'items' => $submenuItems
  291. ]);
  292. }
  293. ?>
  294. </nav>
  295. <div id="infos-producer">
  296. <?php if (!$this->getProducerModule()->hasSpecificDelays($producer) && $producer->order_deadline && $producer->order_delay): ?>
  297. <span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
  298. <span class="glyphicon glyphicon-time"></span> Commande avant
  299. <strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
  300. <span data-toggle="tooltip" data-placement="bottom"
  301. title="Exemple : commande le lundi pour le
  302. <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi
  303. <?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi
  304. <?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche
  305. <?php elseif ($producer->order_delay == 7): ?>lundi d'après<?php endif; ?>"><strong><?= Html::encode($producer->order_delay) ?> jour<?php if ($producer->order_delay > 1): ?>s<?php endif; ?></strong> à l'avance</span>
  306. <?php endif; ?>
  307. <div class="clr"></div>
  308. </div>
  309. </div>
  310. <section id="content">
  311. <?php
  312. // Message utilisateur
  313. if($userCurrent):
  314. $userMessagesArray = $userMessageModule->getRepository()->findUserMessagesUnreadByUser($userCurrent);
  315. if($userMessagesArray && count($userMessagesArray)):
  316. foreach($userMessagesArray as $userMessage): ?>
  317. <div class="alert alert-info">
  318. <h4 class="alert-heading">
  319. <i class="bi bi-envelope"></i>
  320. Nouveau message
  321. </h4>
  322. <p><?= nl2br(Html::encode($userMessage->getMessage())) ?></p>
  323. <p>
  324. <a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['site/'.($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userMessage->getCreatedBy()) ? 'support' : 'contact')]); ?>">
  325. Répondre</a>
  326. &bull;
  327. <a class="alert-link" href="<?= Yii::$app->urlManager->createUrl(['site/user-message-read', 'idUserMessage' => $userMessage->getId()]); ?>">
  328. Fermer
  329. </a>
  330. </p>
  331. </div>
  332. <?php endforeach;
  333. endif;
  334. endif; ?>
  335. <?php
  336. // Message congés
  337. $leavePeriodMessageDisplay = $producerModule->getSolver()->getConfig('option_leave_period_message_display', $producer);
  338. $leavePeriodMessageTitle = $producerModule->getSolver()->getConfig('option_leave_period_message_title', $producer);
  339. $leavePeriodMessage = $producerModule->getSolver()->getConfig('option_leave_period_message', $producer);
  340. if($leavePeriodMessageDisplay && ($leavePeriodMessageTitle || $leavePeriodMessage)): ?>
  341. <div class="alert alert-warning alert-leave-period">
  342. <?php if($leavePeriodMessageTitle): ?>
  343. <h4 class="alert-heading<?php if(!$leavePeriodMessage): ?> without-message<?php endif; ?>">
  344. <i class="bi bi-calendar-range"></i>
  345. <?= $leavePeriodMessageTitle ?>
  346. </h4>
  347. <?php endif; ?>
  348. <?php if($leavePeriodMessage): ?>
  349. <p>
  350. <?php if(!$leavePeriodMessageTitle): ?><i class="bi bi-calendar-range"></i><?php endif; ?>
  351. <?= nl2br(Html::encode($leavePeriodMessage)) ?>
  352. </p>
  353. <?php endif; ?>
  354. </div>
  355. <?php endif; ?>
  356. <?php if (strlen($this->getTitle())): ?>
  357. <h2 id="page-title">
  358. <?= $this->getTitle(); ?>
  359. <?php
  360. if ($this->buttons && count($this->buttons)): ?>
  361. <span id="buttons">
  362. <?php foreach ($this->buttons as $button) {
  363. echo '<a href="' . \Yii::$app->urlManagerProducer->createUrl($button['url']) . '" class="' . $button['class'] . '">' . $button['label'] . '</a>';
  364. }
  365. ?>
  366. </span>
  367. <?php endif; ?>
  368. </h2>
  369. <?php endif; ?>
  370. <?php if (Yii::$app->session->hasFlash('error')): ?>
  371. <div class="alert alert-danger" role="alert">
  372. <?= \Yii::$app->session->getFlash('error') ?>
  373. </div>
  374. <?php endif; ?>
  375. <?php if (Yii::$app->session->hasFlash('success')): ?>
  376. <div class="alert alert-success" role="alert">
  377. <?= \Yii::$app->session->getFlash('success') ?>
  378. </div>
  379. <?php endif; ?>
  380. <?= $content ?>
  381. </section>
  382. </div>
  383. <?php if (strlen($producer->mentions) || strlen($producer->gcs)): ?>
  384. <div id="footer-producer">
  385. <?php if (strlen($producer->mentions)): ?>
  386. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/mentions']); ?>">Mentions légales</a>
  387. <?php endif; ?>
  388. <?php if (strlen($producer->mentions) && strlen($producer->gcs)): ?> | <?php endif; ?>
  389. <?php if (strlen($producer->gcs)): ?>
  390. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/gcs']); ?>">Conditions générales de vente</a>
  391. <?php endif; ?>
  392. </div>
  393. <?php endif; ?>
  394. <footer id="footer" class="container">
  395. <div class="content">
  396. <!--<a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">Souke</a> &bull;
  397. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/mentions']); ?>">Mentions légales</a> &bull;
  398. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/cgv']); ?>">CGS</a>-->
  399. <?php if($featureModule->getChecker()->isEnabled(Feature::ALIAS_SHOP_SUPPORT)): ?>
  400. <div id="button-shop-support">
  401. <a href="<?= Yii::$app->urlManager->createUrl(['site/support']) ?>" class="btn btn-sm btn-secondary">
  402. <i class="bi bi-life-preserver"></i>
  403. Besoin d'aide ?
  404. </a>
  405. </div>
  406. <?php endif; ?>
  407. </div>
  408. </footer>
  409. <script type="text/javascript" src="https://cdn.polyfill.io/v3/polyfill.min.js?features=Intl.~locale.fr"></script>
  410. <?php $this->endBody() ?>
  411. </body>
  412. </html>
  413. <?php $this->endPage() ?>