Aggiunta tabella regioni

This commit is contained in:
Luca 2022-04-22 19:08:53 +02:00
parent d47786e2f3
commit 372b97853a
3 changed files with 75 additions and 2 deletions

View File

@ -341,6 +341,25 @@ switch ($resource) {
break;
case 'regioni':
if (isset($superselect['id_nazione'])) {
$query = 'SELECT an_regioni.id AS id, an_regioni.iso2, CONCAT(CONCAT_WS(\' - \', an_regioni.iso2, an_regioni.nome), \' (\', an_nazioni.iso2, \')\') AS descrizione FROM an_regioni INNER JOIN an_nazioni ON an_regioni.id_nazione = an_nazioni.id |where| ORDER BY an_regioni.nome';
foreach ($elements as $element) {
$filter[] = 'an_regioni.id='.prepare($element);
}
$where[] = 'an_regioni.id_nazione='.prepare($superselect['id_nazione']);
if (!empty($search)) {
$search_fields[] = 'an_regioni.nome LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'an_regioni.iso2 LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'CONCAT_WS(\' - \', an_regioni.iso2, an_regioni.nome) LIKE '.prepare('%'.$search.'%');
}
}
break;
case 'relazioni':
$query = 'SELECT id, descrizione, colore AS bgcolor FROM an_relazioni |where| ORDER BY descrizione';

View File

@ -51,7 +51,7 @@ include_once __DIR__.'/../../core.php';
</div>
<div class="col-md-6">
{[ "type": "select", "label": "<?php echo tr('Regione'); ?>", "name": "id_regione", "value": "$id_regione$", "ajax-source": "regioni" ]}
{[ "type": "select", "label": "<?php echo tr('Regione'); ?>", "name": "id_regione", "value": "$id_regione$", "ajax-source": "regioni", "select-options": <?php echo json_encode(['id_nazione' => $record['id_nazione']]); ?> ]}
</div>
</div>
@ -72,3 +72,21 @@ include_once __DIR__.'/../../core.php';
<a class="btn btn-danger ask" data-backto="record-list">
<i class="fa fa-trash"></i> <?php echo tr('Elimina'); ?>
</a>
<script>
var nazione = input("id_nazione");
var regione = input("id_regione");
// Gestione della modifica della nazione
nazione.change(function() {
updateSelectOption("id_nazione", $(this).val());
session_set("superselect,id_nazione", $(this).val(), 0);
let value = !$(this).val();
let placeholder = value ? "<?php echo tr('Seleziona prima una nazione'); ?>" : "<?php echo tr("Seleziona un'opzione"); ?>";
regione.getElement()
.selectReset(placeholder);
});
</script>

View File

@ -103,4 +103,40 @@ UPDATE `zz_modules` SET `options` = 'SELECT |select|\nFROM `co_preventivi`\n
INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `format`, `html_format`, `search_inside`, `order_by`, `visible`, `summable`, `default`) VALUES
((SELECT `id` FROM `zz_modules` WHERE `name`='Interventi'), 'Contratto', 'contratto.info', 21, 1, 0, 0, 0, '', '', 0, 0, 1),
((SELECT `id` FROM `zz_modules` WHERE `name`='Interventi'), 'Preventivo', 'preventivo.info', 22, 1, 0, 0, 0, '', '', 0, 0, 1),
((SELECT `id` FROM `zz_modules` WHERE `name`='Interventi'), 'Ordine', 'ordine.info', 23, 1, 0, 0, 0, '', '', 0, 0, 1);
((SELECT `id` FROM `zz_modules` WHERE `name`='Interventi'), 'Ordine', 'ordine.info', 23, 1, 0, 0, 0, '', '', 0, 0, 1);
CREATE TABLE `an_regioni` (
`id` int NOT NULL,
`id_nazione` int NOT NULL,
`nome` varchar(255) NOT NULL,
`iso2` varchar(2) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_nazione`) REFERENCES `an_nazioni`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
INSERT INTO `an_regioni` (`id`, `nome`, `id_nazione`) VALUES
(1, 'Abruzzo', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(2, 'Basilicata', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(3, 'Calabria', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(4, 'Campania', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(5, 'Emilia-Romagna', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(6, 'Friuli-Venezia Giulia', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(7, 'Lazio', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(8, 'Liguria', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(9, 'Lombardia', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(10, 'Marche', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(11, 'Molise', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(12, 'Piemonte', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(13, 'Puglia', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(14, 'Sardegna', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(15, 'Sicilia', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(16, 'Toscana', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(17, 'Trentino-Alto Adige', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(18, 'Umbria', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(19, 'Valle d''Aosta', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT')),
(20, 'Veneto', (SELECT `id` FROM `an_nazioni` WHERE `iso2` = 'IT'));