@@ -147,7 +147,7 @@ public static function selectResults($query, $where, $filter = [], $search = [],
147147 public static function search ($ term )
148148 {
149149 if (strlen ($ term ) < 2 ) {
150- return ;
150+ return [] ;
151151 }
152152
153153 $ files = self ::find ('ajax/search.php ' );
@@ -157,9 +157,15 @@ public static function search($term)
157157
158158 $ results = [];
159159 foreach ($ files as $ file ) {
160- $ module_results = self ::getSearchResults ($ file , $ term );
160+ try {
161+ $ module_results = self ::getSearchResults ($ file , $ term );
161162
162- $ results = array_merge ($ results , $ module_results );
163+ if (is_array ($ module_results )) {
164+ $ results = array_merge ($ results , $ module_results );
165+ }
166+ } catch (Exception $ e ) {
167+ // Continua con gli altri moduli
168+ }
163169 }
164170
165171 return $ results ;
@@ -335,27 +341,43 @@ protected static function transformElementLink($element, $link)
335341 */
336342 protected static function getSearchResults ($ file , $ term )
337343 {
344+ // Verifica che il file esista
345+ if (!file_exists ($ file )) {
346+ return [];
347+ }
348+
338349 // Database
339350 $ dbo = $ database = database ();
340351
341352 // Ricerca anagrafiche per ragione sociale per potere mostrare gli interventi, fatture,
342353 // ordini, ecc della persona ricercata
343354 $ idanagrafiche = ['-1 ' ];
344355 $ ragioni_sociali = ['-1 ' ];
345- $ rs = $ dbo ->fetchArray ('SELECT idanagrafica, ragione_sociale FROM an_anagrafiche WHERE ragione_sociale LIKE "% ' .$ term .'%" ' );
346356
347- for ($ a = 0 ; $ a < sizeof ($ rs ); ++$ a ) {
348- $ idanagrafiche [] = $ rs [$ a ]['idanagrafica ' ];
349- $ ragioni_sociali [$ rs [$ a ]['idanagrafica ' ]] = $ rs [$ a ]['ragione_sociale ' ];
357+ try {
358+ $ rs = $ dbo ->fetchArray ('SELECT idanagrafica, ragione_sociale FROM an_anagrafiche WHERE ragione_sociale LIKE ' .prepare ('% ' .$ term .'% ' ));
359+
360+ for ($ a = 0 ; $ a < sizeof ($ rs ); ++$ a ) {
361+ $ idanagrafiche [] = $ rs [$ a ]['idanagrafica ' ];
362+ $ ragioni_sociali [$ rs [$ a ]['idanagrafica ' ]] = $ rs [$ a ]['ragione_sociale ' ];
363+ }
364+ } catch (Exception $ e ) {
365+ // Continua senza anagrafiche
350366 }
351367
352368 $ results = [];
353369
354- require $ file ;
370+ try {
371+ require $ file ;
372+ } catch (Exception $ e ) {
373+ return [];
374+ }
355375
356376 $ results = (array ) $ results ;
357377 foreach ($ results as $ key => $ value ) {
358- $ results [$ key ]['value ' ] = $ key ;
378+ if (is_array ($ value )) {
379+ $ results [$ key ]['value ' ] = $ key ;
380+ }
359381 }
360382
361383 return $ results ;
0 commit comments