1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-24 22:42:33 +01:00
openstamanager/modules/segmenti/actions.php
Thomas Zilio 207108e02b Ottimizzazione API interventi
Fix completo #109.
2018-05-12 10:50:51 +02:00

69 lines
1.9 KiB
PHP

<?php
include_once __DIR__.'/../../core.php';
switch (post('op')) {
case 'update':
$pattern = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$predefined = post('predefined');
if (empty(Modules::getSegments($id_module))) {
$predefined = 1;
}
if ($predefined) {
$dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($id_module));
}
$dbo->update('an_anagrafiche', [
'id_module' => post('module'),
'name' => post('name'),
'clause' => post('clause'),
'pattern' => $pattern,
'note' => post('note'),
'position' => post('pisition'),
'predefined' => $predefined,
], ['id' => $id_record]);
$_SESSION['infos'][] = tr('Modifiche salvate correttamente');
break;
case 'add':
$pattern = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$predefined = post('predefined');
if (empty(Modules::getSegments($id_module))) {
$predefined = 1;
}
if ($predefined) {
$dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($id_module));
}
$dbo->insert('zz_segments', [
'id_module' => post('module'),
'name' => post('name'),
'clause' => '1=1',
'pattern' => $pattern,
'note' => post('note'),
'predefined' => $predefined,
]);
$id_record = $dbo->lastInsertedID();
$_SESSION['infos'][] = 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?
$_SESSION['infos'][] = tr('Segmento eliminato');
break;
}