2017-08-04 16:28:16 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . n . c .
*
* 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 />.
*/
2017-08-04 16:28:16 +02:00
2020-09-03 15:00:52 +02:00
use Geocoder\Provider\GoogleMaps ;
use Ivory\HttpAdapter\CurlHttpAdapter ;
use Modules\Anagrafiche\Anagrafica ;
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2020-09-03 15:00:52 +02:00
$google = setting ( 'Google Maps API key' );
2017-08-04 16:28:16 +02:00
switch ( post ( 'op' )) {
case 'delete-bulk' :
2020-09-03 15:00:52 +02:00
$id_tipo_azienda = $dbo -> fetchArray ( " SELECT idtipoanagrafica FROM an_tipianagrafiche WHERE descrizione='Azienda' " )[ 0 ][ 'idtipoanagrafica' ];
2018-06-26 14:30:26 +02:00
2019-05-16 04:52:16 +02:00
foreach ( $id_records as $id ) {
$anagrafica = $dbo -> fetchArray ( 'SELECT an_tipianagrafiche.idtipoanagrafica FROM an_tipianagrafiche INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche.idtipoanagrafica=an_tipianagrafiche_anagrafiche.idtipoanagrafica WHERE idanagrafica=' . prepare ( $id ));
$tipi = array_column ( $anagrafica , 'idtipoanagrafica' );
2018-06-26 14:30:26 +02:00
2019-05-16 04:52:16 +02:00
// Se l'anagrafica non è di tipo Azienda
2020-09-03 15:00:52 +02:00
if ( ! in_array ( $id_tipo_azienda , $tipi )) {
2019-05-16 04:52:16 +02:00
$dbo -> query ( 'UPDATE an_anagrafiche SET deleted_at = NOW() WHERE idanagrafica = ' . prepare ( $id ) . Modules :: getAdditionalsQuery ( $id_module ));
}
}
2018-06-26 14:30:26 +02:00
2019-05-16 04:52:16 +02:00
flash () -> info ( tr ( 'Anagrafiche eliminate!' ));
2017-08-04 16:28:16 +02:00
2020-09-03 15:00:52 +02:00
break ;
case 'ricerca-coordinate' :
$curl = new CurlHttpAdapter ();
$geocoder = new GoogleMaps ( $curl , null , null , true , $google );
foreach ( $id_records as $id ) {
$anagrafica = Anagrafica :: find ( $id );
if ( empty ( $anagrafica -> lat ) && empty ( $anagrafica -> lng ) && ! empty ( $anagrafica -> sedeLegale -> citta ) && ! empty ( $anagrafica -> sedeLegale -> cap )) {
2020-09-08 14:25:38 +02:00
$indirizzo = $anagrafica -> sedeLegale -> citta . ' ' . $anagrafica -> sedeLegale -> cap ;
// Ricerca indirizzo
$address = $geocoder -> geocode ( $indirizzo ) -> first ();
2020-09-03 15:00:52 +02:00
$coordinates = $address -> getCoordinates ();
2020-09-08 14:25:38 +02:00
// Salvataggio informazioni
$anagrafica -> lat = $coordinates -> getLatitude ();
$anagrafica -> lng = $coordinates -> getLongitude ();
$anagrafica -> save ();
2020-09-03 15:00:52 +02:00
}
}
2017-08-04 16:28:16 +02:00
break ;
2020-11-24 17:25:07 +01:00
case 'download-csv' :
$dir = base_dir () . '/files/export_anagrafiche/' ;
directory ( $dir . 'tmp/' );
$file = secure_random_string () . '.csv' ;
$dir_csv = slashes ( $dir . 'tmp/' . $file );
$filename = 'anagrafiche.csv' ;
$t = new Modules\Anagrafiche\Export\CSV ( $dir_csv );
if ( $t -> exportRecords ()){
download ( $dir_csv , $filename );
delete ( $dir . 'tmp/' );
}
break ;
2017-08-04 16:28:16 +02:00
}
2020-09-23 12:00:21 +02:00
$operations = [];
2019-05-13 17:01:43 +02:00
if ( App :: debug ()) {
2020-05-29 17:12:23 +02:00
$operations [ 'delete-bulk' ] = [
2020-11-24 17:25:07 +01:00
'text' => '<span><i class="fa fa-trash"></i> ' . tr ( 'Elimina selezionati' ) . '</span> <span class="label label-danger" >beta</span>' ,
2020-05-29 17:12:23 +02:00
'data' => [
'msg' => tr ( 'Vuoi davvero eliminare le anagrafiche selezionate?' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-danger' ,
],
2019-05-16 04:52:16 +02:00
];
2020-11-24 17:25:07 +01:00
$operations [ 'download-csv' ] = [
'text' => '<span><i class="fa fa-download"></i> ' . tr ( 'Esporta tutto' ) . '</span> <span class="label label-danger" >beta</span>' ,
'data' => [
'msg' => tr ( 'Vuoi davvero esportare un CSV con tutte le anagrafiche?' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-danger' ,
'blank' => true ,
],
];
2019-05-13 17:01:43 +02:00
}
2020-09-03 15:00:52 +02:00
if ( App :: debug () && $google ) {
$operations [ 'ricerca-coordinate' ] = [
'text' => '<span><i class="fa fa-map"></i> ' . tr ( 'Ricerca coordinate' ) . '</span>' ,
'data' => [
'msg' => tr ( 'Ricercare le coordinate per le anagrafiche selezionate senza latitudine e longitudine?' ),
'button' => tr ( 'Procedi' ),
'class' => 'btn btn-lg btn-warning' ,
],
];
}
2019-05-13 17:01:43 +02:00
return $operations ;