1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-26 07:44:02 +01:00
openstamanager/modules/segmenti/actions.php
2018-05-30 11:04:05 +02:00

71 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('zz_segments', [
'id_module' => post('module'),
'name' => post('name'),
'clause' => post('clause'),
'pattern' => $pattern,
'note' => post('note'),
'position' => post('position'),
'predefined' => $predefined,
], ['id' => $id_record]);
$_SESSION['infos'][] = tr('Modifiche salvate correttamente');
break;
case 'add':
$pattern = str_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($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;
}