openstamanager/modules/utenti/ajax/select.php

145 lines
5.5 KiB
PHP
Raw Normal View History

<?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/>.
*/
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'anagrafiche_utenti':
2019-07-26 16:24:20 +02:00
$query = 'SELECT `an_anagrafiche`.`idanagrafica` AS id, `an_anagrafiche`.`ragione_sociale` AS descrizione, `an_tipianagrafiche`.`descrizione` AS optgroup FROM `an_tipianagrafiche` INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche`.`idtipoanagrafica`=`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
$where[] = 'an_anagrafiche.deleted_at IS NULL';
2018-11-30 16:10:15 +01:00
foreach ($elements as $element) {
$filter[] = 'an_anagrafiche.idanagrafica='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'an_anagrafiche.ragione_sociale LIKE '.prepare('%'.$search.'%');
}
2018-06-26 14:30:26 +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
$wh = '';
if (count($where) != 0) {
$wh = 'WHERE '.implode(' AND ', $where);
}
$query = str_replace('|where|', $wh, $query);
2018-06-26 14:30:26 +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
$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':
$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`.`descrizione` AS optgroup
2020-09-07 15:04:06 +02:00
FROM zz_users
2019-07-26 16:24:20 +02:00
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`.`idtipoanagrafica`=`an_tipianagrafiche_anagrafiche`.`idtipoanagrafica`
|where| ORDER BY `optgroup` ASC";
$where[] = 'an_anagrafiche.deleted_at IS NULL';
foreach ($elements as $element) {
$filter[] = 'zz_users.id='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'an_anagrafiche.ragione_sociale LIKE '.prepare('%'.$search.'%');
$search_fields[] = 'zz_users.username LIKE '.prepare('%'.$search.'%');
}
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
case 'gruppi':
2023-08-04 14:54:28 +02:00
$query = 'SELECT zz_groups.id, zz_groups.nome AS descrizione FROM zz_groups |where| ORDER BY descrizione';
foreach ($elements as $element) {
$filter[] = 'zz_groups.id='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'zz_groups.nome LIKE '.prepare('%'.$search.'%');
}
break;
2022-08-29 17:48:19 +02:00
case 'moduli_gruppo':
2023-08-04 14:54:28 +02:00
$query = 'SELECT zz_modules.id, zz_modules.title AS descrizione FROM zz_modules LEFT JOIN zz_permissions ON zz_permissions.idmodule=zz_modules.id |where| GROUP BY id ORDER BY descrizione';
2022-08-29 17:48:19 +02:00
$where[] = 'zz_modules.enabled=1';
2023-08-04 14:54:28 +02:00
if (isset($superselect['idgruppo']) && $superselect['idgruppo'] != 1) {
2022-08-29 17:48:19 +02:00
$where[] = 'zz_permissions.idgruppo='.prepare($superselect['idgruppo']);
}
2023-08-04 14:54:28 +02:00
2022-08-29 17:48:19 +02:00
foreach ($elements as $element) {
$filter[] = 'zz_modules.id='.prepare($element);
}
if (!empty($search)) {
2023-02-09 17:24:34 +01:00
$search_fields[] = 'zz_modules.title LIKE '.prepare('%'.$search.'%');
2022-08-29 17:48:19 +02:00
}
break;
}