From 893d1b60816350d8b326ee8d809f6d53d63d5a36 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Sat, 23 Jun 2018 15:41:32 +0200 Subject: [PATCH] Rimozione di vari warning --- ajax_dataload.php | 4 +- bug.php | 5 +- config.example.php | 1 + core.php | 27 ++- include/top.php | 16 +- mail.php | 10 +- modules/anagrafiche/ajax/select.php | 4 +- modules/articoli/modutil.php | 36 ++-- modules/articoli/plugins/articoli.lotti.php | 6 +- modules/contratti/edit.php | 2 +- .../contratti/plugins/addpianficazione.php | 111 ++++++------ modules/contratti/variables.php | 5 +- modules/dashboard/edit.php | 12 +- modules/ddt/add.php | 8 +- modules/ddt/variables.php | 5 +- modules/fatture/variables.php | 5 +- modules/impostazioni/edit.php | 2 +- modules/interventi/ajax_tecnici.php | 60 +++---- modules/interventi/edit.php | 12 +- modules/interventi/variables.php | 5 +- modules/ordini/variables.php | 5 +- modules/preventivi/variables.php | 5 +- src/AJAX.php | 2 +- src/App.php | 61 +++---- src/Database.php | 24 ++- src/HTMLBuilder/HTMLBuilder.php | 2 +- src/HTMLBuilder/Handler/ChoicesHandler.php | 2 +- src/HTMLBuilder/Handler/DateHandler.php | 2 +- src/HTMLBuilder/Handler/SelectHandler.php | 14 +- src/HTMLBuilder/Manager/ButtonManager.php | 5 + src/HTMLBuilder/Manager/FileManager.php | 159 +++++++++--------- src/HTMLBuilder/Manager/WidgetManager.php | 5 +- src/HTMLBuilder/Wrapper/HTMLWrapper.php | 16 +- src/Import.php | 4 +- src/Intl/Formatter.php | 1 + src/Mail.php | 17 +- src/Modules.php | 13 +- src/Prints.php | 9 +- 38 files changed, 334 insertions(+), 348 deletions(-) diff --git a/ajax_dataload.php b/ajax_dataload.php index de55cf6f5..5faf8d93d 100644 --- a/ajax_dataload.php +++ b/ajax_dataload.php @@ -102,7 +102,7 @@ if (!empty($result_query) && $result_query != 'menu' && $result_query != 'custom // Query effettiva $query = str_replace_once('SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $result_query); - + $rs = $dbo->fetchArray($query); // Conteggio dei record filtrati @@ -187,7 +187,7 @@ if (!empty($result_query) && $result_query != 'menu' && $result_query != 'custom // Colore del testo if (!empty($column['data-background'])) { - $column['data-color'] = $column['data-color'] ?: color_inverse($column['data-background']); + $column['data-color'] = isset($column['data-color']) ? $column['data-color'] : color_inverse($column['data-background']); } // Link della colonna diff --git a/bug.php b/bug.php index e8ed833bf..f72270b95 100644 --- a/bug.php +++ b/bug.php @@ -72,7 +72,6 @@ if (filter('op') == 'send') { } $pageTitle = tr('Bug'); -$jscript_modules[] = App::getPaths()['js'].'/ckeditor/ckeditor.js'; if (file_exists($docroot.'/include/custom/top.php')) { include $docroot.'/include/custom/top.php'; @@ -191,7 +190,9 @@ echo ' } }); }); -'; + + +'; if (file_exists($docroot.'/include/custom/bottom.php')) { include $docroot.'/include/custom/bottom.php'; diff --git a/config.example.php b/config.example.php index 9b411ee4e..884994cb9 100644 --- a/config.example.php +++ b/config.example.php @@ -41,5 +41,6 @@ $formatter = [ // Ulteriori file CSS e JS da includere $assets = [ 'css' => [], + 'print' => [], 'js' => [], ]; diff --git a/core.php b/core.php index 6f17d6c32..e09a64725 100644 --- a/core.php +++ b/core.php @@ -65,7 +65,7 @@ if (!API::isAPIRequest()) { // Impostazioni di debug if (!empty($debug)) { - // Ignoramento degli avvertimenti e delle informazioni relative alla deprecazione di componenti + // Ignora gli avvertimenti e le informazioni relative alla deprecazione di componenti error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_USER_DEPRECATED); // File di log ordinato in base alla data @@ -178,21 +178,13 @@ if (!API::isAPIRequest()) { register_shutdown_function('translateTemplate'); // Impostazione della sessione di base - $_SESSION['infos'] = array_unique((array) $_SESSION['infos']); - $_SESSION['warnings'] = array_unique((array) $_SESSION['warnings']); - $_SESSION['errors'] = array_unique((array) $_SESSION['errors']); + $_SESSION['infos'] = isset($_SESSION['infos']) ? array_unique($_SESSION['infos']) : []; + $_SESSION['warnings'] = isset($_SESSION['warnings']) ? array_unique($_SESSION['warnings']) : []; + $_SESSION['errors'] = isset($_SESSION['errors']) ? array_unique($_SESSION['errors']) : []; // Impostazione del tema grafico di default $theme = !empty($theme) ? $theme : 'default'; - $assets = App::getAssets(); - - // CSS di base del progetto - $css_modules = $assets['css']; - - // JS di base del progetto - $jscript_modules = $assets['js']; - if ($continue) { $id_module = filter('id_module'); $id_record = filter('id_record'); @@ -211,11 +203,6 @@ if (!API::isAPIRequest()) { $_SESSION['period_end'] = date('Y').'-12-31'; } - // Segmenti - if (empty($_SESSION['m'.$id_module]['id_segment'])) { - $_SESSION['m'.$id_module]['id_segment'] = Modules::getSegments($id_module)[0]['id']; - } - $user = Auth::user(); if (!empty($id_module)) { @@ -223,6 +210,12 @@ if (!API::isAPIRequest()) { $pageTitle = $module['title']; + // Segmenti + if (!isset($_SESSION['m'.$id_module]['id_segment'])) { + $segments = Modules::getSegments($id_module); + $_SESSION['m'.$id_module]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null; + } + Permissions::addModule($id_module); } diff --git a/include/top.php b/include/top.php index 9cb547564..0c8e6ced3 100644 --- a/include/top.php +++ b/include/top.php @@ -33,11 +33,16 @@ echo ' '; -foreach ($css_modules as $style) { - $style = (is_array($style)) ? $style : ['href' => $style, 'media' => 'all']; - +// CSS +foreach (App::getAssets()['css'] as $style) { echo ' -'; + '; +} + +// Print CSS +foreach (App::getAssets()['print'] as $style) { + echo ' + '; } if (Auth::check()) { @@ -128,7 +133,8 @@ if (Auth::check()) { '; } -foreach ($jscript_modules as $js) { +// JS +foreach (App::getAssets()['js'] as $js) { echo ' '; } diff --git a/mail.php b/mail.php index f4cce66c2..8ea6a934a 100644 --- a/mail.php +++ b/mail.php @@ -131,8 +131,11 @@ echo ' - @@ -183,7 +183,7 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica'];
-
- - @@ -251,7 +251,7 @@ $_SESSION['superselect']['idanagrafica'] = $records[0]['idanagrafica'];
-{( "name": "filelist_and_upload", "id_module": "", "id_record": "", )} +{( "name": "filelist_and_upload", "id_module": "", "id_record": "", )}
diff --git a/modules/interventi/variables.php b/modules/interventi/variables.php index 5dbcf27fe..d0b2d4f2d 100644 --- a/modules/interventi/variables.php +++ b/modules/interventi/variables.php @@ -1,13 +1,10 @@ fetchArray('SELECT *, +$r = $dbo->fetchOne('SELECT *, (SELECT MAX(orario_fine) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS data_fine, (SELECT email FROM an_anagrafiche WHERE an_anagrafiche.idanagrafica=in_interventi.idanagrafica) AS email FROM in_interventi WHERE id='.prepare($id_record)); -// Risultato effettivo -$r = $rs[0]; - // Variabili da sostituire return [ 'email' => $r['email'], diff --git a/modules/ordini/variables.php b/modules/ordini/variables.php index b95e93367..0c22be4d0 100644 --- a/modules/ordini/variables.php +++ b/modules/ordini/variables.php @@ -1,12 +1,9 @@ fetchArray('SELECT *, +$r = $dbo->fetchOne('SELECT *, (SELECT email FROM an_anagrafiche WHERE an_anagrafiche.idanagrafica=or_ordini.idanagrafica) AS email FROM or_ordini WHERE id='.prepare($id_record)); -// Risultato effettivo -$r = $rs[0]; - // Variabili da sostituire return [ 'email' => $r['email'], diff --git a/modules/preventivi/variables.php b/modules/preventivi/variables.php index 588306629..9121eaf66 100644 --- a/modules/preventivi/variables.php +++ b/modules/preventivi/variables.php @@ -1,12 +1,9 @@ fetchArray('SELECT *, +$r = $dbo->fetchOne('SELECT *, (SELECT email FROM an_anagrafiche WHERE an_anagrafiche.idanagrafica=co_preventivi.idanagrafica) AS email FROM co_preventivi WHERE id='.prepare($id_record)); -// Risultato effettivo -$r = $rs[0]; - // Variabili da sostituire return [ 'email' => $r['email'], diff --git a/src/AJAX.php b/src/AJAX.php index d144dae35..0c1ebe16a 100644 --- a/src/AJAX.php +++ b/src/AJAX.php @@ -131,7 +131,7 @@ class AJAX $results = self::completeResults($query, $where, $filter, $search_fields, $custom); } - return $results; + return isset($results) ? $results : null; } protected static function getSelectInfo() diff --git a/src/App.php b/src/App.php index 677b191b4..ae3f8a2a8 100644 --- a/src/App.php +++ b/src/App.php @@ -18,10 +18,11 @@ class App 'app.min.css', 'style.min.css', 'themes.min.css', - [ - 'href' => 'print.min.css', - 'media' => 'print', - ], + ], + + // Print CSS + 'print' => [ + 'print.min.css', ], // JS @@ -155,49 +156,39 @@ class App // Assets aggiuntivi $config = self::getConfig(); - $css = array_unique(array_merge(self::$assets['css'], $config['assets']['css'])); - $js = array_unique(array_merge(self::$assets['js'], $config['assets']['js'])); - // Impostazione dei percorsi $paths = self::getPaths(); $lang = Translator::getInstance()->getCurrentLocale(); - foreach ($css as $key => $value) { - if (is_array($value)) { - $path = $value['href']; - } else { - $path = $value; + // Sezioni: nome - percorso + $sections = [ + 'css' => 'css', + 'print' => 'css', + 'js' => 'js', + ]; + + $assets = []; + + foreach ($sections as $section => $dir) { + $result = array_unique(array_merge(self::$assets[$section], $config['assets'][$section])); + + foreach ($result as $key => $element) { + $element = $paths[$dir].'/'.$element; + $element = str_replace('|lang|', $lang, $element); + + $result[$key] = $element; } - $path = $paths['css'].'/'.$path; - $path = str_replace('|lang|', $lang, $path); - - if (is_array($value)) { - $value['href'] = $path; - } else { - $value = $path; - } - - $css[$key] = $value; - } - - foreach ($js as $key => $value) { - $value = $paths['js'].'/'.$value; - $value = str_replace('|lang|', $lang, $value); - - $js[$key] = $value; + $assets[$section] = $result; } // JS aggiuntivi per gli utenti connessi if (Auth::check()) { - $js[] = ROOTDIR.'/lib/functions.js'; - $js[] = ROOTDIR.'/lib/init.js'; + $assets['js'][] = ROOTDIR.'/lib/functions.js'; + $assets['js'][] = ROOTDIR.'/lib/init.js'; } - return [ - 'css' => $css, - 'js' => $js, - ]; + return $assets; } /** diff --git a/src/Database.php b/src/Database.php index d60bc454b..155a66d45 100644 --- a/src/Database.php +++ b/src/Database.php @@ -286,8 +286,28 @@ class Database extends Util\Singleton */ public function fetchRow($query) { + return $this->fetchOne($query); + } + + /** + * Restituisce il primo elemento della selezione, strutturato in base ai nomi degli attributi. + * Attenzione: aggiunge il LIMIT relativo a fine della query. + * + * @since 2.4 + * + * @param string $query Query da eseguire + * + * @return array + */ + public function fetchOne($query) + { + if (!str_contains($query, 'LIMIT')) { + $query .= ' LIMIT 1'; + } + $result = $this->fetchArray($query); - if (is_array($result)) { + + if (isset($result[0])) { return $result[0]; } @@ -390,7 +410,7 @@ class Database extends Util\Singleton throw new UnexpectedValueException(); } - if (!is_array($array[0])) { + if (!isset($array[0]) || !is_array($array[0])) { $array = [$array]; } diff --git a/src/HTMLBuilder/HTMLBuilder.php b/src/HTMLBuilder/HTMLBuilder.php index 699fbfd2a..6a1b5e6ee 100644 --- a/src/HTMLBuilder/HTMLBuilder.php +++ b/src/HTMLBuilder/HTMLBuilder.php @@ -204,7 +204,7 @@ class HTMLBuilder unset($json[$key]); } // Sostituzione delle variabili $nome$ col relativo valore da database - elseif (preg_match_all('/\$([a-z0-9\_]+)\$/i', $json[$key], $m)) { + elseif (is_string($json[$key]) && preg_match_all('/\$([a-z0-9\_]+)\$/i', $json[$key], $m)) { for ($i = 0; $i < count($m[0]); ++$i) { $record = isset($records[0][$m[1][$i]]) ? $records[0][$m[1][$i]] : ''; $json[$key] = str_replace($m[0][$i], prepareToField($record), $json[$key]); diff --git a/src/HTMLBuilder/Handler/ChoicesHandler.php b/src/HTMLBuilder/Handler/ChoicesHandler.php index f0ae1bf2b..1e0872438 100644 --- a/src/HTMLBuilder/Handler/ChoicesHandler.php +++ b/src/HTMLBuilder/Handler/ChoicesHandler.php @@ -48,7 +48,7 @@ class ChoicesHandler implements HandlerInterface // Generazione del codice HTML // "+ this.checked" rende il valore booleano un numero - $result .= ' + $result = '
diff --git a/src/HTMLBuilder/Handler/DateHandler.php b/src/HTMLBuilder/Handler/DateHandler.php index 9e469b976..0890bbcfd 100644 --- a/src/HTMLBuilder/Handler/DateHandler.php +++ b/src/HTMLBuilder/Handler/DateHandler.php @@ -18,7 +18,7 @@ class DateHandler implements HandlerInterface 'min-date', ]; foreach ($detect as $attr) { - if ($values[$attr] == '-now-') { + if (isset($values[$attr]) && $values[$attr] == '-now-') { $values[$attr] = date(\Intl\Formatter::getStandardFormats()['timestamp']); } } diff --git a/src/HTMLBuilder/Handler/SelectHandler.php b/src/HTMLBuilder/Handler/SelectHandler.php index f36975f37..ca230d19f 100644 --- a/src/HTMLBuilder/Handler/SelectHandler.php +++ b/src/HTMLBuilder/Handler/SelectHandler.php @@ -46,8 +46,13 @@ 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']); + } + // Gestione del select da query specifica (se il campo "values" è impostato a "query=SQL") - if (preg_match_all('/^query=(.+?)$/', $values['values'], $matches)) { + elseif (preg_match_all('/^query=(.+?)$/', $values['values'], $matches)) { $result .= $this->selectQuery($matches[1][0], $values['value']); } @@ -55,11 +60,6 @@ class SelectHandler implements HandlerInterface elseif (preg_match_all('/^list=(.+?)$/', $values['values'], $matches)) { $result .= $this->selectList(json_decode('{'.$matches[1][0].'}', true), $values); } - - // Gestione del select dal formato JSON completo, convertito in array - elseif (is_array($values['values'])) { - $result .= $this->selectArray($values['values'], $values['value']); - } } // Impostazione del placeholder @@ -155,6 +155,8 @@ class SelectHandler implements HandlerInterface */ protected function selectArray($array, $values) { + $result = ''; + $prev = ''; foreach ($array as $element) { if (!empty($element['optgroup'])) { diff --git a/src/HTMLBuilder/Manager/ButtonManager.php b/src/HTMLBuilder/Manager/ButtonManager.php index 6db4b2088..fe70bc1d0 100644 --- a/src/HTMLBuilder/Manager/ButtonManager.php +++ b/src/HTMLBuilder/Manager/ButtonManager.php @@ -9,6 +9,8 @@ class ButtonManager implements ManagerInterface { public function manage($options) { + $options['parameters'] = isset($options['parameters']) ? $options['parameters'] : null; + $result = ''; if (isset($options['id'])) { @@ -111,6 +113,7 @@ class ButtonManager implements ManagerInterface 'id_module' => $options['id_module'], 'id_record' => $options['id_record'], 'class' => $options['class'], + 'parameters' => $options['parameters'], ]); unset($list[$main]); @@ -131,6 +134,7 @@ class ButtonManager implements ManagerInterface 'id_module' => $options['id_module'], 'id_record' => $options['id_record'], 'class' => false, + 'parameters' => $options['parameters'], ]).''; } @@ -144,6 +148,7 @@ class ButtonManager implements ManagerInterface 'id_module' => $options['id_module'], 'id_record' => $options['id_record'], 'class' => $options['class'], + 'parameters' => $options['parameters'], ]); } else { $result = ' '; diff --git a/src/HTMLBuilder/Manager/FileManager.php b/src/HTMLBuilder/Manager/FileManager.php index 88564c420..3a649d13e 100644 --- a/src/HTMLBuilder/Manager/FileManager.php +++ b/src/HTMLBuilder/Manager/FileManager.php @@ -9,27 +9,31 @@ namespace HTMLBuilder\Manager; */ class FileManager implements ManagerInterface { - - /** - * Gestione "filelist_and_upload". + /** + * Gestione "filelist_and_upload". * Esempio: {( "name": "filelist_and_upload", "id_module": "2", "id_record": "1", "readonly": "false", "ajax": "true" )}. * * @param array $options * * @return string */ - public function manage($options) { - $options['readonly'] = ($options['readonly']=='true') ? true : false; + $options['readonly'] = !empty($options['readonly']) ? true : false; $options['ajax'] = isset($options['ajax']) ? $options['ajax'] : false; - $options['showpanel'] = isset($options['showpanel']) ? $options['showpanel'] : true; + $options['showpanel'] = isset($options['showpanel']) ? $options['showpanel'] : true; $options['label'] = isset($options['label']) ? $options['label'] : tr('Nuovo allegato').':'; + // Riferimento ad un plugin + $plugin = null; + if (!empty($options['id_plugin'])) { + $plugin = '_'.$options['id_plugin']; + } + $dbo = \Database::getConnection(); -$result .= ' -
+ $result = ' +
'; if (!empty($options['showpanel'])) { @@ -65,43 +69,40 @@ $result .= ' '.\Translator::timestampToLocale($r['created_at']).' - + '; - - - //Anteprime supportate dal browser - $extension = strtolower(end((explode('.', $r['original'])))); - $supported_extensions = ['pdf','jpg','png','gif','jpeg','bmp']; - if ( in_array($extension, $supported_extensions)){ - - $result .= "
"; - - if ($extension=='pdf'){ - $result .= " - "; - }else{ - $result .= " - "; - } - - $result .= "
"; - - $result .= " "; - - }else{ - $result .= " \n"; - } - - if (!$options['readonly']){ - $result .= ' + + //Anteprime supportate dal browser + $extension = strtolower(end((explode('.', $r['original'])))); + $supported_extensions = ['pdf', 'jpg', 'png', 'gif', 'jpeg', 'bmp']; + if (in_array($extension, $supported_extensions)) { + $result .= "
"; + + if ($extension == 'pdf') { + $result .= ' + '; + } else { + $result .= ' + '; + } + + $result .= '
'; + + $result .= ' "; + } else { + $result .= ' \n"; + } + + if (!$options['readonly']) { + $result .= ' '; - } - - $result .= ' + } + + $result .= ' '; } @@ -110,63 +111,69 @@ $result .= '

'; - }else{ - //in caso di readonly, se non è stato caricato nessun allegato mostro almeno box informativo - if ($options['readonly']){ - $result .= ' + } else { + //in caso di readonly, se non è stato caricato nessun allegato mostro almeno box informativo + if ($options['readonly']) { + $result .= '
'.tr('Nessun allegato è stato caricato', []).'.
'; - } - } + } + } - - if (!$options['readonly']){ - - // Form per l'upload di un nuovo file - $result .= ' + if (!$options['readonly']) { + // Form per l'upload di un nuovo file + $result .= ' '.$options['label'].'
- +
- {[ "type": "text", "placeholder": "'.tr('Nome').'", "name": "nome_allegato", "id": "nome_allegato_'.$options['id_record'].((!empty($options['id_plugin'])) ? '_'.$options['id_plugin'] : '').'" ]} + {[ "type": "text", "placeholder": "'.tr('Nome').'", "name": "nome_allegato", "id": "nome_allegato_'.$options['id_record'].$plugin.'" ]}
- {[ "type": "file", "placeholder": "'.tr('File').'", "name": "blob", "id": "blob_'.$options['id_record'].((!empty($options['id_plugin'])) ? '_'.$options['id_plugin'] : '').'", "required": 0 ]} + {[ "type": "file", "placeholder": "'.tr('File').'", "name": "blob", "id": "blob_'.$options['id_record'].$plugin.'", "required": 0 ]}
'; - - $result .= ' + + $result .= '
-
'; - - $result .= ' + + $result .= '
'; - } + } $result .= '