-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
797 lines (732 loc) · 41.6 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
<?php
$UID = $UNAME = "";
if (!isset($_COOKIE["VIEWLOG_LOGIN"])) {
header("location: login.php");
} else {
$COOKIE = json_decode($_COOKIE["VIEWLOG_LOGIN"], true);
$UID = $COOKIE["uid"];
$UNAME = $COOKIE["name"];
}
$inc_o = ["default"];
require "_php/include.php";
$SQL = <<<SQL
SELECT IF(MAX(`id`) IS NULL, 0, MAX(`id`)+1) AS NEXT_ID FROM `report` WHERE `owner` = '$UID'
SQL;
$NEXT_REPORT_ID = sql_execute_scalar($SQL);
$REDIRECT_PAGE = [
"v-pills-detail" => "v-pills-dashboard"
];
$PAGE_TITLES = [
"v-pills-dashboard" => "Dashboard",
"v-pills-dashboard-sharing" => "Compartilhados",
"v-pills-detail" => "Detalhes",
"v-pills-profile" => "Perfil",
"v-pills-reports" => "Meus relatórios"
];
if (isset($_COOKIE["CURRENT_PAGE"]) && $_COOKIE["CURRENT_PAGE"] !== "undefined") {
if (array_key_exists($_COOKIE["CURRENT_PAGE"], $REDIRECT_PAGE)) {
$CURRENT_PAGE = $REDIRECT_PAGE[$_COOKIE["CURRENT_PAGE"]];
} else {
$CURRENT_PAGE = $_COOKIE["CURRENT_PAGE"];
}
} else {
$CURRENT_PAGE = "v-pills-dashboard";
}
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Acompanhamento de Visualização de Relatórios">
<meta name="author" content="Paulo Cézar">
<link rel="shortcut icon" href="_img/spy.ico">
<link rel="manifest" href="manifest.json">
<!-- Add to homescreen for Chrome on Android -->
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="512x512" href="_img/spy-256.png">
<!-- Add to homescreen for Safari on iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="ViewLog">
<link rel="apple-touch-icon-precomposed" href="_img/spy-256.png">
<!-- Tile icon for Win8 (144x144 + tile color) -->
<meta name="msapplication-TileImage" content="_img/spy-256.png">
<meta name="msapplication-TileColor" content="#3372DF">
<title>ViewLog <?= (" - " . $PAGE_TITLES[$CURRENT_PAGE]) ?></title>
<!--Stylesheets-->
<link href="_css/jquery.toast.min.css" rel="stylesheet"/>
<link href="_css/bootstrap.min.css" rel="stylesheet"/>
<link href="_css/bootstrap-select.min.css" rel="stylesheet"/>
<link href="_css/app.css" rel="stylesheet"/>
<!--Scripts-->
<script src="_js/jquery-3.3.1.min.js"></script>
<script src="_js/respond.min.js"></script>
<script src="_js/popper.min.js"></script>
<script src="_js/jquery.toast.min.js"></script>
<script src="_js/bootstrap.min.js"></script>
<script src="_js/bootstrap-select.min.js"></script>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<script src="_js/amchart.js"></script>
</head>
<body>
<div class="row">
<div class="nav flex-column nav-pills col-2" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<div id="owner" db-id="<?= $UID ?>">
<?= $UNAME ?>
</div>
<a class="nav-link <?= ($CURRENT_PAGE == "v-pills-dashboard" ? "active" : "") ?>"
id="v-pills-dashboard-tab"
data-toggle="pill"
href="#v-pills-dashboard"
role="tab"
aria-controls="v-pills-dashboard"
aria-selected="true">
Dashboard
</a>
<a class="nav-link <?= ($CURRENT_PAGE == "v-pills-dashboard-sharing" ? "active" : "") ?>"
id="v-pills-dashboard-sharing-tab"
data-toggle="pill"
href="#v-pills-dashboard-sharing"
role="tab"
aria-controls="v-pills-dashboard-sharing"
aria-selected="true">
Dashboard Sharing
</a>
<a class="nav-link <?= ($CURRENT_PAGE == "v-pills-profile" ? "active" : "") ?>"
id="v-pills-profile-tab"
data-toggle="pill"
href="#v-pills-profile"
role="tab"
aria-controls="v-pills-profile"
aria-selected="false">
Perfil
</a>
<a class="nav-link <?= ($CURRENT_PAGE == "v-pills-reports" ? "active" : "") ?>"
id="v-pills-reports-tab"
data-toggle="pill"
href="#v-pills-reports"
role="tab"
aria-controls="v-pills-reports"
aria-selected="false">
Meus relatórios
</a>
<a class="nav-link"
href="logout.php">
Sair
</a>
</div>
<div class="tab-content col-10" id="v-pills-tabContent">
<div class="tab-pane fade <?= ($CURRENT_PAGE == "v-pills-dashboard" ? "active show" : "") ?>"
id="v-pills-dashboard" role="tabpanel" aria-labelledby="v-pills-dashboard-tab">
<h1>Dashboard</h1>
<h2>Painel de acompanhamento de visualizações</h2>
<input class="form-control" id="search" type="text" placeholder="Filtrar relatórios">
<small id="search-count"></small>
<hr/>
<!--
<div class="card">
<div id="featured" class="card-header"></div>
<div class="card-body">
<h5 class="card-title">Recentemente Visualizados</h5>
<a class="btn btn-primary detail"
id="v-pills-detail-tab"
data-toggle="pill"
href="#v-pills-detail"
role="tab"
aria-controls="v-pills-detail"
aria-selected="false">
Detalhes
</a>
</div>
</div>
-->
<?php
$REPORTS["SQL"] = "SELECT * FROM `report` WHERE `owner` = '$UID'";
$REPORTS["QUERY"] = sql_execute($REPORTS["SQL"]);
while ($REPORTS["ROW"] = $REPORTS["QUERY"]->fetch_assoc()) {
$REPORT_DATA["SQL"] = "SELECT DATE_FORMAT(`dt`, '%Y-%m-%d') AS 'date', COUNT(id) AS 'value' FROM `viewlog` WHERE `owner_id` = '$UID' AND `rep_id` = '{$REPORTS["ROW"]["id"]}' GROUP BY DATE_FORMAT(`dt`, '%Y-%m-%d')";
$REPORT_DATA["QUERY"] = sql_execute($REPORT_DATA["SQL"]);
$GRAPH_CONFIGURATION = "";
$GRAPH_FAILMESSAGE = "";
if ($REPORT_DATA["QUERY"]->num_rows === 0) {
$GRAPH_FAILMESSAGE = "<span class='empty_graph'>Este relatório ainda não possui visualizações.</span>";
$GRAPH_CLASS = "fail-message";
} else {
$REPORT_DATA["ARRAY"] = [];
$REPORT_DATA["JS"] = [];
while ($REPORT_DATA["ROW"] = $REPORT_DATA["QUERY"]->fetch_object()) {
array_push($REPORT_DATA["JS"], "{date: '{$REPORT_DATA["ROW"]->date}', value: {$REPORT_DATA["ROW"]->value}}");
array_push($REPORT_DATA["ARRAY"], [$REPORT_DATA["ROW"]->date => $REPORT_DATA["ROW"]->value]);
}
$REPORT_DATA["JS"] = implode(",", $REPORT_DATA["JS"]);
$GRAPH_CONFIGURATION = "<script>"
. "var chart_{$REPORTS["ROW"]["owner"]}_{$REPORTS["ROW"]["id"]} = draw('report-{$REPORTS["ROW"]["owner"]}-{$REPORTS["ROW"]["id"]}', "
. "[{$REPORT_DATA["JS"]}]);"
. "</script>";
$GRAPH_CLASS = "graph";
}
echo "
<div class=\"card\" search='{$REPORTS["ROW"]["id"]}|{$REPORTS["ROW"]["name"]}|{$REPORTS["ROW"]["description"]}'>
$GRAPH_CONFIGURATION
<div id=\"report-{$REPORTS["ROW"]["owner"]}-{$REPORTS["ROW"]["id"]}\" class=\"card-header $GRAPH_CLASS\">$GRAPH_FAILMESSAGE</div>
<div class=\"card-body\">
<h5 class=\"card-title\">{$REPORTS["ROW"]["name"]}</h5>
<p class=\"card-text\">{$REPORTS["ROW"]["description"]}</p>
<!--a class=\"btn btn-primary detail\"
id=\"v-pills-detail-tab\"
data-toggle=\"pill\"
href=\"#v-pills-detail\"
role=\"tab\"
owner=\"{$REPORTS["ROW"]["owner"]}\"
report=\"{$REPORTS["ROW"]["id"]}\"
reportName=\"{$REPORTS["ROW"]["name"]}\"
aria-controls=\"v-pills-detail\"
aria-selected=\"false\">
Detalhes
</a-->
<a class=\"btn btn-primary detail shared\"
href=\"detail.php?own={$REPORTS["ROW"]["owner"]}&id={$REPORTS["ROW"]["id"]}\">
Detalhes
</a>
</div>
</div>";
}
?>
</div>
<div class="tab-pane fade <?= ($CURRENT_PAGE == "v-pills-dashboard-sharing" ? "active show" : "") ?>"
id="v-pills-dashboard-sharing" role="tabpanel" aria-labelledby="v-pills-dashboard-sharing-tab">
<h1>Dashboard Relatórios Compartilhados</h1>
<h2>Painel de acompanhamento de visualizações dos relatórios compartilhados</h2>
<input class="form-control" id="shared-search" type="text" placeholder="Filtrar relatórios">
<small id="shared-search-count"></small>
<hr/>
<?php
$SHARED_REPORTS["SQL"] = "
SELECT s.owner_id AS owner_id, u.name AS owner_name, s.report_id AS report_id, r.name AS report_name, r.description AS report_description
FROM `report` r
INNER JOIN `share` s ON r.`id` = s.`report_id` AND r.`owner` = s.`owner_id`
INNER JOIN `usr` u ON s.`owner_id` = u.`uid`
WHERE s.`usr_id` = '$UID' ORDER BY s.`owner_id`, r.`name`";
$SHARED_REPORTS["QUERY"] = sql_execute($SHARED_REPORTS["SQL"]);
while ($SHARED_REPORTS["ROW"] = $SHARED_REPORTS["QUERY"]->fetch_assoc()) {
$REPORT_DATA["SQL"] = "SELECT * FROM `viewlog` WHERE `owner_id` = '{$SHARED_REPORTS["ROW"]["owner_id"]}' AND `rep_id` = '{$SHARED_REPORTS["ROW"]["report_id"]}';";
$SHARED_REPORT_DATA["SQL"] = "SELECT DATE_FORMAT(`dt`, '%Y-%m-%d') AS 'date', COUNT(id) AS 'value' FROM `viewlog` WHERE `owner_id` = '{$SHARED_REPORTS["ROW"]["owner_id"]}' AND `rep_id` = '{$SHARED_REPORTS["ROW"]["report_id"]}' GROUP BY DATE_FORMAT(`dt`, '%Y-%m-%d')";
$SHARED_REPORT_DATA["QUERY"] = sql_execute($SHARED_REPORT_DATA["SQL"]);
$GRAPH_CONFIGURATION = "";
$GRAPH_FAILMESSAGE = "";
if ($SHARED_REPORT_DATA["QUERY"]->num_rows === 0) {
$GRAPH_FAILMESSAGE = "<span class='empty_graph'>Este relatório ainda não possui visualizações.</span>";
$GRAPH_CLASS = "fail-message";
} else {
$SHARED_REPORT_DATA["ARRAY"] = [];
$SHARED_REPORT_DATA["JS"] = [];
while ($SHARED_REPORT_DATA["ROW"] = $SHARED_REPORT_DATA["QUERY"]->fetch_object()) {
array_push($SHARED_REPORT_DATA["JS"], "{date: '{$SHARED_REPORT_DATA["ROW"]->date}', value: {$SHARED_REPORT_DATA["ROW"]->value}}");
array_push($SHARED_REPORT_DATA["ARRAY"], [$SHARED_REPORT_DATA["ROW"]->date => $SHARED_REPORT_DATA["ROW"]->value]);
}
$SHARED_REPORT_DATA["JS"] = implode(",", $SHARED_REPORT_DATA["JS"]);
$GRAPH_CONFIGURATION = "<script>"
. "var shared_chart_{$SHARED_REPORTS["ROW"]["owner_id"]}_{$SHARED_REPORTS["ROW"]["report_id"]} = draw('shared-report-{$SHARED_REPORTS["ROW"]["owner_id"]}-{$SHARED_REPORTS["ROW"]["report_id"]}', "
. "[{$SHARED_REPORT_DATA["JS"]}]);"
. "</script>";
$GRAPH_CLASS = "graph";
}
echo "
<div class=\"card shared-card\" shared-search='{$SHARED_REPORTS["ROW"]["report_id"]}|{$SHARED_REPORTS["ROW"]["report_name"]}|{$SHARED_REPORTS["ROW"]["report_description"]}|{$SHARED_REPORTS["ROW"]["owner_name"]}'>
$GRAPH_CONFIGURATION
<div id=\"shared-report-{$SHARED_REPORTS["ROW"]["owner_id"]}-{$SHARED_REPORTS["ROW"]["report_id"]}\" class=\"card-header $GRAPH_CLASS\">$GRAPH_FAILMESSAGE</div>
<div class=\"card-body\">
<h5 class=\"card-title\"><span class=\"badge badge-secondary\">{$SHARED_REPORTS["ROW"]["owner_name"]}</span> {$SHARED_REPORTS["ROW"]["report_name"]}</h5>
<p class=\"card-text\">{$SHARED_REPORTS["ROW"]["report_description"]}</p>
<!--a class=\"btn btn-primary detail shared\"
id=\"v-pills-detail-tab\"
data-toggle=\"pill\"
href=\"#v-pills-detail\"
role=\"tab\"
owner=\"{$SHARED_REPORTS["ROW"]["owner_id"]}\"
report=\"{$SHARED_REPORTS["ROW"]["report_id"]}\"
reportName=\"{$SHARED_REPORTS["ROW"]["report_name"]}\"
aria-controls=\"v-pills-detail\"
aria-selected=\"false\">
Detalhes
</a-->
<a class=\"btn btn-primary detail shared\"
href=\"detail.php?own={$SHARED_REPORTS["ROW"]["owner_id"]}&id={$SHARED_REPORTS["ROW"]["report_id"]}\">
Detalhes
</a>
</div>
</div>";
}
?>
</div>
<div class="tab-pane fade <?= ($CURRENT_PAGE == "v-pills-detail" ? "active show" : "") ?>"
id="v-pills-detail"
role="tabpanel"
aria-labelledby="v-pills-detail-tab">
<h1 id='title-detail'>Detalhes</h1>
<h2>Detalhes de acesso ao relatório <span id='detail-report-name'></span></h2>
<div id="detail-loading" class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div>
</div>
<hr/>
<div id="detail-content">
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>Volume de acesso</h5>
<p class='card-text'>Acessos mais recentes por dia</p>
</div>
<hr/>
<div id='report-detail' class='card-header graph'></div>
</div>
<hr/>
<div class='card'>
<div class='card-body'>
<h5 class='card-title'>Relação dos ultimos acessos</h5>
<p class='card-text'>Agrupados por IP e Usuário (quando disponível)</p>
</div>
<div class='card-header'><div id='detail-table'></div></div>
</div>
</div>
</div>
<div class="tab-pane fade <?= ($CURRENT_PAGE == "v-pills-profile" ? "active show" : "") ?>"
id="v-pills-profile"
role="tabpanel"
aria-labelledby="v-pills-profile-tab">
<h1>Perfil</h1>
<h2>Atualize suas informações pessoais</h2>
<hr/>
<?php
if (isset($_COOKIE["VIEWLOG_UPDATE_PROFILE_ERROR"])) {
echo /** @lang html */
"
<div class=\"alert alert-danger\" role=\"alert\">
{$_COOKIE["VIEWLOG_UPDATE_PROFILE_ERROR"]}
</div>
";
}
?>
<form action="_php/update_profile.php" method="post">
<div class="row">
<div class="col">
<input class="form-control" name="new_name" placeholder="Nome" value="<?= $UNAME ?>"/>
</div>
<div class="col">
<input type="password" name="new_pwd" class="form-control" placeholder="Nova senha">
</div>
<div class="col">
<input type="password" name="new_pwd_confirm" class="form-control"
placeholder="Confirmar senha">
</div>
<div class="col">
<button class="btn btn-primary">Salvar</button>
</div>
</div>
</form>
</div>
<div class="tab-pane fade <?= ($CURRENT_PAGE == "v-pills-reports" ? "active show" : "") ?>"
id="v-pills-reports"
role="tabpanel"
aria-labelledby="v-pills-reports-tab">
<h1>Meus relatórios</h1>
<h2>Adicione, edite, remova ou compartilhe seus relatórios</h2>
<hr/>
<div id="edit-my-report">
<div class="form-group row">
<div class="col-1">
<input class="form-control" id="my-report-edit-id" placeholder="ID"
value="<?= $NEXT_REPORT_ID ?>"/>
</div>
<div class="col-11">
<input class="form-control" placeholder="Nome do Relatório" id="my-report-edit-name"/>
</div>
</div>
<div class="form-group">
<label for="my-report-edit-description">Descrição</label>
<textarea class="form-control" id="my-report-edit-description" rows="2"></textarea>
</div>
<div class="form-group">
<div class="form-check form-check-inline">
<?php
$users["SQL"] = "SELECT `uid`, `name` FROM `usr` WHERE `uid` != '{$UID}'";
$users["QUERY"] = sql_execute($users["SQL"]);
$i = 0;
while ($users["ROW"] = $users["QUERY"]->fetch_assoc()) {
if (( ++$i % 9) === 0) {
echo "</div><br /><div class=\"form-check form-check-inline\">";
}
echo /** @lang HTML */
"
<div class='users'>
<input class=\"form-check-input\" type=\"checkbox\" id=\"usr-{$users["ROW"]["uid"]}\">
<label class=\"form-check-label\" for=\"usr-{$users["ROW"]["uid"]}\">
{$users["ROW"]["name"]}
</label>
</div>
";
}
?>
</div>
</div>
<div class="form-group">
<button id="my-report-edit-save" type="button" class="btn btn-primary">Salvar</button>
<button id="my-report-edit-show-modal" data-toggle="modal" data-target="#modalExcluirRelatorio"
type="button" class="btn btn-danger" disabled>Excluir
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="modalExcluirRelatorio" tabindex="-1" role="dialog"
aria-labelledby="modalExcluirRelatorioLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalExcluirRelatorioLabel">Excluir relatório do
acompanhamento</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Tem certeza que deseja excluir relatório de todos os acompanhamentos e
compartilhamentos?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>
<button id="my-report-edit-del" type="button" class="btn btn-danger">Excluir</button>
</div>
</div>
</div>
</div>
</div>
<hr/>
<div class="list-group">
<?php
$my_reports["SQL"] = "SELECT `id`, `name`, `description` FROM `report` WHERE `owner` = '$UID'";
$my_reports["QUERY"] = sql_execute($my_reports["SQL"]);
while ($my_reports["ROW"] = $my_reports["QUERY"]->fetch_assoc()) {
$sharing["SQL"] = "SELECT `usr_id`, `usr`.`name` FROM `share` INNER JOIN `usr` ON `usr`.`uid` = `usr_id` WHERE `owner_id` = '$UID' and `report_id` = '{$my_reports["ROW"]["id"]}'";
$sharing["QUERY"] = sql_execute($sharing["SQL"]);
$sharing_ids = "";
if (($sharing["QUERY"] === false) || ($sharing["QUERY"]->num_rows === 0)) {
$sharing_pills = "<span class=\"badge badge-secondary\">Sem compatilhamentos</span>";
} else {
$sharing_ids = [];
$sharing_pills = [];
while ($sharing["ROW"] = $sharing["QUERY"]->fetch_assoc()) {
$sharing_pills[] = "<span class=\"badge badge-primary\">{$sharing["ROW"]["name"]}</span>";
$sharing_ids[] = $sharing["ROW"]["usr_id"];
}
$sharing_pills = implode(" ", $sharing_pills);
$sharing_ids = implode(",", $sharing_ids);
}
$last_seen["SQL"] = "SELECT * FROM `viewlog` WHERE `owner_id` = '{$UID}' AND `rep_id` = '{$my_reports["ROW"]["id"]}' ORDER BY `dt` DESC LIMIT 1";
$last_seen["QUERY"] = sql_execute($last_seen["SQL"]);
if (($last_seen["QUERY"] === false) || ($last_seen["QUERY"]->num_rows === 0)) {
$last_seen_str = "Nunca";
} else {
$last_seen["ROW"] = $last_seen["QUERY"]->fetch_assoc();
$date = date_create_from_format("Y-m-d H:i:s", $last_seen["ROW"]["dt"]);
$date_str = $date->format("d/m H:i");
$last_seen_str = implode("", [
$date_str,
($last_seen["ROW"]["ip"] !== "") ? " IP: " : "",
$last_seen["ROW"]["ip"],
($last_seen["ROW"]["ip"] !== "") ? " ID: " : "",
$last_seen["ROW"]["gccr_id"],
($last_seen["ROW"]["ip"] !== "") ? " - " : "",
$last_seen["ROW"]["gccr_name"]
]);
}
echo /** @lang HTML */
"
<a href=\"#\" class=\"list-group-item list-group-item-action flex-column align-items-start\"
db-id='{$my_reports["ROW"]["id"]}'
db-name='{$my_reports["ROW"]["name"]}'
db-description='{$my_reports["ROW"]["description"]}'
db-shares='{$sharing_ids}'
>
<div class=\"d-flex w-100 justify-content-between\">
<h5 class=\"mb-1\">#{$my_reports["ROW"]["id"]}: {$my_reports["ROW"]["name"]}</h5>
<small>Visto por último: $last_seen_str</small>
</div>
<p class=\"mb-1\">{$my_reports["ROW"]["description"]}</p>
<small>$sharing_pills</small>
</a>
";
}
?>
</div>
<hr/>
</div>
</div>
</div>
<script type="text/javascript">
var detail_owner_id = 0;
var detail_report_id = 0;
var intervalFx = null;
var updateTimeMillis = 1000;
var uid = $("#owner").attr("db-id");
$(".nav-link").click(function () {
document.cookie = "CURRENT_PAGE=" + $(this).attr("aria-controls");
document.title = "ViewLog - " + $(this).html();
//clearInterval(intervalFx);
switch ($(this).attr("aria-controls")) {
case 'v-pills-dashboard':
$("#v-pills-detail").removeClass("active show");
$("#v-pills-detail").hide();
var chart = window["chart_" + detail_owner_id + "_" + detail_report_id];
chart.write("report-" + detail_owner_id + "-" + detail_report_id);
var div = $("#report-" + detail_owner_id + "-" + detail_report_id);
div.height(div.height() - 1);
setTimeout(function () {
div.height(div.height() + 1);
}, 100);
break;
case 'v-pills-dashboard-sharing':
$("#v-pills-detail").removeClass("active show");
$("#v-pills-detail").hide();
var chart = window["shared_chart_" + detail_owner_id + "_" + detail_report_id];
chart.write("shared-report-" + detail_owner_id + "-" + detail_report_id);
var div = $("#report-" + detail_owner_id + "-" + detail_report_id);
div.height(div.height() - 1);
setTimeout(function () {
div.height(div.height() + 1);
}, 100);
break;
case 'v-pills-detail':
break;
default:
break;
}
});
$(".list-group-item-action").click(function () {
$(window).animate({
scrollTop: 0
}, 2000);
$(".list-group-item-action").removeClass("active");
$(this).addClass("active");
$("#my-report-edit-id").val($(this).attr("db-id"));
$("#my-report-edit-name").val($(this).attr("db-name"));
$("#my-report-edit-description").val($(this).attr("db-description"));
$(".form-check-input").removeAttr("checked");
$("#my-report-edit-show-modal").removeAttr("disabled");
var shares = $(this).attr("db-shares").split(",");
if (shares.length > 0) {
for (var i = 0; i < shares.length; i++) {
$("#usr-" + shares[i]).attr("checked", "checked");
}
}
});
$(".detail").click(function () {
detail_owner_id = $(this).attr("owner");
detail_report_id = $(this).attr("report");
document.cookie = "CURRENT_PAGE=" + $(this).attr("aria-controls");
document.title = "ViewLog - " + $(this).html();
$("#detail-loading").show();
$("#title-detail").text($(this).attr("reportName"));
var classname = $(this).attr("class");
var chart = false;
if ($(this).hasClass("shared")) {
chart = window["shared_chart_" + detail_owner_id + "_" + detail_report_id];
$("#v-pills-dashboard-sharing-tab").removeClass("active");
$("#v-pills-dashboard-sharing").removeClass("active show");
} else {
chart = window["chart_" + detail_owner_id + "_" + detail_report_id];
$("#v-pills-dashboard-tab").removeClass("active");
$("#v-pills-dashboard").removeClass("active show");
}
chart.write("report-detail");
$("#report-detail").height($("#report-detail").height() - 1);
setTimeout(function () {
$("#report-detail").height($("#report-detail").height() + 1);
}, 100);
$("#v-pills-detail").show();
$("#v-pills-detail").fadeIn(100, function () {
$("#v-pills-detail").addClass("active show");
$("#detail-loading").hide();
$(document).scrollTop();
});
});
var toastSave = false;
$("#my-report-edit-save").click(function () {
toastSave = $.toast({
heading: 'Salvar relatório',
text: "Processando requisição...",
hideAfter: 2000,
icon: 'info',
loader: true
});
var request, rep_id, rep_name, rep_description, shares = [];
rep_id = $("#my-report-edit-id").val();
rep_name = $("#my-report-edit-name").val();
rep_description = $("#my-report-edit-description").val() || "";
$(".form-check-input:checked").each(function () {
shares.push($(this).attr("id").split("-")[1]);
});
$.post("_php/update_report.php", {
'uid': uid,
'rep_id': rep_id,
"rep_name": rep_name,
"rep_description": rep_description,
"shares": shares
}, function (r) {
try {
var response = JSON.parse(r);
console.log(response);
toastSave.update({
heading: 'Salvar relatório',
text: response.message,
hideAfter: 1000,
icon: (parseInt(response.status) === 0) ? 'error' : 'success',
loader: true,
afterHidden: function () {
if (parseInt(response.status) === 1)
location.reload();
}
});
} catch (e) {
toastSave.update({
heading: 'Erro inesperado',
text: r,
hideAfter: 10000,
icon: 'error',
loader: true
});
}
});
});
$("#my-report-edit-del").click(function () {
var toastDelete = $.toast({heading: 'Excluir relatório',
text: "Processando requisição...",
hideAfter: 3000,
icon: 'info',
loader: true
});
var request, rep_id;
rep_id = $("#my-report-edit-id").val();
$.post("_php/delete_report.php", {
'uid': uid, 'rep_id': rep_id
}, function (response) {
try {
var r = JSON.parse(response);
toastDelete.update({
heading: 'Excluir relatório',
text: r.message,
hideAfter: 2000,
icon: (r.status === 0) ? 'error' : 'success',
loader: true,
afterHidden: function () {
location.reload();
}
});
} catch (err) {
toastDelete.update({
heading: 'Falha ao excluir relatório',
text: [
"Resposta do servidor:",
response,
"Erro javascript:",
err
],
hideAfter: 10 * 1000,
icon: 'error'
});
}
});
});
$("#search").keyup(function () {
var search = $(this).val();
var count = 0, hide = 0;
$(".card").each(function () {
var attr = $(this).attr('search');
if (typeof attr !== 'undefined' && attr !== false) {
if (!attr.match(new RegExp(search, 'i'))) {
$(this).hide();
hide++;
} else {
$(this).show();
count++;
}
}
});
if (hide > 0) {
$("#search-count").text(count + " resultado" + ((count === 1) ? "" : "s"));
} else {
$("#search-count").text("");
}
});
$("#shared-search").keyup(function () {
var search = $(this).val();
var count = 0, hide = 0;
$(".shared-card").each(function () {
var attr = $(this).attr('shared-search');
if (typeof attr !== 'undefined' && attr !== false) {
if (!attr.match(new RegExp(search, 'i'))) {
$(this).hide();
hide++;
} else {
$(this).show();
count++;
}
}
});
if (hide > 0) {
$("#shared-search-count").text(count + " resultado" + ((count === 1) ? "" : "s"));
} else {
$("#shared-search-count").text("");
}
});
setTimeout(function () {
setInterval(function () {
var toastUpdate = $.toast({heading: 'Atualizando',
text: "Atualizando gráficos...",
hideAfter: false,
icon: "info",
showHideTransition: "slide",
loader: false
});
$.post("_php/get_data_updated.php", function(r){
try {
var response = JSON.parse(r);
for(var date in response){
if (response.hasOwnProperty(date)) {
if(typeof window[date] !== 'undefined'){
window[date].dataProvider = response[date].data;
window[date].validateData();
}
}
}
toastUpdate.reset();
$.toast({
heading: 'Atualizar gráficos',
text: "Gráficos atualizados com sucesso",
hideAfter: 1000,
icon: "success",
loader: true
});
} catch (e) {
toastUpdate.reset();
$.toast({
heading: 'Atualizar gráficos',
text: "Falha na atualização dos gráficos<br>" + e,
hideAfter: 4000,
icon: "error",
loader: true
});
console.error(e);
console.log(r);
}
});
}, 10000);
}, 5000);
</script>
</body>
</html>