From 6490ca640dd6ca02a1934fe02291e677242420b6 Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 28 Feb 2024 01:46:48 +0100 Subject: [PATCH] =?UTF-8?q?Pulsante=20Precedente=20e=20Successivo=20all'in?= =?UTF-8?q?terno=20della=20scheda=20attivit=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common.php | 23 +++++++++++++++++++++++ modules/interventi/edit.php | 3 --- modules/interventi/init.php | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/common.php b/lib/common.php index 07b4fb43d..99e1688cd 100755 --- a/lib/common.php +++ b/lib/common.php @@ -344,3 +344,26 @@ function checkPrefix($cellulare) { return false; // Nessun prefisso trovato } + + +/** + * Funzione PHP che dato id_modulo restituisce un array contenente tutti i valori di "search_" per quel modulo + * + * @param int $id_module + * + * @return array + */ +function getSearchValues($id_module) { + $result = []; + + if(isset($_SESSION['module_'.$id_module])) { + // Itera su tutti i valori + foreach($_SESSION['module_'.$id_module] as $key => $value) { + // Controlla se la chiave inizia con "search_" + if (!empty($value) && string_starts_with($key, 'search_')) { + $result[str_replace(["search_", "-"], ["", " "], $key)] = $value; + } + } + } + return $result; +} \ No newline at end of file diff --git a/modules/interventi/edit.php b/modules/interventi/edit.php index 8e4a0c5f7..418939cfa 100755 --- a/modules/interventi/edit.php +++ b/modules/interventi/edit.php @@ -25,9 +25,6 @@ include_once __DIR__.'/../../core.php'; $block_edit = $record['flag_completato']; $module_anagrafiche = Modules::get('Anagrafiche'); -$codice = $database->FetchOne('SELECT codice FROM in_interventi WHERE id = '.$intervento->id.'')['codice']; -$prev = $database->FetchOne('SELECT id FROM in_interventi WHERE codice = '.($codice-1).' AND data_richiesta > "'.$_SESSION['period_start'].'" AND data_richiesta < "'.$_SESSION['period_end'].'"')['id']; -$next = $database->FetchOne('SELECT id FROM in_interventi WHERE codice = '.($codice+1).' AND data_richiesta > "'.$_SESSION['period_start'].'" AND data_richiesta < "'.$_SESSION['period_end'].'"')['id']; // Verifica aggiuntive sulla sequenzialità dei numeri $numero_previsto = verifica_numero_intervento($intervento); diff --git a/modules/interventi/init.php b/modules/interventi/init.php index 651ed38fd..1dc77ede6 100755 --- a/modules/interventi/init.php +++ b/modules/interventi/init.php @@ -42,4 +42,29 @@ if (isset($id_record)) { INNER JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento` = `in_statiintervento`.`idstatointervento` WHERE `in_interventi`.`id`='.prepare($id_record)); + + + + //Pulsante Precedente e Successivo all'interno della scheda attività + $module_query = Util\Query::getQuery(Models\Module::getCurrent()); + + if (!empty(getSearchValues($id_module))) { + $having = []; + $search_values = getSearchValues($id_module); + foreach($search_values as $key => $value) { + $having[] = '`'.$key.'` LIKE "%'.$value.'%"'; + } + foreach($having as $condition) { + $module_query = str_replace('2=2', '2=2 AND '.$condition, $module_query); + } + } + + + $prev_query = str_replace('1=1', '1=1 AND `in_interventi`.`codice` = '.($record['codice']-1), $module_query); + $prev = $database->FetchOne($prev_query)['id']; + + $next_query = str_replace('1=1', '1=1 AND `in_interventi`.`codice` = '.($record['codice']+1), $module_query); + $next = $database->FetchOne($next_query)['id']; + + }