2018-06-29 17:58:42 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2018-06-29 17:58:42 +02:00
2023-12-06 17:24:23 +01:00
/*
2018-12-19 18:24:19 +01:00
* Controlla se il database presenta alcune sezioni personalizzate .
2018-12-12 17:54:31 +01:00
*
* @ return array
*/
2023-12-06 16:48:54 +01:00
if ( ! function_exists ( 'customStructure' )) {
function customStructure ()
{
$results = [];
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$dirs = [
'modules' ,
'templates' ,
'plugins' ,
];
// Controlli di personalizzazione fisica
foreach ( $dirs as $dir ) {
$files = glob ( base_dir () . '/' . $dir . '/*/custom/*.{php,html}' , GLOB_BRACE );
$recursive_files = glob ( base_dir () . '/' . $dir . '/*/custom/**/*.{php,html}' , GLOB_BRACE );
$files = array_merge ( $files , $recursive_files );
foreach ( $files as $file ) {
$file = str_replace ( base_dir () . '/' , '' , $file );
$result = explode ( '/custom/' , $file )[ 0 ];
if ( ! in_array ( $result , $results )) {
$results [] = $result ;
}
}
}
// Gestione cartella include
$files = glob ( base_dir () . '/include/custom/*.{php,html}' , GLOB_BRACE );
$recursive_files = glob ( base_dir () . '/include/custom/**/*.{php,html}' , GLOB_BRACE );
2020-12-11 18:03:23 +01:00
2021-02-18 18:48:44 +01:00
$files = array_merge ( $files , $recursive_files );
2020-12-11 18:03:23 +01:00
2020-06-11 12:59:33 +02:00
foreach ( $files as $file ) {
2020-09-23 13:36:37 +02:00
$file = str_replace ( base_dir () . '/' , '' , $file );
2020-06-11 12:59:33 +02:00
$result = explode ( '/custom/' , $file )[ 0 ];
if ( ! in_array ( $result , $results )) {
$results [] = $result ;
}
}
2020-12-11 18:03:23 +01:00
2023-12-06 16:48:54 +01:00
return $results ;
2018-12-12 17:54:31 +01:00
}
}
2023-12-06 17:24:23 +01:00
/*
2018-12-19 18:24:19 +01:00
* Controlla se il database presenta alcune sezioni personalizzate .
2018-12-12 17:54:31 +01:00
*
* @ return array
*/
2023-12-06 16:48:54 +01:00
if ( ! function_exists ( 'customTables' )) {
function customTables ()
{
$tables = include base_dir () . '/update/tables.php' ;
$names = [];
foreach ( $tables as $table ) {
$names [] = prepare ( $table );
}
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$database = database ();
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$results = $database -> fetchArray ( 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ' . prepare ( $database -> getDatabaseName ()) . ' AND TABLE_NAME NOT IN (' . implode ( ',' , $names ) . " ) AND TABLE_NAME != 'updates' " );
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
return array_column ( $results , 'TABLE_NAME' );
}
2018-12-12 17:54:31 +01:00
}
2023-12-06 17:24:23 +01:00
/*
2018-12-19 18:24:19 +01:00
* Controlla se il database presenta alcune sezioni personalizzate .
2018-12-12 17:54:31 +01:00
*
* @ return array
*/
2023-12-06 16:48:54 +01:00
if ( ! function_exists ( 'customDatabase' )) {
function customDatabase ()
{
$database = database ();
2024-04-18 17:44:05 +02:00
$modules = $database -> fetchArray ( " SELECT `title`, CONCAT('modules/', `directory`) AS directory FROM `zz_modules` LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = " . prepare ( Models\Locale :: getDefault () -> id ) . " ) WHERE `options2` != '' " );
$plugins = $database -> fetchArray ( " SELECT `title`, CONCAT('plugins/', `directory`) AS directory FROM `zz_plugins` LEFT JOIN `zz_plugins_lang` ON (`zz_plugins`.`id` = `zz_plugins_lang`.`id_record` AND `zz_plugins_lang`.`id_lang` = " . prepare ( Models\Locale :: getDefault () -> id ) . " ) WHERE `options2` != '' " );
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$results = array_merge ( $modules , $plugins );
return $results ;
}
2018-12-12 17:54:31 +01:00
}
2023-12-06 16:48:54 +01:00
if ( ! function_exists ( 'customComponents' )) {
function customComponents ()
{
$database_check = customDatabase ();
$structure_check = customStructure ();
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$list = [];
foreach ( $database_check as $element ) {
$pos = array_search ( $element [ 'directory' ], $structure_check );
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
$list [] = [
'path' => $element [ 'directory' ],
'database' => true ,
'directory' => $pos !== false ,
];
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
if ( $pos !== false ) {
unset ( $structure_check [ $pos ]);
}
2018-12-12 17:54:31 +01:00
}
2023-12-06 16:48:54 +01:00
foreach ( $structure_check as $element ) {
$list [] = [
'path' => $element ,
'database' => false ,
'directory' => true ,
];
}
2018-12-12 17:54:31 +01:00
2023-12-06 16:48:54 +01:00
return $list ;
}
2023-12-06 17:24:23 +01:00
}