. */ include_once __DIR__.'/../../core.php'; switch (post('op')) { case 'update': $pattern = string_contains(post('pattern'), '#') ? post('pattern') : '####'; $predefined = post('predefined'); $module = post('module'); if (empty(Modules::getSegments($module))) { $predefined = 1; } if ($predefined) { $dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($module)); } $predefined_accredito = post('predefined_accredito'); if ($predefined_accredito) { $dbo->query('UPDATE zz_segments SET predefined_accredito = 0 WHERE id_module = '.prepare($module)); } $predefined_addebito = post('predefined_addebito'); if ($predefined_addebito) { $dbo->query('UPDATE zz_segments SET predefined_addebito = 0 WHERE id_module = '.prepare($module)); } $dbo->update('zz_segments', [ 'id_module' => $module, 'name' => post('name'), 'clause' => $_POST['clause'], 'pattern' => $pattern, 'note' => post('note'), 'dicitura_fissa' => post('dicitura_fissa'), 'position' => post('position'), 'predefined' => $predefined, 'is_fiscale' => post('is_fiscale'), 'predefined_accredito' => $predefined_accredito, 'predefined_addebito' => $predefined_addebito, 'autofatture' => post('autofatture'), ], ['id' => $id_record]); // Aggiornamento dei permessi relativi $dbo->sync('zz_group_segment', ['id_segment' => $id_record], ['id_gruppo' => (array) post('gruppi')]); flash()->info(tr('Modifiche salvate correttamente')); break; case 'add': $pattern = string_contains(post('pattern'), '#') ? post('pattern') : '####'; $predefined = post('predefined'); $module = post('module'); if (empty(Modules::getSegments($module))) { $predefined = 1; } if ($predefined) { $dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($module)); } $dbo->insert('zz_segments', [ 'id_module' => $module, 'name' => post('name'), 'clause' => '1=1', 'pattern' => $pattern, 'note' => post('note'), 'predefined' => $predefined, 'is_sezionale' => post('is_sezionale'), ]); $id_record = $dbo->lastInsertedID(); // Aggiunta permessi segmento $gruppi = $dbo->fetchArray('SELECT `id` FROM `zz_groups`'); $array = []; foreach ($gruppi as $gruppo) { $array[] = [ 'id_gruppo' => $gruppo['id'], 'id_segment' => $id_record, ]; } $dbo->insert('zz_group_segment', $array); flash()->info(tr('Nuovo segmento aggiunto')); break; case 'delete': $dbo->query('DELETE FROM zz_segments WHERE id='.prepare($id_record)); // TODO // eliminare riferimento sulle fatture eventuali collegate a questo segmento? flash()->info(tr('Segmento eliminato')); break; }