2019-05-04 02:03: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 />.
*/
2019-05-04 02:03:42 +02:00
include_once __DIR__ . '/../../core.php' ;
2020-11-27 17:11:18 +01:00
use API\Services ;
use Models\Cache ;
2019-05-04 02:03:42 +02:00
use Util\FileSystem ;
$id = post ( 'id' );
switch ( filter ( 'op' )) {
case 'uninstall' :
if ( ! empty ( $id )) {
// Leggo l'id del modulo
$rs = $dbo -> fetchArray ( 'SELECT id, name, directory FROM zz_modules WHERE id=' . prepare ( $id ) . ' AND `default`=0' );
$modulo = $rs [ 0 ][ 'title' ];
$module_dir = $rs [ 0 ][ 'directory' ];
if ( count ( $rs ) == 1 ) {
// Elimino il modulo dal menu
$dbo -> query ( 'DELETE FROM zz_modules WHERE id=' . prepare ( $id ) . ' OR parent=' . prepare ( $id ));
2020-09-23 13:36:37 +02:00
$uninstall_script = base_dir () . '/modules/' . $module_dir . '/update/uninstall.php' ;
2019-05-04 02:03:42 +02:00
if ( file_exists ( $uninstall_script )) {
include_once $uninstall_script ;
}
2020-09-23 13:36:37 +02:00
delete ( base_dir () . '/modules/' . $module_dir . '/' );
2019-05-04 02:03:42 +02:00
flash () -> info ( tr ( 'Modulo "_MODULE_" disinstallato!' , [
'_MODULE_' => $modulo ,
]));
}
}
break ;
case 'disable' :
$dbo -> query ( 'UPDATE `zz_modules` SET `enabled` = 0 WHERE (`id` = ' . prepare ( $id ) . ' OR `parent` = ' . prepare ( $id ) . ') AND `id` != ' . prepare ( Modules :: get ( 'Stato dei servizi' )[ 'id' ]));
flash () -> info ( tr ( 'Modulo "_MODULE_" disabilitato!' , [
'_MODULE_' => Modules :: get ( $id )[ 'title' ],
]));
break ;
case 'enable' :
$dbo -> query ( 'UPDATE `zz_modules` SET `enabled` = 1 WHERE `id` = ' . prepare ( $id ) . ' OR `parent` = ' . prepare ( $id ));
flash () -> info ( tr ( 'Modulo "_MODULE_" abilitato!' , [
'_MODULE_' => Modules :: get ( $id )[ 'title' ],
]));
break ;
case 'disable_widget' :
$dbo -> query ( 'UPDATE zz_widgets SET enabled = 0 WHERE id = ' . prepare ( $id ));
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
flash () -> info ( tr ( 'Widget "_WIDGET_" disabilitato!' , [
'_WIDGET_' => $widget ,
]));
break ;
case 'enable_widget' :
$dbo -> query ( 'UPDATE zz_widgets SET enabled=1 WHERE id=' . prepare ( $id ));
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
flash () -> info ( tr ( 'Widget "_WIDGET_" abilitato!' , [
'_WIDGET_' => $widget ,
]));
break ;
case 'change_position_widget_top' :
$dbo -> query ( " UPDATE zz_widgets SET location='controller_top' WHERE id= " . prepare ( $id ));
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
flash () -> info ( tr ( 'Posizione del widget "_WIDGET_" aggiornata!' , [
'_WIDGET_' => $widget ,
]));
break ;
case 'change_position_widget_right' :
$dbo -> query ( " UPDATE zz_widgets SET location='controller_right' WHERE id= " . prepare ( $id ));
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
flash () -> info ( tr ( 'Posizione del widget "_WIDGET_" aggiornata!' , [
'_WIDGET_' => $widget ,
]));
break ;
// Ordinamento moduli di primo livello
2019-07-26 17:40:52 +02:00
case 'sort_modules' :
2019-05-04 02:03:42 +02:00
$rs = $dbo -> fetchArray ( 'SELECT id FROM zz_modules WHERE enabled = 1 AND parent IS NULL ORDER BY `order` ASC' );
if ( $_POST [ 'ids' ] != implode ( ',' , array_column ( $rs , 'id' ))) {
$ids = explode ( ',' , $_POST [ 'ids' ]);
for ( $i = 0 ; $i < count ( $ids ); ++ $i ) {
$dbo -> query ( 'UPDATE zz_modules SET `order`=' . prepare ( $i ) . ' WHERE id=' . prepare ( $ids [ $i ]));
}
flash () -> info ( tr ( 'Posizione delle voci di menù aggiornata!' ));
}
break ;
2019-07-26 17:40:52 +02:00
case 'sort_widgets' :
2019-05-04 02:03:42 +02:00
$location = post ( 'location' );
2019-07-26 17:40:52 +02:00
$id_module_widget = post ( 'id_module_widget' );
2019-05-04 02:03:42 +02:00
$location = empty ( $id_record ) ? 'controller_' . $location : 'editor_' . $location ;
2019-07-26 17:40:52 +02:00
$rs = $dbo -> fetchArray ( " SELECT CONCAT('widget_', id) AS id FROM zz_widgets WHERE enabled = 1 AND location = " . prepare ( $location ) . ' AND id_module = ' . prepare ( $id_module_widget ) . ' ORDER BY `order` ASC' );
2019-05-04 02:03:42 +02:00
if ( $_POST [ 'ids' ] != implode ( ',' , array_column ( $rs , 'id' ))) {
$ids = explode ( ',' , $_POST [ 'ids' ]);
for ( $i = 0 ; $i < count ( $ids ); ++ $i ) {
$id = explode ( '_' , $ids [ $i ]);
$dbo -> query ( 'UPDATE zz_widgets SET `order`=' . prepare ( $i ) . ' WHERE id=' . prepare ( $id [ 1 ]));
}
flash () -> info ( tr ( 'Posizioni widgets aggiornate!' ));
}
break ;
case 'sizes' :
$results = [];
$backup_dir = App :: getConfig ()[ 'backup_dir' ];
$dirs = [
$backup_dir => tr ( 'Backup' ),
2020-09-23 13:36:37 +02:00
base_dir () . '/files' => tr ( 'Allegati' ),
base_dir () . '/logs' => tr ( 'Logs' ),
2019-05-04 02:03:42 +02:00
];
foreach ( $dirs as $dir => $description ) {
2020-06-26 16:26:42 +02:00
$size = FileSystem :: folderSize ( $dir , [ 'htaccess' ]);
2019-07-19 15:23:00 +02:00
2019-05-04 02:03:42 +02:00
$results [] = [
'description' => $description ,
'size' => $size ,
'formattedSize' => FileSystem :: formatBytes ( $size ),
2020-08-31 16:30:54 +02:00
'count' => FileSystem :: fileCount ( $dir , [ 'htaccess' ]) ? : 0 ,
'dbSize' => ( $description == 'Allegati' ) ? $dbo -> fetchOne ( 'SELECT SUM(`size`) AS dbsize FROM zz_files' )[ 'dbsize' ] : '' ,
'dbCount' => ( $description == 'Allegati' ) ? $dbo -> fetchOne ( 'SELECT COUNT(`id`) AS dbcount FROM zz_files' )[ 'dbcount' ] : '' ,
'dbExtensions' => ( $description == 'Allegati' ) ? $dbo -> fetchArray ( " SELECT SUBSTRING_INDEX(filename, '.', -1) AS extension, COUNT(*) AS num FROM zz_files GROUP BY extension ORDER BY num DESC LIMIT 10 " ) : '' ,
2019-05-04 02:03:42 +02:00
];
}
echo json_encode ( $results );
break ;
2020-11-27 17:11:18 +01:00
case 'informazioni-fe' :
$info = Cache :: pool ( 'Informazioni su spazio FE' );
if ( ! $info -> isValid ()) {
$response = Services :: request ( 'POST' , 'informazioni_fe' );
$response = Services :: responseBody ( $response );
$info -> set ( $response [ 'result' ]);
}
$informazioni = $info -> content ;
2021-03-01 16:41:52 +01:00
// Formattazione dei contenuti
$history = ( array ) $informazioni [ 'history' ];
foreach ( $history as $key => $value ) {
$history [ $key ][ 'size' ] = Filesystem :: formatBytes ( $value [ 'size' ]);
2021-03-16 16:31:58 +01:00
$history [ $key ][ 'invoices_size' ] = Filesystem :: formatBytes ( $value [ 'invoices_size' ]);
$history [ $key ][ 'notifies_size' ] = Filesystem :: formatBytes ( $value [ 'notifies_size' ]);
2021-03-01 16:41:52 +01:00
}
2020-11-27 17:11:18 +01:00
echo json_encode ([
'invoice_number' => $informazioni [ 'invoice_number' ],
'size' => Filesystem :: formatBytes ( $informazioni [ 'size' ]),
2021-03-16 16:31:58 +01:00
'invoices_size' => Filesystem :: formatBytes ( $informazioni [ 'invoices_size' ]),
'notifies_size' => Filesystem :: formatBytes ( $informazioni [ 'notifies_size' ]),
2021-03-01 16:47:01 +01:00
'history' => $history ,
2020-11-27 17:11:18 +01:00
]);
break ;
2019-05-04 02:03:42 +02:00
}