openstamanager/modules/stato_servizi/elenco-sessioni.php

98 lines
3.7 KiB
PHP
Raw Normal View History

<?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';
2024-03-22 15:52:24 +01:00
if (setting('Attiva notifica di presenza utenti sul record')) {
echo '
<table class="table table-hover table-condensed">
<thead>
<tr>
2024-02-23 13:14:38 +01:00
<th>'.tr('Modulo').'</th>
<th>'.tr('Record').'</th>
<th>'.tr('Data e ora accesso').'</th>
<th>'.tr('Ultimo aggiornamento').'</th>
<!--th>'.tr('Permanenza').'</th-->
</tr>
</thead>';
2024-03-22 15:52:24 +01:00
$sessioni = $dbo->fetchArray('SELECT
2024-03-05 16:01:45 +01:00
`zz_semaphores`.*,
SUBSTRING_INDEX(`posizione`, ",", -1) AS id_record,
2024-04-18 17:44:05 +02:00
`zz_modules_lang`.`title` AS modulo,
2024-03-05 16:01:45 +01:00
TIMESTAMPDIFF(SECOND, `zz_semaphores`.`created_at`, `zz_semaphores`.`updated`) AS permanenza,
`zz_users`.`username` AS utente
FROM
`zz_semaphores`
INNER JOIN `zz_modules` ON SUBSTRING_INDEX(`posizione`, ",", 1) = `zz_modules`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-03-05 16:01:45 +01:00
INNER JOIN `zz_users` ON `zz_semaphores`.`id_utente` = `zz_users`.`id`
ORDER BY
`utente` ASC, SUBSTRING_INDEX(`posizione`, ",", -1) ASC');
2024-02-23 13:14:38 +01:00
2024-03-22 15:52:24 +01:00
$gruppi = collect($sessioni)->groupBy('utente');
$i = 0;
foreach ($gruppi as $utente => $sessioni) {
$utente = Models\User::find($sessioni[$i]['id_utente']);
++$i;
2024-03-22 15:52:24 +01:00
echo '
<thead>
<tr>
2024-03-22 15:52:24 +01:00
<th colspan="5" class="text-center text-muted" >'.(($utente->photo) ? "<img class='attachment-img tip' title=".$utente->username.' src='.$utente->photo.'>' : "<i class='fa fa-user-circle-o attachment-img tip' title=".$utente->username.'></i>').'<span class="direct-chat-name"> '.$utente->anagrafica->ragione_sociale.' ['.$utente->gruppo.']</span></th>
</tr>
</thead>
<tbody>';
2024-03-22 15:52:24 +01:00
foreach ($sessioni as $sessione) {
$class = 'info';
2024-03-22 15:52:24 +01:00
echo '
<tr class="'.$class.'" data-id="'.$sessione['id'].'" data-nome='.json_encode($sessione['name']).'>
<td>
2024-02-23 13:14:38 +01:00
'.$sessione['modulo'].'
</td>
2024-02-23 13:14:38 +01:00
<td>
'.$sessione['id_record'].'
</td>
2024-02-23 13:14:38 +01:00
<td>
'.Translator::timestampToLocale($sessione['created_at']).'
</td>
2024-02-23 13:14:38 +01:00
<td>
<span class="tip" title="'.Translator::timestampToLocale($sessione['updated']).'" >'.Carbon\Carbon::parse($sessione['updated'])->diffForHumans().'</span>
</td>
2024-02-23 13:14:38 +01:00
<!--td>
<span class="tip" title="'.Translator::timestampToLocale($sessione['updated']).'" >'.gmdate('H:i:s', $sessione['permanenza']).'</span>
</td-->
</tr>';
2024-03-22 15:52:24 +01:00
}
}
2024-03-22 15:52:24 +01:00
echo '
</tbody>
</table>';
2024-03-22 15:52:24 +01:00
} else {
echo '<span>Non è possibile monitorare la presenta degli utenti.</span>';
}