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.

header.php 19KB

1 vuosi sitten
9 kuukautta sitten
9 kuukautta sitten
9 kuukautta sitten
8 kuukautta sitten
8 kuukautta sitten
9 kuukautta sitten
9 kuukautta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <?php
  2. /**
  3. * Copyright Souke (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 common\helpers\Price;
  40. use domain\Distribution\Distribution\Distribution;
  41. use domain\Feature\Feature\Feature;
  42. use domain\Feature\Feature\FeatureModule;
  43. use domain\Producer\Producer\Producer;
  44. use domain\Producer\Producer\ProducerModule;
  45. use domain\Setting\AdminSettingBag;
  46. use domain\User\User\UserModule;
  47. use common\helpers\Environment;
  48. use yii\helpers\Html;
  49. $userModule = UserModule::getInstance();
  50. $producerModule = ProducerModule::getInstance();
  51. $producer = GlobalParam::getCurrentProducer();
  52. $userCurrent = GlobalParam::getCurrentUser();
  53. $featureChecker = FeatureModule::getInstance()->getChecker();
  54. $adminSettingBag = AdminSettingBag::getInstance();
  55. ?>
  56. <header class="main-header">
  57. <?php $beta = Environment::badgeBeta(); ?>
  58. <?= Html::a('<span class="logo-mini"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-souke.svg" /></span><span class="logo-lg"><img src="' . Yii::$app->urlManagerBackend->getBaseUrl() . '/img/logo-souke.svg" />'.$beta.'</span>'.$beta, Yii::$app->homeUrl, ['class' => 'logo']) ?>
  59. <?php /*Html::a(
  60. 'Opendistrib',
  61. $userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)
  62. ? Yii::$app->urlManager->createUrl('dashboard-admin/index')
  63. : Yii::$app->homeUrl,
  64. ['class' => 'logo']
  65. );*/ ?>
  66. <nav class="navbar navbar-static-top" role="navigation">
  67. <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
  68. <span class="sr-only">Toggle navigation</span>
  69. </a>
  70. <span class="producer-panel<?php if(!$producer->logo || !Image::isPhotoExist($producer->logo)): ?> without-logo<?php endif; ?>">
  71. <?php if($producer->logo && Image::isPhotoExist($producer->logo)): ?>
  72. <span class="logo">
  73. <img class="img-logo"
  74. src="<?= Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  75. alt="Logo <?= Html::encode($producer->name) ?>" />
  76. </span>
  77. <?php endif; ?>
  78. <div class="title">
  79. <?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
  80. <a href="<?= Yii::$app->urlManager->createUrl(['producer-admin/update', 'id' => $producer->id]) ?>">
  81. <?php endif; ?>
  82. <?= Html::encode($producer->name) ?>
  83. <?php if($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
  84. </a>
  85. <?php endif; ?>
  86. <?php if ($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
  87. <span class="producer-id">#<?= $producer->id ?></span>
  88. <?php endif; ?>
  89. <?php if (!$producer->active): ?>
  90. <span class="label label-danger">Hors-ligne</span>
  91. <?php endif; ?>
  92. </div>
  93. </span>
  94. <div class="navbar-custom-menu">
  95. <?php
  96. $usersArray = $userModule->queryUsersBy(['id_producer' => GlobalParam::getCurrentProducerId()])
  97. ->andWhere('CAST(FROM_UNIXTIME(user.created_at) AS date) > \'' . date("Y-m-d", strtotime("-7 days")) . '\'')
  98. ->orderBy('created_at DESC')
  99. ->all();
  100. ?>
  101. <ul class="nav navbar-nav">
  102. <?php if ($userModule->getAuthorizationChecker()->isGrantedAsAdministrator($userCurrent)): ?>
  103. <li class="dropdown producer-menu">
  104. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  105. <i class="bi bi-bookmarks"></i>
  106. <span class="hidden-xs hidden-sm">Producteurs</span>
  107. <i class="fa fa-caret-down"></i>
  108. </a>
  109. <ul class="dropdown-menu">
  110. <li>
  111. <input type="text" class="search-producer form-control" placeholder="Rechercher" />
  112. </li>
  113. <li class="li-alert-no-results">
  114. <div class="alert alert-warning">Aucun producteur trouvé</div>
  115. </li>
  116. <?php $producersArray = Producer::find()->orderBy('name ASC')->all(); ?>
  117. <?php foreach ($producersArray as $producer): ?>
  118. <?php if ($producer->active == 1 && $producer->is_new): ?>
  119. <li class="producer">
  120. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>">
  121. <label class="label label-info">Nouveau</label>
  122. <?= Html::encode($producer->name) ?>
  123. <span class="producer-id">#<?= $producer->id ?></span>
  124. </a>
  125. </li>
  126. <?php endif; ?>
  127. <?php endforeach; ?>
  128. <?php foreach ($producersArray as $producer): ?>
  129. <?php if ($producer->active == 1 && !$producer->is_new): ?>
  130. <li class="producer">
  131. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>">
  132. <?php if($producer->is_new): ?> <label class="label label-info">Nouveau</label> <?php endif; ?>
  133. <?= Html::encode($producer->name) ?>
  134. <span class="producer-id">#<?= $producer->id ?></span>
  135. </a>
  136. </li>
  137. <?php endif; ?>
  138. <?php endforeach; ?>
  139. <?php foreach ($producersArray as $producer): ?>
  140. <?php if ($producer->active != 1): ?>
  141. <li class="producer">
  142. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/switch-producer', 'id' => $producer->id]); ?>">
  143. <label class="label label-danger">Hors-ligne</label>
  144. <?= Html::encode($producer->name) ?>
  145. <span class="producer-id">#<?= $producer->id ?></span>
  146. </a>
  147. </li>
  148. <?php endif; ?>
  149. <?php endforeach; ?>
  150. </ul>
  151. </li>
  152. <?php endif; ?>
  153. <?php
  154. $pastDistributionsArray = Distribution::find()
  155. ->where(['<', 'distribution.date', date('Y-m-d')])
  156. ->andWhere([
  157. 'distribution.id_producer' => GlobalParam::getCurrentProducerId(),
  158. 'distribution.active' => 1
  159. ])
  160. ->orderBy('date DESC')
  161. ->limit(3)
  162. ->all();
  163. $pastDistributionsArray = array_reverse($pastDistributionsArray);
  164. $incomingDistributionsArray = Distribution::find()
  165. ->where(['>=', 'distribution.date', date('Y-m-d')])
  166. ->andWhere([
  167. 'distribution.id_producer' => GlobalParam::getCurrentProducerId(),
  168. 'distribution.active' => 1
  169. ])
  170. ->orderBy('date ASC')
  171. ->limit(20)
  172. ->all();
  173. ?>
  174. <li class="dropdown distributions-menu notifications-menu">
  175. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  176. <i class="bi bi-calendar"></i>
  177. <i class="fa fa-caret-down"></i>
  178. </a>
  179. <ul class="dropdown-menu">
  180. <?php if (count($pastDistributionsArray)): ?>
  181. <li class="header">3 dernières distributions :</li>
  182. <li>
  183. <ul class="menu">
  184. <?php foreach ($pastDistributionsArray as $distribution): ?>
  185. <li>
  186. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['distribution/index', 'date' => $distribution->date]); ?>">
  187. <h5><?= strftime('%A %d %B', strtotime($distribution->date)) ?></h5>
  188. </a>
  189. </li>
  190. <?php endforeach; ?>
  191. </ul>
  192. </li>
  193. <?php endif; ?>
  194. <?php if (count($incomingDistributionsArray)): ?>
  195. <li class="header">Prochaines distributions :</li>
  196. <li>
  197. <ul class="menu">
  198. <?php foreach ($incomingDistributionsArray as $distribution): ?>
  199. <li>
  200. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['distribution/index', 'date' => $distribution->date]); ?>">
  201. <h5><?= strftime('%A %d %B', strtotime($distribution->date)) ?></h5>
  202. </a>
  203. </li>
  204. <?php endforeach; ?>
  205. </ul>
  206. </li>
  207. <?php else: ?>
  208. <li class="header">
  209. Aucune distribution prévue.<br/>
  210. <a class="btn btn-default"
  211. href="<?= Yii::$app->urlManagerBackend->createUrl(['distribution/index']); ?>">Gérer
  212. mes distributions</a>
  213. </li>
  214. <?php endif; ?>
  215. </ul>
  216. </li>
  217. <li class="dropdown users-menu notifications-menu">
  218. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  219. <i class="bi bi-person-plus"></i>
  220. <?php if (count($usersArray)): ?><span
  221. class="label label-success"><?= count($usersArray) ?></span>
  222. <?php else: ?><span class="label label-warning">0</span><?php endif; ?>
  223. <i class="fa fa-caret-down"></i>
  224. </a>
  225. <ul class="dropdown-menu">
  226. <?php if (count($usersArray)): ?>
  227. <li class="header">Inscriptions des 7 derniers jours</li>
  228. <li>
  229. <ul class="menu">
  230. <?php foreach ($usersArray as $user): ?>
  231. <li>
  232. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/update', 'id' => $user['user_id']]); ?>">
  233. <h5><?= Html::encode((isset($user['name_legal_person']) && strlen($user['name_legal_person'])) ? $user['name_legal_person'] : $user['name'] . ' ' . $user['lastname']); ?>
  234. <small>
  235. <i class="fa fa-clock-o"></i> <?= date('d/m/Y à H:i', $user['created_at']); ?>
  236. </small>
  237. </h5>
  238. </a>
  239. </li>
  240. <?php endforeach; ?>
  241. </ul>
  242. </li>
  243. <?php else: ?>
  244. <li class="header">Aucun nouvel inscrit ces 7 derniers jours.</li>
  245. <?php endif; ?>
  246. </ul>
  247. </li>
  248. <?php
  249. $usersNegativeCreditArray = $userModule->findUsersWithNegativeCredit();
  250. ?>
  251. <li class="dropdown users-negative-credit-menu notifications-menu">
  252. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  253. <i class="bi bi-currency-euro"></i>
  254. <?php if (count($usersNegativeCreditArray)): ?><span
  255. class="label label-warning"><?= count($usersNegativeCreditArray) ?></span>
  256. <?php else: ?><span class="label label-success">0</span><?php endif; ?>
  257. <i class="fa fa-caret-down"></i>
  258. </a>
  259. <ul class="dropdown-menu">
  260. <?php if (count($usersNegativeCreditArray)): ?>
  261. <li class="header"><a href="<?= Yii::$app->urlManager->createUrl(['credit/index']); ?>">Utilisateurs avec une cagnotte en négatif</a></li>
  262. <li>
  263. <ul class="menu">
  264. <?php foreach ($usersNegativeCreditArray as $user): ?>
  265. <li>
  266. <a href="<?= Yii::$app->urlManagerBackend->createUrl(['user/credit', 'id' => $user['user_id']]); ?>">
  267. <h5><?= $userModule->getUsernameFromArray($user); ?>
  268. <small>
  269. <i class="fa fa-euro"></i> <?= Price::format($user['credit']); ?>
  270. </small>
  271. </h5>
  272. </a>
  273. </li>
  274. <?php endforeach; ?>
  275. </ul>
  276. </li>
  277. <?php else: ?>
  278. <li class="header">Aucun de vos utilisateurs n'a de cagnotte en négatif.</li>
  279. <?php endif; ?>
  280. </ul>
  281. </li>
  282. <li>
  283. <a href="<?= Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">
  284. <i class="bi bi-house-door"></i>
  285. <span class="hidden-xs hidden-sm">Accueil</span>
  286. </a>
  287. </li>
  288. <?php if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)): ?>
  289. <li>
  290. <a href="<?= Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => GlobalParam::getCurrentProducer()->slug]); ?>">
  291. <i class="bi bi-shop"></i>
  292. <span class="hidden-xs hidden-sm">Ma boutique</span>
  293. </a>
  294. </li>
  295. <?php endif; ?>
  296. <?php if($featureChecker->isEnabled(Feature::ALIAS_FORUM)): ?>
  297. <li>
  298. <a href="<?= $adminSettingBag->get('forumFlarumUrl') ?>" target="_blank">
  299. <i class="bi bi-people"></i>
  300. <span class="hidden-xs hidden-sm">Forum</span>
  301. </a>
  302. </li>
  303. <?php endif; ?>
  304. <li class="dropdown user user-menu">
  305. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  306. <i class="bi bi-person"></i>
  307. <span class="hidden-xs hidden-sm"><?= Html::encode(GlobalParam::getCurrentUser()->name . ' ' . substr(GlobalParam::getCurrentUser()->lastname, 0, 1) .'.'); ?></span>
  308. <i class="fa fa-caret-down"></i>
  309. </a>
  310. <ul class="dropdown-menu">
  311. <!--<li><a href="<?= Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">
  312. <i class="bi bi-house-door"></i> Accueil</a></li>-->
  313. <li><a href="<?= Yii::$app->urlManagerFrontend->createAbsoluteUrl(['user/update']); ?>">
  314. <i class="bi bi-person"></i> Mon profil</a></li>
  315. <li><a href="<?= Yii::$app->urlManagerBackend->createUrl(['site/logout']); ?>">
  316. <i class="bi bi-box-arrow-left"></i> Déconnexion</a></li>
  317. </ul>
  318. </li>
  319. <li class="link-control-sidebar">
  320. <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
  321. </li>
  322. </ul>
  323. </div>
  324. </nav>
  325. </header>