Fix Campi personalizzati creati dopo i record
This commit is contained in:
parent
2683d16900
commit
1b43a74dcd
21
actions.php
21
actions.php
|
@ -156,12 +156,9 @@ if ($structure->permission == 'rw') {
|
||||||
|
|
||||||
// Operazioni generiche per i campi personalizzati
|
// Operazioni generiche per i campi personalizzati
|
||||||
if (post('op') != null) {
|
if (post('op') != null) {
|
||||||
$query = 'SELECT `id`, `name` FROM `zz_fields` WHERE ';
|
$custom_where = !empty($id_plugin) ? '`id_plugin` = '.prepare($id_plugin) : '`id_module` = '.prepare($id_module);
|
||||||
if (!empty($id_plugin)) {
|
|
||||||
$query .= '`id_plugin` = '.prepare($id_plugin);
|
$query = 'SELECT `id`, `html_name` AS `name` FROM `zz_fields` WHERE '.$custom_where;
|
||||||
} else {
|
|
||||||
$query .= '`id_module` = '.prepare($id_module);
|
|
||||||
}
|
|
||||||
$customs = $dbo->fetchArray($query);
|
$customs = $dbo->fetchArray($query);
|
||||||
|
|
||||||
if (!starts_with(post('op'), 'delete')) {
|
if (!starts_with(post('op'), 'delete')) {
|
||||||
|
@ -188,13 +185,25 @@ if ($structure->permission == 'rw') {
|
||||||
|
|
||||||
// Aggiornamento
|
// Aggiornamento
|
||||||
elseif (starts_with(post('op'), 'update')) {
|
elseif (starts_with(post('op'), 'update')) {
|
||||||
|
$query = 'SELECT `zz_field_record`.`id_field` FROM `zz_field_record` JOIN `zz_fields` ON `zz_fields`.`id` = `zz_field_record`.`id_field` WHERE id_record = '.prepare($id_record).' AND '.$custom_where;
|
||||||
|
$customs_present = $dbo->fetchArray($query);
|
||||||
|
$customs_present = array_column($customs_present, 'id_field');
|
||||||
|
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
|
if (in_array($key, $customs_present)) {
|
||||||
$dbo->update('zz_field_record', [
|
$dbo->update('zz_field_record', [
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
], [
|
], [
|
||||||
'id_record' => $id_record,
|
'id_record' => $id_record,
|
||||||
'id_field' => $key,
|
'id_field' => $key,
|
||||||
]);
|
]);
|
||||||
|
} else {
|
||||||
|
$dbo->insert('zz_field_record', [
|
||||||
|
'id_record' => $id_record,
|
||||||
|
'id_field' => $key,
|
||||||
|
'value' => $value,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue