|
17 | 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | 18 | */ |
19 | 19 |
|
| 20 | +use Carbon\Carbon; |
| 21 | + |
20 | 22 | include_once __DIR__.'/core.php'; |
21 | 23 |
|
22 | 24 | $pageTitle = tr('Log'); |
|
34 | 36 | <table class="datatables table table-hover"> |
35 | 37 | <thead> |
36 | 38 | <tr> |
37 | | - <th>'.tr('Username').'</th> |
38 | | - <th>'.tr('Data').'</th> |
39 | | - <th>'.tr('Stato').'</th> |
40 | | - <th>'.tr('Indirizzo IP').'</th> |
| 39 | + <th width="200">'.tr('Username').'</th> |
| 40 | + <th width="150">'.tr('Data').'</th> |
| 41 | + <th width="100">'.tr('Indirizzo IP').'</th> |
| 42 | + <th>'.tr('Dispositivo').'</th> |
| 43 | + <th width="180">'.tr('Stato').'</th> |
41 | 44 | </tr> |
42 | 45 | </thead> |
43 | 46 | <tbody>'; |
|
50 | 53 | } else { |
51 | 54 | $q = 'SELECT * FROM `zz_logs` WHERE `id_utente`='.prepare(Auth::user()['id']).' ORDER BY `created_at` DESC LIMIT 0, 100'; |
52 | 55 | } |
53 | | -$rs = $dbo->fetchArray($q); |
54 | | -$n = sizeof($rs); |
55 | | - |
56 | | -for ($i = 0; $i < $n; ++$i) { |
57 | | - $id = $rs[$i]['id']; |
58 | | - $id_utente = $rs[$i]['id_utente']; |
59 | | - $username = $rs[$i]['username']; |
60 | | - $ip = $rs[$i]['ip']; |
| 56 | +$logs = $dbo->fetchArray($q); |
61 | 57 |
|
62 | | - $timestamp = Translator::timestampToLocale($rs[$i]['created_at']); |
| 58 | +foreach ($logs as $log) { |
| 59 | + $timestamp = Translator::timestampToLocale($log['created_at']); |
63 | 60 |
|
64 | 61 | $status = Auth::getStatus(); |
65 | | - if ($rs[$i]['stato'] == $status['success']['code']) { |
| 62 | + if ($log['stato'] == $status['success']['code']) { |
66 | 63 | $type = 'success'; |
67 | 64 | $stato = $status['success']['message']; |
68 | | - } elseif ($rs[$i]['stato'] == $status['disabled']['code']) { |
| 65 | + } elseif ($log['stato'] == $status['disabled']['code']) { |
69 | 66 | $type = 'warning'; |
70 | 67 | $stato = $status['disabled']['message']; |
71 | | - } elseif ($rs[$i]['stato'] == $status['unauthorized']['code']) { |
| 68 | + } elseif ($log['stato'] == $status['unauthorized']['code']) { |
72 | 69 | $type = 'warning'; |
73 | 70 | $stato = $status['unauthorized']['message']; |
74 | 71 | } else { |
75 | 72 | $type = 'danger'; |
76 | 73 | $stato = $status['failed']['message']; |
77 | 74 | } |
78 | 75 |
|
| 76 | + $created_at = new Carbon($log['created_at']); |
| 77 | + |
79 | 78 | echo ' |
80 | 79 | <tr class="'.$type.'"> |
81 | | - <td>'.$username.'</td> |
82 | | - <td>'.$timestamp.'</td> |
| 80 | + <td>'.$log['username'].'</td> |
| 81 | + <td class="tip" title="'.$created_at->format('d/m/Y H:i:s').'">'.$created_at->diffForHumans().'</td> |
| 82 | + <td>'.$log['ip'].'</td> |
| 83 | + <td class="user-agent tip" title="'.strip_tags($log['user_agent']).'">'.$log['user_agent'].'</td> |
83 | 84 | <td><span class="label label-'.$type.'">'.$stato.'</span></td> |
84 | | - <td>'.$ip.'</td> |
85 | 85 | </tr>'; |
86 | 86 | } |
87 | 87 |
|
|
93 | 93 | <!-- /.box-body --> |
94 | 94 | </div> |
95 | 95 | <!-- /.box -->'; |
| 96 | +?> |
| 97 | + |
| 98 | +<script> |
| 99 | +$(document).ready(function() { |
| 100 | + var parser = new UAParser(); |
96 | 101 |
|
| 102 | + $('tr').each(function(){ |
| 103 | + user_agent_cell = $(this).find('.user-agent'); |
| 104 | + user_agent = user_agent_cell.text(); |
| 105 | + |
| 106 | + if (user_agent !== '') { |
| 107 | + parser.setUA(user_agent); |
| 108 | + device = parser.getResult(); |
| 109 | + |
| 110 | + user_agent_cell.html('<strong>' + device.browser.name + '</strong> ' + device.browser.version + ' | <strong>' + device.os.name + '</strong> ' + device.os.version); |
| 111 | + |
| 112 | + console.log(device); |
| 113 | + } |
| 114 | + }) |
| 115 | +}) |
| 116 | +</script> |
| 117 | + |
| 118 | +<?php |
97 | 119 | include_once App::filepath('include|custom|', 'bottom.php'); |
0 commit comments