Aggiunta tabella zz_groups_lang

This commit is contained in:
Pek5892 2024-03-12 16:39:34 +01:00
parent c7720101b9
commit 5ff6d4c427
24 changed files with 157 additions and 70 deletions

View File

@ -27,7 +27,7 @@ echo '
<p>'.tr('Trascina le colonne per ordinare la struttura della tabella principale, seleziona e deseleziona le colonne per renderle visibili o meno').'.</p>
<div class="sortable">';
$fields = $dbo->fetchArray('SELECT *, (SELECT GROUP_CONCAT(`zz_groups`.`nome`) FROM `zz_group_view` INNER JOIN `zz_groups` ON `zz_group_view`.`id_gruppo` = `zz_groups`.`id` WHERE `zz_group_view`.`id_vista` = `zz_views`.`id`) AS gruppi_con_accesso FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($id_module).' ORDER BY `order` ASC');
$fields = $dbo->fetchArray('SELECT *, (SELECT GROUP_CONCAT(`zz_groups_lang`.`name`) FROM `zz_group_view` INNER JOIN `zz_groups` ON `zz_group_view`.`id_gruppo` = `zz_groups`.`id` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `zz_group_view`.`id_vista` = `zz_views`.`id`) AS gruppi_con_accesso FROM `zz_views` LEFT JOIN `zz_views_lang` ON (`zz_views`.`id` = `zz_views_lang`.`id_record` AND `zz_views_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `id_module`='.prepare($id_module).' ORDER BY `order` ASC');
foreach ($fields as $field) {
echo '
<div class="panel panel-default clickable col-md-4" data-id="'.$field['id'].'">

View File

@ -22,6 +22,7 @@ include_once __DIR__.'/../../core.php';
use Modules\Anagrafiche\Tipo;
use Models\Module;
use Models\Setting;
use Models\Group;
if (Update::isUpdateAvailable() || !$dbo->isInstalled()) {
return;
@ -88,9 +89,7 @@ if (post('action') == 'init') {
// Utente amministratore
if (!$has_user) {
$admin = $dbo->selectOne('zz_groups', ['id'], [
'nome' => 'Amministratori',
]);
$admin = Group::where('nome', '=', 'Amministratori')->first();
// Creazione utente Amministratore
$dbo->insert('zz_users', [

View File

@ -18,6 +18,7 @@
*/
use Models\Module;
use Models\Group;
if (in_array($id_cliente, $tipi_anagrafica) or in_array($id_fornitore, $tipi_anagrafica)) {
echo '
@ -31,7 +32,7 @@ if (in_array($id_cliente, $tipi_anagrafica) or in_array($id_fornitore, $tipi_ana
// Aggiunta utente per i tecnici
if (in_array($id_tecnico, $tipi_anagrafica)) {
echo '
<li><a data-toggle="modal" data-title="'.tr('Aggiungi utente').'" data-href="modules/utenti/user.php?id_module='.(new Module())->getByName('Utenti e permessi')->id_record.'&id_record='.$dbo->fetchOne('SELECT id FROM zz_groups WHERE nome=\'Tecnici\'')['id'].'&idanagrafica='.$record['idanagrafica'].'"><i class="fa fa-user"></i>'.tr('Nuovo utente').'
<li><a data-toggle="modal" data-title="'.tr('Aggiungi utente').'" data-href="modules/utenti/user.php?id_module='.(new Module())->getByName('Utenti e permessi')->id_record.'&id_record='.(new Group())->getByName('Tecnici')->id_record.'&idanagrafica='.$record['idanagrafica'].'"><i class="fa fa-user"></i>'.tr('Nuovo utente').'
</a></li>';
}

View File

@ -37,7 +37,7 @@ if ($record['doc_associati'] > 0) {
</div>
<div class="col-md-3">
{[ "type": "select", "label": "<?php echo tr('Gruppi abilitati'); ?>", "name": "permessi[]", "value": "$permessi$", "values": "query=SELECT `id`, `nome` AS text FROM `zz_groups`", "multiple": 1 ]}
{[ "type": "select", "label": "<?php echo tr('Gruppi abilitati'); ?>", "name": "permessi[]", "value": "$permessi$", "values": "query=SELECT `zz_groups`.`id`, `zz_groups_lang`.`name` AS text FROM `zz_groups`", "multiple": 1 ]}
</div>
</div>
</form>

View File

@ -22,6 +22,7 @@ namespace Modules\CategorieDocumentali;
use Common\SimpleModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Models\Group;
class Categoria extends Model
{
@ -35,7 +36,7 @@ class Categoria extends Model
$model = new static();
$model->save();
$gruppi = database()->fetchArray('SELECT `id` FROM `zz_groups`');
$gruppi = Group::get();
$model->syncPermessi(array_column($gruppi, 'id'));
return $model;

View File

@ -56,7 +56,7 @@ echo '
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT id, nome AS text FROM zz_groups" ]}
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT `zz_groups`.`id`, `name` AS text FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(setting('Lingua')).')" ]}
</div>
<div class="col-md-6">

View File

@ -44,7 +44,7 @@ echo '
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT id, nome AS text FROM zz_groups" ]}
{[ "type": "select", "label": "'.tr('Gruppo assegnato').'", "name": "group_id", "values": "query=SELECT `zz_groups`.`id`, `name` AS text FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(setting('Lingua')).')" ]}
</div>
</div>

View File

@ -18,6 +18,7 @@
*/
include_once __DIR__.'/../../core.php';
use Models\Group;
switch (post('op')) {
case 'update':
@ -101,11 +102,11 @@ switch (post('op')) {
]);
// Aggiunta permessi segmento
$gruppi = $dbo->fetchArray('SELECT `id` FROM `zz_groups`');
$gruppi = Group::get();
$array = [];
foreach ($gruppi as $gruppo) {
$array[] = [
'id_gruppo' => $gruppo['id'],
'id_gruppo' => $gruppo->id,
'id_segment' => $id_record,
];
}

View File

@ -37,7 +37,7 @@ $operations['set_groups'] = [
'text' => '<span><i class="fa fa-users"></i> '.tr('Imposta l\'accesso ai segmenti').'</span>',
'data' => [
'title' => tr('Imposta l\'accesso ai segmenti.'),
'msg' => '{[ "type": "select", "multiple":"1", "label": "<small>'.tr('Seleziona i gruppi che avranno accesso ai segmenti selezionati:').'</small>", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "name": "gruppi[]" ]}',
'msg' => '{[ "type": "select", "multiple":"1", "label": "<small>'.tr('Seleziona i gruppi che avranno accesso ai segmenti selezionati:').'</small>", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC", "name": "gruppi[]" ]}',
'button' => tr('Procedi'),
'class' => 'btn btn-lg btn-warning',
'blank' => false,

View File

@ -103,8 +103,8 @@ $_SESSION['module_'.$record['id_module']]['id_segment'] = $previous_module;
echo '
<div class="row">
<div class="col-md-12">
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi[]", "multiple": "1", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "value": "';
$results = $dbo->fetchArray('SELECT GROUP_CONCAT(DISTINCT id_gruppo SEPARATOR \',\') AS gruppi FROM zz_group_segment WHERE id_segment='.prepare($id_record));
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi[]", "multiple": "1", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC", "value": "';
$results = $dbo->fetchArray('SELECT GROUP_CONCAT(DISTINCT `id_gruppo` SEPARATOR \',\') AS gruppi FROM `zz_group_segment` WHERE `id_segment`='.prepare($id_record));
echo $results[0]['gruppi'].'"';

View File

@ -21,6 +21,7 @@ include_once __DIR__.'/../../core.php';
use Models\User;
use Models\Module;
use Models\Group;
$id_utente = filter('id_utente');
@ -32,15 +33,12 @@ switch (filter('op')) {
$theme = filter('theme') ?: null;
// Verifico che questo nome gruppo non sia già stato usato
if ($dbo->fetchNum('SELECT nome FROM zz_groups WHERE nome='.prepare($nome)) == 0) {
$dbo->insert('zz_groups', [
'nome' => $nome,
'id_module_start' => $id_module_start,
'theme' => $theme,
'editable' => 1,
]);
if ((new Group())->getByName($nome)->id_record == null) {
$group = Group::build($nome, $theme, $id_module_start);
$id_record = $dbo->lastInsertedID();
$group->editable = 1;
$group->name = $nome;
$group->save();
if ($id_module_start) {
$dbo->insert('zz_permissions', [
@ -58,14 +56,14 @@ switch (filter('op')) {
// Abilita utente
case 'enable_user':
if ($dbo->query('UPDATE zz_users SET enabled=1 WHERE id='.prepare($id_utente))) {
if ($dbo->query('UPDATE `zz_users` SET `enabled`=1 WHERE `id`='.prepare($id_utente))) {
flash()->info(tr('Utente abilitato!'));
}
break;
// Disabilita utente
case 'disable_user':
if ($dbo->query('UPDATE zz_users SET enabled=0 WHERE id='.prepare($id_utente))) {
if ($dbo->query('UPDATE `zz_users` SET `enabled`=0 WHERE `id`='.prepare($id_utente))) {
flash()->info(tr('Utente disabilitato!'));
}
break;
@ -77,7 +75,7 @@ switch (filter('op')) {
$password = $_POST['password'];
$id_utente = filter('id_utente');
if ($dbo->fetchNum('SELECT username FROM zz_users WHERE id != '.prepare($id_utente).' AND username='.prepare($username)) == 0) {
if ($dbo->fetchNum('SELECT `username` FROM `zz_users` WHERE `id` != '.prepare($id_utente).' AND `username`='.prepare($username)) == 0) {
// Aggiunta/modifica utente
if (!empty($id_utente)) {
$utente = User::find($id_utente);
@ -222,14 +220,14 @@ switch (filter('op')) {
// Elimina gruppo
case 'deletegroup':
// Verifico se questo gruppo si può eliminare
$query = 'SELECT editable FROM zz_groups WHERE id='.prepare($id_record);
$query = 'SELECT `editable` FROM `zz_groups` WHERE `id`='.prepare($id_record);
$rs = $dbo->fetchArray($query);
if ($rs[0]['editable'] == 1) {
if ($dbo->query('DELETE FROM zz_groups WHERE id='.prepare($id_record))) {
$dbo->query('DELETE FROM zz_users WHERE idgruppo='.prepare($id_record));
$dbo->query('DELETE FROM zz_tokens WHERE id_utente IN (SELECT id FROM zz_users WHERE idgruppo='.prepare($id_record).')');
$dbo->query('DELETE FROM zz_permissions WHERE idgruppo='.prepare($id_record));
if ($dbo->query('DELETE FROM `zz_groups` WHERE `id`='.prepare($id_record))) {
$dbo->query('DELETE FROM `zz_users` WHERE `idgruppo`='.prepare($id_record));
$dbo->query('DELETE FROM `zz_tokens` WHERE `id_utente` IN (SELECT `id` FROM `zz_users` WHERE `idgruppo`='.prepare($id_record).')');
$dbo->query('DELETE FROM `zz_permissions` WHERE `idgruppo`='.prepare($id_record));
flash()->info(tr('Gruppo e relativi utenti eliminati!'));
}
} else {
@ -302,22 +300,15 @@ switch (filter('op')) {
break;
case 'update_id_module_start':
$dbo->update('zz_groups', [
'id_module_start' => filter('id_module_start'),
], ['id' => $id_record]);
ob_end_clean();
echo 'ok';
$group->id_module_start = filter('id_module_start');
$group->save();
flash()->info(tr('Modulo aggiornato!'));
break;
case 'update_theme':
$dbo->update('zz_groups', [
'theme' => filter('theme'),
], ['id' => $id_record]);
ob_end_clean();
echo 'ok';
$group->theme = filter('theme');
$group->save();
flash()->info(tr('Tema aggiornato!'));
break;
}

View File

@ -117,13 +117,13 @@ switch ($resource) {
break;
case 'gruppi':
$query = 'SELECT zz_groups.id, zz_groups.nome AS descrizione FROM zz_groups |where| ORDER BY descrizione';
$query = 'SELECT `zz_groups`.`id`, `zz_groups`.`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(setting('Lingua')).' |where| ORDER BY `name`';
foreach ($elements as $element) {
$filter[] = 'zz_groups.id='.prepare($element);
$filter[] = '`zz_groups`.`id`='.prepare($element);
}
if (!empty($search)) {
$search_fields[] = 'zz_groups.nome LIKE '.prepare('%'.$search.'%');
$search_fields[] = '`zz_groups`.`name` LIKE '.prepare('%'.$search.'%');
}
break;

View File

@ -19,11 +19,12 @@
include_once __DIR__.'/../../core.php';
use Models\Module;
use Models\Group;
if (!empty(filter('idanagrafica'))) {
$utente['id_anagrafica'] = filter('idanagrafica');
} else {
$current_idgruppo = $dbo->fetchOne('SELECT `id` FROM `zz_groups` WHERE `id` = '.prepare($id_record))['id'];
$current_idgruppo = Group::find($id_record)->id;
}
echo '

View File

@ -25,17 +25,17 @@ echo '
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">'.tr('Utenti del gruppo: _GROUP_', [
'_GROUP_' => $record['nome'],
'_GROUP_' => $group->name,
]).'</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-3 pull-right">
{["type":"select", "label":"'.tr('Modulo iniziale').'", "name":"id_module_start", "ajax-source":"moduli_gruppo", "select-options": '.json_encode(['idgruppo' => $record['id']]).', "placeholder":"'.tr('Modulo iniziale').'", "value":"'.$record['id_module_start'].'" ]}
{["type":"select", "label":"'.tr('Modulo iniziale').'", "name":"id_module_start", "ajax-source":"moduli_gruppo", "select-options": '.json_encode(['idgruppo' => $group->id]).', "placeholder":"'.tr('Modulo iniziale').'", "value":"'.$group->id_module_start.'" ]}
</div>
<div class="col-md-3 pull-right">
{["type":"select", "label":"'.tr('Tema').'", "name":"theme", "values":"list=\"\": \"'.tr('Predefinito').'\",\"black-light\": \"'.tr('Bianco').'\",\"black\": \"'.tr('Nero').'\",\"red-light\": \"'.tr('Rosso chiaro').'\",\"red\": \"'.tr('Rosso').'\",\"blue-light\": \"'.tr('Blu chiaro').'\",\"blue\": \"'.tr('Blu').'\",\"green-light\": \"'.tr('Verde chiaro').'\",\"green\": \"'.tr('Verde').'\",\"yellow-light\": \"'.tr('Giallo chiaro').'\",\"yellow\": \"'.tr('Giallo').'\",\"purple-light\": \"'.tr('Viola chiaro').'\",\"purple\": \"'.tr('Viola').'\" ", "value":"'.$record['theme'].'" ]}
{["type":"select", "label":"'.tr('Tema').'", "name":"theme", "values":"list=\"\": \"'.tr('Predefinito').'\",\"black-light\": \"'.tr('Bianco').'\",\"black\": \"'.tr('Nero').'\",\"red-light\": \"'.tr('Rosso chiaro').'\",\"red\": \"'.tr('Rosso').'\",\"blue-light\": \"'.tr('Blu chiaro').'\",\"blue\": \"'.tr('Blu').'\",\"green-light\": \"'.tr('Verde chiaro').'\",\"green\": \"'.tr('Verde').'\",\"yellow-light\": \"'.tr('Giallo chiaro').'\",\"yellow\": \"'.tr('Giallo').'\",\"purple-light\": \"'.tr('Viola chiaro').'\",\"purple\": \"'.tr('Viola').'\" ", "value":"'.$group->theme.'" ]}
</div>
</div>
<br>';

View File

@ -18,7 +18,10 @@
*/
include_once __DIR__.'/../../core.php';
use Models\Group;
if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM `zz_groups` WHERE `id`='.prepare($id_record));
$record = $dbo->fetchOne('SELECT * FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = '.prepare(setting('Lingua')).') WHERE `zz_groups`.`id`='.prepare($id_record));
$group = Group::find($id_record);
}

View File

@ -82,8 +82,8 @@ foreach ($fields as $key => $field) {
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi['.$key.'][]", "multiple": "1", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "value": "';
$results = $dbo->fetchArray('SELECT GROUP_CONCAT(DISTINCT id_gruppo SEPARATOR \',\') AS gruppi FROM zz_group_view WHERE id_vista='.prepare($field['id']));
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi['.$key.'][]", "multiple": "1", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC", "value": "';
$results = $dbo->fetchArray('SELECT GROUP_CONCAT(DISTINCT `id_gruppo` SEPARATOR \',\') AS gruppi FROM `zz_group_view` WHERE `id_vista`='.prepare($field['id']));
echo $results[0]['gruppi'].'"';
@ -202,7 +202,7 @@ echo '
<div class="row">
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi[-id-][]", "multiple": "1", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC" ]}
{[ "type": "select", "label": "'.tr('Gruppi con accesso').'", "name": "gruppi[-id-][]", "multiple": "1", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC" ]}
</div>
<div class="col-md-6">

View File

@ -78,7 +78,7 @@ if (!empty($additionals)) {
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo['.$num.']", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "value": "'.$additional['idgruppo'].'", "readonly": '.intval(!$editable).' ]}
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo['.$num.']", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC", "value": "'.$additional['idgruppo'].'", "readonly": '.intval(!$editable).' ]}
</div>
<div class="col-md-3">
@ -135,7 +135,7 @@ echo '
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo[-id-]", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC" ]}
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo[-id-]", "values": "query=SELECT `zz_groups`.`id`, `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(setting('Lingua')).') ORDER BY `zz_groups`.`id` ASC" ]}
</div>
<div class="col-md-3">

View File

@ -38,10 +38,11 @@ class Login extends Resource implements CreateInterface
$utente = $database->fetchOne('SELECT
`an_anagrafiche`.`idanagrafica` AS id_anagrafica,
`an_anagrafiche`.`ragione_sociale`,
`zz_groups`.`nome` AS gruppo
`zz_groups_lang`.`name` AS gruppo
FROM `zz_users`
INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
INNER JOIN `zz_groups` ON `zz_users`.`idgruppo`=`zz_groups`.`id`
LEFT JOIN `zz_groups_lang` ON (`zz_groups_lang`.`id_record` = `zz_groups`.`id` AND `zz_groups_lang`.`id_lang` = '.prepare(setting('Lingua')).')
WHERE `an_anagrafiche`.`deleted_at` IS NULL AND `zz_users`.`id` = :id', [
':id' => $user['id'],
]);
@ -49,13 +50,14 @@ class Login extends Resource implements CreateInterface
$utente = $database->fetchOne('SELECT
`an_anagrafiche`.`idanagrafica` AS id_anagrafica,
`an_anagrafiche`.`ragione_sociale`,
`zz_groups`.`nome` AS gruppo
`zz_groups_lang`.`name` AS gruppo
FROM `zz_users`
INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idanagrafica` = `an_anagrafiche`.`idanagrafica`
INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche`.`idtipoanagrafica` = `an_tipianagrafiche`.`id`
LEFT JOIN `an_tipianagrafiche_lang` ON (`an_tipianagrafiche_lang`.`id_record` = `an_tipianagrafiche`.`id` AND `an_tipianagrafiche_lang`.`id_lang` = '.prepare(setting('Lingua')).")
INNER JOIN `zz_groups` ON `zz_users`.`idgruppo`=`zz_groups`.`id`
LEFT JOIN `zz_groups_lang` ON (`zz_groups_lang`.`id_record` = `zz_groups`.`id` AND `zz_groups_lang`.`id_lang` = ".prepare(setting('Lingua')).")
WHERE `an_tipianagrafiche_lang`.`name` = 'Tecnico' AND `an_anagrafiche`.`deleted_at` IS NULL AND `id` = :id", [
':id' => $user['id'],
]);

View File

@ -19,6 +19,7 @@
use API\Response as API;
use Models\User;
use Models\Group;
/**
* Classe per la gestione delle utenze.
@ -130,9 +131,8 @@ class Auth extends Util\Singleton
if (!empty($user['enabled'])) {
$this->identifyUser($user['id']);
$gruppo = $database->fetchOne('SELECT zz_groups.* FROM zz_groups INNER JOIN zz_users ON zz_users.idgruppo=zz_groups.id WHERE zz_users.id='.prepare($user['id']));
$module = $gruppo['id_module_start'];
$gruppo = Group::join('zz_users', 'zz_users.idgruppo', '=', 'zz_groups.id')->where('zz_users.id', '=', $user['id'])->first();
$module = $gruppo->id_module_start;
$module = $this->getFirstModule($module);
if ($force) {
@ -265,9 +265,9 @@ class Auth extends Util\Singleton
$query = 'SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `enabled` = 1';
if (!$this->isAdmin()) {
$query .= " AND `id` IN (SELECT `idmodule` FROM `zz_permissions` WHERE `idgruppo` = (SELECT `id` FROM `zz_groups` WHERE `nome` = :group) AND `permessi` IN ('r', 'rw'))";
$group = $this->getUser()['gruppo'];
$parameters[':group'] = $this->getUser()['gruppo'];
$query .= " AND `id` IN (SELECT `idmodule` FROM `zz_permissions` WHERE `idgruppo` = ".(new Group())->getByName($group)->id_record." AND `permessi` IN ('r', 'rw'))";
}
$database = database();
@ -475,7 +475,7 @@ class Auth extends Util\Singleton
$database = database();
try {
$results = $database->fetchArray('SELECT id, idanagrafica, username, (SELECT nome FROM zz_groups WHERE zz_groups.id = zz_users.idgruppo) AS gruppo FROM zz_users WHERE id = :user_id AND enabled = 1 LIMIT 1', [
$results = $database->fetchArray('SELECT `id`, `idanagrafica`, `username`, (SELECT `name` FROM `zz_groups` LEFT JOIN `zz_groups_lang` ON `zz_groups`.`id`=`zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang`='.setting('Lingua').' WHERE `zz_groups`.`id` = `zz_users`.`idgruppo`) AS gruppo FROM `zz_users` WHERE `id` = :user_id AND `enabled` = 1 LIMIT 1', [
':user_id' => $user_id,
]);

View File

@ -28,6 +28,18 @@ class Group extends Model
protected $table = 'zz_groups';
public static function build($nome, $theme, $id_module_start)
{
$model = new static();
$model->nome = $nome;
$model->theme = $theme;
$model->id_module_start = $id_module_start;
$model->save();
return $model;
}
/* Relazioni Eloquent */
public function users()
@ -44,4 +56,58 @@ class Group extends Model
{
return $this->belongsToMany(View::class, 'zz_group_view', 'id_gruppo', 'id_vista');
}
/**
* Ritorna l'attributo name del gruppo.
*
* @return string
*/
public function getNameAttribute()
{
return database()->table($this->table.'_lang')
->select('name')
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'))
->first()->name;
}
/**
* Imposta l'attributo name del gruppo.
*/
public function setNameAttribute($value)
{
$table = database()->table($this->table.'_lang');
$translated = $table
->where('id_record', '=', $this->id)
->where('id_lang', '=', setting('Lingua'));
if ($translated->count() > 0) {
$translated->update([
'name' => $value
]);
} else {
$table->insert([
'id_record' => $this->id,
'id_lang' => setting('Lingua'),
'name' => $value
]);
}
}
/**
* Ritorna l'id del gruppo a partire dal nome.
*
* @param string $name il nome da ricercare
*
* @return \Illuminate\Support\Collection
*/
public function getByName($name)
{
return database()->table($this->table.'_lang')
->select('id_record')
->where('name', '=', $name)
->where('id_lang', '=', setting('Lingua'))
->first();
}
}

View File

@ -21,6 +21,7 @@ use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem;
use Models\Cache;
use Models\Setting;
use Models\Group;
/**
* Classe dedicata alla gestione delle procedure di aggiornamento del database del progetto.
@ -287,7 +288,7 @@ class Update
// Permessi di default delle viste
if ($database->tableExists('zz_views')) {
$gruppi = $database->fetchArray('SELECT `id` FROM `zz_groups`');
$gruppi = Group::get()->toArray();
$viste = $database->fetchArray('SELECT `id` FROM `zz_views` WHERE `id` NOT IN (SELECT `id_vista` FROM `zz_group_view`)');
$array = [];
@ -306,7 +307,7 @@ class Update
// Permessi di default dei segmenti
if ($database->tableExists('zz_segments')) {
$gruppi = $database->fetchArray('SELECT `id` FROM `zz_groups`');
$gruppi = Group::get()->toArray();
$segments = $database->fetchArray('SELECT `id` FROM `zz_segments` WHERE `id` NOT IN (SELECT `id_segment` FROM `zz_group_segment`)');
$array = [];

View File

@ -18,6 +18,7 @@
*/
include_once __DIR__.'/../../core.php';
use Modules\Anagrafiche\Anagrafica;
$search_targa = get('search_targa');
$search_nome = get('search_nome');
@ -40,13 +41,14 @@ $query = "
`mg_movimenti`.`idutente`,
`zz_users`.`username`,
`mg_articoli`.`um`,
`zz_groups`.`nome` as gruppo
`zz_groups_lang`.`name` as gruppo
FROM
`mg_movimenti`
INNER JOIN `mg_articoli` ON `mg_movimenti`.`idarticolo`=`mg_articoli`.`id`
INNER JOIN `co_iva` ON `mg_articoli`.`idiva_vendita` = `co_iva`.`id`
INNER JOIN `zz_users` ON `mg_movimenti`.'idutente'=`zz_users`.'id'
INNER JOIN `zz_groups` ON 'zz_users'.`idgruppo`=`zz_groups`.`id`
LEFT JOIN `zz_groups_lang` ON (`zz_groups`.`id` = `zz_groups_lang`.`id_record` AND `zz_groups_lang`.`id_lang` = ".prepare(setting('Lingua')).")
INNER JOIN `an_sedi` ON `mg_movimenti`.`idsede`=`an_sedi`.`id`
LEFT JOIN `co_iva_lang` ON (`co_iva`.`id` = `co_iva_lang`.`id_record` AND `co_iva_lang`.`id_lang` = ".prepare(setting('Lingua')).")
LEFT JOIN `mg_categorie` ON `mg_categorie`.`id`=`mg_articoli`.`id_sottocategoria`
@ -54,11 +56,11 @@ $query = "
LEFT JOIN `mg_articoli_lang` ON (`mg_articoli`.`id`=`mg_articoli_lang`.`id_record` AND `mg_articoli_lang`.`id_lang` = ".prepare(setting('Lingua')).")
WHERE
`mg_movimenti`.`qta`>0 AND (`mg_movimenti`.`idsede` > 0) AND (`mg_movimenti`.`idintervento` IS NULL) AND
((`mg_movimenti`.`data` BETWEEN ".prepare($startTM)." AND ".prepare($endTM).") AND (`zz_groups`.`nome` IN ('Amministratori')))";
((`mg_movimenti`.`data` BETWEEN ".prepare($startTM)." AND ".prepare($endTM).") AND (`zz_groups_lang`.`name` = 'Amministratori'))";
$query .= ' AND (`an_sedi`.`targa` LIKE '.prepare('%'.$search_targa.'%').') AND (`an_sedi`.`nome` LIKE '.prepare('%'.$search_nome.'%').') ';
$query .= ' ORDER BY `an_sedi`.`targa`, `mg_articoli`.`descrizione`';
$rs = $dbo->fetchArray($query);
$totrows = sizeof($rs);
$azienda = $dbo->fetchOne('SELECT * FROM `an_anagrafiche` WHERE `idanagrafica`='.prepare(setting('Azienda predefinita')));
$azienda = Anagrafica::where('id', setting('Azienda predefinita'))->first();

View File

@ -2248,3 +2248,21 @@ ALTER TABLE `zz_hooks`
DROP `name`;
ALTER TABLE `zz_hooks_lang` ADD CONSTRAINT `zz_hooks_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `zz_hooks`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
-- Aggiunta tabella zz_groups_lang
CREATE TABLE IF NOT EXISTS `zz_groups_lang` (
`id` int NOT NULL,
`id_lang` int NOT NULL,
`id_record` int NOT NULL,
`name` VARCHAR(255) NOT NULL
);
ALTER TABLE `zz_groups_lang`
ADD PRIMARY KEY (`id`);
ALTER TABLE `zz_groups_lang`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
INSERT INTO `zz_groups_lang` (`id`, `id_lang`, `id_record`, `name`) SELECT NULL, (SELECT `id` FROM `zz_langs` WHERE `iso_code` = 'it'), `id`, `nome` FROM `zz_groups`;
ALTER TABLE `zz_groups_lang` ADD CONSTRAINT `zz_groups_lang_ibfk_1` FOREIGN KEY (`id_record`) REFERENCES `zz_groups`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;

View File

@ -166,6 +166,7 @@ return [
'zz_files',
'zz_files_print',
'zz_groups',
'zz_groups_lang',
'zz_group_module',
'zz_group_segment',
'zz_group_view',