From 90abc3ff1490d9c211695c73c758d84770db65f4 Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Fri, 15 Sep 2023 14:25:05 +0200 Subject: [PATCH] Integrazione link file e stampa in input select --- mail.php | 6 ++-- modules/stampe/edit.php | 2 +- src/HTMLBuilder/Handler/SelectHandler.php | 37 +++++++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/mail.php b/mail.php index 069cf8b50..9b9afb0a7 100755 --- a/mail.php +++ b/mail.php @@ -150,7 +150,7 @@ echo '
- {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).' AND enabled=1 AND is_record=1" ]} + {[ "type": "select", "multiple": "1", "label": "'.tr('Stampe').'", "name": "prints[]", "value": "'.implode(',', $selected).'", "values": "query=SELECT id, title AS text FROM zz_prints WHERE id_module = '.prepare($id_module).' AND enabled=1 AND is_record=1", "link": "stampa" ]}
'; $uploads = []; @@ -163,9 +163,9 @@ if ($smtp['pec'] == 1 && $module['name'] == 'Fatture di vendita') { echo '
- {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "help": "'.tr('Allegati del documento o caricati nell\'anagrafica dell\'azienda.').'", "values": "query=SELECT id, name AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record)." UNION SELECT id, CONCAT(name, ' (Azienda)') AS text FROM zz_files WHERE id_module = ".prepare(Modules::get('Anagrafiche')['id'])." AND id_record = (SELECT valore FROM zz_settings WHERE nome = 'Azienda predefinita')\"]} + {[ "type": "select", "multiple": "1", "label": "'.tr('Allegati').'", "name": "uploads[]", "value": "'.implode(',', $uploads).'", "help": "'.tr('Allegati del documento o caricati nell\'anagrafica dell\'azienda.').'", "values": "query=SELECT id, name AS text FROM zz_files WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record).' UNION SELECT id, CONCAT(name, \' (Azienda)\') AS text FROM zz_files WHERE id_module = '.prepare(Modules::get('Anagrafiche')['id']).' AND id_record = (SELECT valore FROM zz_settings WHERE nome = \'Azienda predefinita\')", "link": "allegato" ]}
-
"; + '; echo ' diff --git a/modules/stampe/edit.php b/modules/stampe/edit.php index 0bf12981b..e64a3915d 100755 --- a/modules/stampe/edit.php +++ b/modules/stampe/edit.php @@ -54,7 +54,7 @@ $id_files = $dbo->select('zz_files_print', 'id_file', ['id_print' => $id_record]
- {[ "type": "select", "multiple": "1", "label": "", "name": "id_files[]", "value": "", "ajax-source": "allegati", "select-options": $id_module, 'id_record' => $id_record]); ?> ]} + {[ "type": "select", "multiple": "1", "label": "", "name": "id_files[]", "value": "", "ajax-source": "allegati", "select-options": $id_module, 'id_record' => $id_record]); ?>, "link": "allegato" ]}
diff --git a/src/HTMLBuilder/Handler/SelectHandler.php b/src/HTMLBuilder/Handler/SelectHandler.php index 1121d494e..fe93b436c 100755 --- a/src/HTMLBuilder/Handler/SelectHandler.php +++ b/src/HTMLBuilder/Handler/SelectHandler.php @@ -20,6 +20,7 @@ namespace HTMLBuilder\Handler; use AJAX; +use Prints; /** * Gestione dell'input di tipo "select". @@ -71,7 +72,7 @@ class SelectHandler implements HandlerInterface unset($values['select-options']); if (!empty($values['value']) || is_numeric($values['value'])) { - $result .= $this->select2($source, $values['value'], $infos); + $result .= $this->select2($source, $values['value'], $infos, $values['link']); } } else { if (!in_array('multiple', $extras)) { @@ -81,21 +82,21 @@ class SelectHandler implements HandlerInterface // Gestione del select dal formato JSON completo, convertito in array if (is_array($values['values'])) { - $result .= $this->selectArray($values['values'], $values['value']); + $result .= $this->selectArray($values['values'], $values['value'], $values['link']); } // Gestione del select da query specifica (se il campo "values" รจ impostato a "query=SQL") elseif (string_starts_with($values['values'], 'query=')) { $query = substr($values['values'], strlen('query=')); - $result .= $this->selectQuery($query, $values['value']); + $result .= $this->selectQuery($query, $values['value'], $values['link']); } // Gestione del select dal formato JSON parziale (valori singoli) elseif (string_starts_with($values['values'], 'list=')) { $list = substr($values['values'], strlen('list=')); - $result .= $this->selectList(json_decode('{'.$list.'}', true), $values); + $result .= $this->selectList(json_decode('{'.$list.'}', true), $values, $values['link']); } } @@ -136,7 +137,7 @@ class SelectHandler implements HandlerInterface * * @return string */ - protected function select2($op, $elements, $info) + protected function select2($op, $elements, $info, $link = null) { // Richiamo del file dedicato alle richieste AJAX per ottenere il valore iniziale del select $response = AJAX::select($op, $elements, null, 0, 100, $info); @@ -154,6 +155,14 @@ class SelectHandler implements HandlerInterface $attributes[] = 'selected'; } + if ($link == 'stampa') { + $element['title'] = ' '; + $element['text'] = ''.$element['text'].' '; + } elseif ($link == 'allegato') { + $element['title'] = ' '; + $element['text'] = ''.$element['text'].' '; + } + if (!empty($element['_bgcolor_'])) { $attributes[] = 'style="background:'.$element['_bgcolor_'].'; color:'.color_inverse($element['_bgcolor_'].';"'); } @@ -178,7 +187,7 @@ class SelectHandler implements HandlerInterface * * @return string */ - protected function selectArray($array, $values) + protected function selectArray($array, $values, $link = null) { $result = ''; @@ -194,6 +203,14 @@ class SelectHandler implements HandlerInterface $element['text'] = empty($element['text']) ? $element['descrizione'] : $element['text']; + if ($link == 'stampa') { + $element['title'] = ' '; + $element['text'] = ''.$element['text'].' '; + } elseif ($link == 'allegato') { + $element['title'] = ' '; + $element['text'] = ''.$element['text'].' '; + } + $attributes = []; if (in_array($element['id'], $values)) { $attributes[] = 'selected'; @@ -225,13 +242,13 @@ class SelectHandler implements HandlerInterface * * @return string */ - protected function selectQuery($query, $values) + protected function selectQuery($query, $values, $link = null) { $database = database(); $array = $database->fetchArray($query); - return $this->selectArray($array, $values); + return $this->selectArray($array, $values, $link); } /** @@ -243,7 +260,7 @@ class SelectHandler implements HandlerInterface * * @return string */ - protected function selectList($datas, &$values) + protected function selectList($datas, &$values, $link = null) { $array = []; @@ -255,6 +272,6 @@ class SelectHandler implements HandlerInterface } } - return $this->selectArray($array, $values['value']); + return $this->selectArray($array, $values['value'], $link); } }