2022-11-28 09:27:25 +01:00
< ? php
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . r . l .
*
* 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 />.
*/
include_once __DIR__ . '/../../../core.php' ;
switch ( $resource ) {
case 'segmenti' :
$user = Auth :: user ();
$id_module = $superselect [ 'id_module' ];
$is_fiscale = $superselect [ 'is_fiscale' ];
$is_sezionale = $superselect [ 'is_sezionale' ];
2024-02-22 00:00:38 +01:00
$for_fe = $superselect [ 'for_fe' ];
2023-06-20 15:36:28 +02:00
$escludi_id = $superselect [ 'escludi_id' ];
2022-11-28 09:27:25 +01:00
if ( isset ( $id_module )) {
2024-03-22 15:52:24 +01:00
$query = 'SELECT `zz_segments`.`id`, `zz_segments_lang`.`name` AS descrizione FROM `zz_segments` LEFT JOIN `zz_segments_lang` ON (`zz_segments`.`id` = `zz_segments_lang`.`id_record` AND `zz_segments_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') INNER JOIN `zz_group_segment` ON `zz_segments`.`id` = `zz_group_segment`.`id_segment` |where| ORDER BY `name` ASC' ;
2022-11-28 09:27:25 +01:00
2024-03-11 10:40:42 +01:00
$where [] = '`zz_segments`.`id_module` = ' . prepare ( $id_module );
$where [] = '`zz_group_segment`.`id_gruppo` = ' . prepare ( $user -> idgruppo );
2022-11-28 09:27:25 +01:00
if ( $is_fiscale != null ) {
2024-03-11 10:40:42 +01:00
$where [] = '`zz_segments`.`is_fiscale` = ' . prepare ( $is_fiscale );
2022-11-28 09:27:25 +01:00
}
if ( $is_sezionale != null ) {
2024-03-11 10:40:42 +01:00
$where [] = '`zz_segments`.`is_sezionale` = ' . prepare ( $is_sezionale );
2022-11-28 09:27:25 +01:00
}
2024-02-22 17:03:48 +01:00
2024-02-22 00:00:38 +01:00
if ( $for_fe != null ) {
2024-03-11 10:40:42 +01:00
$where [] = '`zz_segments`.`for_fe` = ' . prepare ( $for_fe );
2024-02-22 00:00:38 +01:00
}
2022-11-28 09:27:25 +01:00
2023-06-20 15:36:28 +02:00
if ( $escludi_id != null ) {
2024-03-11 10:40:42 +01:00
$where [] = '`zz_segments`.`id` != ' . prepare ( $escludi_id );
2023-06-20 15:36:28 +02:00
}
2022-11-28 09:27:25 +01:00
foreach ( $elements as $element ) {
2024-03-11 10:40:42 +01:00
$filter [] = '`zz_segments`.`id`=' . prepare ( $element );
2022-11-28 09:27:25 +01:00
}
if ( ! empty ( $search )) {
2024-03-11 10:40:42 +01:00
$search_fields [] = '`zz_segments_lang`.`name` LIKE ' . prepare ( '%' . $search . '%' );
2022-11-28 09:27:25 +01:00
}
}
break ;
}