|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione |
| 4 | + * Copyright (C) DevCode s.r.l. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (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 General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +include_once __DIR__.'/../../core.php'; |
| 21 | +use Modules\Ubicazioni; |
| 22 | +//use Modules\Articoli\Categoria; |
| 23 | + |
| 24 | +switch (filter('op')) { |
| 25 | + case 'update': |
| 26 | + $u_label = filter('u_label'); |
| 27 | + //$u_label_info = filter('u_label_info'); |
| 28 | + $title = filter('title'); |
| 29 | + $colore = filter('colore'); |
| 30 | + $notes = filter('notes'); |
| 31 | + $u_tags = filter('u_tags'); |
| 32 | + //$u_id = filter('id'); |
| 33 | + |
| 34 | + if (isset($u_label)) { |
| 35 | + if ($dbo->fetchNum('SELECT * FROM `mg_ubicazioni` WHERE `mg_ubicazioni`.`u_label`='.prepare($u_label).' AND `mg_ubicazioni`.`id`!='.prepare($id_record)) == 0) { |
| 36 | + $dbo->query('UPDATE `mg_ubicazioni` LEFT JOIN `mg_ubicazioni_lang` ON (`mg_ubicazioni`.`id` = `mg_ubicazioni_lang`.`id_record` AND `mg_ubicazioni_lang`.`id_lang` = '.prepare(parameter: Models\Locale::getDefault()->id).') |
| 37 | + SET `mg_ubicazioni`.`u_label`='.prepare($u_label).', |
| 38 | + `mg_ubicazioni`.`u_tags`='.prepare($u_tags).', |
| 39 | + `mg_ubicazioni`.`colore`='.prepare($colore).', |
| 40 | + `mg_ubicazioni_lang`.`title`='.prepare($title).', |
| 41 | + `mg_ubicazioni_lang`.`notes`='.prepare($notes).' |
| 42 | + WHERE `mg_ubicazioni`.`id`='.prepare($id_record)); |
| 43 | + //$ubicazione->colore = $colore; |
| 44 | + //$categoria->parent = $id_original ?: null; |
| 45 | + //$ubicazione->setTranslation('title', $title); |
| 46 | + //$ubicazione->setTranslation('notes', $notes); |
| 47 | + //$ubicazione->save(); |
| 48 | + flash()->info(tr('Salvataggio completato.')); |
| 49 | + } else { |
| 50 | + flash()->error(tr("E' già presente una tipologia di _TYPE_ con lo stesso valore.", [ |
| 51 | + '_TYPE_' => 'ubicazione', |
| 52 | + ])); |
| 53 | + } |
| 54 | + } else { |
| 55 | + flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio')); |
| 56 | + } |
| 57 | + |
| 58 | + break; |
| 59 | + |
| 60 | + //aggiornato con l'aggiunta di mg_ubicazioni_lang |
| 61 | + case 'add': |
| 62 | + $u_label = filter('u_label'); |
| 63 | + //$u_label_info = filter('u_label_info'); |
| 64 | + $title = filter('title'); |
| 65 | + $colore = filter('colore'); |
| 66 | + $notes = filter('notes'); |
| 67 | + $u_tags = filter('u_tags'); |
| 68 | + //$u_id = filter('id'); |
| 69 | + |
| 70 | + if (isset($u_label)) { |
| 71 | + if ($dbo->fetchNum('SELECT * FROM `mg_ubicazioni` WHERE `u_label`='.prepare($u_label)) == 0) { |
| 72 | + $dbo->query('INSERT INTO `mg_ubicazioni` (`u_label`,`u_tags`,`colore`) VALUES ('.prepare($u_label).','.prepare($u_tags).','.prepare($colore).')'); |
| 73 | + $id_record = $dbo->lastInsertedID(); |
| 74 | + $dbo->query('INSERT INTO `mg_ubicazioni_lang` (`id_lang`,`id_record`,`title`,`notes`) VALUES ('.prepare(parameter: Models\Locale::getDefault()->id).','.prepare($id_record).','.prepare($title).','.prepare($notes).')'); |
| 75 | + |
| 76 | + if (isAjaxRequest()) { |
| 77 | + echo json_encode(['id' => $u_label, 'text' => $u_label]); |
| 78 | + } |
| 79 | + |
| 80 | + flash()->info(tr('Aggiunta nuova tipologia di _TYPE_', [ |
| 81 | + '_TYPE_' => 'ubicazione', |
| 82 | + ])); |
| 83 | + } else { |
| 84 | + flash()->error(tr("E' già presente una tipologia di _TYPE_ con lo stesso valore.", [ |
| 85 | + '_TYPE_' => 'ubicazione', |
| 86 | + ])); |
| 87 | + } |
| 88 | + } else { |
| 89 | + flash()->error(tr('Ci sono stati alcuni errori durante il salvataggio')); |
| 90 | + } |
| 91 | + |
| 92 | + break; |
| 93 | + |
| 94 | + case 'delete': |
| 95 | + //$righe = $dbo->fetchNum('SELECT `id` FROM `co_righe_documenti` WHERE `um`='.prepare($record['valore']).' |
| 96 | + // UNION SELECT `id` FROM `dt_righe_ddt` WHERE `um`='.prepare($record['valore']).' |
| 97 | + // UNION SELECT `id` FROM `or_righe_ordini` WHERE `um`='.prepare($record['valore']).' |
| 98 | + // UNION SELECT `id` FROM `co_righe_contratti` WHERE `um`='.prepare($record['valore']).' |
| 99 | + // UNION SELECT `id` FROM `mg_articoli` WHERE `um`='.prepare($record['valore']).' |
| 100 | + // UNION SELECT `id` FROM `co_righe_preventivi` WHERE `um`='.prepare($record['valore'])); |
| 101 | + |
| 102 | + //aggiornato con il delete anche dei record mg_ubicazione_lang |
| 103 | + if (!empty($id_record)) { |
| 104 | + $dbo->query('DELETE FROM `mg_ubicazioni` WHERE `id`='.prepare($id_record)); |
| 105 | + flash()->info(tr('Tipologia di _TYPE_ eliminata con successo!', [ |
| 106 | + '_TYPE_' => 'ubicazione', |
| 107 | + ])); |
| 108 | + $dbo->query('DELETE FROM `mg_ubicazioni_lang` WHERE `id_record`='.prepare($id_record)); |
| 109 | + flash()->info(tr('Tipologia di _TYPE_ eliminata con successo!', [ |
| 110 | + '_TYPE_' => 'ubicazione_lang', |
| 111 | + ])); |
| 112 | + } else { |
| 113 | + flash()->error(tr('Errore cancellazione di questa ubicazione.')); |
| 114 | + } |
| 115 | + |
| 116 | + break; |
| 117 | +} |
0 commit comments