openstamanager/modules/segmenti/actions.php

71 lines
1.9 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/../../core.php';
switch (post('op')) {
2018-05-11 15:56:08 +02:00
case 'update':
$pattern = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$predefined = post('predefined');
2018-05-11 15:56:08 +02:00
if (empty(Modules::getSegments($id_module))) {
$predefined = 1;
}
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
if ($predefined) {
$dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($id_module));
}
2018-03-22 15:40:20 +01:00
2018-05-30 10:06:08 +02:00
$dbo->update('zz_segments', [
2018-05-11 15:56:08 +02:00
'id_module' => post('module'),
'name' => post('name'),
'clause' => post('clause'),
'pattern' => $pattern,
'note' => post('note'),
2018-05-30 10:06:08 +02:00
'position' => post('position'),
2018-05-11 15:56:08 +02:00
'predefined' => $predefined,
], ['id' => $id_record]);
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
$_SESSION['infos'][] = tr('Modifiche salvate correttamente');
2018-05-11 15:56:08 +02:00
break;
2018-05-11 15:56:08 +02:00
case 'add':
$pattern = str_contains(post('pattern'), '#') ? post('pattern') : '####';
$predefined = post('predefined');
2018-05-30 10:06:08 +02:00
$module = post('module');
2018-05-30 10:06:08 +02:00
if (empty(Modules::getSegments($module))) {
2018-05-11 15:56:08 +02:00
$predefined = 1;
}
2018-05-11 15:56:08 +02:00
if ($predefined) {
$dbo->query('UPDATE zz_segments SET predefined = 0 WHERE id_module = '.prepare($id_module));
}
2018-05-11 15:56:08 +02:00
$dbo->insert('zz_segments', [
'id_module' => post('module'),
'name' => post('name'),
'clause' => '1=1',
'pattern' => $pattern,
'note' => post('note'),
'predefined' => $predefined,
]);
2018-03-22 15:40:20 +01:00
$id_record = $dbo->lastInsertedID();
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
$_SESSION['infos'][] = tr('Nuovo segmento aggiunto');
2018-03-22 15:40:20 +01:00
2018-05-11 15:56:08 +02:00
break;
2018-05-11 15:56:08 +02:00
case 'delete':
$dbo->query('DELETE FROM zz_segments WHERE id='.prepare($id_record));
2018-05-11 15:56:08 +02:00
// TODO
// eliminare riferimento sulle fatture eventuali collegate a questo segmento?
2018-05-11 15:56:08 +02:00
$_SESSION['infos'][] = tr('Segmento eliminato');
2018-05-11 15:56:08 +02:00
break;
}