diff --git a/ajax_dataload.php b/ajax_dataload.php index d016c8f16..e4e8da30e 100644 --- a/ajax_dataload.php +++ b/ajax_dataload.php @@ -13,18 +13,14 @@ array_shift($columns); // Lettura parametri iniziali if (!empty($id_plugin)) { - $total = Plugins::getQuery($id_plugin); - - $total['query'] = Modules::replacePlaceholder($total['query'], $id_parent); + $element = Plugins::get($id_plugin); } else { - $total = Modules::getQuery($id_module); + $element = Modules::get($id_module); } +$total = App::readQuery($element); // Lettura parametri modulo -$module_query = $total['query']; -$module_query = str_replace('|period_start|', $_SESSION['period_start'], $module_query); -$module_query = str_replace('|period_end|', $_SESSION['period_end'], $module_query); -$module_query = str_replace('|select|', $total['select'], $module_query); +$result_query = $total['query']; // Predisposizione dela risposta $results = []; @@ -33,12 +29,12 @@ $results['recordsTotal'] = 0; $results['recordsFiltered'] = 0; $results['summable'] = []; -if (!empty($module_query) && $module_query != 'menu' && $module_query != 'custom') { +if (!empty($result_query) && $result_query != 'menu' && $result_query != 'custom') { // Conteggio totale - $query = 'SELECT COUNT(*) as `tot` FROM ('.$module_query.') AS `count`'; - $cont = $dbo->fetchArray($query); - if (!empty($cont)) { - $results['recordsTotal'] = $cont[0]['tot']; + $count_query = 'SELECT COUNT(*) as `tot` FROM ('.$result_query.') AS `count`'; + $count = $dbo->fetchArray($count_query); + if (!empty($count)) { + $results['recordsTotal'] = $count[0]['tot']; } // Filtri di ricerica @@ -61,48 +57,42 @@ if (!empty($module_query) && $module_query != 'menu' && $module_query != 'custom } } } - - - - /*filtro sezionali*/ - if (isset($_SESSION['entrata']['idsezionale']) AND (($modules_info[$id_module]['name'] == 'Fatture di vendita') or ($modules_info[$id_module]['name'] == 'Laboratorio') or ($modules_info[$id_module]['name'] == 'Ticket')) ){ - - $module_query = str_replace('1=1', " 1=1 AND idsezionale = '".$_SESSION['entrata']["idsezionale"]."' ", $module_query); - - } - - if (isset($_SESSION['uscita']['idsezionale']) AND ($modules_info[$id_module]['name'] == 'Fatture di acquisto') ){ - - $module_query = str_replace('1=1', " 1=1 AND idsezionale = '".$_SESSION['uscita']["idsezionale"]."' ", $module_query); - } - /*fine filtro sezionali*/ - - + + /*filtro sezionali*/ + if (isset($_SESSION['entrata']['idsezionale']) and (($modules_info[$id_module]['name'] == 'Fatture di vendita') or ($modules_info[$id_module]['name'] == 'Laboratorio') or ($modules_info[$id_module]['name'] == 'Ticket'))) { + $result_query = str_replace('1=1', " 1=1 AND idsezionale = '".$_SESSION['entrata']['idsezionale']."' ", $result_query); + } + + if (isset($_SESSION['uscita']['idsezionale']) and ($modules_info[$id_module]['name'] == 'Fatture di acquisto')) { + $result_query = str_replace('1=1', " 1=1 AND idsezionale = '".$_SESSION['uscita']['idsezionale']."' ", $result_query); + } + /*fine filtro sezionali*/ + if (!empty($search_filters)) { - $module_query = str_replace('2=2', '2=2 AND ('.implode(' AND ', $search_filters).') ', $module_query); + $result_query = str_replace('2=2', '2=2 AND ('.implode(' AND ', $search_filters).') ', $result_query); } // Filtri derivanti dai permessi (eventuali) if (empty($id_plugin)) { - $module_query = Modules::replaceAdditionals($id_module, $module_query); + $result_query = Modules::replaceAdditionals($id_module, $result_query); } // Ordinamento dei risultati if (isset($order['dir']) && isset($order['column'])) { - $pieces = explode('ORDER', $module_query); + $pieces = explode('ORDER', $result_query); - $cont = count($pieces); - if ($cont > 1) { - unset($pieces[$cont - 1]); + $count = count($pieces); + if ($count > 1) { + unset($pieces[$count - 1]); } - $module_query = implode('ORDER', $pieces).' ORDER BY '.$total['order_by'][$order['column']].' '.$order['dir']; + $result_query = implode('ORDER', $pieces).' ORDER BY '.$total['order_by'][$order['column']].' '.$order['dir']; } // Calcolo di eventuali somme if (!empty($total['summable'])) { - $query = str_replace_once('SELECT', 'SELECT '.implode(', ', $total['summable']).' FROM(SELECT ', $module_query).') AS `z`'; - $sums = $dbo->fetchArray($query)[0]; + $sum_query = str_replace_once('SELECT', 'SELECT '.implode(', ', $total['summable']).' FROM(SELECT ', $result_query).') AS `z`'; + $sums = $dbo->fetchArray($sum_query)[0]; if (!empty($sums)) { $r = []; foreach ($sums as $key => $sum) { @@ -116,17 +106,17 @@ if (!empty($module_query) && $module_query != 'menu' && $module_query != 'custom // Paginazione if ($length > 0) { - $module_query .= ' LIMIT '.$start.', '.$length; + $result_query .= ' LIMIT '.$start.', '.$length; } // Query effettiva - $query = str_replace_once('SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $module_query); + $query = str_replace_once('SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $result_query); $rs = $dbo->fetchArray($query); // Conteggio dei record filtrati - $cont = $dbo->fetchArray('SELECT FOUND_ROWS()'); - if (!empty($cont)) { - $results['recordsFiltered'] = $cont[0]['FOUND_ROWS()']; + $count = $dbo->fetchArray('SELECT FOUND_ROWS()'); + if (!empty($count)) { + $results['recordsFiltered'] = $count[0]['FOUND_ROWS()']; } // Creazione della tabella diff --git a/config.example.php b/config.example.php index f6f95ccd8..6beba5d7e 100644 --- a/config.example.php +++ b/config.example.php @@ -36,3 +36,9 @@ $formatter = [ 'thousands' => '.', ], ]; + +// Ulteriori file CSS e JS da includere +$assets = [ + 'css' => [], + 'js' => [], +]; diff --git a/core.php b/core.php index 8cec68f49..eca370414 100644 --- a/core.php +++ b/core.php @@ -12,24 +12,16 @@ if (file_exists(__DIR__.'/config.inc.php')) { include_once __DIR__.'/config.inc.php'; } -// Individuazione dei percorsi di base -$docroot = __DIR__; -$rootdir = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')).'/'; -if (strrpos($rootdir, '/'.basename($docroot).'/') !== false) { - $rootdir = substr($rootdir, 0, strrpos($rootdir, '/'.basename($docroot).'/')).'/'.basename($docroot); -} else { - $rootdir = '/'; -} -$rootdir = rtrim($rootdir, '/'); -$rootdir = str_replace('%2F', '/', rawurlencode($rootdir)); - -// Aggiunta delle variabili globali -define('DOCROOT', $docroot); -define('ROOTDIR', $rootdir); - // Caricamento delle dipendenze e delle librerie del progetto require_once __DIR__.'/vendor/autoload.php'; +// Individuazione dei percorsi di base +App::definePaths(__DIR__); + +$docroot = DOCROOT; +$rootdir = ROOTDIR; +$baseurl = BASEURL; + // Redirect al percorso HTTPS se impostato nella configurazione if (!empty($redirectHTTPS) && !isHTTPS(true)) { header('HTTP/1.1 301 Moved Permanently'); @@ -37,10 +29,6 @@ if (!empty($redirectHTTPS) && !isHTTPS(true)) { exit(); } -// Individuazione del percorso BASEURL -$baseurl = (isHTTPS(true) ? 'https' : 'http').'://'.$_SERVER['SERVER_NAME'].$rootdir; -define('BASEURL', $baseurl); - // Forzamento del debug // $debug = true; @@ -59,11 +47,11 @@ use Monolog\Handler\RotatingFileHandler; $handlers = []; if (!API::isAPIRequest()) { // File di log di base (logs/error.log) - $handlers[] = new StreamHandler(__DIR__.'/logs/error.log', Monolog\Logger::ERROR); - $handlers[] = new StreamHandler(__DIR__.'/logs/setup.log', Monolog\Logger::EMERGENCY); + $handlers[] = new StreamHandler($docroot.'/logs/error.log', Monolog\Logger::ERROR); + $handlers[] = new StreamHandler($docroot.'/logs/setup.log', Monolog\Logger::EMERGENCY); // Impostazione dei log estesi (per monitorare in modo completo le azioni degli utenti) - $handlers[] = new StreamHandler(__DIR__.'/logs/info.log', Monolog\Logger::INFO); + $handlers[] = new StreamHandler($docroot.'/logs/info.log', Monolog\Logger::INFO); // Impostazioni di debug if (!empty($debug)) { @@ -71,26 +59,24 @@ if (!API::isAPIRequest()) { error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_USER_DEPRECATED); // File di log ordinato in base alla data - $handlers[] = new RotatingFileHandler(__DIR__.'/logs/error.log', 0, Monolog\Logger::ERROR); - $handlers[] = new RotatingFileHandler(__DIR__.'/logs/setup.log', 0, Monolog\Logger::EMERGENCY); + $handlers[] = new RotatingFileHandler($docroot.'/logs/error.log', 0, Monolog\Logger::ERROR); + $handlers[] = new RotatingFileHandler($docroot.'/logs/setup.log', 0, Monolog\Logger::EMERGENCY); - if (version_compare(PHP_VERSION, '5.5.9') >= 0) { - $prettyPageHandler = new Whoops\Handler\PrettyPageHandler(); + $prettyPageHandler = new Whoops\Handler\PrettyPageHandler(); - // Imposta Whoops come gestore delle eccezioni di default - $whoops = new Whoops\Run(); - $whoops->pushHandler($prettyPageHandler); + // Imposta Whoops come gestore delle eccezioni di default + $whoops = new Whoops\Run(); + $whoops->pushHandler($prettyPageHandler); - // Abilita la gestione degli errori nel caso la richiesta sia di tipo AJAX - if (Whoops\Util\Misc::isAjaxRequest()) { - $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); - } - - $whoops->register(); + // Abilita la gestione degli errori nel caso la richiesta sia di tipo AJAX + if (Whoops\Util\Misc::isAjaxRequest()) { + $whoops->pushHandler(new Whoops\Handler\JsonResponseHandler()); } + + $whoops->register(); } } else { - $handlers[] = new StreamHandler(__DIR__.'/logs/api.log', Monolog\Logger::ERROR); + $handlers[] = new StreamHandler($docroot.'/logs/api.log', Monolog\Logger::ERROR); } // Disabilita la segnalazione degli errori (se il debug è disabilitato) @@ -183,36 +169,13 @@ if (!API::isAPIRequest()) { // Impostazione del tema grafico di default $theme = !empty($theme) ? $theme : 'default'; - $assets = $rootdir.'/assets/dist'; - $css = $assets.'/css'; - $js = $assets.'/js'; - $img = $assets.'/img'; + $assets = App::getAssets(); // CSS di base del progetto - $css_modules = []; - - $css_modules[] = $css.'/app.min.css'; - $css_modules[] = $css.'/style.min.css'; - $css_modules[] = $css.'/themes.min.css'; - $css_modules[] = [ - 'href' => $css.'/print.min.css', - 'media' => 'print', - ]; + $css_modules = $assets['css']; // JS di base del progetto - $jscript_modules = []; - - $jscript_modules[] = $js.'/app.min.js'; - $jscript_modules[] = $js.'/custom.min.js'; - $jscript_modules[] = $js.'/i18n/parsleyjs/'.$lang.'.min.js'; - $jscript_modules[] = $js.'/i18n/select2/'.$lang.'.min.js'; - $jscript_modules[] = $js.'/i18n/moment/'.$lang.'.min.js'; - $jscript_modules[] = $js.'/i18n/fullcalendar/'.$lang.'.min.js'; - - if (Auth::check()) { - $jscript_modules[] = $rootdir.'/lib/functions.js'; - $jscript_modules[] = $rootdir.'/lib/init.js'; - } + $jscript_modules = $assets['js']; if ($continue) { // Istanziamento della barra di debug @@ -249,36 +212,8 @@ if (!API::isAPIRequest()) { } Permissions::check(); - - // Retrocompatibilità - $user_idanagrafica = $user['idanagrafica']; - - $rs = $dbo->fetchArray('SELECT * FROM `zz_modules` LEFT JOIN (SELECT `idmodule`, `permessi` FROM `zz_permissions` WHERE `idgruppo`=(SELECT `idgruppo` FROM `zz_users` WHERE `id`='.prepare($_SESSION['id_utente']).')) AS `zz_permissions` ON `zz_modules`.`id`=`zz_permissions`.`idmodule` LEFT JOIN (SELECT `idmodule`, `clause` FROM `zz_group_module` WHERE `idgruppo`=(SELECT `idgruppo` FROM `zz_users` WHERE `id`='.prepare($_SESSION['id_utente']).')) AS `zz_group_module` ON `zz_modules`.`id`=`zz_group_module`.`idmodule`'); - - $modules_info = []; - for ($i = 0; $i < count($rs); ++$i) { - foreach ($rs[$i] as $name => $value) { - if ($name == 'permessi' && (Auth::admin() || $value == null)) { - if (Auth::admin()) { - $value = 'rw'; - } else { - $value = '-'; - } - } - if ($name != 'idmodule' && $name != 'updated_at' && $name != 'created_at' && $name != 'clause') { - $modules_info[$rs[$i]['name']][$name] = $value; - } elseif ($name == 'clause') { - $additional_where[$rs[$i]['name']] = !empty($value) ? ' AND '.$value : $value; - } - } - - $modules_info[$rs[$i]['id']]['name'] = $rs[$i]['name']; - } } - // Istanziamento di HTMLHelper (retrocompatibilità) - $html = new HTMLHelper(); - // Variabili GET e POST $post = Filter::getPOST(); $get = Filter::getGET(); diff --git a/include/manager.php b/include/manager.php index 158640e3d..cfd9f4175 100644 --- a/include/manager.php +++ b/include/manager.php @@ -4,14 +4,14 @@ include_once __DIR__.'/../core.php'; // Lettura parametri iniziali del modulo if (!empty($id_plugin)) { - $info = Plugins::get($id_plugin); + $element = Plugins::get($id_plugin); - if (!empty($info['script'])) { + if (!empty($element['script'])) { // Inclusione di eventuale plugin personalizzato - if (file_exists($docroot.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script'])) { - include $docroot.'/modules/'.$info['module_dir'].'/plugins/custom/'.$info['script']; - } elseif (file_exists($docroot.'/modules/'.$info['module_dir'].'/plugins/'.$info['script'])) { - include $docroot.'/modules/'.$info['module_dir'].'/plugins/'.$info['script']; + if (file_exists($docroot.'/modules/'.$element['module_dir'].'/plugins/custom/'.$element['script'])) { + include $docroot.'/modules/'.$element['module_dir'].'/plugins/custom/'.$element['script']; + } elseif (file_exists($docroot.'/modules/'.$element['module_dir'].'/plugins/'.$element['script'])) { + include $docroot.'/modules/'.$element['module_dir'].'/plugins/'.$element['script']; } return; @@ -19,9 +19,9 @@ if (!empty($id_plugin)) { echo '