2018-06-01 10:20:58 +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-01 10:20:58 +02:00
include_once __DIR__ . '/../../../core.php' ;
switch ( $resource ) {
case 'anagrafiche_utenti' :
2024-03-13 11:38:29 +01:00
$query = 'SELECT `an_anagrafiche`.`idanagrafica` AS id, `an_anagrafiche`.`ragione_sociale` AS descrizione, `an_tipianagrafiche_lang`.`name` AS optgroup FROM `an_tipianagrafiche` LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche`.`id`=`an_tipianagrafiche_lang`.`id_record` AND `an_tipianagrafiche_lang`.`id_lang`=' . prepare ( \App :: getLang ()) . ') INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche`.`id`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica`=`an_tipianagrafiche_anagrafiche`.`idanagrafica` |where| ORDER BY `optgroup` ASC' ;
2018-06-26 14:30:26 +02:00
2024-02-05 17:07:33 +01:00
$where [] = '`an_anagrafiche`.`deleted_at` IS NULL' ;
2018-11-30 16:10:15 +01:00
foreach ( $elements as $element ) {
2024-02-05 17:07:33 +01:00
$filter [] = '`an_anagrafiche`.`idanagrafica`=' . prepare ( $element );
2018-11-30 16:10:15 +01:00
}
2018-06-01 10:20:58 +02:00
if ( ! empty ( $search )) {
2024-02-05 17:07:33 +01:00
$search_fields [] = '`an_anagrafiche`.`ragione_sociale` LIKE ' . prepare ( '%' . $search . '%' );
2018-06-01 10:20:58 +02:00
}
2018-06-26 14:30:26 +02:00
2018-06-01 10:20:58 +02:00
if ( ! empty ( $search_fields )) {
$where [] = '(' . implode ( ' OR ' , $search_fields ) . ')' ;
}
if ( ! empty ( $filter )) {
$where [] = '(' . implode ( ' OR ' , $filter ) . ')' ;
}
2018-06-26 14:30:26 +02:00
2018-06-01 10:20:58 +02:00
$wh = '' ;
if ( count ( $where ) != 0 ) {
$wh = 'WHERE ' . implode ( ' AND ' , $where );
}
$query = str_replace ( '|where|' , $wh , $query );
2018-06-26 14:30:26 +02:00
2018-06-01 10:20:58 +02:00
$rs = $dbo -> fetchArray ( $query );
foreach ( $rs as $r ) {
if ( $prev != $r [ 'optgroup' ]) {
$results [] = [ 'text' => $r [ 'optgroup' ], 'children' => []];
$prev = $r [ 'optgroup' ];
}
2018-06-26 14:30:26 +02:00
2018-06-01 10:20:58 +02:00
$results [ count ( $results ) - 1 ][ 'children' ][] = [
'id' => $r [ 'id' ],
'text' => $r [ 'descrizione' ],
'descrizione' => $r [ 'descrizione' ],
];
}
2019-07-26 16:24:20 +02:00
break ;
case 'utenti' :
2024-02-05 17:07:33 +01:00
$query = " SELECT `zz_users`.`id` AS id, if(`an_anagrafiche`.`idanagrafica` IS NOT NULL, CONCAT(`an_anagrafiche`.`ragione_sociale`, ' (', `zz_users`.`username`, ')'), `zz_users`.`username`) AS descrizione, `an_tipianagrafiche_lang`.`name` AS optgroup
FROM
`zz_users`
LEFT JOIN `an_anagrafiche` ON `an_anagrafiche` . `idanagrafica` = `zz_users` . `idanagrafica`
INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche` . `idanagrafica` = `an_tipianagrafiche_anagrafiche` . `idanagrafica`
INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche` . `id` = `an_tipianagrafiche_anagrafiche` . `idtipoanagrafica`
2024-03-13 11:38:29 +01:00
LEFT JOIN `an_tipianagrafiche_lang` ON ( `an_tipianagrafiche` . `id` = `an_tipianagrafiche_lang` . `id_record` AND `an_tipianagrafiche_lang` . `id_lang` = " .prepare( \ App::getLang()).')
2024-02-05 17:07:33 +01:00
| where |
ORDER BY
`optgroup` ASC ' ;
$where [] = '`an_anagrafiche`.`deleted_at` IS NULL' ;
2019-07-26 16:24:20 +02:00
foreach ( $elements as $element ) {
2024-02-05 17:07:33 +01:00
$filter [] = '`zz_users`.`id`=' . prepare ( $element );
2019-07-26 16:24:20 +02:00
}
if ( ! empty ( $search )) {
2024-02-05 17:07:33 +01:00
$search_fields [] = '`an_anagrafiche`.`ragione_sociale` LIKE ' . prepare ( '%' . $search . '%' );
$search_fields [] = '`zz_users`.`username` LIKE ' . prepare ( '%' . $search . '%' );
2019-07-26 16:24:20 +02:00
}
if ( ! empty ( $search_fields )) {
$where [] = '(' . implode ( ' OR ' , $search_fields ) . ')' ;
}
if ( ! empty ( $filter )) {
$where [] = '(' . implode ( ' OR ' , $filter ) . ')' ;
}
$wh = '' ;
if ( count ( $where ) != 0 ) {
$wh = 'WHERE ' . implode ( ' AND ' , $where );
}
$query = str_replace ( '|where|' , $wh , $query );
$rs = $dbo -> fetchArray ( $query );
foreach ( $rs as $r ) {
if ( $prev != $r [ 'optgroup' ]) {
$results [] = [ 'text' => $r [ 'optgroup' ], 'children' => []];
$prev = $r [ 'optgroup' ];
}
$results [ count ( $results ) - 1 ][ 'children' ][] = [
'id' => $r [ 'id' ],
'text' => $r [ 'descrizione' ],
'descrizione' => $r [ 'descrizione' ],
];
}
2022-08-29 17:48:19 +02:00
break ;
2023-08-04 14:54:28 +02:00
2023-03-07 19:15:02 +01:00
case 'gruppi' :
2024-03-13 17:32:07 +01:00
$query = 'SELECT `zz_groups`.`id`, `zz_groups_lang`.`name` AS descrizione FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON `zz_groups`.`id`=`zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang`=' . prepare ( \App :: getLang ()) . ' |where| ORDER BY `name`' ;
2023-03-07 19:15:02 +01:00
foreach ( $elements as $element ) {
2024-03-12 16:39:34 +01:00
$filter [] = '`zz_groups`.`id`=' . prepare ( $element );
2023-03-07 19:15:02 +01:00
}
if ( ! empty ( $search )) {
2024-03-13 17:32:07 +01:00
$search_fields [] = '`zz_groups_lang`.`name` LIKE ' . prepare ( '%' . $search . '%' );
2023-03-07 19:15:02 +01:00
}
break ;
2022-08-29 17:48:19 +02:00
case 'moduli_gruppo' :
2024-03-13 11:38:29 +01:00
$query = 'SELECT `zz_modules`.`id`, `zz_modules_lang`.`title` AS descrizione FROM `zz_modules` LEFT JOIN `zz_modules_lang` ON `zz_modules`.`id`=`zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang`=' . prepare ( \App :: getLang ()) . ' LEFT JOIN `zz_permissions` ON `zz_permissions`.`idmodule`=`zz_modules`.`id` |where| GROUP BY `zz_modules`.`id` ORDER BY `title`' ;
2022-08-29 17:48:19 +02:00
2024-03-05 16:01:45 +01:00
$where [] = '`zz_modules`.`enabled`=1' ;
2022-08-29 17:48:19 +02:00
2023-08-04 14:54:28 +02:00
if ( isset ( $superselect [ 'idgruppo' ]) && $superselect [ 'idgruppo' ] != 1 ) {
2024-03-05 16:01:45 +01:00
$where [] = '`zz_permissions`.`idgruppo`=' . prepare ( $superselect [ 'idgruppo' ]);
2022-08-29 17:48:19 +02:00
}
2023-08-04 14:54:28 +02:00
2022-08-29 17:48:19 +02:00
foreach ( $elements as $element ) {
2024-03-05 16:01:45 +01:00
$filter [] = '`zz_modules`.`id`=' . prepare ( $element );
2022-08-29 17:48:19 +02:00
}
if ( ! empty ( $search )) {
2024-03-05 16:01:45 +01:00
$search_fields [] = '`zz_modules_lang`.`title` LIKE ' . prepare ( '%' . $search . '%' );
2022-08-29 17:48:19 +02:00
}
2018-06-01 10:20:58 +02:00
break ;
}