blob: 7f920af3ebe23ea850ebad5b7dc9ccf026957f37 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
Adrià Vilanova Martínez5af86512023-12-02 20:44:16 +01002/*
3 * hores
4 * Copyright (c) 2023 Adrià Vilanova Martínez
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public
17 * License along with this program.
18 * If not, see http://www.gnu.org/licenses/.
19 */
20
Copybara botbe50d492023-11-30 00:16:42 +010021require_once("core.php");
22security::checkType(security::ADMIN);
23
24$mdHeaderRowBefore = visual::backBtn("settings.php");
25?>
26<!DOCTYPE html>
27<html>
28<head>
29 <title><?php echo $conf["appName"]; ?></title>
30 <?php visual::includeHead(); ?>
31 <link rel="stylesheet" href="css/dashboard.css">
32
33 <style>
34 .addcompany {
35 position: fixed;
36 bottom: 16px;
37 right: 16px;
38 z-index: 1000;
39 }
40
41 @media (max-width: 655px) {
42 .extra {
43 display: none;
44 }
45 }
46 </style>
47</head>
48<?php visual::printBodyTag(); ?>
49 <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
50 <?php visual::includeNav(); ?>
51 <button class="addcompany mdl-button md-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--accent"><i class="material-icons">add</i><span class="mdl-ripple"></span></button>
52 <main class="mdl-layout__content">
53 <div class="page-content">
54 <div class="main mdl-shadow--4dp">
55 <h2>Empresas</h2>
56 <?php
57 $companies = companies::getAll(false);
58 if (count($companies)) {
59 ?>
60 <div class="overflow-wrapper overflow-wrapper--for-table">
61 <table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp">
62 <thead>
63 <tr>
64 <th class="extra">ID</th>
65 <th class="mdl-data-table__cell--non-numeric">Empresa</th>
66 <th class="mdl-data-table__cell--non-numeric">CIF</th>
67 <th class="mdl-data-table__cell--non-numeric"></th>
68 </tr>
69 </thead>
70 <tbody>
71 <?php
72 foreach ($companies as $c) {
73 ?>
74 <tr>
75 <td class="extra"><?=(int)$c["id"]?></td>
76 <td class="mdl-data-table__cell--non-numeric"><?=security::htmlsafe($c["name"])?></td>
77 <td class="mdl-data-table__cell--non-numeric"><?=(empty($c["cif"]) ? "-" : security::htmlsafe($c["cif"]))?></td>
78 <td class='mdl-data-table__cell--non-numeric'><a href='dynamic/editcompany.php?id=<?=(int)$c["id"]?>' data-dyndialog-href='dynamic/editcompany.php?id=<?=(int)$c["id"]?>' title='Editar empresa'><i class='material-icons icon'>edit</i></a></td>
79 </tr>
80 <?php
81 }
82 ?>
83 </tbody>
84 </table>
85 </div>
86 <?php
87 } else {
88 ?>
89 <p>Todavía no hay definida ninguna empresa.</p>
90 <p>Puedes añadir una haciendo clic en el botón de la esquina inferior derecha de la página.</p>
91 <?php
92 }
93 ?>
94
95 <?php visual::printDebug("companies::getAll()", $companies); ?>
96 </div>
97 </div>
98 </main>
99 </div>
100
101 <dialog class="mdl-dialog" id="addcompany">
102 <form action="doaddcompany.php" method="POST" autocomplete="off">
103 <h4 class="mdl-dialog__title">Añade una empresa</h4>
104 <div class="mdl-dialog__content">
105 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
106 <input class="mdl-textfield__input" type="text" name="name" id="name" autocomplete="off" data-required>
107 <label class="mdl-textfield__label" for="name">Nombre de la empresa</label>
108 </div>
109 <br>
110 <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
111 <input class="mdl-textfield__input" type="text" name="cif" id="cif" autocomplete="off">
112 <label class="mdl-textfield__label" for="cif">CIF (opcional)</label>
113 </div>
114 </div>
115 <div class="mdl-dialog__actions">
116 <button type="submit" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--accent">Añadir</button>
117 <button onclick="event.preventDefault(); document.querySelector('#addcompany').close();" class="mdl-button mdl-js-button mdl-js-ripple-effect cancel">Cancelar</button>
118 </div>
119 </form>
120 </dialog>
121
122 <?php
123 visual::smartSnackbar([
124 ["added", "Se ha añadido la empresa correctamente."],
125 ["modified", "Se ha modificado la empresa correctamente."],
126 ["empty", "Faltan datos por introducir en el formulario."],
127 ["unexpected", "Ha ocurrido un error inesperado. Inténtelo de nuevo en unos segundos."]
128 ]);
129 ?>
130
131 <script src="js/companies.js"></script>
132</body>
133</html>