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.

403 lines
20KB

  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\GlobalParam;
  38. use common\helpers\Image;
  39. use domain\Feature\Feature\Feature;
  40. use domain\Feature\Feature\FeatureModule;
  41. use domain\Order\Order\Order;
  42. use domain\PointSale\PointSale\PointSaleModule;
  43. use domain\Producer\Producer\ProducerModule;
  44. use domain\Product\Product\ProductModule;
  45. use domain\User\User\UserModule;
  46. use domain\User\UserProducer\UserProducer;
  47. use yii\bootstrap5\Nav;
  48. use yii\helpers\Html;
  49. \common\assets\CommonAsset::register($this);
  50. \producer\assets\AppAsset::register($this);
  51. $userModule = UserModule::getInstance();
  52. $userCurrent = GlobalParam::getCurrentUser();
  53. $producerModule = ProducerModule::getInstance();
  54. $featureModule = FeatureModule::getInstance();
  55. $productModule = ProductModule::getInstance();
  56. $pointSaleModule = PointSaleModule::getInstance();
  57. $producerUser = null;
  58. if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
  59. $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);
  60. }
  61. $producer = $this->context->getProducerCurrent();
  62. if (!Yii::$app->user->isGuest) {
  63. $userProducer = UserProducer::findOne(['id_user' => GlobalParam::getCurrentUserId(), 'id_producer' => $producer->id]);
  64. }
  65. $mainColor = $producer->option_main_color ?: '#ee6f42' ;
  66. ?>
  67. <?php $this->beginPage() ?>
  68. <!DOCTYPE html>
  69. <html lang="fr-FR">
  70. <head>
  71. <title>
  72. <?php if($this->getControllerAction() == 'site/index'): ?>
  73. <?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?>
  74. <?php else: ?>
  75. <?= $this->getPageTitle(); ?> | <?= Html::encode($producer->name); ?>
  76. <?php endif; ?>
  77. </title>
  78. <meta charset="utf-8">
  79. <meta name="viewport" content="width=device-width, initial-scale=1">
  80. <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">
  81. <meta name="slug-producer" content="<?= $producer->slug; ?>">
  82. <?= Html::csrfMetaTags() ?>
  83. <link rel="icon" type="image/png"
  84. href="<?php echo \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon-souke-1.png"/>
  85. <?php $this->head() ?>
  86. <?= $this->render('@common/views/matomo.php') ?>
  87. <style>
  88. #header #title h1 a.producer-name,
  89. #header #title h2 .location .bi,
  90. #content a,
  91. .credit-history #credit-user,
  92. .credit-history #content .table span.payment-positive,
  93. .order-order #main #app-order-order #steps ul li .info-step,
  94. .block-date .month,
  95. #footer-producer a {
  96. color: <?= $mainColor ?>
  97. }
  98. #header nav#main-nav ul a.active,
  99. #header nav#main-nav ul li a:hover,
  100. #header nav#main-nav ul li a span.label-success,
  101. #main .btn-primary,
  102. .order-order #main #app-order-order #steps ul li .btn.btn-primary,
  103. ul.pagination li.active a, ul.pagination li a:hover, ul.pagination li a:focus, ul.pagination li a:active,
  104. .order-order #main #app-order-order table#products tr.total .price-total span,
  105. .subscription-create .subscription-form .products tr.total .price-total span,
  106. .subscription-update .subscription-form .products tr.total .price-total span {
  107. background-color: <?= $mainColor ?>;
  108. }
  109. #main .badge.bg-primary {
  110. background-color: <?= $mainColor ?> !important;
  111. }
  112. #header nav#main-nav {
  113. border-top: solid 5px <?= $mainColor ?>;
  114. }
  115. #main form .form-control:focus {
  116. box-shadow: 0px 0px 0px 1px <?= $mainColor ?>;
  117. border: solid 1px <?= $mainColor ?>;
  118. }
  119. .order-order #main #app-order-order #steps ul li .btn.btn-primary::after {
  120. border-left: 17px solid <?= $mainColor ?>;
  121. }
  122. #header nav#main-nav ul li a span.label.label-success {
  123. border: solid 1px <?= $mainColor ?>;
  124. }
  125. .order-order #main #app-order-order table#products tr.category-open td.category-name,
  126. .order-order #main #app-order-order table#products tr.category-closed td.category-name:hover{
  127. border-left-color: <?= $mainColor ?>;
  128. }
  129. </style>
  130. </head>
  131. <body class="<?= \Yii::$app->controller->id . '-' . \Yii::$app->controller->action->id ?>">
  132. <?php $this->beginBody() ?>
  133. <?= $this->render('@common/views/nav_user_top', [
  134. 'context' => 'producer'
  135. ]); ?>
  136. <div id="main" class="container">
  137. <?php $hasLogo = strlen($producer->logo) && Image::isPhotoExist($producer->logo); ?>
  138. <div id="header" class="<?= $hasLogo ? 'with-logo' : 'without-logo'; ?>">
  139. <?php if (strlen($producer->photo) || strlen($producer->logo)): ?>
  140. <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; ?>">
  141. </div>
  142. <?php endif; ?>
  143. <?php if ($hasLogo): ?>
  144. <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; ?>>
  145. <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
  146. <img class="img-logo"
  147. src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  148. alt="Logo <?= Html::encode($producer->name) ?>"/>
  149. </a>
  150. </div>
  151. <?php endif; ?>
  152. <div id="title">
  153. <h1>
  154. <a class="producer-name" href="<?= Yii::$app->urlManager->createUrl(['site/index']); ?>">
  155. <?= Html::encode($producer->name); ?>
  156. </a>
  157. <?php if (!Yii::$app->user->isGuest): ?>
  158. <?php if ($userProducer && $userProducer->bookmark): ?>
  159. <a class="bookmark"
  160. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'delete']); ?>"
  161. data-bs-toggle="tooltip" data-bs-placement="top" title="Supprimer de ma liste de producteurs">
  162. <i class="bi bi-bookmark-heart-fill"></i>
  163. </a>
  164. <?php else: ?>
  165. <a class="bookmark"
  166. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'add']); ?>"
  167. data-bs-toggle="tooltip" data-bs-placement="top"
  168. title="Ajouter à ma liste de producteurs">
  169. <i class="bi bi-bookmark-heart"></i>
  170. </a>
  171. <?php endif; ?>
  172. <?php endif; ?>
  173. </h1>
  174. <h2>
  175. <?= Html::encode($producer->type) ?>
  176. <span class="location">
  177. <i class="bi bi-geo-alt-fill"></i>
  178. <?= Html::encode($producer->postcode); ?> <?= Html::encode($producer->city); ?>
  179. </span>
  180. </h2>
  181. </div>
  182. <nav id="main-nav">
  183. <?php
  184. $credit = '';
  185. if (isset($userProducer) && $userProducer) {
  186. $labelType = $userProducer->credit > 0 ? 'success' : 'danger';
  187. $credit = ' <span class="label label-' . $labelType . '">' . number_format($userProducer->credit, 2, ',', ' ') . ' €</span>';
  188. }
  189. $countSubcriptions = 0;
  190. if ($userCurrent) {
  191. $countSubcriptions = $this->getSubscriptionModule()->countSubscriptionsByUser(
  192. $userCurrent
  193. );
  194. }
  195. $labelSubscription = $countSubcriptions > 0 ? 'success' : 'default';
  196. $countOrders = Order::find()
  197. ->joinWith(['distribution'])
  198. ->where([
  199. 'id_user' => GlobalParam::getCurrentUserId(),
  200. 'distribution.id_producer' => GlobalParam::getCurrentProducerId()
  201. ])
  202. ->params([':date_today' => date('Y-m-d')])
  203. ->andWhere('distribution.date >= :date_today')
  204. ->count();
  205. $labelOrders = $countOrders > 0 ? 'success' : 'default';
  206. $isUserSubscribedNewsletter = $userModule->isUserSubscribedNewsletter($userCurrent);
  207. $isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']);
  208. echo Nav::widget([
  209. 'encodeLabels' => false,
  210. 'options' => ['class' => ''],
  211. 'items' => [
  212. [
  213. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  214. 'label' => '<i class="bi bi-house-door"></i> <span class="hide-desktop"> Accueil</span>',
  215. 'active' => $isHome,
  216. ],
  217. [
  218. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  219. 'url' => $this->getUrlManagerProducer()->createUrl(['order/order']),
  220. 'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
  221. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  222. ],
  223. [
  224. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  225. '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])]),
  226. 'visible' => !$producer->option_allow_order_guest && \Yii::$app->user->isGuest,
  227. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  228. ],
  229. [
  230. 'label' => '<i class="bi bi-folder2-open"></i> Mes commandes <span class="label label-' . $labelOrders . '">' . $countOrders . '</span>',
  231. 'url' => $this->getUrlManagerProducer()->createUrl(['order/history']),
  232. 'visible' => !Yii::$app->user->isGuest,
  233. 'active' => $this->getControllerAction() == 'order/history',
  234. ],
  235. [
  236. 'label' => '<i class="bi bi-arrow-repeat"></i> Abonnements <span class="label label-' . $labelSubscription . '">' . $countSubcriptions . '</span>',
  237. 'url' => $this->getUrlManagerProducer()->createUrl(['subscription/index']),
  238. 'visible' => !Yii::$app->user->isGuest && $producer->user_manage_subscription,
  239. 'active' => in_array($this->getControllerAction(), ['subscription/index', 'subscription/form']),
  240. ],
  241. [
  242. 'label' => '<i class="bi bi-piggy-bank"></i> Cagnotte' . $credit,
  243. 'url' => $this->getUrlManagerProducer()->createUrl(['credit/history']),
  244. 'visible' => !Yii::$app->user->isGuest && $producer->credit,
  245. 'active' => $this->getControllerAction() == 'credit/history',
  246. ],
  247. [
  248. 'label' => '<i class="bi bi-megaphone"></i> Infolettre <span class="label label-' . ($isUserSubscribedNewsletter ? 'success' : 'danger') . '">' . ($isUserSubscribedNewsletter ? 'Oui' : 'Non') . '</span>',
  249. 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
  250. 'visible' => !Yii::$app->user->isGuest,
  251. 'active' => $this->getControllerAction() == 'newsletter/index',
  252. ],
  253. [
  254. 'label' => '<i class="bi bi-envelope"></i> Contact',
  255. 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']),
  256. 'active' => $this->getControllerAction() == 'site/contact',
  257. 'visible' => $featureModule->getChecker()->isEnabled(Feature::ALIAS_CONTACT)
  258. ],
  259. ],
  260. ]);
  261. $submenuItems = null;
  262. if($isHome) {
  263. $submenuItems = [
  264. [
  265. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  266. 'label' => 'Présentation',
  267. 'active' => $this->getControllerAction() == 'site/index',
  268. ],
  269. [
  270. 'url' => $this->getUrlManagerProducer()->createUrl(['site/products']),
  271. 'label' => 'Produits <span class="label label-default">'.$productModule->getRepository()->countProducts(true).'</span>',
  272. 'active' => $this->getControllerAction() == 'site/products',
  273. ],
  274. [
  275. 'url' => $this->getUrlManagerProducer()->createUrl(['site/points-sale']),
  276. 'label' => 'Points de vente <span class="label label-default">'.$pointSaleModule->getRepository()->countPointSalesPublic().'</span>',
  277. 'active' => $this->getControllerAction() == 'site/points-sale',
  278. ],
  279. ];
  280. }
  281. if($submenuItems) {
  282. echo Nav::widget([
  283. 'encodeLabels' => false,
  284. 'options' => ['class' => 'submenu'],
  285. 'items' => $submenuItems
  286. ]);
  287. }
  288. ?>
  289. </nav>
  290. <div id="infos-producer">
  291. <?php if (!$this->getProducerModule()->hasSpecificDelays($producer) && $producer->order_deadline && $producer->order_delay): ?>
  292. <span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
  293. <span class="glyphicon glyphicon-time"></span> Commande avant
  294. <strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
  295. <span data-toggle="tooltip" data-placement="bottom"
  296. title="Exemple : commande le lundi pour le
  297. <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi
  298. <?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi
  299. <?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche
  300. <?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>
  301. <?php endif; ?>
  302. <div class="clr"></div>
  303. </div>
  304. </div>
  305. <section id="content">
  306. <?php
  307. // Message congés
  308. $leavePeriodMessageDisplay = $producerModule->getSolver()->getConfig('option_leave_period_message_display', $producer);
  309. $leavePeriodMessageTitle = $producerModule->getSolver()->getConfig('option_leave_period_message_title', $producer);
  310. $leavePeriodMessage = $producerModule->getSolver()->getConfig('option_leave_period_message', $producer);
  311. if($leavePeriodMessageDisplay && ($leavePeriodMessageTitle || $leavePeriodMessage)): ?>
  312. <div class="alert alert-warning alert-leave-period">
  313. <?php if($leavePeriodMessageTitle): ?>
  314. <h4 class="alert-heading<?php if(!$leavePeriodMessage): ?> without-message<?php endif; ?>">
  315. <i class="bi bi-calendar-range"></i>
  316. <?= $leavePeriodMessageTitle ?>
  317. </h4>
  318. <?php endif; ?>
  319. <?php if($leavePeriodMessage): ?>
  320. <p>
  321. <?php if(!$leavePeriodMessageTitle): ?><i class="bi bi-calendar-range"></i><?php endif; ?>
  322. <?= nl2br(Html::encode($leavePeriodMessage)) ?>
  323. </p>
  324. <?php endif; ?>
  325. </div>
  326. <?php endif; ?>
  327. <?php if (strlen($this->getTitle())): ?>
  328. <h2 id="page-title">
  329. <?= $this->getTitle(); ?>
  330. <?php
  331. if ($this->buttons && count($this->buttons)): ?>
  332. <span id="buttons">
  333. <?php foreach ($this->buttons as $button) {
  334. echo '<a href="' . \Yii::$app->urlManagerProducer->createUrl($button['url']) . '" class="' . $button['class'] . '">' . $button['label'] . '</a>';
  335. }
  336. ?>
  337. </span>
  338. <?php endif; ?>
  339. </h2>
  340. <?php endif; ?>
  341. <?php if (Yii::$app->session->hasFlash('error')): ?>
  342. <div class="alert alert-danger" role="alert">
  343. <?= \Yii::$app->session->getFlash('error') ?>
  344. </div>
  345. <?php endif; ?>
  346. <?php if (Yii::$app->session->hasFlash('success')): ?>
  347. <div class="alert alert-success" role="alert">
  348. <?= \Yii::$app->session->getFlash('success') ?>
  349. </div>
  350. <?php endif; ?>
  351. <?= $content ?>
  352. </section>
  353. </div>
  354. <?php if (strlen($producer->mentions) || strlen($producer->gcs)): ?>
  355. <div id="footer-producer">
  356. <?php if (strlen($producer->mentions)): ?>
  357. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/mentions']); ?>">Mentions légales</a>
  358. <?php endif; ?>
  359. <?php if (strlen($producer->mentions) && strlen($producer->gcs)): ?> | <?php endif; ?>
  360. <?php if (strlen($producer->gcs)): ?>
  361. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/gcs']); ?>">Conditions générales de vente</a>
  362. <?php endif; ?>
  363. </div>
  364. <?php endif; ?>
  365. <footer id="footer" class="container">
  366. <div class="content">
  367. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">Souke</a> &bull;
  368. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/mentions']); ?>">Mentions légales</a> &bull;
  369. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/cgv']); ?>">CGS</a>
  370. </div>
  371. </footer>
  372. <script type="text/javascript" src="https://cdn.polyfill.io/v3/polyfill.min.js?features=Intl.~locale.fr"></script>
  373. <?php $this->endBody() ?>
  374. </body>
  375. </html>
  376. <?php $this->endPage() ?>