diff --git a/actions.php b/actions.php
index 5d9fc2ac8..14c4ad86a 100644
--- a/actions.php
+++ b/actions.php
@@ -242,7 +242,7 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
include $docroot.$directory.'/init.php';
}
- if(Modules::getPermission($permesso) == 'rw'){
+ if (Modules::getPermission($permesso) == 'rw') {
// Esecuzione delle operazioni di gruppo
$id_records = post('id_records');
$id_records = is_array($id_records) ? $id_records : explode(';', $id_records);
@@ -266,6 +266,46 @@ if (Modules::getPermission($permesso) == 'r' || Modules::getPermission($permesso
} elseif (file_exists($docroot.$directory.'/actions.php')) {
include $docroot.$directory.'/actions.php';
}
+
+ // Operazioni generiche per i campi personalizzati
+ if (post('op') != null && post('op') != 'delete') {
+ $customs = $dbo->fetchArray('SELECT `id`, `name` FROM `zz_fields` WHERE `id_module` = '.prepare($id_module));
+
+ $values = [];
+ foreach ($customs as $custom) {
+ if (isset($post[$custom['name']])) {
+ $values[$custom['id']] = $post[$custom['name']];
+ }
+ }
+
+ // Inserimento iniziale
+ if (post('op') == 'add') {
+ foreach ($values as $key => $value) {
+ $dbo->insert('zz_field_record', [
+ 'id_record' => $id_record,
+ 'id_field' => $key,
+ 'value' => $value,
+ ]);
+ }
+ }
+
+ // Aggiornamento
+ elseif (post('op') == 'update') {
+ foreach ($values as $key => $value) {
+ $dbo->update('zz_field_record', [
+ 'value' => $value,
+ ], [
+ 'id_record' => $id_record,
+ 'id_field' => $key,
+ ]);
+ }
+ }
+ }
+
+ // Eliminazione
+ elseif (post('op') == 'delete') {
+ $dbo->query('DELETE FROM `zz_field_record` WHERE `id_record` = '.prepare($id_record).' AND `id_field` IN (SELECT `id` FROM `zz_fields` WHERE `id_module` = '.prepare($id_module).')');
+ }
}
}
}
diff --git a/add.php b/add.php
index 7d64fb99a..834d6f984 100644
--- a/add.php
+++ b/add.php
@@ -34,6 +34,25 @@ if (file_exists($docroot.$directory.'/custom/add.php')) {
echo '
';
+// Campi personalizzati
+echo '
+
+
+ {( "name": "custom_fields", "id_module": "'.$id_module.'", "position": "top" )}
+
+
+
+ {( "name": "custom_fields", "id_module": "'.$id_module.'", "position": "bottom" )}
+
+
+';
+
if (isAjaxRequest()) {
echo '
';
+
foreach ($plugins as $plugin) {
echo '
';
diff --git a/src/HTMLBuilder/HTMLBuilder.php b/src/HTMLBuilder/HTMLBuilder.php
index dde31c3df..a0323b1a5 100644
--- a/src/HTMLBuilder/HTMLBuilder.php
+++ b/src/HTMLBuilder/HTMLBuilder.php
@@ -76,6 +76,7 @@ class HTMLBuilder
'filelist_and_upload' => 'HTMLBuilder\Manager\FileManager',
'button' => 'HTMLBuilder\Manager\ButtonManager',
'csrf' => 'HTMLBuilder\Manager\CSRFManager',
+ 'custom_fields' => 'HTMLBuilder\Manager\FieldManager',
],
'instances' => [],
];
diff --git a/src/HTMLBuilder/Manager/FieldManager.php b/src/HTMLBuilder/Manager/FieldManager.php
new file mode 100644
index 000000000..0dd7ae5ba
--- /dev/null
+++ b/src/HTMLBuilder/Manager/FieldManager.php
@@ -0,0 +1,72 @@
+getInfo($options);
+
+ return $this->generate($info);
+ }
+
+ public function getInfo($options)
+ {
+ $database = \Database::getConnection();
+
+ $query = 'SELECT `zz_fields`.*'.(isset($options['id_record']) ? ', `zz_field_record`.`value`' : '').' FROM `zz_fields`';
+
+ if (isset($options['id_record'])) {
+ $query .= ' LEFT JOIN `zz_field_record` ON `zz_fields`.`id` = `zz_field_record`.`id_field`';
+ }
+
+ $query .= ' WHERE `id_module` = '.prepare($options['id_module']);
+
+ if (isset($options['id_record'])) {
+ $query .= ' AND `id_record` = '.prepare($options['id_record']);
+ }
+
+ $query .= ' AND `top` = '.((isset($options['position']) && $options['position'] == 'top') ? 1 : 0).' ORDER BY `order`';
+
+ $results = $database->fetchArray($query);
+
+ return $results;
+ }
+
+ public function generate($fields)
+ {
+ // Spazio per evitare problemi con la sostituzione del tag
+ $result = ' ';
+
+ // Costruzione dei campi
+ foreach ($fields as $key => $field) {
+ if ($key % 3 == 0) {
+ $result .= '
+
';
+ }
+
+ $field['value'] = isset($field['value']) ? $field['value'] : '';
+
+ $result .= '
+
+ '.str_replace('|value|', $field['value'], $field['content']).'
+
';
+
+ if (($key + 1) % 3 == 0) {
+ $result .= '
+
';
+ }
+ }
+
+ if (!empty($fields) && ($key + 1) % 3 != 0) {
+ $result .= '
+
';
+ }
+
+ return $result;
+ }
+}
diff --git a/update/2_4.sql b/update/2_4.sql
index 0eadfa61f..1634a67e7 100644
--- a/update/2_4.sql
+++ b/update/2_4.sql
@@ -215,4 +215,33 @@ UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM((SELECT SUM(subtotale+iva-sconto) FROM co_righe_documenti WHERE iddocumento=co_documenti.id)+iva_rivalsainps+rivalsainps+bollo-ritenutaacconto), 2), ",", "#"), ".", ","), "#", "."), "€") AS dato FROM co_documenti WHERE idtipodocumento IN(SELECT id FROM co_tipidocumento WHERE dir="entrata") AND idstatodocumento = (SELECT id FROM co_statidocumento WHERE descrizione="Emessa") |idsezionale| AND data >= "|period_start|" AND data <= "|period_end|" AND 1=1' WHERE `zz_widgets`.`name` = 'Crediti da clienti' ;
-- Help text per widget Fatturato
-UPDATE `zz_widgets` SET `help` = 'Fatturato IVA inclusa.' WHERE `zz_widgets`.`name` = 'Fatturato';
\ No newline at end of file
+UPDATE `zz_widgets` SET `help` = 'Fatturato IVA inclusa.' WHERE `zz_widgets`.`name` = 'Fatturato';
+
+--
+-- Struttura della tabella `zz_fields`
+--
+
+CREATE TABLE IF NOT EXISTS `zz_fields` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `id_module` int(11) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `content` text NOT NULL,
+ `options` text,
+ `order` int(11) NOT NULL,
+ `top` boolean NOT NULL,
+ PRIMARY KEY (`id`),
+ FOREIGN KEY (`id_module`) REFERENCES `zz_modules`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB;
+
+--
+-- Struttura della tabella `zz_fields`
+--
+
+CREATE TABLE IF NOT EXISTS `zz_field_record` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `id_field` int(11) NOT NULL,
+ `id_record` int(11) NOT NULL,
+ `value` text NOT NULL,
+ PRIMARY KEY (`id`),
+ FOREIGN KEY (`id_field`) REFERENCES `zz_fields`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB;