2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$id = post ( 'id' );
switch ( post ( 'op' )) {
case 'upload' :
include $docroot . '/modules/aggiornamenti/upload_modules.php' ;
break ;
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 ][ 'name' ];
$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 ));
$uninstall_script = $docroot . '/modules/' . $module_dir . '/update/uninstall.php' ;
if ( file_exists ( $uninstall_script )) {
include_once $uninstall_script ;
}
2017-09-11 17:49:03 +02:00
delete ( $docroot . '/modules/' . $module_dir . '/' );
2017-09-10 14:35:41 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Modulo _MODULE_ disinstallato!' , [
2017-09-11 17:49:03 +02:00
'_MODULE_' => '"' . $modulo . '"' ,
]);
2017-08-04 16:28:16 +02:00
}
}
break ;
case 'disable' :
2018-06-29 18:32:39 +02:00
$dbo -> query ( 'UPDATE `zz_modules` SET `enabled` = 0 WHERE (`id` = ' . prepare ( $id ) . ' OR `parent` = ' . prepare ( $id ) . ') AND `id` != ' . prepare ( Modules :: get ( 'Aggiornamenti' )[ 'id' ]));
2018-03-24 13:02:37 +01:00
2017-09-10 14:35:41 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Modulo _MODULE_ disabilitato!' , [
2018-06-29 17:58:42 +02:00
'_MODULE_' => '"' . Modules :: get ( $id )[ 'name' ] . '"' ,
2017-09-10 14:35:41 +02:00
]);
2017-08-04 16:28:16 +02:00
break ;
case 'enable' :
2018-06-29 17:58:42 +02:00
$dbo -> query ( 'UPDATE `zz_modules` SET `enabled` = 1 WHERE `id` = ' . prepare ( $id ) . ' OR `parent` = ' . prepare ( $id ));
2018-03-24 13:02:37 +01:00
2017-09-10 14:35:41 +02:00
$_SESSION [ 'infos' ][] = tr ( 'Modulo _MODULE_ abilitato!' , [
2018-06-29 17:58:42 +02:00
'_MODULE_' => '"' . Modules :: get ( $id )[ 'name' ] . '"' ,
2017-09-10 14:35:41 +02:00
]);
2017-08-04 16:28:16 +02:00
break ;
case 'disable_widget' :
2018-06-29 17:58:42 +02:00
$dbo -> query ( 'UPDATE zz_widgets SET enabled = 0 WHERE id = ' . prepare ( $id ));
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$_SESSION [ 'infos' ][] = tr ( 'Widget _WIDGET_ disabilitato!' , [
'_WIDGET_' => '"' . $widget . '"' ,
]);
2017-08-04 16:28:16 +02:00
break ;
case 'enable_widget' :
2018-02-22 09:38:31 +01:00
$dbo -> query ( 'UPDATE zz_widgets SET enabled=1 WHERE id=' . prepare ( $id ));
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$_SESSION [ 'infos' ][] = tr ( 'Widget _WIDGET_ abilitato!' , [
'_WIDGET_' => '"' . $widget . '"' ,
]);
2017-08-04 16:28:16 +02:00
break ;
case 'change_position_widget_top' :
2018-02-22 09:38:31 +01:00
$dbo -> query ( " UPDATE zz_widgets SET location='controller_top' WHERE id= " . prepare ( $id ));
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$_SESSION [ 'infos' ][] = tr ( 'Posizione del widget _WIDGET_ aggiornata!' , [
'_WIDGET_' => '"' . $widget . '"' ,
]);
2017-08-04 16:28:16 +02:00
break ;
case 'change_position_widget_right' :
2018-02-22 09:38:31 +01:00
$dbo -> query ( " UPDATE zz_widgets SET location='controller_right' WHERE id= " . prepare ( $id ));
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$rs = $dbo -> fetchArray ( 'SELECT id, name FROM zz_widgets WHERE id=' . prepare ( $id ));
$widget = $rs [ 0 ][ 'name' ];
2018-03-24 13:02:37 +01:00
2018-02-22 09:38:31 +01:00
$_SESSION [ 'infos' ][] = tr ( 'Posizione del widget _WIDGET_ aggiornata!' , [
'_WIDGET_' => '"' . $widget . '"' ,
]);
2017-08-04 16:28:16 +02:00
break ;
// Ordinamento moduli di primo livello
case 'sortmodules' :
2018-02-22 00:00:35 +01:00
$rs = $dbo -> fetchArray ( 'SELECT id FROM zz_modules WHERE enabled = 1 AND parent IS NULL ORDER BY `order` ASC' );
2018-02-18 19:53:23 +01:00
2018-02-22 00:00:35 +01:00
if ( $_POST [ 'ids' ] != implode ( ',' , array_column ( $rs , 'id' ))) {
$ids = explode ( ',' , $_POST [ 'ids' ]);
2018-02-18 19:53:23 +01:00
2018-02-22 00:00:35 +01:00
for ( $i = 0 ; $i < count ( $ids ); ++ $i ) {
$dbo -> query ( 'UPDATE zz_modules SET `order`=' . prepare ( $i ) . ' WHERE id=' . prepare ( $ids [ $i ]));
}
$_SESSION [ 'infos' ][] = tr ( 'Posizione voci di menù aggiornate!' );
2017-08-04 16:28:16 +02:00
}
2018-02-18 19:53:23 +01:00
2017-08-04 16:28:16 +02:00
break ;
case 'sortwidget' :
$id_module = post ( 'id_module' );
2018-03-24 00:19:15 +01:00
$id_record = post ( 'id_record' );
2017-08-04 16:28:16 +02:00
$location = post ( 'location' );
2018-03-24 13:02:37 +01:00
$location = empty ( $id_record ) ? 'controller_' . $location : 'editor_' . $location ;
2017-08-04 16:28:16 +02:00
2018-03-24 13:02:37 +01: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 ) . ' ORDER BY `order` ASC' );
2017-08-04 16:28:16 +02:00
2018-03-24 13:02:37 +01:00
if ( $_POST [ 'ids' ] != implode ( ',' , array_column ( $rs , 'id' ))) {
2018-03-24 00:19:15 +01:00
$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 ]));
}
2018-03-24 13:02:37 +01:00
2018-03-24 00:19:15 +01:00
$_SESSION [ 'infos' ][] = tr ( 'Posizioni widgets aggiornate!' );
}
2017-08-04 16:28:16 +02:00
break ;
case 'updatewidget' :
$id_module = post ( 'id_module' );
2018-03-24 00:19:15 +01:00
$id_record = post ( 'id_record' );
2017-08-04 16:28:16 +02:00
$location = post ( 'location' );
2018-03-24 00:19:15 +01:00
$class = post ( 'class' );
2017-08-04 16:28:16 +02:00
$id = explode ( '_' , post ( 'id' ));
2018-03-24 13:02:37 +01:00
$location = empty ( $id_record ) ? 'controller_' . $location : 'editor_' . $location ;
if ( ! empty ( $class )) {
$dbo -> query ( 'UPDATE zz_widgets SET class=' . prepare ( $class ) . ' WHERE id=' . prepare ( $id [ 1 ]));
}
2017-08-04 16:28:16 +02:00
break ;
}