From 088f52037442f6c096301ccf9c7031711490d4b0 Mon Sep 17 00:00:00 2001 From: Pek5892 Date: Wed, 28 Feb 2024 11:39:12 +0100 Subject: [PATCH] Aggiunta tabella in_fasceorarie_lang --- modules/fasce_orarie/actions.php | 22 ++++++----- modules/fasce_orarie/ajax/select.php | 8 ++-- modules/fasce_orarie/edit.php | 4 +- modules/fasce_orarie/init.php | 2 +- .../tipi_intervento/ajax_addebiti_costi.php | 2 +- update/2_4_55.sql | 37 ++++++++++++++++++- update/tables.php | 1 + 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/modules/fasce_orarie/actions.php b/modules/fasce_orarie/actions.php index db990145f..15eefa780 100644 --- a/modules/fasce_orarie/actions.php +++ b/modules/fasce_orarie/actions.php @@ -28,21 +28,22 @@ switch (post('op')) { $include_bank_holidays = post('include_bank_holidays'); $is_predefined = post('is_predefined'); - if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` WHERE `nome`='.prepare($nome).' AND `id`!='.prepare($id_record)) == 0) { + if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `name`='.prepare($nome).' AND `in_fasceorarie`.`id`!='.prepare($id_record)) == 0) { if (!empty($is_predefined)) { - $dbo->query('UPDATE in_fasceorarie SET is_predefined = 0'); + $dbo->query('UPDATE `in_fasceorarie` SET `is_predefined` = 0'); } $dbo->update('in_fasceorarie', [ - 'nome' => $nome, 'giorni' => $giorni ? implode(',', $giorni) : null, 'ora_inizio' => $ora_inizio, 'ora_fine' => $ora_fine, 'include_bank_holidays' => $include_bank_holidays, 'is_predefined' => $is_predefined, - ], [ - 'id' => $id_record, - ]); + ], ['id' => $id_record]); + + $dbo->update('in_fasceorarie_lang', [ + 'name' => $nome + ], ['id_record' => $id_record, 'id_lang' => setting('Lingua')]); flash()->info(tr('Salvataggio completato.')); } else { @@ -58,14 +59,17 @@ switch (post('op')) { $ora_inizio = post('ora_inizio'); $ora_fine = post('ora_fine'); - if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` WHERE `nome`='.prepare($nome)) == 0) { + if ($dbo->fetchNum('SELECT * FROM `in_fasceorarie` LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `name`='.prepare($nome)) == 0) { $dbo->insert('in_fasceorarie', [ - 'nome' => $nome, 'ora_inizio' => $ora_inizio, 'ora_fine' => $ora_fine, ]); - $id_record = $dbo->lastInsertedID(); + $dbo->insert('in_fasceorarie_lang', [ + 'name' => $nome, + 'id_record' => $id_record, + 'id_lang' => setting('Lingua'), + ]); $tipi_intervento = $dbo->select('in_tipiintervento', '*'); foreach ($tipi_intervento as $tipo_intervento) { diff --git a/modules/fasce_orarie/ajax/select.php b/modules/fasce_orarie/ajax/select.php index 645221792..751222e9d 100644 --- a/modules/fasce_orarie/ajax/select.php +++ b/modules/fasce_orarie/ajax/select.php @@ -21,17 +21,17 @@ include_once __DIR__.'/../../../core.php'; switch ($resource) { case 'fasce_orarie': - $query = 'SELECT id, nome AS descrizione FROM in_fasceorarie |where| ORDER BY nome ASC'; + $query = 'SELECT `in_fasceorarie`.`id`, `name` AS `descrizione` FROM `in_fasceorarie` LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.`id_lang` = '.prepare(setting('Lingua')).') |where| ORDER BY `name` ASC'; foreach ($elements as $element) { - $filter[] = 'id='.prepare($element); + $filter[] = '`in_fasceorarie`.`id`='.prepare($element); } if (empty($filter)) { - $where[] = 'in_fasceorarie.deleted_at IS NULL'; + $where[] = '`in_fasceorarie`.`deleted_at` IS NULL'; } if (!empty($search)) { - $search_fields[] = 'nome LIKE '.prepare('%'.$search.'%'); + $search_fields[] = '`name` LIKE '.prepare('%'.$search.'%'); } break; diff --git a/modules/fasce_orarie/edit.php b/modules/fasce_orarie/edit.php index 0c1c7ff6e..c37bd829b 100644 --- a/modules/fasce_orarie/edit.php +++ b/modules/fasce_orarie/edit.php @@ -38,7 +38,7 @@ use Modules\Pagamenti\Pagamento;
- {[ "type": "text", "label": "", "name": "nome", "required": 1, "value": "$nome$" ]} + {[ "type": "text", "label": "", "name": "nome", "required": 1, "value": "$name$" ]}
@@ -140,7 +140,7 @@ function aggiungiData() { fetchArray('SELECT in_tipiintervento.codice, in_tipiintervento.descrizione, in_tipiintervento.idtipointervento FROM in_tipiintervento LEFT JOIN in_fasceorarie_tipiintervento ON in_tipiintervento.idtipointervento=in_fasceorarie_tipiintervento.idtipointervento WHERE in_fasceorarie_tipiintervento.idfasciaoraria='.prepare($id_record)); +$elementi = $dbo->fetchArray('SELECT `in_tipiintervento`.`codice`, `in_tipiintervento`.`descrizione`, `in_tipiintervento`.`idtipointervento` FROM `in_tipiintervento` LEFT JOIN `in_fasceorarie_tipiintervento` ON `in_tipiintervento`.`idtipointervento`=`in_fasceorarie_tipiintervento`.`idtipointervento` WHERE `in_fasceorarie_tipiintervento`.`idfasciaoraria`='.prepare($id_record)); if (!empty($elementi)) { echo ' diff --git a/modules/fasce_orarie/init.php b/modules/fasce_orarie/init.php index 05d90bc3b..d04d4bdac 100644 --- a/modules/fasce_orarie/init.php +++ b/modules/fasce_orarie/init.php @@ -20,5 +20,5 @@ include_once __DIR__.'/../../core.php'; if (isset($id_record)) { - $record = $dbo->fetchOne('SELECT * FROM `in_fasceorarie` WHERE id='.prepare($id_record)); + $record = $dbo->fetchOne('SELECT * FROM `in_fasceorarie` LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `in_fasceorarie`.`id`='.prepare($id_record)); } diff --git a/modules/tipi_intervento/ajax_addebiti_costi.php b/modules/tipi_intervento/ajax_addebiti_costi.php index fd574973c..827b5062b 100644 --- a/modules/tipi_intervento/ajax_addebiti_costi.php +++ b/modules/tipi_intervento/ajax_addebiti_costi.php @@ -7,7 +7,7 @@ if (file_exists(__DIR__.'/../../../core.php')) { } // Fasce orarie per il tipo di attività -$fasce_orarie = $dbo->fetchArray("SELECT *, CONCAT (in_fasceorarie.nome, ' (', DATE_FORMAT(ora_inizio, '%H:%i'), '-', DATE_FORMAT(ora_fine, '%H:%i'), ')') AS descrizione FROM in_fasceorarie_tipiintervento INNER JOIN in_fasceorarie ON in_fasceorarie_tipiintervento.idfasciaoraria = in_fasceorarie.id WHERE idtipointervento=".prepare($id_record)); +$fasce_orarie = $dbo->fetchArray("SELECT *, CONCAT (`in_fasceorarie_lang`.`name`, ' (', DATE_FORMAT(`ora_inizio`, '%H:%i'), '-', DATE_FORMAT(`ora_fine`, '%H:%i'), ')') AS descrizione FROM `in_fasceorarie_tipiintervento` INNER JOIN `in_fasceorarie` ON `in_fasceorarie_tipiintervento`.`idfasciaoraria` = `in_fasceorarie`.`id` LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.`id_lang` = ".prepare(setting('Lingua')).") WHERE `idtipointervento`=".prepare($id_record)); echo ' diff --git a/update/2_4_55.sql b/update/2_4_55.sql index 612e58cfe..bd943dab5 100644 --- a/update/2_4_55.sql +++ b/update/2_4_55.sql @@ -1255,4 +1255,39 @@ INSERT INTO `fe_tipi_documento_lang` (`id`, `id_lang`, `id_record`, `name`) SELE ALTER TABLE `fe_tipi_documento` DROP `descrizione`; -ALTER TABLE `fe_tipi_documento_lang` ADD CONSTRAINT `fe_tipi_documento_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `fe_tipi_documento`(`codice`) ON DELETE CASCADE ON UPDATE RESTRICT; \ No newline at end of file +ALTER TABLE `fe_tipi_documento_lang` ADD CONSTRAINT `fe_tipi_documento_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `fe_tipi_documento`(`codice`) ON DELETE CASCADE ON UPDATE RESTRICT; + +-- Aggiunta tabella in_fasceorarie_lang +CREATE TABLE IF NOT EXISTS `in_fasceorarie_lang` ( + `id` int NOT NULL, + `id_lang` int NOT NULL, + `id_record` int NOT NULL, + `name` VARCHAR(255) NOT NULL +); +ALTER TABLE `in_fasceorarie_lang` + ADD PRIMARY KEY (`id`); + +ALTER TABLE `in_fasceorarie_lang` + MODIFY `id` int NOT NULL AUTO_INCREMENT; + +INSERT INTO `in_fasceorarie_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `nome` FROM `in_fasceorarie`; + +ALTER TABLE `in_fasceorarie` + DROP `nome`; + +ALTER TABLE `in_fasceorarie` CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT; + +ALTER TABLE `in_fasceorarie_lang` ADD CONSTRAINT `in_fasceorarie_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `in_fasceorarie`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +-- Allineamento vista Fasce orarie +UPDATE `zz_modules` SET `options` = " +SELECT + |select| +FROM + `in_fasceorarie` + LEFT JOIN `in_fasceorarie_lang` ON (`in_fasceorarie_lang`.`id_record` = `in_fasceorarie`.`id` AND `in_fasceorarie_lang`.|lang|) +WHERE + 1=1 AND deleted_at IS NULL +HAVING + 2=2" WHERE `name` = 'Fasce orarie'; +UPDATE `zz_views` INNER JOIN `zz_modules` ON `zz_views`.`id_module` = `zz_modules`.`id` SET `zz_views`.`query` = '`in_fasceorarie_lang`.`name`' WHERE `zz_modules`.`name` = 'Fasce orarie' AND `zz_views`.`name` = 'nOME'; diff --git a/update/tables.php b/update/tables.php index fc18390ba..b00d8e320 100755 --- a/update/tables.php +++ b/update/tables.php @@ -113,6 +113,7 @@ return [ 'in_tipiintervento', 'in_vociservizio', 'in_fasceorarie', + 'in_fasceorarie_lang', 'in_fasceorarie_tipiintervento', 'mg_articoli', 'mg_fornitore_articolo',